MSX1 pages and slots

Page 1/7
| 2 | 3 | 4 | 5 | 6

By tokumaru

Expert (83)

tokumaru's picture

03-07-2006, 20:07

Hello. I'm really close to understanding how the pages and slots work. I just have a few more questions.

How would I go about assigning cartridge ROM to page 0? I know that the first few bytes of a ROM identify the cart, and specify an start address. But How does that take part in placing ROM at page 0? If most 16 or 32KB ROMS start execution at $4010 (after the header) what is physically present at $0000-$3FFF in the cartridge slot? If I have a 64KB ROM, how the heck can I access all of it (no bankswitching, say I want to map all 4 pages to my ROM)?

I think the only way to have your own VBlank interrupt is to place either your own ROM or RAM in page 0. Let's say I want to map RAM there, but my system has only 8KB of RAM (wich would physically be at E000-FFFF). If the RAM is at the end of the addressing space, is there anyway to access it in page 0? When less than 64KB of RAM is present, is it by any chance mirrored through the rest of the space? That would sure solve things.

Also, how can I know which slot contains what? Could the value read from port A8h be used to identify the RAM slot (always in page 3 by the time ROM execution starts?)? How would I know what slot is my cartridge/ROM running from?

Thanks for all the help.

Login or register to post comments

By Edwin

Paragon (1182)

Edwin's picture

03-07-2006, 20:50

The only cart that starts at $0 is a 48KB ROM. (see msxdev05 for two examples) You still have your "AB"+start_address header at $4000 though. After that you find out the slot you run from and set page 2 and 0 to that slot. (disasm some existing roms for practical examples if you need any). I'm not sure if any 64KB ROMS exist that also have page 3 in ROM. I'm not even sure it's possible. All existing 64KB roms are mappers that only have ROM in page 1&2.

You're right about the interrupt handler. You can only place that in RAM if you have at least 64Kb of memory. A 48KB ROM would make it possible. Which is the option I used in Universe: Unknown.

As for the detection, disasm some >16KB ROMs. Most will have approximately the same thing right at the beginning.

By tokumaru

Expert (83)

tokumaru's picture

03-07-2006, 21:25

You still have your "AB"+start_address header at $4000 though.
I see. I was having a hard time understanding this because when you view a ROM file in an hex editor, most have "AB" + start_address right at the beginning, but that place would be mapped to $4000, even though it was at the beggining of the file. That is whay I couldn't understand how would you have anything before that. By what you are saying, I guess ROM size is what determines it, then.

After that you find out the slot you run from and set page 2 and 0 to that slot. (disasm some existing roms for practical examples if you need any).
OK, that would result in your ROM at pages 0, 1 and 2 and RAM at page 3, right? I guess that's OK. I'll look at some disassembled games, but I'm guessing you just have to read from port A8h and see what slot is used in page 1 (where ROM execution begins), is that right?

I'm not sure if any 64KB ROMS exist that also have page 3 in ROM. I'm not even sure it's possible. All existing 64KB roms are mappers that only have ROM in page 1&2.
I read in some MSX docs that it would be possible to have a 64KB ROM without mappers, although no commercial cartridges do it. I think it would be OK, the last page could have some sort of simple data, like graphics, that you can read and output to VRAM directly, without needing any RAM. After the transfer is done, put RAM back at page 3. That could work, right?

You're right about the interrupt handler. You can only place that in RAM if you have at least 64Kb of memory. A 48KB ROM would make it possible. Which is the option I used in Universe: Unknown.
I see. No RAM mirroring, then! BTW, your game is pretty nice! =)

As for the detection, disasm some >16KB ROMs. Most will have approximately the same thing right at the beginning.
OK, I will. Thanks for the help.

By DamageX

Master (216)

DamageX's picture

03-07-2006, 23:40

I use this code to setup pages 0,1,2 to ROM for a 48K game. I tested it in blueMSX and it seems to work in any slot/subslot but I'm new to Z80 assembly so be warned... (seems a bit long doesn't it?)

        di
        in a,($A8)              
        rrca
        rrca
        and 3                   ; which slot are we?
        ld c,a
        ld b,0                  
        ld hl,$FCC1             
        add hl,bc               
        cp (hl)               ; is it a subslot?
        jp m,a6
        in a,($A8)            ; nope, that makes it easy
        and $CC
        or c
        sla c
        sla c
        sla c
        sla c
        or c
        out ($A8),a
        jr a7
a6
        inc hl                  ; is a subslot so more work to do
        inc hl
        inc hl
        inc hl
        ld a,(hl)
        and $CC
        ld b,a
        and $0C
        ld c,a
        srl c
        srl c
        sla a
        sla a
        or b
        or c
        ld e,a

        in a,($A8)
        and $CC
        ld b,a
        and $0C
        ld c,a
        srl c
        srl c
        sla a
        sla a
        or b
        or c
        ld d,a

        sla a
        sla a
        out ($A8),a
        ld a,e
        ld ($FFFF),a            ;
        ld a,d                  ; phew!
        out ($A8),a             ;

a7        
        ei

By BiFi

Enlighted (4348)

BiFi's picture

04-07-2006, 07:11

There is a shorter method... using an interslotcall that never returns to select your ROM in page 0 (nicely ripped from The Cure and Universe: Unknown Smile)... which basically means you call an address in page 0 of your own ROM which jumps to the rest of your init routine.

By tokumaru

Expert (83)

tokumaru's picture

04-07-2006, 15:54

I understood the code that DamageX posted (wich is pretty much what I had in mind - although I still have some catching up to do on the subslot thing), but not exactly what BiFi said. How can you call and address in page 0 if your ROM is not there yet? (I will take a look at the disassembly of those games)

By BiFi

Enlighted (4348)

BiFi's picture

04-07-2006, 19:19

There is a BIOS routine called CALSLT (address $1c) which enables you to call a routine in a different slot. Put the address you want to call in IX and the slot in the high part of IY (something like

LD A,(slot)
PUSH AF
POP IY

) before you call the routine. CALSLT will do the slot switching for you before the address is called. Also check the MSX Assembly Pages.

By tokumaru

Expert (83)

tokumaru's picture

15-07-2006, 01:30

I think I finally understand how the secondary slots work. I plan on testing a few things when I have the time to make sure I got it right.

Say I don't want to use any BIOS routines, for whatever reason. Would I be able to set up the slots/subslots like this?

1. check the slot you are running from (by reading $A8);
2. set that same slot to page 3, and any other pages you want;
3. check wich subslot you are running from (by reading $FFFF);
4. set that slot to all the pages you'll be using;
5. put RAM back into page 3;

I guess I could always do it that way, even if a secondary slot is not beeing used, right? If by any chance $FFFF is not the secondary slot register, I'll just be performing some dummy math with that
memory location... right? Or will writing back to it cause any trouble? Is it mandatory that I check if the program is running from a subslot?

By NYYRIKKI

Enlighted (5457)

NYYRIKKI's picture

15-07-2006, 02:04

tokumaru: Yes, you are absolutely right. Only note that all bits are inverted when you read the address #FFFF

By tokumaru

Expert (83)

tokumaru's picture

15-07-2006, 20:48

OK, bits inverted, I knew that one! =)

Well, good to know there is a way to do it simply and directly, without worrying about the different kinds of set-ups. I'll test all this stuff really soon, on my actual MSX (not an emulator) if possible.

By ARTRAG

Enlighted (6330)

ARTRAG's picture

18-07-2006, 13:11

One question:

I have noted that MSX Cbios runs the rom images even if the signature "AB"+initaddress is on page 0.

Does it happen also on the MSX1/2 standard roms ?

Page 1/7
| 2 | 3 | 4 | 5 | 6