• Rise from your gwave!

Another Saturn SDK

Discussion in 'Saturn Dev' started by Red Ring Rico, Jun 29, 2014.

  1. Red Ring Rico

    Red Ring Rico Mid Boss

    I've tried using my BIOS to underclock the CPU, but the temperatures were still high. I'll give this utility a try, though. Thanks.

    You will need to set/create the SATURN_ROOT environment variable to the root directory of the SDK, which is installed to your home directory under saturndev/saturn-sdk by default. This environment variable is not too difficult to add to the installer for Windows, but Linux requires some more work (I'm not sure why it's not built-in to the Qt Installer Framework for Linux). In Code::Blocks, you will need to go to Settings/Compiler, select GNU GCC Compiler for Hitachi SH-2 from the drop-down, navigate to the "Toolchain executables" tab, select "Auto-detect" next to the ellipsis where the "Compiler's installation directory" area is, then "Set as default" which is under the drop-down for "Selected compiler" if it detects the directory correctly.

    EDIT: After trying to run it under Windows, the linker script seems to be missing. I'm not sure how this happened. For now, you will need to download the linker script from https://raw.githubusercontent.com/SaturnSDK/Saturn-SDK-Sample-00-Basic/master/Source/Saturn.lnk. As it's pretty late over here I'll have to look into this later.
     
    Last edited: Jul 2, 2015
  2. CarlosTheMover

    CarlosTheMover New Member

    To which folder does the saturn.lnk file go?

    EDIT: There's one in the saturn-sdk\ide\share\CodeBlocks\templates\wizard\saturn\Saturn.lnk folder. It's not getting copied to the right location or something?

    EDIT2: Copied it to a test project I did. Got me farther. Post build step is reporting an issue.

    /toolchain_elf/bin/saturn-sh2-elf-objcopy -O binary bin\Debug\Test003.exe bin\Debug\Test003.exe.bin
    Execution of '/toolchain_elf/bin/saturn-sh2-elf-objcopy -O binary bin\Debug\Test003.exe bin\Debug\Test003.exe.bin' in 'C:\Incoming\SaturnProjects\Test003' failed.
    I'll poke around some more.

    EDIT3: manually calling it on the command line appears to work. That's the final result and I can run that in an emulator?

    EDIT4: Some other observations.

    Codeblocks didn't originally see the $SATURN_ROOT\toolchain_elf when I tried to auto detect it in the compiler settings. I had to manually set the full path to the SDK to get something to build. I reverified that I had the correct ENV variable. I went back to the setting, put $SATURN_ROOT\toolchain_elf again, clicked on auto detect and it found it. It then changed $SATURN_ROOT\toolchain_elf to the full path. I'm not sure if that automatic path change is supposed to happen or not.

    Forgot to mention that whenever I create a new project in Codeblocks, I get script warnings about the wizard not knowing how to setup warning, debug and optimization flags for the compiler.

    The saturn.lnk file on Windows is treated like a shortcut, with a shortcut mini icon and hides the file extension.
     
    Last edited: Jul 3, 2015
  3. Red Ring Rico

    Red Ring Rico Mid Boss

    I can't believe I missed the vital step of telling you where to put the linker script. Sorry about that!

    The compiler hasn't been set up completely, which is why there are those warnings when you create a new SEGA Saturn project. If you started Code::Blocks without setting the environment variable first (as in the first time you start C::B) it will not try to look again unless you use the "Auto select" button in the compiler settings. When you do, it will use the absolute path found from $SATURN_ROOT. You could delete the SaturnIDE directory under your application data directory in Windows to have C::B forget its settings.

    As for the linker script, you could disable the "Hide extensions" in "Tools/Folder options/View" for Explorer. I wouldn't recommend assigning a program to open it as this could break other programs which rely on .lnk files on Windows.

    The generated .bin file under your project's bin/Debug or bin/Release directory should work in an emulator. Unfortunately there isn't anything exciting about the program. You can use the emulator's debugger to step through the program and see that it just keeps branching to the same location, which is to be expected and means it worked. Most emulators them come with a debug interface, if not Yabause does.

    I'll work on the environment variable issue and the linker script as well as start working on uploading the binary to a Saturn (at least on Linux).
     
  4. CarlosTheMover

    CarlosTheMover New Member

    Ok, I have something better working.

    Triple checked $SATURN_ROOT, removed SaturnIDE from my AppData\Roaming, rebooted and restarted Code Blocks. It saw the GCC for Hitachi on startup. So that's good!

    If somehow you can't include setting the SATURN_ROOT variable in the installer, it'll help if that step is more prominent in the instructions. From what I've experienced, even setting it after doesn't make it work correctly. EDIT: Thinking about it, maybe I should've just rebooted at the time.

    Created a new project but the wizard still complained about the same flags as mentioned earlier.

    Copied the saturn.lnk* file to my project folder, compiled and voila. It built. (Woot!)

    ((*)Is that's actually where it's meant to go?)

    The installer doesn't properly create an entry in the Start Menu. Tried on Windows 7 and XP.

    What settings do I need in Yabause for it to run my compiled bin? I've messed around with various CD-Rom settings but can't get it to load the .bin properly. It complains of Unsupported CD Image and Cannot initialize IOS-File Virtual Drive. Do I need to wrap up the bin into a proper ISO or something?
     
    Last edited: Jul 3, 2015
  5. Red Ring Rico

    Red Ring Rico Mid Boss

    I can set the environment variable in Windows with Qt IFW, but on Linux there's no support for it. I'm sure there's a method involving using the scripting language for it to modify ~/.profile and append or modify the environment variable there. You will need to use mkisofs and create a valid IP.BIN using the official SEGA Saturn tools, or you can use the pre-compiled IP.BIN from the SGL (under sample/sys). With those two downloaded, you can create an ISO with this command (courtesy of The Rockin'-B):

    mkisofs -quiet -sysid "SEGA SATURN" -volid "SaturnApp" -volset "SaturnApp" -publisher "SEGA ENTERPRISES, LTD." -preparer "SEGA ENTERPRISES, LTD." -appid "SaturnApp" -abstract "ABS.TXT" -copyright "CPY.TXT" -biblio "BIB.TXT" -generic-boot IP.BIN -full-iso9660-filenames -o sl.iso CD

    Assuming that you've opened a terminal and changed into your project's bin/Debug or bin/Release directory, and that mkisofs is copied into that directory. The CD at the end is a relative directory called CD, which should contain ABS.TXT, CPY.TXT, BIB.TXT, and your binary. Name the binary 001.bin (or anything which will be considered the first file by name). Also note that the SEGA Saturn requires uppercase characters for these files, if you create abs.TXT or abs.txt it will not work. These files can be empty, just as long as you create them. IP.BIN is case-insensitive and is only used by mkisofs, not included in the CD directory. This is another step which will be automated by the IDE in the future, too.

    When you run it you should see the SEGA license notice, check out Debug/Master SH2 from Yabause, you should see the following highlighted:
    0x600406E: bra 0x0600406E
     
  6. CarlosTheMover

    CarlosTheMover New Member

    I'll try that out, thanks!

    for mkisofs, do you think that would belong in a post build step built into the project or do you think it should always be separate?
     
  7. Red Ring Rico

    Red Ring Rico Mid Boss

    It will be a post-process step after the binary is created so you can test it as soon as you can under an emulator or burn it to a CD-R. Of course, this will be optional and turned on or off as the user sees fit in the project's settings.
     
  8. CarlosTheMover

    CarlosTheMover New Member

    Woot! It works, thanks!

    The SDK seems to come with only a basic SDK. I can't find any graphics API, for example. Is that something I need to download separately? Is there one you can recommend?
     
  9. Red Ring Rico

    Red Ring Rico Mid Boss

    The SDK is still in an infantile state, it will be a while before it's complete and ready to go. There are a few APIs, such as SGL and libyaul available. I haven't had much time to actually do Saturn development, as I'm working on this development environment. vbt may be able to tell you how to set it up.

    Update: I've updated the installer to create an environment variable under Windows for SATURN_ROOT, next I'll look at the linker script, then work out how to set the environment variable under Linux.

    Update #2: After 2 hours 20 minutes, I figured out the Qt Installer Framework documentation, which is helpful if you know how to read it (it refers to Qt-specific JavaScript, and I don't know regular JavaScript). Anyway, after trying 5 different methods to achieve the same thing, creating 44 different directories with the installer, and learning some JavaScript along the way, I finally managed to add 14 lines of script which adds export SATURN_ROOT=<path> to ~/.bashrc. I also tried getting it set after the installer has finished (running source ~/.bashrc didn't work as it is like opening a new terminal and expecting it to work on all the others) but could not get that working in the end.

    Update #3: Fixed the linker script issue on Windows, which created an issue on Linux, leading to another build which works on both. I thought the lnk extension was being ignored as a valid extension under Windows and therefore Code::Blocks just couldn't see the file. This was not the case, I needed to have a Saturn.lnk file in both the C and C++ directories. Next: Looking at deploying to a Saturn from Code::Blocks.
     
    Last edited: Jul 4, 2015
  10. antime

    antime Extra Hard Mid Boss

    The abstract, bibliography and copyright files are not actually needed. Sega's cert process required that they're present, but the firmware doesn't check for them. The filename case thing is probably due to how mkisofs sorts the files when generating the image. The "first load file" will always be the first file entry in the root folder, and it is up to the generating software which file that is. Most just sort the files alphabetically, which is why in most games it's named "0" or "0.bin" or something similar.

    As you've noticed, using the .lnk file extension is not a good idea, and I would suggest you rename the linker scripts to make it easier for your Windows users.
     
  11. Red Ring Rico

    Red Ring Rico Mid Boss

    I think you're right, antime. Not being able to associate the files with an editor is a problem. I just wanted to get it working and was blinded that it would create another problem. I can't remember where I read that file names had to be upper-case ASCII, including numbers and some limited set of symbols. Misinformation isn't good, and I should have been more thorough.

    On another note; I'm setting up the build server for the Windows version of Code::Blocks on an Amazon EC2 instance, mainly because it's free for a year. I'm still looking into getting it cross-compiled from Linux.
     
  12. antime

    antime Extra Hard Mid Boss

    For the abs/bib/cpy files, the character set is limited to 0-9, A-Z and the underscore character (if you really want to know, the details are found in the ECMA-119 document). But there's nothing on the Saturn that cares, so any name that mkisofs accepts will do.
     
  13. Red Ring Rico

    Red Ring Rico Mid Boss

    Thanks for the information, antime.

    After building the IDE on an Amazon EC2 instance, the compilation time has gone from 1 hour to ten minutes.
     
  14. Red Ring Rico

    Red Ring Rico Mid Boss

    Update

    It turns out that the issue I had with my desktop overheating was due to the motherboard being warped. Too much pressure used when mounting the HSF. Luckily, I can just get a new motherboard and RAM, unfortunately the motherboard I was looking at isn't in stock at the moment. Hopefully it won't be too long until I can replace it.

    In the meantime I'm looking into C++ support and installing the SDK on BSD as well as Mac OS X.

    Update

    Initial C++ support
    After a few hours of re-compiling (which turned into days with trying to get Mac OS X running in VirtualBox) I have built the C++ compiler and libstdc++. Though I have not thoroughly tested support, at least the compiler and standard C++ library are working.

    Deploying to the Saturn
    I'm currently looking through the source code of the file transfer utility for the USB Development Cartridge in order to allow for deployment directly to the Saturn by pressing Ctrl+F10 to run or F9 to build and run.

    Website

    Over the next few months I will be setting up a website dedicated to the SDK to bring everything into one cohesive location. Mainly the site is just for laying out a full roadmap for all the components of the SDK and allowing for separate issues (the IDE, compiler, other tools) to be discussed with their own threads via a mailing list.
     
    Last edited: Jul 13, 2015
  15. dibz

    dibz Staff Member

    You're more then welcome to use SX as a base for your forums and hosting the files and such.
     
  16. Red Ring Rico

    Red Ring Rico Mid Boss

    Thanks, dibz. I was thinking that I could set up a github.io site for the organisation as a landing page for describing the SDK, use each project on GitHub for bug tracking, and use the forums here for communication of ideas (improvements, changes, etc.). The file hosting isn't a problem as I have a 1TiB transfer limit per month, and I haven't gone anywhere near it.

    I just created the site a few minutes ago: http://saturnsdk.github.io
     
  17. dibz

    dibz Staff Member

    Sounds like a plan to me. I'm thinking a sub-forum of this saturn dev forum, thoughts? and name for it?
     
  18. Red Ring Rico

    Red Ring Rico Mid Boss

    A sub-forum here would be great. I think "SEGA Saturn SDK" would be very megalomaniacal of me to put forward. "Rico's Saturn SDK" would be a better fit.
     
  19. dibz

    dibz Staff Member

    All set.

    I set you up as a moderator of the new sub-forum as well.
     

Share This Page