How to handle the Rom/Ram memory slots?

Page 1/2
| 2

By Prodatron

Paragon (1857)

Prodatron's picture

07-05-2006, 12:10

Hi,

I played around a little bit with the ram and rom banking of the MSX2.
As an information source I used this document:
http://www.work.de/nocash/portar.txt

In section "Memory" I found the description of the slot register and the memory mapper.

What I want is to hide all roms, so that I see the full 64K ram (which I may swap with the ports #FC-#FF).

So I did the following:
ld bc,#ffa8
out (c),b
ld a,#aa
ld (#ffff),a

This seems to work. I just wonder if this is the best way to hide all roms/catridges/mapped IOs, or do I need to consider something else?

CU,
Prodatron

Login or register to post comments

By Edwin

Paragon (1182)

Edwin's picture

07-05-2006, 12:36

That is a rather static solution. It will not work on all machines. While I think every MSX2 and higher has its internal memory in slot 3, it's certainly not always in subslot 2. Also, there could be a larger memory mapper in one of the expansion slots, which you may want to use as primary or extra memory. Except for turbo R machines where internal memory is a great deal faster than memory in expansions.
Basically you will have to figure out what is where first. This stuff has all been done before though. So code or methods may be readily available.

If you need to discuss some topics you can find quite a few people on IRC (#msx, #msxdev, #msxdev). I can usually be found in #msxdev @ Rizon.

By Sonic_aka_T

Enlighted (4130)

Sonic_aka_T's picture

07-05-2006, 14:38

Personally I'd start developing by loading SymbOS from MSX-DOS. You'll already have RAM present at all pages, and there's no need to phase out MSX-BASIC. If you want, you could later always make a loader that also works from BASIC, but I doubt many people will have a particular need for that.

By the time you're ready to fire up SymbOS the MSX BIOS will already be installed. This means that most of the slot-info is already available. You can check EXPTBL to see if each of the primary slots is expanded or not. EXPTBL is located at address $FCC1 - $FCC4. If bit 7 of the byte is set, then the slot it expanded.

When in DOS, you can check RAMAD0 to find the slot address of the primary mapper. Again, bit 7 indicates if it's an expanded slot, the lowest 4 bits indicate the primary and secondary slot number. On $F348 you can find the slot address of the primary disk ROM, this is only set if there is a disk ROM, but DOS requires one to boot anyways. $FB22, $FB24, $FB26 and $FB28 contain the slot-addresses of the first 4 disk ROMs. The byte that follows the slot-address contains the amount of drives found.

Check http://map.tni.nl/ for some more system variables. They can be very handy and save you a few checks. The mapper system is pretty straight forward, just do an OUT to ports $FC - $FF to change a bank in the ranges $0000, $4000, $8000 and $C000. Remember the MSX does an RST $38 each time the VDP (or anything else) generates an interrupt, so if you're paging something out, you'll want to be sure you do this with interrupts disabled, or a proper interrupt handler present at $0038.

By Edwin

Paragon (1182)

Edwin's picture

07-05-2006, 15:00

What you're suggesting may seem easy, but I doubt it really is. MSX-DOS has a lot of quirks you will have to live with if you're trying to run something under that. And the variables you mention are set even if DOS isn't started. Plus, IIRC, SymbOS was designed with the system running in the high memory range, which you can't touch if you allow things to run through the BIOS. All in all, it may require a lot of patching to the system to make it run. Which is all wasted effort in the end.

BTW, Prodatron, which interrupt mode do you use in SymbOS?

By Prodatron

Paragon (1857)

Prodatron's picture

07-05-2006, 15:41

Regarding the starting point: Currently I start my code from basic, as I use the "autoexec.bas" like described in the "cross compiler" thread. Btw, how do I switch from Basic to MSX-DOS? If I type "call system" I get an "illegal function call". Currently I am using the startard MSX2 configuration in BlueMSX.
Regarding the methode, how to hide all ROMs/catridges/etc: Ok, so I will need a better function here or I could use Tobis hints. This small code I posted seems to work so far with my config, so I could do the improvement later. Now the most important thing is, that I can always use the #FC-#FF ports for changing the memory banking.
@Edwin: You spoke about primary/extra/internal/external memory. Can it all be addressed via these four ports?
@Sonic_aka_T: Yes, on the CPC I need a handler at #38 in every ram bank, too.
I use IM 1 in SymbOS, so I also can use the I-register. In SymbOS it's used to store the current RAM memory configuration.

Thanx a lot for your help! It's very exciting to start coding on the MSX Smile

By Prodatron

Paragon (1857)

Prodatron's picture

07-05-2006, 15:51

Another question: Is it possible in Basic to load a binary into the extended memory (>64K) or in the RAM blocks 2 and 3 (#0000-#7ffff)?

By Manuel

Ascended (19678)

Manuel's picture

07-05-2006, 15:57

Some short hints and comments:
- MSX-DOS 1 can only be started from basic if you already booted the system with DOS. Unless you do a POKE &HF346,1 to fake this Smile
- Use I/O port 0xA8 to select the primary slot for each 16k page, use address 0xFFFF of those slots to select the secondary slot. See: http://map.tni.nl/resources/msx_io_ports.php#ppi

By Edwin

Paragon (1182)

Edwin's picture

07-05-2006, 17:09

@Edwin: You spoke about primary/extra/internal/external memory. Can it all be addressed via these four ports?

Internal/external is just the physical location. It only matters on turbo R machines because external access gets delayed when in R800 mode. Primary is what the system selects ase the base mapper (that could be either the internal memory or a cartrigdge). It is possible to use multiple mappers as well, although it is a bit slower due to the slot switching that must be done.
Basically, at startup you need to find it all by looping through all (sub)slots and then through the mapper segments (through one of the ports $FC..FF) and find out if there is memory. You can use $FCC1..4 to find out if a slot is subslotted or not since those values are set at startup anyway.

I use IM 1 in SymbOS, so I also can use the I-register. In SymbOS it's used to store the current RAM memory configuration.

Good. I was worried for a bit that you could be using IM2, which won't work on MSX.

I don't know what you want to do with basic and how much space you need. But, IIRC, you can set the start address of where basic programs are stored (here). If you set it above $C000, you have page 2 ($8000-$BFFF) free for switching, even from basic.

By norakomi

Paragon (1150)

norakomi's picture

07-05-2006, 18:18

Btw, how do I switch from Basic to MSX-DOS? If I type "call system" I get an "illegal function call". start with putting a dos disk in the drive Tongue(doh), then type poke&hf346,1:_system

By msd

Paragon (1532)

msd's picture

07-05-2006, 19:23

MSX-DOS has a lot of quirks you will have to live with if you're trying to run something under that. Like what?

By Prodatron

Paragon (1857)

Prodatron's picture

07-05-2006, 19:54

Another question:
Currently I am trying to get the kernel up and running on the MSX2. I use BlueMSX for testing. As I said, SymbOS is running in IM1 and I have the interrupt handler installed at #38. While the interrupt routine works (maybe about 100-150 instructions), the interrupts of course are disabled.
In the blueMSX debugger I see, that everytime when it should leave the interrupt routine with EI:RET a new interrupt is triggered directly after the EI command?! So I am sticked in the interrupt routine. Why could this happen? I thought, only the VDP generates an interrupt 50times/second?

Page 1/2
| 2