Prev: 29192 Up: Map Next: 29247
29199: Room Handler Dispatch
Used by the routine at Run_Main_Loop_Body.
This is a self-modified instruction so the immediate value is patched at runtime. If it is non-zero, store it in *CurrentLevel.
RoomHandlerDispatch 29199 LD A,0 A=0.
29201 OR A Jump to RoomHandlerDispatch_TestSpriteAttributes if A is zero.
29202 JR Z,RoomHandlerDispatch_TestSpriteAttributes
29204 LD (24497),A Write A to *CurrentLevel.
If *RespawnFlag is non-zero, clear 2047 bytes of the sprite attribute buffer at 59392.
RoomHandlerDispatch_TestSpriteAttributes 29207 LD A,(24507) A=*RespawnFlag.
29210 OR A Jump to RoomHandlerDispatch_Lookup if A is zero.
29211 JR Z,RoomHandlerDispatch_Lookup
29213 LD HL,59392 Clear 2047 bytes from 59392 onwards.
29216 LD DE,59393
29219 LD (HL),0
29221 LD BC,2047
29224 LDIR
Look up the handler address for the current room from the jump table at JumpTable_RoomHandler. Each entry is a two-byte address; the room number (one-indexed) is decremented to form a zero-based index.
RoomHandlerDispatch_Lookup 29226 LD A,(24497) B=*CurrentLevel.
29229 LD B,A
29230 LD A,(24517) A=*CurrentRoom.
29233 DEC A Decrement to make the room ID zero-indexed.
29234 LD DE,31534 DE=JumpTable_RoomHandler.
29237 LD L,A Transfer the room index to HL.
29238 LD H,0
29240 ADD HL,HL Multiply by 2 (two bytes per table entry).
29241 ADD HL,DE Add the jump table base address.
29242 LD E,(HL) Read the two-byte handler address from the table into DE.
29243 INC HL
29244 LD D,(HL)
29245 EX DE,HL Transfer the handler address to HL.
29246 JP (HL) Jump to the room handler.
Prev: 29192 Up: Map Next: 29247