Contest! Detecting the memory mapper size, closes 08/31/2022.

Page 1/2
| 2

Par MagicBox

Master (209)

Portrait de MagicBox

11-08-2022, 12:39

Hey all,
It's been a long while since posting here. However, recently I have been having some fun with my MSX emulator (BlueMSX) while still having a functional real one, a Philips NMS8245. During this, I wanted a routine that determines correctly and without messing with memory contents the size of the mapper. After having finished it, I thought.. it got pretty nifty! Well, from a perspective of Z80 coding. So I figured, without giving anything away yet, I am curious if anyone could come up with something equal or better. Soooo.... here is the contest! Cool

The goal:
Create a routine that determines the size of the memory mapper in as few bytes as possible. To have the contest stick to the actual detection code, there are some rules that help with comparing the size of the routine and strip it from auxilaries like slot management etc. so only the number of bytes for the detection code is what remains.

Rules:
- Only the fixed sizes ought to be considered: 64K, 128K, 256K, 512KB, 1MB, 2MB and 4MB.
- The routine must return a value that indicates one of the fixed memory mapper sizes in a register.
- No requirement to save registers.
- No requirement to save flags.
- No requirement to handle primary and or secondary slot selection and restore.
- No requirement to test through a specific Z80 page, thus memory mapper register.
- Any memory locations used to test must be restored (no memory corruption)
- Any mapper IO registers must be restored.
- Reading mapper IO registers is not allowed (though would be, on computers supporting it, the fastest way Wink )

So... what would be the prize? Well... that would be the version I cooked up in an assembly file, along with full comments that may have educational value. And ofcourse a big cheers.

So, when you have some time left and feel like a challenge, here it is!

Greetings from Holland,
MagicBox.

!login ou Inscrivez-vous pour poster

Par Eugeny_Brychkov

Paragon (1232)

Portrait de Eugeny_Brychkov

12-08-2022, 11:49

MagicBox wrote:

- Any mapper IO registers must be restored.

It is not possible because original values for mapper registers are not known and you do not allow reading them.

Edit: technically it is possible, but if you do not know source or target mapper register values then requirement for smallest size in bytes must not be the primary one. List requirement for the configuration for code to run in: BASIC/DOS/DOS2? Must check for mapper presence or assume mapper is in there? Size of the code will depend on configuration of the environment.

By scanning data in the slot we can find existence of the RAM in specific pages, but it will not indicate real mapper size: there're machines where actual RAM is less than mapper size, and approximating to next bigger size may not give correct physical mapper size. This way you will find that mapper size is *not less* than some specific size, but hot how big it is.

Par Louthrax

Prophet (2465)

Portrait de Louthrax

12-08-2022, 12:48

That reminds me something I had to do for SofaRunIt (an MSX tool that simulates a floppy drive using hard disk images).

The "fake" MSX-DOS driver of SofaRunIt is located in higher memory mapper pages. When invoked, it has to install itself at 4000-7FFF, perform the disk operations, and then restore the "game" memory mapper segment at 4000-7FFF. But reading memory mapper register is indeed not allowed and not working on some MSX !

I was desperate at the time because SofaRunIt was not working for games using memory mapper on MSX with no mapper "readback" functionnalities.

I finally figured out a workaround by first writing a "signature" at 4000 in the existing game segment (something like "SofaRunItSignature") and backuping the existing game data at that location. When the disk operation is finished, I scan all segments at 4000-7FFF for that signature, which implies doing up to 255 OUTs to 0xFD (writing to the mapper segments is kind of allowed, at least it works on all MSX). When the magic signature is found, I restore the game data and return. That approach is kind of slow, but that time is very small anyway compared to the disk operation itself.

Par sdsnatcher73

Prophet (3951)

Portrait de sdsnatcher73

12-08-2022, 12:53

The most common mapper size in MSX is 64kB…

Par gdx

Enlighted (6212)

Portrait de gdx

12-08-2022, 13:57

As Eugeny and sdsnatcher73 pointed out, your contest goes on bad bases.

It is impossible to know the values of the memory mapper registers directly except in two cases.

1/ when the MSX has an internal mapper and if it has no other added mapper of different size.
2/ Just after starting the MSX.

Indirectly, perhaps it is possible by writing values in the RAM and changing segment as you go in the deduction, and also taking care to restore the contents of the RAM just after.

You can see my routines used in BMMS and DBMM if you want.
https://github.com/gdx-msx/BMMS
https://github.com/gdx-msx/DBMM

They consider that the FCH-FFH registers have the initial values to work.

Par MagicBox

Master (209)

Portrait de MagicBox

12-08-2022, 14:12

LOL you're completely right. In fact my version does read before it starts flipping pages. Soooo, yes, that one particular requirement may be dropped! Oooo saves me another few opcodes Wink

Par Eugeny_Brychkov

Paragon (1232)

Portrait de Eugeny_Brychkov

12-08-2022, 14:18

Gave it some more thought after reading replies. By accessing RAM you can only find out the size of RAM in the mapper. You can not know size of mapper without writing 0 to mapper register and then reading value back seeing how many 0s you actually read. But in this case you obtain mapper size with maximal capacity, there's no guarantee that there're no more mappers of smaller sizes, and that smaller mapper is not accidentally located in the slot you are looking in.

Question: what is the practical application of the resulting code? Why do you need to know size of mapper (rather than size of available RAM in the mapper)?

Par MagicBox

Master (209)

Portrait de MagicBox

12-08-2022, 14:29

sdsnatcher73 wrote:

The most common mapper size in MSX is 64kB…

That's right, so that size oughtta be included as well. Unfortunately I can not update the main post any more to remove the requirement addressed by a previous poster.

So, in summary, the requirement updates are as follows:

- Include 64KB as a fixed size.
- The save the mapper IO page requirement can be dropped.

In my code, it was a mere flipping of one bit in an immediate value somewhere in the code to support a 64K detect at no extra cost in bytes Tongue

As far as a general notice goes, I am not assuming that a given mapper size does not sport available memory pages. It would mean that there are full or partial empty pages and I would not consider that a 'complete' mapper. So I wonder, the machine that is being talked about with only partial ram available in the allotted banks, which machine is it? Is the mapper homebrew?

Back in the days when I still went to the MTS (tech school in the Netherlands) I made myself a homebrew internal memory mapper with a mapper size of 1MB, using 8 256Kx4 DRAMs. However, since back then I gave away 4 ICs to fix a PC of a friend with broken RAMs, I only had 512K in it. It was sufficient for most disks I played, save copying disks in one go. And yes, this is a situation where there were 32 blank pages, returning all FF's for the memory locations. Recently I bought a brand new set of 256Kx4 ICs off E-bay, and now there's 1MB sitting in there again, all with the same ICs! I save the 4 remaining I had. Back in the days I used ICs of various manufacturers and it still worked as they all met the access time required.

As far as multiple memory mappers go, I don't think the routine should have trouble with it when the testing is confined to the (sub)slot of one of the mappers. The other will 'dance along' when setting the IO ports, but that will not affect the test for the one you're testing.

Par MagicBox

Master (209)

Portrait de MagicBox

12-08-2022, 14:41

Eugeny_Brychkov wrote:

Question: what is the practical application of the resulting code? Why do you need to know size of mapper (rather than size of available RAM in the mapper)?

See reply above, because it would normally reflect the actual size of the available RAM in the slot containing the mapper. So in the end, to determine the available RAM in slot, whether this RAM is mapped or not.

And that is highly likely why the MSX2 standard made these ports write-only, so that 'duplicated' mapper hardware (example, both internal and external through a cartridge slot) will not cause bus congestion when the ports are read. Multiple mapper register implementations ofcourse may all respond to the same write.
As an idea, I'm tempted to make a 4MB cartridge that would be just like any other cartridge. But, that's a project for when I retire, still some 20 years from now on lol. The CPLD housing the logic would decode the full address bus and have it's own mapper write-only ports.

The internal mapper I made however, does offer read functionality, but since the values are the same, there is no buscongestion; Though for the upper bits, it may possibly short the MSX engine bits, but I remember having tested in the past for these data pins to be 3-state; undriven. The computer still works haha. In retrospect, this means that if one goes by reading the mapper registers to find out the size, one gets the largest size available. Regardless, reading the IO registers had been forbidden as a requirement and the size detecting code should work only on a per-slot basis where one has to manage slots oneself. This contest is about determining the size within a given slot without further assumption about other existing mappers.

Par Briqunullus

Hero (665)

Portrait de Briqunullus

12-08-2022, 15:00

Is the source code of MemMan available somewhere?

Par gdx

Enlighted (6212)

Portrait de gdx

12-08-2022, 16:06

MagicBox wrote:

The internal mapper I made however, does offer read functionality, but since the values are the same, there is no buscongestion; Though for the upper bits, it may possibly short the MSX engine bits, but I remember having tested in the past for these data pins to be 3-state; undriven. The computer still works haha.

It doesn't always work. MSXs that don't have a problem with this probably have circuitry designed to prevent shorting, but that's not always the case. Especially those who have been upgraded. I've heard the story before of people fried the circuit of the MSX and/or another external mapper. Those who make mapper cartridges should not make register reading possible, or only optional and with a warning.

Page 1/2
| 2