Hi, i am wanting to put an irq routine in zero page and another one in page 1. Offcourse i cannot simply load directly into these pages because the loading routines may very well prohibit or rely on these locations.
So i will copy the code from the loaded area to pages 0 and 1. This is not a problem.
However, when compiling, XA will always assume i am compiling them in main memory, so all the STA's (self modified code) and JMP's (To zero page) will be wrong.
How do i achieve this?
Routines in Zero Page
After having done some experimentations, it appears that using the sections things does not work very well. So use .zero only for defining adresses in zero page.
For the code, I tried this, and it seems to work:
It's not particularly elegant, but it seems to work fine
For the code, I tried this, and it seems to work:
Code: Select all
; Some code here
SomeRoutine1
lda foo
sta bar
rts
; Defines a label to mark the begining of the section to copy later
BaseCopyAdress
; Switch program counter to page 0
*=$00
ZeroPageRoutine
lda #$12
lda #$13
sta ZeroPageRoutine+1 ; This will use ZP adressing mode
ZeroPageRoutineEnd
; Switch program counter to page 1
*=$100
OnePageRoutine
lda #$12
lda #$13
sta OnePageRoutine+1
OnePageRoutineEnd
; Move back the program counter to a usable adress
; by adding the size of the two previous routines to the
; label we defined before the program counter change.
*=BaseCopyAdress+(ZeroPageRoutineEnd-ZeroPageRoutine)+(OnePageRoutineEnd-OnePageRoutine)
; Some more code here
SomeRoutine2
lda foo
sta bar
rts
Twilighte wrote:Thats great, thanks Dbug.
Just one other question..
How do i allign code to a page boundary in xa?
Code: Select all
.dsb 256-(*&255)
Obfuscated XADbug wrote:Code: Select all
.dsb 256-(*&255)
but that is the way I do it, as the .align directive does not seem to work.