\r
\r
#include "PicoInt.h"\r
-#ifndef __GNUC__\r
-#pragma warning (disable:4706) // Disable assignment within conditional\r
-#endif\r
\r
int (*PicoScan)(unsigned int num, void *data)=NULL;\r
\r
-unsigned short DefOutBuff[320*2];\r
+#if OVERRIDE_HIGHCOL\r
+static unsigned char DefHighCol[8+320+8];\r
+unsigned char *HighCol=DefHighCol;\r
+#else\r
unsigned char HighCol[8+320+8];\r
+#endif\r
+unsigned short DefOutBuff[320*2];\r
+void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to\r
+\r
static int HighCacheA[41+1]; // caches for high layers\r
static int HighCacheB[41+1];\r
static int HighCacheS[80+1]; // and sprites\r
// lsb->msb: moved sprites, not all window tiles use same priority, accurate sprites (copied from PicoOpt), interlace\r
// dirty sprites, sonic mode, have layer with all hi prio tiles (mk3), layer sh/hi already processed\r
int rendstatus;\r
-void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to\r
int Scanline=0; // Scanline\r
\r
static int SpriteBlocks;\r
}\r
}\r
\r
-void (*FinalizeLine)(int sh) = FinalizeLineBGR444;\r
+static void (*FinalizeLine)(int sh) = FinalizeLineBGR444;\r
\r
// --------------------------------------------\r
\r
if (Pico.video.reg[1]&0x40)\r
DrawDisplay(sh);\r
\r
- FinalizeLine(sh);\r
- //if (SpriteBlocks & (1<<(scan>>3))) for (sh=0; sh < 30; sh++) DrawLineDest[sh] = 0xf;\r
+ if (FinalizeLine != NULL)\r
+ FinalizeLine(sh);\r
\r
Skip=PicoScan(Scanline,DrawLineDest);\r
\r
\r
void PicoDrawSetColorFormat(int which)\r
{\r
- if (which == 2)\r
- FinalizeLine = FinalizeLine8bit;\r
- else if (which == 1)\r
- FinalizeLine = FinalizeLineRGB555;\r
- else FinalizeLine = FinalizeLineBGR444;\r
+ switch (which)\r
+ {\r
+ case 2: FinalizeLine = FinalizeLine8bit; break;\r
+ case 1: FinalizeLine = FinalizeLineRGB555; break;\r
+ case 0: FinalizeLine = FinalizeLineBGR444; break;\r
+ default:FinalizeLine = NULL; break;\r
+ }\r
}\r
+\r
@ (c) Copyright 2007, Grazvydas "notaz" Ignotas\r
@ All Rights Reserved\r
\r
+.include "port_config.s"\r
\r
.extern Pico\r
.extern PicoOpt\r
add r8, r8, r9, lsr #8 @ tilex+=cellskip\r
add r7, r7, r9, lsr #5 @ dx+=cellskip<<3;\r
sub r10,r10,r9, lsl #16 @ cells-=cellskip\r
- mvn r9, #0 @ r9=prevcode=-1\r
\r
@ cache some stuff to avoid mem access\r
+.if OVERRIDE_HIGHCOL\r
+ ldr r11,=HighCol\r
+ mov r0, #0xf\r
+ ldr r11,[r11]\r
+.else\r
ldr r11,=HighCol\r
mov r0, #0xf\r
+.endif\r
+\r
+ mvn r9, #0 @ r9=prevcode=-1\r
add r1, r11, r7 @ r1=pdest\r
\r
\r
add r8, r8, r9, lsr #8 @ tilex+=cellskip\r
add r7, r7, r9, lsr #5 @ dx+=cellskip<<3;\r
add r10,r10,r9, lsl #16 @ cell+=cellskip\r
- mvn r9, #0 @ r9=prevcode=-1\r
\r
@ cache some stuff to avoid mem access\r
+.if OVERRIDE_HIGHCOL\r
ldr r11,=HighCol\r
mov r0, #0xf\r
- add r1, r11, r7 @ r1=pdest\r
+ ldr r11,[r11]\r
+.else\r
+ ldr r11,=HighCol\r
+ mov r0, #0xf\r
+.endif\r
\r
+ mvn r9, #0 @ r9=prevcode=-1\r
+ add r1, r11, r7 @ r1=pdest\r
\r
@ r4 & r7 are scratch in this loop\r
.dsloop_vs_subr1:\r
BackFill:\r
stmfd sp!, {r4-r9,lr}\r
\r
+.if OVERRIDE_HIGHCOL\r
+ ldr lr, =HighCol\r
+ mov r0, r0, lsl #26\r
+ ldr lr, [lr]\r
+ mov r0, r0, lsr #26\r
+ add lr, lr, #8\r
+.else\r
ldr lr, =(HighCol+8)\r
-\r
mov r0, r0, lsl #26\r
mov r0, r0, lsr #26\r
+.endif\r
+\r
orr r0, r0, r1, lsl #6\r
orr r0, r0, r0, lsl #8\r
orr r0, r0, r0, lsl #16\r
stmfd sp!, {r4-r8,r11,lr}\r
\r
@ cache some stuff to avoid mem access\r
+.if OVERRIDE_HIGHCOL\r
ldr r11,=HighCol\r
- ldr lr, =(Pico+0x10000) @ lr=Pico.vram\r
mov r12,#0xf\r
+ ldr r11,[r11]\r
+.else\r
+ ldr r11,=HighCol\r
+ mov r12,#0xf\r
+.endif\r
+ ldr lr, =(Pico+0x10000) @ lr=Pico.vram\r
\r
mvn r5, #0 @ r5=prevcode=-1\r
ands r8, r1, #1\r
stmfd sp!, {r4-r11,lr}\r
\r
@ cache some stuff to avoid mem access\r
+.if OVERRIDE_HIGHCOL\r
ldr r11,=HighCol\r
+ mov r12,#0xf\r
+ ldr r11,[r11]\r
+.else\r
+ ldr r11,=HighCol\r
+ mov r12,#0xf\r
+.endif\r
ldr lr, =(Pico+0x10000) @ lr=Pico.vram\r
mov r6, r1, lsl #31\r
orr r6, r6, #1<<30\r
- mov r12,#0xf\r
\r
mov r10, r0\r
\r
bne .dspr_cache @ if(code&0x8000) // high priority - cache it\r
\r
@ cache some stuff to avoid mem access\r
+.if OVERRIDE_HIGHCOL\r
+ ldr r11,=HighCol\r
+ mov r12,#0xf\r
+ ldr r11,[r11]\r
+.else\r
ldr r11,=HighCol\r
- ldr lr, =(Pico+0x10000) @ lr=Pico.vram\r
mov r12,#0xf\r
+.endif\r
+ ldr lr, =(Pico+0x10000) @ lr=Pico.vram\r
\r
mov r5, r5, lsl #4 @ delta<<=4; // Delta of address\r
and r4, r9, #0x6000\r
orr r6, r6, r3, lsl #8 @ shadow mode\r
\r
sub r8, r1, r0\r
- mov r8, r8, lsl #1 @ cells\r
-\r
- mvn r9, #0 @ r9=prevcode=-1\r
\r
@ cache some stuff to avoid mem access\r
+.if OVERRIDE_HIGHCOL\r
+ ldr r11,=HighCol\r
+ mov r8, r8, lsl #1 @ cells\r
+ ldr r11,[r11]\r
+ mvn r9, #0 @ r9=prevcode=-1\r
+ add r11,r11,#8\r
+.else\r
ldr r11,=(HighCol+8)\r
+ mov r8, r8, lsl #1 @ cells\r
+ mvn r9, #0 @ r9=prevcode=-1\r
+.endif\r
add r1, r11, r0, lsl #4 @ r1=pdest\r
mov r0, #0xf\r
b .dwloop_enter\r
\r
\r
.fl_noshBGR444:\r
+.if OVERRIDE_HIGHCOL\r
+ ldr r1, =HighCol\r
+ mov lr, #0xff\r
+ ldr r1, [r1]\r
+ mov lr, lr, lsl #1\r
+ add r1, r1, #8\r
+.else\r
ldr r1, =(HighCol+8)\r
mov lr, #0xff\r
mov lr, lr, lsl #1\r
+.endif\r
\r
.fl_loopBGR444:\r
\r
orr \reg, \reg, r3 @ add blue back\r
.endm\r
\r
+.global vidConvCpyRGB565\r
+\r
vidConvCpyRGB565: @ void *to, void *from, int pixels\r
stmfd sp!, {r4-r9,lr}\r
\r
sub r3, r3, #0x40*2\r
\r
.fl_noshRGB555:\r
+.if OVERRIDE_HIGHCOL\r
+ ldr r1, =HighCol\r
+ ldr r0, =DrawLineDest\r
+ ldr r1, [r1]\r
+ ldr r0, [r0]\r
+ add r1, r1, #8\r
+.else\r
ldr r0, =DrawLineDest\r
ldr r1, =(HighCol+8)\r
ldr r0, [r0]\r
+.endif\r
\r
ldrb r12, [r8, #12]\r
mov lr, #0xff\r
stmfd sp!, {r4-r9,lr}\r
\r
ldr lr, =PicoDraw2FB @ lr=PicoDraw2FB\r
+ mov r0, r0, lsl #26\r
ldr lr, [lr]\r
+ mov r0, r0, lsr #26\r
add lr, lr, #328*8\r
\r
- mov r0, r0, lsl #26\r
- mov r0, r0, lsr #26\r
orr r0, r0, r0, lsl #8\r
orr r0, r0, r0, lsl #16\r
\r
\r
mov r6, r1 @ hcache\r
\r
+ ldr r11, =(Pico+0x22228) @ Pico.video\r
+ ldr r10, =(Pico+0x10000) @ r10=Pico.vram\r
+ ldrb r5, [r11, #13] @ pvid->reg[13]\r
+ ldrb r7, [r11, #11]\r
+\r
sub lr, r3, r2\r
and lr, lr, #0x00ff0000 @ lr=cells\r
\r
- ldr r10, =(Pico+0x10000) @ r10=Pico.vram\r
-\r
- ldr r11, =(Pico+0x22228) @ Pico.video\r
- ldrb r5, [r11, #13] @ pvid->reg[13]\r
mov r5, r5, lsl #10 @ htab=pvid->reg[13]<<9; (halfwords)\r
add r5, r5, r0, lsl #1 @ htab+=plane\r
bic r5, r5, #0x00ff0000 @ just in case\r
\r
- ldrb r7, [r11, #11]\r
tst r7, #3 @ full screen scroll? (if ==0)\r
+ ldrb r7, [r11, #16] @ ??hh??ww\r
ldreqh r5, [r10, r5]\r
biceq r5, r5, #0x0000fc00 @ r5=hscroll (0-0x3ff)\r
movne r5, r5, lsr #1\r
orrne r5, r5, #0x8000 @ this marks that we have htab pointer, not hscroll here\r
\r
- ldrb r7, [r11, #16] @ ??hh??ww\r
and r8, r7, #3\r
\r
orr r5, r5, r7, lsl #1+24\r
mov r8, r8, lsl #24+5\r
orr r8, r8, #0x1f000000\r
\r
- @ Find name table:\r
+ @ Find name table:\r
tst r0, r0\r
ldreqb r4, [r11, #2]\r
moveq r4, r4, lsr #3\r
orr lr, lr, r4, lsl #13 @ lr|=nametab_bits{3}<<13\r
\r
ldr r11, =PicoDraw2FB @ r11=PicoDraw2FB\r
- ldr r11, [r11]\r
sub r4, r9, #(START_ROW<<24)\r
+ ldr r11, [r11]\r
mov r4, r4, asr #24\r
mov r7, #328*8\r
mla r11, r4, r7, r11 @ scrpos+=8*328*(planestart-START_ROW);\r
\r
- @ Get vertical scroll value:\r
+ @ Get vertical scroll value:\r
add r7, r10, #0x012000\r
add r7, r7, #0x000180 @ r7=Pico.vsram (Pico+0x22180)\r
ldr r7, [r7]\r
ldrh r7, [r10, r7]\r
\r
.rtr_hscroll_done:\r
+ and r8, r8, #0xff000000\r
rsb r4, r7, #0 @ r4=tilex=(-ts->hscroll)>>3\r
mov r4, r4, asr #3\r
and r4, r4, #0xff\r
- and r8, r8, #0xff000000\r
orr r8, r8, r4 @ r8=(xmask<<24)|tilex\r
\r
sub r7, r7, #1\r
mvn r6, #0 @ r6=prevy=-1\r
\r
ldr r4, =PicoDraw2FB @ r4=PicoDraw2FB\r
- ldr r4, [r4]\r
ldr r1, [r0], #4 @ read y offset\r
+ ldr r4, [r4]\r
mov r7, #328\r
mla r1, r7, r1, r4\r
sub r12, r1, #(328*8*START_ROW) @ r12=scrpos\r
movs r1, r7, lsr #16 @ r1=dx;\r
ldmeqfd sp!, {r4-r10,pc} @ dx is never zero, this must be a terminator, return\r
\r
- @ trow changed?\r
+ @ row changed?\r
cmp r6, r7, lsr #27\r
movne r6, r7, lsr #27\r
movne r4, #328*8\r
mov r9, #0xff000000 @ r9=prevcode=-1\r
\r
ldr r11, =PicoDraw2FB @ r11=scrpos\r
+ and r4, r0, #0xff\r
ldr r11, [r11]\r
+ sub r4, r4, #START_ROW\r
add r11, r11, #328*8\r
add r11, r11, #8\r
\r
- and r4, r0, #0xff\r
- sub r4, r4, #START_ROW\r
mov r7, #328*8\r
mla r11, r7, r4, r11 @ scrpos+=8*328*(start-START_ROW);\r
mov r0, #0xf\r
\r
mov r12, r3, lsl #23\r
mov r12, r12, lsr #23\r
- sub r12, r12, #0x78 @ r12=sy\r
\r
ldr lr, [r0, #4] @ lr=code\r
+ sub r12, r12, #0x78 @ r12=sy\r
mov r8, lr, lsl #7\r
mov r8, r8, lsr #23\r
sub r8, r8, #0x78 @ r8=sx\r
and r3, lr, #0x6000\r
mov r3, r3, lsr #9 @ r3=pal=((code>>9)&0x30);\r
\r
- ldr r10, =(Pico+0x10000) @ r10=Pico.vram\r
-\r
ldr r11, =PicoDraw2FB @ r11=scrpos\r
+ ldr r10, =(Pico+0x10000) @ r10=Pico.vram\r
ldr r11, [r11]\r
sub r1, r12, #(START_ROW*8)\r
mov r0, #328\r
// Draw.c\r
void PicoDrawSetColorFormat(int which); // 0=BGR444, 1=RGB555, 2=8bit(HighPal pal)\r
extern void *DrawLineDest;\r
+#if OVERRIDE_HIGHCOL\r
+extern unsigned char *HighCol;\r
+#endif\r
extern int (*PicoScan)(unsigned int num, void *data);\r
// internals\r
extern unsigned short HighPal[0x100];\r
// utility\r
#ifdef _ASM_DRAW_C\r
void *blockcpy(void *dst, const void *src, size_t n);\r
+void vidConvCpyRGB565(void *to, void *from, int pixels);\r
#else\r
#define blockcpy memcpy\r
#endif\r
--- /dev/null
+// (c) Copyright 2006-2007 notaz, All rights reserved.\r
+// Free for non-commercial use.\r
+\r
+// For commercial use, separate licencing terms must be obtained.\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <ctype.h> // tolower\r
+#ifndef NO_SYNC\r
+#include <unistd.h>\r
+#endif\r
+\r
+#include "emu.h"\r
+#include "menu.h"\r
+#include "fonts.h"\r
+#include "lprintf.h"\r
+\r
+#include <Pico/PicoInt.h>\r
+#include <Pico/Patch.h>\r
+#include <zlib/zlib.h>\r
+\r
+#if defined(__GP2X__)\r
+ #include "../gp2x/gp2x.h"\r
+ #define SCREEN_WIDTH 320\r
+ #define SCREEN_BUFFER gp2x_screen\r
+#elif defined(__GIZ__)\r
+ #include "../gizmondo/giz.h"\r
+ #define SCREEN_WIDTH 321\r
+ #define SCREEN_BUFFER giz_screen // ?\r
+#endif\r
+\r
+char *PicoConfigFile = "picoconfig.bin";\r
+currentConfig_t currentConfig;\r
+unsigned char *rom_data = NULL;\r
+char noticeMsg[64];\r
+int state_slot = 0;\r
+int config_slot = 0, config_slot_current = 0;\r
+\r
+unsigned char *movie_data = NULL;\r
+static int movie_size = 0;\r
+\r
+// provided by platform code:\r
+extern char romFileName[];\r
+extern void emu_noticeMsgUpdated(void);\r
+extern void emu_getMainDir(char *dst, int len);\r
+extern void emu_setDefaultConfig(void);\r
+extern void menu_romload_prepare(const char *rom_name);\r
+extern void menu_romload_end(void);\r
+\r
+\r
+// utilities\r
+static void strlwr_(char* string)\r
+{\r
+ while ( (*string++ = (char)tolower(*string)) );\r
+}\r
+\r
+static int try_rfn_cut(void)\r
+{\r
+ FILE *tmp;\r
+ char *p;\r
+\r
+ p = romFileName + strlen(romFileName) - 1;\r
+ for (; p > romFileName; p--)\r
+ if (*p == '.') break;\r
+ *p = 0;\r
+\r
+ if((tmp = fopen(romFileName, "rb"))) {\r
+ fclose(tmp);\r
+ return 1;\r
+ }\r
+ return 0;\r
+}\r
+\r
+static void get_ext(char *file, char *ext)\r
+{\r
+ char *p;\r
+\r
+ p = file + strlen(file) - 4;\r
+ if (p < file) p = file;\r
+ strncpy(ext, p, 4);\r
+ ext[4] = 0;\r
+ strlwr_(ext);\r
+}\r
+\r
+char *biosfiles_us[] = { "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210" };\r
+char *biosfiles_eu[] = { "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210" };\r
+char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
+\r
+int emu_findBios(int region, char **bios_file)\r
+{\r
+ static char bios_path[1024];\r
+ int i, count;\r
+ char **files;\r
+ FILE *f = NULL;\r
+\r
+ if (region == 4) { // US\r
+ files = biosfiles_us;\r
+ count = sizeof(biosfiles_us) / sizeof(char *);\r
+ } else if (region == 8) { // EU\r
+ files = biosfiles_eu;\r
+ count = sizeof(biosfiles_eu) / sizeof(char *);\r
+ } else if (region == 1 || region == 2) {\r
+ files = biosfiles_jp;\r
+ count = sizeof(biosfiles_jp) / sizeof(char *);\r
+ } else {\r
+ return 0;\r
+ }\r
+\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ emu_getMainDir(bios_path, sizeof(bios_path));\r
+ strcat(bios_path, files[i]);\r
+ strcat(bios_path, ".bin");\r
+ f = fopen(bios_path, "rb");\r
+ if (f) break;\r
+\r
+ bios_path[strlen(bios_path) - 4] = 0;\r
+ strcat(bios_path, ".zip");\r
+ f = fopen(bios_path, "rb");\r
+ if (f) break;\r
+ }\r
+\r
+ if (f) {\r
+ lprintf("using bios: %s\n", bios_path);\r
+ fclose(f);\r
+ if (bios_file) *bios_file = bios_path;\r
+ return 1;\r
+ } else {\r
+ sprintf(menuErrorMsg, "no %s BIOS files found, read docs",\r
+ region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+ lprintf("%s\n", menuErrorMsg);\r
+ return 0;\r
+ }\r
+}\r
+\r
+/* checks if romFileName points to valid MegaCD image\r
+ * if so, checks for suitable BIOS */\r
+int emu_cdCheck(int *pregion)\r
+{\r
+ unsigned char buf[32];\r
+ pm_file *cd_f;\r
+ int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe\r
+\r
+ cd_f = pm_open(romFileName);\r
+ if (!cd_f) return 0; // let the upper level handle this\r
+\r
+ if (pm_read(buf, 32, cd_f) != 32) {\r
+ pm_close(cd_f);\r
+ return 0;\r
+ }\r
+\r
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO)\r
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN)\r
+ if (type == 0) {\r
+ pm_close(cd_f);\r
+ return 0;\r
+ }\r
+\r
+ /* it seems we have a CD image here. Try to detect region now.. */\r
+ pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
+ pm_read(buf, 1, cd_f);\r
+ pm_close(cd_f);\r
+\r
+ if (buf[0] == 0x64) region = 8; // EU\r
+ if (buf[0] == 0xa1) region = 1; // JAP\r
+\r
+ lprintf("detected %s Sega/Mega CD image with %s region\n",\r
+ type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+\r
+ if (pregion != NULL) *pregion = region;\r
+\r
+ return type;\r
+}\r
+\r
+int emu_ReloadRom(void)\r
+{\r
+ unsigned int rom_size = 0;\r
+ char *used_rom_name = romFileName;\r
+ char ext[5];\r
+ pm_file *rom;\r
+ int ret, cd_state, cd_region, cfg_loaded = 0;\r
+\r
+ lprintf("emu_ReloadRom(%s)\n", romFileName);\r
+\r
+ get_ext(romFileName, ext);\r
+\r
+ // detect wrong extensions\r
+ if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz\r
+ sprintf(menuErrorMsg, "Not a ROM selected.");\r
+ return 0;\r
+ }\r
+\r
+ PicoPatchUnload();\r
+\r
+ // check for movie file\r
+ if(movie_data) {\r
+ free(movie_data);\r
+ movie_data = 0;\r
+ }\r
+ if(!strcmp(ext, ".gmv")) {\r
+ // check for both gmv and rom\r
+ int dummy;\r
+ FILE *movie_file = fopen(romFileName, "rb");\r
+ if(!movie_file) {\r
+ sprintf(menuErrorMsg, "Failed to open movie.");\r
+ return 0;\r
+ }\r
+ fseek(movie_file, 0, SEEK_END);\r
+ movie_size = ftell(movie_file);\r
+ fseek(movie_file, 0, SEEK_SET);\r
+ if(movie_size < 64+3) {\r
+ sprintf(menuErrorMsg, "Invalid GMV file.");\r
+ fclose(movie_file);\r
+ return 0;\r
+ }\r
+ movie_data = malloc(movie_size);\r
+ if(movie_data == NULL) {\r
+ sprintf(menuErrorMsg, "low memory.");\r
+ fclose(movie_file);\r
+ return 0;\r
+ }\r
+ fread(movie_data, 1, movie_size, movie_file);\r
+ fclose(movie_file);\r
+ if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) {\r
+ sprintf(menuErrorMsg, "Invalid GMV file.");\r
+ return 0;\r
+ }\r
+ dummy = try_rfn_cut() || try_rfn_cut();\r
+ if (!dummy) {\r
+ sprintf(menuErrorMsg, "Could't find a ROM for movie.");\r
+ return 0;\r
+ }\r
+ get_ext(romFileName, ext);\r
+ }\r
+ else if (!strcmp(ext, ".pat")) {\r
+ int dummy;\r
+ PicoPatchLoad(romFileName);\r
+ dummy = try_rfn_cut() || try_rfn_cut();\r
+ if (!dummy) {\r
+ sprintf(menuErrorMsg, "Could't find a ROM to patch.");\r
+ return 0;\r
+ }\r
+ get_ext(romFileName, ext);\r
+ }\r
+\r
+ if ((PicoMCD & 1) && Pico_mcd != NULL)\r
+ Stop_CD();\r
+\r
+ // check for MegaCD image\r
+ cd_state = emu_cdCheck(&cd_region);\r
+ if (cd_state > 0)\r
+ {\r
+ // valid CD image, check for BIOS..\r
+\r
+ // we need to have config loaded at this point\r
+ ret = emu_ReadConfig(1, 1);\r
+ if (!ret) emu_ReadConfig(0, 1);\r
+ cfg_loaded = 1;\r
+\r
+ if (PicoRegionOverride) {\r
+ cd_region = PicoRegionOverride;\r
+ lprintf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA");\r
+ }\r
+ if (!emu_findBios(cd_region, &used_rom_name)) {\r
+ // bios_help() ?\r
+ return 0;\r
+ }\r
+\r
+ PicoMCD |= 1;\r
+ get_ext(used_rom_name, ext);\r
+ }\r
+ else\r
+ {\r
+ if (PicoMCD & 1) Stop_CD();\r
+ PicoMCD &= ~1;\r
+ }\r
+\r
+ rom = pm_open(used_rom_name);\r
+ if(!rom) {\r
+ sprintf(menuErrorMsg, "Failed to open rom.");\r
+ return 0;\r
+ }\r
+\r
+ menu_romload_prepare(used_rom_name);\r
+\r
+ if(rom_data) {\r
+ free(rom_data);\r
+ rom_data = 0;\r
+ rom_size = 0;\r
+ }\r
+\r
+ if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) {\r
+ sprintf(menuErrorMsg, "PicoCartLoad() failed.");\r
+ lprintf("%s\n", menuErrorMsg);\r
+ pm_close(rom);\r
+ menu_romload_end();\r
+ return 0;\r
+ }\r
+ pm_close(rom);\r
+ menu_romload_end();\r
+\r
+ // detect wrong files (Pico crashes on very small files), also see if ROM EP is good\r
+ if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||\r
+ ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {\r
+ if (rom_data) free(rom_data);\r
+ rom_data = 0;\r
+ sprintf(menuErrorMsg, "Not a ROM selected.");\r
+ return 0;\r
+ }\r
+\r
+ // load config for this ROM (do this before insert to get correct region)\r
+ if (!cfg_loaded) {\r
+ ret = emu_ReadConfig(1, 1);\r
+ if (!ret) emu_ReadConfig(0, 1);\r
+ }\r
+\r
+ lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
+ if(PicoCartInsert(rom_data, rom_size)) {\r
+ sprintf(menuErrorMsg, "Failed to load ROM.");\r
+ return 0;\r
+ }\r
+\r
+ Pico.m.frame_count = 0;\r
+\r
+ // insert CD if it was detected\r
+ if (cd_state > 0) {\r
+ ret = Insert_CD(romFileName, cd_state == 2);\r
+ if (ret != 0) {\r
+ sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
+ lprintf("%s\n", menuErrorMsg);\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ // emu_ReadConfig() might have messed currentConfig.lastRomFile\r
+ strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
+ currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
+\r
+ if (PicoPatches) {\r
+ PicoPatchPrepare();\r
+ PicoPatchApply();\r
+ }\r
+\r
+ // additional movie stuff\r
+ if (movie_data) {\r
+ if(movie_data[0x14] == '6')\r
+ PicoOpt |= 0x20; // 6 button pad\r
+ else PicoOpt &= ~0x20;\r
+ PicoOpt |= 0x10040; // accurate timing, no VDP fifo timing\r
+ if(movie_data[0xF] >= 'A') {\r
+ if(movie_data[0x16] & 0x80) {\r
+ PicoRegionOverride = 8;\r
+ } else {\r
+ PicoRegionOverride = 4;\r
+ }\r
+ PicoReset(0);\r
+ // TODO: bits 6 & 5\r
+ }\r
+ movie_data[0x18+30] = 0;\r
+ sprintf(noticeMsg, "MOVIE: %s", (char *) &movie_data[0x18]);\r
+ }\r
+ else\r
+ {\r
+ PicoOpt &= ~0x10000;\r
+ if(Pico.m.pal) {\r
+ strcpy(noticeMsg, "PAL SYSTEM / 50 FPS");\r
+ } else {\r
+ strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS");\r
+ }\r
+ }\r
+ emu_noticeMsgUpdated();\r
+\r
+ // load SRAM for this ROM\r
+ if(currentConfig.EmuOpt & 1)\r
+ emu_SaveLoadGame(1, 1);\r
+\r
+ return 1;\r
+}\r
+\r
+\r
+static void romfname_ext(char *dst, const char *prefix, const char *ext)\r
+{\r
+ char *p;\r
+ int prefix_len = 0;\r
+\r
+ // make save filename\r
+ for (p = romFileName+strlen(romFileName)-1; p >= romFileName && *p != '/'; p--); p++;\r
+ *dst = 0;\r
+ if (prefix) {\r
+ strcpy(dst, prefix);\r
+ prefix_len = strlen(prefix);\r
+ }\r
+ strncpy(dst + prefix_len, p, 511-prefix_len);\r
+ dst[511-8] = 0;\r
+ if (dst[strlen(dst)-4] == '.') dst[strlen(dst)-4] = 0;\r
+ if (ext) strcat(dst, ext);\r
+}\r
+\r
+\r
+int emu_ReadConfig(int game, int no_defaults)\r
+{\r
+ FILE *f;\r
+ char cfg[512], extbuf[16];\r
+ int bread = 0;\r
+\r
+ if (!game)\r
+ {\r
+ if (!no_defaults)\r
+ {\r
+ emu_setDefaultConfig();\r
+ }\r
+ strncpy(cfg, PicoConfigFile, 511);\r
+ if (config_slot != 0)\r
+ {\r
+ char *p = strrchr(cfg, '.');\r
+ if (p == NULL) p = cfg + strlen(cfg);\r
+ sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+ strncpy(p, extbuf, 511 - (p - cfg));\r
+ }\r
+ cfg[511] = 0;\r
+ } else {\r
+ if (config_slot != 0)\r
+ sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+ else strcpy(extbuf, ".pbcfg");\r
+ romfname_ext(cfg, "cfg/", extbuf);\r
+ f = fopen(cfg, "rb");\r
+ if (!f) romfname_ext(cfg, NULL, ".pbcfg");\r
+ else fclose(f);\r
+ }\r
+\r
+ lprintf("emu_ReadConfig: %s ", cfg);\r
+ f = fopen(cfg, "rb");\r
+ if (f) {\r
+ bread = fread(¤tConfig, 1, sizeof(currentConfig), f);\r
+ fclose(f);\r
+ }\r
+ lprintf(bread > 0 ? "(ok)\n" : "(failed)\n");\r
+\r
+ PicoOpt = currentConfig.PicoOpt;\r
+ PsndRate = currentConfig.PsndRate;\r
+ PicoRegionOverride = currentConfig.PicoRegion;\r
+ PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;\r
+ PicoCDBuffers = currentConfig.PicoCDBuffers;\r
+ //scaling_update();\r
+ // some sanity checks\r
+ if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
+ if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
+ if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50;\r
+ // if volume keys are unbound, bind them to volume control\r
+ if (!currentConfig.KeyBinds[23] && !currentConfig.KeyBinds[22]) {\r
+ currentConfig.KeyBinds[23] = 1<<29; // vol up\r
+ currentConfig.KeyBinds[22] = 1<<30; // vol down\r
+ }\r
+\r
+ if (bread > 0) config_slot_current = config_slot;\r
+ return (bread > 0); // == sizeof(currentConfig));\r
+}\r
+\r
+\r
+int emu_WriteConfig(int game)\r
+{\r
+ FILE *f;\r
+ char cfg[512], extbuf[16];\r
+ int bwrite = 0;\r
+\r
+ if (!game)\r
+ {\r
+ strncpy(cfg, PicoConfigFile, 511);\r
+ if (config_slot != 0)\r
+ {\r
+ char *p = strrchr(cfg, '.');\r
+ if (p == NULL) p = cfg + strlen(cfg);\r
+ sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+ strncpy(p, extbuf, 511 - (p - cfg));\r
+ }\r
+ cfg[511] = 0;\r
+ } else {\r
+ if (config_slot != 0)\r
+ sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+ else strcpy(extbuf, ".pbcfg");\r
+ romfname_ext(cfg, "cfg/", extbuf);\r
+ }\r
+\r
+ lprintf("emu_WriteConfig: %s ", cfg);\r
+ f = fopen(cfg, "wb");\r
+ if (f) {\r
+ currentConfig.PicoOpt = PicoOpt;\r
+ currentConfig.PsndRate = PsndRate;\r
+ currentConfig.PicoRegion = PicoRegionOverride;\r
+ currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder;\r
+ currentConfig.PicoCDBuffers = PicoCDBuffers;\r
+ bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f);\r
+ fflush(f);\r
+ fclose(f);\r
+#ifndef NO_SYNC\r
+ sync();\r
+#endif\r
+ }\r
+ lprintf((bwrite == sizeof(currentConfig)) ? "(ok)\n" : "(failed)\n");\r
+\r
+ if (bwrite == sizeof(currentConfig)) config_slot_current = config_slot;\r
+ return (bwrite == sizeof(currentConfig));\r
+}\r
+\r
+\r
+void emu_textOut8(int x, int y, const char *text)\r
+{\r
+ int i,l,len=strlen(text);\r
+ unsigned char *screen = (unsigned char *)SCREEN_BUFFER + x + y*SCREEN_WIDTH;\r
+\r
+ /* always using built-in font */\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ for (l=0;l<8;l++)\r
+ {\r
+ unsigned char fd = fontdata8x8[((text[i])*8)+l];\r
+ if (fd&0x80) screen[l*SCREEN_WIDTH+0]=0xf0;\r
+ if (fd&0x40) screen[l*SCREEN_WIDTH+1]=0xf0;\r
+ if (fd&0x20) screen[l*SCREEN_WIDTH+2]=0xf0;\r
+ if (fd&0x10) screen[l*SCREEN_WIDTH+3]=0xf0;\r
+ if (fd&0x08) screen[l*SCREEN_WIDTH+4]=0xf0;\r
+ if (fd&0x04) screen[l*SCREEN_WIDTH+5]=0xf0;\r
+ if (fd&0x02) screen[l*SCREEN_WIDTH+6]=0xf0;\r
+ if (fd&0x01) screen[l*SCREEN_WIDTH+7]=0xf0;\r
+ }\r
+ screen += 8;\r
+ }\r
+}\r
+\r
+void emu_textOut16(int x, int y, const char *text)\r
+{\r
+ int i,l,len=strlen(text);\r
+ unsigned short *screen = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH;\r
+\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ for (l=0;l<8;l++)\r
+ {\r
+ unsigned char fd = fontdata8x8[((text[i])*8)+l];\r
+ if(fd&0x80) screen[l*SCREEN_WIDTH+0]=0xffff;\r
+ if(fd&0x40) screen[l*SCREEN_WIDTH+1]=0xffff;\r
+ if(fd&0x20) screen[l*SCREEN_WIDTH+2]=0xffff;\r
+ if(fd&0x10) screen[l*SCREEN_WIDTH+3]=0xffff;\r
+ if(fd&0x08) screen[l*SCREEN_WIDTH+4]=0xffff;\r
+ if(fd&0x04) screen[l*SCREEN_WIDTH+5]=0xffff;\r
+ if(fd&0x02) screen[l*SCREEN_WIDTH+6]=0xffff;\r
+ if(fd&0x01) screen[l*SCREEN_WIDTH+7]=0xffff;\r
+ }\r
+ screen += 8;\r
+ }\r
+}\r
+\r
+\r
+void emu_updateMovie(void)\r
+{\r
+ int offs = Pico.m.frame_count*3 + 0x40;\r
+ if (offs+3 > movie_size) {\r
+ free(movie_data);\r
+ movie_data = 0;\r
+ strcpy(noticeMsg, "END OF MOVIE.");\r
+ lprintf("END OF MOVIE.\n");\r
+ emu_noticeMsgUpdated();\r
+ } else {\r
+ // MXYZ SACB RLDU\r
+ PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU\r
+ if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // A\r
+ if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // B\r
+ if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // A\r
+ PicoPad[1] = ~movie_data[offs+1] & 0x8f; // ! SCBA RLDU\r
+ if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // A\r
+ if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // B\r
+ if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // A\r
+ PicoPad[0] |= (~movie_data[offs+2] & 0x0A) << 8; // ! MZYX\r
+ if(!(movie_data[offs+2] & 0x01)) PicoPad[0] |= 0x0400; // X\r
+ if(!(movie_data[offs+2] & 0x04)) PicoPad[0] |= 0x0100; // Z\r
+ PicoPad[1] |= (~movie_data[offs+2] & 0xA0) << 4; // ! MZYX\r
+ if(!(movie_data[offs+2] & 0x10)) PicoPad[1] |= 0x0400; // X\r
+ if(!(movie_data[offs+2] & 0x40)) PicoPad[1] |= 0x0100; // Z\r
+ }\r
+}\r
+\r
+\r
+static size_t gzRead2(void *p, size_t _size, size_t _n, void *file)\r
+{\r
+ return gzread(file, p, _n);\r
+}\r
+\r
+\r
+static size_t gzWrite2(void *p, size_t _size, size_t _n, void *file)\r
+{\r
+ return gzwrite(file, p, _n);\r
+}\r
+\r
+static int try_ropen_file(const char *fname)\r
+{\r
+ FILE *f;\r
+\r
+ f = fopen(fname, "rb");\r
+ if (f) {\r
+ fclose(f);\r
+ return 1;\r
+ }\r
+ return 0;\r
+}\r
+\r
+char *emu_GetSaveFName(int load, int is_sram, int slot)\r
+{\r
+ static char saveFname[512];\r
+ char ext[16];\r
+\r
+ if (is_sram)\r
+ {\r
+ romfname_ext(saveFname, (PicoMCD&1) ? "brm/" : "srm/", (PicoMCD&1) ? ".brm" : ".srm");\r
+ if (load) {\r
+ if (try_ropen_file(saveFname)) return saveFname;\r
+ // try in current dir..\r
+ romfname_ext(saveFname, NULL, (PicoMCD&1) ? ".brm" : ".srm");\r
+ if (try_ropen_file(saveFname)) return saveFname;\r
+ return NULL; // give up\r
+ }\r
+ }\r
+ else\r
+ {\r
+ ext[0] = 0;\r
+ if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);\r
+ strcat(ext, (currentConfig.EmuOpt & 8) ? ".mds.gz" : ".mds");\r
+\r
+ romfname_ext(saveFname, "mds/", ext);\r
+ if (load) {\r
+ if (try_ropen_file(saveFname)) return saveFname;\r
+ romfname_ext(saveFname, NULL, ext);\r
+ if (try_ropen_file(saveFname)) return saveFname;\r
+ if (currentConfig.EmuOpt & 8) {\r
+ ext[0] = 0;\r
+ if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);\r
+ strcat(ext, ".mds");\r
+\r
+ romfname_ext(saveFname, "mds/", ext);\r
+ if (try_ropen_file(saveFname)) return saveFname;\r
+ romfname_ext(saveFname, NULL, ext);\r
+ if (try_ropen_file(saveFname)) return saveFname;\r
+ }\r
+ return NULL;\r
+ }\r
+ }\r
+\r
+ return saveFname;\r
+}\r
+\r
+int emu_checkSaveFile(int slot)\r
+{\r
+ return emu_GetSaveFName(1, 0, slot) ? 1 : 0;\r
+}\r
+\r
+void emu_setSaveStateCbs(int gz)\r
+{\r
+ if (gz) {\r
+ areaRead = gzRead2;\r
+ areaWrite = gzWrite2;\r
+ areaEof = (areaeof *) gzeof;\r
+ areaSeek = (areaseek *) gzseek;\r
+ areaClose = (areaclose *) gzclose;\r
+ } else {\r
+ areaRead = (arearw *) fread;\r
+ areaWrite = (arearw *) fwrite;\r
+ areaEof = (areaeof *) feof;\r
+ areaSeek = (areaseek *) fseek;\r
+ areaClose = (areaclose *) fclose;\r
+ }\r
+}\r
+\r
+int emu_SaveLoadGame(int load, int sram)\r
+{\r
+ int ret = 0;\r
+ char *saveFname;\r
+\r
+ // make save filename\r
+ saveFname = emu_GetSaveFName(load, sram, state_slot);\r
+ if (saveFname == NULL) {\r
+ if (!sram) {\r
+ strcpy(noticeMsg, load ? "LOAD FAILED (missing file)" : "SAVE FAILED ");\r
+ emu_noticeMsgUpdated();\r
+ }\r
+ return -1;\r
+ }\r
+\r
+ lprintf("saveLoad (%i, %i): %s\n", load, sram, saveFname);\r
+\r
+ if(sram) {\r
+ FILE *sramFile;\r
+ int sram_size;\r
+ unsigned char *sram_data;\r
+ int truncate = 1;\r
+ if (PicoMCD&1) {\r
+ if (PicoOpt&0x8000) { // MCD RAM cart?\r
+ sram_size = 0x12000;\r
+ sram_data = SRam.data;\r
+ if (sram_data)\r
+ memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4);\r
+ } else {\r
+ sram_size = 0x2000;\r
+ sram_data = Pico_mcd->bram;\r
+ truncate = 0; // the .brm may contain RAM cart data after normal brm\r
+ }\r
+ } else {\r
+ sram_size = SRam.end-SRam.start+1;\r
+ if(Pico.m.sram_reg & 4) sram_size=0x2000;\r
+ sram_data = SRam.data;\r
+ }\r
+ if (!sram_data) return 0; // SRam forcefully disabled for this game\r
+\r
+ if (load) {\r
+ sramFile = fopen(saveFname, "rb");\r
+ if(!sramFile) return -1;\r
+ fread(sram_data, 1, sram_size, sramFile);\r
+ fclose(sramFile);\r
+ if ((PicoMCD&1) && (PicoOpt&0x8000))\r
+ memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4);\r
+ } else {\r
+ // sram save needs some special processing\r
+ // see if we have anything to save\r
+ for (; sram_size > 0; sram_size--)\r
+ if (sram_data[sram_size-1]) break;\r
+\r
+ if (sram_size) {\r
+ sramFile = fopen(saveFname, truncate ? "wb" : "r+b");\r
+ if (!sramFile) sramFile = fopen(saveFname, "wb"); // retry\r
+ if (!sramFile) return -1;\r
+ ret = fwrite(sram_data, 1, sram_size, sramFile);\r
+ ret = (ret != sram_size) ? -1 : 0;\r
+ fclose(sramFile);\r
+#ifndef NO_SYNC\r
+ sync();\r
+#endif\r
+ }\r
+ }\r
+ return ret;\r
+ }\r
+ else\r
+ {\r
+ void *PmovFile = NULL;\r
+ if (strcmp(saveFname + strlen(saveFname) - 3, ".gz") == 0) {\r
+ if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {\r
+ emu_setSaveStateCbs(1);\r
+ if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {\r
+ emu_setSaveStateCbs(0);\r
+ }\r
+ }\r
+ if(PmovFile) {\r
+ ret = PmovState(load ? 6 : 5, PmovFile);\r
+ areaClose(PmovFile);\r
+ PmovFile = 0;\r
+ if (load) Pico.m.dirtyPal=1;\r
+#ifndef NO_SYNC\r
+ else sync();\r
+#endif\r
+ }\r
+ else ret = -1;\r
+ if (!ret)\r
+ strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED ");\r
+ else\r
+ {\r
+ strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED ");\r
+ ret = -1;\r
+ }\r
+\r
+ emu_noticeMsgUpdated();\r
+ return ret;\r
+ }\r
+}\r
--- /dev/null
+// (c) Copyright 2006-2007 notaz, All rights reserved.
+// Free for non-commercial use.
+
+// For commercial use, separate licencing terms must be obtained.
+
+typedef struct {
+ char lastRomFile[512];
+ int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,
+ // squidgehack, no_save_cfg_on_exit, <unused>, 16_bit_mode
+ // craigix_ram, confirm_save, show_cd_leds, confirm_load
+ // A_SNs_gamma, perfect_vsync
+ int PicoOpt; // used for config saving only, see Pico.h
+ int PsndRate; // ditto
+ int PicoRegion; // ditto
+ int Frameskip;
+ int CPUclock;
+ int KeyBinds[32];
+ int volume;
+ int gamma;
+ int JoyBinds[4][32];
+ int PicoAutoRgnOrder;
+ int PicoCDBuffers;
+ int scaling; // 0=center, 1=hscale, 2=hvscale, 3=hsoftscale
+} currentConfig_t;
+
+
+extern currentConfig_t currentConfig;
+extern char *PicoConfigFile;
+extern unsigned char *rom_data;
+extern char noticeMsg[64];
+extern int state_slot;
+extern int config_slot, config_slot_current;
+extern unsigned char *movie_data;
+
+
+int emu_ReloadRom(void);
+int emu_SaveLoadGame(int load, int sram);
+int emu_ReadConfig(int game, int no_defaults);
+int emu_WriteConfig(int game);
+char *emu_GetSaveFName(int load, int is_sram, int slot);
+int emu_checkSaveFile(int slot);
+void emu_setSaveStateCbs(int gz);
+void emu_updateMovie(void);
+int emu_cdCheck(int *pregion);
+int emu_findBios(int region, char **bios_file);
+void emu_textOut8 (int x, int y, const char *text);
+void emu_textOut16(int x, int y, const char *text);
+
#include "lprintf.h"\r
\r
#if defined(__GP2X__)\r
-#include "../gp2x/gp2x.h"\r
-#define SCREEN_WIDTH 320\r
-#define SCREEN_BUFFER gp2x_screen\r
+ #include "../gp2x/gp2x.h"\r
+ #define SCREEN_WIDTH 320\r
+ #define SCREEN_BUFFER gp2x_screen\r
#elif defined(__GIZ__)\r
-#include "../gizmondo/giz.h"\r
-#define SCREEN_WIDTH 321\r
-#define SCREEN_BUFFER menu_screen\r
-extern unsigned char menu_screen[321*240*2];\r
+ //#include "../gizmondo/giz.h"\r
+ #define SCREEN_WIDTH 321\r
+ #define SCREEN_BUFFER menu_screen\r
+ extern unsigned char *menu_screen;\r
#endif\r
\r
+char menuErrorMsg[64] = { 0, };\r
+\r
static unsigned char menu_font_data[10240];\r
static int menu_text_color = 0xffff; // default to white\r
static int menu_sel_color = -1; // disabled\r
void smalltext_out16_lim(int x, int y, const char *texto, int color, int max);
void menu_draw_selection(int x, int y, int w);
+extern char menuErrorMsg[64];
typedef enum
\r
\r
\r
-DEFINC = -I../.. -I. -D__GIZ__ -D_UNZIP_SUPPORT\r
-COPT_COMMON = -static -Wall -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math\r
+DEFINC = -I../.. -I. -D__GIZ__ -D_UNZIP_SUPPORT -DNO_SYNC\r
+COPT_COMMON = -static -Wall -Winline\r
+ifeq ($(DEBUG),)\r
+COPT_COMMON += -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math\r
+else\r
+COPT_COMMON += -ggdb\r
+endif\r
ifeq "$(profile)" "1"\r
COPT_COMMON += -fprofile-generate\r
endif\r
LD = $(CROSS)ld\r
\r
# frontend\r
-OBJS += main.o menu.o giz.o emu.o\r
+OBJS += main.o emu.o menu.o giz.o asm_utils.o\r
\r
# common\r
-OBJS += ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o\r
+OBJS += ../common/emu.o ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o\r
\r
# Pico\r
ifeq "$(amalgamate)" "1"\r
../../Pico/sound/mix_asm.o : ../../Pico/sound/mix.s\r
@echo $<\r
@$(AS) $(ASFLAGS) $< -o $@\r
-../../Pico/misc_asm.o : ../../Pico/misc.s\r
+../../Pico/misc_asm.o : ../../Pico/Misc.s\r
@echo $<\r
@$(AS) $(ASFLAGS) $< -o $@\r
../../Pico/cd/pico_asm.o : ../../Pico/cd/Pico.s\r
../../Pico/cd/memory_asm.o : ../../Pico/cd/Memory.s\r
@echo $<\r
@$(AS) $(ASFLAGS) $< -o $@\r
-../../Pico/cd/misc_asm.o : ../../Pico/cd/misc.s\r
+../../Pico/cd/misc_asm.o : ../../Pico/cd/Misc.s\r
@echo $<\r
@$(AS) $(ASFLAGS) $< -o $@\r
\r
find ../.. -name '*.gcno' -delete\r
find ../.. -name '*.gcda' -delete\r
\r
+up: PicoDrive.exe\r
+ synce-pcp -d 3 PicoDrive.exe ":/SD Card/emus/PicoDrive/PicoDrive.exe"\r
+\r
+run: up\r
+ synce-prun "/SD Card/emus/PicoDrive/PicoDrive.exe"\r
+\r
+run_only:\r
+ synce-prun "/SD Card/emus/PicoDrive/PicoDrive.exe"\r
+\r
# ----------- release -----------\r
ifneq ($(findstring rel,$(MAKECMDGOALS)),)\r
ifeq ($(VER),)\r
--- /dev/null
+
+void vidCpy8to16_40(void *dest, void *src, short *pal, int lines);
+
--- /dev/null
+@ vim:filetype=armasm
+
+
+.global vidCpy8to16_40 @ void *dest, void *src, short *pal, int lines
+
+vidCpy8to16_40:
+ stmfd sp!, {r4-r9,lr}
+
+ mov r3, r3, lsr #1
+ orr r3, r3, r3, lsl #8
+ add r1, r1, #8
+ orr r3, r3, #(320/8-1)<<24
+
+ @ even lines
+vcloop_40_aligned:
+ ldr r12, [r1], #4
+ ldr r7, [r1], #4
+
+ and r4, lr, r12, lsl #1
+ ldrh r4, [r2, r4]
+ and r5, lr, r12, lsr #7
+ ldrh r5, [r2, r5]
+ and r6, lr, r12, lsr #15
+ ldrh r6, [r2, r6]
+ orr r4, r4, r5, lsl #16
+
+ and r5, lr, r12, lsr #23
+ ldrh r5, [r2, r5]
+ and r8, lr, r7, lsl #1
+ ldrh r8, [r2, r8]
+ orr r5, r6, r5, lsl #16
+
+ and r6, lr, r7, lsr #7
+ ldrh r6, [r2, r6]
+ and r12,lr, r7, lsr #15
+ ldrh r12,[r2, r12]
+ and r9, lr, r7, lsr #23
+ ldrh r9, [r2, r9]
+ orr r8, r8, r6, lsl #16
+
+ subs r3, r3, #1<<24
+ orr r12,r12, r9, lsl #16
+
+ stmia r0!, {r4,r5,r8,r12}
+ bpl vcloop_40_aligned
+
+ add r1, r1, #336 @ skip a line and 1 col
+ add r0, r0, #320*2+2*2
+ add r3, r3, #(320/8)<<24
+ sub r3, r3, #1
+ tst r3, #0xff
+ bne vcloop_40_aligned
+
+ and r4, r3, #0xff00
+ orr r3, r3, r4, lsr #8
+ mov r4, r4, lsr #7
+ sub r4, r4, #1
+ mov r5, #320*2
+ add r5, r5, #2
+ mul r4, r5, r4
+ sub r0, r0, r4
+ mov r5, #328
+ mul r4, r5, r4
+ sub r1, r1, r4
+
+vcloop_40_unaligned:
+ ldr r12, [r1], #4
+ ldr r7, [r1], #4
+
+ and r4, lr, r12, lsl #1
+ ldrh r4, [r2, r4]
+ and r5, lr, r12, lsr #7
+ ldrh r5, [r2, r5]
+ strh r4, [r0]!
+ and r6, lr, r12, lsr #15
+ ldrh r6, [r2, r6]
+
+ and r4, lr, r12, lsr #23
+ ldrh r4, [r2, r4]
+ orr r5, r5, r6, lsl #16
+
+ and r8, lr, r7, lsl #1
+ ldrh r8, [r2, r8]
+
+ and r6, lr, r7, lsr #7
+ ldrh r6, [r2, r6]
+ orr r8, r4, r8, lsl #16
+
+ and r12,lr, r7, lsr #15
+ ldrh r12,[r2, r12]
+
+ and r4, lr, r7, lsr #23
+ ldrh r4, [r2, r6]
+ orr r12,r6, r12,lsl #16
+ subs r3, r3, #1
+
+ stmia r0!, {r5,r8,r12}
+ strh r4, [r0]!
+ bne vcloop_40_unaligned
+
+ add r1, r1, #336 @ skip a line and 1 col
+ add r0, r0, #320*2+2*2
+ add r3, r3, #(320/8)<<24
+ sub r3, r3, #1
+ tst r3, #0xff
+ bne vcloop_40_unaligned
+
+ ldmfd sp!, {r4-r9,lr}
+ bx lr
+
+
+
#include <windows.h>
+#include <string.h>
+#include "kgsdk/Framework2D.h"
+#include "kgsdk/FrameworkAudio.h"
+#include "../common/emu.h"
+#include "../common/lprintf.h"
+#include "../common/arm_utils.h"
#include "emu.h"
+#include "menu.h"
+#include "giz.h"
+#include "asm_utils.h"
+#include <Pico/PicoInt.h>
+
+#ifdef BENCHMARK
+#define OSD_FPS_X 220
+#else
+#define OSD_FPS_X 260
+#endif
+
+// main 300K gfx-related buffer. Used by menu and renderers.
+unsigned char gfx_buffer[321*240*2*2];
char romFileName[MAX_PATH];
int engineState;
-currentConfig_t currentConfig;
-unsigned char *rom_data = NULL;
-unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer
-int state_slot = 0;
+unsigned char *PicoDraw2FB = gfx_buffer; // temporary buffer for alt renderer ( (8+320)*(8+240+8) )
int reset_timing = 0;
-int config_slot = 0, config_slot_current = 0;
-
-
-
-
-int emu_ReloadRom(void){}
-void emu_Init(void){}
-void emu_Deinit(void){}
-int emu_SaveLoadGame(int load, int sram){}
-void emu_Loop(void){}
-void emu_ResetGame(void){}
-int emu_ReadConfig(int game, int no_defaults){}
-int emu_WriteConfig(int game){}
-char *emu_GetSaveFName(int load, int is_sram, int slot){}
-int emu_check_save_file(int slot){}
-void emu_set_save_cbs(int gz){}
-void emu_forced_frame(void){}
-int emu_cd_check(int *pregion){}
-int find_bios(int region, char **bios_file){}
-void scaling_update(void){}
+
+static DWORD noticeMsgTime = 0;
+static int osd_fps_x;
+
+
+static void blit(const char *fps, const char *notice);
+static void clearArea(int full);
+
+void emu_noticeMsgUpdated(void)
+{
+ noticeMsgTime = GetTickCount();
+}
+
+void emu_getMainDir(char *dst, int len)
+{
+ if (len > 0) *dst = 0;
+}
+
+static void emu_msg_cb(const char *msg)
+{
+ if (giz_screen == NULL)
+ giz_screen = Framework2D_LockBuffer();
+
+ memset32((int *)((char *)giz_screen + 321*232*2), 0, 321*8*2/4);
+ emu_textOut16(4, 232, msg);
+ noticeMsgTime = GetTickCount() - 2000;
+
+ /* assumption: emu_msg_cb gets called only when something slow is about to happen */
+ reset_timing = 1;
+}
+
+static void emu_state_cb(const char *str)
+{
+ clearArea(0);
+ blit("", str);
+}
+
+static void emu_msg_tray_open(void)
+{
+ strcpy(noticeMsg, "CD tray opened");
+ noticeMsgTime = GetTickCount();
+}
+
+
+void emu_Init(void)
+{
+ // make dirs for saves, cfgs, etc.
+ CreateDirectory(L"mds", NULL);
+ CreateDirectory(L"srm", NULL);
+ CreateDirectory(L"brm", NULL);
+ CreateDirectory(L"cfg", NULL);
+
+ PicoInit();
+ PicoMessage = emu_msg_cb;
+ PicoMCDopenTray = emu_msg_tray_open;
+ PicoMCDcloseTray = menu_loop_tray;
+}
+
+void emu_Deinit(void)
+{
+ // save SRAM
+ if((currentConfig.EmuOpt & 1) && SRam.changed) {
+ emu_SaveLoadGame(0, 1);
+ SRam.changed = 0;
+ }
+
+ if (!(currentConfig.EmuOpt & 0x20)) {
+ FILE *f = fopen(PicoConfigFile, "r+b");
+ if (!f) emu_WriteConfig(0);
+ else {
+ // if we already have config, reload it, except last ROM
+ fseek(f, sizeof(currentConfig.lastRomFile), SEEK_SET);
+ fread(¤tConfig.EmuOpt, 1, sizeof(currentConfig) - sizeof(currentConfig.lastRomFile), f);
+ fseek(f, 0, SEEK_SET);
+ fwrite(¤tConfig, 1, sizeof(currentConfig), f);
+ fflush(f);
+ fclose(f);
+ }
+ }
+
+ PicoExit();
+}
+
+void emu_setDefaultConfig(void)
+{
+ memset(¤tConfig, 0, sizeof(currentConfig));
+ currentConfig.lastRomFile[0] = 0;
+ currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds
+ currentConfig.PicoOpt = 0x0f | 0xc00; // | cd_pcm, cd_cdda
+ currentConfig.PsndRate = 22050;
+ currentConfig.PicoRegion = 0; // auto
+ currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP
+ currentConfig.Frameskip = -1; // auto
+ currentConfig.volume = 50;
+ currentConfig.KeyBinds[ 2] = 1<<0; // SACB RLDU
+ currentConfig.KeyBinds[ 3] = 1<<1;
+ currentConfig.KeyBinds[ 0] = 1<<2;
+ currentConfig.KeyBinds[ 1] = 1<<3;
+ currentConfig.KeyBinds[ 5] = 1<<4;
+ currentConfig.KeyBinds[ 6] = 1<<5;
+ currentConfig.KeyBinds[ 7] = 1<<6;
+ currentConfig.KeyBinds[ 8] = 1<<7;
+ currentConfig.KeyBinds[ 4] = 1<<26; // switch rend
+ currentConfig.KeyBinds[ 8] = 1<<27; // save state
+ currentConfig.KeyBinds[ 9] = 1<<28; // load state
+ currentConfig.KeyBinds[12] = 1<<29; // vol up
+ currentConfig.KeyBinds[11] = 1<<30; // vol down
+ currentConfig.PicoCDBuffers = 64;
+ currentConfig.scaling = 0;
+}
+
+
+static int EmuScan16(unsigned int num, void *sdata)
+{
+ if (!(Pico.video.reg[1]&8)) num += 8;
+ DrawLineDest = (unsigned short *) giz_screen + 321*(num+1);
+
+ return 0;
+}
+
+static int EmuScan8(unsigned int num, void *sdata)
+{
+ // draw like the fast renderer
+ if (!(Pico.video.reg[1]&8)) num += 8;
+ HighCol = gfx_buffer + 328*8 + 328*(num+1);
+
+ return 0;
+}
+
+static void osd_text(int x, int y, const char *text)
+{
+ int len = strlen(text) * 8;
+ int *p, i, h;
+ len = (len+1) >> 1;
+ for (h = 0; h < 8; h++) {
+ p = (int *) ((unsigned short *) giz_screen+x+321*(y+h));
+ p = (int *) ((int)p & ~3); // align
+ for (i = len; i; i--, p++) *p = 0;
+ }
+ emu_textOut16(x, y, text);
+}
+
+
+short localPal[0x100];
+static void (*vidCpy8to16)(void *dest, void *src, short *pal, int lines) = NULL;
+
+static void blit(const char *fps, const char *notice)
+{
+ int emu_opt = currentConfig.EmuOpt;
+
+ if (PicoOpt&0x10) {
+ // 8bit fast renderer
+ if (Pico.m.dirtyPal) {
+ Pico.m.dirtyPal = 0;
+ vidConvCpyRGB565(localPal, Pico.cram, 0x40);
+ }
+ vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, 224);
+ } else if (!(emu_opt&0x80)) {
+ // 8bit accurate renderer
+ if (Pico.m.dirtyPal) {
+ Pico.m.dirtyPal = 0;
+ vidConvCpyRGB565(localPal, Pico.cram, 0x40);
+ if(Pico.video.reg[0xC]&8) { // shadow/hilight mode
+ //vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);
+ //vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40); // TODO
+ blockcpy(localPal+0xc0, localPal+0x40, 0x40*4);
+ localPal[0xc0] = 0x0600;
+ localPal[0xd0] = 0xc000;
+ localPal[0xe0] = 0x0000; // reserved pixels for OSD
+ localPal[0xf0] = 0xffff;
+ }
+ /* no support
+ else if (rendstatus & 0x20) { // mid-frame palette changes
+ vidConvCpyRGB565(localPal+0x40, HighPal, 0x40);
+ vidConvCpyRGB565(localPal+0x80, HighPal+0x40, 0x40);
+ } */
+ }
+ // TODO...
+ vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, 224);
+ }
+
+ if (notice || (emu_opt & 2)) {
+ int h = 232;
+ if (notice) osd_text(4, h, notice);
+ if (emu_opt & 2) osd_text(osd_fps_x, h, fps);
+ }
+// if ((emu_opt & 0x400) && (PicoMCD & 1))
+// cd_leds();
+
+ //gp2x_video_wait_vsync();
+
+ if (!(PicoOpt&0x10)) {
+ if (Pico.video.reg[1] & 8) {
+ if (currentConfig.EmuOpt&0x80)
+ DrawLineDest = (unsigned short *) giz_screen;
+ else
+ HighCol = gfx_buffer;
+ } else {
+ if (currentConfig.EmuOpt&0x80)
+ DrawLineDest = (unsigned short *) giz_screen + 320*8;
+ else
+ HighCol = gfx_buffer + 328*8;
+ }
+ }
+}
+
+// clears whole screen or just the notice area (in all buffers)
+static void clearArea(int full)
+{
+ if (giz_screen == NULL)
+ giz_screen = Framework2D_LockBuffer();
+ if (full) memset32(giz_screen, 0, 320*240*2/4);
+ else memset32((int *)((char *)giz_screen + 320*232*2), 0, 320*8*2/4);
+}
+
+static void vidResetMode(void)
+{
+ void *screen;
+ if (PicoOpt&0x10) {
+ } else if (currentConfig.EmuOpt&0x80) {
+ PicoDrawSetColorFormat(1);
+ PicoScan = EmuScan16;
+ } else {
+ PicoDrawSetColorFormat(0);
+ PicoScan = EmuScan8;
+ }
+ if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {
+ // setup pal for 8-bit modes
+ localPal[0xc0] = 0x0600;
+ localPal[0xd0] = 0xc000;
+ localPal[0xe0] = 0x0000; // reserved pixels for OSD
+ localPal[0xf0] = 0xffff;
+ }
+ Pico.m.dirtyPal = 1;
+ screen = Framework2D_LockBuffer();
+ memset32(screen, 0, 320*240*2/4);
+ Framework2D_UnlockBuffer();
+ giz_screen = NULL;
+}
+
+
+static void SkipFrame(int do_audio)
+{
+ PicoSkipFrame=do_audio ? 1 : 2;
+ PicoFrame();
+ PicoSkipFrame=0;
+}
+
+void emu_forcedFrame(void)
+{
+ // TODO
+}
+
+static void updateKeys(void)
+{
+}
+
+static void simpleWait(DWORD until)
+{
+}
+
+void emu_Loop(void)
+{
+ //static int PsndRate_old = 0, PicoOpt_old = 0, PsndLen_real = 0, pal_old = 0;
+ char fpsbuff[24]; // fps count c string
+ DWORD tval, tval_prev = 0, tval_thissec = 0; // timing
+ int frames_done = 0, frames_shown = 0, oldmodes = 0;
+ int target_fps, target_frametime, lim_time, tval_diff, i;
+ char *notice = NULL;
+
+ lprintf("entered emu_Loop()\n");
+
+ fpsbuff[0] = 0;
+
+ // make sure we are in correct mode
+ vidResetMode();
+ if (currentConfig.scaling) PicoOpt|=0x4000;
+ else PicoOpt&=~0x4000;
+ Pico.m.dirtyPal = 1;
+ oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
+ //find_combos(); // TODO
+
+ // pal/ntsc might have changed, reset related stuff
+ target_fps = Pico.m.pal ? 50 : 60;
+ target_frametime = (1000<<8)/target_fps;
+ reset_timing = 1;
+
+ // prepare sound stuff
+/* if (currentConfig.EmuOpt & 4) {
+ int snd_excess_add;
+ if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
+ sound_rerate(Pico.m.frame_count ? 1 : 0);
+ }
+ snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
+ lprintf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
+ PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);
+ gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);
+ gp2x_sound_volume(currentConfig.volume, currentConfig.volume);
+ PicoWriteSound = updateSound;
+ memset(sndBuffer, 0, sizeof(sndBuffer));
+ PsndOut = sndBuffer;
+ PsndRate_old = PsndRate;
+ PsndLen_real = PsndLen;
+ PicoOpt_old = PicoOpt;
+ pal_old = Pico.m.pal;
+ } else*/ {
+ PsndOut = 0;
+ }
+
+ // prepare CD buffer
+ if (PicoMCD & 1) PicoCDBufferInit();
+
+ // loop?
+ while (engineState == PGS_Running)
+ {
+ int modes;
+
+ tval = GetTickCount();
+ if (reset_timing || tval < tval_prev) {
+ reset_timing = 0;
+ tval_thissec = tval;
+ frames_shown = frames_done = 0;
+ }
+
+ // show notice message?
+ if (noticeMsgTime) {
+ static int noticeMsgSum;
+ if (tval - noticeMsgTime > 2000) { // > 2.0 sec
+ noticeMsgTime = 0;
+ clearArea(0);
+ notice = 0;
+ } else {
+ int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];
+ if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }
+ notice = noticeMsg;
+ }
+ }
+
+ // check for mode changes
+ modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);
+ if (modes != oldmodes) {
+ osd_fps_x = OSD_FPS_X;
+ //if (modes & 4)
+ vidCpy8to16 = vidCpy8to16_40;
+ //else
+ // vidCpy8to16 = vidCpy8to16_32col;
+ oldmodes = modes;
+ clearArea(1);
+ }
+
+ // second passed?
+ if (tval - tval_thissec >= 1000)
+ {
+#ifdef BENCHMARK
+ static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];
+ if(++bench == 10) {
+ bench = 0;
+ bench_fps_s = bench_fps;
+ bf[bfp++ & 3] = bench_fps;
+ bench_fps = 0;
+ }
+ 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)
+ sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done);
+#endif
+ tval_thissec = tval;
+
+ if (PsndOut == 0 && currentConfig.Frameskip >= 0) {
+ frames_done = frames_shown = 0;
+ } else {
+ // it is quite common for this implementation to leave 1 fame unfinished
+ // when second changes, but we don't want buffer to starve.
+ if (PsndOut && frames_done < target_fps && frames_done > target_fps-5) {
+ updateKeys();
+ SkipFrame(1); frames_done++;
+ }
+
+ frames_done -= target_fps; if (frames_done < 0) frames_done = 0;
+ frames_shown -= target_fps; if (frames_shown < 0) frames_shown = 0;
+ if (frames_shown > frames_done) frames_shown = frames_done;
+ }
+ }
+#ifdef PFRAMES
+ sprintf(fpsbuff, "%i", Pico.m.frame_count);
+#endif
+
+ tval_prev = tval;
+ lim_time = (frames_done+1) * target_frametime;
+ if (currentConfig.Frameskip >= 0) // frameskip enabled
+ {
+ for (i = 0; i < currentConfig.Frameskip; i++) {
+ updateKeys();
+ SkipFrame(1); frames_done++;
+ if (PsndOut) { // do framelimitting if sound is enabled
+ int tval_diff;
+ tval = GetTickCount();
+ tval_diff = (int)(tval - tval_thissec) << 8;
+ if (tval_diff < lim_time) // we are too fast
+ simpleWait(tval + ((lim_time - tval_diff)>>8));
+ }
+ lim_time += target_frametime;
+ }
+ }
+ else // auto frameskip
+ {
+ int tval_diff;
+ tval = GetTickCount();
+ tval_diff = (int)(tval - tval_thissec) << 8;
+ if (tval_diff > lim_time)
+ {
+ // no time left for this frame - skip
+ if (tval_diff - lim_time >= (300<<8)) {
+ /* something caused a slowdown for us (disk access? cache flush?)
+ * try to recover by resetting timing... */
+ reset_timing = 1;
+ continue;
+ }
+ updateKeys();
+ SkipFrame(tval_diff < lim_time+target_frametime*2); frames_done++;
+ continue;
+ }
+ }
+
+ updateKeys();
+
+ if (giz_screen == NULL)
+ giz_screen = Framework2D_LockBuffer();
+
+ PicoFrame();
+ blit(fpsbuff, notice);
+
+ if (giz_screen != NULL) {
+ Framework2D_UnlockBuffer();
+ giz_screen = NULL;
+ }
+
+ // check time
+ tval = GetTickCount();
+ tval_diff = (int)(tval - tval_thissec) << 8;
+
+ if (currentConfig.Frameskip < 0 && tval_diff - lim_time >= (300<<8)) // slowdown detection
+ reset_timing = 1;
+ else if (PsndOut != NULL || currentConfig.Frameskip < 0)
+ {
+ // sleep if we are still too fast
+ if (tval_diff < lim_time)
+ {
+ // we are too fast
+ simpleWait(tval + ((lim_time - tval_diff) >> 8));
+ }
+ }
+
+ frames_done++; frames_shown++;
+ }
+
+
+ if (PicoMCD & 1) PicoCDBufferFree();
+
+ // save SRAM
+ if ((currentConfig.EmuOpt & 1) && SRam.changed) {
+ emu_state_cb("Writing SRAM/BRAM..");
+ emu_SaveLoadGame(0, 1);
+ SRam.changed = 0;
+ }
+}
+
+
+void emu_ResetGame(void)
+{
+ PicoReset(0);
+ reset_timing = 1;
+}
PGS_RestartRun,\r
};\r
\r
-typedef struct {\r
- char lastRomFile[512];\r
- int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,\r
- // <reserved>, no_save_cfg_on_exit, <unused>, 16_bit_mode\r
- // <reserved>, confirm_save, show_cd_leds, confirm_load\r
- // <reserved>, <reserved>\r
- int PicoOpt; // used for config saving only, see Pico.h\r
- int PsndRate; // ditto\r
- int PicoRegion; // ditto\r
- int Frameskip;\r
- int CPUclock; // unused, placeholder for config compatibility\r
- int KeyBinds[32];\r
- int volume;\r
- int gamma; // unused\r
- int JoyBinds[4][32]; // unused\r
- int PicoAutoRgnOrder;\r
- int PicoCDBuffers;\r
- int scaling; // unused\r
-} currentConfig_t;\r
-\r
+extern unsigned char gfx_buffer[321*240*2*2];\r
extern char romFileName[];\r
extern int engineState;\r
-extern currentConfig_t currentConfig;\r
\r
\r
-int emu_ReloadRom(void);\r
void emu_Init(void);\r
void emu_Deinit(void);\r
-int emu_SaveLoadGame(int load, int sram);\r
void emu_Loop(void);\r
void emu_ResetGame(void);\r
-int emu_ReadConfig(int game, int no_defaults);\r
-int emu_WriteConfig(int game);\r
-char *emu_GetSaveFName(int load, int is_sram, int slot);\r
-int emu_check_save_file(int slot);\r
-void emu_set_save_cbs(int gz);\r
-void emu_forced_frame(void);\r
-int emu_cd_check(int *pregion);\r
-int find_bios(int region, char **bios_file);\r
-void scaling_update(void);\r
+void emu_forcedFrame(void);\r
\r
{
int ret;
- giz_screen = NULL;
-
lprintf("PicoDrive v" VERSION " (c) notaz, 2006,2007\n");
lprintf("%s %s\n\n", __DATE__, __TIME__);
lprintf_al("Framework2D_Init() failed\n");
exit(1);
}
+
+ // test screen
+ giz_screen = Framework2D_LockBuffer();
+ if (giz_screen == NULL)
+ {
+ lprintf_al("Framework2D_LockBuffer() failed\n");
+ exit(1);
+ }
+ lprintf("Framework2D_LockBuffer returned %p\n", giz_screen);
+ Framework2D_UnlockBuffer();
+ giz_screen = NULL;
}
void giz_deinit(void)
\r
#include "giz.h"\r
#include "menu.h"\r
-#include "../common/menu.h"\r
#include "emu.h"\r
+#include "../common/menu.h"\r
+#include "../common/emu.h"\r
#include "version.h"\r
\r
\r
#include "menu.h"\r
#include "../common/arm_utils.h"\r
#include "../common/menu.h"\r
+#include "../common/emu.h"\r
#include "../common/readpng.h"\r
#include "version.h"\r
#include "kgsdk/Framework.h"\r
#include <Pico/Patch.h>\r
#include <zlib/zlib.h>\r
\r
-extern char romFileName[MAX_PATH];\r
-extern char *rom_data;\r
-extern int state_slot;\r
-extern int config_slot, config_slot_current;\r
\r
#define gizKeyUnkn "???"\r
static const char * const gizKeyNames[] = {\r
"LEFT", "RIGHT", "UP", "DOWN", "STOP", "PLAY", "FORWARD", "REWIND",\r
"LEFT_SHOULDER", "RIGHT_SHOULDER", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn,\r
gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,\r
- gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,\r
+ gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn\r
};\r
\r
-static unsigned char bg_buffer[321*240*2];\r
-unsigned char menu_screen[321*240*2]; /* draw here and blit later, to avoid flicker */\r
-char menuErrorMsg[40] = {0, };\r
+static unsigned char *bg_buffer = gfx_buffer + 321*240*2;\r
+unsigned char *menu_screen = gfx_buffer; /* draw here and blit later, to avoid flicker */\r
\r
static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);\r
static void menu_prepare_bg(int use_game_bg);\r
\r
for (slot = 0; slot < 10; slot++)\r
{\r
- if (emu_check_save_file(slot))\r
+ if (emu_checkSaveFile(slot))\r
{\r
state_slot_flags |= 1 << slot;\r
}\r
\r
if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
file = gzopen(fname, "rb");\r
- emu_set_save_cbs(1);\r
+ emu_setSaveStateCbs(1);\r
} else {\r
file = fopen(fname, "rb");\r
- emu_set_save_cbs(0);\r
+ emu_setSaveStateCbs(0);\r
}\r
\r
if (file) {\r
areaClose(file);\r
}\r
\r
- emu_forced_frame();\r
+ emu_forcedFrame();\r
menu_prepare_bg(1);\r
\r
memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
menu_id selected_id;\r
char *bios, *p;\r
\r
- if (find_bios(4, &bios)) { // US\r
+ if (emu_findBios(4, &bios)) { // US\r
for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;\r
} else strcpy(bios_names.us, "NOT FOUND");\r
\r
- if (find_bios(8, &bios)) { // EU\r
+ if (emu_findBios(8, &bios)) { // EU\r
for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;\r
} else strcpy(bios_names.eu, "NOT FOUND");\r
\r
- if (find_bios(1, &bios)) { // JP\r
+ if (emu_findBios(1, &bios)) { // JP\r
for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;\r
} else strcpy(bios_names.jp, "NOT FOUND");\r
}\r
switch (selected_id) { // BIOS testers\r
case MA_CDOPT_TESTBIOS_USA:\r
- if (find_bios(4, &bios)) { // test US\r
+ if (emu_findBios(4, &bios)) { // test US\r
strcpy(romFileName, bios);\r
engineState = PGS_ReloadRom;\r
return;\r
}\r
break;\r
case MA_CDOPT_TESTBIOS_EUR:\r
- if (find_bios(8, &bios)) { // test EU\r
+ if (emu_findBios(8, &bios)) { // test EU\r
strcpy(romFileName, bios);\r
engineState = PGS_ReloadRom;\r
return;\r
}\r
break;\r
case MA_CDOPT_TESTBIOS_JAP:\r
- if (find_bios(1, &bios)) { // test JP\r
+ if (emu_findBios(1, &bios)) { // test JP\r
strcpy(romFileName, bios);\r
engineState = PGS_ReloadRom;\r
return;\r
// unbind XYZ MODE, just in case\r
unbind_action(0xf00);\r
}\r
- scaling_update();\r
}\r
\r
static int menu_loop_options(void)\r
selfname = romsel_loop(curr_path);\r
if (selfname) {\r
int ret = -1, cd_type;\r
- cd_type = emu_cd_check(NULL);\r
+ cd_type = emu_cdCheck(NULL);\r
if (cd_type > 0)\r
ret = Insert_CD(romFileName, cd_type == 2);\r
if (ret != 0) {\r
\r
// For commercial use, separate licencing terms must be obtained.\r
\r
-extern char menuErrorMsg[40];\r
-\r
void menu_init(void);\r
void text_out16(int x, int y, const char *texto, ...);\r
void menu_loop(void);\r
\r
#define CPU_CALL\r
\r
+// draw.c\r
+#define OVERRIDE_HIGHCOL 1\r
+\r
// draw2.c\r
#define START_ROW 0 // which row of tiles to start rendering at?\r
#define END_ROW 28 // ..end\r
@ vim:filetype=armasm\r
\r
-@ .equiv START_ROW, 1\r
-@ .equiv END_ROW, 27\r
+@ .equiv START_ROW, 1\r
+@ .equiv END_ROW, 27\r
@ one row means 8 pixels. If above example was used, (27-1)*8=208 lines would be rendered.\r
-.equiv START_ROW, 0\r
-.equiv END_ROW, 28\r
+.equiv START_ROW, 0\r
+.equiv END_ROW, 28\r
+\r
+.equiv OVERRIDE_HIGHCOL, 1\r
\r
@ this should be set to one only for GP2X port\r
-.equiv EXTERNAL_YM2612, 0\r
+.equiv EXTERNAL_YM2612, 0\r
+\r
#include "mp3.h"\r
#include "../common/arm_utils.h"\r
#include "../common/menu.h"\r
+#include "../common/emu.h"\r
#include "../../Pico/PicoInt.h"\r
#include "../../Pico/sound/ym2612.h"\r
#include "../../Pico/sound/mix.h"\r
OBJS += 940ctl.o\r
\r
# common\r
-OBJS += ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o\r
+OBJS += ../common/emu.o ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o\r
\r
# Pico\r
ifeq "$(amalgamate)" "1"\r
../../Pico/sound/mix_asm.o : ../../Pico/sound/mix.s\r
@echo $<\r
@$(AS) $(ASOPT) $< -o $@\r
-../../Pico/misc_asm.o : ../../Pico/misc.s\r
+../../Pico/misc_asm.o : ../../Pico/Misc.s\r
@echo $<\r
@$(AS) $(ASOPT) $< -o $@\r
../../Pico/cd/pico_asm.o : ../../Pico/cd/Pico.s\r
../../Pico/cd/memory_asm.o : ../../Pico/cd/Memory.s\r
@echo $<\r
@$(AS) $(ASOPT) $< -o $@\r
-../../Pico/cd/misc_asm.o : ../../Pico/cd/misc.s\r
+../../Pico/cd/misc_asm.o : ../../Pico/cd/Misc.s\r
@echo $<\r
@$(AS) $(ASOPT) $< -o $@\r
\r
#include "menu.h"\r
#include "../common/arm_utils.h"\r
#include "../common/fonts.h"\r
+#include "../common/emu.h"\r
#include "cpuctrl.h"\r
\r
#include <Pico/PicoInt.h>\r
\r
int engineState;\r
int select_exits = 0;\r
-char *PicoConfigFile = "picoconfig.bin";\r
-currentConfig_t currentConfig;\r
\r
char romFileName[PATH_MAX];\r
-unsigned char *rom_data = NULL;\r
\r
extern int crashed_940;\r
\r
static short sndBuffer[2*44100/50];\r
-static char noticeMsg[64]; // notice msg to draw\r
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
static int osd_fps_x;\r
static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos\r
static int gp2x_old_gamma = 100;\r
-static unsigned char *movie_data = NULL;\r
-static int movie_size = 0;\r
+char noticeMsg[64]; // notice msg to draw\r
unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer\r
-int state_slot = 0;\r
int reset_timing = 0;\r
-int config_slot = 0, config_slot_current = 0;\r
\r
+static void emu_msg_cb(const char *msg);\r
+static void emu_msg_tray_open(void);\r
\r
-// utilities\r
-static void strlwr(char* string)\r
-{\r
- while ( (*string++ = (char)tolower(*string)) );\r
-}\r
\r
-static int try_rfn_cut(void)\r
+void emu_noticeMsgUpdated(void)\r
{\r
- FILE *tmp;\r
- char *p;\r
-\r
- p = romFileName + strlen(romFileName) - 1;\r
- for (; p > romFileName; p--)\r
- if (*p == '.') break;\r
- *p = 0;\r
-\r
- if((tmp = fopen(romFileName, "rb"))) {\r
- fclose(tmp);\r
- return 1;\r
- }\r
- return 0;\r
+ gettimeofday(¬iceMsgTime, 0);\r
}\r
\r
-static void get_ext(char *file, char *ext)\r
+void emu_getMainDir(char *dst, int len)\r
{\r
- char *p;\r
+ extern char **g_argv;\r
+ int j;\r
\r
- p = file + strlen(file) - 4;\r
- if (p < file) p = file;\r
- strncpy(ext, p, 4);\r
- ext[4] = 0;\r
- strlwr(ext);\r
+ strncpy(dst, g_argv[0], len);\r
+ len -= 32; // reserve\r
+ if (len < 0) len = 0;\r
+ dst[len] = 0;\r
+ for (j = strlen(dst); j > 0; j--)\r
+ if (dst[j] == '/') { dst[j+1] = 0; break; }\r
}\r
\r
-char *biosfiles_us[] = { "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210" };\r
-char *biosfiles_eu[] = { "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210" };\r
-char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
-\r
-extern char **g_argv;\r
-\r
-int find_bios(int region, char **bios_file)\r
-{\r
- static char bios_path[1024];\r
- int i, j, count;\r
- char **files;\r
- FILE *f = NULL;\r
-\r
- if (region == 4) { // US\r
- files = biosfiles_us;\r
- count = sizeof(biosfiles_us) / sizeof(char *);\r
- } else if (region == 8) { // EU\r
- files = biosfiles_eu;\r
- count = sizeof(biosfiles_eu) / sizeof(char *);\r
- } else if (region == 1 || region == 2) {\r
- files = biosfiles_jp;\r
- count = sizeof(biosfiles_jp) / sizeof(char *);\r
- } else {\r
- return 0;\r
- }\r
-\r
- for (i = 0; i < count; i++)\r
- {\r
- strncpy(bios_path, g_argv[0], 1023);\r
- bios_path[1024-32] = 0;\r
- for (j = strlen(bios_path); j > 0; j--)\r
- if (bios_path[j] == '/') { bios_path[j+1] = 0; break; }\r
- strcat(bios_path, files[i]);\r
- strcat(bios_path, ".bin");\r
- f = fopen(bios_path, "rb");\r
- if (f) break;\r
-\r
- bios_path[strlen(bios_path) - 4] = 0;\r
- strcat(bios_path, ".zip");\r
- f = fopen(bios_path, "rb");\r
- if (f) break;\r
- }\r
-\r
- if (f) {\r
- printf("using bios: %s\n", bios_path);\r
- fclose(f);\r
- if (bios_file) *bios_file = bios_path;\r
- return 1;\r
- } else {\r
- sprintf(menuErrorMsg, "no %s BIOS files found, read docs",\r
- region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
- printf("%s\n", menuErrorMsg);\r
- return 0;\r
- }\r
-}\r
-\r
-/* checks if romFileName points to valid MegaCD image\r
- * if so, checks for suitable BIOS */\r
-int emu_cd_check(int *pregion)\r
-{\r
- unsigned char buf[32];\r
- pm_file *cd_f;\r
- int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe\r
-\r
- cd_f = pm_open(romFileName);\r
- if (!cd_f) return 0; // let the upper level handle this\r
-\r
- if (pm_read(buf, 32, cd_f) != 32) {\r
- pm_close(cd_f);\r
- return 0;\r
- }\r
-\r
- if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO)\r
- if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN)\r
- if (type == 0) {\r
- pm_close(cd_f);\r
- return 0;\r
- }\r
-\r
- /* it seems we have a CD image here. Try to detect region now.. */\r
- pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
- pm_read(buf, 1, cd_f);\r
- pm_close(cd_f);\r
-\r
- if (buf[0] == 0x64) region = 8; // EU\r
- if (buf[0] == 0xa1) region = 1; // JAP\r
-\r
- printf("detected %s Sega/Mega CD image with %s region\n",\r
- type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
-\r
- if (pregion != NULL) *pregion = region;\r
-\r
- return type;\r
-}\r
-\r
-int emu_ReloadRom(void)\r
-{\r
- unsigned int rom_size = 0;\r
- char *used_rom_name = romFileName;\r
- char ext[5];\r
- pm_file *rom;\r
- int ret, cd_state, cd_region, cfg_loaded = 0;\r
-\r
- printf("emu_ReloadRom(%s)\n", romFileName);\r
-\r
- get_ext(romFileName, ext);\r
-\r
- // detect wrong extensions\r
- if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz\r
- sprintf(menuErrorMsg, "Not a ROM selected.");\r
- return 0;\r
- }\r
-\r
- PicoPatchUnload();\r
-\r
- // check for movie file\r
- if(movie_data) {\r
- free(movie_data);\r
- movie_data = 0;\r
- }\r
- if(!strcmp(ext, ".gmv")) {\r
- // check for both gmv and rom\r
- int dummy;\r
- FILE *movie_file = fopen(romFileName, "rb");\r
- if(!movie_file) {\r
- sprintf(menuErrorMsg, "Failed to open movie.");\r
- return 0;\r
- }\r
- fseek(movie_file, 0, SEEK_END);\r
- movie_size = ftell(movie_file);\r
- fseek(movie_file, 0, SEEK_SET);\r
- if(movie_size < 64+3) {\r
- sprintf(menuErrorMsg, "Invalid GMV file.");\r
- fclose(movie_file);\r
- return 0;\r
- }\r
- movie_data = malloc(movie_size);\r
- if(movie_data == NULL) {\r
- sprintf(menuErrorMsg, "low memory.");\r
- fclose(movie_file);\r
- return 0;\r
- }\r
- fread(movie_data, 1, movie_size, movie_file);\r
- fclose(movie_file);\r
- if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) {\r
- sprintf(menuErrorMsg, "Invalid GMV file.");\r
- return 0;\r
- }\r
- dummy = try_rfn_cut() || try_rfn_cut();\r
- if (!dummy) {\r
- sprintf(menuErrorMsg, "Could't find a ROM for movie.");\r
- return 0;\r
- }\r
- get_ext(romFileName, ext);\r
- }\r
- else if (!strcmp(ext, ".pat")) {\r
- int dummy;\r
- PicoPatchLoad(romFileName);\r
- dummy = try_rfn_cut() || try_rfn_cut();\r
- if (!dummy) {\r
- sprintf(menuErrorMsg, "Could't find a ROM to patch.");\r
- return 0;\r
- }\r
- get_ext(romFileName, ext);\r
- }\r
-\r
- if ((PicoMCD & 1) && Pico_mcd != NULL)\r
- Stop_CD();\r
-\r
- // check for MegaCD image\r
- cd_state = emu_cd_check(&cd_region);\r
- if (cd_state > 0)\r
- {\r
- // valid CD image, check for BIOS..\r
-\r
- // we need to have config loaded at this point\r
- ret = emu_ReadConfig(1, 1);\r
- if (!ret) emu_ReadConfig(0, 1);\r
- cfg_loaded = 1;\r
-\r
- if (PicoRegionOverride) {\r
- cd_region = PicoRegionOverride;\r
- printf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA");\r
- }\r
- if (!find_bios(cd_region, &used_rom_name)) {\r
- // bios_help() ?\r
- return 0;\r
- }\r
-\r
- PicoMCD |= 1;\r
- get_ext(used_rom_name, ext);\r
- }\r
- else\r
- {\r
- if (PicoMCD & 1) Stop_CD();\r
- PicoMCD &= ~1;\r
- }\r
-\r
- rom = pm_open(used_rom_name);\r
- if(!rom) {\r
- sprintf(menuErrorMsg, "Failed to open rom.");\r
- return 0;\r
- }\r
-\r
- menu_romload_prepare(used_rom_name);\r
-\r
- if(rom_data) {\r
- free(rom_data);\r
- rom_data = 0;\r
- rom_size = 0;\r
- }\r
-\r
- if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) {\r
- sprintf(menuErrorMsg, "PicoCartLoad() failed.");\r
- printf("%s\n", menuErrorMsg);\r
- pm_close(rom);\r
- menu_romload_end();\r
- return 0;\r
- }\r
- pm_close(rom);\r
- menu_romload_end();\r
-\r
- // detect wrong files (Pico crashes on very small files), also see if ROM EP is good\r
- if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||\r
- ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {\r
- if (rom_data) free(rom_data);\r
- rom_data = 0;\r
- sprintf(menuErrorMsg, "Not a ROM selected.");\r
- return 0;\r
- }\r
-\r
- // load config for this ROM (do this before insert to get correct region)\r
- if (!cfg_loaded) {\r
- ret = emu_ReadConfig(1, 1);\r
- if (!ret) emu_ReadConfig(0, 1);\r
- }\r
-\r
- printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
- if(PicoCartInsert(rom_data, rom_size)) {\r
- sprintf(menuErrorMsg, "Failed to load ROM.");\r
- return 0;\r
- }\r
-\r
- Pico.m.frame_count = 0;\r
-\r
- // insert CD if it was detected\r
- if (cd_state > 0) {\r
- ret = Insert_CD(romFileName, cd_state == 2);\r
- if (ret != 0) {\r
- sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
- printf("%s\n", menuErrorMsg);\r
- return 0;\r
- }\r
- }\r
-\r
- // emu_ReadConfig() might have messed currentConfig.lastRomFile\r
- strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
- currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
-\r
- if (PicoPatches) {\r
- PicoPatchPrepare();\r
- PicoPatchApply();\r
- }\r
-\r
- // additional movie stuff\r
- if (movie_data) {\r
- if(movie_data[0x14] == '6')\r
- PicoOpt |= 0x20; // 6 button pad\r
- else PicoOpt &= ~0x20;\r
- PicoOpt |= 0x10040; // accurate timing, no VDP fifo timing\r
- if(movie_data[0xF] >= 'A') {\r
- if(movie_data[0x16] & 0x80) {\r
- PicoRegionOverride = 8;\r
- } else {\r
- PicoRegionOverride = 4;\r
- }\r
- PicoReset(0);\r
- // TODO: bits 6 & 5\r
- }\r
- movie_data[0x18+30] = 0;\r
- sprintf(noticeMsg, "MOVIE: %s", (char *) &movie_data[0x18]);\r
- }\r
- else\r
- {\r
- PicoOpt &= ~0x10000;\r
- if(Pico.m.pal) {\r
- strcpy(noticeMsg, "PAL SYSTEM / 50 FPS");\r
- } else {\r
- strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS");\r
- }\r
- }\r
- gettimeofday(¬iceMsgTime, 0);\r
-\r
- // load SRAM for this ROM\r
- if(currentConfig.EmuOpt & 1)\r
- emu_SaveLoadGame(1, 1);\r
-\r
- return 1;\r
-}\r
-\r
-\r
-static void emu_msg_cb(const char *msg);\r
-static void emu_msg_tray_open(void);\r
-\r
void emu_Init(void)\r
{\r
// make temp buffer for alt renderer\r
}\r
\r
\r
-static void romfname_ext(char *dst, const char *prefix, const char *ext)\r
-{\r
- char *p;\r
- int prefix_len = 0;\r
-\r
- // make save filename\r
- for (p = romFileName+strlen(romFileName)-1; p >= romFileName && *p != '/'; p--); p++;\r
- *dst = 0;\r
- if (prefix) {\r
- strcpy(dst, prefix);\r
- prefix_len = strlen(prefix);\r
- }\r
- strncpy(dst + prefix_len, p, 511-prefix_len);\r
- dst[511-8] = 0;\r
- if (dst[strlen(dst)-4] == '.') dst[strlen(dst)-4] = 0;\r
- if (ext) strcat(dst, ext);\r
-}\r
-\r
-\r
static void find_combos(void)\r
{\r
int act, u;\r
}\r
\r
\r
-void scaling_update(void)\r
+static void scaling_update(void)\r
{\r
PicoOpt &= ~0x4100;\r
switch (currentConfig.scaling) {\r
}\r
\r
\r
-int emu_ReadConfig(int game, int no_defaults)\r
-{\r
- FILE *f;\r
- char cfg[512], extbuf[16];\r
- int bread = 0;\r
-\r
- if (!game)\r
- {\r
- if (!no_defaults)\r
- {\r
- // set default config\r
- memset(¤tConfig, 0, sizeof(currentConfig));\r
- currentConfig.lastRomFile[0] = 0;\r
- currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds\r
- currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda\r
- currentConfig.PsndRate = 22050; // 44100;\r
- currentConfig.PicoRegion = 0; // auto\r
- currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
- currentConfig.Frameskip = -1; // auto\r
- currentConfig.CPUclock = 200;\r
- currentConfig.volume = 50;\r
- currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
- currentConfig.KeyBinds[ 4] = 1<<1;\r
- currentConfig.KeyBinds[ 2] = 1<<2;\r
- currentConfig.KeyBinds[ 6] = 1<<3;\r
- currentConfig.KeyBinds[14] = 1<<4;\r
- currentConfig.KeyBinds[13] = 1<<5;\r
- currentConfig.KeyBinds[12] = 1<<6;\r
- currentConfig.KeyBinds[ 8] = 1<<7;\r
- currentConfig.KeyBinds[15] = 1<<26; // switch rend\r
- currentConfig.KeyBinds[10] = 1<<27; // save state\r
- currentConfig.KeyBinds[11] = 1<<28; // load state\r
- currentConfig.KeyBinds[23] = 1<<29; // vol up\r
- currentConfig.KeyBinds[22] = 1<<30; // vol down\r
- currentConfig.gamma = 100;\r
- currentConfig.PicoCDBuffers = 64;\r
- currentConfig.scaling = 0;\r
- }\r
- strncpy(cfg, PicoConfigFile, 511);\r
- if (config_slot != 0)\r
- {\r
- char *p = strrchr(cfg, '.');\r
- if (p == NULL) p = cfg + strlen(cfg);\r
- sprintf(extbuf, ".%i.pbcfg", config_slot);\r
- strncpy(p, extbuf, 511 - (p - cfg));\r
- }\r
- cfg[511] = 0;\r
- } else {\r
- if (config_slot != 0)\r
- sprintf(extbuf, ".%i.pbcfg", config_slot);\r
- else strcpy(extbuf, ".pbcfg");\r
- romfname_ext(cfg, "cfg/", extbuf);\r
- f = fopen(cfg, "rb");\r
- if (!f) romfname_ext(cfg, NULL, ".pbcfg");\r
- else fclose(f);\r
- }\r
-\r
- printf("emu_ReadConfig: %s ", cfg);\r
- f = fopen(cfg, "rb");\r
- if (f) {\r
- bread = fread(¤tConfig, 1, sizeof(currentConfig), f);\r
- fclose(f);\r
- }\r
- printf(bread > 0 ? "(ok)\n" : "(failed)\n");\r
-\r
- PicoOpt = currentConfig.PicoOpt;\r
- PsndRate = currentConfig.PsndRate;\r
- PicoRegionOverride = currentConfig.PicoRegion;\r
- PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;\r
- PicoCDBuffers = currentConfig.PicoCDBuffers;\r
- scaling_update();\r
- // some sanity checks\r
- if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
- if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
- if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50;\r
- // if volume keys are unbound, bind them to volume control\r
- if (!currentConfig.KeyBinds[23] && !currentConfig.KeyBinds[22]) {\r
- currentConfig.KeyBinds[23] = 1<<29; // vol up\r
- currentConfig.KeyBinds[22] = 1<<30; // vol down\r
- }\r
-\r
- if (bread > 0) config_slot_current = config_slot;\r
- return (bread > 0); // == sizeof(currentConfig));\r
-}\r
-\r
-\r
-int emu_WriteConfig(int game)\r
-{\r
- FILE *f;\r
- char cfg[512], extbuf[16];\r
- int bwrite = 0;\r
-\r
- if (!game)\r
- {\r
- strncpy(cfg, PicoConfigFile, 511);\r
- if (config_slot != 0)\r
- {\r
- char *p = strrchr(cfg, '.');\r
- if (p == NULL) p = cfg + strlen(cfg);\r
- sprintf(extbuf, ".%i.pbcfg", config_slot);\r
- strncpy(p, extbuf, 511 - (p - cfg));\r
- }\r
- cfg[511] = 0;\r
- } else {\r
- if (config_slot != 0)\r
- sprintf(extbuf, ".%i.pbcfg", config_slot);\r
- else strcpy(extbuf, ".pbcfg");\r
- romfname_ext(cfg, "cfg/", extbuf);\r
- }\r
-\r
- printf("emu_WriteConfig: %s ", cfg);\r
- f = fopen(cfg, "wb");\r
- if (f) {\r
- currentConfig.PicoOpt = PicoOpt;\r
- currentConfig.PsndRate = PsndRate;\r
- currentConfig.PicoRegion = PicoRegionOverride;\r
- currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder;\r
- currentConfig.PicoCDBuffers = PicoCDBuffers;\r
- bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f);\r
- fflush(f);\r
- fclose(f);\r
-#ifndef NO_SYNC\r
- sync();\r
-#endif\r
- }\r
- printf((bwrite == sizeof(currentConfig)) ? "(ok)\n" : "(failed)\n");\r
-\r
- if (bwrite == sizeof(currentConfig)) config_slot_current = config_slot;\r
- return (bwrite == sizeof(currentConfig));\r
-}\r
-\r
-\r
void emu_Deinit(void)\r
{\r
// save SRAM\r
set_gamma(100, 0);\r
}\r
\r
-static void text_out8_builtin(int x, int y, const char *text)\r
-{\r
- int i,l,len=strlen(text);\r
- unsigned char *screen = (unsigned char *)gp2x_screen + x + y*320;\r
-\r
- /* always using built-in font */\r
- for (i = 0; i < len; i++)\r
- {\r
- for (l=0;l<8;l++)\r
- {\r
- unsigned char fd = fontdata8x8[((text[i])*8)+l];\r
- if (fd&0x80) screen[l*320+0]=0xf0;\r
- if (fd&0x40) screen[l*320+1]=0xf0;\r
- if (fd&0x20) screen[l*320+2]=0xf0;\r
- if (fd&0x10) screen[l*320+3]=0xf0;\r
- if (fd&0x08) screen[l*320+4]=0xf0;\r
- if (fd&0x04) screen[l*320+5]=0xf0;\r
- if (fd&0x02) screen[l*320+6]=0xf0;\r
- if (fd&0x01) screen[l*320+7]=0xf0;\r
- }\r
- screen += 8;\r
- }\r
-}\r
-\r
-static void text_out16_builtin(int x, int y, const char *text)\r
-{\r
- int i,l,len=strlen(text);\r
- unsigned short *screen = (unsigned short *)gp2x_screen + x + y*320;\r
-\r
- for (i = 0; i < len; i++)\r
- {\r
- for (l=0;l<8;l++)\r
- {\r
- unsigned char fd = fontdata8x8[((text[i])*8)+l];\r
- if(fd&0x80) screen[l*320+0]=0xffff;\r
- if(fd&0x40) screen[l*320+1]=0xffff;\r
- if(fd&0x20) screen[l*320+2]=0xffff;\r
- if(fd&0x10) screen[l*320+3]=0xffff;\r
- if(fd&0x08) screen[l*320+4]=0xffff;\r
- if(fd&0x04) screen[l*320+5]=0xffff;\r
- if(fd&0x02) screen[l*320+6]=0xffff;\r
- if(fd&0x01) screen[l*320+7]=0xffff;\r
- }\r
- screen += 8;\r
- }\r
+void emu_setDefaultConfig(void)\r
+{\r
+ memset(¤tConfig, 0, sizeof(currentConfig));\r
+ currentConfig.lastRomFile[0] = 0;\r
+ currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds\r
+ currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda\r
+ currentConfig.PsndRate = 22050; // 44100;\r
+ currentConfig.PicoRegion = 0; // auto\r
+ currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
+ currentConfig.Frameskip = -1; // auto\r
+ currentConfig.CPUclock = 200;\r
+ currentConfig.volume = 50;\r
+ currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
+ currentConfig.KeyBinds[ 4] = 1<<1;\r
+ currentConfig.KeyBinds[ 2] = 1<<2;\r
+ currentConfig.KeyBinds[ 6] = 1<<3;\r
+ currentConfig.KeyBinds[14] = 1<<4;\r
+ currentConfig.KeyBinds[13] = 1<<5;\r
+ currentConfig.KeyBinds[12] = 1<<6;\r
+ currentConfig.KeyBinds[ 8] = 1<<7;\r
+ currentConfig.KeyBinds[15] = 1<<26; // switch rend\r
+ currentConfig.KeyBinds[10] = 1<<27; // save state\r
+ currentConfig.KeyBinds[11] = 1<<28; // load state\r
+ currentConfig.KeyBinds[23] = 1<<29; // vol up\r
+ currentConfig.KeyBinds[22] = 1<<30; // vol down\r
+ currentConfig.gamma = 100;\r
+ currentConfig.PicoCDBuffers = 64;\r
+ currentConfig.scaling = 0;\r
}\r
\r
-\r
void osd_text(int x, int y, const char *text)\r
{\r
int len = strlen(text)*8;\r
p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h));\r
for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
}\r
- text_out8_builtin(x, y, text);\r
+ emu_textOut8(x, y, text);\r
} else {\r
int *p, i, h;\r
x &= ~1; // align x\r
p = (int *) ((unsigned short *) gp2x_screen+x+320*(y+h));\r
for (i = len; i; i--, p++) *p = (*p>>2)&0x39e7;\r
}\r
- text_out16_builtin(x, y, text);\r
+ emu_textOut16(x, y, text);\r
}\r
}\r
\r
{\r
if(which & 0x1800) { // save or load (but not both)\r
int do_it = 1;\r
- if ( emu_check_save_file(state_slot) &&\r
+ if ( emu_checkSaveFile(state_slot) &&\r
(( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
(!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
unsigned long keys;\r
state_slot += 1;\r
if(state_slot > 9) state_slot = 0;\r
}\r
- sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_check_save_file(state_slot) ? "USED" : "FREE");\r
+ sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
if(which & 0x0080) {\r
}\r
\r
\r
-static void updateMovie(void)\r
-{\r
- int offs = Pico.m.frame_count*3 + 0x40;\r
- if (offs+3 > movie_size) {\r
- free(movie_data);\r
- movie_data = 0;\r
- strcpy(noticeMsg, "END OF MOVIE.");\r
- printf("END OF MOVIE.\n");\r
- gettimeofday(¬iceMsgTime, 0);\r
- } else {\r
- // MXYZ SACB RLDU\r
- PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU\r
- if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // A\r
- if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // B\r
- if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // A\r
- PicoPad[1] = ~movie_data[offs+1] & 0x8f; // ! SCBA RLDU\r
- if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // A\r
- if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // B\r
- if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // A\r
- PicoPad[0] |= (~movie_data[offs+2] & 0x0A) << 8; // ! MZYX\r
- if(!(movie_data[offs+2] & 0x01)) PicoPad[0] |= 0x0400; // X\r
- if(!(movie_data[offs+2] & 0x04)) PicoPad[0] |= 0x0100; // Z\r
- PicoPad[1] |= (~movie_data[offs+2] & 0xA0) << 4; // ! MZYX\r
- if(!(movie_data[offs+2] & 0x10)) PicoPad[1] |= 0x0400; // X\r
- if(!(movie_data[offs+2] & 0x40)) PicoPad[1] |= 0x0100; // Z\r
- }\r
-}\r
-\r
-\r
static void updateKeys(void)\r
{\r
unsigned long keys, allActions[2] = { 0, 0 }, events;\r
\r
events &= ~prevEvents;\r
if (events) RunEvents(events);\r
- if (movie_data) updateMovie();\r
+ if (movie_data) emu_updateMovie();\r
\r
prevEvents = (allActions[0] | allActions[1]) >> 16;\r
}\r
}\r
\r
\r
-void emu_forced_frame(void)\r
+void emu_forcedFrame(void)\r
{\r
int po_old = PicoOpt;\r
int eo_old = currentConfig.EmuOpt;\r
\r
// make sure we are in correct mode\r
vidResetMode();\r
+ scaling_update();\r
Pico.m.dirtyPal = 1;\r
oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
find_combos();\r
}\r
} else if(tval.tv_usec > lim_time) { // auto frameskip\r
// no time left for this frame - skip\r
- if (tval.tv_usec - lim_time >= 0x300000) {\r
+ if (tval.tv_usec - lim_time >= 300000) {\r
/* something caused a slowdown for us (disk access? cache flush?)\r
* try to recover by resetting timing... */\r
reset_timing = 1;\r
gettimeofday(&tval, 0);\r
if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
\r
- if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 0x300000) // slowdown detection\r
+ if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection\r
reset_timing = 1;\r
else if (PsndOut != NULL || currentConfig.Frameskip < 0)\r
{\r
\r
// if in 8bit mode, generate 16bit image for menu background\r
if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80))\r
- emu_forced_frame();\r
+ emu_forcedFrame();\r
}\r
\r
\r
}\r
\r
\r
-size_t gzRead2(void *p, size_t _size, size_t _n, void *file)\r
-{\r
- return gzread(file, p, _n);\r
-}\r
-\r
-\r
-size_t gzWrite2(void *p, size_t _size, size_t _n, void *file)\r
-{\r
- return gzwrite(file, p, _n);\r
-}\r
-\r
-static int try_ropen_file(const char *fname)\r
-{\r
- FILE *f;\r
-\r
- f = fopen(fname, "rb");\r
- if (f) {\r
- fclose(f);\r
- return 1;\r
- }\r
- return 0;\r
-}\r
-\r
-char *emu_GetSaveFName(int load, int is_sram, int slot)\r
-{\r
- static char saveFname[512];\r
- char ext[16];\r
-\r
- if (is_sram)\r
- {\r
- romfname_ext(saveFname, (PicoMCD&1) ? "brm/" : "srm/", (PicoMCD&1) ? ".brm" : ".srm");\r
- if (load) {\r
- if (try_ropen_file(saveFname)) return saveFname;\r
- // try in current dir..\r
- romfname_ext(saveFname, NULL, (PicoMCD&1) ? ".brm" : ".srm");\r
- if (try_ropen_file(saveFname)) return saveFname;\r
- return NULL; // give up\r
- }\r
- }\r
- else\r
- {\r
- ext[0] = 0;\r
- if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);\r
- strcat(ext, (currentConfig.EmuOpt & 8) ? ".mds.gz" : ".mds");\r
-\r
- romfname_ext(saveFname, "mds/", ext);\r
- if (load) {\r
- if (try_ropen_file(saveFname)) return saveFname;\r
- romfname_ext(saveFname, NULL, ext);\r
- if (try_ropen_file(saveFname)) return saveFname;\r
- if (currentConfig.EmuOpt & 8) {\r
- ext[0] = 0;\r
- if(slot > 0 && slot < 10) sprintf(ext, ".%i", slot);\r
- strcat(ext, ".mds");\r
-\r
- romfname_ext(saveFname, "mds/", ext);\r
- if (try_ropen_file(saveFname)) return saveFname;\r
- romfname_ext(saveFname, NULL, ext);\r
- if (try_ropen_file(saveFname)) return saveFname;\r
- }\r
- return NULL;\r
- }\r
- }\r
-\r
- return saveFname;\r
-}\r
-\r
-int emu_check_save_file(int slot)\r
-{\r
- return emu_GetSaveFName(1, 0, slot) ? 1 : 0;\r
-}\r
-\r
-void emu_set_save_cbs(int gz)\r
-{\r
- if (gz) {\r
- areaRead = gzRead2;\r
- areaWrite = gzWrite2;\r
- areaEof = (areaeof *) gzeof;\r
- areaSeek = (areaseek *) gzseek;\r
- areaClose = (areaclose *) gzclose;\r
- } else {\r
- areaRead = (arearw *) fread;\r
- areaWrite = (arearw *) fwrite;\r
- areaEof = (areaeof *) feof;\r
- areaSeek = (areaseek *) fseek;\r
- areaClose = (areaclose *) fclose;\r
- }\r
-}\r
-\r
-int emu_SaveLoadGame(int load, int sram)\r
-{\r
- int ret = 0;\r
- char *saveFname;\r
-\r
- // make save filename\r
- saveFname = emu_GetSaveFName(load, sram, state_slot);\r
- if (saveFname == NULL) {\r
- if (!sram) {\r
- strcpy(noticeMsg, load ? "LOAD FAILED (missing file)" : "SAVE FAILED ");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- return -1;\r
- }\r
-\r
- printf("saveLoad (%i, %i): %s\n", load, sram, saveFname);\r
-\r
- if(sram) {\r
- FILE *sramFile;\r
- int sram_size;\r
- unsigned char *sram_data;\r
- int truncate = 1;\r
- if (PicoMCD&1) {\r
- if (PicoOpt&0x8000) { // MCD RAM cart?\r
- sram_size = 0x12000;\r
- sram_data = SRam.data;\r
- if (sram_data)\r
- memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4);\r
- } else {\r
- sram_size = 0x2000;\r
- sram_data = Pico_mcd->bram;\r
- truncate = 0; // the .brm may contain RAM cart data after normal brm\r
- }\r
- } else {\r
- sram_size = SRam.end-SRam.start+1;\r
- if(Pico.m.sram_reg & 4) sram_size=0x2000;\r
- sram_data = SRam.data;\r
- }\r
- if (!sram_data) return 0; // SRam forcefully disabled for this game\r
-\r
- if (load) {\r
- sramFile = fopen(saveFname, "rb");\r
- if(!sramFile) return -1;\r
- fread(sram_data, 1, sram_size, sramFile);\r
- fclose(sramFile);\r
- if ((PicoMCD&1) && (PicoOpt&0x8000))\r
- memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4);\r
- } else {\r
- // sram save needs some special processing\r
- // see if we have anything to save\r
- for (; sram_size > 0; sram_size--)\r
- if (sram_data[sram_size-1]) break;\r
-\r
- if (sram_size) {\r
- sramFile = fopen(saveFname, truncate ? "wb" : "r+b");\r
- if (!sramFile) sramFile = fopen(saveFname, "wb"); // retry\r
- if (!sramFile) return -1;\r
- ret = fwrite(sram_data, 1, sram_size, sramFile);\r
- ret = (ret != sram_size) ? -1 : 0;\r
- fclose(sramFile);\r
-#ifndef NO_SYNC\r
- sync();\r
-#endif\r
- }\r
- }\r
- return ret;\r
- }\r
- else\r
- {\r
- void *PmovFile = NULL;\r
- if (strcmp(saveFname + strlen(saveFname) - 3, ".gz") == 0) {\r
- if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {\r
- emu_set_save_cbs(1);\r
- if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);\r
- }\r
- }\r
- else\r
- {\r
- if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {\r
- emu_set_save_cbs(0);\r
- }\r
- }\r
- if(PmovFile) {\r
- ret = PmovState(load ? 6 : 5, PmovFile);\r
- areaClose(PmovFile);\r
- PmovFile = 0;\r
- if (load) Pico.m.dirtyPal=1;\r
-#ifndef NO_SYNC\r
- else sync();\r
-#endif\r
- }\r
- else ret = -1;\r
- if (!ret)\r
- strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED ");\r
- else\r
- {\r
- strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED ");\r
- ret = -1;\r
- }\r
-\r
- gettimeofday(¬iceMsgTime, 0);\r
- return ret;\r
- }\r
-}\r
PGS_RestartRun,\r
};\r
\r
-typedef struct {\r
- char lastRomFile[512];\r
- int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,\r
- // squidgehack, no_save_cfg_on_exit, <unused>, 16_bit_mode\r
- // craigix_ram, confirm_save, show_cd_leds, confirm_load\r
- // A_SNs_gamma, perfect_vsync\r
- int PicoOpt; // used for config saving only, see Pico.h\r
- int PsndRate; // ditto\r
- int PicoRegion; // ditto\r
- int Frameskip;\r
- int CPUclock;\r
- int KeyBinds[32];\r
- int volume;\r
- int gamma;\r
- int JoyBinds[4][32];\r
- int PicoAutoRgnOrder;\r
- int PicoCDBuffers;\r
- int scaling; // 0=center, 1=hscale, 2=hvscale, 3=hsoftscale\r
-} currentConfig_t;\r
-\r
extern char romFileName[];\r
extern int engineState;\r
-extern currentConfig_t currentConfig;\r
\r
\r
-int emu_ReloadRom(void);\r
void emu_Init(void);\r
void emu_Deinit(void);\r
-int emu_SaveLoadGame(int load, int sram);\r
void emu_Loop(void);\r
void emu_ResetGame(void);\r
-int emu_ReadConfig(int game, int no_defaults);\r
-int emu_WriteConfig(int game);\r
-char *emu_GetSaveFName(int load, int is_sram, int slot);\r
-int emu_check_save_file(int slot);\r
-void emu_set_save_cbs(int gz);\r
-void emu_forced_frame(void);\r
-int emu_cd_check(int *pregion);\r
-int find_bios(int region, char **bios_file);\r
-void scaling_update(void);\r
+void emu_forcedFrame(void);\r
+\r
+void osd_text(int x, int y, const char *text);\r
\r
#include "gp2x.h"\r
#include "menu.h"\r
#include "../common/menu.h"\r
+#include "../common/emu.h"\r
#include "emu.h"\r
#include "940ctl.h"\r
#include "version.h"\r
#include "emu.h"\r
#include "menu.h"\r
#include "usbjoy.h"\r
-#include "../common/arm_utils.h"\r
+#include "../common/emu.h"\r
#include "../common/menu.h"\r
+#include "../common/arm_utils.h"\r
#include "../common/readpng.h"\r
#include "version.h"\r
\r
#error "need d_type for file browser\r
#endif\r
\r
-extern char romFileName[PATH_MAX];\r
-extern char *rom_data;\r
extern int mmuhack_status;\r
-extern int state_slot;\r
-extern int config_slot, config_slot_current;\r
\r
static const char *gp2xKeyNames[] = {\r
"UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",\r
"???", "???", "???", "PUSH", "???", "???", "???", "???"\r
};\r
\r
-char menuErrorMsg[40] = {0, };\r
-\r
static void menu_darken_bg(void *dst, int pixels, int darker);\r
static void menu_prepare_bg(int use_game_bg);\r
\r
\r
for (slot = 0; slot < 10; slot++)\r
{\r
- if (emu_check_save_file(slot))\r
+ if (emu_checkSaveFile(slot))\r
{\r
state_slot_flags |= 1 << slot;\r
}\r
\r
if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
file = gzopen(fname, "rb");\r
- emu_set_save_cbs(1);\r
+ emu_setSaveStateCbs(1);\r
} else {\r
file = fopen(fname, "rb");\r
- emu_set_save_cbs(0);\r
+ emu_setSaveStateCbs(0);\r
}\r
\r
if (file) {\r
areaClose(file);\r
}\r
\r
- emu_forced_frame();\r
+ emu_forcedFrame();\r
menu_prepare_bg(1);\r
\r
memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
menu_id selected_id;\r
char *bios, *p;\r
\r
- if (find_bios(4, &bios)) { // US\r
+ if (emu_findBios(4, &bios)) { // US\r
for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;\r
} else strcpy(bios_names.us, "NOT FOUND");\r
\r
- if (find_bios(8, &bios)) { // EU\r
+ if (emu_findBios(8, &bios)) { // EU\r
for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;\r
} else strcpy(bios_names.eu, "NOT FOUND");\r
\r
- if (find_bios(1, &bios)) { // JP\r
+ if (emu_findBios(1, &bios)) { // JP\r
for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;\r
} else strcpy(bios_names.jp, "NOT FOUND");\r
if (inp & GP2X_START) { // BIOS testers\r
switch (selected_id) {\r
case MA_CDOPT_TESTBIOS_USA:\r
- if (find_bios(4, &bios)) { // test US\r
+ if (emu_findBios(4, &bios)) { // test US\r
strcpy(romFileName, bios);\r
engineState = PGS_ReloadRom;\r
return;\r
}\r
break;\r
case MA_CDOPT_TESTBIOS_EUR:\r
- if (find_bios(8, &bios)) { // test EU\r
+ if (emu_findBios(8, &bios)) { // test EU\r
strcpy(romFileName, bios);\r
engineState = PGS_ReloadRom;\r
return;\r
}\r
break;\r
case MA_CDOPT_TESTBIOS_JAP:\r
- if (find_bios(1, &bios)) { // test JP\r
+ if (emu_findBios(1, &bios)) { // test JP\r
strcpy(romFileName, bios);\r
engineState = PGS_ReloadRom;\r
return;\r
// unbind XYZ MODE, just in case\r
unbind_action(0xf00, -1, -1);\r
}\r
- scaling_update();\r
}\r
\r
static int menu_loop_options(void)\r
selfname = romsel_loop(curr_path);\r
if (selfname) {\r
int ret = -1, cd_type;\r
- cd_type = emu_cd_check(NULL);\r
+ cd_type = emu_cdCheck(NULL);\r
if (cd_type > 0)\r
ret = Insert_CD(romFileName, cd_type == 2);\r
if (ret != 0) {\r
\r
// For commercial use, separate licencing terms must be obtained.\r
\r
-extern char menuErrorMsg[40];\r
-\r
void menu_loop(void);\r
int menu_loop_tray(void);\r
void menu_romload_prepare(const char *rom_name);\r
\r
#define CPU_CALL\r
\r
+// draw.c\r
+#define OVERRIDE_HIGHCOL 0\r
+\r
// draw2.c\r
#define START_ROW 0 // which row of tiles to start rendering at?\r
#define END_ROW 28 // ..end\r
@ vim:filetype=armasm\r
\r
-@ .equiv START_ROW, 1\r
-@ .equiv END_ROW, 27\r
+@ .equiv START_ROW, 1\r
+@ .equiv END_ROW, 27\r
@ one row means 8 pixels. If above example was used, (27-1)*8=208 lines would be rendered.\r
-.equiv START_ROW, 0\r
-.equiv END_ROW, 28\r
+.equiv START_ROW, 0\r
+.equiv END_ROW, 28\r
+\r
+.equiv OVERRIDE_HIGHCOL, 0\r
\r
@ this should be set to one only for GP2X port\r
-.equiv EXTERNAL_YM2612, 1\r
+.equiv EXTERNAL_YM2612, 1\r
+\r