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 - bank switching Devkit SMS

Reply to topic
Author Message
  • Joined: 15 Mar 2021
  • Posts: 31
Reply with quote
bank switching Devkit SMS
Post Posted: Sun Jun 20, 2021 7:57 pm
Hello I would like to use the bank Switching technique with the C language and the SMS devkit ... I arrive at more than 32kb and miraculously I don't know how it is extended to 48kb ... if someone can explain to me? how to proceed with the SMS Devkit in C to add Bank ... THANKS
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3805
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Jun 20, 2021 9:26 pm
you don't need ROM paging if you don't go over 48 KB.

In case you do, check this. Basically you store your assets (art, music) in data banks and you 'map' them (make them ready) when you need to use them.

assets2banks is the tool you need to create the data banks.
  View user's profile Send private message Visit poster's website
  • Joined: 15 Mar 2021
  • Posts: 31
Reply with quote
Post Posted: Fri Jun 25, 2021 3:26 pm
Thanks 👌🏽👍🏽🙏🏽🙏🏽🙏🏽🙏🏽
  View user's profile Send private message
  • Joined: 15 Mar 2021
  • Posts: 31
Reply with quote
Post Posted: Mon Jun 28, 2021 9:01 am
hello I succeeded in creating bank 2 and bank 3 at compilation I now have 64kb but when I run my program it won't look for the data in the banks ... in my code I used the ,But that did not work
SMS_mapROMBank ( 2) // bank2 SMS_mapROMBank (3) // bank3.
this is what I have in my data compilation file: bat sdcc -c -mz80 --constseg BANK2 bank2.c
sdcc -c -mz80 --constseg BANK3 bank3.c
how do i call these banks in my program? thank you
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3805
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Jun 28, 2021 10:24 am
basically the bankswitching feature works this way:
1] you want to load some data that it's stored in a ROM bank
2] you have to map the bank where the data is found to be able to access the data (this is the page switch feature of the mapper)
3] you load the data

example: you have some VRAM tiles in a file called tiles.bin and you want to load them to the beginning of VRAM (starting from tile number 0) so you do:

SMS_mapROMBank(tiles_bin_bank);
SMS_loadTiles (tiles_bin, 0, tiles_bin_size);


all the constant (tiles_bin, tiles_bin_size and tiles_bin_bank) are generated for you by the assets2banks tool so you don't have to worry about their values and you can just use them.

I hope this helps.


edit: also, you don't have to compile ROM banks yourself, you can use assets2banks --compile command line parameter and have the tool produce the .rel files directly.
  View user's profile Send private message Visit poster's website
  • Joined: 15 Mar 2021
  • Posts: 31
Reply with quote
Post Posted: Wed Jun 30, 2021 9:58 am
Thank you, I just found my problem, but I can't resolve it inside my Assets folder, I have all my data, the problem is when I compile it creates two banks for me, but the files are scattered ... this poses a problem with my code because I can apparently not call a bank at a time ..
example I have my TILES.bin in bank 2
TILES.psgcompr in bank 3 ..and for called TILES it is apparently a problem if it is not in the same bank.
I would like to know how to group my files in the right bank ...

to my compilation I did that ...
Is there a file that organizes the data layout for each bank?
@echo off
assets2banks assets --compile rem data
sdcc -c -mz80 --constseg BANK2 source/header/bank2.c
sdcc -c -mz80 --constseg BANK3 source/header/bank3.c
pause
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3805
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Jun 30, 2021 10:38 am
I don't think you need asset grouping in this case as you could just do:

// load tiles
SMS_mapROMBank(tiles_bin_bank);
SMS_loadTiles (tiles_bin, 0, tiles_bin_size);

// load compressed tiles
SMS_mapROMBank(tiles_psgcompr_bank);
SMS_loadPSGaidencompressedTiles (tiles_psgcompr, 0);


Anyway if for some reason you really want to group assets into the same bank, you have to create an assets2banks.cfg file (a simple text file) into your assets folder and give assets2banks tool simple instructions of what you want to do.

For instance if you want your tiles.bin and tiles.psgcompr files be in the same bank, you simply use curly braces this way:

{
tiles.bin
tiles.psgcompr
}


this will tell assets2banks that those two files are bound to stay together, no matter what. Here is all the info you need about assets2banks utility.

But, again, I honestly think you don't need this at this time.
  View user's profile Send private message Visit poster's website
  • Joined: 15 Mar 2021
  • Posts: 31
Reply with quote
Post Posted: Thu Jul 01, 2021 9:30 am
thank you thank you thanks to you I am the happiest man in the world !!! I was able to solve my bankswitching problem I followed your example to the letter ... finally I think we can access any banks, I just have to place an sms_ROMbank () before each load ... and that walk !!!thank you again !!!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3805
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Jul 01, 2021 10:50 am
I'm happy it works :)

So, yeah, I should probably explain better how this bank-switching thing works somewhere - in the repository wiki probably?

In short: the Z80 CPU can only 'see' 64 KB of memory (16 bit addressing, from $0000 to $FFFF). Addresses from $0000 to $BFFF (48 KB) access the ROM on the cartridge and addresses from $C000 to $FFFF access the RAM in the console (well, usually).

So if your ROM is at most 48 KB, the Z80 CPU can access every part of it, but when your ROM is bigger the only way to access the ROM is to ask the mapper chip (that is inside the cartridge) to 'connect' a specific part of the ROM to a specific address that the Z80 CPU can reach.

So that's why there's commonly one SMS_mapROMBank command before each data access. This is the request that gets sent to the mapper, and until you issue a new request, the mapper will hold the last requested bank accessible. After issuing this bankswitch request, you will be able the access the data the way you would do normally and not worry at all.

I hope this helps!
  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!