Jump to content
IGNORED

Newbie question about Breakout code


Recommended Posts

i fancy having a crack at learning how to program the 2600. i'm going to print out the main tutorial and go through that and also saw a post which recommended taking a 2k game and dissasembling it to go through the code.

 

i did this with breakout although the code looks different to the combat dissasembly from the atariage site. here's a snapshot:

 

VSYNC   =  $00
VBLANK  =  $01
WSYNC   =  $02
NUSIZ0  =  $04
NUSIZ1  =  $05
COLUP0  =  $06
COLUP1  =  $07
COLUPF  =  $08
COLUBK  =  $09
CTRLPF  =  $0A
PF0     =  $0D
PF1     =  $0E
PF2     =  $0F
AUDC0   =  $15
AUDF0   =  $17
AUDV0   =  $19
GRP0    =  $1B
GRP1    =  $1C
ENAM0   =  $1D
ENAM1   =  $1E
ENABL   =  $1F
VDELBL  =  $27
HMOVE   =  $2A
HMCLR   =  $2B
CXCLR   =  $2C
CXP0FB  =  $32
CXP1FB  =  $33
CXM0FB  =  $34
CXM1FB  =  $35
CXBLPF  =  $36
INPT0   =  $38
SWCHA   =  $0280
SWCHB   =  $0282
INTIM   =  $0284
TIM64T  =  $0296

      ORG $F000
LF000: .byte $4C,$37,$F2
LF003: LDY    #$04    
LF005: STY    WSYNC   
      LDA    ($D0),Y 
      AND    #$0F    
      AND    $EE     
      STA    PF1     
      LDA    ($D2),Y 
      AND    #$0F    
      STA    $BB     
      LDA    ($D4),Y 
      AND    #$F0    
      ORA    $BB     
      STA    PF2     
      LDA    ($D6),Y 
      AND    #$F0    
      AND    $EE     
      STA    PF1     
      LDA    ($D8),Y 
      AND    #$0F    
      STA    PF2     
      INX            

 

 

i guess it's not different at all - i just need to learn more although as breakout was one of my favourite games i thought i'd look at that first. also there doesnt seem to be crazy amounts of code for it either which i thought would be good from a learning point of view.

 

 

anyway, with regards to going through the breakout code to find out what each line does, where would i be best to look to find out what lines like these do:

 

HMOVE = $2A

HMCLR = $2B

CXCLR = $2C

CXP0FB = $32

 

and

 

 

LF005: STY WSYNC

LDA ($D0),Y

AND #$0F

AND $EE

STA PF1

 

 

thanks in advance

Link to comment
Share on other sites

anyway, with regards to going through the breakout code to find out what each line does, where would i be best to look to find out what lines like these do:

 

HMOVE  =  $2A

HMCLR  =  $2B

CXCLR  =  $2C

CXP0FB  =  $32

 

and

 

 

LF005: STY    WSYNC 

      LDA    ($D0),Y

      AND    #$0F   

      AND    $EE   

      STA    PF1   

 

 

thanks in advance

1005193[/snapback]

 

The first group of lines are "equates" that define what and where specific memory locations are. This is really optional, as you can write assembly code that gives the memory address rather than using an equate, *BUT* equates make it a *LOT* easier to understand the code. The locations of those particular memory addresses are fixed, they never change (although they do have "mirrored" locations at other memory addresses that can also be used), and the names used (e.g., "HMOVE") have been agreed upon through long usage and convention, plus whatever they were called by the original designers and in the original documents about what the locations are and how they're used. If you want to know more about those lines, refer to the "Stella Programming Guide":

 

http://www.atarihq.com/danb/a2600.shtml

- then scroll down to "Technical Files" and it's the third link.

 

The second group of lines is more difficult to understand. First, you need to know about 6502 assembly code, you can start here:

 

http://www.6502.org/tutorials/6502opcodes.html

 

But it isn't as simple as just looking up what a given memory location and 6502 opcode does, because when you do a disassembly of a ROM image, Distella can convert some of the memory addresses to "English" using the standard equates, but it can't convert the memory addresses for subroutines and variables. You have to study the code carefully to see how specific memory addresses (variables) are being used-- for example, maybe one particular memory address is being used to store the vertical position of a given sprite-- and to figure out what the various subroutines are doing, and either add more equates and disassemble again using the additional equates, or edit the disassembly to add labels and comments, etc.

Note that there are already some commented disassemblies for some games.

 

I can make some intelligent guesses about the specific code lines you posted:

 

LF005: STY    WSYNC   
      LDA    ($D0),Y 
      AND    #$0F    
      AND    $EE     
      STA    PF1    

 

The first line starts with an address ("LF005", which is a label created by Distella to indicate that this line starts at address $F005), then a 6502 opcode ("STY", which means "store the value of the Y register"), and a memory address ("WSYNC", the equate name for the TIA register that tells the Atari 2600 to "wait for horizontal sync"). So what it's doing is storing the value of the Y register in the location that makes the Atari twiddle its thumbs until the RGB raster beams have reached the right edge of the playfield and need to be swept back to the left edge of the screen to begin drawing the next scan line. This is done to keep the graphics drawing for each scan line all lined up nice and neat.

 

The second line starts with an opcode ("LDA", meaning "load the accumulator"), then an indexed address ("($D0),Y", meaning "the address that's being pointed to by addresses $D0 and $D1, offset by the value in the Y register"). Based on what the fifth line says, this line is loading the graphics data that will be used for part of the playfield, and the Y index is probably holding either the scan line number or some similar value (e.g., a row number, where each row actually consists of several scan lines).

 

The third line starts with an opcode ("AND", meaning "perform a logical 'and' with the bits of the value in the accumulator"), then an immediate value ("#$0F", which is the hexadecimal value of the number 15). What this is doing is taking the value in the accumulator-- which is the playfield graphics data that was just loaded in the second line-- and ignoring or "zeroing" the left half of it.

 

The fourth line starts with an opcode ("AND" again), then an address ("$EE", which is a zero-page address located in the 128 bytes of RAM). What this is doing is taking the value in the accumulator-- the playfield graphics data that just had the left half "wiped out"-- and doing another logical 'and' with the value that's in address $EE.

 

The fifth line starts with an opcode ("STA", meaning "store the value of the accumulator"), then a memory address ("PF1", the equate name for the "playfield 1" register, which holds part of the playfield data). So this is taking the graphics data that was just processed in the preceding lines, and storing it in one of the playfield registers so that it appears on the screen.

 

Michael Rideout

Link to comment
Share on other sites

Reverse engineering is the simpler the better you know the engineering bit without the reverse thingy. That said, I recommend looking at Andrews tutorial first. Looking at game source codes or disassembling games is good for learning advanced techniques. Reading Andrew's tutorial will also help you to spot common Atari 2600 programming idioms. This will greatly help you when you're actually ready to disassemble and analyze a game.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...