Prev: B21E Up: Map Next: B26B
B235: 1UP/ 2UP Swapper
Used by the routines at InitialiseGame and SwitchPlayer.
Swaps over the state of player 1 and player 2, by swapping three blocks of memory with the stored copy for the other player. The active player flag in Flag_ActivePlayer is also flipped. The blocks swapped are:
Active Stored Bytes
ActivePlayer_Unknown InactivePlayer_Unknown 0023
RoomObjectTable RoomObjectTable_Stored 0200
ImmortalData StoredActorTable 012C
ChangePlayer B235 LD A,($969E) Fetch the active player from Flag_ActivePlayer.
B238 CPL Flip the bits to switch to the other player.
B239 LD ($969E),A Store the new active player in Flag_ActivePlayer.
These are all the player states.
B23C LD HL,$96BC Point HL at the state of the active player at ActivePlayer_Unknown.
B23F LD DE,$96DF Point DE at the state of the inactive player at InactivePlayer_Unknown.
B242 LD BC,$0023 Set the number of bytes to swap in BC to 23.
B245 CALL ChangePlayer_Loop Swap the bytes.
These are the room objects.
B248 LD HL,$DDEC Point HL at the room objects of the active player at RoomObjectTable.
B24B LD DE,$DFEC Point DE at the room objects of the inactive player at RoomObjectTable_Stored.
B24E LD BC,$0200 Set the number of bytes to swap in BC to 0200.
B251 CALL ChangePlayer_Loop Swap the bytes.
And these are the actors.
B254 LD HL,$9702 Point HL at the actors of the active player at ImmortalData.
B257 LD DE,$982E Point DE at the actors of the inactive player at StoredActorTable.
B25A LD BC,$012C Set the number of bytes to swap in BC to 012C.
Swap the bytes at HL and DE, for the number of bytes in BC.
ChangePlayer_Loop B25D LD A,(DE) Fetch a byte of the inactive player's data.
B25E EX AF,AF' Switch to the shadow AF register.
B25F LD A,(HL) Copy a byte of the active player's data over the inactive player's data.
B260 LD (DE),A
B261 EX AF,AF' Switch back to the normal AF register.
B262 LD (HL),A Write the inactive player's byte over the active player's data.
B263 INC DE Move onto the next byte of the inactive player's data.
B264 INC HL Move onto the next byte of the active player's data.
B265 DEC BC Decrease the byte counter by one.
B266 LD A,B Loop back to ChangePlayer_Loop until all of the bytes have been swapped.
B267 OR C
B268 JR NZ,ChangePlayer_Loop
B26A RET Return.
View the equivalent code in;
Prev: B21E Up: Map Next: B26B