Routines |
Prev: B866 | Up: Map | Next: B916 |
This finds the next vischar or item that should be drawn.
Used by the routine at plot_sprites.
|
||||||||||||||
get_next_drawable | B89C | LD BC,$0000 | BC and DE are previous_x and previous_y. Zero them both | |||||||||||
B89F | LD D,C | |||||||||||||
B8A0 | LD E,C | |||||||||||||
B8A1 | LD A,$FF | Load A with a 'nothing found' marker ($FF) | ||||||||||||
B8A3 | EX AF,AF' | Bank it | ||||||||||||
B8A4 | EXX | Bank the previous_x/y registers | ||||||||||||
Note that we maintain a previous_height but it's never usefully used.
|
||||||||||||||
B8A5 | LD DE,$0000 | Initialise the previous_height to zero | ||||||||||||
B8A8 | LD BC,$0820 | Set B for eight iterations and set C for a 32 byte stride simultaneously | ||||||||||||
B8AB | LD HL,$8007 | Point HL at vischar 0's counter_and_flags | ||||||||||||
Find the rearmost vischar that is flagged for drawing.
Start loop
|
||||||||||||||
lvoi_loop | B8AE | BIT 7,(HL) | Is counter_and_flags' vischar_DRAWABLE flag set? | |||||||||||
B8B0 | JR Z,lvoi_next | Jump to next iteration if not | ||||||||||||
B8B2 | PUSH HL | Preserve the vischar pointer | ||||||||||||
B8B3 | PUSH BC | Preserve the loop counter and stride | ||||||||||||
Check the X axis
|
||||||||||||||
B8B4 | LD A,$08 | Point HL at vischar.mi.pos.x | ||||||||||||
B8B6 | ADD A,L | |||||||||||||
B8B7 | LD L,A | |||||||||||||
B8B8 | LD C,(HL) | Load vischar.mi.pos.x into BC | ||||||||||||
B8B9 | INC L | |||||||||||||
B8BA | LD B,(HL) | |||||||||||||
B8BB | INC BC | Add 4 | ||||||||||||
B8BC | INC BC | |||||||||||||
B8BD | INC BC | |||||||||||||
B8BE | INC BC | |||||||||||||
B8BF | PUSH BC | Stack it | ||||||||||||
B8C0 | EXX | Switch banks to get spare HL | ||||||||||||
B8C1 | POP HL | HL = vischar.mi.pos.x + 4 | ||||||||||||
B8C2 | SBC HL,BC | Subtract previous_x | ||||||||||||
B8C4 | EXX | Bank | ||||||||||||
B8C5 | JR C,lvoi_pop_next | Jump if (vischar.mi.pos.x + 4) < previous_x? | ||||||||||||
Check the Y axis
|
||||||||||||||
B8C7 | INC L | Load vischar.mi.pos.y into BC | ||||||||||||
B8C8 | LD C,(HL) | |||||||||||||
B8C9 | INC L | |||||||||||||
B8CA | LD B,(HL) | |||||||||||||
B8CB | INC BC | Add 4 | ||||||||||||
B8CC | INC BC | |||||||||||||
B8CD | INC BC | |||||||||||||
B8CE | INC BC | |||||||||||||
B8CF | PUSH BC | Stack it | ||||||||||||
B8D0 | EXX | Switch banks to get spare HL | ||||||||||||
B8D1 | POP HL | HL = vischar.mi.pos.y + 4 | ||||||||||||
B8D2 | SBC HL,DE | Subtract previous_y | ||||||||||||
B8D4 | EXX | Bank | ||||||||||||
B8D5 | JR C,lvoi_pop_next | Jump if (vischar.mi.pos.y + 4) < previous_y? | ||||||||||||
B8D7 | INC L | Point HL at vischar.mi.pos.height | ||||||||||||
We compute a vischar index here but the outer code never usefully uses it.
|
||||||||||||||
B8D8 | POP BC | Fetch the loop counter from the stack | ||||||||||||
B8D9 | PUSH BC | |||||||||||||
B8DA | LD A,$08 | Compute the vischar index (8 - B) | ||||||||||||
B8DC | SUB B | |||||||||||||
B8DD | EX AF,AF' | Bank it for return value | ||||||||||||
B8DE | LD E,(HL) | previous_height = vischar.mi.pos.height | ||||||||||||
B8DF | INC L | |||||||||||||
B8E0 | LD D,(HL) | |||||||||||||
B8E1 | PUSH HL | Preserve the vischar pointer | ||||||||||||
B8E2 | EXX | Bank | ||||||||||||
B8E3 | POP HL | Restore vischar pointer to the other bank | ||||||||||||
B8E4 | DEC L | Point HL at vischar.mi.pos.y | ||||||||||||
B8E5 | DEC L | |||||||||||||
B8E6 | LD D,(HL) | previous_y = vischar.mi.pos.y | ||||||||||||
B8E7 | DEC L | |||||||||||||
B8E8 | LD E,(HL) | |||||||||||||
B8E9 | DEC L | |||||||||||||
B8EA | LD B,(HL) | previous_x = vischar.mi.pos.x | ||||||||||||
B8EB | DEC L | |||||||||||||
B8EC | LD C,(HL) | |||||||||||||
B8ED | LD A,L | Point HL at vischar | ||||||||||||
B8EE | SUB $0F | |||||||||||||
B8F0 | LD L,A | |||||||||||||
B8F1 | PUSH HL | Set IY to HL | ||||||||||||
B8F2 | POP IY | |||||||||||||
B8F4 | EXX | |||||||||||||
lvoi_pop_next | B8F5 | POP BC | Restore loop counter and stride | |||||||||||
B8F6 | POP HL | Restore vischar pointer | ||||||||||||
lvoi_next | B8F7 | LD A,L | Advance to the next vischar | |||||||||||
B8F8 | ADD A,C | |||||||||||||
B8F9 | LD L,A | |||||||||||||
B8FA | DJNZ lvoi_loop | ...loop | ||||||||||||
B8FC | CALL get_next_drawable_itemstruct | Iterate over all item_structs looking for nearby items | ||||||||||||
B8FF | EX AF,AF' | Get the old A back | ||||||||||||
If the topmost bit of A' remains set from its initialisation at B8A1, then no vischar was found. It's preserved by the call to get_next_drawable_itemstruct.
|
||||||||||||||
B900 | BIT 7,A | Does bit 7 remain set from initialisation? | ||||||||||||
B902 | RET NZ | Return with Z clear if so: nothing was found | ||||||||||||
Otherwise we've found a vischar
|
||||||||||||||
B903 | PUSH IY | Get vischar in HL | ||||||||||||
B905 | POP HL | |||||||||||||
B906 | BIT 6,A | Is item_FOUND set? ($40) | ||||||||||||
B908 | JR NZ,lvoi_item_found | Jump if so | ||||||||||||
B90A | RES 7,(IY+$07) | Clear the vischar.counter_and_flags vischar_DRAWABLE flag | ||||||||||||
B90E | RET | Return with Z set | ||||||||||||
lvoi_item_found | B90F | INC HL | Point HL at itemstruct.room_and_flags | |||||||||||
B910 | RES 6,(HL) | Clear itemstruct_ROOM_FLAG_NEARBY_6 | ||||||||||||
B912 | BIT 6,(HL) | Test the bit we've just cleared (odd!) - sets Z | ||||||||||||
B914 | DEC HL | Point HL back at the base of the itemstruct. (Note that DEC HL doesn't alter the Z flag) | ||||||||||||
B915 | RET | Return with Z set |
Prev: B866 | Up: Map | Next: B916 |