NES programming (dendy), assembler 6502

Since childhood, I had a dream to write a game for the beloved dandy console, as time went on, the dream appeared and then died down again. She directed me towards the magic of programming, and now more than 20 years have passed I am a programmer, and again I am trying to comprehend the magic of that very dandy that so excited my imagination in a difficult but happy childhood. Today I will tell you how I comprehended the secrets of this magic, finally I was able to display sprites on the screen and learned how to draw a background.






php , assembler , assembler api . Dendy ( NES, Famicom), , , , . ():







1. CPU -

2. PPU -

3. APU -





, PPU . , 2 CHR ( ) . 0- 1-, 88, 2- . .



0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0

0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0

0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0

0 1 1 1 1 1 0 0 + 1 1 1 1 1 1 1 1

0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0

0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0

0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0



, 3- :





  • 0 + 0 = 0 -





  • 0 + 1 = 1 -





  • 1 + 1 = 2 -





  • 1 + 0 = 3 -





, background 4 , 3-. , 1- .





, , A, X, Y. X, Y . A.





LDA {argument} -   A  argument ( #20, hex #$20,  %00010010)
STA {address} -  A   ( ppu  )
      
      



X Y





LDX {argument} -    X
LDY {argument}
STX {address} -  X
STY {address} -  Y
INX - increment X
INY - increment Y
CPX {argument} -  x  
CPY {argument} -  y  
      
      



:





JMP {address} -   
BEQ {address} -     CPX true
BNQ {address} -     CPX   
      
      



, :





  • ?





  • ?





NES, PAL 256x240, NTSC 256x224. 88, 3230 PAL, NTSC . , 3 : , nametable ( ), .





  1. - 16 4 4 . .





  2. Nametable - 3230 , , 2 , 2 4- 4 . , , .





  3. - nes 3232 22 , 88 , 1 , %00000000. 2 2 .

    -----------------

    | 0 | 1 |

    -----------------

    | 2 | 3 |

    -----------------



    , , . 2 :





00 - 0-  4- 
01 - 1-
11 - 2-
10 - 3-
      
      



nes

, , , X PPU $2005 X Y, .





LDA #25 ;   X 
STA $2005 ;  #25  
LDA #00 ; 0   Y
STA $2005 ;  #0  
      
      







LDA #100     ;  Y 
STA $2004   ;    OEM data PPU
LDA #00     ;      (      )
STA $2004   ;   
LDA #%00010111  ;        
								;  ,     
STA $2004   ;   
LDA #192    ;  Y 
STA $2004   ;   
      
      



88 6. , $2000 - $2400 , $2400 - $2800 . nametable.





LDA #$20 ;  
STA $2006 ;  2          
LDA #$00 ;  
STA $2006
      
      



, X Y, .





LDA $24 ;       CHR
STA $2007 ;    
;         
      
      



, ,





  LDX #00 ;  0  x  decimal    #$00 - #$FF  
section: 
  ;        
  LDA $24
  STA $2007
  CPX #255
  INX
  BNE section
      
      



255 255 , . Y 4 . , $3F00-$3F0F - 16 . nametable





LDA #$3F ;    $3F
STA $2006
LDA #$00 ;   
STA $2006

LDA $22 ;   nes 
STA $2007 ;     $3F00

LDA $05 ; 
STA $2007 ;     $3F01

;     14 
      
      



16 16





background_pallete:
  .byt $01, $02, $03, $04 
  .byt $05, $22, $23, $24 
  .byt $25, $26, $27, $28
  .byt $31, $32, $33, $34

   LDX #$00 ; x  0

   LDA #$3F ;    $3F
	 STA $2006
	 LDA #$00 ;   
	 STA $2006

loadPallete:
   LDA background_pallete, x ; background_pallete    
                             ;     , x  +1  
   STA $2007 ;  
   CPX #$0F ;  X  16 
   INX ; X = X+1
   BNE loadPallete ;      X   16 
                   ;         
      
      



, $23C0 - $23FF $23C0, $23C8 8 8 .





, , , , , $2007





LDA #$23
STA $2006
LDA #$C2
STA $2006 ;   $23C2 
LDA %00001100 ;    ,      
STA $2007 ;    
      
      



Thus, displaying the background turns into a rather trivial task, the result of 2 weeks of studying the topic of assemblers you saw in the screenshot in the title of the article. In fact, assembler nes is not so complicated if we break the programming stereotypes that we are now using, and it is easier to look at all this when the moment comes to understand that it is possible for an assembler to access an available memory area to write some information there, which will then magically be displayed on the screen ... This is a small victory over oneself, a small step towards a dream. Thank you all for your attention and see you soon.








All Articles