Conference speech about nesdev, I need your help reviewing it

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
User avatar
RJM
Posts: 55
Joined: Mon Jul 27, 2020 11:56 am
Location: Rzeszów, Poland

Conference speech about nesdev, I need your help reviewing it

Post by RJM »

Hi All!

I've recently submitted a speech to the incoming https://digitaldragons.pl/ conference about making games for NES in 2022.
Just yesterday got an email, that they accepted it.
This is one of the biggest game dev events in my country, where people from companies such as Activision, CD-Projekt, or EA meet.
I'm not even in the same industry, so obviously, a little bit anxious and would like to do my best to entertain them and teach them something interesting.

The purpose of my speech is to encourage new people to join the community and show them how to start, set up the local environment, pick the right tools, and so on. I'm mostly targeting software developers here, but I have bits about graphics and audio too.

I've prepared a presentation: https://docs.google.com/presentation/d/ ... sp=sharing and I'm reviewing it to check if I got everything right. Would really love to have the second pair of eyes - I've been doing NES dev for only 2 years now.

There is a chapter where I talk about limitations and how important is to keep NMI short. My slide is based on https://www.nesdev.org/wiki/Cycle_refer ... cle_counts. Wiki says that rendering frame on NTSC takes 29780.5 cycles and NMI to start of rendering is 2273 1⁄3. I do not see the definition of a frame, but I'm assuming NMI time is not counted into frame time here. Can you confirm it?

Thanks, Roman
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Conference speech about nesdev, I need your help reviewing it

Post by Dwedit »

The numbers:

262 total scanlines
341 PPU dots per scanline
3 PPU dots per 1 CPU cycle

1 prerender scanline
240 visible scanlines
1 postrender scanline (waste of perfectly good vblank time)
NMI, 20 scanlines of vblank time after receiving the non-maskable interrupt

20 * 341 / 3 = 2273.33, so that number is perfect.

-----

While it is Vertical Blanking Time that is signaled from receiving a Non-Maskable Interrupt (NMI), and it is the time to safely draw onto the screen, I'm not sure if calling it "NMI time" is the best choice of phrasing it. But I'm sure that is widely used among NES developers.

Meanwhile, "Updating the Sound Engine" and "restoring all registers from the stack" are not required to happen inside of vblank time. Updating the sound engine is done because the beginning of the frame can be a convenient time to run the sound engine (which needs to be run once a frame). Restoring all registers from the stack is part of how you leave the NMI Handler.
Maybe shade the background for those last two lines slightly darker or something? Those are more "whenever" tasks than "do this in VBLANK or else" tasks.
I'd also move "Change scrolling" to be after "update palettes" and "update background", since those tasks trash scrolling values.

Do we need to note that it's a 6502 with decimal mode removed? Since other 6502 systems have decimal mode available, some games for those systems will use Decimal mode a lot. Dragster on Atari 2600 is one such game.

"56 instructions" is only correct if you're talking about instructions with unique names. There are 151 official 6502 instructions.
Last edited by Dwedit on Sat Apr 02, 2022 9:28 am, edited 1 time in total.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
RJM
Posts: 55
Joined: Mon Jul 27, 2020 11:56 am
Location: Rzeszów, Poland

Re: Conference speech about nesdev, I need your help reviewing it

Post by RJM »

Dwedit wrote: Sat Apr 02, 2022 9:05 am The numbers:

262 total scanlines
341 PPU dots per scanline
3 PPU dots per 1 CPU cycle

1 prerender scanline
240 visible scanlines
1 postrender scanline (waste of perfectly good vblank time)
NMI, 20 scanlines of vblank time after receiving the non-maskable interrupt

20 * 341 / 3 = 2273.33, so that number is perfect.

-----

While it is Vertical Blanking Time that is signaled from receiving a Non-Maskable Interrupt (NMI), and it is the time to safely draw onto the screen, I'm not sure if calling it "NMI time" is the best choice of phrasing it. But I'm sure that is widely used among NES developers.
Thanks for confirming it Dwedit!
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Conference speech about nesdev, I need your help reviewing it

Post by Dwedit »

(note that my previous post was edited)

"Lack of Writable memory in console" is ridiculous, that's just the wrong word there.
It should be 'non-volatile', 'persistent', or 'permanent' storage instead, as the internal memory is quite writable.

And the "No negative numbers" thing is just not correct at all.
It's an issue between representation and interpretation.
They are represented as 8-bit numbers.
They can be interpreted as:
Hex 00 to FF
Unsigned 0 to 255
Twos-compliment signed -128 to 127
The representation of the number doesn't change, just how it is interpreted.

The CPU does have a way to quickly tell you if the most significant bit of a number is set, and it's called the "negative" flag.
It also has a way to tell you if a math operation caused the sign of a number to change in a way that indicates that the math overflowed, via the "overflow" flag.
So I'd say then that the 6502 does have hardware features that assist with negative numbers.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Conference speech about nesdev, I need your help reviewing it

Post by tokumaru »

The general mixup between vblank and NMI is what's standing out the most to me... Here's a quick summary that might help:

vblank - Period after the visible picture, lasting 2273 1/3 CPU cycles, during which the PPU does not access the video memory (unless instructed to by the CPU).

NMI - Interrupt that fires when vblank starts, so the program knows when it's safe to update the video. It's also useful for timing, since it fires at the constant rate of approximately 60Hz.

NMI handler - piece of code executed when the NMI fires. This will normally execute tasks that must happen during vblank (e.g. sprite, background and scroll updates), and then other tasks that need to happen every frame (e.g. audio updates, controller reading).

While the vertical blank lasts for a fixed amount of time, there's nothing dictating how long the NMI handler has to run. It has only 2273 1/3 CPU cycles to do PPU-related tasks, but after that it can keep going and carry out other tasks (audio, etc.) without problems. Some games even run the game logic itself in the NMI handler (e.g. SMB).

BTW, the 29780.5 figure DOES include the 2273 1/3 cycles of vblank. 29780.5 cycles is the time taken by an entire frame, all 262 scanlines, and 20 of those correspond to the vblank period.
User avatar
RJM
Posts: 55
Joined: Mon Jul 27, 2020 11:56 am
Location: Rzeszów, Poland

Re: Conference speech about nesdev, I need your help reviewing it

Post by RJM »

@Dwedit: thanks a lot for the detailed review! I've applied all your comments, except decimal mode. I think it might be a little bit too detailed. Frankly, they are giving me 45min for this speech. I'm a little bit afraid I won't be able to show it all.

@tokumaru I agree that in the presentation NMI handler and vblank are a bit mixed up together. I've changed some captions on my slides. I feel I do understand these concepts but I'm failing to clearly put them on the slides. I'll think how to better organize it. Thanks!
User avatar
RJM
Posts: 55
Joined: Mon Jul 27, 2020 11:56 am
Location: Rzeszów, Poland

Re: Conference speech about nesdev, I need your help reviewing it

Post by RJM »

BTW I've added you guys to the reviewers section, hope you're fine with that :)
Post Reply