Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
there is a nice way to declare and use constants and variables that are located in various ROM and RAM banks and access the data in them transparently. all you need is to declare them in special way and use an old linker because the one in sdcc is broken.
GITHUB: https://github.com/untoxa/sdcc4_banks_example
any questions? welcome!
Last edited by toxa (2020-04-23 06:03:07)
Offline
this depends on the version of sdcc only. not the library. the answer is yes, it should work just perfectly with gbdk3.0. all this is all about the elimination of the "#pragma bank N" and "-b0N". you just declare constants/variables and that's all. it simplifys the build scripts also.
the only that make.bat do - produces just two commands:
sdcc -mgbz80 --no-std-crt0 -Dnonbanked= -I ..\..\gbdk\include -I ..\..\gbdk\include\asm -I src\include -c -DUSE_SFR_FOR_REG sdcc4banks.c -o build\sdcc4banks.rel ..\..\gbdk\bin\link-gbz80.exe -n -- -z -m -j -yt2 -yo4 -ya4 -k..\..\gbdk\lib\small\asxxxx\gbz80\ -lgbz80.lib -k..\..\gbdk\lib\small\asxxxx\gb\ -lgb.lib sdcc4banks.gb ..\..\gbdk\lib\small\asxxxx\gb\crt0.o build\sdcc4banks.rel
where sdcc is an sdcc4, and link-gbz80 is a ye olde linker
ps: if you were asking if this works with a new gbdk ONLY? no. this example will work with ANY gbdk. only modern SDCC is needed.
Last edited by toxa (2020-04-22 09:53:27)
Offline
pps: AH! MY BAD!! to make this work with an aincient GBDK, like 2.95, please remove the -DUSE_SFR_FOR_REG because the syntax of declaring sfr's had changed in new sdcc.
Last edited by toxa (2020-04-22 09:57:35)
Offline
added switch_to() macro, see above.
Offline
added RESTORE_BANKS macro. current bank numbers are saved, and if you have an interrupt (gbt_player, for example), that switches the bank voluntarily, you just add RESTORE_BANKS; at the end of an interrupt routine that rollbacks all bank switching were made during the interrupt.
if you want to switch banks IN THE INTERRUPT, you MUST use regular SWITCH_ROM_MBC1/SWITCH_RAM_MBC1, and if you want to access the "banked" variables declared with __addressmod IN THE INTERRUPT, you MUST ALWAYS cast them directly (char *)hello2 to avoid transparent bank switching. never use: a = hello2[0]; always use: a = ((char *)hello2)[0];
Last edited by toxa (2020-04-22 15:57:08)
Offline
i made a repo to keep this up-to-date: https://github.com/untoxa/sdcc4_banks_example
Offline
hi, guys!
you know an old anecdote about one man, who prayed all his life about the winning the lottery, and before his death, he asked god "why didn't you do this for me?". and the voice from the skies said: "why didn't you ever buy a ticket"?!
I found a bug in sdcc, that results in the incorrect bank switching: https://sourceforge.net/p/sdcc/bugs/2995/, posted a bug-report two days ago, it is already fixed today. I wonder, did anyone reported bugs of an original linker?!
May be we just need to buy (create) a ticket?
Offline