4.5.6 BEQ out of range

9Panzer

Well-known member
Hey folks,
having any annoying out of range error when I'm using a BEQ. The error only occurs when I jump banks.

AI Action script:
SwitchBank #$18
JSR doBossAttack
ReturnBank
Entry in Bank18
doBossAttack:
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%10000000 ;Pugna Boss Fight
BEQ +
;;; do stuff
+
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%01000000 ; Grokk Boss Fight
BEQ +
;;; do stuff
+
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%00100000 ; Spider Boss Fight
BEQ +
;;; do stuff
+
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%00010000 ; Vespeto Boss Fight
BEQ +
SwitchBank #$18
JSR doVespeto
ReturnBank
+
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%00001000 ; Sarya
BEQ +
;;; do stuff
+
RTS
RTS

It doesn't work... any one have any idea why?
 

kevin81

Well-known member
"Branch out of range" indicates the position to branch to is too far away (over 127 bytes forward or 128 bytes backward) in the code. A solution is to reverse logic and use a JMP statement, something like this:

Code:
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%00010000 ; Vespeto Boss Fight
BNE +
   JMP notVespeto
+
SwitchBank #$18
JSR doVespeto
ReturnBank

notVespeto:
 
Last edited:

9Panzer

Well-known member
Thanks for chiming in @kevin81 .
I was trying to reduce the amount of bank00 text by just having it jump to bank18 and run the full routine. I originally had something similar to that.

Is it because of the initial jump on the AI that's causing the grief?
 

kevin81

Well-known member
I'm not sure, but I don't think so, as there seems to be no branching going on in the AI action script.
Do you know which file and line number throws the error when you try to compile it, and which BEQ statement is on that line?

Also unfortunately I'm not familiar with custom bank switching yet, but it looks like the script is switching to bank #$18 while that piece of script already resides in bank #$18.
 
Top Bottom