Saturn serial loader

Murzik

Established Member
Update:
v0.124
-LSHIFT/RSHIFT to switch baudrate. Default is 209954 (for NTSC Sega Saturn)
v0.123
-Experimental. Placed sci buffer and sci isr into sh2 cache.
v0.122
- Few cleanups
v0.121
- Changed baud rate to 211000 bps (NTSC Sega Saturn). Works much faster now

Connect Master TX, Master RX, GND from Saturn Communication Connector to RX, TX, GND of any USB UART TTL adapter (if it have jumper to select 3.3v/5v mode - use 5v mode) connected to your PC, or use max232 to connect Saturn MTX, MRX, GND directly to your PC hardware RS232 port.
Then run sloader at your Saturn and use provided sloader.py python script on your PC.
Exact measured baudrate is euqal to 209954 bps on NTSC Sega Saturn.

Examples of usage:
Code:
//dump 256kb cartridge rom
sloader.py d cart_rom_cs0.bin 0x02000000 0x40000

//dump 512kb bios rom for backup purpose from your Sega Saturn
sloader.py d bios_backup.bin 0x00000000 0x80000

//dump 4Mbit Backup RAM cart (saves)
sloader.py d bksv4m.bin 0x24000000 0x100000

//dump Internal Battery backup RAM (saves)
sloader.py d bkram.bin 0x00180000 0x10000

//restore Internal Battery backup RAM (saves) from bkram.bin
sloader.py w bkram.bin 0x00180000

//upload and execute serial.bin from 0x06004000
sloader.py r serial.bin 0x06004000

//jump to 0x06004000
sloader.py j 0x06004000

If you prefer to use other way to communicate with serial loader, proto is:
Code:
//Serial loader command awaiting mode (default):
uint8 command // "d" for dump, "j" for jumping to addr, "r" for load and run binary, "w" for writing binary to memory
//dump()
uint32 address // address
uint32 size // size
//then serial loader will send data from specified address byte by byte
//jump()
uint32 address // address to jump
//run()
uint32 address // upload and start address for your program
uint32 size // size of your program
//then upload program byte by byte, when its done uploading it will be run by serial loader
//write()
uint32 address // upload address for your data
uint32 size // size of your data
//then upload data byte by byte

Example of speed (so, 3 sec to backup internal saves and same for loading and running sloader binary, and 12 sec to backup 256kb cartridge):
timing.gif


I measured real baudrate frequency with freq meter, so, calculations fixed and now equal to real speeds. And here is real baudrates for NTSC Sega Saturn (it is test branch of serial loader, where possible to switch baudrates speed):
freq00.jpg


Below is outdated info for history purposes

It using sh2 master SCI in uart mode at 31250 bps. To upload your program, use included python script serial.py
serial.py <binary> <address to load>
Or use any other way, the protocol format is simple
uint8 command // "r" for upload
when in "r" mode, Serial loader awaits:
uint32 address // upload and start address for your program
uint32 size // size of your program
then upload program byte by byte, when its done uploading it will be run by serial loader


Hi

I decided to try out saturn serial port. I printed great connector created by our forum user zone66x And it is fit communication port ideally.
I wrote simple test program for saturn to test communication and it works fine. I think, i will add few useful functions (uploading/running binary and backup interal backup ram) and then upload it here.

ps. sh2 is very picky about clocks, when it came to uart and to be true, using internal clocks to drive, make it almost useless as it is not something you may call fast. But.. it works.


sci_test01.jpg
 

Attachments

  • sci_test02.jpg
    sci_test02.jpg
    129.9 KB · Views: 255
  • sci_test03.jpg
    sci_test03.jpg
    220.4 KB · Views: 259
  • serial01.zip
    61.4 KB · Views: 149
  • serial0121.zip
    64.1 KB · Views: 129
  • serial0122.zip
    63.4 KB · Views: 144
  • sloader0123.zip
    64.2 KB · Views: 136
  • serial0124.zip
    70.3 KB · Views: 174
  • sloader.jpg
    sloader.jpg
    49.6 KB · Views: 205
Last edited:
Connect pin 13 of your CH340G (DTR) to your master clock pin (center top pin of connector, next to your master TX pin) and you will be able to send a clock pulse from the PC side. It is what we are using with the networking project.

FYI, I am currently designing a connector to go from the Sega Saturn connector head to an RJ45 Jack, so you may want to keep that in mind for some of your projects.
 
My cheap idea

 

Attachments

  • 0FAA7E28-A577-4A3C-B711-728614147833.jpeg
    0FAA7E28-A577-4A3C-B711-728614147833.jpeg
    1.2 MB · Views: 203
v0.121
Changed baud rate to 211000 bps (NTSC Sega Saturn)
much faster now

v0.12
Added memory dump/memory write/load and run/jump

Examples:
Code:
//dump 256kb cartridge rom
sloader.py d cart_rom_cs0.bin 0x02000000 0x40000

//dump Internal Battery backup RAM (saves)
sloader.py d bkram.bin 0x00180000 0x10000

//restore Internal Battery backup RAM (saves) from bkram.bin
sloader.py w bkram.bin 0x00180000

//upload and execute serial.bin from 0x06004000
sloader.py r serial.bin 0x06004000

//jump to 0x06004000
sloader.py j 0x06004000

If you prefer to use other way to communicate with serial loader, proto is:
Code:
//Serial loader command awaiting mode (default):
uint8 command // "d" for dump, "j" for jumping to addr, "r" for load and run binary, "w" for writing binary to memory
//dump()
uint32 address // address
uint32 size // size
//then serial loader will send data from specified address byte by byte
//jump()
uint32 address // address to jump
//run()
uint32 address // upload and start address for your program
uint32 size // size of your program
//then upload program byte by byte, when its done uploading it will be run by serial loader
//write()
uint32 address // upload address for your data
uint32 size // size of your data
//then upload data byte by byte

Knight0fDragon, thank you for information. For serial loader i prefer to stick it to uart mode drived by internal clock. I already have some project in prototype stage with much faster speeds. Would be very interesting to take a preview look at your connector design.

tzmwx Your connector is great too. Thank you.
sci_test04.jpg
 

Attachments

  • serial012.zip
    64.1 KB · Views: 153
  • serial0121.zip
    64.1 KB · Views: 141
Last edited:
Does something have to be running on the Saturn first? I see the zip contains an iso and a bin file.
 
Would you be so kind to calculate the clock when Baud is set to 1, 2 , and 3? I have these cheap PL2303's I want to use, but I can't get the baud rate to match an acceptable rate on them. 209,954 seems to be a little too much for these devices to handle. Using the formula from Hitachi, I get 112,109.375 when setting baud to 1, which almost works but produces a lot of errors along the way.
 
Just quick calculations, sorry didnt tested with freq meter (but results are close to datasheet examples):
For NTSC sh2 clock equal to 26874122
N = 0;
n = 1;
baudrate = 52489
N = 0;
n = 2;
baudrate = 13122
N = 0;
n = 3;
baudrate = 3281

for example, if sh2 clock is 28636363 and N=126, n=2, calcualted baudrate = 110, same as in datasheet table

Btw, for cp210x based usb uart ttl adapters there is ic manufacturer software tool to "tune" baudrates - link, didnt checked pl2303 (btw have few somewhere, if ill find one ill try to test), but maybe there is something similiar to check/tune what baudrate it really sets.
 
Awesome. If you are using windows with PL2303, keep in mind that the newest drivers do not work with clones. If your PL2303 is a clone, use these drivers.
 

Attachments

  • Prolific PL2303 driver v3.3.2.102 (2008-24-09) Win8_x64_x86.7z
    69 KB · Views: 146
ok, so I was wondering why your numbers seem off. You were providing the numbers based on clock division (0 is clock / 4, 1 is clock / 16, 2 is clock / 64, 3 is clock / 256)

I was more interested in the BRR, so the larger N.

for 1, I calculate it at around 104,977.

Your mention of clock cycle now brings up a good point. The CPU also changes speed when your video is 320 or 352. Do you happen to have the clock speeds for the wide screen modes as well?
 
I was more interested in the BRR, so the larger N.

for 1, I calculate it at around 104,977.
Those already in Serial loader, N switched by lshift/rshift, thought, you checked it.
Serial loader merged in SDLoader use 28Mhz instead of 26Mhz as reference clock for it internal baudrate generator, so, yes, calculations use 28 mhz correctly (checked with freqmeter).

Anyway, attaching sorted baudrates list for 26Mhz and 28Mhz for all "n" and "N" combinations
For example, top10 list:
Code:
baudrate=223721 freq=28636363 n=0 N=0
baudrate=209954 freq=26874122 n=0 N=0
baudrate=111860 freq=28636363 n=0 N=1
baudrate=104977 freq=26874122 n=0 N=1
baudrate=74573 freq=28636363 n=0 N=2
baudrate=69984 freq=26874122 n=0 N=2
baudrate=55930 freq=28636363 n=1 N=0
baudrate=55930 freq=28636363 n=0 N=3
baudrate=52488 freq=26874122 n=1 N=0
baudrate=52488 freq=26874122 n=0 N=3

I may suggest you, just for testing, to try common 19200 with "baudrate=19086 freq=26874122 n=0 N=10"
 

Attachments

  • sh2_baudrates.zip
    11.5 KB · Views: 148
Last edited:
Those already in Serial loader, N switched by lshift/rshift, thought, you checked it.

Sorry, I am working outside of your serial project, was more going off of your notes and trying to document number accuracy since you have the tools to do so.

Turns out though that PL2303 does support the higher speeds, you just need the latest driver that it can accept. I attached that driver to this post.


BTW, are you planning on open sourcing the SDLoader from the controller? Would love to include that work into my project and create controller to serial adapters.
 

Attachments

  • 3.4.25.218.zip
    113.2 KB · Views: 137
BTW, are you planning on open sourcing the SDLoader from the controller?
For sure. Right now it need huge code refactoring and cleanup as it is mix of assembly and c, with addition of some post compiling/prelinking objects patching to overcome gcc limitations to further optimize critical code for saving few cycles. And as it is constantly worked on, code get new features and so on. So, i think i will first prepare it for opening, and last but not least, will add much more comments.

Would love to include that work into my project and create controller to serial adapters.
That would be cool. Interesting to know more about your project. It is same project that utilize saturn serial to rj45 3d printed connector? May you show some preview of how it looks?
 
Last edited:
For sure. Right now it need huge code refactoring and cleanup as it is mix of assembly and c, with addition of some post compiling/prelinking objects patching to overcome gcc limitations to further optimize critical code for saving few cycles. And as it is constantly worked on, code get new features and so on. So, i think i will first prepare it for opening, and last but not least, will add much more comments.


That would be cool. Interesting to know more about your project. It is same project that utilize saturn serial to rj45 3d printed connector? May you show some preview of how it looks?
I am replacing the netlink code on the netlink games. We will be able to play them without the need of the dial up modem.

I will upload some pictures later on tonight of my prototypes.
 
Back
Top