MSX1 pages and slots

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

Van ARTRAG

Enlighted (6550)

afbeelding van ARTRAG

02-09-2006, 11:10

This is the complete source of the rom boot sequence.
I have corrected some errors and now the ROM is recognized by all the C-BIOS roms (msx1,2 & 2+)
but NOT by the standard MSX roms.
They simply ignore my rom and go to basic

;
; $Id: myrtz80-s.as,v 0.01 31/08/2006 11:45:15 art rag $
;
; Runtime startoff module Z80 compiler.  ROM version
;
; 
;
    psect   text,global,pure,class=CODE
    psect   vectors,ovrld,global,pure,class=CODE
    psect   lowtext,class=CODE
    psect   data,global,class=DATA
    psect   bss,global,class=DATA
    psect   stack,global,class=DATA
    psect   strings,global,pure,class=CODE
    psect   const,global,pure,class=CODE
    psect   baseram,global,class=DATA,reloc=1000h
    psect   im2vecs,ovrld,class=CODE
    psect   ramstart,global,class=DATA
    psect   heap,global,class=DATA
    psect   nvram,global,class=DATA

    global  small_model
small_model equ 1

    psect   vectors

    
    global  start,_main,_exit,__Hstack,__Hbss, __Lbss
    global  __Ldata, __Hdata, __Lconst

;   MSX ROM Header

    org 0000h

    defb 'A','B'
    defw start


    org 0038h

SAT equ   0x1b00       ; Sprite Attribute Table    

    global  _vdps0, _curr_plan, _n_sprt, _sprt

;   RST 38 handler

    ex  af,af'
    exx
   
    in  a,(0x99)
    ld  (_vdps0),a

    bit 06h,a
    jp  z,3f            
                
    and 31
    add a,a
    add a,a
    ld  b,a
    ld  a,(_curr_plan)
    add a,b
    ld  e,a                 ; curr_plan + = (vdps0 & 31)*4;

    ld  a,(_n_sprt)
    ld  c,a

;   In A rest of E / C

    xor a
    ld b,8
2:
    rl e
    rla
    sub c
    jr nc,1f
    add a,c
1:
    djnz 2b

    and a
    jp  z,3f                        

    ld  (_curr_plan),a      ; curr_plan -= (curr_plan/(n_sprt)) * (n_sprt);
    ld  e,a

    ld  a,SAT & 255
    out (0x99),a
    ld  a,SAT/256 | 64
    out (0x99),a

    ld  hl,_sprt
    ld  d,0
    add hl,de           ; hl = sprt + curr_plan
    ld  c,0x98
    ld  a,(_n_sprt)
    sub e
    ld  b,a             ;  b = n_sprt -curr_plan
    otir
    ld  hl,_sprt        ; hl = sprt
    ld  b,e             ;  b = curr_plan
    otir
    jp    1f
3:
    ld  a,SAT & 255
    out (0x99),a
    ld  a,SAT/256 | 64
    out (0x99),a

    xor a
    ld  (_curr_plan),a

    ld  hl,_sprt
    ld  c,0x98
    ld  a,(_n_sprt)
    ld  b,a
    otir
    
1:
    ld  a,208
    out (0x98),a    
    
    ex  af,af'
    exx
    ei
    ret

start:
    di
    ld  sp,__Hstack-1   ;top of stack area
    inc sp
    ld  de,__Lbss   ;Start of BSS segment
    or  a       ;clear carry
    ld  hl,__Hbss
    sbc hl,de       ;size of uninitialized data area
    ld  c,l
    ld  b,h
    dec bc  
    ld  l,e
    ld  h,d
    inc de
    ld  (hl),0
    ldir            ;clear memory

;   now copy data psect if necessary

    ld  hl,seg __Ldata
    ld  de,seg __Lconst
    or  a
    sbc hl,de
    jr  z,1f
    ld  hl,seg __Ldata
    ld  de,__Ldata  ;get load and link base of data psect
    or  a
    sbc hl,de       ;subtract and compare
    jr  z,1f        ;same - no copying to be done
    ld  hl,__Hdata  ;get top to find size
    or  a
    sbc hl,de       ;calculate size
    jr  z,1f        ;zero, still nothing to be done
    ld  c,l
    ld  b,h     ;move count to BC
    ld  hl,seg __Ldata  ;get source address again
    ldir            ;copy it

1:

; set pages and subslot

    in a,(0xA8)
    and 0xC0
    ld b,a             ; which slot is for ram (page 3)?

    in a,(0xA8)
    and 3              ; which slot are we in (for page 0)?
    ld c,a

    sla a
    sla a
    or c
    sla a
    sla a
    or c
    or b

    ld e,a             ; page 0,1 & 2 are at the same primary slot of page 0
                       ; page 3 stay unchanged
    rrc c
    rrc c
    in a,(0xA8)
    and 0x3F
    or c
    out (0xA8),a       ; page 3 is set to the same primary slot that was of page 0

    ld a,(-1)
    cpl
    and 0xC0
    ld b,a             ; which sub slot is for ram (at page 3)?    

    ld a,(-1)
    cpl
    and 3              ; which sub slot are we in (for page 0)?
    ld c,a

    sla a
    sla a
    or c
    sla a
    sla a
    or c
    or b
    ld (-1),a          ; page 0,1 & 2 are at the same sub slot of page 0
                       ; page 3 has subslot unchanged

    ld a,e
    out (0xA8),a       ; page 0,1 & 2 are at the same primary slot of page 0
                       ; page 3 is unchanged


;   Run the main
    call    _main
    signat  _exit,4152
_exit:
    jp  start           ; reset




    psect   bss
;
;   Vector table used by "set_vector()"
;   ***Dummy: needed by the compiler
;
__vectors:
bdosvec:    defs    3



Any idea ? If someone has an Idea I can send him the resulting rom (that boots only in c-bios)

Van NYYRIKKI

Enlighted (5877)

afbeelding van NYYRIKKI

02-09-2006, 21:58

I don't think it's gonna work if you don't burn it to ROM. To emulate this, make sure the file is exactly 16KB long and then copy it after it self to make it 32KB ROM. I don't know emulators too well, but if you find something like "16KB mirrored" it might do the trick as well.

Idea is to ignore at least bit 15 of the address bus. In this case other high bits can be ignored as well, but to make it boot whole address should not be handled. Copying 16KB file to it self emulates ignoring bits 14 & 15. (Ignore = not connected)

Van ARTRAG

Enlighted (6550)

afbeelding van ARTRAG

02-09-2006, 23:41

But this means that I cannot use this trick in 48K roms or in any other rom with size >16K !!
This is very strange as Crazy Train is 32K and has AB at 0000h (and not at 4000h) and seems to work
without setting the pages...
How does it happen?

Van NYYRIKKI

Enlighted (5877)

afbeelding van NYYRIKKI

03-09-2006, 15:23

I think, that you can find a copy of the 32KB ROM in #8000

Van ARTRAG

Enlighted (6550)

afbeelding van ARTRAG

03-09-2006, 17:58

For 32K it make sense, but if I do a megarom of 128K I cannot use any mirroring effect,
as the address 0000h would fall in page 0.
Is it correct?

Van ARTRAG

Enlighted (6550)

afbeelding van ARTRAG

20-10-2014, 09:06

Sparkie, juno First, Crazy Train
All these roms have start address in page 0 but are detected in page 1...
A mystery to me, has anyone a link to good explanation?

Van Guillian

Prophet (3450)

afbeelding van Guillian

20-10-2014, 09:26

Bios checks ROM in page 1 and 2. If it detects a ROM header jumps to the init address (using an interslot call) wherever it is.

Van Grauw

Ascended (10068)

afbeelding van Grauw

20-10-2014, 09:48

Note that some (many?) 32K ROM dumps have pages 1 & 2 swapped. The emulator auto-detects this by searching for the "AB" header and checking the start address.

Van DamnedAngel

Master (232)

afbeelding van DamnedAngel

07-02-2020, 05:58

I have a question regarding booting cartridges which does not map into the previously discussed ones, but I though it would fit nicely in this topic.

I am sorry if I am improperly hijacking the thread.

My question is: I am writing a very basic ROM sample project (for my Visual Studio Templates pack) and I got it working (it just prints a hello message and RET to BASIC/MSX-DOS).

However...

The init routine gets called twice. Using OpenMSX debugger, I found out that the calls occur once after the inspection of addresses 0x4000-0x4003 (Id and Init address) and once more after the inspection of addresses 0x4004-0x4009 (statement, device and text (BASIC program)).

It occurred to me that maybe I'd have to flag the execution the first time it runs and check the flag the second time to avoid the execution, but I debugged the IDE cartridge on OpenMSX and it does NOT get called the second time (maybe it somehow flags to the BIOS, during the first execution, that it should not be called twice, I don´t know).

I tried to find this double call effect in the literature (MSX Top Secret, The Red Book, Sony's MSX Technical Data Book), but found nothing that seemed relevant.

Do you guys kno what is happening?

Best,

Van gdx

Enlighted (4706)

afbeelding van gdx

07-02-2020, 08:52

Init routine is called two time when the Rom have a size of 16kB or less with mirrors and if Init routine gives back hand to Rom search routine of the system.

https://www.msx.org/wiki/Develop_a_program_in_cartridge_ROM

It can also happen with some megaroms with mirrors and with its segments all initialized to 0 at start up.

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