Is there any clever trick for assembly code to maintain some kind of mutable state while beebasm is assembling it?
A good while back (I think I posted about it on the Retro Software forum but I can't find the post anywhere now) I created a patch to add a crude stack datatype to beebasm and used it to build some structured assembly macros, so you could write things like:
and that would turn into:
Code: Select all
lda &70
bne .hiddenlabel
lda #1
.hiddenlabel
Watching some of David Given's videos on Youtube has reminded me of this and while (to be scrupulously honest) I don't actually have any pet projects lined up to use this on, I still think it would be nice if I could write code like this in beebasm.
I am wondering if there's any way to abuse some other beebasm feature to allow these macros to track state, without needing a change to the beebasm code. I have a feeling there isn't anything. Strings are not mutable. Although you can write arbitrary data to a spare part of the 64K address space, I don't think you can read it back, so you can't do something like:
Code: Select all
macro inithackystack ; this works
; we use &F000 as the assembly time stack pointer and initialise it to itself for an empty stack
old_P% = P%
P%=&F000
equw &F000
P%=old_P%
endmacro
macro hackystackpush v ; this doesn't work - we can't read the contents of the address space from assembler code
memory[&f000] += 2
memory[memory[&f000]] = v
endmacro
Does anyone have any diabolically twisted ideas?
(The fact macros have to be "syntactically complete" means you can't open and close scopes inside the structured assembly macros to reflect the implicit code structure, for better or worse.)