Skip to content

Commit

Permalink
msx2: read machine type and info
Browse files Browse the repository at this point in the history
This is required to select the proper keyboard layout
and use additional hw features in MSX2+ and TR.
  • Loading branch information
geijoenr committed Feb 1, 2015
1 parent 08b9a77 commit 53b2375
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 25 deletions.
30 changes: 27 additions & 3 deletions Kernel/platform-msx2/bootrom.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
.dw 0,0,0,0,0,0

.globl enaslt
; data to save from bios
.globl _slotrom
.globl _slotram
.globl _vdpport
.globl _infobits
.globl _machine_type
.globl find_ram
.globl kstack_top

Expand Down Expand Up @@ -37,35 +41,55 @@ bootstrap:
ld d,a
call find_rom
ld e,a

; read machine info bits
ld bc,(0x002b) ; localization and interrupt frequency
ld hl,(0x0006) ; vdp ports
inc h
inc l
ld a,(0x002d) ; machine type

ex af,af'
ld a,e
exx

ld hl,#0xc000
ld sp,#0xa000 ; keep stack in ram
call enaslt ; set bank 3 to rom
call enaslt ; set bank 3 to rom

; copy kernel page 0 from bank 3 to ram in bank 2
; it contains the common area if the rom > 48Kb
ld hl, #0xc000
ld de, #0x8000
ld bc, #0x4000
ldir
exx

exx
push de
push bc
push hl
ld hl,#0xc000 ; set bank 3 back to ram
ld a,d
call enaslt
pop de ; store slot data in ram now
pop hl
pop bc
pop de

ld a, #4
out (0xFF),a
ld a,d
ld (_slotram),a
ld a,e
ld (_slotrom),a
ld (_infobits),bc
ld (_vdpport),hl
ex af,af'
ld (_machine_type),a

ld sp, #kstack_top ; move stack to final location

; set cartridge rom in bank 0
ld a,e
ld hl,#0
call enaslt

Expand Down
12 changes: 11 additions & 1 deletion Kernel/platform-msx2/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
.globl enaslt
.globl _slotram
.globl _slotrom
.globl _vdpport
.globl _infobits
.globl _machine_type
.globl find_ram

; startup code @0x100
Expand Down Expand Up @@ -67,7 +70,11 @@ start:
ld d,a
ld a,(_slotrom)
ld e,a
ld bc,(_infobits)
ld hl,(_vdpport)
ld a,(_machine_type)
exx
ex af,af'
; move the common memory where it belongs
ld hl, #s__INITIALIZER
ld de, #s__COMMONMEM
Expand All @@ -80,13 +87,16 @@ start:
ldir

exx
ex af,af'
ld (_infobits),bc
ld (_vdpport),hl
ld (_machine_type),a
; restore slot data
ld a,d
ld (_slotram),a
ld a,e
ld (_slotrom),a


; then zero the data area
ld hl, #s__DATA
ld de, #s__DATA + 1
Expand Down
25 changes: 25 additions & 0 deletions Kernel/platform-msx2/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <devtty.h>
#include <devsd.h>
#include <blkdev.h>
#include "msx2.h"
#include <printf.h>

extern int megasd_probe();

Expand Down Expand Up @@ -46,6 +48,29 @@ void device_init(void)
inittod();
#endif

kprintf ("Running on a ");
if (machine_type == MACHINE_MSX1) {
kprintf("MSX1 not supported\n");
// hang!
} else if (machine_type == MACHINE_MSX2) {
kprintf("MSX2 ");
} else if (machine_type == MACHINE_MSX2P) {
kprintf("MSX2+ ");
} else if (machine_type == MACHINE_MSXTR) {
kprintf("MSX TurboR ");
}

if ((infobits & KBDTYPE_MASK) == KBDTYPE_JPN) {
kprintf("JP ");
} else {
kprintf("INT ");
}
if ((infobits & INTFREQ_MASK) == INTFREQ_60Hz) {
kprintf("60Hz\n");
} else {
kprintf("50Hz\n");
}

if (megasd_probe()) {
/* probe for megaflash rom sd */
devsd_init();
Expand Down
5 changes: 1 addition & 4 deletions Kernel/platform-msx2/devmegasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ int megasd_probe()
uint8_t *sigp = (uint8_t *) MSD_MAGIC_ADDR;
uint8_t slot = 1;

kprintf("MegaSD...");

for (slot = 1; slot < 3; slot++) {
/* try to find MegaFlashRom signature in slots 1 and 2 */
slotmfr = 0x80 | MSD_SUBSLOT << 2 | slot;
Expand All @@ -57,12 +55,11 @@ int megasd_probe()
goto found;
}
mapslot_bank1(slotram);
kprintf("not found\n");
return 0;

found:
mapslot_bank1(slotram);
kprintf("found in slot %d-3\n", slot);
kprintf("MegaSD found in slot %d-3\n", slot);
return 1;
}

Expand Down
3 changes: 0 additions & 3 deletions Kernel/platform-msx2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <printf.h>
#include <devtty.h>

/* These are set by the msx startup asm code */
uint16_t vdpport = 0x99 + 256 * 80;
uint16_t infobits;
uint16_t msxmaps;

void platform_idle(void)
Expand Down
26 changes: 26 additions & 0 deletions Kernel/platform-msx2/msx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,31 @@ extern int mapslot_bank1(uint8_t slot);
extern int mapslot_bank2(uint8_t slot);

extern uint8_t slotram;
extern uint8_t slotrom;
extern uint8_t machine_type;
extern uint16_t infobits;

#define MACHINE_MSX1 0
#define MACHINE_MSX2 1
#define MACHINE_MSX2P 2
#define MACHINE_MSXTR 3

#define CHARSET_MASK (0xF)
#define CHARSET_JPN 0
#define CHARSET_INT 1
#define CHARSET_KR 2

#define INTFREQ_MASK (1 << 7)
#define DATEFMT_MASK (7 << 4)
#define INTFREQ_60Hz 0
#define INTFREQ_50Hz 1

#define KBDTYPE_MASK (0xF)
#define KBDTYPE_JPN 0
#define KBDTYPE_INT 1
#define KBDTYPE_FR 2
#define KBDTYPE_UK 3
#define KBDTYPE_DIN 4
#define KBDTYPE_ES 6

#endif
25 changes: 11 additions & 14 deletions Kernel/platform-msx2/msx2.s
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
.globl outstring
.globl outstringhex

; stuff to save
.globl _vdpport
.globl _infobits

.globl _slotrom
.globl _slotram
.globl _vdpport
.globl _infobits
.globl _machine_type

;
; vdp - we must initialize this bit early for the vt
Expand Down Expand Up @@ -93,19 +94,9 @@ _kernel_flag:
.area _CODE

init_early:
ld a, #'F'
out (0x2F), a
ret
ret

init_hardware:
ld a, #'U'
out (0x2F), a
; save the useful bits of low memory first
ld hl, (0x2B)
ld (_infobits), a
; ld a, (0x07)
; ld (_vdpport), a

; Size RAM
call size_memory

Expand Down Expand Up @@ -437,6 +428,12 @@ _slotrom:
.db 0
_slotram:
.db 0
_vdpport:
.dw 0
_infobits:
.dw 0
_machine_type:
.db 0

; emulator debug port for now
outchar:
Expand Down

0 comments on commit 53b2375

Please sign in to comment.