Neat programming trick for optional operations
Posted: Tue Sep 18, 2018 3:16 pm
Since work is now less crunchy, I actually managed to find some time to work on my Gunstar Heroes disassem, and stumbled across a neat trick (apologies if this is already known but I thought it was cool):
So a single variable controls which out of the four optional bits of code get run, always starting with the first. The first is some kind of palette update and I haven't figured out the rest yet, but it seems like a neat method for doing partial updates depending on a dirty flag. Neat!
Code: Select all
MOVE.w $FFFF8002.w, D0 ; var indicating which processing to perform
; 0 will never overflow (so will skip all processing)
; 8000 will overflow once (and afterwards be 0)
; C000 will overflow twice (and afterwards be 0)
; E000 will overflow three times (and afterwards be 0)
; F000 will overflow four times (and afterwards be 0)
ADD.w D0, D0
BCC.w @skipPaletteFunc_000036C6 ; skip palette processing if D0 add didn't cause overflow
; palette processing here
@skipPaletteFunc_000036C6:
ADD.w D0, D0
BCC.w @loc_000036DC
; optional processing 2
@loc_000036DC:
ADD.w D0, D0
BCC.w @loc_000036F2
; optional processing 3
@loc_000036F2:
ADD.w D0, D0
BCC.w @loc_00003708
; optional processing 4
@loc_00003708:
RTS