SDLoader v0.12: run binaries from SD Card and backup/restore saves

Hello!

UPDATE:
Attached is new version v0.218b
- transfer speed more than 90kb/sec

Short version:
It is just a Proof Of Concept.
I wanted to backup my saves from saturn.

What SDloader do:
- Loads and run binaries from sd card connected to Saturn second game port.
- Save/Load saturn battery backed ram to/from sd card (approx. it takes 4s to backup saturn saves to sdcard). Saves format is raw dump of battery backed ram (64kb), same as in Yabause (bkram.bin).

Tested SDLoader with non sdhc, 2gb sdcard, with fat16. Probably will work with sdhc and fat32.

At default, this tool loads file boot.bin to 0x06004000 from sdcard and run it from there.
If you create plain text file named boot.cfg, you may load any other file, to any location and run it from any entry point (or just load one binary, but jump to some bios/arp function, or something, you decide yourself how to use it).

SDLoader use Petit FatFs - tiny fatfs library, so, it cant create new files. To backup your saturn saves, you need to create (place on sdcard) 64kb file bkramsv.bin which will be updated (overwrited) by SDLoader with your saturn saves. You may create it with dd (dd if=/dev/zero of=bkramsv.bin bs=64k count=1) or with fsutil (fsutil file createnew bkramsv.bin 65536), or use bkram.bin (64kb) from Yabause. Name it bkramsv.bin, place at sd card root, and SDload will overwrite it with your saturn internal saves, and/or name it bkramld.bin and SDload restore it to your saturn internal battery backed ram.

Update: included sample bkramsv.bin, bkramld.bin and boot.cfg in attachment to this topic.


Long version:
Wanted to backup saves from my saturn, so i decided to do sd card tool which use second gamepad port to communicate with sd cards. It is just a proof of concept, but it works. To match levels, fastest and cheaper way was to utilize microsd module (you may get one in any electronic diy shop, get microsd one, as it includes 5v tolerant buffer ic and 3.3v voltage regulator). If you dont want to use, or dont have such module at hand, use any basic level shifting and do not wire sdcard directly to saturn gameport2.

As it is quick proof of concept, for SDLoader i used Petit FatFs - tiny fatfs library, so, it is limited to work only with existed files (no function to create new files). Also, tested it with 2GB sdcard (probably, not sdhc) with fat16 fs. It may work with sdhc and fat32, but i not tested it. So, to backup saves from Saturn to sdcard, you need to prepare 64kb file named bkramsv.bin place it at sd card root (SDLoader will overwrite it with your actual saves), and to load saves from sdcard to Saturn, SDLoader looks for 64kb bkramld.bin.

Also, it may load and run binary from sdcard. Default, it looks for file "boot.bin", load it to 0x06004000 and run from there. But if you create file boot.cfg with simple format:
file=FILE.NAM
load=0xNNNNNNNN
start=0xMMMMMMM
it will try to load FILE.NAM to 0xNNNNNNNN and jump to 0xMMMMMMMM

About speed, it takes aprox. 4s to backup 64kb backup ram (saves) to sd card. And about 9s to load and execute 40kb binary.

Wiring
(sd card to saturn game port 2). Remember to shift levels, do not connect sdcard directly to saturn game port:
Saturn gameport2 (5v)​
SD card (3.3v)​
1​
VCC​
4​
/CS​
5​
MOSI​
7​
SCK​
8​
MISO​
9​
GND​


As for port pinout: if you look at game port on console from front, it is 1 to 9 from left to right

SD card (regular non- sdhc with FAT tested and works ok, sdhc and FAT32 probably will work too) filenames and structure
SD card ROOT:
boot.bin (optional, if you want to load and run something)
boot.cfg (highly optional, if you want to load and run other file than boot.bin and not to default memory location)
bkramsv.bin (64kb, optional, if you want to backup your saturn internal saves to sdcard, may use bkram.bin from yabause, just rename it and SDload will overwrite it with your saturn saves)
bkramld.bin (64kb, optional, if you want to import saves from sdcard to your saturn, may use bkram.bin from Yabause, just rename it)

Update: included sample bkramsv.bin, bkramld.bin and boot.cfg in attachment to this topic.
 

Attachments

  • sdloader01.jpg
    sdloader01.jpg
    206.9 KB · Views: 264
  • sdloader02.jpg
    sdloader02.jpg
    320.1 KB · Views: 137
  • sdloader03.jpg
    sdloader03.jpg
    237.6 KB · Views: 181
  • sdloader04.jpg
    sdloader04.jpg
    380.4 KB · Views: 7,184
  • sdloader05.jpg
    sdloader05.jpg
    347.6 KB · Views: 316
  • sdloader.zip
    50.5 KB · Views: 69
  • sdloader012.zip
    77.3 KB · Views: 35
  • sdloader0124.zip
    137.4 KB · Views: 55
  • wiring.jpg
    wiring.jpg
    91.8 KB · Views: 197
  • sdloader0218b.zip
    153.3 KB · Views: 27
Last edited:

Danthrax

Established Member
So how fast is the data transfer through the game port compared to reading data off a CD? Would you be able to play games loaded onto the SD card with your method?

Also, how do programs run off the SD card? Does the device take over the Saturn's normal boot method, or do you have to run the provided ISO through another method, like a Pseudo Saturn Kai cartridge? Can you show a video of it working?

(Thanks!)
 
Last edited:

Knight0fDragon

Patron Supporter
If it takes 4 seconds to do a 64KB file, then it seems that they are only pulling 16KB/s, Could need some optimizing to make it work faster.
 

fafling

Gear Supporter
64 kB file for internal back up ram means that every other byte is useless and can be stripped out as the actual size of the backup ram is 32 kB.
That should lower the transfer time.
 
Great.
You are opening the doors to the future for the mighty Sega Saturn.
Maybe one day you'll be able to run .isos straight from the SD card at low cost.
Could you pass your file in binary mode?
I'll try to record in my action replay and with that I don't need the cd sdloader.
I want to make the sdloader boot directly from the action replay reflash.
is it possible to send in binary mode?

Thanks
 
Hi
Could you pass your file in binary mode?
Sure. You want to place it in RomFs of Pseudo Saturn? Or if you want to place it in some specific CS0 area, let me know, and i will provide binary for it.

Upd. Just checked - it works from RomFs at PSKAI (at least in Yabause). Also it works if converted to arp firmware with cafe-alfa's mkfirm tool. But, i suppose, variant with placing it at RomFs in Pseudo Saturn Kai is much more useful.
So, would be glad to hear your success story!

pskai01.png

pskai02.png
 

Attachments

  • sdloader.zip
    32.7 KB · Views: 31
Last edited:

mrkotfw

Mid Boss
This looks great!
I take it that your SD card adapter has a 5v to 3.3v convert built in?
If so, which one did you purchase?
 
Thanks for the file in .bin mode.

Do you have mkfirm.exe ? I can't find it anywhere, not even on the blog.
 
Just for fun, patched lastest official PSKAI Lite version (256kb) firmware bin (PSKAI256.BIN) to make it bootable binary to load and run from 0x6004000 and also "enabled" rom-less mode (no cart mode). Seems to work on Yabause.
So, you may try to load and run it from sdcard.

Attached xdelta patch for original PSKAI256.BIN from current PSKAI official release (pskai_release_20211113, found at \tools\pskai_sdm.iso image, in FW directory).
Original PSKAI256.BIN md5 bbe5f0ced74427e6e1cfb2c65309f975

To patch:
xdelta3-3.1.0-x86_64.exe -d -s PSKAI256.BIN PSKAI256toBIN.xdelta boot.bin

..then just place boot.bin at sd card root

To braza:
Maybe it will be handy for you, if you will overwrite your cart with mkfirm. Any way, will be glad to hear about your experience.
 

Attachments

  • PSKAI256toBIN_fix.zip
    596 bytes · Views: 28
Last edited:
Nice result, braza! Glad that everything works as expected. You are welcome :) Its really handy that you did bank switching on your arp. I also recommend you to reflash new SDLoader, it is much better comparing to prev version.

I updated SDLoader to v0.12. It is much faster now, takes about 20s to load and run 648kb binary. Also, fixed vdp reset, when running loaded binary. And now it tested and works with sdhc 16gb/fat32 card.

Also Included binary version.
 

Attachments

  • sdloader012.zip
    77.3 KB · Views: 32
  • wiring.jpg
    wiring.jpg
    91.8 KB · Views: 46
  • sdloader0121.zip
    77.4 KB · Views: 25
Last edited:
Thank you, braza!

And here is new version 0.124. I did some optimizations, but speed increase is not so noticeable, so you may stay with 0.121.

Some calculations, if someone is interested.
In v0.124, for shift in/shift out one byte code routine, i reduced total instructions count to 175 (bit shift loop was unrolled to save few instructions count). According to what sh2 documentation states - basic instruction takes one cycle to execute. So, if Saturn's sh2 clocked at 26.87412246153846 Mhz, one cycle takes 37ns, and 175 instructions takes 6475ns. And, thereofe, for 1s it wll transfer 154440 bytes (almost cd-rom 1x speed). But it is only in theory. Because there is many overheads involving in process. And in actual result, 0.124 not really noticeable increased in speed with 0.121, where it get more instructions to shift 1 byte.
 

Attachments

  • sdloader0124.zip
    137.4 KB · Views: 20
Worked perfectly
(V.0.124 Incompatible with 3D control pad)
 

Attachments

  • 5A276670-4366-4C08-B85C-41CA7633C5D0.jpeg
    5A276670-4366-4C08-B85C-41CA7633C5D0.jpeg
    660.4 KB · Views: 80
  • 77AE141C-0655-48FE-A20D-26FB5F072B0D.jpeg
    77AE141C-0655-48FE-A20D-26FB5F072B0D.jpeg
    374.5 KB · Views: 61
  • 288F76FC-51FF-4144-9277-AE4FCE92FF70.jpeg
    288F76FC-51FF-4144-9277-AE4FCE92FF70.jpeg
    764.5 KB · Views: 66
  • 1BF1B2DA-0207-42D7-8617-70B0813C075F.jpeg
    1BF1B2DA-0207-42D7-8617-70B0813C075F.jpeg
    692.1 KB · Views: 70
  • B8D3A19B-BD74-4326-BBD0-5ECEA91A4204.jpeg
    B8D3A19B-BD74-4326-BBD0-5ECEA91A4204.jpeg
    533.4 KB · Views: 87
  • 0C2A29E3-60ED-4E1E-9DBD-A364F07A9DD7.jpeg
    0C2A29E3-60ED-4E1E-9DBD-A364F07A9DD7.jpeg
    704.9 KB · Views: 97
Last edited:
Thank you, tzmwx! Very nice way to avoid searching for spare controller connector, like it!
I added support for analog pad, and, also, cant resistate to tweak byte shifting a little, now total instructions count per 1 byte = 136. DIdnt tested it on real hw yet. But at least it works now on mednafen with "ss.input.port1 3dpad" option. Would be cool if you will try it on your config!
 

Attachments

  • sdloader0124b.zip
    141.8 KB · Views: 22
Top