Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - devkitSMS experimental branch

Reply to topic
Author Message
  • Joined: 05 Sep 2013
  • Posts: 2790
Reply with quote
devkitSMS experimental branch
Post Posted: Tue Nov 10, 2020 11:26 pm
SDCC version 4 is arrived and it's bringing banked code with it.

So I have created an experimental branch in devkitSMS and I'll be working on that... whenever possible.

In short: code can be written in separate source files that gets assembled in separate code banks. When calling a banked function, the code will trigger a slot-1 bank change (using trampolines that are 'hidden' in bank 0 code) and will restore the previous bank upon returning from called function.

This means that only code in bank 0 won't ever be paged out, but that means that there will no longer be code size restrictions to 32 KiB.

At the moment this is still very experimental, and a few things might change in the near future. But for now, if you're interested into this, this is what you need to know.

1st: you need at least SDCC 4.0.4 #11929. Get a recent snapshot from their website and you're good.

2nd: you need to compile each code bank into a specific separate code segment, for instance as in:
sdcc -c -mz80 --codeseg BANK1 banked_code_1.c

3rd: you need to use (the devkitSMS provided) crt0b.rel as the first module in your linker call

4th: you need to instruct the linker to place all the banked code at address 0x4000 + the virtual address of the bank, which is banknumber×2¹⁶ (so code segment BANK1 goes at 0x14000, code segment BANK2 goes at 0x24000 and so on...)
sdcc -o output.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK1=0x14000 crt0b_sms.rel SMSlib.lib main.rel banked_code_1.rel

5th: you need to use the newer makesms tool to convert the ihx output to the sms file (this works very differently compared to ihx2sms so that's why it's a separate tool)
makesms output.ihx output.sms


A simple example. Note how func_next is declared as __banked in both the source and the header file (this is very important as the caller needs to know that in advance). Also note how code can call 'local' functions within same code bank just regularly.

main.c:
//  SDCC banked code test

#include "banked_code_1.h"

#include "SMSlib.h"

void main (void) {
  unsigned char n=5;
  n=func_next(n);
}

SMS_EMBED_SEGA_ROM_HEADER_16KB(9999,0);


banked_code_1.h:
//  SDCC banked code test header file

unsigned char func_next (unsigned char num) __banked;


banked_code_1.c:
//  SDCC banked code test

unsigned char local_function (unsigned char num) {
  return (num+1);
}

unsigned char func_next (unsigned char num) __banked {
  // calls a local function
  return (local_function(num));
}


There's still a lot of work to be done but I hope you'll find this interesting.

Feedback appreciated. Questions welcome. :)
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 640
  • Location: Spain
Reply with quote
Post Posted: Wed Nov 11, 2020 7:59 am
wow! seems really interesting, although I think I'll wait sometime before trying it :-)
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2790
Reply with quote
Post Posted: Wed Nov 11, 2020 4:08 pm
I don't expect many people to really need this, anyway.

But Eruiz would find it handy :D
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 640
  • Location: Spain
Reply with quote
Post Posted: Wed Nov 11, 2020 4:46 pm
I've a use case for this (more or less). I thought about having a game that at the end, will show fmv using the video player gligli created some time ago. So, it'll mean banking the player code in the slot 1 just at the end of the game and start banking the data on the slot 2.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2790
Reply with quote
Post Posted: Thu Nov 12, 2020 11:03 am
is that player code very big?
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 640
  • Location: Spain
Reply with quote
Post Posted: Thu Nov 12, 2020 11:54 am
Not sure, but the "n*ked player code" should fit on 16kb, I don't think is such a monster to be 32kb...
  View user's profile Send private message
  • Joined: 28 Jan 2017
  • Posts: 379
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sun Nov 22, 2020 12:27 pm
sverx wrote
I don't expect many people to really need this, anyway.

But Eruiz would find it handy :D


LOL...

In fact i was playing with some ideas ,thinking about this, when i entered in smspower page to check news... And voilá!

I have a game for msx (done with SDCC) which does code banking (it compiles several .c files mapped to the same address, and then link them all.. SDCC linker warns about this but it works. After the linking you have to separately link the bank, rel files to ihxs, fill those ihxs to 8kb each and do a binary copy to make the final rom file. You have to be careful but it works. I can prove it :) In fact, i was going to try this technique for SMS.

But if sdcc4.0 developers have done the work for me, it will be better for sure. So downloading now to check.!

Working on (maybe) new game for compo. First graphics and some music but i have tye idea (the most difficult part for sure)...

Regards!!!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2790
Reply with quote
Post Posted: Sun Nov 22, 2020 4:55 pm
eruiz00 wrote
if sdcc4.0 developers have done the work for me, it will be better for sure


they added that __banked keyword, and the trampolines that make the code bank switch possible

this is still pretty new and all WIP so it will improve in the coming months, I guess.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 379
  • Location: Málaga, Spain
Reply with quote
Flawless!!!
Post Posted: Fri Nov 27, 2020 11:53 pm
Ummmmm... After some hours changing the build script and the needed srcs , i have to say IT WORKS !!!!

I have been checking all the needed functions (zx7 unpacking to ram, vram tiles and tilemaps writing and background music & sound ) and i found that, if all the assets are in the same bank, ( and compiled with the source code) it just works.

I used the ctr0b file only, as the rest of smslib and psglib seems equal.

Now i can fit 85 minigames into a rom. Great!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2790
Reply with quote
Post Posted: Mon Nov 30, 2020 12:11 pm
assets handling with assets2banks it's still a bit of a mess with this experimental fork... you either put banked code in the banks after the assets ones or you use folder2c and you allocate assets in the banks following your code

I likely have to add a command line option to assets2banks to set the number of the first bank to be used. I will look into that when I get some free time.
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!