initial 32x tests
[megadrive.git] / megaed-sv / main.c
index 4473c5c..a0741b6 100644 (file)
@@ -36,6 +36,8 @@ extern u16 start_hvc;
     *((volatile u16 *) (a))
 #define read32(a) \
     *((volatile u32 *) (a))
+#define write8(a, d) \
+    *((volatile u8 *) (a)) = (d)
 #define write16(a, d) \
     *((volatile u16 *) (a)) = (d)
 #define write32(a, d) \
@@ -213,6 +215,17 @@ static noinline int printf(const char *fmt, ...)
     return d; // wrong..
 }
 
+static u8 gethex(char c)
+{
+    if ('0' <= c && c <= '9')
+        return c - '0';
+    if ('a' <= c && c <= 'f')
+        return c - 'a' + 10;
+    if ('A' <= c && c <= 'F')
+        return c - 'A' + 10;
+    return 0;
+}
+
 static const char *exc_names[] = {
     NULL,
     NULL,
@@ -509,11 +522,17 @@ static int do_run(OsRoutine *ed, u8 b3, int tas_sync)
     case 'M':
         mapper = MTYPE_10M;
         break;
+    case 'n':
+        // raw numer: hex XX: mtype | x;
+        // x: bits [4-7]: SRAM_ON, SRAM_3M_ON, SNAP_SAVE_ON, MKEY
+        mapper  = gethex(ed->usbReadByte()) << 4;
+        mapper |= gethex(ed->usbReadByte());
+        break;
     default:
         return -1;
     }
 
-    printf("starting mapper %x..\n", mapper);
+    printf("syncing and starting mapper %x..\n", mapper);
 
     while (read16(GFX_CTRL_PORT) & 2)
         ;
@@ -528,6 +547,25 @@ static int do_run(OsRoutine *ed, u8 b3, int tas_sync)
     return -1;
 }
 
+void setup_z80(void)
+{
+    u8 *mem = (u8 *)0xa00000;
+    int i;
+
+    write8(0xa11100, 1);
+    write8(0xa11200, 1);
+
+    while (read8(0xa11100) & 1)
+        ;
+
+    /* must use byte access */
+    for (i = 0x2000; i > 0; i--)
+        *mem++ = 0;
+
+    /* console starts with reset on, busreq off,
+     * gens starts with busreq on, keep that for gmv.. */
+}
+
 int main()
 {
     OsRoutine *ed;
@@ -538,6 +576,10 @@ int main()
     ed = (OsRoutine *) *(u32 *)0x1A0;
     ed->memInitDmaCode(); 
 
+    /* setup VDP */
+    while (read16(GFX_CTRL_PORT) & 2)
+        ;
+
     ed->VDP_setReg(VDP_MODE1, 0x04); 
     ed->VDP_setReg(VDP_MODE2, 0x64); 
     ed->VDP_setReg(VDP_AUTOINC, 2); 
@@ -559,11 +601,13 @@ int main()
     /* note: relying on ED menu's font setup here.. */
 
     printf("\n");
-    printf("version: %02x, start_hvc: %04x\n",
-           read8(0xa10001), start_hvc);
+    printf("version: %02x, hvc: %04x %04x\n",
+           read8(0xa10001), start_hvc, read16(0xc00008));
     printf("ED os/fw: %d/%d\n\n", ed->osGetOsVersion(),
            ed->osGetFirmVersion());
 
+    setup_z80();
+
     for (;;) {
         if (!ed->usbRdReady()) {
             /* note: stop corrupts SDRAM */