Jump to content

[AQUARIUS] z88dk Aquarius Development


Recommended Posts

This is untested but it sets the start address for a ROM cart and includes the required 16 byte cart header.

If you have to use more than 8K of space you have define another block starting $C000 and tell the linker what code to put above and below the start address.

Banked ROM carts require even more work.

This doesn't include setting the heap address for the linker or the stack pointer on startup.

The heap should be set to $3800 and stack should be the top of RAM which would depend on the memory size the machine has or how much you need.

The top of built in ram would be $3FFF, 4K expansion would be $4FFF, 16K would be $7FFF and 32K would be $BFFF.


;       CRT0 for the Mattel Aquarius
;       Stefano Bodrato Dec. 2000
;       If an error occurs eg break we just drop back to BASIC
;       $Id: aquarius_crt0.asm,v 1.8 2009/06/22 21:20:05 dom Exp $
                MODULE  aquarius_crt0
; Include zcc_opt.def to find out some info
        INCLUDE "zcc_opt.def"
; Some scope definitions
        XREF    _main           ;main() is always external to crt0 code
        XDEF    cleanup         ;jp'd to by exit()
        XDEF    l_dcal          ;jp(hl)
        XDEF    _std_seed        ;Integer rand() seed
        XDEF    _vfprintf       ;jp to the printf() core
        XDEF    exitsp          ;atexit() variables
        XDEF    exitcount
        XDEF    __sgoioblk      ;stdio info block
        XDEF heaplast ;Near malloc heap variables
XDEF heapblocks
        XDEF    base_graphics   ;Graphical variables
XDEF coords ;Current xy position
XDEF snd_tick ;Sound variable
        ;;org     14768 ; Mattel relocating loader
;org 14712 ; Simpler loader
; Begin Main 8K Bank ($E000-$FFFF)
    org    $E000
    ; Aquarius Cartridge Header (SuperCart I, 8K Mode)
    defb    $53,$43,$30,$38,$4B,$9C,$B5,$B0,$A8,$6C,$AC,$64,$CC,$A8,$06,$70
        ld      (start1+1),sp ;Save entry stack
        ld      hl,-64
        add     hl,sp
        ld      sp,hl
        ld      (exitsp),sp
IF !DEFINED_nostreams
; Set up the std* stuff so we can be called again
ld hl,__sgoioblk+2
ld (hl),19 ;stdin
ld hl,__sgoioblk+6
ld (hl),21 ;stdout
ld hl,__sgoioblk+10
ld (hl),21 ;stderr
        call    _main ;Call user program
;       Deallocate memory which has been allocated here!
IF !DEFINED_nostreams
LIB closeall
call closeall
start1: ld sp,0 ;Restore stack to entry value
l_dcal: jp (hl) ;Used for function pointer calls
; Define the stdin/out/err area. For the z88 we have two models - the
; classic (kludgey) one and "ANSI" model
INCLUDE "stdio_fp.asm"
        defw    -11,-12,-10
; Select which printf core we want
IF DEFINED_floatstdio
LIB vfprintf_fp
jp vfprintf_fp
IF DEFINED_complexstdio
LIB vfprintf_comp
jp vfprintf_comp
IF DEFINED_ministdio
LIB vfprintf_mini
jp vfprintf_mini
; Now some variables
coords:         defw    0       ; Current graphics xy coordinates
base_graphics:  defw    $3028   ; Address of the Graphics map
; (text area-second line)
_std_seed:      defw    0       ; Seed for integer rand() routines
exitsp:         defw    0       ; Address of where the atexit() stack is
exitcount:      defb    0       ; How many routines on the atexit() stack
heaplast:       defw    0       ; Address of last block on heap
heapblocks:     defw    0       ; Number of blocks
snd_tick:       defb    0       ; Sound variable
defm "Small C+ Aquarius" ;Unnecessary file signature
defb 0
; Floating point support
IF NEED_floatpack
        INCLUDE         "float.asm"
fp_seed:        defb    $80,$80,0,0,0,0 ;FP seed (unused ATM)
extra:          defs    6 ;FP register
fa:             defs    6 ;FP Accumulator
fasign:         defb    0 ;FP register
Edited by JamesD
Link to comment
Share on other sites

I really don't have the time to fix everything at the moment but I can tell you where I think this needs to go from here.

The Aquarius ROM disassembly shows the stack pointer is initially set to $38a0 in the code following START2: before jumping to the cartridge.
The startup code seems to lower it by 64 bytes so it's normally set to $3860 once the C code is called in a cart.
The ROM starts out treating the start of user RAM as $3964. You could set the heap to that address if the stack is large enough at it's default location.
I don't think the cart needs that much space between the two but you can set it to whatever you like. Perhaps $3861?

The ROM routine that checks for RAM is at RAMTEST: in the disassembly and part of that code could be extracted and placed in the crt0 Aquarius module to use for a cartridge if needed. That's also where I found the start of user RAM... or at least where it starts testing for user RAM anyway.

The cartridge should never exit so saving the stack pointer and returning to basic in crt0 needs to be changed for a cart. The code should probably just set the stack pointer on entry and jump back to the first executable address of the cart on exit.
I think some other stuff could be dumped but this should all be done with IF DEFINDED code blocks so one crt0 file could be used for carts or regular executables.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...