From af07ca644c5ffbfa798f817d312c8430b4b29308 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 8 Nov 2014 23:25:06 +0000 Subject: [PATCH] msx1: scan for AB rom signatures, hash the first 2K First steps to detecting the disks etc --- Kernel/platform-msx1/devices.c | 14 +++++++ Kernel/platform-msx1/devices.h | 6 +++ Kernel/platform-msx1/msx1.s | 74 ++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 Kernel/platform-msx1/devices.h diff --git a/Kernel/platform-msx1/devices.c b/Kernel/platform-msx1/devices.c index b5805f17..d8e373a4 100644 --- a/Kernel/platform-msx1/devices.c +++ b/Kernel/platform-msx1/devices.c @@ -1,6 +1,8 @@ #include +#include #include #include +#include #include #include #include @@ -33,6 +35,18 @@ bool validdev(uint16_t dev) return true; } +/* + * We may want to do this differently in the end but report the + * cartridge hashes found. + * + * A4B6 = Sony HBD-F1 + * 3B49 = Sony HBK-30 + */ void device_init(void) { + int i; + for (i = 0; i < 16; i++) { + if (slot_table[i]) + kprintf("%d.%d: %x\n", (i>>2) & 3, i & 3, slot_table[i]); + } } diff --git a/Kernel/platform-msx1/devices.h b/Kernel/platform-msx1/devices.h new file mode 100644 index 00000000..53a0965a --- /dev/null +++ b/Kernel/platform-msx1/devices.h @@ -0,0 +1,6 @@ +#ifndef _PLATFORM_DEVICES_H +#define _PLATFORM_DEVICES_H + +extern uint16_t slot_table[16]; + +#endif \ No newline at end of file diff --git a/Kernel/platform-msx1/msx1.s b/Kernel/platform-msx1/msx1.s index 716bbe32..61b703b9 100644 --- a/Kernel/platform-msx1/msx1.s +++ b/Kernel/platform-msx1/msx1.s @@ -14,6 +14,7 @@ .globl map_process_always .globl map_save .globl map_restore + .globl _slot_table ; video driver .globl _vtinit @@ -143,6 +144,7 @@ size_memory: ld de, #0x40 ; main memory for kernel add hl, de ld (_ramsize), hl + call rom_scan ret _program_vectors: @@ -637,3 +639,75 @@ map_megaram: pop de call setslot1 ret + +; +; Find each rom and insert it by hash code into the slot table. We +; can then use this to find out where things like floppy drives have +; been hidden. Right now we are only scanning 0x4000-0x7FFF, but we +; will probably need to scan 0x8000-0xBFFF as well eventually (which +; will be a right PITA as we'll need slotscan2 and all the supporting +; logic to be in 0x0000-0x3FFF!) +; +rom_scan: + ld hl, #rom_scan_f + exx + call slotscan1 + ret + +rom_scan_f: + ld a, #'*' + out (0x2f), a + ld a, (0x4000) + cp #'A' + ret nz + ld a, (0x4001) + cp #'B' + ret nz + ; + ; ROM found. Preserve HL as its the call vector + ; + ld a, #'R' + out (0x2f), a + push hl + ld hl, #0x4002 + ld bc, #2048 + ld de, #0 + ; Use the low 2K as a checksum identifier +rom_scan_1: + ld a, (hl) + add e + ld e, a + ld a, d + adc #0 + ld d, a + inc hl + djnz rom_scan_1 + dec c + jr nz,rom_scan_1 + exx + push de ;slot info + exx + pop bc + ld a, b + and #0x0C + ld b, a + ld a, c + and #0x03 + or b + add a + ld c, a + ld b, #0 + ld hl, #_slot_table + add hl, bc + ld (hl), e + inc hl + ld (hl), d + pop hl + ret + +; Needs to be outside of 0x4000-0x7FFF +_slot_table: + .dw 0,0,0,0 + .dw 0,0,0,0 + .dw 0,0,0,0 + .dw 0,0,0,0 -- 2.34.1