Zsy wrote:
But the problem is that I have to load so much info that I get a "branch out of range" error while compiling.
The common fix to "branch out of range" is to check for the opposite condition to skip over a JMP. For example, this:
Code:
CMP #$01
BNE Label
;(do stuff here)
RTS
Label
Can be modified like this:
Code:
CMP #$01
BEQ Skip
JMP Label
Skip:
;(do stuff here)
RTS
Label:
To fix a branch out of range. It works exactly the same.
But I have to agree that in your case a jump table might be the best option. Depending on the number of screens you have, comparing a screen's index against a lot of numbers might take a while. So instead you can make a table with the addresses of the code that draws each screen, like this:
Code:
DrawScreenPointers:
.dw DrawScreen0, DrawScreen1, DrawScreen2, DrawScreen3, (...)
And then you can do the following to go to the proper routine for the current screen:
Code:
LDA CurrentScreen ;get the screen's index
ASL ;multiply by 2 because each address is 2 bytes
TAX ;put it in an index register
LDA DrawScreenPointers+0, X ;copy the low byte of the address
STA Pointer+0
LDA DrawScreenPointers+1, X ;copy the high byte of the address
STA Pointer+1
JMP (Pointer) ;jump to the drawing routine
And then of course you need to make all the drawing routines, like this:
Code:
DrawScreen0:
;(do stuff here)
RTS
DrawScreen1:
;(do stuff here)
RTS
DrawScreen2
;(do stuff here)
RTS
(...)