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 - Specifying a slot without specifying a bank in the superfree section

Reply to topic
Author Message
  • Joined: 30 Jan 2023
  • Posts: 2
Reply with quote
Specifying a slot without specifying a bank in the superfree section
Post Posted: Tue Apr 09, 2024 10:31 am
Hi, I am learning how to use bank switching and the superfree section of WLA-DX.
I have understood a little bit from other topics and have written some test code to see how it works, but it doesn't work as expected.
I hope someone can help me with this.


.bank 1 slot 1
.section "aaa" free
aaa:
    .db $00, $01
.ends

.bank 2 slot 2
.section "bbb" free
bbb:
    nop
    ret
.ends

.slot 1
.section "ccc" superfree
ccc:
    .db $02, $03
.ends

.slot 2
.section "ddd" superfree
ddd:
    nop
    ret
.ends


The aaa section is stored in bank 1 since the bank is specified.
This makes sense.
The same is true for the bbb section, which is stored in bank 2.
The problem is with the ccc and ddd sections.
In my opinion, the ccc section should be stored in some bank for slot 1, so I would expect it to be stored in bank 1 in this case.
But in fact it is stored in bank 0.
Similarly, the ddd section would be expected to be stored in bank 2, but is actually stored in bank 0.

I think something is wrong in my understanding.
How can I specify a slot in the superfree section without specifying a bank?
test.asm (1.95 KB)

  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 671
  • Location: London, UK
Reply with quote
Post Posted: Tue Apr 09, 2024 10:41 am
Slots and banks do completely different things:

- Banks specify which physical 16KB (or whatever) bank of ROM image the code will be emitted to during building the image.
- Slots specify the range within the memory map where the code is expected to be found at runtime. This is in order to calculate the addresses of any labels and jumps etc. properly.

When you specify a superfree section, you are explicitly saying that you don't care what bank the code will end up in (WLA actually puts it as far towards the beginning of the ROM image as possible, given any other constraints you've specified), and using the slot directive doesn't change that.

EDIT: P.S. welcome to the forum :)
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Tue Apr 09, 2024 11:07 am
Another way to look at it is that each label has an address in the ROM, which you can control by specifying the bank, and an address in the CPU memory map, which you control by specifying the slot. It’s up to you to then select the right banks into the right slots at runtime. This CPU memory map address affects how the code compiles, e.g. jp and call instructions need to “bake in” the CPU address.

Sections for different slots can be in the same bank. You don’t care about the bytes outside the section you want, so they can be anything.
  View user's profile Send private message Visit poster's website
  • Joined: 06 Mar 2022
  • Posts: 671
  • Location: London, UK
Reply with quote
Post Posted: Tue Apr 09, 2024 11:18 am
Yes, that's a good way of thinking about it: there are two different address schemes - a physical map (banks) and a runtime map (slots).

Usually we don't much care which bank the code ends up going in, which is why superfree exists — because we are happy to let WLA make the decision for us. An obvious exception is bank 0 (or whatever you call it), which contains the code which will run on boot.

Also, because it took me ages to find in the docs when I was learning this, if you want to get the bank number relating to some label in order to facilitate bank switching, you prefix it with a : symbol, i.e. if your label is foo: and it ends up (whether explicitly or by automatic allocation) in bank 3, then the symbol :foo will be replaced with the number 3 during linking.
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jan 2023
  • Posts: 2
Reply with quote
Post Posted: Tue Apr 09, 2024 3:04 pm
Thank you for your quick replies!
I have a better understanding after reading both of your replies.

Quote
Sections for different slots can be in the same bank. You don’t care about the bytes outside the section you want, so they can be anything.


This is the truth. Amazing!
I had mistakenly thought that one bank could only store sections for one slot.
I really don't care which bank the section is stored in, I just need to get the bank number and set it in the correct slot.
It is truly superfree.

Thank you so much!
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!