X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=f5b8ce3df8b11e5c13a1c1a3d2b6045f849f3788;hb=e1cd546fc7ec6f3c83a5b0f50e2d4ea93b139e3c;hp=e329b5aa9ef543b8d3358096499234fedce81c13;hpb=88bfc63d316f9a19ce6d63421757f520cb4d6df9;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index e329b5a..f5b8ce3 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -53,6 +53,8 @@ char noticeMsg[64]; // notice msg to draw unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer int reset_timing = 0; +static int pico_pen_x = 0, pico_pen_y = 0, pico_inp_mode = 0; + static void emu_msg_cb(const char *msg); static void emu_msg_tray_open(void); @@ -225,18 +227,18 @@ static void cd_leds(void) } } -static int EmuScan16(unsigned int num, void *sdata) +static int EmuScanBegin16(unsigned int num) { if (!(Pico.video.reg[1]&8)) num += 8; - DrawLineDest = (unsigned short *) gp2x_screen + 320*(num+1); + DrawLineDest = (unsigned short *) gp2x_screen + 320 * num; return 0; } -static int EmuScan8(unsigned int num, void *sdata) +static int EmuScanBegin8(unsigned int num) { if (!(Pico.video.reg[1]&8)) num += 8; - DrawLineDest = (unsigned char *) gp2x_screen + 320*(num+1); + DrawLineDest = (unsigned char *) gp2x_screen + 320 * num; return 0; } @@ -266,7 +268,8 @@ static void blit(const char *fps, const char *notice) else if (!(emu_opt&0x80)) { // 8bit accurate renderer - if (Pico.m.dirtyPal) { + if (Pico.m.dirtyPal) + { Pico.m.dirtyPal = 0; if(Pico.video.reg[0xC]&8) { // shadow/hilight mode vidConvCpyRGB32(localPal, Pico.cram, 0x40); @@ -278,7 +281,7 @@ static void blit(const char *fps, const char *notice) localPal[0xe0] = 0x00000000; // reserved pixels for OSD localPal[0xf0] = 0x00ffffff; gp2x_video_setpalette(localPal, 0x100); - } else if (rendstatus & 0x20) { // mid-frame palette changes + } else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes vidConvCpyRGB32(localPal, Pico.cram, 0x40); vidConvCpyRGB32(localPal+0x40, HighPal, 0x40); vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40); @@ -297,7 +300,7 @@ static void blit(const char *fps, const char *notice) if (emu_opt & 2) osd_text(osd_fps_x, h, fps); } - if ((emu_opt & 0x400) && (PicoMCD & 1)) + if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD)) cd_leds(); //gp2x_video_wait_vsync(); @@ -339,13 +342,11 @@ static void vidResetMode(void) } else if (currentConfig.EmuOpt&0x80) { gp2x_video_changemode(16); PicoDrawSetColorFormat(1); - PicoScan = EmuScan16; - PicoScan(0, 0); + PicoScanBegin = EmuScanBegin16; } else { gp2x_video_changemode(8); PicoDrawSetColorFormat(2); - PicoScan = EmuScan8; - PicoScan(0, 0); + PicoScanBegin = EmuScanBegin8; } if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { // setup pal for 8-bit modes @@ -397,6 +398,41 @@ static void emu_msg_tray_open(void) gettimeofday(¬iceMsgTime, 0); } +static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) +{ + if (events & (1 << 3)) { + pico_inp_mode++; + if (pico_inp_mode > 2) pico_inp_mode = 0; + switch (pico_inp_mode) { + case 0: strcpy(noticeMsg, "Input: Joytick "); break; + case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break; + case 2: strcpy(noticeMsg, "Input: Pen on Pad "); break; + } + gettimeofday(¬iceMsgTime, 0); + } + if (events & (1 << 4)) { + PicoPicoPage--; + if (PicoPicoPage < 0) PicoPicoPage = 0; + sprintf(noticeMsg, "Page %i ", PicoPicoPage); + gettimeofday(¬iceMsgTime, 0); + } + if (events & (1 << 5)) { + PicoPicoPage++; + if (PicoPicoPage > 6) PicoPicoPage = 6; + sprintf(noticeMsg, "Page %i ", PicoPicoPage); + gettimeofday(¬iceMsgTime, 0); + } + if (pico_inp_mode != 0) { + PicoPad[0] &= ~0x0f; // release UDLR + if (gp2x_keys & GP2X_UP) { pico_pen_y--; if (pico_pen_y < 0) pico_pen_y = 0; } + 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); + } +} + static void update_volume(int has_changed, int is_up) { static int prev_frame = 0, wait_frames = 0; @@ -466,9 +502,11 @@ static void RunEvents(unsigned int which) (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save unsigned long keys; blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)"); - while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) + while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024); if (keys & GP2X_X) do_it = 0; + while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release + usleep(50*1024); clearArea(0); } if (do_it) { @@ -519,8 +557,8 @@ static void RunEvents(unsigned int which) static void updateKeys(void) { - unsigned long keys, allActions[2] = { 0, 0 }, events; - static unsigned long prevEvents = 0; + unsigned int keys, keys2, allActions[2] = { 0, 0 }, events; + static unsigned int prevEvents = 0; int joy, i; keys = gp2x_joystick_read(0); @@ -531,10 +569,11 @@ static void updateKeys(void) } keys &= CONFIGURABLE_KEYS; + keys2 = keys; for (i = 0; i < 32; i++) { - if (keys & (1 << i)) + if (keys2 & (1 << i)) { int pl, acts = currentConfig.KeyBinds[i]; if (!acts) continue; @@ -545,9 +584,9 @@ static void updateKeys(void) // let's try to find the other one if (acts_c) { for (; u < 32; u++) - if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { + if ( (keys2 & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { allActions[pl] |= acts_c & currentConfig.KeyBinds[u]; - keys &= ~((1 << i) | (1 << u)); + keys2 &= ~((1 << i) | (1 << u)); break; } } @@ -565,9 +604,9 @@ static void updateKeys(void) { gp2x_usbjoy_update(); for (joy = 0; joy < num_of_joys; joy++) { - int keys = gp2x_usbjoy_check2(joy); + int btns = gp2x_usbjoy_check2(joy); for (i = 0; i < 32; i++) { - if (keys & (1 << i)) { + if (btns & (1 << i)) { int acts = currentConfig.JoyBinds[joy][i]; int pl = (acts >> 16) & 1; allActions[pl] |= acts; @@ -589,6 +628,10 @@ static void updateKeys(void) change_fast_forward(events & 0x40); events &= ~prevEvents; + + if (PicoAHW == PAHW_PICO) + RunEventsPico(events, keys); + if (events) RunEvents(events); if (movie_data) emu_updateMovie(); @@ -625,8 +668,7 @@ void emu_forcedFrame(void) //vidResetMode(); PicoDrawSetColorFormat(1); - PicoScan = EmuScan16; - PicoScan(0, 0); + PicoScanBegin = EmuScanBegin16; Pico.m.dirtyPal = 1; PicoFrameDrawOnly(); @@ -782,7 +824,7 @@ void emu_Loop(void) } // prepare CD buffer - if (PicoMCD & 1) PicoCDBufferInit(); + if (PicoAHW & PAHW_MCD) PicoCDBufferInit(); // calc vsync offset to sync timing code with vsync if (currentConfig.EmuOpt&0x2000) { @@ -865,9 +907,10 @@ void emu_Loop(void) bench_fps += frames_shown; sprintf(fpsbuff, "%02i/%02i/%02i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2); #else - if (currentConfig.EmuOpt & 2) + if (currentConfig.EmuOpt & 2) { sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done); - if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; } + if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; } + } #endif frames_shown = frames_done = 0; thissec = tval.tv_sec; @@ -959,7 +1002,7 @@ void emu_Loop(void) change_fast_forward(0); - if (PicoMCD & 1) PicoCDBufferFree(); + if (PicoAHW & PAHW_MCD) PicoCDBufferFree(); // save SRAM if((currentConfig.EmuOpt & 1) && SRam.changed) { @@ -976,7 +1019,7 @@ void emu_Loop(void) void emu_ResetGame(void) { - PicoReset(0); + PicoReset(); reset_timing = 1; }