msx1: ROM probing for cards
authorAlan Cox <alan@linux.intel.com>
Sun, 7 Apr 2019 19:27:55 +0000 (20:27 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 7 Apr 2019 19:27:55 +0000 (20:27 +0100)
We can now autodetect the IDE controller by ROM (if you have the same ROM anyway
other identifiers may well be needed).

Kernel/platform-msx1/README.md
Kernel/platform-msx1/devices.c
Kernel/platform-msx1/devide_sunrise.c
Kernel/platform-msx1/devide_sunrise.h
Kernel/platform-msx1/discard.c
Kernel/platform-msx1/main.c
Kernel/platform-msx1/msx.h
Kernel/platform-msx1/rom.h [new file with mode: 0644]
Kernel/platform-msx1/slots.s

index 546aa73..6acfd4d 100644 (file)
@@ -60,6 +60,8 @@ To Debug
 
 (Hopefully fixed)Seem to have had some disk corruption - how to reproduce/why ?
 Display flicker of weird chars when scroll/clear bottom line ?
+We blow up with slot expanders early in boot (in find_ram). Seems to be a
+problem if the cartridge is in an expander.
 
 In Progress
 
@@ -68,6 +70,9 @@ Move the switch helper into both banks so we can fix the FIXME in map_kernel
 To do
 
 Detection logic by ROM hash and find the sunrise etc
+Fix cursor interaction with fsck (don't xx bs flush but bs xx flush)
+Can we put find_ram etc in discard ?
+Do we need a font and should it move somewhere to make const space ?
 Tune swap logic so we only read/write relevant pages
 We badly need the cached path walk or some other optimizations on user copy
 or the bank switch
@@ -76,7 +81,11 @@ map_kernel etc by knowing if we are mapping k->k u->u or a transition and
 we can label all other cases with a value meaning 'other' as we don't need
 to worry about fastpaths that much
 Given the MSX1 mess consider just writing JIT code for k-> u->k etc so non
-stupid machines are not too slow.
+stupid machines are not too slow. In particular if we see that RAM is not in
+the same slot as anything else we use we can set the subslots once and just
+bash 0xA8 like a sane computer.
+For machines with bussed I/O do we want a /dev/iobus or similar that has the
+info for a program to unpack (ROM hashes etc) ?
 
 Target initial I/O devices
 
index 3de288a..5616ae7 100644 (file)
@@ -104,5 +104,5 @@ void device_init(void)
     keyrepeat.first = 2 * ticks_per_dsecond;
     keyrepeat.continual = 1 * ticks_per_dsecond;
 
-    sunrise_probe(1,0xFF);
+    sunrise_probe();
 }
index 09a7fcc..f1eaf1c 100644 (file)
@@ -125,12 +125,19 @@ failout:
     tmpfree(devide_buf);
 }
 
-void sunrise_probe(uint8_t slot, uint8_t subslot)
+static const uint16_t sunrise_roms[2] = {
+    0x8FB3,
+    0x0000
+};
+
+void sunrise_probe(void)
 {
-    uint8_t i = slot;
+    uint8_t slot, subslot;
+    uint8_t i;
 
-    if (subslot != 0xFF)
-        i |= 0x80 | (subslot << 2);
+    i = device_find(sunrise_roms);
+    if (i == 0xFF)
+        return;
 
     /* Generate and cache the needed mapping table */
     memcpy(&sunrise_k, map_slot1_kernel(i), sizeof(sunrise_k));
index c9ed112..73ea513 100644 (file)
@@ -4,7 +4,7 @@ extern void do_ide_end_reset(void) __z88dk_fastcall;
 extern uint8_t do_ide_flush_cache(uint8_t drive) __z88dk_fastcall;
 extern uint8_t do_ide_xfer(uint8_t drive) __z88dk_fastcall;
 
-extern void sunrise_probe(uint8_t slot, uint8_t subslot);
+extern void sunrise_probe(void);
 
 #define IDE_DRIVE_COUNT                2
 
index c18fbd7..a66dde1 100644 (file)
@@ -76,6 +76,18 @@ void map_init(void)
   kprintf("User map %x %x %x %x %x %x\n",
     *bp, bp[1], bp[2], bp[3], bp[4], bp[5]);
   copy_vectors();
+  for (i = 0; i < 4; i++){
+    for (pp = 0; pp < 4; pp++) {
+      if (devtab[i][pp][1] & 0x8000)
+        kprintf("@0x4000: %d.%d: %x\n", i, pp, devtab[i][pp][1] & 0x7FFF);
+    }
+  }
+  for (i = 0; i < 4; i++){
+    for (pp = 0; pp < 4; pp++) {
+      if (devtab[i][pp][2] & 0x8000)
+        kprintf("@0x8000: %d.%d: %x\n", i, pp, devtab[i][pp][2] & 0x7FFF);
+    }
+  }
 }
 
 /*
index 078a3b6..fcfdb40 100644 (file)
@@ -13,6 +13,7 @@ uint16_t ramtop = 0xC000;
 uint8_t machine_type;
 uint8_t vdptype;
 uint8_t *bouncebuffer;
+uint16_t devtab[4][4][3];
 
 void platform_idle(void)
 {
@@ -48,3 +49,22 @@ void platform_discard(void)
        at the end (probably FDFE-FFFE (FFFF being magic)) */
     bouncebuffer = (uint8_t *)0xFD00;  /* Hack for now */
 }
+
+uint8_t device_find(const uint16_t *romtab)
+{
+  uint8_t slot, sub;
+  while(*romtab) {
+    for (slot = 0; slot < 4; slot++) {
+      for (sub = 0; sub < 4; sub++) {
+        if (*romtab == devtab[slot][sub][1]) {
+          if (subslots & (1 << slot))
+            return 0x80 | slot | (sub << 2);
+          else
+            return slot;
+        }
+      }
+    }
+    romtab++;
+  }
+  return 0xFF;
+}
index 9f13471..79f424d 100644 (file)
@@ -3,6 +3,7 @@
 
 extern uint8_t machine_type;
 extern uint16_t infobits;
+extern uint8_t subslots;
 
 #define MACHINE_MSX1   0
 #define MACHINE_MSX2   1
@@ -33,9 +34,10 @@ struct msx_map {
 
 extern uint8_t *map_slot1_kernel(uint8_t slotinfo) __z88dk_fastcall;
 extern uint8_t *map_slot1_user(uint8_t slotinfo) __z88dk_fastcall;
-
+extern uint8_t device_find(const uint16_t *romtab);
 extern void copy_vectors(void);
 
+extern uint16_t devtab[4][4][3];
 extern uint8_t *bouncebuffer;
 
 #endif
diff --git a/Kernel/platform-msx1/rom.h b/Kernel/platform-msx1/rom.h
new file mode 100644 (file)
index 0000000..7610b4e
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ *     Known ROM signatures
+ */
+
+#define MSXDOS2_1              (0x8000|0x08F2)
+#define PANASONIC_FS_CA1_1     (0x8000|0x7BA0)
+#define PHILIPS_NMS1205_1      (0x8000|0x6D77)
+#define SUNRISE_IDE_1          (0x8000|0x0FB3)
index 7ab73d0..37908d5 100644 (file)
@@ -33,6 +33,7 @@
        .globl _map_slot1_user
        .globl find_ram
        .globl _ramtab
+       .globl _devtab
        .globl _kernel_map
        .globl _user_map
        .globl _current_map
@@ -441,6 +442,7 @@ no_subslot_map:
 ;
 find_ram:
        ld ix,#0xFCC1
+       ld iy,#_devtab          ; device scan table
        ld b,#4
        ld e,#0
 next_slot:
@@ -546,8 +548,13 @@ next_sub:
        ; Recover our slot count
        ;
        pop de
+       jr sub_done
 
 not_sub:
+       ld bc,#18               ; move on correct table distance (3 x 6
+                               ; bytes) as no subslots
+       add iy,bc
+sub_done:
        ;
        ;       Recover the old slot map state
        ;
@@ -599,7 +606,33 @@ romcheck:
 ;      A device ROM. Potentially interesting. Need to add code to checksum
 ;      or otherwise identify them later
 ;
-       ;FIXME
+       push de
+       push bc
+       xor a
+       ld l,a                  ; back to ROM start
+
+       ld d,a                  ; count
+       ld e,a
+       ld b,a                  ; 256 bytes
+       ld c,#8                 ; 2K
+
+nextrombyte:
+       ld a,(hl)
+       inc hl
+       add e
+       ld e,a
+       jr nc,noinc
+       inc d
+noinc:
+       djnz nextrombyte
+       dec c
+       jr nz,nextrombyte
+
+       set 7,d                 ; ROM present flag
+       ld (iy),e               ; 15 bit sum
+       ld 1(iy),d
+       pop bc
+       pop de
        jr notram
 
 writecheckd:
@@ -624,11 +657,13 @@ writecheck:
        inc bc
        ld a,d
        ld (bc),a
-       inc bc
-       ret
+       jr incout
 notram:
        inc bc
+incout:
        inc bc
+       inc iy
+       inc iy
        ret
 ;
 ;      Scan a slot/subslot for RAM