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 banking code questions

Reply to topic Goto page Previous  1, 2
Author Message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Thu Sep 07, 2023 8:31 am
If in assembly, I’d guess it would be on the order of 100 cycles extra. I wouldn’t worry too much about it unless somehow you do it in a “hot” code path, eg calling a paged function once for a very byte of VRAM to clear it, which would of course be madness.
  View user's profile Send private message Visit poster's website
  • Joined: 01 Feb 2014
  • Posts: 878
Reply with quote
Post Posted: Thu Sep 07, 2023 1:05 pm
You might also add that banking code is a non-issue for a majority of projects, as you will have a hard time filling up the freely accessible 32K with code.

Unless you’re making a game of epic proportions with many bespoke parts or for some reason you clog up your lower banks with art and sound assets, you shouldn’t need to worry about banked pieces of code.
  View user's profile Send private message
  • Joined: 09 Aug 2021
  • Posts: 131
Reply with quote
Post Posted: Thu Sep 07, 2023 1:52 pm
pw wrote
Is there a large performance hit when calling a banked function?

native SDCC trampoline functions are not very efficient, they imply use of system dependent bank switching functions like:

get_bank::                              ; get current code bank num into A
        ld a,(#0xfffe)                  ; (read current page from mapper)
        ret
set_bank::                              ; set current code bank num to A
        ld (#0xfffe),a                  ; (restore caller page)
        ret

it is possible to write own trampoline functions as, for example, made in the SMS/GG library port of the GBDK-2020.

So:
1. yes, there is a performance hit.
2. It depend on how frequently you call banked functions.
3. situation may be improved on the library side
4. situation may be even more improved on the SDCC codegen side (push word instead of byte to stack, as made in the GB port).
  View user's profile Send private message
  • Joined: 27 Feb 2023
  • Posts: 136
  • Location: France
Reply with quote
Post Posted: Thu Sep 07, 2023 6:52 pm
Kagesan wrote
You might also add that banking code is a non-issue for a majority of projects, as you will have a hard time filling up the freely accessible 32K with code.

My very first game coded entirely in C fills the 32 KB and I had to optimize several times to not go beyond it. It was actually a bit constraining.

But this is an adventure game with quite a bit of content. Of course things can always be handled differently to gain space, but when you have tenths of events that are all specific in how the text is displayed (depending on adventure switches), making something "generic" is not always possible.

I have started my next project and being able to bank code is a relief honestly. I am currently working out the best way to handle maps, transitions between screens and teleporters with a "generic" approach. This is not trivial actually, as there are many possibilities. I would be curious to see how SEGA managed this for a game such as Phantasy Star II for example, that has a lot of map, all different sizes, containing tons of teleporters and exits to the borders.
  View user's profile Send private message
  • Joined: 01 Feb 2014
  • Posts: 878
Reply with quote
Post Posted: Fri Sep 08, 2023 7:00 am
cireza wrote
But this is an adventure game with quite a bit of content. Of course things can always be handled differently to gain space, but when you have tenths of events that are all specific in how the text is displayed (depending on adventure switches), making something "generic" is not always possible.

That does fit the description of a "game of epic proportions with many bespoke parts" quite nicely, doesn’t it? ;)

Anyway, I’m in no way against banked code. It can be very useful, obviously. I just think it’s not exactly the first thing someone who’s just starting out with SMS development needs to worry about.
  View user's profile Send private message
  • Joined: 28 Jan 2017
  • Posts: 556
  • Location: Málaga, Spain
Reply with quote
Post Posted: Fri Sep 08, 2023 8:32 am
... an obvious yet invaluable advice based on experience....

If you keep the functions which use/call/decompress into memory banked assets in the bank 0 or 1..... you Will avoid a bunch of headaches.

But 32kb, even after including the libs, is many space!
  View user's profile Send private message
  • Joined: 27 Feb 2023
  • Posts: 136
  • Location: France
Reply with quote
Post Posted: Fri Sep 08, 2023 4:19 pm
Kagesan wrote
"game of epic proportions with many bespoke parts" quite nicely, doesn’t it? ;)

It is not as large as a full fledged RPG like Phantasy Star though. But I was certainly not meaning to contradict you :)

I was simply surprised that I reached that quickly this 32 KB limit because I thought my game was quite reasonable in its initial ambitions.

For a very first project, it definitely sounds reasonable to leave code banking aside and make something that fits into 32 KB. This was personal conclusion upon starting my first game, and I would recommend this to anybody making a first project for sure. Especially if this is an assembly project, because I suspect that working in C generates a lot more code.
  View user's profile Send private message
  • Joined: 04 Jul 2010
  • Posts: 542
  • Location: Angers, France
Reply with quote
Post Posted: Fri Sep 08, 2023 5:44 pm
No suspicion, it's a fact ;)
  View user's profile Send private message
Reply to topic Goto page Previous  1, 2



Back to the top of this page

Back to SMS Power!