Example of optimization:
result from compilation of the code above (more or less)
push xbc and pop xbc is done for all branches but xbc is only used in one of them, so it can be relocated in it:
result from compilation of the code above (more or less)
Code:
_myHBL2:
push XBC
push WA
ld A,(0x8009)
incb 0x1,(_myHBCounter)
cp A,0x8
j ne,L9
cpb (_showHUD),0x0
j eq,L12
lda XBC,_plane1
ld A,(XBC+0x1)
ld (0x8033),A
ld A,(XBC)
ld (0x8032),A
ldb (0x8021),0x0
cpb (_currentLevel),0x0
j eq,L12
ld A,(_plane2 + 0x1)
ld (0x8035),A
j L12
L9: ;1
cp A,0x3c ; '<' 60
j ne,L13
cpb (_screenSplit),0x0
j eq,L12
ld A,(_split1)
ld (0x8034),A
j L12
L13: ;1
cp A,0x64 ; 'd' 100
j ne,L12
cpb (_screenSplit),0x0
j eq,L12
ld A,(_split2)
ld (0x8034),A
L12: ;8
pop WA
pop XBC
reti
push xbc and pop xbc is done for all branches but xbc is only used in one of them, so it can be relocated in it:
Code:
_myHBL2:
push WA
ld A,(0x8009)
incb 0x1,(_myHBCounter)
cp A,0x8
j ne,L9
cpb (_showHUD),0x0
j eq,L12
push XBC
lda XBC,_plane1
ld A,(XBC+0x1)
ld (0x8033),A
ld A,(XBC)
pop XBC
ld (0x8032),A
ldb (0x8021),0x0
cpb (_currentLevel),0x0
j eq,L12
ld A,(_plane2 + 0x1)
ld (0x8035),A
j L12
L9: ;1
cp A,0x3c ; '<' 60
j ne,L13
cpb (_screenSplit),0x0
j eq,L12
ld A,(_split1)
ld (0x8034),A
j L12
L13: ;1
cp A,0x64 ; 'd' 100
j ne,L12
cpb (_screenSplit),0x0
j eq,L12
ld A,(_split2)
ld (0x8034),A
L12: ;8
pop WA
reti