View Single Post
Old 27th August 2013, 06:24 AM   #6
Gotta fill something here.
Miksy91's Avatar
Join Date: Jul 2013
Location: Northern Europe
Age: 27
Posts: 117

Example of jump table;

ld a, indexValue
ld hl, tableStartAddress
dec a
ld c, a
ld b, 00
add hl, bc
add hl, bc
ldi a, (hl)
ld h, (hl)
ld l, a
jp hl
I guess you'd rather want to save space by writing the way you have, but if we weren't rom hacking, but would be programming instead, any programmer would replace comparing cases with jump tables.
I've never had that much problems with free space when it comes to coding new stuff, only with existing data structures. So I'm used to trying to think of the smartest way the code the feature, though it might not always be the most save spacing.

(Anyway, what you could do about the code is to remove useless "cp a, 00" instructions. "and a, a" and "xor a, a" are instructions that take only one byte and can do a lot of valuable stuff on their own.)

and a,a
-Always resets carry flag // scf + ccf
-Resets zero flag if a = 00 // cp a, 00

xor a,a
-Always sets a to 00 // ld a, 00
-Always resets zero flag

They have a pretty good implementation of jump table in pokemon G/S/C as two of the RST instructions.

Last edited by Miksy91; 27th August 2013 at 06:27 AM.
Miksy91 is offline