From: notaz Date: Fri, 26 Sep 2014 20:47:24 +0000 (+0300) Subject: megaed-sv: implement ROM load/run X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df43aeea93272c120d348dde8226ed52efa74fc1;p=megadrive.git megaed-sv: implement ROM load/run --- diff --git a/megaed-sv/asmtools.h b/megaed-sv/asmtools.h index a5733d1..7f6cd50 100644 --- a/megaed-sv/asmtools.h +++ b/megaed-sv/asmtools.h @@ -1 +1,2 @@ void read_joy_responses(u8 resp[8*5]); +void run_game(u16 mapper); diff --git a/megaed-sv/asmtools.s b/megaed-sv/asmtools.s index db93940..d1e1316 100644 --- a/megaed-sv/asmtools.s +++ b/megaed-sv/asmtools.s @@ -6,7 +6,7 @@ .endm -.globl read_joy_responses /* u8 *rbuf */ +.global read_joy_responses /* u8 *rbuf */ read_joy_responses: ldarg 0, 0, a1 movem.l d2-d7, -(sp) @@ -49,4 +49,49 @@ read_joy_responses: rts +.global run_game /* u16 mapper */ +run_game: + move.w #0x2700, sr + ldarg 0, 0, d7 + move.l #0xa10000, a7 + moveq.l #0x00, d1 + move.b #0xff, d2 + move.b d1, (0x0b,a7) /* CtrlB */ + move.b d1, (0x0d,a7) /* CtrlC */ + move.b d2, (0x0f,a7) /* TxDataA */ + move.b d1, (0x13,a7) /* S-CtrlA */ + move.b d2, (0x15,a7) /* TxDataB */ + move.b d1, (0x19,a7) /* S-CtrlB */ + move.b d2, (0x1b,a7) /* TxDataC */ + move.b d1, (0x1f,a7) /* S-CtrlC */ + + move.l #0xff0000, a1 + move.l #0x10000/4/4-1, %d0 +0: + move.l d1, (%a1)+ + move.l d1, (%a1)+ + move.l d1, (%a1)+ + move.l d1, (%a1)+ + dbra d0, 0b + + lea (run_game_code,pc), a0 + move.l #0xfff000, a1 + move.l #(run_game_code_end - run_game_code)/2-1, d0 +0: + move.w (%a0)+, (%a1)+ + dbra d0, 0b + jmp 0xfff000 + +run_game_code: + move.w #0x3210, (0xA13006) + + move.w d7, (0xA13010) + move.w #0, (0xA13000) + + move.l (0x00), a7 + move.l (0x04), a0 + jmp (a0) +run_game_code_end: + + # vim:filetype=asmM68k:ts=4:sw=4:expandtab diff --git a/megaed-sv/main.c b/megaed-sv/main.c index 4065a8a..7c0955f 100644 --- a/megaed-sv/main.c +++ b/megaed-sv/main.c @@ -24,6 +24,12 @@ #define APLANE (TILE_MEM_END + 0x1000) #define BPLANE (TILE_MEM_END + 0x3000) +#define read8(a) \ + *((volatile u8 *) (a)) +#define read16(a) \ + *((volatile u16 *) (a)) +#define read32(a) \ + *((volatile u32 *) (a)) #define write16(a, d) \ *((volatile u16 *) (a)) = (d) #define write32(a, d) \ @@ -285,10 +291,60 @@ static int do_test(OsRoutine *ed, u8 b3) return -1; } +#define MTYPE_OS 0 +#define MTYPE_MD 1 +#define MTYPE_SSF 2 +#define MTYPE_CD 3 +#define MTYPE_SMS 4 +#define MTYPE_10M 5 +#define MTYPE_32X 6 + +static int do_run(OsRoutine *ed, u8 b3) +{ + u8 mapper = 0; + + switch (b3) + { + case 's': + mapper = MTYPE_SMS | (7 << 4); + break; + case 'm': + mapper = MTYPE_MD; + break; + case 'o': + mapper = MTYPE_OS; + break; + case 'c': + mapper = MTYPE_CD; + break; + case '3': + mapper = MTYPE_32X; + break; + case 'M': + mapper = MTYPE_10M; + break; + default: + return -1; + } + + while (read32(GFX_CTRL_PORT) & 2) + ; + ed->VDP_setReg(VDP_MODE1, 0x04); + ed->VDP_setReg(VDP_MODE2, 0x44); + + ed->usbWriteByte('k'); + + run_game(mapper); + /* should not get here.. */ + + return -1; +} + int main() { OsRoutine *ed; u8 buf[16]; + int len; int i, d, ret; ed = (OsRoutine *) *(u32 *)0x1A0; @@ -310,6 +366,10 @@ int main() /* note: relying on ED menu's font setup here.. */ + printf("version: %02x\n", read8(0xa10001)); + printf("ED os/fw: %x/%x\n\n", ed->osGetOsVersion(), + ed->osGetFirmVersion()); + for (;;) { if (!ed->usbRdReady()) { asm volatile("stop #0x2000"); @@ -330,6 +390,24 @@ int main() case 'T': ed->usbWriteByte('k'); break; + case 'g': + len = ed->usbReadByte() * 128; + printf("loading %d bytes.. ", len * 512); + ed->usbWriteByte('k'); + ed->usbReadDma((void *)0x200000, len); + ed->usbWriteByte('d'); + printf("done\n"); + break; + case 'r': + buf[2] = ed->usbReadByte(); + ret = do_run(ed, buf[2]); + if (ret != 0) { + d = 3; + goto bad_input; + } + printf("run returned??\n"); + break; + /* custom */ case 't': buf[2] = ed->usbReadByte(); diff --git a/megaed-sv/sega_gcc.s b/megaed-sv/sega_gcc.s index 42e3d5f..0702158 100644 --- a/megaed-sv/sega_gcc.s +++ b/megaed-sv/sega_gcc.s @@ -20,18 +20,32 @@ .ascii " " .ascii "JUE " -/* magic ED app init */ RST: + move.w #0x2700, sr +/* magic ED app init */ move.w #0x0000, (0xA13006) jmp init_ed.l init_ed: - move.w #0x210f, (0xA13006) +/* relocate to bank a, so that other ROMs can be loaded */ + move.w #0x0a0f, (0xA13006) + movea.l #0x100000, %a0 + movea.l #0x200000, %a1 + move.l #0x100000/4/4-1, %d0 +0: + move.l (a0)+, (a1)+ + move.l (a0)+, (a1)+ + move.l (a0)+, (a1)+ + move.l (a0)+, (a1)+ + dbra %d0, 0b + + move.w #0x10af, (0xA13006) move.l #HBL, (0x70) move.l #VBL, (0x78) - moveq #0,%d0 - movea.l %d0,%a7 - move %a7,%usp + moveq #0, %d0 + movea.l %d0, %a7 + move %a7, %usp + move.w #0x2000, sr bra main INT: