From 65d9165cf790c51d46b68866f47b042105083f43 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 28 Sep 2014 00:19:20 +0300 Subject: [PATCH] megaed-sv: tas sync code --- megaed-sv/asmtools.h | 2 +- megaed-sv/asmtools.s | 117 ++++++++++++++++++++++++++++++++++--------- megaed-sv/main.c | 18 ++++--- megaed-sv/sega_gcc.s | 7 +++ 4 files changed, 113 insertions(+), 31 deletions(-) diff --git a/megaed-sv/asmtools.h b/megaed-sv/asmtools.h index 7f6cd50..6305339 100644 --- a/megaed-sv/asmtools.h +++ b/megaed-sv/asmtools.h @@ -1,2 +1,2 @@ void read_joy_responses(u8 resp[8*5]); -void run_game(u16 mapper); +void run_game(u16 mapper, int tas_sync); diff --git a/megaed-sv/asmtools.s b/megaed-sv/asmtools.s index d1e1316..5e3ae7a 100644 --- a/megaed-sv/asmtools.s +++ b/megaed-sv/asmtools.s @@ -49,40 +49,57 @@ read_joy_responses: rts -.global run_game /* u16 mapper */ +.global run_game /* u16 mapper, int tas_sync */ 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 */ + ldarg 1, 0, d6 + move.l #0xa10000, a6 + move.l #0xc00000, a5 + move.l #0xc00005, a4 + move.l #0xc00004, a3 + moveq.l #0x00, d2 + move.b #0xff, d3 + move.b #0x40, d4 + move.b d4, (0x09,a6) /* CtrlA */ + move.b d2, (0x0b,a6) /* CtrlB */ + move.b d2, (0x0d,a6) /* CtrlC */ + move.b d2, (0x13,a6) /* S-CtrlA */ + move.b d3, (0x0f,a6) /* TxDataA */ + move.b d2, (0x19,a6) /* S-CtrlB */ + move.b d3, (0x15,a6) /* TxDataB */ + move.b d2, (0x1f,a6) /* S-CtrlC */ + move.b d3, (0x1b,a6) /* TxDataC */ + + /* set up for vram write */ + move.l #0x40000000, (a3) move.l #0xff0000, a1 - move.l #0x10000/4/4-1, %d0 + move.l #0x10000/4/4-1, d0 0: - move.l d1, (%a1)+ - move.l d1, (%a1)+ - move.l d1, (%a1)+ - move.l d1, (%a1)+ + move.l d2, (a1)+ + move.l d2, (a1)+ + move.l d2, (a1)+ + move.l d2, (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 + move.l #0xfffe00, a1 + tst.l d6 + bne use_tas_code + + lea (run_game_r,pc), a0 + move.l #(run_game_r_end - run_game_r)/2-1, d0 + bra 0f +use_tas_code: + lea (run_game_r_tas,pc), a0 + move.l #(run_game_r_tas_end - run_game_r_tas)/2-1, d0 + 0: - move.w (%a0)+, (%a1)+ + move.w (a0)+, (a1)+ dbra d0, 0b - jmp 0xfff000 + jmp 0xfffe00 -run_game_code: +run_game_r: move.w #0x3210, (0xA13006) move.w d7, (0xA13010) @@ -91,7 +108,59 @@ run_game_code: move.l (0x00), a7 move.l (0x04), a0 jmp (a0) -run_game_code_end: +run_game_r_end: + +run_game_r_tas: + move.w #0x3210, (0xA13006) + move.w d7, (0xA13010) + move.w #0, (0xA13000) + + move.l (0x00), a7 + move.l (0x04), a0 + +0: /* wait for special code */ + move.b d4, (0x03,a6) + move.b (0x03,a6), d0 + move.b d2, (0x03,a6) + move.b (0x03,a6), d1 + and.b #0x3f, d0 + cmp.b d0, d1 + bne 0b + cmp.b #0x25, d0 + bne 0b + +0: /* wait for special code to end */ + cmp.b (0x03,a6), d0 + beq 0b + /* wait for active display */ + moveq.l #3, d0 +0: + btst d0, (a4) /* 8 */ + beq.s 0b /* 10 */ +0: + btst d0, (a4) + bne.s 0b + + /* flood the VDP FIFO */ +.rept 5 + move.w d2, (a5) +.endr + + /* doesn't help.. */ +.if 0 +.rept 94 + nop +.endr + move.l #0x93049400, (a3) /* DMALEN LO/HI = 0x0008 */ + move.l #0x95009601, (a3) /* DMA SRC LO/MID */ + move.l #0x977f8114, (a3) /* DMA SRC HI/MODE, Turn off Display */ + move.l #0xc0000080, (a3) /* start DMA */ +.endif + + move.b d2, (0x09,a6) /* CtrlA */ + move.b d4, (0x03,a6) + jmp (a0) +run_game_r_tas_end: # vim:filetype=asmM68k:ts=4:sw=4:expandtab diff --git a/megaed-sv/main.c b/megaed-sv/main.c index a5ba918..d5a65a9 100644 --- a/megaed-sv/main.c +++ b/megaed-sv/main.c @@ -13,6 +13,8 @@ #include "edos.h" #include "asmtools.h" +extern u16 start_hvc; + #define GFX_DATA_PORT 0xC00000 #define GFX_CTRL_PORT 0xC00004 @@ -22,7 +24,7 @@ #define TILE_FONT_BASE (TILE_MEM_END / 32 - FONT_LEN) /* note: using ED menu's layout here.. */ -#define WPLAN (TILE_MEM_END + 0x0000) +#define WPLANE (TILE_MEM_END + 0x0000) #define HSCRL (TILE_MEM_END + 0x0800) #define SLIST (TILE_MEM_END + 0x0C00) #define APLANE (TILE_MEM_END + 0x1000) @@ -384,7 +386,7 @@ static int do_test(OsRoutine *ed, u8 b3) #define MTYPE_10M 5 #define MTYPE_32X 6 -static int do_run(OsRoutine *ed, u8 b3) +static int do_run(OsRoutine *ed, u8 b3, int tas_sync) { u8 mapper = 0; @@ -412,14 +414,16 @@ static int do_run(OsRoutine *ed, u8 b3) return -1; } - while (read32(GFX_CTRL_PORT) & 2) + printf("starting mapper %x..\n", mapper); + + while (read16(GFX_CTRL_PORT) & 2) ; ed->VDP_setReg(VDP_MODE1, 0x04); ed->VDP_setReg(VDP_MODE2, 0x44); ed->usbWriteByte('k'); - run_game(mapper); + run_game(mapper, tas_sync); /* should not get here.. */ return -1; @@ -451,7 +455,8 @@ int main() /* note: relying on ED menu's font setup here.. */ - printf("version: %02x\n", read8(0xa10001)); + printf("version: %02x, start_hvc: %04x\n", + read8(0xa10001), start_hvc); printf("ED os/fw: %x/%x\n\n", ed->osGetOsVersion(), ed->osGetFirmVersion()); @@ -484,8 +489,9 @@ int main() printf("done\n"); break; case 'r': + case 'R': buf[2] = ed->usbReadByte(); - ret = do_run(ed, buf[2]); + ret = do_run(ed, buf[2], buf[1] == 'R'); if (ret != 0) { d = 3; goto bad_input; diff --git a/megaed-sv/sega_gcc.s b/megaed-sv/sega_gcc.s index 514f4c8..897acdf 100644 --- a/megaed-sv/sega_gcc.s +++ b/megaed-sv/sega_gcc.s @@ -22,6 +22,7 @@ exc_tab: .ascii "JUE " RST: + move.w (0xc00008), start_hvc move.w #0x2700, %sr /* magic ED app init */ move.w #0x0000, (0xA13006) @@ -212,4 +213,10 @@ exc_stub 3d exc_stub 3e exc_stub 3f +.bss +.align 2 +.global start_hvc +start_hvc: + .word 0 + # vim:filetype=asmM68k:ts=4:sw=4:expandtab -- 2.39.2