From 66fdc0f0d590809fb0040d08fd57607bf80b1abc Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 16 Mar 2007 20:59:11 +0000 Subject: [PATCH] loading msgs, bugfixes git-svn-id: file:///home/notaz/opt/svn/PicoDrive@69 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Cart.c | 5 +++++ Pico/Memory.s | 8 ++++---- Pico/MemoryCmn.c | 7 +++---- Pico/Pico.c | 15 ++------------- Pico/Pico.h | 2 +- Pico/cd/Memory.c | 23 ++++++++++++++++++----- Pico/cd/Pico.s | 23 +++++++++++------------ Pico/cd/buffering.c | 19 +++++++++++++++++-- cpu/Cyclone/Main.cpp | 10 ++++------ platform/gp2x/940ctl.c | 6 ++++++ platform/gp2x/Makefile | 2 +- platform/gp2x/emu.c | 20 ++++++++++++++++++++ platform/gp2x/menu.c | 2 +- 13 files changed, 93 insertions(+), 49 deletions(-) diff --git a/Pico/Cart.c b/Pico/Cart.c index a865033..07ced8c 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -129,6 +129,11 @@ int pm_seek(pm_file *stream, long offset, int whence) } else if (stream->type == PMT_ZIP) { + if (PicoMessage != NULL && offset > 6*1024*1024) { + long pos = gztell((gzFile) stream->param); + if (offset < pos || offset - pos > 6*1024*1024) + PicoMessage("Decompressing data..."); + } return gzseek((gzFile) stream->param, offset, whence); } else diff --git a/Pico/Memory.s b/Pico/Memory.s index 51778c4..02c5a2c 100644 --- a/Pico/Memory.s +++ b/Pico/Memory.s @@ -384,7 +384,7 @@ m_read8_above_rom: stmfd sp!,{r0,lr} bic r0, r0, #1 mov r1, #8 - bl UnusualRead16 + bl OtherRead16End ldmfd sp!,{r1,lr} tst r1, #1 moveq r0, r0, lsr #8 @@ -507,7 +507,7 @@ m_read16_ram: m_read16_above_rom: mov r1, #16 - ldr r2, =UnusualRead16 + ldr r2, =OtherRead16End bic r0, r0, #1 bx r2 @@ -657,13 +657,13 @@ m_read32_above_rom: bic r0, r0, #1 stmfd sp!,{r0,lr} mov r1, #32 - bl UnusualRead16 + bl OtherRead16End mov r1, r0 ldmfd sp!,{r0} stmfd sp!,{r1} add r0, r0, #2 mov r1, #32 - bl UnusualRead16 + bl OtherRead16End ldmfd sp!,{r1,lr} orr r0, r0, r1, lsl #16 bx lr diff --git a/Pico/MemoryCmn.c b/Pico/MemoryCmn.c index 5c7ef84..43433af 100644 --- a/Pico/MemoryCmn.c +++ b/Pico/MemoryCmn.c @@ -98,15 +98,14 @@ u32 OtherRead16(u32 a, int realsize) // |=0x80 for Shadow of the Beast & Super Offroad; rotate fakes next fetched instruction for Time Killers if (a==0xa11100) { // z80 busreq d=Pico.m.z80Run&1; -#if 0 if (!d) { - // do we need this? + // needed by buggy Terminator (Sega CD) extern int z80stopCycle; int stop_before = SekCyclesDone() - z80stopCycle; - if (stop_before > 0 && stop_before <= 16) // Gens uses 16 here + dprintf("stop before: %i", stop_before); + if (stop_before > 0 && stop_before <= 32) // Gens uses 16 here d = 1; // bus not yet available } -#endif d=(d<<8)|0x8000|Pico.m.rotate++; dprintf("get_zrun: %04x [%i|%i] @%06x", d, Pico.m.scanline, SekCyclesDone(), SekPc); goto end; diff --git a/Pico/Pico.c b/Pico/Pico.c index 3cee0c2..5fd1557 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -636,19 +636,8 @@ int PicoFrame(void) return 0; } -static int DefaultCram(int cram) -{ - int high=0x0841; - // Convert 0000bbbb ggggrrrr - // to rrrr1ggg g10bbbb1 - high|=(cram&0x00f)<<12; // Red - high|=(cram&0x0f0)<< 3; // Green - high|=(cram&0xf00)>> 7; // Blue - return high; -} - -// Function to convert Megadrive Cram into a native colour: -int (*PicoCram)(int cram)=DefaultCram; +// callback to output message from emu +void (*PicoMessage)(const char *msg)=NULL; #if defined(__DEBUG_PRINT) || defined(WIN32) // tmp debug: dump some stuff diff --git a/Pico/Pico.h b/Pico/Pico.h index 603c5e9..597f021 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -42,8 +42,8 @@ void PicoExit(void); int PicoReset(int hard); int PicoFrame(void); extern int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU -extern int (*PicoCram)(int cram); // Callback to convert colour ram 0000bbb0 ggg0rrr0 extern void (*PicoWriteSound)(int len); // called once per frame at the best time to send sound buffer (PsndOut) to hardware +extern void (*PicoMessage)(const char *msg); // callback to output text message from emu int PicoFrameMCD(void); diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index 5a4f28e..805c9f3 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -27,6 +27,7 @@ typedef unsigned int u32; //#define __debug_io //#define __debug_io2 + //#define rdprintf dprintf #define rdprintf(...) //#define wrdprintf dprintf @@ -106,18 +107,30 @@ static void m68k_reg_write8(u32 a, u32 d) case 2: Pico_mcd->s68k_regs[2] = d; // really use s68k side register return; - case 3: + case 3: { + u32 dold = Pico_mcd->s68k_regs[3]&0x1f; dprintf("m68k_regs w3: %02x @%06x", (u8)d, SekPc); d &= 0xc2; - if ((Pico_mcd->s68k_regs[3]>>6) != ((d>>6)&3)) + if ((dold>>6) != ((d>>6)&3)) dprintf("m68k: prg bank: %i -> %i", (Pico_mcd->s68k_regs[a]>>6), ((d>>6)&3)); //if ((Pico_mcd->s68k_regs[3]&4) != (d&4)) dprintf("m68k: ram mode %i mbit", (d&4) ? 1 : 2); //if ((Pico_mcd->s68k_regs[3]&2) != (d&2)) dprintf("m68k: %s", (d&4) ? ((d&2) ? "word swap req" : "noop?") : // ((d&2) ? "word ram to s68k" : "word ram to m68k")); - d |= Pico_mcd->s68k_regs[3]&0x1d; - if (!(d & 4) && (d & 2)) d &= ~1; // return word RAM to s68k in 2M mode - Pico_mcd->s68k_regs[3] = d; // really use s68k side register + if (dold & 4) { + d ^= 2; // writing 0 to DMNA actually sets it, 1 does nothing + } else { + //dold &= ~2; // ?? + if (d & 2) dold &= ~1; // return word RAM to s68k in 2M mode + } + Pico_mcd->s68k_regs[3] = d | dold; // really use s68k side register + +/* + d |= Pico_mcd->s68k_regs[3]&0x1d; + if (!(d & 4) && (d & 2)) d &= ~1; // return word RAM to s68k in 2M mode + Pico_mcd->s68k_regs[3] = d; // really use s68k side register +*/ return; + } case 6: Pico_mcd->bios[0x72 + 1] = d; // simple hint vector changer return; diff --git a/Pico/cd/Pico.s b/Pico/cd/Pico.s index 24e4d1c..380ca5d 100644 --- a/Pico/cd/Pico.s +++ b/Pico/cd/Pico.s @@ -83,8 +83,9 @@ schedule_s68k: ldr r9, [r9] sub r0, r9, r8 - add r3, r3, r3, asr #1 - add r3, r3, r3, asr #3 @ cycn_s68k = (cycn + cycn/2 + cycn/8) + mov r2, r3 + add r3, r3, r2, asr #1 + add r3, r3, r2, asr #3 @ cycn_s68k = (cycn + cycn/2 + cycn/8) subs r5, r0, r3, asr #16 ble schedule_m68k @ s68k has not enough cycles @@ -148,31 +149,29 @@ CycloneRunLocal: ;@ r7 = Pointer to Cpu Context ;@ r8 = Current Opcode ldrb r9,[r7,#0x46] ;@ r9 = Flags (NZCV) - ldr r0,[r7,#0x44] - mov r9,r9,lsl #28 ;@ r9 = Flags 0xf0000000, cpsr format + ldr r1,[r7,#0x44] ;@ get SR high and IRQ level + orr r9,r9,r9,lsl #28 ;@ r9 = Flags 0xf0000000, cpsr format ;@ r10 = Source value / Memory Base ;@ CheckInterrupt: - movs r0,r0,lsr #24 ;@ Get IRQ level + movs r0,r1,lsr #24 ;@ Get IRQ level beq NoIntsLocal cmp r0,#6 ;@ irq>6 ? - ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III andle r1,r1,#7 ;@ Get interrupt mask cmple r0,r1 ;@ irq<=6: Is irq<=mask ? - blgt CycloneDoInterrupt -;@ Check if interrupt used up all the cycles: - subs r5,r5,#0 - ldrlt r1,[r7,#0x54] - bxlt r1 ;@ jump to alternative CycloneEnd + ldrgt lr,[r7,#0x54] @ Interrupt will definitely use more cycles than our step, + bgt CycloneDoInterrupt @ so make this function return directly to CycloneEnd_* NoIntsLocal: -;@ Check if our processor is in stopped state and jump to opcode handler if not + ;@ Check if our processor is in stopped state and jump to opcode handler if not ldr r0,[r7,#0x58] ldrh r8,[r4],#2 ;@ Fetch first opcode tst r0,r0 ;@ stopped? + andeq r9,r9,#0xf0000000 ldreq pc,[r6,r8,asl #2] ;@ Jump to opcode handler @ stopped + sub r4,r4,#2 ldr r1,[r7,#0x54] mov r5,#0 bx r1 diff --git a/Pico/cd/buffering.c b/Pico/cd/buffering.c index 5afc6e8..c391cf4 100644 --- a/Pico/cd/buffering.c +++ b/Pico/cd/buffering.c @@ -49,7 +49,7 @@ void PicoCDBufferFree(void) /* this is a try to fight slow SD access of GP2X */ void PicoCDBufferRead(void *dest, int lba) { - int is_bin, offs, read_len; + int is_bin, offs, read_len, moved = 0; reads++; is_bin = Pico_mcd->TOC.Tracks[0].ftype == TYPE_BIN; @@ -84,15 +84,21 @@ void PicoCDBufferRead(void *dest, int lba) if (lba < prev_lba && prev_lba - lba < PicoCDBuffers) { - dprintf("CD buffer move"); read_len = prev_lba - lba; + dprintf("CD buffer move=%i, read_len=%i", PicoCDBuffers - read_len, read_len); memmove(cd_buffer + read_len*2048, cd_buffer, (PicoCDBuffers - read_len)*2048); + moved = 1; } else { read_len = PicoCDBuffers; } + if (PicoMessage != NULL && read_len >= 512) + { + PicoMessage("Buffering data..."); + } + if (is_bin) { int i; @@ -108,5 +114,14 @@ void PicoCDBufferRead(void *dest, int lba) } memcpy32(dest, (int *) cd_buffer, 2048/4); prev_lba = lba; + + if (moved) + { + /* file pointer must point to the same data in file, as would-be data after our buffer */ + int where_seek; + lba += PicoCDBuffers; + where_seek = is_bin ? (lba * 2352 + 16) : (lba << 11); + pm_seek(Pico_mcd->TOC.Tracks[0].F, where_seek, SEEK_SET); + } } diff --git a/cpu/Cyclone/Main.cpp b/cpu/Cyclone/Main.cpp index aca7f4f..3bb129d 100644 --- a/cpu/Cyclone/Main.cpp +++ b/cpu/Cyclone/Main.cpp @@ -86,11 +86,10 @@ static void PrintException(int ints) void CheckInterrupt(int op) { ot(";@ CheckInterrupt:\n"); - ot(" ldr r0,[r7,#0x44]\n"); // same as ldrb r0,[r7,#0x47] - ot(" movs r0,r0,lsr #24 ;@ Get IRQ level (loading word is faster)\n"); + ot(" ldr r1,[r7,#0x44] ;@ Get SR high T_S__III and irq level\n"); + ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47] ot(" beq NoInts%x\n",op); ot(" cmp r0,#6 ;@ irq>6 ?\n"); - ot(" ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III\n"); ot(" andle r1,r1,#7 ;@ Get interrupt mask\n"); ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n"); ot(" blgt CycloneDoInterrupt\n"); @@ -113,15 +112,14 @@ static void PrintFramework() ot(" ldr r5,[r7,#0x5c] ;@ r5 = Cycles\n"); ot(" ldr r4,[r7,#0x40] ;@ r4 = Current PC + Memory Base\n"); ot(" ;@ r8 = Current Opcode\n"); - ot(" ldr r0,[r7,#0x44]\n"); + ot(" ldr r1,[r7,#0x44] ;@ Get SR high T_S__III and irq level\n"); ot(" mov r9,r9,lsl #28 ;@ r9 = Flags 0xf0000000, cpsr format\n"); ot(" ;@ r10 = Source value / Memory Base\n"); ot("\n"); ot(";@ CheckInterrupt:\n"); - ot(" movs r0,r0,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47] + ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47] ot(" beq NoInts0\n"); ot(" cmp r0,#6 ;@ irq>6 ?\n"); - ot(" ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III\n"); ot(" andle r1,r1,#7 ;@ Get interrupt mask\n"); ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n"); ot(" blgt CycloneDoInterrupt\n"); diff --git a/platform/gp2x/940ctl.c b/platform/gp2x/940ctl.c index 5c53761..48ebfa0 100644 --- a/platform/gp2x/940ctl.c +++ b/platform/gp2x/940ctl.c @@ -563,6 +563,12 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 if (loaded_mp3 != f) { // printf("loading mp3... "); fflush(stdout); + if (PicoMessage != NULL) + { + fseek(f, 0, SEEK_END); + if (ftell(f) > 2*1024*1024) + PicoMessage("Loading MP3..."); + } fseek(f, 0, SEEK_SET); fread(mp3_mem, 1, MP3_SIZE_MAX, f); // if (feof(f)) printf("done.\n"); diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index d6ba1d5..7818741 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -8,7 +8,7 @@ CROSS = arm-linux- dprint = 1 #mz80 = 1 #debug_cyclone = 1 -asm_memory = 0 # TODO +asm_memory = 1 asm_render = 1 asm_ym2612 = 1 asm_misc = 1 diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index a98a5be..033f275 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -393,6 +393,8 @@ int emu_ReloadRom(void) } +static void emu_msg_cb(const char *msg); + void emu_Init(void) { // make temp buffer for alt renderer @@ -409,6 +411,7 @@ void emu_Init(void) mkdir("cfg", 0777); PicoInit(); + PicoMessage = emu_msg_cb; // logf = fopen("log.txt", "w"); } @@ -771,6 +774,23 @@ static void vidResetMode(void) } +static void emu_msg_cb(const char *msg) +{ + if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + // 8-bit renderers + gp2x_memset_all_buffers(320*232, 0xe0, 320*8); + osd_text(4, 232, msg); + gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232, 320*232, 320*8); + } else { + // 16bit accurate renderer + gp2x_memset_all_buffers(320*232*2, 0, 320*8*2); + osd_text(4, 232, msg); + gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232*2, 320*232*2, 320*8*2); + } + gettimeofday(¬iceMsgTime, 0); + noticeMsgTime.tv_sec -= 2; +} + static void emu_state_cb(const char *str) { clearArea(0); diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 5cab760..7050b98 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -744,7 +744,7 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3 gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4 gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5 - gp2x_text_out8(tl_x, (y+=10), "Better sync (slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6 + gp2x_text_out8(tl_x, (y+=10), "Better sync (slower) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6 gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer %s", ra_buff); // 7 gp2x_text_out8(tl_x, (y+=10), "Done"); -- 2.39.2