PowerPak Namco 163 fixes: CHR nametables, sample length, internal RAM readback, iNES 2 CHR-RAM

Discuss hardware-related topics, such as development cartridges, CopyNES, PowerPak, EPROMs, or whatever.

Moderator: Moderators

Post Reply
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

PowerPak Namco 163 fixes: CHR nametables, sample length, internal RAM readback, iNES 2 CHR-RAM

Post by rainwarrior »

**

This mapper was improved later in the thread!

See: finished version below.


** Original Post Below **

Was looking at this one because Quantam was asking if it could support large CHR-RAM. The CHR-RAM ended up being a tinychange to the verilog, now that I have a loader stub that can read the iNES 2 header. While I was testing this I noticed Rolling Thunder's bass sounded wrong... and it turned out the N163 sound was using only 3 bits of sample length (instead of the fully 6), as this had been incorrectly documented and implemented by emulators that way for a long time.

Sadly, I couldn't just change 3 into 6... this implementation maxes out the FPGA at only 4 bits. :S However, that's just enough for Rolling Thunder bass to sound better. :) Possibly it can be rewritten in a "tinier" way, but for now this is a worthwhile improvement at least.
loopy_n163_fix2.zip
(34.7 KiB) Downloaded 28 times
Last edited by rainwarrior on Sun Dec 04, 2022 12:56 pm, edited 3 times in total.
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

A harder problem to solve with this mapper is readable mapper-internal RAM, and then also battery saving its 128 bytes. According to this thread the relevant games are:
  • Battle Fleet
  • Famista '90
  • Kaijuu Monogatari
  • Mindseeker
Mindseeker boots with messed up graphics. The others seem playable, but I haven't tried getting far enough for a save to be relevant.

Supporting saves for these might be hard. For it to survive reset, it should have to go in WRAM, but since writes to the internal RAM are via a single serial port address, I don't think there's an opportunity to mirror them.

The most sensible thing to do is probably patch all 4 games to use WRAM instead of internal RAM, since these games don't have WRAM. (The whole reason to use the mapper RAM was to avoid the WRAM cost.)
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

Looks like it doesn't support the CHR-ROM as Nametable feature on the N163 properly, as they are used on Mindseeker's opening screens extensively. Not sure if any other N163 games used this feature? Anyway, that tells me what needs fixing for that.

Otherwise the saving part I think needs to be addressed with patching because I don't have any idea for how to support that otherwise. A cursory examination seems like the patching will be simple, though, as the games seem to mostly just copy the internal RAM data to and from NES RAM.
NewRisingSun
Posts: 1510
Joined: Thu May 19, 2005 11:30 am

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by NewRisingSun »

ROM nametables are used by Final Lap and Mappy Kids, in addition to Mindseeker according to rainwarrior's report.
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

My report? Did I do some research on this years ago and forget?
NewRisingSun
Posts: 1510
Joined: Thu May 19, 2005 11:30 am

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by NewRisingSun »

"as they are used on Mindseeker's opening screens extensively"
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

Oh, lol. (Thanks for pointing out the other two though.)
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

Okay, this fixes the graphics in Mindseeker, and presumably the other games NewRisingSun listed as well.
loopy_n163_fix3.zip
(34.86 KiB) Downloaded 25 times
The old CHR code was using the $E000 sound disable register (incorrectly called "mirror") in the CHR selection in a weird way. I didn't quite sort out what its intended logic was, but I rewrote it and I haven't seen any graphical problems in any of the N163 games. (Played all of them for a few minutes.)

However, I discovered that Namco Classic II can't be played, and I believe this is because of not being able to read back the internal sound RAM. I'll explain that below, but first the CHR code.

New CHR control:

Code: Select all

    //CHR control
    reg [17:10] chrbank;
    always@* begin
        case(chrain[13:10])
            // ... chrbank = chrX
        endcase
        // chrbank goes straight to CHR address (and ciram as ramchraout[10]))
        ramchraout[17:10] = chrbank & {cfg_chrmask[17:12],2'b11};
        // bank>$E0 uses nametable if E800 (chr_en) or PPU>$2000 (ppu a13)
        // chr_en has two bits for $0000 and $1000 regions (prg a12)
        ciram_ce = (chrbank[17:15] == 3'b111) & (~chr_en[chrain[12]] | chrain[13]);
        chrram_oe = neschr_rd & ~ciram_ce;
        chrram_we = neschr_wr & ~ciram_ce & cfg_chrram;
    end
Old CHR control:

Code: Select all

    // CHR control
    reg chrram;
    reg [17:10] chrbank;
    always@* begin
        case(chrain[13:10])
            // ... chrbank = chrX
        endcase
        chrram=(~(chrain[12]?chr_en[1]:chr_en[0]))&(&chrbank[17:15]);   //ram/rom select
        if(!chrain[13]) begin
            ciram_ce=0;
            chrram_oe=neschr_rd;
            chrram_we=neschr_wr & chrram;
            ramchraout[10]=chrbank[10];
        end else begin
            ciram_ce=&chrbank[17:15] | mirror;
            chrram_oe=~ciram_ce & neschr_rd;
            chrram_we=~ciram_ce & neschr_wr & chrram;
            ramchraout[10]=mirror?chrain[10]:chrbank[10];
        end
        ramchraout[11]=chrbank[11];
        ramchraout[17:12]=chrbank[17:12] & cfg_chrmask[17:12];
        ramchraout[18]=chrram;
    end
So, reading back the sound RAM... it seems that none of the battery-backed non-WRAM games actually need this to run. They only need it to save your game. However, Namco Classic II seems to use it as a little bit of extra RAM space? It hangs when trying to select a caddy. :(

However, I'm running up against a wall here because the FPGA is maxed out. I tried to add a readback, but it always went over. I tried to add the extra sound bits, but it always went over. I tried a bunch of different ways to reorganize things (e.g. there's a lot of stuff in always/case/reg constructions that can reduce to wire/array, but none of the things I tried actually succeeded in lowering the internal complexity. :S I guess the synthesizer just ends up putting them together the same way? I guess it's pretty good at figuring out sequential dependencies.

So, known problems, in decreasing severity:
  • Sound RAM readback doesn't work. 4 games need this to save but are otherwise playable, Namco Classic II needs it to run.
  • Sound RAM can't be recovered after reset for save. An intractable problem at this level, I think.
  • Sample length register is 4 instead of 6 bits. I don't think any existing games use lengths above 64, so not a real problem.
  • Audio mute isn't connected. I think games that write the sound RAM avoid the sound register area, so another non-problem.
All of the readback problems can be addressed with patches to use WRAM instead though. (Namco Classic II included.)

Actually, since the Game Genie stuff can be disabled, I guess I should check on that... 430/432 slices drops to... 299/432. Game genie takes 30% of this thing?? Wow. Well, maybe another day I'll try it with fewer game genie codes. :P
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

If anyone needs a program to test N163 sound RAM readback, I had to make one to test it myself:
n163_soundram.zip
(5.38 KiB) Downloaded 47 times
User avatar
rainwarrior
Posts: 8733
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PowerPak Namco 163 mapper: CHR-RAM and sample length fix

Post by rainwarrior »

Alright this should be it. Sound RAM readback works, and Namco Classic II is now playable.
loopy_n163_fix4.zip
(34.55 KiB) Downloaded 49 times
So, this is what's improved:
  • CHR-ROM as nametables now works properly (fixes Mindseeker, and probably Final Lap, Mappy Kids).
  • Sample length now uses all 6 bits (fixes Rolling Thunder bassline).
  • Internal sound-RAM readback (fixes Namco Classic II, and supports temporary saving in some other games).
  • iNES 2 large CHR-RAM is now available. (supports a project Quantam was working on)
  • Sound mute register via $E000. (no real consequence because games without sound avoid writing the channel control area)
This is the what remains compromised:
  • 4 games that use internal sound RAM as save will have to be patched to use WRAM instead in order to have a non-volatile save, but are otherwise playable by keeping your NES on. (Battle Fleet, Famista '90, Kaijuu Monogatari, Mindseeker)
  • The 5th Game Genie code will not function.
Post Reply