From: notaz Date: Wed, 25 May 2011 21:58:38 +0000 (+0300) Subject: hexed: vram transfer + early pc transfers X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0e0673602899ee26c6dec3964199e266881241c;p=megadrive.git hexed: vram transfer + early pc transfers --- diff --git a/hexed/hexed.s b/hexed/hexed.s index 418ca5c..99d1c08 100644 --- a/hexed/hexed.s +++ b/hexed/hexed.s @@ -275,6 +275,33 @@ main: tst.w (0xc00004).l no_tmss: + /* want to do early PC transfer (with RAM/VRAM intact and such)? + * also give time PC to see start condition */ + move.l #0x2000,d0 +0: dbra d0,0b + + move.l #0xa10005,a0 + btst.b #5,(a0) + bne no_early_transfer +move.b #1,(0) + move.b #0x40,(0xa1000b).l /* port 2 ctrl */ + move.b #0x00,(a0) /* port 2 data - start with TH low */ + move.l #0x2000,d0 +0: + btst.b #4,(a0) + beq do_early_transfer + dbra d0,0b + +move.b #2,(0) + move.b #0,(0xa1000b).l + bra no_early_transfer /* timeout */ + +do_early_transfer: +move.b #9,(0) + bsr do_transfer + +no_early_transfer: + .if COPY_TO_EXP /* copy to expansion device if magic number is set */ move.l #0x400000,a1 @@ -1327,7 +1354,8 @@ wait_tl_low0: bne wait_tl_low0 menu_text txt_working, 13, 13, 0 - bra do_transfer + bsr do_transfer + bra return_to_main # go back to main mode return_to_main: diff --git a/hexed/pc_transfer.c b/hexed/pc_transfer.c index ef1f58b..bcfb652 100644 --- a/hexed/pc_transfer.c +++ b/hexed/pc_transfer.c @@ -193,7 +193,8 @@ static void usage(const char *argv0) "\trecv \n" "\tjump \n" "\tio {r{8,16,32} ,w{8,16,32} }*\n" - "\tloadstate \n", argv0); + "\tloadstate \n" + "\trecvvram \n", argv0); exit(1); } @@ -404,6 +405,20 @@ int main(int argc, char *argv[]) data[i + 1] = tmp; } } + else if (strcmp(argv[1], "recvvram") == 0) + { + if (argc != 3) + usage(argv[0]); + + file = fopen(argv[2], "wb"); + if (file == NULL) { + fprintf(stderr, "can't open file: %s\n", argv[2]); + return 1; + } + + size = 0x10000; + memset(data, 0, size); + } else usage(argv[0]); @@ -417,18 +432,29 @@ int main(int argc, char *argv[]) printf("regs: %02x %02x %02x\n", inb(PORT_DATA), inb(PORT_STATUS), inb(PORT_CONTROL)); + + /* wait for start condition */ + if (!(inb(PORT_STATUS) & 0x40)) + printf("waiting for TH high..\n"); + while (!(inb(PORT_STATUS) & 0x40)) + usleep(10000); + outb(0xe8, PORT_CONTROL); /* TR low - request for transfer */ + /* wait for request ack */ if (inb(PORT_STATUS) & 0x40) printf("waiting for TH low..\n"); - while (inb(PORT_STATUS) & 0x40) - usleep(100000); + for (i = 10000; inb(PORT_STATUS) & 0x40; i += 100) { + if (i > 100000) + i = 100000; + usleep(i); + } outb(0xe0, PORT_CONTROL); if (strcmp(argv[1], "send") == 0) { - send_cmd(CMD_MD_SEND); + send_cmd(CMD_PC_SEND); send_byte((addr >> 16) & 0xff); send_byte((addr >> 8) & 0xff); send_byte((addr >> 0) & 0xff); @@ -449,7 +475,7 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[1], "recv") == 0) { - send_cmd(CMD_MD_RECV); + send_cmd(CMD_PC_RECV); send_byte((addr >> 16) & 0xff); send_byte((addr >> 8) & 0xff); send_byte((addr >> 0) & 0xff); @@ -545,6 +571,24 @@ int main(int argc, char *argv[]) send_byte(data[i]); } } + else if (strcmp(argv[1], "recvvram") == 0) + { + send_cmd(CMD_VRAM_RECV); + output_to_input(); + + for (i = 0; i < size; i++) + { + if ((i & 0xff) == 0) { + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b"); + printf("%06x/%06x", i, size); + fflush(stdout); + } + + data[i] = recv_byte(); + } + + fwrite(data, 1, size, file); + } if (size != 0) { printf("\b\b\b\b\b\b\b\b\b\b\b\b\b"); diff --git a/hexed/transfer.S b/hexed/transfer.S index 1ac2d62..ef5bf5d 100644 --- a/hexed/transfer.S +++ b/hexed/transfer.S @@ -120,10 +120,23 @@ recv_ad: move.l d2,d0 rts +# send 1 byte in d0 +# in: a1 - data port +# trash: d1,d2 send_byte: send_one_byte rts +.macro switch_to_output +0: /*Lwait_tl_low: PC should switch to rx mode before lowering tl */ + move.b (a1),d0 + btst.b #4,d0 + bne 0b /*Lwait_tl_low*/ + + move.b #0x4f,(0xa1000b).l + move.b #0x40,(a1) +.endm + .equ sat_maxsize, (80*8+0x200) /* sprites+max_align */ # make sure cache is invalidated @@ -185,6 +198,7 @@ jumptab: bra pcc_jump bra pcc_io bra pcc_loadstate + bra pcc_vram_send bra pcc_test_code @@ -210,13 +224,7 @@ pcc_transfer_send: bsr recv_ad move.l d0,d3 -0: /*Lwait_tl_low: it should switch to rx mode before lowering tl */ - move.b (a1),d0 - btst.b #4,d0 - bne 0b /*Lwait_tl_low*/ - - move.b #0x4f,(0xa1000b).l - move.b #0x40,(a1) + switch_to_output tr_send_loop: move.b (a0)+,d0 @@ -292,13 +300,7 @@ pcc_io_w32: bra pcc_io_loop pcc_io_rx: -0: /*Lwait_tl_low:*/ - move.b (a1),d0 - btst.b #4,d0 - bne 0b /*Lwait_tl_low*/ - - move.b #0x4f,(0xa1000b).l - move.b #0x40,(a1) + switch_to_output cmp.b #IOSEQ_R32, d3 beq pcc_io_r32 @@ -402,6 +404,26 @@ tr_do_vdpreg_loop: bra return +pcc_vram_send: + /* write VRAM */ + move.l #0xc00000,a0 + move.w #0x8f02,4(a0) /* auto increment 2 */ + move.l #0,4(a0) /* VRAM read, addr 0 */ + move.l #0x10000/2-1,d4 + + switch_to_output + +tr_vram_send_loop: + move.w (a0),d3 + move.w d3,d0 + lsr.w #8,d0 + bsr send_byte + move.b d3,d0 + bsr send_byte + dbra d4,tr_vram_send_loop + + bra return + /* some random code */ @@ -418,7 +440,8 @@ return: move.l d2,(a1)+ move.l d3,(a1)+ move.l a0,(a1)+ - bra return_to_main + rts +# bra return_to_main # vim:filetype=asmM68k diff --git a/hexed/transfer.h b/hexed/transfer.h index 7db1e5e..118b752 100644 --- a/hexed/transfer.h +++ b/hexed/transfer.h @@ -1,14 +1,15 @@ /* all data is big endian */ #define CMD_PREFIX 0x5a -#define CMD_MD_SEND 0xc1 /* send to MD: addr[3], len[3], data[] */ -#define CMD_MD_RECV 0xc2 /* recv from MD: addr[3], len[3], data[] */ +#define CMD_PC_SEND 0xc1 /* send to MD: addr[3], len[3], data[] */ +#define CMD_PC_RECV 0xc2 /* recv from MD: addr[3], len[3], data[] */ #define CMD_JUMP 0xc3 /* jump to addr: addr[3] */ #define CMD_IOSEQ 0xc4 /* perform i/o ops: count[2], [type[1], addr[3], data[{0,1,2,4}]]* */ #define CMD_LOADSTATE 0xc5 /* load PD state: vram[64k], cram[128], vsram[128], vdp[32] */ -#define CMD_TEST 0xc6 /* test code */ +#define CMD_VRAM_RECV 0xc6 /* recv from MD: vram[64k] */ +#define CMD_TEST 0xc7 /* test code */ -#define CMD_FIRST CMD_MD_SEND +#define CMD_FIRST CMD_PC_SEND #define CMD_LAST CMD_TEST #define IOSEQ_R8 0xb0