\r
#include "emu.h"\r
#include "gp2x.h"\r
-#include "usbjoy.h"\r
#include "menu.h"\r
+#include "../linux/usbjoy.h"\r
#include "../common/arm_utils.h"\r
#include "../common/fonts.h"\r
#include "../common/emu.h"\r
#include "../common/config.h"\r
+#include "../common/input.h"\r
+#include "../linux/sndout_oss.h"\r
#include "cpuctrl.h"\r
\r
-#include <Pico/PicoInt.h>\r
-#include <Pico/Patch.h>\r
-#include <Pico/sound/mix.h>\r
+#include <pico/pico_int.h>\r
+#include <pico/patch.h>\r
+#include <pico/sound/mix.h>\r
#include <zlib/zlib.h>\r
\r
//#define PFRAMES\r
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
static int osd_fps_x;\r
static int gp2x_old_gamma = 100;\r
-char noticeMsg[64]; // notice msg to draw\r
unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer\r
int reset_timing = 0;\r
\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
\r
-void emu_getMainDir(char *dst, int len)\r
+int emu_getMainDir(char *dst, int len)\r
{\r
extern char **g_argv;\r
int j;\r
dst[len] = 0;\r
for (j = strlen(dst); j > 0; j--)\r
if (dst[j] == '/') { dst[j+1] = 0; break; }\r
+\r
+ return j + 1;\r
}\r
\r
void emu_Init(void)\r
SRam.changed = 0;\r
}\r
\r
- if (!(currentConfig.EmuOpt & 0x20)) {\r
- config_writelrom(PicoConfigFile);\r
-#ifndef NO_SYNC\r
- sync();\r
-#endif\r
- }\r
+ if (!(currentConfig.EmuOpt & EOPT_NO_AUTOSVCFG))\r
+ emu_writelrom();\r
\r
free(PicoDraw2FB);\r
\r
defaultConfig.KeyBinds[22] = 1<<30; // vol down\r
defaultConfig.gamma = 100;\r
defaultConfig.scaling = 0;\r
-}\r
-\r
-void emu_setDefaultConfig(void)\r
-{\r
- memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig));\r
- PicoOpt = currentConfig.s_PicoOpt;\r
- PsndRate = currentConfig.s_PsndRate;\r
- PicoRegionOverride = currentConfig.s_PicoRegion;\r
- PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
- PicoCDBuffers = currentConfig.s_PicoCDBuffers;\r
+ defaultConfig.turbo_rate = 15;\r
}\r
\r
void osd_text(int x, int y, const char *text)\r
// 8bit accurate renderer\r
if (Pico.m.dirtyPal)\r
{\r
- int pallen = 0x40;\r
+ int pallen = 0xc0;\r
Pico.m.dirtyPal = 0;\r
if (Pico.video.reg[0xC]&8) // shadow/hilight mode\r
{\r
memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
pallen = 0x100;\r
}\r
- else if (rendstatus & PDRAW_ACC_SPRITES) {\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- memcpy32(localPal+0x40, localPal, 0x40);\r
- memcpy32(localPal+0x80, localPal, 0x40);\r
- memcpy32(localPal+0xc0, localPal, 0x40);\r
- pallen = 0x100;\r
- }\r
else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);\r
- pallen = 0xc0;\r
}\r
else {\r
vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
+ memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess\r
}\r
if (pallen > 0xc0) {\r
localPal[0xc0] = 0x0000c000;\r
\r
static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
{\r
+ int ret, px, py, lim_x;\r
+ static int pdown_frames = 0;\r
+\r
emu_RunEventsPico(events);\r
\r
- if (pico_inp_mode != 0)\r
+ if (pico_inp_mode == 0) return;\r
+\r
+ // for F200\r
+ ret = gp2x_touchpad_read(&px, &py);\r
+ if (ret >= 0)\r
{\r
- PicoPad[0] &= ~0x0f; // release UDLR\r
- if (gp2x_keys & GP2X_UP) { pico_pen_y--; if (pico_pen_y < 0) pico_pen_y = 0; }\r
- if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 239-PICO_PEN_ADJUST_Y) pico_pen_y = 239-PICO_PEN_ADJUST_Y; }\r
- if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; }\r
- if (gp2x_keys & GP2X_RIGHT) {\r
- int lim = (Pico.video.reg[12]&1) ? 319 : 255;\r
- pico_pen_x++;\r
- if (pico_pen_x > lim-PICO_PEN_ADJUST_X)\r
- pico_pen_x = lim-PICO_PEN_ADJUST_X;\r
+ if (ret > 35000)\r
+ {\r
+ if (pdown_frames++ > 5)\r
+ PicoPad[0] |= 0x20;\r
+\r
+ pico_pen_x = px;\r
+ pico_pen_y = py;\r
+ if (!(Pico.video.reg[12]&1)) {\r
+ pico_pen_x -= 32;\r
+ if (pico_pen_x < 0) pico_pen_x = 0;\r
+ if (pico_pen_x > 248) pico_pen_x = 248;\r
+ }\r
+ if (pico_pen_y > 224) pico_pen_y = 224;\r
}\r
- PicoPicohw.pen_pos[0] = pico_pen_x;\r
- if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
- PicoPicohw.pen_pos[0] += 0x3c;\r
- PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
+ else\r
+ pdown_frames = 0;\r
+\r
+ //if (ret == 0)\r
+ // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
}\r
+\r
+ PicoPad[0] &= ~0x0f; // release UDLR\r
+ if (gp2x_keys & GP2X_UP) pico_pen_y--;\r
+ if (gp2x_keys & GP2X_DOWN) pico_pen_y++;\r
+ if (gp2x_keys & GP2X_LEFT) pico_pen_x--;\r
+ if (gp2x_keys & GP2X_RIGHT) pico_pen_x++;\r
+\r
+ lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
+ if (pico_pen_y < 8) pico_pen_y = 8;\r
+ if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y;\r
+ if (pico_pen_x < 0) pico_pen_x = 0;\r
+ if (pico_pen_x > lim_x-PICO_PEN_ADJUST_X) pico_pen_x = lim_x-PICO_PEN_ADJUST_X;\r
+\r
+ PicoPicohw.pen_pos[0] = pico_pen_x;\r
+ if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
+ PicoPicohw.pen_pos[0] += 0x3c;\r
+ PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
}\r
\r
static void update_volume(int has_changed, int is_up)\r
if (vol > 0) vol--;\r
}\r
wait_frames = 0;\r
- gp2x_sound_volume(vol, vol);\r
+ sndout_oss_setvol(vol, vol);\r
currentConfig.volume = vol;\r
}\r
sprintf(noticeMsg, "VOL: %02i", vol);\r
keys &= CONFIGURABLE_KEYS;\r
keys2 = keys;\r
\r
+#if 1\r
+ /* FIXME: combos, player2 */\r
+ allActions[0] = in_update();\r
+#else\r
for (i = 0; i < 32; i++)\r
{\r
if (keys2 & (1 << i))\r
}\r
}\r
}\r
+#endif\r
\r
// add joy inputs\r
if (num_of_joys > 0)\r
{\r
- gp2x_usbjoy_update();\r
+ usbjoy_update();\r
for (joy = 0; joy < num_of_joys; joy++) {\r
- int btns = gp2x_usbjoy_check2(joy);\r
+ int btns = usbjoy_check2(joy);\r
for (i = 0; i < 32; i++) {\r
if (btns & (1 << i)) {\r
int acts = currentConfig.JoyBinds[joy][i];\r
}\r
}\r
\r
- PicoPad[0] = (unsigned short) allActions[0];\r
- PicoPad[1] = (unsigned short) allActions[1];\r
+ PicoPad[0] = allActions[0] & 0xfff;\r
+ PicoPad[1] = allActions[1] & 0xfff;\r
+\r
+ if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);\r
+ if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);\r
\r
events = (allActions[0] | allActions[1]) >> 16;\r
\r
\r
/* avoid writing audio when lagging behind to prevent audio lag */\r
if (PicoSkipFrame != 2)\r
- gp2x_sound_write(PsndOut, len<<1);\r
+ sndout_oss_write(PsndOut, len<<1);\r
+}\r
+\r
+void emu_startSound(void)\r
+{\r
+ static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
+ int target_fps = Pico.m.pal ? 50 : 60;\r
+\r
+ PsndOut = NULL;\r
+\r
+ // prepare sound stuff\r
+ if (currentConfig.EmuOpt & 4)\r
+ {\r
+ int snd_excess_add;\r
+ if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old ||\r
+ ((PicoOpt&0x200) && crashed_940)) {\r
+ PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+ }\r
+ snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
+ printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
+ PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
+ sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);\r
+ sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
+ PicoWriteSound = updateSound;\r
+ update_volume(0, 0);\r
+ memset(sndBuffer, 0, sizeof(sndBuffer));\r
+ PsndOut = sndBuffer;\r
+ PsndRate_old = PsndRate;\r
+ PicoOpt_old = PicoOpt;\r
+ pal_old = Pico.m.pal;\r
+ }\r
+}\r
+\r
+void emu_endSound(void)\r
+{\r
+}\r
+\r
+/* wait until we can write more sound */\r
+void emu_waitSound(void)\r
+{\r
+ // don't need to do anything, writes will block by themselves\r
}\r
\r
\r
currentConfig.EmuOpt = eo_old;\r
}\r
\r
+void emu_platformDebugCat(char *str)\r
+{\r
+ // nothing\r
+}\r
+\r
static void simpleWait(int thissec, int lim_time)\r
{\r
struct timeval tval;\r
\r
void emu_Loop(void)\r
{\r
- static int gp2x_old_clock = 200;\r
- static int PsndRate_old = 0, PicoOpt_old = 0, EmuOpt_old = 0, pal_old = 0;\r
+ static int gp2x_old_clock = 200, EmuOpt_old = 0;\r
char fpsbuff[24]; // fps count c string\r
struct timeval tval; // timing\r
int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync\r
target_frametime = 1000000/target_fps;\r
reset_timing = 1;\r
\r
- // prepare sound stuff\r
- if (currentConfig.EmuOpt & 4)\r
- {\r
- int snd_excess_add;\r
- if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old ||\r
- ((PicoOpt&0x200) && crashed_940)) {\r
- PsndRerate(Pico.m.frame_count ? 1 : 0);\r
- }\r
- snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
- printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
- PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
- gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);\r
- gp2x_sound_volume(currentConfig.volume, currentConfig.volume);\r
- PicoWriteSound = updateSound;\r
- update_volume(0, 0);\r
- memset(sndBuffer, 0, sizeof(sndBuffer));\r
- PsndOut = sndBuffer;\r
- PsndRate_old = PsndRate;\r
- PicoOpt_old = PicoOpt;\r
- pal_old = Pico.m.pal;\r
- } else {\r
- PsndOut = NULL;\r
- }\r
+ emu_startSound();\r
\r
// prepare CD buffer\r
if (PicoAHW & PAHW_MCD) PicoCDBufferInit();\r