Thinking about making an NES Z-Machine

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

Moderator: Moderators

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

Re: Thinking about making an NES Z-Machine

Post by tokumaru » Mon Feb 04, 2019 10:36 pm

halkun wrote:For fun I was wondering if I could do some "race the beam" kind of things with the NES, but that is going to require real hardware. On the Atari 2600 you could count cycles and alter the scan line while it's drawing on the phosphor. Looks like on the NES you are not even allowed to monkey with the beam during HSYNC.
Pixel-level synchronization on the NES is notoriously tricky, and even in the best possible scenario you'll still get a couple pixels of jitter...
I was contemplating if you could update the nametables during HSYNC and have it spit out a different pattern for that line. If you can update the nameable on each line, you can have a full screen bitmap. Like I said, I wouldn't even know how to detect when the beam is in HSYNC so I can play with the PPU while it's off.
To access VRAM during display time, you need to turn rendering off, and one side effect of that is that it compromises the sprites for one scanline. Also, the hblank period is so short, that there there's barely enough time to update a single byte in VRAM, since you need to turn rendering off, set the VRAM address, write the data, reset the scroll and turn rendering back on.

There are other kinds of raster effects that are much easier and safer to perform though, such as scroll changes, pattern swaps and color emphasis/grayscale.

A full screen bitmap can be achieved fairly easily in 1bpp (i.e. 2-color) with some palette trickery and a pattern table swap halfway down the screen. A regular 2bpp full screen bitmap will require more CHR memory, either RAM or ROM.

User avatar
koitsu
Posts: 4216
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Thinking about making an NES Z-Machine

Post by koitsu » Mon Feb 04, 2019 10:54 pm

You don't have much CPU time in HBlank. 6502 instructions average ~3 cycles each (consider: a ZP load followed by a PPU write takes 7 cycles). Switching CHR-ROM banks is certainly possible, or doing a couple PPU register tweaks, but that's about it. Usually this is only something considered if there are truly justified needs for it.

If your goal is to do text-based adventures, HBlank is the least of your concerns/worries right now -- not to tell you how to run your project or anything... HBlank effects are considered highly advanced material; I don't think many here on the forum have spent much time doing it either. On the flip side, demos like this are possible, but consider that entire piece of work is precisely-timed (read: cycle counting) and IIRC, really doesn't leave much CPU time for doing other things within reason.

I think as you get more and more into this project of yours, you're going to realise that understanding the design/model and specifications (plus implementation/usage model) of the NES is going to strongly dictate what you can accomplish. Don't forget: people like myself didn't enjoy Zork because of fancy graphics or effects.

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

Re: Thinking about making an NES Z-Machine

Post by tokumaru » Mon Feb 04, 2019 11:07 pm

tokumaru wrote:There are other kinds of raster effects that are much easier and safer to perform though, such as scroll changes, pattern swaps and color emphasis/grayscale.
Here are a few examples of cool effects on the NES that are possible with combinations of the techniques I mentioned before:

https://youtu.be/BegOGJFePv4?t=0 (title screen in F-FF)
https://youtu.be/XVbZAPBPwZY?t=998 (3D floor in Cosmic Epsilon)
https://youtu.be/dWHPNnrTmKs?t=2185 (overlapping background layers in Bucky O'Hare)
https://youtu.be/43pmwBwBoHs?t=32 (semi-transparent water in Noah's Ark)
https://youtu.be/_GSfLqJUcOM?t=60 (multiple parallax layers with overlap in Sword Master)
https://youtu.be/bukusPiWTmU?t=438 (perspective floor in Battletoads & Double Dragon)
https://youtu.be/V6ngD3ZC1z8?t=594 (roads with hills in Rad Racer)
https://youtu.be/nfY79-3AdGY?t=152 (psychedelic background in Recca)

Post Reply