How do I set up my development environment?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How do I set up my development environment?

Post by tokumaru »

Deemar wrote:- Why does the nametable viewer show the screen 4 times?
The NES can address 4 name tables, arranged in a 2x2 grid, and cartridges are able to map memory differently in this space. Having more than 1 screen worth of background graphics is mostly useful for scrolling (which Dr. Mario doesn't do, so it ended up using single screen mirroring, as indicated at the bottom of that screen), but it could serve other purposes too. The NES doesn't even have enough built-in memory for mapping unique screens to all 4 slots, so any game using more than 2 unique name tables at a time needs extra memory inside the cartridge. Few games do this, though, and from a programming point of view, it's hardly necessary.

For some good name table viewing fun, fire up games that scroll in all directions. It's always fun to see how new background data is constantly loaded, overwriting the parts of the level that you leave behind as you play.
Why is everything in the PPU viewer a shade of blue?
Because the first palette defined by the game you're playing is mostly blue. This is the pattern table, where the raw tiles are stored. NES tiles are only 4 colors, and the emulator will only know which palette each tile will use when they're used in the name tables (the attribute tables are used for selecting background palettes), or when sprites use them. The obvious solution is to allow the user to cycle through all the palettes (with a right button click? I'm not sure) if you really need to see the correct colors for specific tiles.

Some emulators try to be smart and remember what palettes are used for which tiles and reflect that in the pattern viewer, but that doesn't always work because the same tile can be rendered using different palettes (I'm sure you noticed recolored enemies or blocks when playing NES games) and some tiles are never used at all by the game (would these be black?).

EDIT: As for the usefulness of each debug screen, you'll surely find yourself using some of them more frequently than others. The RAM search for example is mostly used for cheating. You can, for example, get hit and search for every byte that its value decreased since the last check. Do that a couple of times and you're likely to find the variable that specifies how much health you have, so you can freeze it or create a Game Genie code to patch the code that manipulates this address. Not useful for homebrewing, since you know where all your variables are.

The PPU debuggers are the most useful IMO, along with the 6502 debugger. By watching the pattern and name tables you can easily see if all the graphics are being put where they should be, and the 6502 debugger is insanely useful to see if your logic is doing what it's supposed to. There you can step through the code instruction by instruction and see how they affect all the CPU registers.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How do I set up my development environment?

Post by rainwarrior »

tepples wrote:That and it's best to test play control feel on the hardware because the latency from input to video and audio will often be substantially less on an NES + CRT SDTV than on a PC-based emulator. PC audio is mostly optimized for noninteractive things, such as music and movie playback and notification sounds.
Audio latency, absolutely yes, but video latency definitely not. TVs on average have a lot more latency than PC video hardware.

Edit: mirsead, didn't catch the "CRT SDTV" part. I was referring to typical modern TVs.
Last edited by rainwarrior on Thu Jul 02, 2015 1:12 pm, edited 2 times in total.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: How do I set up my development environment?

Post by lidnariq »

CRT-based SDTVs have almost no latency. At most a scanline or two.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How do I set up my development environment?

Post by tepples »

lidnariq wrote:CRT-based SDTVs have almost no latency. At most a scanline or two.
Operation Wolf, Zap Ruder, and every Super Scope game depend on this lack of CRT latency.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How do I set up my development environment?

Post by rainwarrior »

lidnariq wrote:CRT-based SDTVs have almost no latency. At most a scanline or two.
Oop, sorry, I misread that part. (I think "SDTV" confused me. I'm not used to that term at all.)
Deemar
Posts: 15
Joined: Thu Jun 25, 2015 9:16 pm
Location: Calgary, Alberta

Re: How do I set up my development environment?

Post by Deemar »

I'm almost there. I compiled the smbdis.asm (disassembled Super Mario Bros.) with ASM6 and it created a .bin file. I read on the forums that I need to add a 16 bit header file to this file, how do I do that? I tried reading how that was done and it was making my head spin. Is it the same header file used every time for every game? I don't understand what that is nor how I make it.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How do I set up my development environment?

Post by tepples »

NES header tells the emulator what hardware is on the game's circuit board.

For SMB1, open a hex editor and enter 4E 45 53 1A 02 01 01 00 then eight more 00 bytes. This tells the emulator that a 256 kbit (02 * 16K = 32768 bytes) PRG ROM and a 64 kbit (01 * 8K = 8192 bytes) CHR ROM are on the board, with no mapper chips, and the board is configured to arrange the nametables (background maps) side-by-side instead of top and bottom. Then combine it with the binary files containing PRG ROM and CHR ROM data:

Code: Select all

cat header.bin game.prg game.chr > game.nes
Or if your assembler is configured to generate a 40960 byte file containing both PRG ROM and CHR ROM, possibly through .incbin statements:

Code: Select all

cat header.bin game.bin > game.nes
In any case, the final ROM file should be 40976 bytes in size.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How do I set up my development environment?

Post by tokumaru »

Deemar wrote:I compiled the smbdis.asm (disassembled Super Mario Bros.) with ASM6 and it created a .bin file. I read on the forums that I need to add a 16 bit header file to this file
That depends. File extensions are meaningless, they're just text. How big is the .bin file? A headerless SMB would be 32768 + 8192 = 40960 bytes long. If that's what you got, then yeah, you need to add a header. If the file is 40976 bytes though, it's probably a ready to use ROM, just rename to .nes.
how do I do that?
A header is just some information that helps the emulator know how to interpret the raw ROM data. It specifies things like the size of the chips, the mapper, mirroring... mostly detail about the physical cartridge that would be used to run the game.

The wiki has a page about the NES header (I won't look it up because I'm on my phone), and there you can see what each byte and bit means. You can use an hex editor to create a 16-byte file and then merge that with the ROM, but I find it much more convenient to define the header in the source code itself, in the form of .db statements. Search for my ASM6 templates here in the forums to see how that can be done.
Is it the same header file used every time for every game?
For games that use the same cartridge configuration, yes.

If you just want a header for SMB, you can open a working ROM in an hex editor and copy the first 16 bytes.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How do I set up my development environment?

Post by rainwarrior »

The header is explained here:
http://wiki.nesdev.com/w/index.php/INES
Deemar
Posts: 15
Joined: Thu Jun 25, 2015 9:16 pm
Location: Calgary, Alberta

Re: How do I set up my development environment?

Post by Deemar »

I copied the following into header.bin:

Code: Select all

4E 45 53 1A 02 01 01 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00
I then ran:

Code: Select all

cat header.bin smbdis.bin > smbdis.nes
Then when I try and run the .nes file in FCEUX I just get a black screen. What did I do wrong?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How do I set up my development environment?

Post by rainwarrior »

Why is your header 72 bytes long, and not 16?
Deemar
Posts: 15
Joined: Thu Jun 25, 2015 9:16 pm
Location: Calgary, Alberta

Re: How do I set up my development environment?

Post by Deemar »

rainwarrior wrote:Why is your header 72 bytes long, and not 16?
Oops, I misunderstood with the 8 bits. I just made it 16 bit:

Code: Select all

4E 45 53 1A 02 01 01 00 00 00 00 00 00 00 00 00
And I get the same result.
mikaelmoizt
Posts: 120
Joined: Sat Apr 12, 2014 12:11 pm
Location: Gothenburg, Sweden

Re: How do I set up my development environment?

Post by mikaelmoizt »

Deemar wrote:
rainwarrior wrote:Why is your header 72 bytes long, and not 16?
Oops, I misunderstood with the 8 bits. I just made it 16 bit:

Code: Select all

4E 45 53 1A 02 01 01 00 00 00 00 00 00 00 00 00
And I get the same result.
16 bytes. I could tell you exactly how to get smbdis.asm working if you use asm6, but you don't learn much from that and should be able to figure it out by yourself.

I could give you a hint.. the header you have there can be inserted like this

Code: Select all

hex 4E 45 53 1A 02 01 01 00 00 00 00 00 00 00 00 00
edit: typo
Last edited by mikaelmoizt on Sat Jul 11, 2015 11:11 pm, edited 1 time in total.
I´ve got %01100011 problems but the BITs aint one.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: How do I set up my development environment?

Post by dougeff »

Hmm, a blank screen. You included a header. Did you also include the CHR-ROM (graphics) at the end of the file? It can be cut-pasted in with a hex editor.

Or, copy the original CHR-ROM ($2000 bytes at the end of the original ROM), and save it as smb.bin file - then add the words...

.incbin "smb.bin" at the end of the file. Re-assemble.

(Edit) If that doesn't work, try opening both files in a hex editor, and seeing where they differ. Are they both the same filesize?
nesdoug.com -- blog/tutorial on programming for the NES
Deemar
Posts: 15
Joined: Thu Jun 25, 2015 9:16 pm
Location: Calgary, Alberta

Re: How do I set up my development environment?

Post by Deemar »

I got it, looks like it was a combination of things. I added the hex header to the top of the file, then added 'incbin "mario.chr"' statement to the bottom of the file since I already had the original Super Mario Bros. CHR file from doing earlier tutorials with it. Then I wrapped it up again and it still didn't work, at least it didn't appear to until I started hitting buttons and I could hear the game start up. It turns out my one vertical monitor was giving me a black screen in FCEUX but when I moved the program to my other horizontal monitor, it worked fine. Both monitors are identical except for their orientation so I guess running FCEUX in WINE on a vertical monitor doesn't work.

After I moved it the game worked fine, it even showed the changes I made to the CHR file. Now I'm going to modify the sprites and make my own character! Thanks!
Post Reply