Allow fixups in asm definitions
ZornsLemma opened this issue · 2 comments
I've been playing around with a prototype for allowing the cross-compiler to generate fixups for code in asm definitions. You can see the code on my branch (off your 'devel' branch) at https://github.com/ZornsLemma/PLASMA/tree/asm-fixup.
hello.pla has been modified to:
include "inc/cmdsys.plh"
predef foo(i)#0
asm bar(i)
!SOURCE "vmsrc/plvmzp.inc"
INC ESTKL,X
!BYTE $20 ; JSR
word @foo
DEX
LDA #42
STA ESTKL,X
LDA #0
STA ESTKH,X
!BYTE $20 ; JSR
word @foo
RTS
end
def foo(i)#0
puts("foo ")
puti(i)
putln
end
puts("Hello, world.\n")
foo(5)
bar(10)
done
Building HELLO#FE1000 from that and executing it on an Apple II, it outputs:
HELLO, WORLD.
FOO 5
FOO 11
FOO 42
Note that the assembly-language bar() function is able to call the PLASMA foo() function and the address is automatically fixed up using the standard PLASMA mechanisms, so the VM doesn't need any changes, just the cross-compiler.
I think this approach is conceptually sound, but I may be overlooking something.
I think a similar technique would allow loading and saving of byte global variables from assembly language. What isn't so trivial is getting the address of a global variable in a more usable form (e.g. for storing in zero page and using with LDA (zp),Y); that would require support for fixups which store the high or low byte of the address only and that might require (probably undesirable) VM changes. It may be that some kind of hacks could be used to work around this without requiring VM changes.
Let me know what you think of this and whether you think there's any potential here.
Edit: I think that code is subtly buggy - bar should either be defined as 'asm bar(i)#0' or the assembly language code should do DEX before RTS. But I don't think this is a fundamental problem, just a slip in the example.
That has some interesting potential. The REL module format has support for MSB and LSB fixups but I didn't apply them as I never ran into that case with PLASMA code.
I'm going to close this for version 2.0 unless there's a push to revisit it