megaed-sv: allow to input raw mapper code
[megadrive.git] / megaed-sv / sega_gcc.s
index 42e3d5f..897acdf 100644 (file)
@@ -1,44 +1,60 @@
-        dc.l 0x0,0x200\r
-        dc.l INT,INT,INT,INT,INT,INT,INT\r
-        dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
-        dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
-        dc.l INT,INT,INT,HBL,INT,VBL,INT,INT\r
-        dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
-        dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
-        dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
-        dc.l INT,INT,INT,INT,INT,INT,INT\r
-        .ascii "SEGA EVERDRIVE                  "\r
-        .ascii "MEGA-ED host                                    "\r
-        .ascii "MEGA-ED host                                    "\r
-        .ascii "GM 00000000-00"\r
-        .byte 0x00,0x00\r
-        .ascii "JD              "\r
-        .byte 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00\r
-        .byte 0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff\r
-        .ascii "               "\r
-        .ascii "                        "\r
-        .ascii "                         "\r
-        .ascii "JUE             "\r
+exc_tab:\r
+    dc.l     0, 0x200, exc02, exc03, exc04, exc05, exc06, exc07\r
+    dc.l exc08, exc09, exc0a, exc0b, exc0c, exc0d, exc0e, exc0f\r
+    dc.l exc10, exc11, exc12, exc13, exc14, exc15, exc16, exc17\r
+    dc.l exc18, exc19, exc1a, exc1b, HBL,   exc1d, VBL,   exc1f\r
+    dc.l exc20, exc21, exc22, exc23, exc24, exc25, exc26, exc27\r
+    dc.l exc28, exc29, exc2a, exc2b, exc2c, exc2d, exc2e, exc2f\r
+    dc.l exc30, exc31, exc32, exc33, exc34, exc35, exc3e, exc37\r
+    dc.l exc38, exc39, exc3a, exc3b, exc3c, exc3d, exc3e, exc3f\r
+\r
+    .ascii "SEGA EVERDRIVE                  "\r
+    .ascii "MEGA-ED host                                    "\r
+    .ascii "MEGA-ED host                                    "\r
+    .ascii "GM 00000000-00"\r
+    .byte 0x00,0x00\r
+    .ascii "JD              "\r
+    .byte 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00\r
+    .byte 0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff\r
+    .ascii "               "\r
+    .ascii "                        "\r
+    .ascii "                         "\r
+    .ascii "JUE             "\r
 \r
-/* magic ED app init */\r
 RST:\r
+       move.w      (0xc00008), start_hvc\r
+       move.w          #0x2700, %sr\r
+/* magic ED app init */\r
        move.w #0x0000, (0xA13006)\r
        jmp init_ed.l\r
 init_ed:\r
-       move.w #0x210f, (0xA13006)\r
-       move.l #HBL, (0x70)\r
-       move.l #VBL, (0x78)\r
+/* relocate to bank a, so that other ROMs can be loaded */\r
+       move.w #0x0a0f, (0xA13006)\r
+       movea.l #0x100000, %a0\r
+       movea.l #0x200000, %a1\r
+       move.l #0x100000/4/4-1, %d0\r
+0:\r
+       move.l (a0)+, (a1)+\r
+       move.l (a0)+, (a1)+\r
+       move.l (a0)+, (a1)+\r
+       move.l (a0)+, (a1)+\r
+       dbra %d0, 0b\r
 \r
-       moveq   #0,%d0\r
-       movea.l %d0,%a7\r
-       move    %a7,%usp\r
-       bra     main\r
+       move.w #0x10af, (0xA13006)\r
 \r
-INT:\r
-       movem.l %d0-%d1/%a0-%a1,-(%sp)\r
-       jsr exception\r
-       movem.l (%sp)+,%d0-%d1/%a0-%a1\r
-       rte\r
+       lea exc_tab, %a0\r
+       adda.l #4*2, %a0\r
+       movea.l #4*2, %a1\r
+       move.l #64-2-1, %d0\r
+0:\r
+       move.l (a0)+, (a1)+\r
+       dbra %d0, 0b\r
+\r
+       moveq   #0, %d0\r
+       movea.l %d0, %a7\r
+       move    %a7, %usp\r
+       move.w  #0x2000, %sr\r
+       bra     main\r
 \r
 HBL:\r
        rte\r
@@ -49,6 +65,15 @@ VBL:
        movem.l (%sp)+,%d0-%d1/%a0-%a1\r
        rte\r
 \r
+pre_exception:\r
+       move.w  #0x2700, %sr\r
+       movem.l %d0-%d7/%a0-%a7,-(%sp)\r
+       move.l %sp, %d0\r
+       move.l %d0,-(%sp)\r
+       jsr exception\r
+0:\r
+       bra 0b\r
+\r
 \r
 * Standard 32X startup code for MD side at 0x3F0\r
        .org 0x3F0\r
@@ -119,3 +144,79 @@ VBL:
         .word   0xFFC0,0x4CD6,0x7FF9,0x44FC,0x0000,0x6014,0x43F9,0x00A1\r
         .word   0x5100,0x3340,0x0006,0x303C,0x8000,0x6004,0x44FC,0x0001\r
 \r
+.macro exc_stub num\r
+exc\num:\r
+       move.w #0x\num, -(%sp)\r
+       jmp pre_exception\r
+.endm\r
+\r
+exc_stub 02\r
+exc_stub 03\r
+exc_stub 04\r
+exc_stub 05\r
+exc_stub 06\r
+exc_stub 07\r
+exc_stub 08\r
+exc_stub 09\r
+exc_stub 0a\r
+exc_stub 0b\r
+exc_stub 0c\r
+exc_stub 0d\r
+exc_stub 0e\r
+exc_stub 0f\r
+exc_stub 10\r
+exc_stub 11\r
+exc_stub 12\r
+exc_stub 13\r
+exc_stub 14\r
+exc_stub 15\r
+exc_stub 16\r
+exc_stub 17\r
+exc_stub 18\r
+exc_stub 19\r
+exc_stub 1a\r
+exc_stub 1b\r
+# exc_stub 1c\r
+exc_stub 1d\r
+# exc_stub 1e\r
+exc_stub 1f\r
+exc_stub 20\r
+exc_stub 21\r
+exc_stub 22\r
+exc_stub 23\r
+exc_stub 24\r
+exc_stub 25\r
+exc_stub 26\r
+exc_stub 27\r
+exc_stub 28\r
+exc_stub 29\r
+exc_stub 2a\r
+exc_stub 2b\r
+exc_stub 2c\r
+exc_stub 2d\r
+exc_stub 2e\r
+exc_stub 2f\r
+exc_stub 30\r
+exc_stub 31\r
+exc_stub 32\r
+exc_stub 33\r
+exc_stub 34\r
+exc_stub 35\r
+exc_stub 36\r
+exc_stub 37\r
+exc_stub 38\r
+exc_stub 39\r
+exc_stub 3a\r
+exc_stub 3b\r
+exc_stub 3c\r
+exc_stub 3d\r
+exc_stub 3e\r
+exc_stub 3f\r
+\r
+.bss\r
+.align 2\r
+.global start_hvc\r
+start_hvc:\r
+    .word 0\r
+\r
+# vim:filetype=asmM68k:ts=4:sw=4:expandtab\r