Questions about NES programming and architecture

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
Secamline
Posts: 39
Joined: Sat Aug 15, 2020 4:25 pm

Re: Questions about NES programming and architecture

Post by Secamline » Thu Sep 03, 2020 9:55 am

That means there are eight internal counters in the PPU? This would explain why there are 8 sprites per scanline at most.

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

Re: Questions about NES programming and architecture

Post by tokumaru » Thu Sep 03, 2020 10:39 am

Yes, each additional sprite increases the cost of the hardware, since the chip gets more complex. Apparently there is enough time in the rendering pipeline to render more sprites, but doing that probably would've meant increasing the cost of the PPU.

User avatar
Secamline
Posts: 39
Joined: Sat Aug 15, 2020 4:25 pm

Re: Questions about NES programming and architecture

Post by Secamline » Thu Sep 03, 2020 5:00 pm

I'm glad to know exactly why the NES has such limitations.
Which reminds me of the lack of a decimal mode on the console's processor. From what I've read, this feature was removed to avoid getting sued by MOS or something. I've always seen NES homebrew games use the instruction CLD at the beginning of their code. Is it mandatory to disable a mode that doesn't even exist on the Ricoh 2A03? Is their actually a Decimal nibble in the 2A03's processor status register?

lidnariq
Posts: 9659
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Questions about NES programming and architecture

Post by lidnariq » Thu Sep 03, 2020 5:16 pm

Secamline wrote:
Thu Sep 03, 2020 5:00 pm
decimal mode [...] was removed to avoid getting sued by MOS or something.
At the time of the NES, silicon received no protection. If you had copies of the masks used to make a device, you could make the device: legally the resulting silicon wasn't protected.

So MOS got a patent on how they implemented decimal mode. By disabling decimal mode, no licensing needed to be paid.
I've always seen NES homebrew games use the instruction CLD at the beginning of their code. Is it mandatory to disable a mode that doesn't even exist on the Ricoh 2A03?
There are famiclones that left the decimal mode functional. While this was almost never used, the superstition did make these games upwardly compatible with later 3rd-party NES copies.
Is there actually a Decimal bit in the 2A03's processor status register?
Yes, it exists. see:
http://visual6502.org/wiki/index.php?ti ... 27_RP2A03G

tepples
Posts: 22049
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Questions about NES programming and architecture

Post by tepples » Fri Sep 04, 2020 3:02 am

Secamline wrote:
Thu Sep 03, 2020 5:00 pm
I've always seen NES homebrew games use the instruction CLD at the beginning of their code. Is it mandatory to disable a mode that doesn't even exist on the Ricoh 2A03?
Presumably devs used debugging tools designed for an authentic MOS 6502, which could be confused by sed or by the unspecified state of the decimal bit of P at power on.

Pokun
Posts: 1511
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Questions about NES programming and architecture

Post by Pokun » Fri Sep 04, 2020 5:54 am

So the decimal flag exists and can be set or cleared, but it has no effect on the decimal mode circuit which is always disabled due to the 5 removed transistors. There not much reason to skip a CLD at the start of your homebrew though.

In interviews with Nintendo it sounded like Ricoh convinced Nintendo to use a 6502, partly because they had a license for it. I wonder if they by "license" they meant that they had the masks to produce it with?

Nintendo's ultimate decision to use a 6502 instead of something like a Z80 was supposedly because the 6502 was a mostly unknown processor in Japan, which would decrease the chance for third-party software (something Nintendo initially tried to avoid). The programmers at Nintendo wasn't very happy with this decision. It wasn't that unknown though, since the Commodore PET was very popular in Japan at the time (and programmers like the late Iwata learned it that way).

tepples
Posts: 22049
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Questions about NES programming and architecture

Post by tepples » Fri Sep 04, 2020 9:01 am

That and 6502 (well, 6507) was the processor associated with the crash of 1983-1984.

User avatar
Secamline
Posts: 39
Joined: Sat Aug 15, 2020 4:25 pm

Re: Questions about NES programming and architecture

Post by Secamline » Fri Sep 04, 2020 5:14 pm

tepples wrote:
Fri Sep 04, 2020 3:02 am
Presumably devs used debugging tools designed for an authentic MOS 6502, which could be confused by sed or by the unspecified state of the decimal bit of P at power on.
Do first party games explicitly clear decimal mode? Afaik Nintendo directly tested their code on the Famicom since the computers they used to make their games didn't run on a 6502.

User avatar
Bregalad
Posts: 7951
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Questions about NES programming and architecture

Post by Bregalad » Sat Sep 05, 2020 3:02 am

Secamline wrote:
Fri Sep 04, 2020 5:14 pm
Do first party games explicitly clear decimal mode?
Yes.

IMO there's no point in overthinking why most games uses CLD when starting up. They just do.
Interestingly enough, the (very incarucate) emulator REW actually simulates the decimal mode if enabled ! This is funny.
Useless, lumbering half-wits don't scare us.

User avatar
Secamline
Posts: 39
Joined: Sat Aug 15, 2020 4:25 pm

Re: Questions about NES programming and architecture

Post by Secamline » Sat Sep 05, 2020 8:13 am

Bregalad wrote:
Sat Sep 05, 2020 3:02 am
IMO there's no point in overthinking why most games uses CLD when starting up.
As you can see in most of my replies, I tend to overthink everything regarding this machine! That being, I still find it amusing in a good way that programmers disable a mode that isn't featured on the CPU, as if they were paranoid or something.

User avatar
Dwedit
Posts: 4351
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Questions about NES programming and architecture

Post by Dwedit » Sat Sep 05, 2020 10:41 am

Not only do games clear decimal mode at bootup, they often disable interrupts too. Turns out that the initial power-on state is to have interrupts disabled, so disabling interrupts doesn't do much. May be useful though if the game wants to jump back to the power-on code to reset the game.

More information regarding removed decimal mode (with images of the cut transitors!): http://visual6502.org/wiki/index.php?ti ... ecimalMode (look near the bottom of the page for images)
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
Secamline
Posts: 39
Joined: Sat Aug 15, 2020 4:25 pm

Re: Questions about NES programming and architecture

Post by Secamline » Sun Sep 06, 2020 1:00 am

While being quite acustomed to 6502 programming, I've never actually used the decimal, do you know what it was used for on other machines?
Same goes for the BRK instruction, from what I understand it's mainly used for debugging. This instruction seems rather obscure to me since it's actually a 1 byte instruction treated as a 2 byte instruction.

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Questions about NES programming and architecture

Post by Oziphantom » Sun Sep 06, 2020 2:24 am

Dwedit wrote:
Sat Sep 05, 2020 10:41 am
Not only do games clear decimal mode at bootup, they often disable interrupts too. Turns out that the initial power-on state is to have interrupts disabled, so disabling interrupts doesn't do much. May be useful though if the game wants to jump back to the power-on code to reset the game.

More information regarding removed decimal mode (with images of the cut transitors!): http://visual6502.org/wiki/index.php?ti ... ecimalMode (look near the bottom of the page for images)
6502s are "dodgy", its more "mostly" clears at boot up. There have been some fun bugs where D flag isn't always cleared at boot see https://c65gs.blogspot.com/2016/08/reve ... -flag.html I would always set it to be sure sure.

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Questions about NES programming and architecture

Post by Oziphantom » Sun Sep 06, 2020 2:25 am

Secamline wrote:
Sun Sep 06, 2020 1:00 am
While being quite acustomed to 6502 programming, I've never actually used the decimal, do you know what it was used for on other machines?
Same goes for the BRK instruction, from what I understand it's mainly used for debugging. This instruction seems rather obscure to me since it's actually a 1 byte instruction treated as a 2 byte instruction.
Its quite handy for counting scores saves all the cmp 10 and fix up. The CIA TODs also store things in BCD format, so it can be handy for working with them. If I was making VisiCalc, BCD mode would be my go to for the money mode. Saves memory and clocks. It was a big deal to business software.

User avatar
Dwedit
Posts: 4351
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Questions about NES programming and architecture

Post by Dwedit » Sun Sep 06, 2020 8:07 am

Atari 2600 games had Decimal Mode available, so they used it. If you look at the disassembly of Dragster, it uses Decimal Mode for all the game's math.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Post Reply