.MoveCode \ We are going to process the five memory blocks defined \ in (blockStartHi blockStartLo)-(blockEndHi blockEndLo) \ \ We will either zero the memory block (for the first \ block in the table), or move the block to the address \ in (blockToHi blockToLo) \ \ We work through the blocks from the last entry to the \ first, so we end up doing this: \ \ * Move &1500-&15DA to &7000-&70DA \ * Move &1300-&14FF to &0B00-&0CFF \ * Move &5A80-&645B to &0D00-&16DB \ * Move &64D0-&6BFF to &5FD0-&63FF \ * Zero &5A80-&5E3F LDX #4 \ Set a block counter in X to work through the five \ memory blocks, starting with the block defined at \ the end of the block tables LDY #0 \ Set Y as a byte counter .move1 LDA blockStartLo,X \ Set (Q P) to the X-th address from (blockStartHi STA P \ blockStartLo) LDA blockStartHi,X STA Q LDA blockToLo,X \ Set (S R) to the X-th address from (blockToHi STA R \ blockToLo) LDA blockToHi,X STA S .move2 LDA (P),Y \ Copy the Y-th byte of (Q P) to the Y-th byte of (S R) STA (R),Y \ \ The LDA (P),Y instruction gets modified to LDA #0 for \ the last block that we process, i.e. when X = 0 INC P \ Increment the address in (Q P), starting with the low \ byte BNE move3 \ Increment the high byte if we cross a page boundary INC Q .move3 INC R \ Increment the address in (S R), starting with the low \ byte BNE move4 \ Increment the high byte if we cross a page boundary INC S .move4 LDA P \ If (Q P) <> (blockEndHi blockEndLo) then jump back to CMP blockEndLo,X \ move2 to process the next byte in the block BNE move2 LDA Q CMP blockEndHi,X BNE move2 DEX \ We have finished processing a block, so decrement the \ block counter in X to move on to the next block (i.e. \ the previous entry in the table) BMI move5 \ If X < 0 then we have finished processing all five \ blocks, so jump to move5 BNE move1 \ If X <> 0, i.e. X > 0, then jump up to move1 to move \ the next block LDA ldaZero \ We get here when X = 0, which means we have reached STA move2 \ the last block to process (i.e. the first entry in the LDA ldaZero+1 \ block tables) STA move2+1 \ \ We don't want to copy this block, we want to zero it, \ so we modify the instruction at move2 to LDA #0, so \ the code zeroes the block rather than moving it JMP move1 \ Jump back to move1 to zero the final block .move5 IF _ACORNSOFT OR _4TRACKS JMP SetupGame \ If we get here we have processed all the blocks in the \ block tables, so jump to SetupGame to continue setting \ up the game ELIF _SUPERIOR OR _REVSPLUS JMP Protect \ If we get here we have processed all the blocks in the \ block tables, so jump to Protect to continue setting \ up the game ENDIFName: MoveCode [Show more] Type: Subroutine Category: Setup Summary: Move and reset various blocks around in memory Deep dive: The jigsaw puzzle binaryContext: See this subroutine in context in the source code References: This subroutine is called as follows: * SwapCode calls MoveCode
[X]
Subroutine Protect (category: Setup)
Decrypt or unprotect the game code (disabled)
[X]
Subroutine SetupGame (category: Setup)
Decrypt or unprotect the game code (disabled)
[X]
Variable blockEndHi (category: Setup)
High byte of the end address of blocks moved by the MoveCode routine
[X]
Variable blockEndLo (category: Setup)
Low byte of the end address of blocks moved by the MoveCode routine
[X]
Variable blockStartHi (category: Setup)
High byte of the start address of blocks moved by the MoveCode routine
[X]
Variable blockStartLo (category: Setup)
Low byte of the start address of blocks moved by the MoveCode routine
[X]
Variable blockToHi (category: Setup)
High byte of the destination address of blocks moved by the MoveCode routine
[X]
Variable blockToLo (category: Setup)
Low byte of the destination address of blocks moved by the MoveCode routine
[X]
Variable ldaZero (category: Setup)
Contains code that's used for modifying the MoveCode routine
[X]
Label move1 is local to this routine
[X]
Label move2 is local to this routine
[X]
Label move3 is local to this routine
[X]
Label move4 is local to this routine
[X]
Label move5 is local to this routine