[Tuto]How to set the RAM_Top in ASM...

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

[Tuto]How to set the RAM_Top in ASM...

Post by XavSnap »

Hi,

If you had to set the Ram_Top to make room for an ASM routine, in Basic:

Exemple @ 78FC
POKE 16388,252 ($FC)
POKE 16389,120 ($78)
And NEW

But, if you had to copy an ASM code beyond this Ram_Top, before the reset, the code will be corrupt by the "NEW" jump command.
In fact, the called ASM code @$3C3, "New"... jump to the Slow/Fast ROM routine, and will tag recalled address in the old SP offset !

This tag will corrupt your code, if you forgot to keep free spaces at the end of the memory...

Code: Select all

03C3    CD;E7;02         CALL $02E7          ; [SET-FAST];NEW ; <-- This CALL will corrupt your code.
03C6    ED;4B;04;40      LD BC,($4004)       ; GET RAM-TOP
03CA    0B               DEC BC               
03CB    60               LD H,B              ; RAM-CHECK
03CC    69               LD L,C               
03CD    3E;3F            LD A,$3F             
03CF    36;02            LD (HL),$02         ; RAM-FILL
03D1    2B               DEC HL               
To avoid to corrupt the code, you had to perform the Fast mode before to call the NEW ROM command.
(with a jump "JP"... not another CALL !)

Code: Select all

    CALL $02E7           ; Set to FAST
    LD (IY+4),$FC        ; Set the RAM_top ($4000+4)
    LD (IY+5),$78        ; in $78FC ($4000+5)
    LD HL,$4082          ; Source offset (your own code in REM)
    LD DE,$78FC          ; Target offset (Future location)
    LD BC,$0703          ; Code length.
    LDIR                 ; COPY HL to DE (length=BC)
    LD SP,$78FA          ; You Ram_top-2 bytes
    JP $03C6            ; [NEW+3]*BIOS ROM*
The Ram_Top will be reset and the new SP target will avoid to destroy the end of your ASM code.

Have fun.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply