FDS $4023 Testing

Discuss emulation of the Nintendo Entertainment System and Famicom.
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

FDS $4023 Testing

Post by TakuikaNinja »

Or more bluntly, "nobody checked what 'disabling FDS registers' via $4023 actually meant until now".
TakuikaNinja wrote: Tue Apr 08, 2025 4:39 pm (I swear I posted here last night... whatever)

So it turns out that the read-only registers are mapped and functional even they're disabled via $4023. I haven't checked the sound registers yet but I would expect them to behave in the same way. This means that only the write-only registers are actually disabled in this state. I've seen some emulators map the read-only registers to open bus when "disabled", so those are incorrect.

Exhibit 1 - $4030-$4033 are still readable when $4023 = 0:
registers_disabled_but_still_readable.png


Exhibit 2 - $4032 can still recognise the disk being inserted/ejected while in this state (first/second reads = while inserted, third read = after ejection):
registers_disabled_but_eject_is_recognised.png
I finally got around to making a program to better visualise/test this behaviour. I will be making separate threads for individual FDS test programs from now on as to not clutter the FDS emulation thread with different topics.

Summary:
  • $4023 state at top of screen. %10000011 on startup/reset, bit 7 cannot be changed.
  • Hex dump of $4020-$409F below, updated in realtime so it can recognise actions such as ejecting/inserting a disk.
  • B toggles $4023.D1 (sound registers), A toggles $4023.D0 (timer IRQ & disk I/O registers).
  • Measures have been put in place to reduce the chance of PRG-RAM corruption caused by leaving $4023.D0 = 0 (DRAM refresh watchdog is disabled). However, it may be necessary to do a full power-cycle/reload should the program ever halt or otherwise fail to reset properly.
Source code: https://github.com/TakuikaNinja/FDS-4023-Test

I'll just have the program attached here. I might get a GitHub release going once I get results from other consoles/emulators. I think I need to update the mirroring test as a result of this new one, and then get back to the DRAM refresh watchdog at some point... Not to mention the tests I also want to make for the byte transfer flag and its IRQs.

Hardware recordings from my Twin Famicom will be posted here soon.
Attachments
FDS-4023-Test.zip
(5.22 KiB) Downloaded 16 times
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

I have a video recording now and will get that up on YouTube in a short moment. Here's a minor update with an adjusted palette for the hex dump - I've found that my EasyCAP doesn't handle grey-on-black very well.
Attachments
FDS-4023-Test.zip
Palette adjustment
(5.22 KiB) Downloaded 16 times
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Right, here's the recording from my Twin Famicom: https://youtu.be/rbvNSA2-kNI

Here's the list of actions taken:
  1. Initial load, $4023 = %10000011
  2. Disk eject + insert
  3. Set $4023.D0 = 0 (disk I/O registers)
  4. Disk eject + insert
  5. Toggle $4023.D1 (sound registers) a few times
  6. Press reset a few times
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Main findings so far:
  • Readable disk I/O registers ($4030-$4033) are still readable when $4023.D0 = 0.
  • $4030.D3 (nametable arrangement status) is seemingly cleared when setting $4023.D0 = 0. It stays cleared, despite setting $4023.D0 = 1 again, until reset (when $4025.D3 is newly written to?). I'll have to test this further in my mirroring test.
  • $4032 can still recognise the disk being inserted/ejected while $4023.D0 = 0.
  • Readable sound registers are still readable when $4023.D1 = 0, though a few of the mod table registers ($4093, $4095) seem to change values?
  • Wavetable RAM ($4040-$407F) seems to return an initial state (note: top 2 bits are open bus), albeit likely influenced by the active wavetable position/accumulators (judging by the reset flakiness)?
Things to further test/research:
  • Does $4030 have any other responses to setting $4023.D0 = 0?
  • Does $4033 reflect the FDS expansion port state while $4023.D0 = 0?
  • Does Wavetable RAM ($4040-$407F) have an actual initial state, or is it undefined?
  • Sound registers in general. I personally don't have a good understanding of them.
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Update on the wavetable RAM: Loading the program from power-on as early as possible (by having the FDSKey remember the disk image between power cycles) resulted in the below hexdump. On my unit, it seems to return open bus bits | $02 and doesn't change across resets.
Attachments
wavetable_ram_after_fastest_load.png
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

SCSR got back to me with some analysis of $4023 behaviour:
The written registers seem to deny writes when $4023.0 is 0, this happens because it also disables part of the clock generator. However, if you enter the test mode, you should be able to write to these registers, since the part of the clock generator that is disabled is bypassed and the other parts are directly clocked through the clk pin. The read registers use different clock signal that is not disabled. This also affects the audio registers. As far as I know, the $4023.1 bit only affects the circuit generating the audio signal.

Setting $4023.0 to 0 also seems to reset IRQ, DRAM refresh and disk I/O related counters and hold reset until 1 is written to $4023.0.

Setting $4023.0 to 0 resets the $4025 to value $06.

I haven't seen anything that would reset the wavetable RAM to specific state, so it's probably random. Most of the audio circuit is still not traced, so I can't say much about it for certain
The "hold in reset state until the bit is set again" behaviour lines up with what's observed in the program.

$4025 being reset to $06 explains why it was affecting $4030 - bit 3 (nametable arrangement) is being cleared. My program does not touch $4025 aside from letting the BIOS reset handler initialise it, which fortunately allowed this behaviour to be detected. Now I have to update my mirroring test to check for this behaviour...

Yuri213212 had made similar observations last year regarding $4023. Regarding the sound registers, they noted that clearing $4023.D1 halts the current wavetable output after a brief pop (wave accumulator & mod counter being reset?) and can be resumed simply by setting the bit again. That's likely why a few of the readable sound registers were changing when toggling the bit. (It only took over a year to catch up...)
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Update: When using a physical drive and a write-enabled disk to test the program response, it appears that pressing the eject button results in an intermediary sequence of $42 -> $46 -> $47 in $4032, i.e. the write protect flag in D2 is updated before the disk flag in D0. I can confirm this by partially pressing the button to get the $46 result. On the other hand, inserting the disk seems to yield a clean $47 -> $42 transition.

I may have to separately test the $4032 response by reading it multiple times a frame...
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Finally getting back into the register research. It appears that disabling disk registers forces $4026 = $7F | power/batter status along with disabling the external connector output.
Screenshot_2026-04-14_13-59-32.png

The drive power/battery status is always observable via $4033.D7, tested by unplugging the FDSKey before the final $4033 read in this sequence:
image.png
image.png (32.29 KiB) Viewed 307 times
Emulators can simply treat the power/battery bit as always being set.

I've been implementing these behaviours into MesenCE for an upcoming PR. Only the read-only audio registers $4091 and $4093-$4097 are missing right now - I'll likely reference/integrate the implementation proposed in this old PR (minus the nonlinear DAC): https://github.com/SourMesen/Mesen2/pull/33

Edit: It appears that I came to the wrong conclusion regarding $4033.D7. I just double checked on the physical drive and that bit is indeed only visible when the motor is enabled ($4025.D1 = 0), so Cluster was right on that one. (I'm guessing the FDSKey or the cable for my Twin Famicom simply holds that line high on the RAM adapter connector)
Last edited by TakuikaNinja on Sun Jun 14, 2026 9:51 pm, edited 1 time in total.
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Alright, I finally ripped the band-aid off and made a test program for the FDS audio. The interface is more or less the same as FDS-4023-Test, except the A button plays a sound on the wavetable channel and only $4090-$4097 is displayed on the top row (one update per frame is definitely not good enough for audio states but it'll have to do for now).

Repo: https://github.com/TakuikaNinja/FDS-Audio-Registers

Twin Famicom recording: https://youtu.be/25eULocF0Mk
(The parts where the note pitch is altered is from me holding/pressing reset during playback.)
Attachments
FDS-Audio-Registers.zip
(4.92 KiB) Downloaded 10 times
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Based on the recording, I think I can say that Yuri213212's analysis is half-correct in that audio can be paused/resumed if you toggle it quickly enough (demonstrated here using a 20Hz turbo). Any slower and the volume gets shut off.

I'm just not sure what's going on with the modulation disappearing after disabling the registers for a longer period, and staying that away after re-enabling them. Maybe the mod table contents decay or is otherwise initialised?
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

The other thing I want to try at some point is writing a value to $4081. It just seems odd that this address gets skipped in the documentation we currently have. If I had to guess based on the order used for the modulation registers, maybe it's a wavetable phase/address counter value?

Anyone with die scan analysis skills is free to take a shot at it. SCSR unfortunately hasn't been active lately.
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Another complication I've been running into is that this "window" for resuming audio seems to get shorter after leaving the console running for some time. It reaches a point where the 20Hz turbo isn't fast enough to prevent the volume from shutting off.

Edit: Leaving the audio registers off then seems to make this window larger again for some reason? Could this be analogue behaviour?
User avatar
Ben Boldt
Posts: 1644
Joined: Tue Mar 22, 2016 8:27 pm

Re: FDS $4023 Testing

Post by Ben Boldt »

TakuikaNinja wrote: Fri Apr 24, 2026 10:21 pm Anyone with die scan analysis skills is free to take a shot at it. SCSR unfortunately hasn't been active lately.
I could try taking a look, but I have no clue if I would be able to make any sense of it. Where can I find die shots and any existing work that has been done on it?
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

New version:
  • Up/Down now changes the mod table counter value (observed in $4097).
  • Wavetable RAM is now initialised while $4023.D1 = 0, in order to disprove claims that writes were disabled while in this state.
This comes after Yuri213212 reported in the Discord that wavetable RAM writes go through just fine while $4023.D1 = 0, which lead to us thinking that it might actually be an "audio reset" feature. My current guess is that the volume envelope ($4080) is being forced to $80 or some other value to silence the output, since I can't actually trigger the audio in while this state.

The modulation behaviour is a bit more convoluted. The mod frequency ($4087.D7 to halt the counter, at the very least) can still be changed while $4023.D1 = 0, but writing to the mod table using $4088 doesn't seem to work properly.

The mod counter in particular interacts with $4023.D1 in an odd way:
  • On program startup, I can't seem to change the mod counter (likely in a state reading a 4 in the mod table).
  • While in the reset state, the next mod counter increment ($4095 lower nybble) always returns F (even mashing the mod counter changes doesn't seem to affect it) and the mod counter is forced to 0 after writes to it (but not instantly).
  • After re-enabling the registers, I can freely change the mod counter. $4095 lower nybble doesn't change from 0.
$4095 is unique in that it consistently shows ($10 | next mod counter increment), $1C (probably reading the 1st mod table value?), then $1F (output disabled?) upon resetting the audio registers. It also seems to briefly change when manipulating the mod counter. Usually, I only see 0-2 in that upper nybble while the audio is running.

I'll double check the wave frequency, mod frequency, and the remaining registers soon.
Attachments
FDS-Audio-Registers.zip
(4.99 KiB) Downloaded 9 times
User avatar
TakuikaNinja
Posts: 664
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: FDS $4023 Testing

Post by TakuikaNinja »

Ben Boldt wrote: Sat Apr 25, 2026 10:44 am I could try taking a look, but I have no clue if I would be able to make any sense of it. Where can I find die shots and any existing work that has been done on it?
The die scan can be found at the usual place: Siliconpr0n
Quietust has previously attempted to trace the metal layer: https://www.qmtpro.com/~nes/chipimages/#rp2c33

It seems like no delayering ever took place, which is why Quietust's attempt stalled out. You'll just have to scour the Discord server for SCSR's notes & partial traces.
Post Reply