Sub Header

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

Post Reply
User avatar
KanedaFr
Administrateur
Posts: 1090
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Sub Header

Post by KanedaFr » Wed Jul 05, 2017 11:40 am

Where could I find info on the SubProgram header ?

I saw nothing on the official doc on how to write a sub program, starting with the header....
For ex, what's the difference between SPInit and SPMain ? Does SPMain mean to be called after a Reset (using register $A12000) ?
Is there 3 , 4 or more jump on the header offsets ?

Chilly Willy
Very interested
Posts: 2425
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sub Header

Post by Chilly Willy » Wed Jul 05, 2017 3:19 pm

The main source is the example SCD code SEGA made... there's two versions included with the last SDK SEGA released, the second showing how to handle CD32X. It's in the docs, but you gotta hunt for it. The CD boot info is in the MEGA-CD Disc Format Specifications, and the header info is in the MEGA-CD BIOS Manual. Specifically, page 34. There's four user call vectors (0 to 3) - the first is called before int level 2 processing starts and is meant for initialization, the second is the main() and will be called over and over again when you exit (allows for chaining programs, I guess), the third is the user int level 2 routine and is called after the BIOS has done its processing. The last one is not called by the BIOS and is free for use by the programmer. I use it to retrieve a pointer to some boot info kept by my boot loader, but it can be of any use.

User avatar
KanedaFr
Administrateur
Posts: 1090
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: Sub Header

Post by KanedaFr » Wed Jul 05, 2017 4:58 pm

Shame on me...everything I was looking for is on the MEGA-CD BIOS Manual, starting at page 30 :oops:
I thought it was only the bios calls :(

For main(), what's the better use then ?
to loop on it (bra _main) or to exit and wait for next int2 ?
From the manual, I would say exit and wait, but none of the code I saw do this....

Chilly Willy
Very interested
Posts: 2425
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sub Header

Post by Chilly Willy » Wed Jul 05, 2017 7:54 pm

I imagine that most games never exit. On console games (until they added OSes at least), the power button was your "exit" from the game. :lol:

My CD loader actually uses the "main" user call, loads "APP.BIN" from the CD, and calls the loaded binary. If that binary exits back, it checks d0 - if it's set, it assumes this is a pointer to a name of a file to load and run, so it tries to load and run that file. If THAT file exits, it does the same thing. Only if d0 is 0 does my loader exit... and then the BIOS will call it again, making it load and run APP.BIN.

User avatar
KanedaFr
Administrateur
Posts: 1090
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: Sub Header

Post by KanedaFr » Wed Jul 05, 2017 9:08 pm

After some times thinking on it, it's clearly a bra that we need.
If you exit, it means you can only handle ONE command per VInt => when the main( ) starts

so let's keep the loop ;)


And I really like your idea...it would be very useful for a Mega(CD)Games compilation ;)

Chilly Willy
Very interested
Posts: 2425
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sub Header

Post by Chilly Willy » Wed Jul 05, 2017 10:36 pm

KanedaFr wrote:After some times thinking on it, it's clearly a bra that we need.
If you exit, it means you can only handle ONE command per VInt => when the main( ) starts

so let's keep the loop ;)
That's if you make your boot loader also the game. I separated the boot loader from any apps, as you can tell from my description. It has one default app name it tries to load initially, then counts on that to provide any other app names.

And I really like your idea...it would be very useful for a Mega(CD)Games compilation ;)
At the time, I was thinking two things: one, a file manager where when you select a file and press run, it passes the name back, so the boot loader loads and runs the file; if you loaded and ran it from the file manager, you'd have to be careful about the two overlapping in memory. And two, having an opening sequence for a game; the first part loaded would be a video player that played the opening video, then when you hit a button or it was done, it would pass back the filename for the game itself. You could even divide the game into levels that were completely separate - then you are less confined by the 512KB limit on program ram. The intro, each level, bonus levels, and the ending could all be completely separate and fill most of the available ram.

User avatar
KanedaFr
Administrateur
Posts: 1090
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: Sub Header

Post by KanedaFr » Thu Jul 06, 2017 8:38 am

I'm not on the size limit yet so I'll keep your idea for later use ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest