I found an interesting bit of code that fetches values from a look-up table. It was located in “101 projects for the z80″ by Frank Tedeschi. The first data location has to be the relative address for the value the user wishes to get. This will be “added” to hl, forming the full address. I have preserved the original comments.
Input:
(data) contains the position of the value in the table.
ld hl, data ; set pointer
ld l, (hl) ; form address to look-up table.
ld a, (hl) ; get answer from table.data:
.db $01, $05, $00….
Output:
Register a would contain $05. This routine is 5 bytes long, and takes 24 TStates.
Limitations:
There are some limitations however, the table must use 1 byte data, and be no longer than 254 bytes. The lower byte of ‘data’ would have to be a zero. This would limit the locations the LUT can be stored.