The first lines of code are pretty standard stuff, disable the NMI (to do the startup without interruptions), reset the stack to point at $01FF and wait 2 VBlanks to warm up the PPU. All this from $8000 to $8012.
Then it starts the RAM initialization part. The page 7 of the RAM (from $0700 to $07FF) seems to be used as game variables storage. When you reset the console, the RAM is not automatically cleared. The SMB code does a check on some of those variables to spot if it was a reset or a power on and based on their values it cleans only some part of the memory.
$8014> LDY #$fe ; RAM cleaning:
$8016> LDX #$05 ; if one byte of $07D7-$07DB is >= A, clear the memory to $07FE
$8018> LDA $07D7,X ; else if $07FF = A5, clear to $07D6
$801B> CMP #$0a ; else clear to $07FE
$801D> BCS $802B ;
$801F> DEX ; Way to check Reset vs Power
$8020> BPL $8018 ;
$8022> LDA $07FF ;
$8025> CMP #$a5 ;
$8027> BNE $802B ;
$8029> LDY #$d6 ;
$802B> JSR $90CC ; Clear RAM Subroutine to 0700+YProbably the memory after $07D7 contains the top scores and other data useful to keep during a reset. The routine in $90CC is the actual cleaner. It takes Y as input parameter and use a loop to clean the memory backwards from $0700 + Y to $0000.
$90CC> LDX #$07 ; SUB Clear_RAM ;Clear memory from $0000 to $0700+Y, skip $01FF to $0160
$90CE> LDA #$00 ;
$90D0> STA $06 ;
$90D2> STX $07 ;
$90D4> CPX #$01 ;
$90D6> BNE $90DC ;
$90D8> CPY #$60 ;
$90DA> BCS $90DE ;
$90DC> STA ($06),Y ;
$90DE> DEY ;
$90DF> CPY #$ff ;
$90E1> BNE $90D4 ;
$90E3> DEX ;
$90E4> BPL $90D2 ;
$90E6> RTS ; ENDSUB Clear_RAMThe loop is using the two addresses in Page Zero ($07 and $06) for indirectly address the whole RAM. I think that the 0x60 bytes skipped on page 1 are reserved as stack and in this way the cleaning routine can be called safely even outside the initialization part.Continuing, there are some sound initialization (disable DPCM and enable all the other four sound channels) instructions and we set the memory $07FF to 0xA5 so next time we know if it was a reset (for now no idea what $07A7 is).
The subroutine at $8220 is responsible for initializing the RAM from $0200 to $02FF with 0xF8 every 5 bytes. Very likely this part of the RAM will contain the buffer for the SPR-RAM (coordinates of the sprites, tile index # and attributes).
$8220> LDY #$00 ; SUB Init_Sprite_RAM ;Write every 4 byte #$F8 from $200
$8222> BIT $04A0 ;
$8225> LDA #$f8 ;
$8227> STA $0200,Y ;
$822A> INY ;
$822B> INY ;
$822C> INY ;
$822D> INY ;
$822E> BNE $8227 ;
$8230> RTS ; ENDSUB Init_Sprite_RAMI don't really understand the meaning of the BIT instruction at address $8222, maybe some leftover from a previous version of the code...There still some interesting subroutines before the end of the reset part and I will keep them for the next post!




No comments:
Post a Comment