Giter Club home page Giter Club logo

Comments (22)

sverx avatar sverx commented on July 28, 2024 1

first: ihx2sms doesn't support banked code, so you can't use that tool and you have to rely on makesms instead, which supports banked data and code and uses virtual addresses

the easiest way to have banked code and banked data in your program is to have whole banks contain either code or data, even if sometimes this requires a bit of waste

so if your banked code uses, for instance, 3 banks, you may want to call them BANK1, BANK2 and BANK3

then your banked data will start from BANK4, say you also have BANK5 and BANK6

then you will link those banks using:

-Wl-b_CODEBANK1=0x14000 -Wl-b_CODEBANK2=0x24000 -Wl-b_CODEBANK3=0x34000 -Wl-b_DATABANK4=0x48000 -Wl-b_DATABANK5=0x58000 -Wl-b_DATABANK6=0x68000

that is: code banks will be at address x4000 and data banks at address x8000 (please note that this is hexadecimal so DATABANK10 will be at A8000 not at 108000)

I hope this helps!

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

did you try something easy like:

sdcc -c -mz80 --codeseg BANK1 bank1.c
sdcc -c -mz80 --codeseg BANK2 bank2.c
sdcc -c -mz80 --codeseg BANK3 bank3.c
sdcc -c -mz80 --constseg BANK4 bank4.c
sdcc -c -mz80 --constseg BANK5 bank5.c
sdcc -o file.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK1=0x14000 -Wl-b_BANK2=0x24000 -Wl-b_BANK3=0x34000 -Wl-b_BANK4=0x48000 Wl-b_BANK5=0x58000 crt0b_sms.rel SMSlib.lib main.rel bank1.rel bank2.rel bank3.rel bank4.rel bank5.rel

this is what I do in my code and it works fine.

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

Also don't let the SMS ROM file fool you. The banks are ordered there but their address is in no way indicative of at what address the Z80 will see them. So code can be at ROM address 0x8000 (ROM bank 2) but will be mapped at Z80 address 0x4000 because that's what mappers do 😄

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

4, of course.
If you use assets2banks tool, you get a bunch of defines that you can use and not even worry about what's the actual value.
Please check that. It's the fastest and easiest way to handle assets (data).

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

assets2banks.py assets --firstbank=4 --compile --singleheader

this will create your rel files directly, starting from bank4.rel, and will create the assets2banks.h file with all the defines you need

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

If everything is done correctly, code mapping should be transparent - you shouldn't need that.

If it wasn't working when the __banked keyword was present, it is likely because the declaration of the function was missing that part. What I mean is that you need to have a .h file that declares that function as banked and you have to include that .h file in your main, or if you don't want a separate .h file, you have to anyway declare the banked function in your main.c as in

void functionBank1(void) __banked;

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

you can ignore that SDCC message, it's a leftover debug info, I have a few of them too and still everything works

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

please try with something very simple like this example here, you'll see the basics of transparent code banking at work

from devkitsms.

sverx avatar sverx commented on July 28, 2024 1

I never added SMS_mapCODEBank() in the first place, as that wasn't needed at all.

If you use transparent code banking you don't need to do anything beside declaring the banked code as banked.

from devkitsms.

sverx avatar sverx commented on July 28, 2024

I'm not sure what you want to get here, I wouldn't use both CODEBANK2 and DATABANK2...

anyway the main problem I see here is the linking: you need to specify virtual addresses for the data banks too so it's

-Wl-b_DATABANK2=0x38000 -Wl-b_DATABANK3=0x48000

and you can see why I would use DATABANK3 and DATABANK4 instead.

... oh, wait, unless you want to use bank 2 for BOTH code and data because why not? So you need correct virtual addresses anyway:

-Wl-b_DATABANK2=0x28000 -Wl-b_DATABANK3=0x38000

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

Ah... Thanks!
I want to use both code and data banks.

I will try to use this "-Wl-b_DATABANK2=0x28000 -Wl-b_DATABANK3=0x38000"

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

Hmm.... I could not locate data banks properly...

Could you please tell me the proper way to use both data and code banks ?
I think makesms does not support data bank like ihx2sms does...

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

mmm. Gave up.

>-Wl-b_CODEBANK1=0x14000 -Wl-b_CODEBANK2=0x24000 -Wl-b_CODEBANK3=0x34000 -Wl-b_DATABANK4=0x48000 -Wl-b_DATABANK5=0x58000 -Wl-b_DATABANK6=0x68000

Why the makesms places CODEBANK2 to 8000H in sms file? I think 8000H is ROM/RAM mapper slot 2.

And, makesms places CODEBANK1 to 04000H in sms file. 04000H is #0 of mapper slot 1.
But, SDCC linker treats CODEBANK1 as 14000H, so SDCC changes bank no to #1 of mapper slot 1 when invoking function on the CODEBANK1.

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

did you try something easy like:

oops, i will try.

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

When I use BANK4 data, which number should I specify to the SMS_mapROMBank( xxx ) API ?

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

Bingo! Thank you!

I could run my program, but..... only when I removed "__banked" magic word from a function. Is that okay...?

So, I must write the following codes... ( SMS_mapCODEBank() is my custom API )

       SMS_mapCODEBank(1);
       SMS_mapROMBank(4);
       functionBank1();  // Using BANK4 data

       SMS_mapCODEBank(2);
       SMS_mapROMBank(5);
       functionBank2();   // Using BANK5 data

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

Hmm... Failed... I placed "__banked" keyword to both declaration and function body... mmm...

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

And do you know what means the following compiler warning message ? Can I skip this message?

source.c:17: info 218: z80instructionSize() failed to parse line node, assuming 999 bytes 'b_fuctionBank1 = 1'

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

Thank you so much!

EDIT: OMG.. What is "SMS_EMBED_SEGA_ROM_HEADER_16KB" ...? Do I need to specify this instead of normal header?

My demo program is here.
https://twitter.com/SNDR_SNDL/status/1381956874287808520

from devkitsms.

sverx avatar sverx commented on July 28, 2024

You might want to use that or you might place the regular header on the source code that goes to bank 1 - I would use that _16KB as it's just easier.

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

So sorry.
SMS_mapCODEBank() is deleted on recent version ?

from devkitsms.

110-kenichi avatar 110-kenichi commented on July 28, 2024

Oops.. so sorry. It is my fault...

from devkitsms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.