Megarom and asMsx

By RibbSayan

Expert (68)

RibbSayan's picture

09-07-2010, 13:29

Hello,
I'll currently developping a MSX game. My knowledge in asm is very weak. However i'm learning...
I'll try to create a "Konami4" Megarom

This code work :

;=====================================================
.bios
.page 1
.megarom KONAMI
.start MAIN_BEGIN
db "MyMegarom",1ah

MAIN_BEGIN:
	call INITIALISATION
MAIN_LOOP:
	halt
	jr	MAIN_LOOP

	
.subpage 1 at $6000	
INITIALISATION:
	ld      hl,0f3e9h				; Color 15,0,0
	ld      [hl],15
	inc     hl
	ld      [hl],0
	inc     hl
	ld      [hl],0
	call    INIGRP					; Screen 2,2
	ld      bc,0e201h
	call    WRTVDP
	ret
;=====================================================

But this code not:

;=====================================================
.bios
.page 1
.megarom KONAMI
.start MAIN_BEGIN
db "MyMegarom",1ah

MAIN_BEGIN:
	.select 2 at $6000
	call INITIALISATION
MAIN_LOOP:
	halt
	jr	MAIN_LOOP

	
.subpage 1 at $6000	
db 0

.subpage 2 at $6000	
INITIALISATION:
	ld      hl,0f3e9h				; Color 15,0,0
	ld      [hl],15
	inc     hl
	ld      [hl],0
	inc     hl
	ld      [hl],0
	call    INIGRP					; Screen 2,2
	ld      bc,0e201h
	call    WRTVDP
	ret
;=====================================================

Thanks for your help.

Login or register to post comments

By RetroTechie

Paragon (1563)

RetroTechie's picture

09-07-2010, 21:24

You seem to rely on assembler directives to produce the code. Maybe that's easier, but you don't need it, MSX cartridges are really simple from a programmer's perspective. It does however:

  • Make sure that to other people reading your code, it may not be clear what's going on.
  • Make it impossible to assemble your code using other assemblers. Which makes it difficult for others to help, AND creates (unnecessary) problems should you ever decide to use another assembler.

Something like this should be clear to any assembler, and easy to read for Z80 programmers:

; (Mega)ROM init code meant to go into Konami type 4 ROM mapper
; for ROM mapper behaviour see http://bifi.msxnet.org/msxnet/tech/megaroms.html
; Untested, but hopefully works

INIGRP: equ 0072h
WRTVDP: equ 0047h

        org 04000h

        db "AB"             ; ID bytes
        dw start            ; cartridge initialization
        dw 0                  ; statement handler (not used)
        dw 0                  ; device handler (not used)
        dw 0                  ; BASIC program in ROM (not used, especially not in page 1)
        dw 0,0,0            ; reserved

start:
        ld a,1
        ld (06000h),a     ; switch ROM block 1 into 6000-7FFFh area (in case reset doesn't do this automatically)
        call screen2
loop:
        jr loop

        ds 06000h-$,0EEh    ; fill rest of 4000-5fffh area (EEh = easy to recognize in hex viewer)

; What follows here, should wind up at offset 2000h in generated binary
; (check with hex viewer if that's the case)
; = block nr. 1 (2nd block) of MegaROM
; Assembler's program counter should be 6000h at this point
; (check "block1" label in assembler list output to see if that's the case)

block1:

screen2:
        ld hl,0f3e9h                                   ; Color 15,0,0
        ld (hl),15
        inc hl
        ld (hl),0
        inc hl
        ld (hl),0
        call INIGRP                                    ; Screen 2,2
        ld bc,0e201h
        jp WRTVDP                                    ; CALL+RET shortened to JP

        ds 08000h-$,0EEh      ; fill rest of 6000-7FFFh area

; = block nr. 2 (3rd block) of MegaROM
; Assembler's program counter should be 8000h at this point
; etc, etc.

block2:

In other ROM blocks, you can use "org" assembler statements to set program counter at addresses where you plan to access these blocks. Just be careful that size of empty space remaining in block(s) is calculated correctly. Also note that enabling the megaROM in 8000-BFFFh area is something you have to do yourself, before using it (unless you want to use RAM there). Check for example some existing megaROMs to see how they determine what slot they're in. And other than for 4000-5FFFh area, megaROM blocks may not be initialized after a reset (depending on cartridge type). If you ignore this, you may get a MegaROM that works fine on emulators but not (reliable) on real hardware.
Btw - didn't check what graphics stuff you're trying to do, I'm not much of an MSX graphics coder... Wink

By RibbSayan

Expert (68)

RibbSayan's picture

10-07-2010, 17:35

Thanks for reply...

But I'va got some others questions. For Megarom Konami type 4 ROM mapper, we have this definition :
Bank 1: 4000h - 5FFFh
Bank 2: 6000h - 7FFFh
Bank 3: 8000h - 9FFFh
Bank 4: A000h - BFFFh
If my Megarom have 16 blocks of 8 Ko, how can I select the last block on bank 4 [ ld a,16 > ld (0A000h),a ] ? Can All blocks ares interchangeabes ?

By Guillian

Prophet (3370)

Guillian's picture

10-07-2010, 18:02

The first block is 0 (range from 0 to 15). So to select the last block:
ld a,15
ld (#a000),a