About the address map when execute a rom created with ZCC

Post Reply
masushin
New member
Posts: 3
Joined: Sun Sep 26, 2021 6:30 am

About the address map when execute a rom created with ZCC

Post by masushin »

I have a question about a ROM created by "zcc +msx -subtype=rom".
The C source code is simple as shown below.

Code: Select all

#include <stdio.h>
#include <msx.h>

void main()
{
  msx_screen(1);
  printf("Test Program..");
  while(1){
  }
}
I build it.

Code: Select all

$ zcc +msx -lmsxbios -create-app -subtype=rom -o test.rom test.c
Run it with openMSX.

Code: Select all

$ openmsx test.rom
It works fine.
The size of the ROM created is 16KB. So I expected the address map would be as follows.

0x0000 (Page0) : Slot 0
0x4000 (Page1) : Slot 1 (Created ROM)
0x8000 (Page2) : Slot 3-2 RAM
0xc000 (Page3) : Slot 3-2 RAM

However, the actual result is as follows.

0x0000 (Page0) : Slot 0
0x4000 (Page1) : Slot 1 (Created ROM)
0x8000 (Page2) : Slot 1 (Created ROM ?)
0xc000 (Page3) : Slot 3-2 RAM


The following code was included at the beginning of the INIT entry of the created ROM when viewed in the debugger.

...

Code: Select all

start:
4010    di
4011    ld     sp,(#fc4a)
4015    ei
4016    in     a,(#a8)
4018    and    #cf
401A    ld     d,a
401D    and    #0c
401F    add    a,a
4020    add    a,a
4021    or     d
4022    out    (#a8),a
...

This seems to me to make the slot of Page2 the same slot as Page1.
Why is this process inserted? Is it necessary?
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: About the address map when execute a rom created with ZCC

Post by Timmy »

The effect that the 16K ROM is read twice is called ROM mirroring. It is what some MSX machines do (probably), and emulators.

Also, MSX(1) machines can have as little as 8K or 16K of RAM (they can also have more). And duplicating RAM means that you could have your system variables duplicated, and everywhere.

You can still make 32K ROMs if you don't like the duplication, but the current set up means that your ROMs are compatible with most emulators and machines. Or make tape games, where it is assumed there is a lot of RAM available.

External link about this mirroring issue (example):
https://www.msx.org/forum/msx-talk/deve ... hstke-hook
masushin
New member
Posts: 3
Joined: Sun Sep 26, 2021 6:30 am

Re: About the address map when execute a rom created with ZCC

Post by masushin »

Thanks for the reply.
I'm also interested in the information on external links.


I confuse a little.

The test.rom generated by ZCC contains the code to perform ROM mirroring.

In other words, executing ROM generated by z88dk will performe ROM mirroring on all environments (whether emulator or actual machine).

So, this behavior is a specification of z88dk is seem to me, but is it not? There are not compile option that can generate ROM without ROM mirroring (without change the slot of Page2) ?
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: About the address map when execute a rom created with ZCC

Post by Timmy »

masushin wrote: Sun Sep 26, 2021 4:26 pm So, this behavior is a specification of z88dk is seem to me, but is it not? There are not compile option that can generate ROM without ROM mirroring (without change the slot of Page2) ?
Sorry, I was confused by your question. I needed to re-read it many times. I think I understand it now.

The instructions for -subtype=rom can be found in another thread:
Timmy wrote: Fri Apr 11, 2014 12:13 pm This new current target is a very minimal build, and it creates a ROM file, starting at 16384 (dec) with a size of 32768, RAM is stored from 49152 upwards, and system ROM from 0-16383. Some MSX system variables are stored at the top end of the RAM (near 65535), and if you use this target SP is set to a place where you can use the stack freely.

This ROM cartridge format does not require any proprietary MSX OS to be run, so it's also working on emulators using C-BIOS.
In other words, it supports *ONLY* 32K ROMs with 16K RAM. From my experience I can also generate 4K ROMs with it, but it will still come with only 16K RAM.

There were no other options because this is the easiest model to support, the easiest to make games in, what users have asked, what most MSX machines have, and it was the only information I could find on making ROMs back then. Even in 2021 this still seems to be the most logical option. Supporting 32K ram in the default rom target would be just a lot of work. There will be much more code, instructions that people can't find, and many more questions (like, why would I get disqualified for using 32K RAM in MSXDev, or does this work on machines that don't have 32k RAM). And I'd rather make more games.

Fortunately, you can write your own msx target within z88dk. You can change in your own build of z88dk and modify the existing rom target to support 32K RAM for yourself. You can even call it "romwith32kram" or something, and you can add your own options in them. And you can provide all the support, obviously.
masushin
New member
Posts: 3
Joined: Sun Sep 26, 2021 6:30 am

Re: About the address map when execute a rom created with ZCC

Post by masushin »

Thank you very much for your reply again.
And I am sorry for confusing you with my poor question.

I understood that the address layout of ROM file generated by the subtype=rom option of the current Z88DK is desidgned with considerring to be able to support almost all models.

In case of acceptable the restriction that it only works for some models, I will try to add "romwith32kram" (as you say), or add my own routine to switch the page slot.

Thank you again for your time.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: About the address map when execute a rom created with ZCC

Post by dom »

I'm obviously not an MSX expert but I think from reading docs it needs to be something like this:

Code: Select all

    in      a,($A8)
    and     a, @11001111
    ld      d,a
    in      a,($A8)
    rrca
    rrca
    and     @00110000
    or      d
    out     ($A8),a
That is take the slot from segment 3, apply it to segment 2. Though as Timmy said, what memory is mapped there will depend on the hardware.

If that's it then adding a link time option to allow it is pretty trivial and I don't mind adding that as an alternative option albeit with caveats.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: About the address map when execute a rom created with ZCC

Post by Timmy »

I must say I haven't looked into the mappings, so if you can supply the code then it's easiest for everyone.

I have no objection of new link time option being added, as long as the default is still the original, and that games using this new option needs to know what they are doing. Like checking that there exists actually 32K memory in your MSX model and display a message if it doesn't. This can be done outside the initialisation routine.

Is there a compiler variable that defines where RAM starts? If so, then that should be part of the option too. (I'm trying to read the latest version of the ROM init code and it's too hard for me to read nowadays.)

During the current MSXDev, 2 games were disqualified because they were using 32K ram. This is one of the reason I hope the default will still be 16K RAM. Also, for 99% of the games the easiest setup is still 32K ROM with 16K RAM.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: About the address map when execute a rom created with ZCC

Post by Timmy »

I will also note that you need to test this with all emulators as well. It's not our problem if any emulator doesn't support your game. They might have to add exceptions each time you make a new game. Fortunately this won't happen very often. :)
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: About the address map when execute a rom created with ZCC

Post by dom »

Timmy wrote: Thu Sep 30, 2021 9:43 amIs there a compiler variable that defines where RAM starts? If so, then that should be part of the option too. (I'm trying to read the latest version of the ROM init code and it's too hard for me to read nowadays.)
-pragma-define:CRT_ORG_BSS=nnnnn is the option you need
Post Reply