Prev: 45598 Up: Map Next: 45675
45621: 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 0035
RoomObjectTable RoomObjectTable_Stored 0512
ImmortalData StoredActorTable 0300
ChangePlayer 45621 LD A,(38558) Fetch the active player from Flag_ActivePlayer.
45624 CPL Flip the bits to switch to the other player.
45625 LD (38558),A Store the new active player in Flag_ActivePlayer.
These are all the player states.
45628 LD HL,38588 Point HL at the state of the active player at ActivePlayer_Unknown.
45631 LD DE,38623 Point DE at the state of the inactive player at InactivePlayer_Unknown.
45634 LD BC,35 Set the number of bytes to swap in BC to 35.
45637 CALL ChangePlayer_Loop Swap the bytes.
These are the room objects.
45640 LD HL,56812 Point HL at the room objects of the active player at RoomObjectTable.
45643 LD DE,57324 Point DE at the room objects of the inactive player at RoomObjectTable_Stored.
45646 LD BC,512 Set the number of bytes to swap in BC to 512.
45649 CALL ChangePlayer_Loop Swap the bytes.
And these are the actors.
45652 LD HL,38658 Point HL at the actors of the active player at ImmortalData.
45655 LD DE,38958 Point DE at the actors of the inactive player at StoredActorTable.
45658 LD BC,300 Set the number of bytes to swap in BC to 300.
Swap the bytes at HL and DE, for the number of bytes in BC.
ChangePlayer_Loop 45661 LD A,(DE) Fetch a byte of the inactive player's data.
45662 EX AF,AF' Switch to the shadow AF register.
45663 LD A,(HL) Copy a byte of the active player's data over the inactive player's data.
45664 LD (DE),A
45665 EX AF,AF' Switch back to the normal AF register.
45666 LD (HL),A Write the inactive player's byte over the active player's data.
45667 INC DE Move onto the next byte of the inactive player's data.
45668 INC HL Move onto the next byte of the active player's data.
45669 DEC BC Decrease the byte counter by one.
45670 LD A,B Loop back to ChangePlayer_Loop until all of the bytes have been swapped.
45671 OR C
45672 JR NZ,ChangePlayer_Loop
45674 RET Return.
View the equivalent code in;
Prev: 45598 Up: Map Next: 45675