PHPnews.io

dot command stack [til/spectrum]

Written by Remy Sharp / Original link on Feb. 21, 2021

When writing dot commands for the Spectrum Next the bytes are loaded into memory position $2000. Normally "free" memory is $8000 onwards to $FFFF (or so I understood), but the stack is sitting at $FF41 (or so) so paging in a bank to the last MMU position will nuke the stack.

Straightforward work around for this is to swap in your own stack:

          ;; as early as possible
          ld (oldStack), sp
          ld sp, stackTop
          jr Start                ; jump to the start of the program

oldStack  DW 0
stack     DS $80, $AA ; $AA is just debug filler of stack area
stackTop  DW $AAAA

cleanUp:
          ;; then on exit restore the oldStack to SP
          ld sp, (oldStack)
          ei
          ret

This way I can now safely use the page of memory at $E000.

Originally published on Remy Sharp's b:log

remysharp

« How to build a simple HTML landing page using Tailwind CSS - The Paradox of Simplification »