Saroo using Sega RAM Cartridge settings.


This is a modified version of the SAROO so it works at Sega's official RAM-cart bus timing (ASR0 0x23301FF0, from TB#47) instead of SAROO's slower timing. Games and hacks that set Sega's timing themselves now work without per-game patches.

What's changed:
  • FPGA: answers the cart bus fast enough for Sega's timing, which is 3 wait states with no wait signal.
  • Saturn firmware: Sega timing from power-on. The menu now runs from Saturn work RAM, which fixed the menu freezes caused by cover loading, and covers load once the cursor stops. Timing patches for 23 games are switched off, since those games now set their own timing.
  • STM32 firmware: built from tpunix's current source with ROMCTL, which switches on 16MB of extra cart RAM on boards that route AA24. That gives 28MB of usable cart RAM for homebrew.
Tested on one console (SAROO board marked 1.66):
  • The RAMCART-Stress test disc ran 100 of 100 runs with 0 errors. It covers the 4MB cart, code run from the cart, and the extra RAM, all with CD loading going on at the same time.
  • Working: KOF96, Castlevania 4MB hack (with saves), Marvel Super Heroes, the CD player, and fast scrolling through the menu with covers.
Not tested on other consoles yet, so please treat it as experimental. The FPGA update has no verify and no fallback, so back up SS_SAVE.BIN / SS_MEMS.BIN first and read the README.
 

Attachments


Covers now come from the STM32 through the CD data FIFO instead of the cart's SDRAM:
in the game list the SAROO menu doesn't touch the cart at all.
Install ssfirm.bin AND mcuapp.bin together (with an older mcuapp.bin there are no covers) on the SD card. The FPGA (change 7) is unchanged.

This fixes the SAROO's menu freezes because the cartridge now behaves like a part designed for the console. While you're in the game list, the Saturn doesn't touch the cart's SDRAM at all. The menu code is copied into the Saturn's own work RAM at boot and runs from there. Covers no longer go into the SDRAM either: the STM32 (the CD half) pushes each cover into the FPGA's CD data buffer, and the Saturn reads it over the A-Bus the same way it reads CD sectors.

Before, the Saturn was running the menu from the cart's SDRAM while the STM32 was writing covers into the same SDRAM on every cursor move. When both wanted the SDRAM at once, the cart could miss its window to answer the Saturn in time. The SAROO's own timing hid this with 8 wait states plus "external wait", which let the cart stall the bus until it was ready. Sega's RAM-cart timing (3 waits, no external wait) gives no such slack, so the menu froze, especially when scrolling fast.

Now the two sides don't fight over the SDRAM in the menu. We also stopped hammering the CD side for covers: the menu waits until the cursor rests before asking for one, and it gives the STM32 time to answer. If a cover doesn't arrive, it just shows no cover instead of hanging. So no more freezes, and the SAROO can use Sega's timing from power-on.
 

Attachments

Last edited:
SAROO and Sega's RAM-cart timing: why the menu froze, and how it's fixed

Background: what "timing" means here


The Saturn talks to the cartridge over the A-Bus. The SCU register ASR0 sets how long each cart access may take. Sega's own RAM cart timing (technical bulletin #47) is 0x23301FF0: 3 wait states, and no external wait. The cart must answer within a fixed time, about 140 ns, and the Saturn takes whatever is on the bus at that moment.

The SAROO firmware uses 0x38803880 instead: 8 wait states, external wait on, which lets the cart hold the Saturn until its data is ready.

Why the SAROO needs that slower timing

The SAROO has no real RAM cart. Cart accesses go through the FPGA to 64 MB of SDRAM, which the STM32 microcontroller also uses for its own work. SDRAM can't answer instantly: it needs refresh cycles, and if the STM32 is in the middle of an access, the Saturn's request has to wait for it to finish. With external wait on, the FPGA simply holds the Saturn until the data is ready, so every read is correct.

At Sega's timing that safety net is gone. The stock FPGA couldn't meet the 3-wait deadline even when the SDRAM was idle. That's why the firmware patches 23 games so they can't switch to Sega's timing, and why some hacks that set it themselves don't work on a SAROO.

Step 1: an FPGA that answers in time ("change 7")

I reworked the FPGA's SDRAM path:
  • Saturn requests are served before refresh and before the STM32.
  • Refresh and STM32 accesses happen in gaps where the Saturn can't be waiting.
  • The requested word goes straight to the bus.
  • Write data is sampled later in the cycle.
Result on hardware: the RAMCART-Stress test disc passes 100 of 100 runs at Sega timing with 0 errors. That covers the 4 MB cart, code run from the cart, the 8 MB above it, and the extra 16 MB with AA24, all with CD loading going on at the same time.

Games run at Sega timing without the per-game patches: KOF96, Castlevania 4MB hack (with saves), Marvel Super Heroes and others.

Step 2: the menu still froze

With Sega timing everywhere, the SAROO menu froze now and then, mainly when scrolling quickly through the game list. Testing narrowed it down:
  • Renaming cover.bin stopped the freezes.
  • Restoring it brought them back.
  • It was not the CS1 half of the timing.
The cause: the SAROO menu runs from the cart, so every instruction is fetched from the same SDRAM. On every cursor move, the STM32 loaded the next cover into that SDRAM. Sooner or later an instruction fetch landed on an STM32 access already in progress. That access can't be interrupted, the answer came too late, the CPU ran a wrong instruction, and the menu froze.

Games aren't affected the same way. They run from Saturn work RAM, and the STM32 keeps CD data in its own RAM, so a game hardly ever competes with the STM32 for the SDRAM.

Step 3: fixing it in the firmware
  1. Debounced covers: a cover is only requested once the cursor has rested for about ¼ second, so fast scrolling no longer floods the SDRAM.
  2. The menu runs from Saturn work RAM. At power-on a small stub copies the menu into low work RAM at the safe timing, checks the copy word by word, then switches to Sega timing and starts it. Only the code games call after they start stays in the cart: game start, save emulation and game patches.
  3. Covers come through the CD data FIFO, not the SDRAM. A new STM32 command sends the cover through the FPGA's CD FIFO, the same path CD sectors take. The menu reads it into work RAM and draws it from there. In the game list the menu now doesn't touch the cart at all.
Tested on hardware:
  • cold boot and boot animation;
  • fast scrolling with covers, with no freezes;
  • KOF96;
  • Castlevania 4MB, including save and reload;
  • the CD player;
  • reset back to the menu.
All of this runs at Sega timing from power-on.

A fallback, if it's ever needed

I've also designed an FPGA version that keeps two copies of the cart memory in different SDRAM banks, so a Saturn read always has a free copy. In simulation it gives 0 errors in every test. It hasn't been flashed and isn't in the release; the firmware fix made it unnecessary for now.

Caveats
  • Tested on one console (SAROO board marked 1.66). Other consoles may have less timing margin.
  • The FPGA update has no verify and no fallback. Back up SS_SAVE.BIN / SS_MEMS.BIN first, and read the README.
  • The new ssfirm.bin and mcuapp.bin must be installed together. With an older mcuapp.bin the menu shows no covers.
 
Back
Top