![]() |
Routines |
| Prev: 9D97 | Up: Map | Next: 9DD9 |
|
Used by the routines at START, DRAW_LOCATION_PICTURE, DO_HELP, MOVE, HANDLED, DO_ACTION, REACT, FIND_OBJECT_HANDLER, GET_OBJECT and TROLLS_TURN_TO_STONE.
The game's general-purpose lookup. A table is a run of three-byte records -- a key, then a two-byte value -- ending at a key of $FF, and this walks it in order looking for the key in A. It is not sorted and does not need to be. Eleven routines use it: the picture table at PICTURE_TABLE is one, the action table at ACTION_TABLE another.
|
||||||||||||||||
| FIND_RECORD | 9DBD | EXX | Work in the other register set, so the caller's BC, DE and HL survive | |||||||||||||
| 9DBE | PUSH IX | HL walks the table from IX | ||||||||||||||
| 9DC0 | POP HL | |||||||||||||||
| 9DC1 | LD B,A | B = the key being looked for | ||||||||||||||
| 9DC2 | LD E,$03 | DE = 3, the size of a record | ||||||||||||||
| 9DC4 | LD D,$00 | |||||||||||||||
| FIND_RECORD_0 | 9DC6 | LD A,(HL) | Found it? The key is tested before the end marker, so a key of $FF can never be found | |||||||||||||
| 9DC7 | CP B | |||||||||||||||
| 9DC8 | JR Z,FIND_RECORD_1 | |||||||||||||||
| 9DCA | CP $FF | Run off the end? | ||||||||||||||
| 9DCC | JR Z,FIND_RECORD_1 | |||||||||||||||
| 9DCE | ADD HL,DE | On to the next record | ||||||||||||||
| 9DCF | JP FIND_RECORD_0 | |||||||||||||||
| FIND_RECORD_1 | 9DD2 | PUSH HL | IX = the record, or the $FF that ended the table | |||||||||||||
| 9DD3 | POP IX | |||||||||||||||
| 9DD5 | CP $FF | NZ if found; A is the key | ||||||||||||||
| 9DD7 | EXX | |||||||||||||||
| 9DD8 | RET | |||||||||||||||
|
Done in the alternate register set, so the caller's BC, DE and HL survive it.
|
||||||||||||||||
| Prev: 9D97 | Up: Map | Next: 9DD9 |