From d49b10c2f2c58e03a1be8b3b9e8bfc08703e0ce0 Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 7 May 2008 18:53:53 +0000 Subject: [PATCH] some Pico work git-svn-id: file:///home/notaz/opt/svn/PicoDrive@442 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Pico.h | 11 +++++++++-- Pico/Pico/Memory.c | 35 ++++++++++++++++++++--------------- Pico/Pico/Pico.c | 40 +++++++++++++++++++++++++++++++++++++--- Pico/PicoInt.h | 1 + platform/gp2x/emu.c | 16 ++++++++-------- 5 files changed, 75 insertions(+), 28 deletions(-) diff --git a/Pico/Pico.h b/Pico/Pico.h index f443bae..be3015a 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -71,8 +71,15 @@ extern int (*PicoMCDcloseTray)(void); extern int PicoCDBuffers; // Pico/Pico.c -extern int PicoPicoPenPos[2]; // x: 0x03c-0x17d, y: 0x200-0x2d8 -extern int PicoPicoPage; +typedef struct +{ + int pen_pos[2]; + int page; + // internal + int fifo_bytes; + int line_counter; +} picohw_state; +extern picohw_state PicoPicohw; // Area.c typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file); diff --git a/Pico/Pico/Memory.c b/Pico/Pico/Memory.c index f18edc4..2995c0e 100644 --- a/Pico/Pico/Memory.c +++ b/Pico/Pico/Memory.c @@ -1,4 +1,5 @@ #include "../PicoInt.h" +#include "../sound/sn76496.h" #ifndef UTYPES_DEFINED typedef unsigned char u8; @@ -7,6 +8,7 @@ typedef unsigned int u32; #define UTYPES_DEFINED #endif + // ----------------------------------------------------------------- // Read Rom and read Ram @@ -19,7 +21,7 @@ static u32 PicoReadPico8(u32 a) a&=0xffffff; - if ((a&0xffffe0)==0xc00000) { // VDP + if ((a&0xfffff0)==0xc00000) { // VDP d=PicoVideoRead(a); if ((a&1)==0) d>>=8; goto end; @@ -30,17 +32,16 @@ static u32 PicoReadPico8(u32 a) switch (a & 0x1f) { case 0x03: - d = PicoPad[0]&0x0f; // d-pad - d |= (PicoPad[0]&0x20) >> 1; // red button -> C - d |= (PicoPad[0]&0x40) << 1; // pen tap -> A + d = PicoPad[0]&0x1f; // d-pad + d |= (PicoPad[0]&0x20) << 2; // red button -> C d = ~d; break; - case 0x05: d = (PicoPicoPenPos[0] >> 8) & 3; break; // what is MS bit for? Games read it.. - case 0x07: d = PicoPicoPenPos[0] & 0xff; break; - case 0x09: d = (PicoPicoPenPos[1] >> 8) & 3; break; - case 0x0b: d = PicoPicoPenPos[1] & 0xff; break; - case 0x0d: d = (1 << (PicoPicoPage & 7)) - 1;break; + case 0x05: d = (PicoPicohw.pen_pos[0] >> 8) & 3; break; // what is MS bit for? Games read it.. + case 0x07: d = PicoPicohw.pen_pos[0] & 0xff; break; + case 0x09: d = (PicoPicohw.pen_pos[1] >> 8) & 3; break; + case 0x0b: d = PicoPicohw.pen_pos[1] & 0xff; break; + case 0x0d: d = (1 << (PicoPicohw.page & 7)) - 1; break; case 0x12: d = 0x80; break; default: elprintf(EL_UIO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc); @@ -65,12 +66,13 @@ static u32 PicoReadPico16(u32 a) if (a 0x3f) ? 0 : (0x3f - PicoPicohw.fifo_bytes); elprintf(EL_UIO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc); @@ -89,7 +91,7 @@ static u32 PicoReadPico32(u32 a) if (a>16)); diff --git a/Pico/Pico/Pico.c b/Pico/Pico/Pico.c index 9b4fa8a..fdd5f44 100644 --- a/Pico/Pico/Pico.c +++ b/Pico/Pico/Pico.c @@ -3,14 +3,48 @@ // x: 0x03c - 0x19d // y: 0x1fc - 0x2f7 // 0x2f8 - 0x3f3 -int PicoPicoPenPos[2] = { 0x3c, 0x200 }; -int PicoPicoPage = 0; // 0-6 +picohw_state PicoPicohw; + +static int prev_line_cnt_irq3 = 0, prev_line_cnt_irq5 = 0; + +static void PicoLineHookPico(int count) +{ + + PicoPicohw.line_counter += count; + if ((PicoPicohw.line_counter & 0xf) == 0 || count > 10) + { + if (PicoPicohw.fifo_bytes > 0) + PicoPicohw.fifo_bytes--; + } + +#if 0 + if (PicoPicohw.line_counter - prev_line_cnt_irq3 > 200) { + prev_line_cnt_irq3 = PicoPicohw.line_counter; + // just a guess/hack, allows 101 Dalmantians to boot + elprintf(EL_ANOMALY, "irq3"); + SekInterrupt(3); + } +#endif + +#if 0 + if (PicoPicohw.line_counter - prev_line_cnt_irq5 > 512) { + prev_line_cnt_irq5 = PicoPicohw.line_counter; + elprintf(EL_ANOMALY, "irq5"); + SekInterrupt(5); + } +#endif +} PICO_INTERNAL int PicoInitPico(void) { elprintf(EL_STATUS, "Pico detected"); + PicoLineHook = PicoLineHookPico; + PicoAHW = PAHW_PICO; - PicoPicoPage = 0; + memset(&PicoPicohw, 0, sizeof(PicoPicohw)); + PicoPicohw.pen_pos[0] = 0x03c + 352/2; + PicoPicohw.pen_pos[1] = 0x200 + 252/2; + prev_line_cnt_irq3 = 0, prev_line_cnt_irq5 = 0; return 0; } diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index e185384..5bc463d 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -365,6 +365,7 @@ typedef struct #define Pico_mcd ((mcd_state *)Pico.rom) + // Area.c PICO_INTERNAL int PicoAreaPackCpu(unsigned char *cpu, int is_sub); PICO_INTERNAL int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub); diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index f5b8ce3..e3f1148 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -411,15 +411,15 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) gettimeofday(¬iceMsgTime, 0); } if (events & (1 << 4)) { - PicoPicoPage--; - if (PicoPicoPage < 0) PicoPicoPage = 0; - sprintf(noticeMsg, "Page %i ", PicoPicoPage); + PicoPicohw.page--; + if (PicoPicohw.page < 0) PicoPicohw.page = 0; + sprintf(noticeMsg, "Page %i ", PicoPicohw.page); gettimeofday(¬iceMsgTime, 0); } if (events & (1 << 5)) { - PicoPicoPage++; - if (PicoPicoPage > 6) PicoPicoPage = 6; - sprintf(noticeMsg, "Page %i ", PicoPicoPage); + PicoPicohw.page++; + if (PicoPicohw.page > 6) PicoPicohw.page = 6; + sprintf(noticeMsg, "Page %i ", PicoPicohw.page); gettimeofday(¬iceMsgTime, 0); } if (pico_inp_mode != 0) { @@ -428,8 +428,8 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 251) pico_pen_y = 251; } if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; } if (gp2x_keys & GP2X_RIGHT){ pico_pen_x++; if (pico_pen_x > 353) pico_pen_x = 353; } - PicoPicoPenPos[0] = 0x03c + pico_pen_x; - PicoPicoPenPos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y); + PicoPicohw.pen_pos[0] = 0x03c + pico_pen_x; + PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y); } } -- 2.39.2