|
>Btw, how do you go about writing relocatable code in WLA-DX?
I've written relocatable code with WLA-DX before, and it was fairly straight forward. However, I never needed to add "self-modifying code" to this though (and that seems to be where the trouble arises?).
Hmm... let me think for a bit.
I guess I'd do it something like this: Use two lables + one definition + one label for each "modified code area"
.DEFINE CodeLocationInRAM
relocate_start: ... blah,blah... modify_opcode: lda #$00 ... blah relocate_end:
Then you just have a routine to copy the data from relocate_start to relocate_end into RAM starting at CodeLocationInRAM. Such as:
ldx #$0000 - lda relocate_start,x sta CodeLocationInRAM,x inx cpx relocate_end bne -
Whenever you need to modify the code, you can refer to that location as:
sta CodeLocationInRAM+(modify_opcode+1)-relocate_start
That looks kind of messy, but isn't too hard to read. This method would allow you to change the code or even it's location in RAM quickly without having to worry about it's consequences on the modifying code, or the code that copies the section into RAM, etc.
Obviously the idea behind this method isn't WLA specific, so it doesn't do anything special really.
I don't know... there's probably a better way to do that. How do you currently do it?
|