• Rise from your gwave!

Saturn program question

Discussion in 'Saturn Dev' started by RadSil, Jan 1, 2002.

  1. RadSil

    RadSil New Member

    I was wondering if it would be possible to make a Saturn program execute a child program. A reason for this would to be to create trainers, etc... Any info appreciated.
     
  2. ExCyber

    ExCyber Staff Member

    I'm not sure, but I think it should work to load the program to where it expects to be and jump to the program's entry point. Depending on the program it might be necessary to do some other stuff like resetting the CPU registers or video mode to BIOS defaults. Loading a normal program would most likely require coding your initial loader program to run from a non-standard location (such as the low work RAM at 00200000).

    Hope this helps.
     
  3. RadSil

    RadSil New Member

    I had an idea... wouldn't it be possible to execute the program as an overlay program to the loader? I don't know the validity of this statement as I haven't checked the docs, but I know about overlay programs in general.

    Then again, there's that problem of the (child) program making assumptions as to where in memory it resides, and the state of the hardware before the program runs, the stack... doesn't the Saturn by default start execution at 06004000 or something like that? Or is that just where SGL or the crt0 sets the entry point in the startup code? Is it possible to start a program at an oddball location like the low work ram? Sorry if I sound like I don't know what I'm talking about but I'm not as "l33t h4x0r" as my title would lead you to believe :)
     
  4. ExCyber

    ExCyber Staff Member

    IIRC, there is a value in the boot area that tells the BIOS where the first program from CD (for the standard boot code, this seems to be the first file on the disc) should be loaded to. The default for SGL is 06004000. Anyway, if you don't want to mess with modifying the boot area, you could probably do a two-stage loader that looks like this:

    Stage 1: Loads normally and runs from 06004000; loads stage 2 to 02000000 and runs it.

    Stage 2 (for your example of a trainer): Does intro/menu/whatever, then loads the final program to its native address, applies patches, and runs.

    There might be problems with using an SGL program as a loader/patcher, since some SGL calls might mess with some of the reserved SGL memory areas, but there's only one way to be sure... If you want to compile a C program for a different address, you might try something like (this is missing the stuff for the SGL libs):

    gcc -o blah.coff blah.c -Ttext 0x02000000

    objcopy blah.coff blah.bin -O binary

    This is just a guess; I'm really no expert on GCC (or ld, which is what the -Ttext option actually gets passed to), and I don't have my Saturn set up to try it right now. Hopefully that will work though.
     
  5. TakaIsSilly

    TakaIsSilly New Member

    SGL will totally mess all upper memory every frame or so, so it's off no use in Stage 2 (since when you load the main file, it's bound to overwrite important GFX SGL values :p), but you can just make the intro/menu on Stage 1 and only write to a couple of pointers that Stage 2 reads... I bet SlCDInit will work without needing most of SGL (just sgl_cd.h should do).
     
  6. RadSil

    RadSil New Member

    Before coming back to check for replies to my question, I looked through the IP.BIN of Cotton 2 (hey, I had it handy) and the value of 06004000 is in there twice: once toward the beginning (0xF0 to be exact) and once at 0xFB4... I'm guessing the first would be the load area and the second one to just be coincidence.

    Would it be possible to include the 1st read binary in the "trainer", load the trainer and start execution at 02000000 and then use the "trainer" to copy the main program to 06004000 and jump to that address? Would this introduce problems with the game should it decide to use the low work ram?

    The real reason I want to do this is not to make a trainer, but to make a disclaimer screen and maybe a Translation Next logo screen for the Cotton 2 translation...
     
  7. TakaIsSilly

    TakaIsSilly New Member

    In a word, Yes.

    In a lot of more works, yes, but I haven't tried it yet, and the only file loading funcion that I was able to use (the now famous SGL one) might screw it up :p.

    My advice? Get one of Denis's emulators, or one of the other simple .ISO's that run on SSF, use Daemon Tools, and try untill your "trainer" works. Then progress to the big thingie. Good luck :p
     
  8. CyberWarriorX

    CyberWarriorX New Member

    Actually, it's discussed in one of the Saturn dev docs. I honestly can't remember which one. I'll take a look for it now.

    RadSil, try to hunt me down on irc. Hopefully by then i'll find it.

    Cyber Warrior X
     
  9. RadSil

    RadSil New Member

    How about (to avoid the CD filesystem functions) I embed the 1st read file as an array in the loader program? This way I could copy the array to the necessary address, and then jump to it.
     
  10. ExCyber

    ExCyber Staff Member

    That should work, assuming that everything fits. A disclaimer screen doesn't really provide the same problems that a trainer would (i.e. you don't need to patch a program in memory or need any of your code to remain resident), so I think this is definitely acheivable. At worst, you'd have to manually program VDP2 to display the screen, but I think some light SGL usage probably wouldn't be a problem as long as you clean up after yourself, don't use malloc, etc.
     
  11. TakaIsSilly

    TakaIsSilly New Member

    Rad, that would be perfect and very trouble free. The problem is the main "game" executable. How do you copy it to the correct location? You need to use the CD library anyway, unless you're lucky enough to fit it under a array as well :p
     
  12. RadSil

    RadSil New Member

    Well I would have to try to keep the program small - All I would need would be a way to display text, maybe a way to show a bitmap, and possibly the CD library if I choose to use it or the array thing doesn't work out...

    Thanks for all your help and support so far, guys - I expected this to be impossible.
     

Share This Page