Closed coopstools closed 12 months ago
The instructions of how to get this running locally are for a mac, but I believe both the assembler and the emulator work on *nix and PC. Of course the download instructions would be different, but a quick google search should show how to get it working.
Let me know if there are any specific screenshots you would like me to take, or any parts of the code you would like me to highlight.
For background on defining the sprites, each pixel in a sprite, which is set as an 8 pixel by 8 pixel element, is defined by two bits, which allow it to select from the 3 colors in a fixed pallete defined elsewhere. Confusingly enough, the MSB and LSB are stored in two different locations.
.byte $f8, $cc, $c6, $c6, $c6, $cc, $f8, $00 <- MSB
.byte $00, $30, $20, $21, $21, $23, $06, $7c <- LSB
Each hex value then represents a row in the sprite. Converting the hexes to binary let's you see the image slightly (if you squint hard enough).
$f8 -> 11111000 -> 11111___
$cc -> 11001100 -> 11__11__
$c6 -> 11000110 -> 11___11_
$c6 -> 11000110 -> 11___11_
$c6 -> 11000110 -> 11___11_
$cc -> 11001100 -> 11__11__
$f8 -> 11111000 -> 11111___
$00 -> 00000000 -> ________
Then, we can take the LSB and do the same.
$00 -> 00000000
$30 -> 00110000
$20 -> 00100000
$21 -> 00100001
$21 -> 00100001
$23 -> 00100011
$06 -> 00000110
$7c -> 01111100
Then, to overlay them, I'll use 'O' to represent the MSB, '.' for the LSB, and leave a space for the zero value (represented as transparent in the PPU).
OOOOO
OO..OO
OO. OO
OO. OO.
OO. OO.
OO. OO..
OOOOO..
.....
While I can't quite count emulators, I did include your work on the "Almost There," thank you! https://github.com/Nakazoto/Hellorld/wiki/Almost-There#nes-nintendo-entertainment-system
My code can be found here (please note this is on the hellorld branch). There is a .mov file included that shows it being run on an fceux NES emulator.
Now, the NES has no concept of ASCII or any letters. So, to display a character, you first need to program in the letters. Each character is a sprite, and below is an excerpt from the creation of those sprites.
The sprites and their location are then stored in rom. They are defined by their Y position, the character they display, the color pallet they will use (a sprite can only be 3 colors), and their X position.
In the startup code, the sprite are pulled out of ROM and into memory ($0200 through $02ff are the available addresses for usable memory at run time.)
And finally, there is an interrupt setup for each screen refresh that runs the code to pull the sprite info out of memory and send it to the graphics chip (PPU) through the register at $2004:
This all comes together to produce the following image:
The rest of the code is either associated with startup, or with moving the sprites around the screen. I know the true hellorld would exclude the movement, but it's an NES. How could I not include some interactive element?