Friday 28 November 2014

Rocket Raid Under The Hood 5: Program Initialization

This is the fifth part in a series of posts on digging into the code of the Acornsoft side-scrolling arcade game, Rocket Raid.

Initialization on Entry


Let's look at the first action the program takes upon entry at location &3400.


Data Relocation


Here is the disassembly that was generated by BeebDis in the last post (with comments added):

.L3400
        LDY #$00      ; Set counter to zero
.L3402
        LDA L3000,Y   ;
        STA L0400,Y   ; Copy data from location &3000+Y to &0400+Y
        LDA L3100,Y   ;
        STA L0500,Y   ; Copy data from location &3100+Y to &0500+Y
        LDA L3200,Y   ;
        STA L0600,Y   ; Copy data from location &3200+Y to &0600+
        DEY ;
BNE L3402             ; Loop back a total of &FF times
Hence this loop copies data in the range [&3000, &32FF] down to [&400, &6FF]. The Advanced User Guide indicates that the area of memory between &400 and &7FF is a workspace for the currently active language ROM (such as BASIC). Since the main game code does not use BASIC, this area is available for its use.

This answers the puzzle in the previous post of what happens to the data at &3000 which will otherwise be overwritten by screen graphics upon switching MODE. 

There is no need for the program to similarly guard the code that sits in the area [&3300, &349D] after it has been used during program initialization, as it is used only once.



BeebDis Custom Labels

It would be nice if some of the automatically-generated labels were replaced with more explanatory names. For example, we might like to replace "L3400" with "entry".

This can be achieved with BeebDis by creating a custom list of labels. First, we create a new text file (called "mylabels.txt" for example) and in it define any labels we wish:
entry         $3400
copyBytes $3402
Adding an extra line in the control file will direct BeebDis to use the file:
symbols mylabels.txt
Running BeebDis again, we can see that the labels have been replaced in the disassembly:
.entry
        LDY #$00    ; Set counter to zero
.copyBytes
        LDA L3000,Y

        ...[snipped]... 
BNE copyBytes



Disassembly of the Relocated Code

I took an extra step to deal with the code [&3000, &32FF] that gets relocated down to location &400. Although there is no major problem with disassembling this section of code in place (i.e. before relocation), there are a few places in the main Rocket Raid code where jumps are made directly into the relocated area, so I decided to disassemble the code using its relocated addresses, for consistency.

I manually "relocated" the section of code by splitting it out as a separately-saved file using a hex editor. This allows it to be loaded by BeebDis with a second control file specifying the relocated starting address:

load $0400 $.RAIDOBJ_relocated
save disassembly_relocated.txt
symbols labels.txt
symbols mylabels.txt



No comments:

Post a Comment