I've got a question about what the best way to do the below is. I'm looking for a solution that returns the minimal number of bytes of code, rather than vast efficiency in code speed.
For the SAGA remake, I need to compress the rooms exits. The standard format is:
Code:
byte N
byte S
byte E
byte W
byte U
byte D
string description (null terminated)
Where N, S, E, W, U, D are the room that going that direction will take you to (up to 150). A 0 indicates the direction is closed.
I've already compressed the description down, so I'm thinking that I can compress this data structure by having:
Code:
string description
byte exits
byte ... Open exits
Where exits is a byte with a bit set for each location if there is an exit (e.g. bit 0 = N, bit 1 = S etc). And then a compacted list of exits for only those rooms that are open.
So I need two routines: one to count the number of exits; the other to match a given exit to the appropriate byte.
The first should be relatively easy, just using a loop like:
Code:
lda exits
ldx #7
ldy #0
.loop dex
beq out
ror a
bcc loop
iny
jmp loop
.out tya
But the second one I can't even think of how to get started; I guess doing something similar to the above but actually increasing the pointer into the data would do?
Any ideas to improve it?