A89: Lookup Tables


[Prev][Next][Index][Thread]

A89: Lookup Tables




How would one go about doing lookup tables in 68k? Here is an example of a
lookup table that I used in Z80 to get the address of the string for weapons
in a game called "Nerd Quest I" for the TI86:

;This code snippet is from part of a much larger routine where
;the player bought weapons at Fry's Electronics. It points to the ;screen
location to display it, loads up the weapon number, checks
;to make sure it's not the last weapon, then uses the lookup table
;to find the correct weapon string to display. (Which is weapon+1)
 ld hl,$0002
 ld (_curRow),hl
 ld a,(Weapon)
 cp 16
 jp z,FryLastWeapon
 inc a
 add a,a
 ld e,a
 ld d,0
 ld hl,WeaponTable
 add hl,de
 call _ldhlind
 call _puts

;Much later...

W1: .db "AOL Disk",0
W2: .db "Pocket Protector",0
W3: .db "Uniball Pen",0
W4:  .db "Ruler",0
W5: .db "Ugly Stick",0
W6: .db "Old Game Boy",0
W7: .db "Linux Reference Book",0
W8: .db "Linux CD",0
W9: .db "Cokebottle Glasses",0
W10: .db "AP Calc Textbook",0
W11: .db "MS Intellimouse",0
W12: .db "Macintosh LC",0
W13: .db "Overhead Projector",0
W14: .db "TI-92+",0
W15: .db "486 Motherboard",0
W16: .db "Giant Screwdriver",0
W17: .db "Soldering Iron",0

WeaponTable: .dw W1,W2,W3,W4,W5,W6,W7,W8,W9,W10,W11,W12,W13,W14,W15,W16,W17


Follow-Ups: