Creating graphics for nes / dendy

My previous articles talk about how to start programming for dandy in assembler. We learned how to draw sprites and background, we also briefly discussed what an attribute table and a name table are, we also figured out how to read a controller. In those articles I used chr from the game super mario bros 2 because I was not an artist, but still to create a game I had to look for tools that would help me in creating my graphics for the game. Under the cut are the stages of graphics development.






It took quite a long time to find a tool for linux to create a table of names, after a while I even started writing my own in php. The idea was simple and it was already close to completion. It is possible to convert a bmp or png image by pixel by pixel. From left to right 128 pixels, and from top to bottom 256 lines. Next, we determine the color of each pixel, and there can be only 4 of these and, depending on the color, set the appropriate bits, each pixel in the chr file is described by 2 bits, according to the following principle:





  • color 0 = 00 = 00000000





  • color 1 = 01 = 00000001





  • color 2 = 10 = 00000010





  • color 3 = 11 = 00000011





That is, these 2 bits are just the last 2 bits of the color sequence number. At the same time, in sprites, color 0 is a transparent color. In background, this is the background color.





The chr literally stores 2 banks, 128 by 128 pixels. Often the 1st bank is used for sprites (and is called the left bank), the 2nd bank, in turn, is used for background sprites (well, or tiles, I may be mistaken in terminology). We figured out this, and as soon as I finished my script, I found img2chr, already ready for node.js





The script is installed quite simply





$ npm install -g img2chr
      
      



This script has 2 parameters, the 1st is the picture file (I use png), the 2nd is the file where you need to save chr





img2chr test.png test.chr
      
      



After that, we can include chr in the code and use it.





A little about the FCEUX emulator

I tried several emulators at the time of this writing, it turned out that FCEUX for Windows, running from under wine, is most convenient. It provides a debugger, and can dump the nametable and attribute table, which is pretty handy for rendering the levels correctly.





, . 128256 8 , .





. .





, , , . , .





, , , . .









. . , , .









img2png test.png t.chr
      
      



. PPU $2004





  1. Y -













  2. X -









LDA #100 ;    A  100
STA $2004 ;    Y   $2004
LDA #$01 ;    1 (0- , 1- ) 
STA $2004 ;    
LDA #%00010110 ;  
STA $2004
LDA #100 ; x  
STA $2004
      
      



And my sprite was displayed on the screen. That could not but rejoice. After that, I brought out all the sprites for drawing the hero, 10 of them came out, of course this is a very large number of sprites, since we can reach the limitations of the prefix, for example, 64 sprites on the screen at the same time, but we will talk about this in the following articles.





Previous articles:





  1. NES programming





  2. Reading the controller








All Articles