Placing a .ROM file in a virtual cartridge slot

Par aoineko

Master (165)

Portrait de aoineko

15-07-2021, 21:42

Following some problems I had with the 48K ROM of my game, Final Smash, I was wondering how emulators guess how to place a .ROM file in a virtual cartridge slot? For example, how do they know whether the beginning of the .ROM should be placed at 0000h or 4000h? The only information that is stored in the ROM is the header (which must be on a multiple of 4000h address) and the start address of the program (which can be anywhere). In my case, the ROM must be placed at address 0000h (which works fine on all emulators I've tested), but if I had made a 48K ROM that is supposed to be placed at 4000h, how would they know?
Do they use the start address of the program to guess where to place the page of the ROM that contains the header and, by deduction, the first page of the ROM?
If so, a ROM with the program start address that is not on the same page as the header would not be correctly detected.

Do the flash tools for FlashROMs use the same logic to know where to place the .ROM in the EPROM?

For ROM Mapper, I saw that OpenMSX looks for the addresses where the program writes the most to guess which mapper is supposed to be used. I imagine that other emulators and flash tools use the same method.

!login ou Inscrivez-vous pour poster

Par Grauw

Ascended (10056)

Portrait de Grauw

15-07-2021, 23:24

Looking at the openMSX guessing source code, for 48K ROMs guesses the ROM_MIRRORED mapping, and then guesses the ROM’s start address based on the four addresses in the “AB” signature at offset 0000H and 4000H of the ROM file. It counts which pages are referred to, and in case of a tie it prefers 4000H > 0000H > 8000H. So for openMSX to guess a 48K ROM correctly, you’ll want the init routine to be in the first page of the ROM.

In the end the only reliable way to is to specify the ROM mapping explicitly using command line arguments. There is no standard guessing algorithm across different ROM loading tools & emulators.

Par gdx

Enlighted (4693)

Portrait de gdx

16-07-2021, 02:47

Take a look in the source code of ROM2MMM. Detection is fairly reliable for ROMs up to 64kB thank to Memory Mapper.

Basically, it proceeds like this:

  1. If ROM file size = 8K then it copies the ROM to 4000h, 6000h, 8000h and A000h.
  2. If ROM file size = 16K then it copies the ROM to 4000h and 8000h.
  3. If ROM file size = 32K then it checks the both headers to copy it either at 0000h, 4000h or 8000h.
    You must check if the header (41 42) is present and ckeck the bit 7 and 6 of start address and check also the bit 7 of the Basic program pointer.
  4. If ROM file size = 48K then check the header 1 and 2 to place the ROM to 0000h or 4000h. If the header is present only at file start, the ROM is probably using a mapper. (If no Memory mapper it can't be loaded to 4000h)
  5. If ROM file size = 64K then check if the header is present at file start. If so, the ROM is probably using a mapper. (If no Memory mapper 64K ROM can't be loaded in RAM)

Then, just do a softreset to launch the ROM.

I'm saying this from memory so there are probably some cases that I'm forgetting, and it is possible to add options to force the rare cases that escape autodetection to be placed in the right place.

Par gdx

Enlighted (4693)

Portrait de gdx

16-07-2021, 15:09

In fact, this method cannot be used as it is for loading in RAM. The MMM has a write-protect mode.
When the ROM is in RAM, it is probably not possible to boot the ROM with a reset. You have to use tips for ROMs that contain a BASIC program or that use the disk. These tips are not always reliable.