From: notaz Date: Sat, 1 Sep 2007 11:07:03 +0000 (+0000) Subject: giz menu works X-Git-Tag: v1.85~685 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5f426aa2e86d56357b8af2795e73cc0c9b17e8f;p=picodrive.git giz menu works git-svn-id: file:///home/notaz/opt/svn/PicoDrive@231 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/Pico/Draw2.c b/Pico/Draw2.c index 5037e2f9..9fc413bc 100644 --- a/Pico/Draw2.c +++ b/Pico/Draw2.c @@ -21,7 +21,6 @@ #define USE_CACHE -extern unsigned char *framebuff; // in format (8+320)x(8+224+8) (eights for borders) int currpri = 0; static int HighCache2A[41*(TILE_ROWS+1)+1+1]; // caches for high layers @@ -139,7 +138,7 @@ static void DrawWindowFull(int start, int end, int prio) { struct PicoVideo *pvid=&Pico.video; int nametab, nametab_step, trow, tilex, blank=-1, code; - unsigned char *scrpos = framebuff; + unsigned char *scrpos = PicoDraw2FB; int tile_start, tile_end; // in cells // parse ranges @@ -239,7 +238,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend) if (plane==0) nametab=(pvid->reg[2]&0x38)<< 9; // A else nametab=(pvid->reg[4]&0x07)<<12; // B - scrpos = framebuff; + scrpos = PicoDraw2FB; scrpos+=8*328*(planestart-START_ROW); // Get vertical scroll value: @@ -317,7 +316,7 @@ static void DrawTilesFromCacheF(int *hc) // unsigned short *pal; unsigned char pal; short blank=-1; // The tile we know is blank - unsigned char *scrpos = framebuff, *pd = 0; + unsigned char *scrpos = PicoDraw2FB, *pd = 0; // *hcache++ = code|(dx<<16)|(trow<<27); // cache it scrpos+=(*hc++)*328 - START_ROW*328*8; @@ -380,7 +379,7 @@ static void DrawSpriteFull(unsigned int *sprite) // goto first vertically visible tile while(sy <= START_ROW*8) { sy+=8; tile+=tdeltay; height--; } - scrpos = framebuff; + scrpos = PicoDraw2FB; scrpos+=(sy-START_ROW*8)*328; for (; height > 0; height--, sy+=8, tile+=tdeltay) @@ -481,7 +480,7 @@ static void DrawAllSpritesFull(int prio, int maxwidth) static void BackFillFull(int reg7) { unsigned int back, i; - unsigned int *p=(unsigned int *)framebuff; + unsigned int *p=(unsigned int *)PicoDraw2FB; // Start with a background color: // back=PicoCramHigh[reg7&0x3f]; diff --git a/Pico/Draw2.s b/Pico/Draw2.s index 7826b1e6..9c3f0272 100644 --- a/Pico/Draw2.s +++ b/Pico/Draw2.s @@ -8,7 +8,7 @@ .extern Pico -.extern framebuff +.extern PicoDraw2FB @ define these constants in your include file: @ .equiv START_ROW, 1 @@ -22,7 +22,7 @@ BackFillFull: stmfd sp!, {r4-r9,lr} - ldr lr, =framebuff @ lr=framebuff + ldr lr, =PicoDraw2FB @ lr=PicoDraw2FB ldr lr, [lr] add lr, lr, #328*8 @@ -394,7 +394,7 @@ DrawLayerFull: and r4, r4, #7 orr lr, lr, r4, lsl #13 @ lr|=nametab_bits{3}<<13 - ldr r11, =framebuff @ r11=framebuff + ldr r11, =PicoDraw2FB @ r11=PicoDraw2FB ldr r11, [r11] sub r4, r9, #(START_ROW<<24) mov r4, r4, asr #24 @@ -572,7 +572,7 @@ DrawTilesFromCacheF: mov r9, #0xff000000 @ r9=prevcode=-1 mvn r6, #0 @ r6=prevy=-1 - ldr r4, =framebuff @ r4=framebuff + ldr r4, =PicoDraw2FB @ r4=PicoDraw2FB ldr r4, [r4] ldr r1, [r0], #4 @ read y offset mov r7, #328 @@ -696,7 +696,7 @@ DrawWindowFull: mov r9, #0xff000000 @ r9=prevcode=-1 - ldr r11, =framebuff @ r11=scrpos + ldr r11, =PicoDraw2FB @ r11=scrpos ldr r11, [r11] add r11, r11, #328*8 add r11, r11, #8 @@ -896,7 +896,7 @@ DrawSpriteFull: ldr r10, =(Pico+0x10000) @ r10=Pico.vram - ldr r11, =framebuff @ r11=scrpos + ldr r11, =PicoDraw2FB @ r11=scrpos ldr r11, [r11] sub r1, r12, #(START_ROW*8) mov r0, #328 diff --git a/Pico/Pico.h b/Pico/Pico.h index 0ec74a88..6adb7f55 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -118,6 +118,7 @@ void *blockcpy(void *dst, const void *src, size_t n); // Draw2.c // stuff below is optional +extern unsigned char *PicoDraw2FB; // buffer for fasr renderer in format (8+320)x(8+224+8) (eights for borders) extern unsigned short *PicoCramHigh; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now) extern void (*PicoPrepareCram)(); // prepares PicoCramHigh for renderer to use diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index f495bb65..d98a900d 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -315,7 +315,8 @@ extern int z80startCycle, z80stopCycle; // in 68k cycles PICO_INTERNAL int CheckDMA(void); // cd/Pico.c -PICO_INTERNAL int PicoInitMCD(void); +PICO_INTERNAL int PicoInitMCD(void); +PICO_INTERNAL void PicoExitMCD(void); PICO_INTERNAL int PicoResetMCD(int hard); PICO_INTERNAL int PicoFrameMCD(void); diff --git a/Pico/cd/Misc.c b/Pico/cd/Misc.c index d43c161f..74beade9 100644 --- a/Pico/cd/Misc.c +++ b/Pico/cd/Misc.c @@ -1,6 +1,7 @@ // Some misc stuff // (c) Copyright 2007, Grazvydas "notaz" Ignotas +#include "../PicoInt.h" unsigned char formatted_bram[4*0x10] = { diff --git a/cpu/DrZ80/drz80.s b/cpu/DrZ80/drz80.s index 47606503..eba8b955 100644 --- a/cpu/DrZ80/drz80.s +++ b/cpu/DrZ80/drz80.s @@ -11,18 +11,21 @@ .global DrZ80Run .global DrZ80Ver - .equiv INTERRUPT_MODE, 0 ;@0 = Use internal int handler, 1 = Use Mames int handler - .equiv FAST_Z80SP, 1 ;@0 = Use mem functions for stack pointer, 1 = Use direct mem pointer - .equiv UPDATE_CONTEXT, 0 - .equiv DRZ80_FOR_PICODRIVE, 1 + .equiv INTERRUPT_MODE, 0 ;@0 = Use internal int handler, 1 = Use Mames int handler + .equiv FAST_Z80SP, 1 ;@0 = Use mem functions for stack pointer, 1 = Use direct mem pointer + .equiv UPDATE_CONTEXT, 0 + .equiv DRZ80_FOR_PICODRIVE, 1 .if INTERRUPT_MODE - .extern Interrupt + .extern Interrupt .endif .if DRZ80_FOR_PICODRIVE - .extern YM2612Read_ - .extern YM2612Read_940 +.include "port_config.s" + .extern YM2612Read_ +.if EXTERNAL_YM2612 + .extern YM2612Read_940 +.endif .extern PicoRead8 .extern Pico .extern z80_write @@ -106,7 +109,6 @@ DrZ80Ver: .long 0x0001 .text .if DRZ80_FOR_PICODRIVE -.include "port_config.s" .macro YM2612Read_and_ret8 stmfd sp!,{r3,r12,lr} diff --git a/platform/gp2x/asmutils.h b/platform/common/arm_utils.h similarity index 100% rename from platform/gp2x/asmutils.h rename to platform/common/arm_utils.h diff --git a/platform/gp2x/asmutils.s b/platform/common/arm_utils.s similarity index 100% rename from platform/gp2x/asmutils.s rename to platform/common/arm_utils.s diff --git a/platform/gp2x/fonts.c b/platform/common/fonts.c similarity index 100% rename from platform/gp2x/fonts.c rename to platform/common/fonts.c diff --git a/platform/gp2x/fonts.h b/platform/common/fonts.h similarity index 100% rename from platform/gp2x/fonts.h rename to platform/common/fonts.h diff --git a/platform/common/lprintf.h b/platform/common/lprintf.h new file mode 100644 index 00000000..5cd176f5 --- /dev/null +++ b/platform/common/lprintf.h @@ -0,0 +1,6 @@ +#if defined(__GP2X__) +#define lprintf printf +#else +#include "giz.h" +#endif + diff --git a/platform/common/menu.c b/platform/common/menu.c new file mode 100644 index 00000000..53ef33d0 --- /dev/null +++ b/platform/common/menu.c @@ -0,0 +1,314 @@ +// (c) Copyright 2006,2007 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + +#include +#include +#include +#include + +#include "menu.h" +#include "fonts.h" +#include "readpng.h" +#include "lprintf.h" + +#if defined(__GP2X__) +#include "../gp2x/gp2x.h" +#define SCREEN_WIDTH 320 +#define SCREEN_BUFFER gp2x_screen +#elif defined(__GIZ__) +#include "../gizmondo/giz.h" +#define SCREEN_WIDTH 321 +#define SCREEN_BUFFER giz_screen +#endif + +static unsigned char menu_font_data[10240]; +static int menu_text_color = 0xffff; // default to white +static int menu_sel_color = -1; // disabled + +// draws text to current bbp16 screen +static void text_out16_(int x, int y, const char *text, int color) +{ + int i, l, u, tr, tg, tb, len; + unsigned short *dest = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH; + tr = (color & 0xf800) >> 8; + tg = (color & 0x07e0) >> 3; + tb = (color & 0x001f) << 3; + + if (text == (void *)1) + { + // selector symbol + text = ""; + len = 1; + } + else + len = strlen(text); + + for (i = 0; i < len; i++) + { + unsigned char *src = menu_font_data + (unsigned int)text[i]*4*10; + unsigned short *dst = dest; + for (l = 0; l < 10; l++, dst += SCREEN_WIDTH-8) + { + for (u = 8/2; u > 0; u--, src++) + { + int c, r, g, b; + c = *src >> 4; + r = (*dst & 0xf800) >> 8; + g = (*dst & 0x07e0) >> 3; + b = (*dst & 0x001f) << 3; + r = (c^0xf)*r/15 + c*tr/15; + g = (c^0xf)*g/15 + c*tg/15; + b = (c^0xf)*b/15 + c*tb/15; + *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3); + c = *src & 0xf; + r = (*dst & 0xf800) >> 8; + g = (*dst & 0x07e0) >> 3; + b = (*dst & 0x001f) << 3; + r = (c^0xf)*r/15 + c*tr/15; + g = (c^0xf)*g/15 + c*tg/15; + b = (c^0xf)*b/15 + c*tb/15; + *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3); + } + } + dest += 8; + } +} + +void text_out16(int x, int y, const char *texto, ...) +{ + va_list args; + char buffer[512]; + + va_start(args,texto); + vsprintf(buffer,texto,args); + va_end(args); + + text_out16_(x,y,buffer,menu_text_color); +} + + +void smalltext_out16(int x, int y, const char *texto, int color) +{ + int i; + unsigned char *src; + unsigned short *dst; + + for (i = 0;; i++, x += 6) + { + unsigned char c = (unsigned char) texto[i]; + int h = 8; + + if (!c) break; + + src = fontdata6x8[c]; + dst = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH; + + while (h--) + { + int w = 0x20; + while (w) + { + if( *src & w ) *dst = color; + dst++; + w>>=1; + } + src++; + + dst += SCREEN_WIDTH-6; + } + } +} + +void smalltext_out16_lim(int x, int y, const char *texto, int color, int max) +{ + char buffer[SCREEN_WIDTH/6+1]; + + strncpy(buffer, texto, SCREEN_WIDTH/6); + if (max > SCREEN_WIDTH/6) max = SCREEN_WIDTH/6; + if (max < 0) max = 0; + buffer[max] = 0; + + smalltext_out16(x, y, buffer, color); +} + +void menu_draw_selection(int x, int y, int w) +{ + int i, h; + unsigned short *dst, *dest; + + text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color); + + if (menu_sel_color < 0) return; // no selection hilight + + if (y > 0) y--; + dest = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH + 14; + for (h = 11; h > 0; h--) + { + dst = dest; + for (i = w; i > 0; i--) + *dst++ = menu_sel_color; + dest += SCREEN_WIDTH; + } +} + +static int parse_hex_color(char *buff) +{ + char *endp = buff; + int t = (int) strtoul(buff, &endp, 16); + if (endp != buff) return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f); + return -1; +} + +void menu_init(void) +{ + int c, l; + unsigned char *fd = menu_font_data; + char buff[256]; + FILE *f; + + // generate default font from fontdata8x8 + memset(menu_font_data, 0, sizeof(menu_font_data)); + for (c = 0; c < 256; c++) + { + for (l = 0; l < 8; l++) + { + unsigned char fd8x8 = fontdata8x8[c*8+l]; + if (fd8x8&0x80) *fd |= 0xf0; + if (fd8x8&0x40) *fd |= 0x0f; fd++; + if (fd8x8&0x20) *fd |= 0xf0; + if (fd8x8&0x10) *fd |= 0x0f; fd++; + if (fd8x8&0x08) *fd |= 0xf0; + if (fd8x8&0x04) *fd |= 0x0f; fd++; + if (fd8x8&0x02) *fd |= 0xf0; + if (fd8x8&0x01) *fd |= 0x0f; fd++; + } + fd += 8*2/2; // 2 empty lines + } + + // load custom font and selector (stored as 1st symbol in font table) + readpng(menu_font_data, "skin/font.png", READPNG_FONT); + memcpy(menu_font_data, menu_font_data + ((int)'>')*4*10, 4*10); // default selector symbol is '>' + readpng(menu_font_data, "skin/selector.png", READPNG_SELECTOR); + + // load custom colors + f = fopen("skin/skin.txt", "r"); + if (f != NULL) + { + lprintf("found skin.txt\n"); + while (!feof(f)) + { + fgets(buff, sizeof(buff), f); + if (buff[0] == '#' || buff[0] == '/') continue; // comment + if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line + if (strncmp(buff, "text_color=", 11) == 0) + { + int tmp = parse_hex_color(buff+11); + if (tmp >= 0) menu_text_color = tmp; + else lprintf("skin.txt: parse error for text_color\n"); + } + else if (strncmp(buff, "selection_color=", 16) == 0) + { + int tmp = parse_hex_color(buff+16); + if (tmp >= 0) menu_sel_color = tmp; + else lprintf("skin.txt: parse error for selection_color\n"); + } + else + lprintf("skin.txt: parse error: %s\n", buff); + } + fclose(f); + } +} + + +int me_id2offset(const menu_entry *entries, int count, menu_id id) +{ + int i; + for (i = 0; i < count; i++) + { + if (entries[i].id == id) return i; + } + + lprintf("%s: id %i not found\n", __FUNCTION__, id); + return 0; +} + +void me_enable(menu_entry *entries, int count, menu_id id, int enable) +{ + int i = me_id2offset(entries, count, id); + entries[i].enabled = enable; +} + +int me_count_enabled(const menu_entry *entries, int count) +{ + int i, ret = 0; + + for (i = 0; i < count; i++) + { + if (entries[i].enabled) ret++; + } + + return ret; +} + +menu_id me_index2id(const menu_entry *entries, int count, int index) +{ + int i; + + for (i = 0; i < count; i++) + { + if (entries[i].enabled) + { + if (index == 0) break; + index--; + } + } + if (i >= count) i = count - 1; + return entries[i].id; +} + +void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param) +{ + int i, y1 = y; + + for (i = 0; i < count; i++) + { + if (!entries[i].enabled) continue; + if (entries[i].name == NULL) + { + if (cust_draw != NULL) + cust_draw(&entries[i], x, y1, param); + y1 += 10; + continue; + } + text_out16(x, y1, entries[i].name); + if (entries[i].beh == MB_ONOFF) + text_out16(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF"); + else if (entries[i].beh == MB_RANGE) + text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var); + y1 += 10; + } +} + +int me_process(menu_entry *entries, int count, menu_id id, int is_next) +{ + int i = me_id2offset(entries, count, id); + menu_entry *entry = &entries[i]; + switch (entry->beh) + { + case MB_ONOFF: + *(int *)entry->var ^= entry->mask; + return 1; + case MB_RANGE: + *(int *)entry->var += is_next ? 1 : -1; + if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min; + if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max; + return 1; + default: + return 0; + } +} + + + diff --git a/platform/common/menu.h b/platform/common/menu.h new file mode 100644 index 00000000..1e096ff0 --- /dev/null +++ b/platform/common/menu.h @@ -0,0 +1,98 @@ +// (c) Copyright 2006,2007 notaz, All rights reserved. + + +void menu_init(void); +void text_out16(int x, int y, const char *texto, ...); +void smalltext_out16(int x, int y, const char *texto, int color); +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); + + + +typedef enum +{ + MB_NONE = 1, /* no auto processing */ + MB_ONOFF, /* ON/OFF setting */ + MB_RANGE, /* [min-max] setting */ +} menu_behavior; + +typedef enum +{ + MA_NONE = 1, + MA_MAIN_RESUME_GAME, + MA_MAIN_SAVE_STATE, + MA_MAIN_LOAD_STATE, + MA_MAIN_RESET_GAME, + MA_MAIN_LOAD_ROM, + MA_MAIN_OPTIONS, + MA_MAIN_CONTROLS, + MA_MAIN_CREDITS, + MA_MAIN_PATCHES, + MA_MAIN_EXIT, + MA_OPT_RENDERER, + MA_OPT_SCALING, + MA_OPT_ACC_TIMING, + MA_OPT_ACC_SPRITES, + MA_OPT_SHOW_FPS, + MA_OPT_FRAMESKIP, + MA_OPT_ENABLE_SOUND, + MA_OPT_SOUND_QUALITY, + MA_OPT_ARM940_SOUND, + MA_OPT_6BUTTON_PAD, + MA_OPT_REGION, + MA_OPT_SRAM_STATES, + MA_OPT_CONFIRM_STATES, + MA_OPT_SAVE_SLOT, + MA_OPT_CPU_CLOCKS, + MA_OPT_SCD_OPTS, + MA_OPT_ADV_OPTS, + MA_OPT_SAVECFG, + MA_OPT_SAVECFG_GAME, + MA_OPT_LOADCFG, + MA_OPT2_GAMMA, + MA_OPT2_A_SN_GAMMA, + MA_OPT2_VSYNC, + MA_OPT2_ENABLE_Z80, + MA_OPT2_ENABLE_YM2612, + MA_OPT2_ENABLE_SN76496, + MA_OPT2_GZIP_STATES, + MA_OPT2_NO_LAST_ROM, + MA_OPT2_RAMTIMINGS, + MA_OPT2_SQUIDGEHACK, + MA_OPT2_DONE, + MA_CDOPT_TESTBIOS_USA, + MA_CDOPT_TESTBIOS_EUR, + MA_CDOPT_TESTBIOS_JAP, + MA_CDOPT_LEDS, + MA_CDOPT_CDDA, + MA_CDOPT_PCM, + MA_CDOPT_READAHEAD, + MA_CDOPT_SAVERAM, + MA_CDOPT_SCALEROT_CHIP, + MA_CDOPT_BETTER_SYNC, + MA_CDOPT_DONE, +} menu_id; + +typedef struct +{ + char *name; + menu_behavior beh; + menu_id id; + void *var; /* for on-off settings */ + int mask; + signed char min; /* for ranged integer settings, to be sign-extended */ + signed char max; + char enabled; +} menu_entry; + + +typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param); + +int me_id2offset(const menu_entry *entries, int count, menu_id id); +void me_enable(menu_entry *entries, int count, menu_id id, int enable); +int me_count_enabled(const menu_entry *entries, int count); +menu_id me_index2id(const menu_entry *entries, int count, int index); +void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param); +int me_process(menu_entry *entries, int count, menu_id id, int is_next); + + diff --git a/platform/gp2x/readpng.c b/platform/common/readpng.c similarity index 76% rename from platform/gp2x/readpng.c rename to platform/common/readpng.c index a890e4ed..2a746688 100644 --- a/platform/gp2x/readpng.c +++ b/platform/common/readpng.c @@ -2,6 +2,7 @@ #include #include #include "readpng.h" +#include "lprintf.h" void readpng(void *dest, const char *fname, readpng_what what) { @@ -18,14 +19,14 @@ void readpng(void *dest, const char *fname, readpng_what what) fp = fopen(fname, "rb"); if (fp == NULL) { - printf(__FILE__ ": failed to open: %s\n", fname); + lprintf(__FILE__ ": failed to open: %s\n", fname); return; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { - printf(__FILE__ ": png_create_read_struct() failed\n"); + lprintf(__FILE__ ": png_create_read_struct() failed\n"); fclose(fp); return; } @@ -33,7 +34,7 @@ void readpng(void *dest, const char *fname, readpng_what what) info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - printf(__FILE__ ": png_create_info_struct() failed\n"); + lprintf(__FILE__ ": png_create_info_struct() failed\n"); goto done; } @@ -43,11 +44,11 @@ void readpng(void *dest, const char *fname, readpng_what what) row_ptr = png_get_rows(png_ptr, info_ptr); if (row_ptr == NULL) { - printf(__FILE__ ": png_get_rows() failed\n"); + lprintf(__FILE__ ": png_get_rows() failed\n"); goto done; } - // printf("%s: %ix%i @ %ibpp\n", fname, (int)info_ptr->width, (int)info_ptr->height, info_ptr->pixel_depth); + // lprintf("%s: %ix%i @ %ibpp\n", fname, (int)info_ptr->width, (int)info_ptr->height, info_ptr->pixel_depth); switch (what) { @@ -57,7 +58,7 @@ void readpng(void *dest, const char *fname, readpng_what what) unsigned short *dst = dest; if (info_ptr->pixel_depth != 24) { - printf(__FILE__ ": bg image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": bg image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth); break; } height = info_ptr->height; @@ -85,13 +86,13 @@ void readpng(void *dest, const char *fname, readpng_what what) unsigned char *dst = dest; if (info_ptr->width != 128 || info_ptr->height != 160) { - printf(__FILE__ ": unexpected font image size %ix%i, needed 128x160\n", + lprintf(__FILE__ ": unexpected font image size %ix%i, needed 128x160\n", (int)info_ptr->width, (int)info_ptr->height); break; } if (info_ptr->pixel_depth != 8) { - printf(__FILE__ ": font image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": font image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth); break; } for (y = 0; y < 16; y++) @@ -115,13 +116,13 @@ void readpng(void *dest, const char *fname, readpng_what what) unsigned char *dst = dest; if (info_ptr->width != 8 || info_ptr->height != 10) { - printf(__FILE__ ": unexpected selector image size %ix%i, needed 8x10\n", + lprintf(__FILE__ ": unexpected selector image size %ix%i, needed 8x10\n", (int)info_ptr->width, (int)info_ptr->height); break; } if (info_ptr->pixel_depth != 8) { - printf(__FILE__ ": selector image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": selector image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth); break; } for (y1 = 0; y1 < 10; y1++) diff --git a/platform/gp2x/readpng.h b/platform/common/readpng.h similarity index 100% rename from platform/gp2x/readpng.h rename to platform/common/readpng.h diff --git a/platform/gizmondo/Makefile b/platform/gizmondo/Makefile new file mode 100644 index 00000000..1824fe14 --- /dev/null +++ b/platform/gizmondo/Makefile @@ -0,0 +1,173 @@ + +# you may or may not need to change this +CROSS = /opt/cegcc/arm-wince-cegcc/bin/ + +# settings +asm_memory = 1 +asm_render = 1 +asm_ym2612 = 1 +asm_misc = 1 +asm_cdpico = 1 +asm_cdmemory = 1 +amalgamate = 0 +#profile = 1 + + + +DEFINC = -I../.. -I. -D__GIZ__ -D_UNZIP_SUPPORT +COPT_COMMON = -static -Wall -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math +ifeq "$(profile)" "1" +COPT_COMMON += -fprofile-generate +endif +ifeq "$(profile)" "2" +COPT_COMMON += -fprofile-use +endif +COPT = $(COPT_COMMON) -mtune=arm920t +ASFLAGS = -mcpu=arm920t -mfloat-abi=soft +GCC = $(CROSS)gcc +STRIP = $(CROSS)strip +AS = $(CROSS)as +LD = $(CROSS)ld + +# frontend +OBJS += main.o menu.o giz.o emu.o + +# common +OBJS += ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o + +# Pico +ifeq "$(amalgamate)" "1" +OBJS += ../../PicoAll.o +else +OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Memory.o ../../Pico/Misc.o \ + ../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o \ + ../../Pico/Patch.o +# Pico - CD +OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ + ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \ + ../../Pico/cd/Area.o ../../Pico/cd/Misc.o ../../Pico/cd/pcm.o ../../Pico/cd/buffering.o +endif + +# asm stuff +ifeq "$(asm_render)" "1" +DEFINC += -D_ASM_DRAW_C +OBJS += ../../Pico/draw_asm.o ../../Pico/draw2_asm.o +endif +ifeq "$(asm_memory)" "1" +DEFINC += -D_ASM_MEMORY_C +OBJS += ../../Pico/memory_asm.o +endif +ifeq "$(asm_ym2612)" "1" +DEFINC += -D_ASM_YM2612_C +OBJS += ../../Pico/sound/ym2612_asm.o +endif +ifeq "$(asm_misc)" "1" +DEFINC += -D_ASM_MISC_C +OBJS += ../../Pico/misc_asm.o +OBJS += ../../Pico/cd/misc_asm.o +endif +ifeq "$(asm_cdpico)" "1" +DEFINC += -D_ASM_CD_PICO_C +OBJS += ../../Pico/cd/pico_asm.o +endif +ifeq "$(asm_cdmemory)" "1" +DEFINC += -D_ASM_CD_MEMORY_C +OBJS += ../../Pico/cd/memory_asm.o +endif + +# Pico - sound +ifneq "$(amalgamate)" "1" +OBJS += ../../Pico/sound/sound.o +endif +OBJS += ../../Pico/sound/mix_asm.o +OBJS += ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o +# zlib +OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \ + ../../zlib/deflate.o ../../zlib/crc32.o ../../zlib/adler32.o ../../zlib/zutil.o ../../zlib/compress.o +# unzip +OBJS += ../../unzip/unzip.o ../../unzip/unzip_stream.o +# mp3 +OBJS += mp3.o +# CPU cores +# Cyclone +DEFINC += -DEMU_C68K +OBJS += ../../cpu/Cyclone/proj/Cyclone.o +# drz80 +DEFINC += -D_USE_DRZ80 +OBJS += ../../cpu/DrZ80/drz80.o + + +all: PicoDrive.exe + +PicoDrive.exe : $(OBJS) + @echo $@ + @$(GCC) -o $@ $(COPT) $^ -lm -lpng -Lkgsdk/ -lKGSDK -Wl,-Map=PicoDrive.map +ifeq ($(DEBUG),) + @$(STRIP) $@ +endif + + +.c.o: + @echo $< + @$(GCC) $(COPT) $(DEFINC) -c $< -o $@ +#.s.o: +# @echo $< +# $(GCC) $(COPT) $(DEFINC) -c $< -o $@ + +../../Pico/draw_asm.o : ../../Pico/Draw.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/draw2_asm.o : ../../Pico/Draw2.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/memory_asm.o : ../../Pico/Memory.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/sound/ym2612_asm.o : ../../Pico/sound/ym2612.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/sound/mix_asm.o : ../../Pico/sound/mix.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/misc_asm.o : ../../Pico/misc.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/cd/pico_asm.o : ../../Pico/cd/Pico.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/cd/memory_asm.o : ../../Pico/cd/Memory.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ +../../Pico/cd/misc_asm.o : ../../Pico/cd/misc.s + @echo $< + @$(AS) $(ASFLAGS) $< -o $@ + +# build Cyclone +../../cpu/Cyclone/proj/Cyclone.s : + @echo building Cyclone... + @make -C ../../cpu/Cyclone/proj CONFIG_FILE=config_pico.h + + + +# cleanup +clean: tidy + @$(RM) PicoDrive.exe +tidy: + @$(RM) $(OBJS) + + +clean_prof: + find ../.. -name '*.gcno' -delete + find ../.. -name '*.gcda' -delete + +# ----------- release ----------- +ifneq ($(findstring rel,$(MAKECMDGOALS)),) +ifeq ($(VER),) +$(error need VER) +endif +endif + +rel: PicoDrive.exe kgsdk/ARMV4IRel/KGSDK.dll ../readme.txt config.txt + zip -9 -j ../../PicoDrive_$(VER).zip $^ + zip -9 -r ../../PicoDrive_$(VER).zip skin -i \*.png -i \*.txt + diff --git a/platform/gizmondo/emu.c b/platform/gizmondo/emu.c new file mode 100644 index 00000000..3d5fae75 --- /dev/null +++ b/platform/gizmondo/emu.c @@ -0,0 +1,33 @@ +#include + +#include "emu.h" + +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; +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(char **bios_file){} +int find_bios(int region, char **bios_file){} +void scaling_update(void){} + diff --git a/platform/gizmondo/emu.h b/platform/gizmondo/emu.h new file mode 100644 index 00000000..e9b58c9c --- /dev/null +++ b/platform/gizmondo/emu.h @@ -0,0 +1,59 @@ +// (c) Copyright 2006-2007 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + + + +// engine states +enum TPicoGameState { + PGS_Paused = 1, + PGS_Running, + PGS_Quit, + PGS_KeyConfig, + PGS_ReloadRom, + PGS_Menu, + PGS_RestartRun, +}; + +typedef struct { + char lastRomFile[512]; + int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves, + // , no_save_cfg_on_exit, , 16_bit_mode + // , confirm_save, show_cd_leds, confirm_load + // , + int PicoOpt; // used for config saving only, see Pico.h + int PsndRate; // ditto + int PicoRegion; // ditto + int Frameskip; + int CPUclock; // unused, placeholder for config compatibility + int KeyBinds[32]; + int volume; + int gamma; // unused + int JoyBinds[4][32]; // unused + int PicoAutoRgnOrder; + int PicoCDBuffers; + int scaling; // unused +} currentConfig_t; + +extern char romFileName[]; +extern int engineState; +extern currentConfig_t currentConfig; + + +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(char **bios_file); +int find_bios(int region, char **bios_file); +void scaling_update(void); + diff --git a/platform/gizmondo/giz.c b/platform/gizmondo/giz.c new file mode 100644 index 00000000..16bad7aa --- /dev/null +++ b/platform/gizmondo/giz.c @@ -0,0 +1,72 @@ +#include +#include +#include + +#include "giz.h" +#include "kgsdk/Framework.h" +#include "kgsdk/Framework2D.h" + +#define LOG_FILE "log.log" + +void *giz_screen = NULL; +static FILE *logf = NULL; + +void lprintf_al(const char *fmt, ...) +{ + va_list vl; + + if (logf == NULL) + { + logf = fopen(LOG_FILE, "w"); + if (logf == NULL) + return; + } + + //if (strchr(fmt, '\n')) + // fprintf(logf, "%lu: ", GetTickCount()); + va_start(vl, fmt); + vfprintf(logf, fmt, vl); + va_end(vl); + fflush(logf); +} + +static void giz_log_close(void) +{ + if (logf != NULL) + { + fclose(logf); + logf = NULL; + } +} + +void giz_init(HINSTANCE hInstance, HINSTANCE hPrevInstance) +{ + int ret; + + giz_screen = NULL; + + lprintf("PicoDrive v" VERSION " (c) notaz, 2006,2007\n"); + lprintf("%s %s\n\n", __DATE__, __TIME__); + + ret = Framework_Init(hInstance, hPrevInstance); + if (!ret) + { + lprintf_al("Framework_Init() failed\n"); + exit(1); + } + ret = Framework2D_Init(); + if (!ret) + { + lprintf_al("Framework2D_Init() failed\n"); + exit(1); + } +} + +void giz_deinit(void) +{ + Framework2D_Close(); + Framework_Close(); + + giz_log_close(); +} + diff --git a/platform/gizmondo/giz.h b/platform/gizmondo/giz.h new file mode 100644 index 00000000..478f6021 --- /dev/null +++ b/platform/gizmondo/giz.h @@ -0,0 +1,22 @@ +extern void *giz_screen; + +void giz_init(); +void giz_deinit(void); +void lprintf_al(const char *fmt, ...); + +#define lprintf lprintf_al + +// button mappings, include kgsdk/Framework.h to use +#define BTN_LEFT (1 << FRAMEWORK_BUTTON_DPAD_LEFT) +#define BTN_RIGHT (1 << FRAMEWORK_BUTTON_DPAD_RIGHT) +#define BTN_UP (1 << FRAMEWORK_BUTTON_DPAD_UP) +#define BTN_DOWN (1 << FRAMEWORK_BUTTON_DPAD_DOWN) +#define BTN_STOP (1 << FRAMEWORK_BUTTON_STOP) +#define BTN_PLAY (1 << FRAMEWORK_BUTTON_PLAY) +#define BTN_FWD (1 << FRAMEWORK_BUTTON_FORWARD) +#define BTN_REW (1 << FRAMEWORK_BUTTON_REWIND) +#define BTN_L (1 << FRAMEWORK_BUTTON_LEFT_SHOULDER) +#define BTN_R (1 << FRAMEWORK_BUTTON_RIGHT_SHOULDER) +#define BTN_HOME (1 << FRAMEWORK_BUTTON_HOME) + + diff --git a/platform/gizmondo/main.c b/platform/gizmondo/main.c new file mode 100644 index 00000000..21216b78 --- /dev/null +++ b/platform/gizmondo/main.c @@ -0,0 +1,63 @@ +// (c) Copyright 2006 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + +#include + +#include "giz.h" +#include "menu.h" +#include "../common/menu.h" +#include "emu.h" +#include "version.h" + + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +{ + emu_ReadConfig(0, 0); + giz_init(hInstance, hPrevInstance); + emu_Init(); + menu_init(); + + engineState = PGS_Menu; + + for (;;) + { + switch (engineState) + { + case PGS_Menu: + menu_loop(); + break; + + case PGS_ReloadRom: + if (emu_ReloadRom()) + engineState = PGS_Running; + else { + lprintf("PGS_ReloadRom == 0\n"); + engineState = PGS_Menu; + } + break; + + case PGS_RestartRun: + engineState = PGS_Running; + + case PGS_Running: + emu_Loop(); + break; + + case PGS_Quit: + goto endloop; + + default: + lprintf("engine got into unknown state (%i), exitting\n", engineState); + goto endloop; + } + } + + endloop: + + emu_Deinit(); + giz_deinit(); + + return 0; +} diff --git a/platform/gizmondo/menu.c b/platform/gizmondo/menu.c new file mode 100644 index 00000000..c4ecd0b5 --- /dev/null +++ b/platform/gizmondo/menu.c @@ -0,0 +1,1532 @@ +// (c) Copyright 2006,2007 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + +// don't like to use loads of #ifdefs, so duplicating GP2X code +// horribly instead + +#include +#include +#include +#include // for getcwd cegcc implementation +#include + +#include "giz.h" +#include "emu.h" +#include "menu.h" +#include "../common/arm_utils.h" +#include "../common/menu.h" +#include "../common/readpng.h" +#include "version.h" +#include "kgsdk/Framework.h" +#include "kgsdk/Framework2D.h" + +#include +#include +#include + +extern char romFileName[MAX_PATH]; +extern char *rom_data; +extern int state_slot; +extern int config_slot, config_slot_current; + +#define gizKeyUnkn "???" +static const char * const gizKeyNames[] = { + "LEFT", "RIGHT", "UP", "DOWN", "STOP", "PLAY", "FORWARD", "REWIND", + "LEFT_SHOULDER", "RIGHT_SHOULDER", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn, + gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, + gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, +}; + +static unsigned char bg_buffer[321*240*2]; +char menuErrorMsg[40] = {0, }; + +static void menu_darken_bg(void *dst, const void *src, int pixels, int darker); +static void menu_prepare_bg(int use_game_bg); + +static unsigned int inp_prev = 0; +static int inp_prevjoy = 0; + +static unsigned long wait_for_input(unsigned int interesting) +{ + unsigned int ret; + static int repeats = 0, wait = 50; + int release = 0, i; + + if (repeats == 2 || repeats == 4) wait /= 2; + if (repeats == 6) wait = 15; + + for (i = 0; i < 6 && inp_prev == Framework_PollGetButtons(); i++) { + if (i == 0) repeats++; + Sleep(wait); + } + + while ( !((ret = Framework_PollGetButtons()) & interesting) ) { + Sleep(50); + release = 1; + } + + if (release || ret != inp_prev) { + repeats = 0; + wait = 50; + } + inp_prev = ret; + inp_prevjoy = 0; + + // we don't need diagonals in menus + if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; + if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; + if ((ret&BTN_DOWN) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; + if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; + + return ret; +} + + +static void menu_draw_begin(int use_bgbuff) +{ + if (giz_screen == NULL) + { + Framework2D_WaitVSync(); + giz_screen = Framework2D_LockBuffer(); + } + else + { + lprintf("%s: screen was not NULL\n", __FUNCTION__); + } + memcpy32(giz_screen, (int *)bg_buffer, 321*240*2/4); +} + + +static void menu_draw_end(void) +{ + Framework2D_UnlockBuffer(); + giz_screen = NULL; +} + + +// --------- loading ROM screen ---------- + +static void load_progress_cb(int percent) +{ + int ln, len = percent * 320 / 100; + unsigned short *dst; + + menu_draw_begin(0); + dst = (unsigned short *)giz_screen + 321*20; + + if (len > 320) len = 320; + for (ln = 10; ln > 0; ln--, dst += 320) + memset(dst, 0xff, len*2); + menu_draw_end(); +} + +void menu_romload_prepare(const char *rom_name) +{ + const char *p = rom_name + strlen(rom_name); + while (p > rom_name && *p != '/') p--; + + if (rom_data == NULL) + memset(giz_screen, 0, 321*240*2); + menu_draw_begin(1); + + smalltext_out16(1, 1, "Loading", 0xffff); + smalltext_out16_lim(1, 10, p, 0xffff, 53); + menu_draw_end(); + PicoCartLoadProgressCB = load_progress_cb; +} + +void menu_romload_end(void) +{ + PicoCartLoadProgressCB = NULL; + menu_draw_begin(0); + smalltext_out16(1, 30, "Starting emulation...", 0xffff); + menu_draw_end(); +} + +// -------------- ROM selector -------------- + +// rrrr rggg gggb bbbb +#if 0 +static unsigned short file2color(const char *fname) +{ + const char *ext = fname + strlen(fname) - 3; + static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso" }; + static const char *other_exts[] = { "gmv", "pat" }; + int i; + + if (ext < fname) ext = fname; + for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++) + if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; + for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++) + if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5; + return 0xffff; +} + +static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) +{ + int start, i, pos; + + start = 12 - sel; + n--; // exclude current dir (".") + + menu_draw_begin(1); + + if (rom_data == NULL) { + menu_darken_bg(giz_screen, giz_screen, 321*240, 0); + } + + menu_darken_bg((char *)giz_screen + 321*120*2, (char *)giz_screen + 321*120*2, 321*8, 0); + + if(start - 2 >= 0) + smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2); + for (i = 0; i < n; i++) { + pos = start + i; + if (pos < 0) continue; + if (pos > 23) break; + if (namelist[i+1]->d_type == DT_DIR) { + smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1); + smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3); + } else { + unsigned short color = file2color(namelist[i+1]->d_name); + smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2); + } + } + text_out16(5, 120, ">"); + menu_draw_end(); +} + +static int scandir_cmp(const void *p1, const void *p2) +{ + struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2; + if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2); + if ((*d1)->d_type == DT_DIR) return -1; // put before + if ((*d2)->d_type == DT_DIR) return 1; + return alphasort(d1, d2); +} + +static char *filter_exts[] = { + ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html", + ".jpg", ".gpe", ".cue" +}; + +static int scandir_filter(const struct dirent *ent) +{ + const char *p; + int i; + + if (ent == NULL || ent->d_name == NULL) return 0; + if (strlen(ent->d_name) < 5) return 1; + + p = ent->d_name + strlen(ent->d_name) - 4; + + for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++) + { + if (strcmp(p, filter_exts[i]) == 0) return 0; + } + + return 1; +} + +static char *romsel_loop(char *curr_path) +{ + struct dirent **namelist; + DIR *dir; + int n, sel = 0; + unsigned long inp = 0; + char *ret = NULL, *fname = NULL; + + // is this a dir or a full path? + if ((dir = opendir(curr_path))) { + closedir(dir); + } else { + char *p; + for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--); + *p = 0; + fname = p+1; + } + + n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp); + if (n < 0) { + // try root + n = scandir("/", &namelist, scandir_filter, scandir_cmp); + if (n < 0) { + // oops, we failed + lprintf("dir: "); lprintf(curr_path); lprintf("\n"); + perror("scandir"); + return NULL; + } + } + + // try to find sel + if (fname != NULL) { + int i; + for (i = 1; i < n; i++) { + if (strcmp(namelist[i]->d_name, fname) == 0) { + sel = i - 1; + break; + } + } + } + + for (;;) + { + draw_dirlist(curr_path, namelist, n, sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP); + if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; } + if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; } + if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } + if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; } + if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } + if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; } + if(inp & BTN_PLAY) { // enter dir/select + again: + if (namelist[sel+1]->d_type == DT_REG) { + strcpy(romFileName, curr_path); + strcat(romFileName, "/"); + strcat(romFileName, namelist[sel+1]->d_name); + ret = romFileName; + break; + } else if (namelist[sel+1]->d_type == DT_DIR) { + int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; + char *p, *newdir = malloc(newlen); + if (strcmp(namelist[sel+1]->d_name, "..") == 0) { + char *start = curr_path; + p = start + strlen(start) - 1; + while (*p == '/' && p > start) p--; + while (*p != '/' && p > start) p--; + if (p <= start) strcpy(newdir, "/"); + else { strncpy(newdir, start, p-start); newdir[p-start] = 0; } + } else { + strcpy(newdir, curr_path); + p = newdir + strlen(newdir) - 1; + while (*p == '/' && p >= newdir) *p-- = 0; + strcat(newdir, "/"); + strcat(newdir, namelist[sel+1]->d_name); + } + ret = romsel_loop(newdir); + free(newdir); + break; + } else { + // unknown file type, happens on NTFS mounts. Try to guess. + FILE *tstf; int tmp; + strcpy(romFileName, curr_path); + strcat(romFileName, "/"); + strcat(romFileName, namelist[sel+1]->d_name); + tstf = fopen(romFileName, "rb"); + if (tstf != NULL) + { + if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0) + namelist[sel+1]->d_type = DT_REG; + else namelist[sel+1]->d_type = DT_DIR; + fclose(tstf); + goto again; + } + } + } + if(inp & BTN_STOP) break; // cancel + } + + if (n > 0) { + while(n--) free(namelist[n]); + free(namelist); + } + + return ret; +} +#endif +static char *romsel_loop(char *curr_path) +{ + return NULL; +} + +// ------------ patch/gg menu ------------ + +static void draw_patchlist(int sel) +{ + int start, i, pos, active; + + start = 12 - sel; + + menu_draw_begin(1); + + for (i = 0; i < PicoPatchCount; i++) { + pos = start + i; + if (pos < 0) continue; + if (pos > 23) break; + active = PicoPatches[i].active; + smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3); + smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6); + } + pos = start + i; + if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4); + + text_out16(5, 120, ">"); + menu_draw_end(); +} + + +static void patches_menu_loop(void) +{ + int menu_sel = 0; + unsigned long inp = 0; + + for(;;) + { + draw_patchlist(menu_sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP); + if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; } + if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; } + if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; } + if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; } + if(inp & BTN_PLAY) { // action + if (menu_sel < PicoPatchCount) + PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active; + else return; + } + if(inp & BTN_STOP) return; + } + +} + +// ------------ savestate loader ------------ + +static int state_slot_flags = 0; + +static void state_check_slots(void) +{ + int slot; + + state_slot_flags = 0; + + for (slot = 0; slot < 10; slot++) + { + if (emu_check_save_file(slot)) + { + state_slot_flags |= 1 << slot; + } + } +} + +static void draw_savestate_bg(int slot) +{ + struct PicoVideo tmp_pv; + unsigned short tmp_cram[0x40]; + unsigned short tmp_vsram[0x40]; + void *tmp_vram, *file; + char *fname; + + fname = emu_GetSaveFName(1, 0, slot); + if (!fname) return; + + tmp_vram = malloc(sizeof(Pico.vram)); + if (tmp_vram == NULL) return; + + memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram)); + memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram)); + memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram)); + memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video)); + + if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { + file = gzopen(fname, "rb"); + emu_set_save_cbs(1); + } else { + file = fopen(fname, "rb"); + emu_set_save_cbs(0); + } + + if (file) { + if (PicoMCD & 1) { + PicoCdLoadStateGfx(file); + } else { + areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file + areaRead(Pico.vram, 1, sizeof(Pico.vram), file); + areaSeek(file, 0x2000, SEEK_CUR); + areaRead(Pico.cram, 1, sizeof(Pico.cram), file); + areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file); + areaSeek(file, 0x221a0, SEEK_SET); + areaRead(&Pico.video, 1, sizeof(Pico.video), file); + } + areaClose(file); + } + + emu_forced_frame(); + menu_prepare_bg(1); + + memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram)); + memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram)); + memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram)); + memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video)); + free(tmp_vram); +} + +static void draw_savestate_menu(int menu_sel, int is_loading) +{ + int tl_x = 25, tl_y = 60, y, i; + + if (state_slot_flags & (1 << menu_sel)) + draw_savestate_bg(menu_sel); + menu_draw_begin(1); + + text_out16(tl_x, 30, is_loading ? "Load state" : "Save state"); + + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108); + + /* draw all 10 slots */ + y = tl_y; + for (i = 0; i < 10; i++, y+=10) + { + text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free"); + } + text_out16(tl_x, y, "back"); + + menu_draw_end(); +} + +static int savestate_menu_loop(int is_loading) +{ + static int menu_sel = 10; + int menu_sel_max = 10; + unsigned long inp = 0; + + state_check_slots(); + + for(;;) + { + draw_savestate_menu(menu_sel, is_loading); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP); + if(inp & BTN_UP ) { + do { + menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; + } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); + } + if(inp & BTN_DOWN) { + do { + menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; + } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); + } + if(inp & BTN_PLAY) { // save/load + if (menu_sel < 10) { + state_slot = menu_sel; + if (emu_SaveLoadGame(is_loading, 0)) { + strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed"); + return 1; + } + return 0; + } else return 1; + } + if(inp & BTN_STOP) return 1; + } +} + +// -------------- key config -------------- + +static char *action_binds(int player_idx, int action_mask) +{ + static char strkeys[32*5]; + int i; + + strkeys[0] = 0; + for (i = 0; i < 32; i++) // i is key index + { + if (currentConfig.KeyBinds[i] & action_mask) + { + if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue; + if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gizKeyNames[i]); break; } + else strcpy(strkeys, gizKeyNames[i]); + } + } + + return strkeys; +} + +static void unbind_action(int action) +{ + int i; + + for (i = 0; i < 32; i++) + currentConfig.KeyBinds[i] &= ~action; +} + +static int count_bound_keys(int action) +{ + int i, keys = 0; + + for (i = 0; i < 32; i++) + if (currentConfig.KeyBinds[i] & action) keys++; + + return keys; +} + +typedef struct { char *name; int mask; } bind_action_t; + +static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel) +{ + int x, y, tl_y = 40, i; + + menu_draw_begin(1); + if (player_idx >= 0) { + text_out16(80, 20, "Player %i controls", player_idx + 1); + x = 100; + } else { + text_out16(80, 20, "Emulator controls"); + x = 40; + } + + menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130); + + y = tl_y; + for (i = 0; i < opt_cnt; i++, y+=10) + text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask)); + + text_out16(x, y, "Done"); + + if (sel < opt_cnt) { + text_out16(30, 180, "Press a button to bind/unbind"); + text_out16(30, 190, "Use SELECT to clear"); + text_out16(30, 200, "To bind UP/DOWN, hold SELECT"); + text_out16(30, 210, "Select \"Done\" to exit"); + } else { + text_out16(30, 190, "Use Options -> Save cfg"); + text_out16(30, 200, "to save controls"); + text_out16(30, 210, "Press B or X to exit"); + } + menu_draw_end(); +} + +static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx) +{ + int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i; + unsigned long inp = 0; + + for (;;) + { + draw_key_config(opts, opt_cnt, player_idx, sel); + inp = wait_for_input(CONFIGURABLE_KEYS); + if (!(inp & BTN_HOME)) { + prev_select = 0; + if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; } + if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; } + } + if (sel >= opt_cnt) { + if (inp & (BTN_PLAY|BTN_STOP)) break; + else continue; + } + // if we are here, we want to bind/unbind something + if ((inp & BTN_HOME) && !prev_select) + unbind_action(opts[sel].mask); + prev_select = inp & BTN_HOME; + inp &= CONFIGURABLE_KEYS; + inp &= ~BTN_HOME; + for (i = 0; i < 32; i++) + if (inp & (1 << i)) { + if (count_bound_keys(opts[sel].mask) >= 2) + currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only + else currentConfig.KeyBinds[i] ^= opts[sel].mask; + if (player_idx >= 0) { + currentConfig.KeyBinds[i] &= ~(3 << 16); + currentConfig.KeyBinds[i] |= player_idx << 16; + } + } + } +} + +static void draw_kc_sel(int menu_sel) +{ + int tl_x = 25+40, tl_y = 60, y; + + y = tl_y; + menu_draw_begin(1); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138); + + text_out16(tl_x, y, "Player 1"); + text_out16(tl_x, (y+=10), "Player 2"); + text_out16(tl_x, (y+=10), "Emulator controls"); + text_out16(tl_x, (y+=10), "Done"); + + menu_draw_end(); +} + + +// PicoPad[] format: MXYZ SACB RLDU +static bind_action_t ctrl_actions[] = +{ + { "UP ", 0x001 }, + { "DOWN ", 0x002 }, + { "LEFT ", 0x004 }, + { "RIGHT ", 0x008 }, + { "A ", 0x040 }, + { "B ", 0x010 }, + { "C ", 0x020 }, + { "START ", 0x080 }, + { "MODE ", 0x800 }, + { "X ", 0x400 }, + { "Y ", 0x200 }, + { "Z ", 0x100 }, +}; + +// player2_flag, ?, ?, ?, ?, ?, ?, menu +// "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE", +// "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE" +static bind_action_t emuctrl_actions[] = +{ + { "Load State ", 1<<28 }, + { "Save State ", 1<<27 }, + { "Prev Save Slot ", 1<<25 }, + { "Next Save Slot ", 1<<24 }, + { "Switch Renderer", 1<<26 }, + { "Volume Down ", 1<<30 }, + { "Volume Up ", 1<<29 }, + { "Enter Menu ", 1<<23 }, +}; + +static void kc_sel_loop(void) +{ + int menu_sel = 3, menu_sel_max = 3; + unsigned long inp = 0; + int is_6button = currentConfig.PicoOpt & 0x020; + + while (1) + { + draw_kc_sel(menu_sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP); + if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if (inp & BTN_PLAY) { + switch (menu_sel) { + case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return; + case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return; + case 2: key_config_loop(emuctrl_actions, + sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return; + case 3: if (rom_data == NULL) emu_WriteConfig(0); return; + default: return; + } + } + if (inp & BTN_STOP) return; + } +} + + +// --------- sega/mega cd options ---------- + +menu_entry cdopt_entries[] = +{ + { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 }, + { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 }, + { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 }, + { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 }, + { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 }, + { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 }, + { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 }, + { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 }, + { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 }, + { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 }, + { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 }, +}; + +#define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0])) + + +struct bios_names_t +{ + char us[32], eu[32], jp[32]; +}; + +static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param) +{ + struct bios_names_t *bios_names = param; + char ra_buff[16]; + + switch (entry->id) + { + case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break; + case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break; + case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break; + case MA_CDOPT_READAHEAD: + if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2); + else strcpy(ra_buff, " OFF"); + text_out16(x, y, "ReadAhead buffer %s", ra_buff); + break; + default:break; + } +} + +static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names) +{ + int tl_x = 25, tl_y = 60; + menu_id selected_id; + char ra_buff[16]; + + if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2); + else strcpy(ra_buff, " OFF"); + + menu_draw_begin(1); + + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246); + + me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names); + + selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel); + if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) || + (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) || + (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND"))) + text_out16(tl_x, 210, "Press start to test selected BIOS"); + + menu_draw_end(); +} + +static void cd_menu_loop_options(void) +{ + static int menu_sel = 0; + int menu_sel_max = 10; + unsigned long inp = 0; + struct bios_names_t bios_names; + menu_id selected_id; + char *bios, *p; + + if (find_bios(4, &bios)) { // US + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0; + } else strcpy(bios_names.us, "NOT FOUND"); + + if (find_bios(8, &bios)) { // EU + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0; + } else strcpy(bios_names.eu, "NOT FOUND"); + + if (find_bios(1, &bios)) { // JP + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0; + } else strcpy(bios_names.jp, "NOT FOUND"); + + for(;;) + { + draw_cd_menu_options(menu_sel, &bios_names); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW); + if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel); + if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise + if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) && + selected_id == MA_CDOPT_READAHEAD) { + if (inp & BTN_LEFT) { + PicoCDBuffers >>= 1; + if (PicoCDBuffers < 64) PicoCDBuffers = 0; + } else { + if (PicoCDBuffers < 64) PicoCDBuffers = 64; + else PicoCDBuffers <<= 1; + if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M + } + } + } + if (inp & BTN_PLAY) { // toggleable options + if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) && + selected_id == MA_CDOPT_DONE) { + return; + } + switch (selected_id) { // BIOS testers + case MA_CDOPT_TESTBIOS_USA: + if (find_bios(4, &bios)) { // test US + strcpy(romFileName, bios); + engineState = PGS_ReloadRom; + return; + } + break; + case MA_CDOPT_TESTBIOS_EUR: + if (find_bios(8, &bios)) { // test EU + strcpy(romFileName, bios); + engineState = PGS_ReloadRom; + return; + } + break; + case MA_CDOPT_TESTBIOS_JAP: + if (find_bios(1, &bios)) { // test JP + strcpy(romFileName, bios); + engineState = PGS_ReloadRom; + return; + } + break; + default: + break; + } + } + if (inp & (BTN_STOP|BTN_REW)) return; + } +} + + +// --------- advanced options ---------- + +menu_entry opt2_entries[] = +{ + { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 }, + { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 }, + { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 }, + { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 }, + { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 }, + { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 }, +}; + +#define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0])) + + +static void draw_amenu_options(int menu_sel) +{ + int tl_x = 25, tl_y = 50; + + menu_draw_begin(1); + + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252); + + me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, NULL, NULL); + + menu_draw_end(); +} + +static void amenu_loop_options(void) +{ + static int menu_sel = 0; + int menu_sel_max; + unsigned long inp = 0; + menu_id selected_id; + + menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1; + + for(;;) + { + draw_amenu_options(menu_sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW); + if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel); + if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise + if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) && + selected_id == MA_OPT2_GAMMA) { + while ((inp = Framework_PollGetButtons(1)) & (BTN_LEFT|BTN_RIGHT)) { + currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1; + if (currentConfig.gamma < 1) currentConfig.gamma = 1; + if (currentConfig.gamma > 300) currentConfig.gamma = 300; + draw_amenu_options(menu_sel); + Sleep(18); + } + } + } + if (inp & BTN_PLAY) { // toggleable options + if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) && + selected_id == MA_OPT2_DONE) { + return; + } + } + if (inp & (BTN_STOP|BTN_REW)) return; + } +} + +// -------------- options -------------- + + +menu_entry opt_entries[] = +{ + { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 }, + { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x001, 0, 3, 1 }, + { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, ¤tConfig.PicoOpt, 0x040, 0, 0, 1 }, + { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, ¤tConfig.PicoOpt, 0x080, 0, 0, 1 }, + { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x002, 0, 0, 1 }, + { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 }, + { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x004, 0, 0, 1 }, + { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 }, + { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, ¤tConfig.PicoOpt, 0x020, 0, 0, 1 }, + { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 }, + { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x001, 0, 0, 1 }, + { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 }, + { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 }, + { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 }, + { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 }, + { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 }, + { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 }, + { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 }, +}; + +#define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0])) + + +static const char *region_name(unsigned int code) +{ + static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" }; + static const char *names_short[] = { "", " JP", " JP", " US", " EU" }; + int u, i = 0; + if (code) { + code <<= 1; + while((code >>= 1)) i++; + if (i > 4) return "unknown"; + return names[i]; + } else { + static char name[24]; + strcpy(name, "Auto:"); + for (u = 0; u < 3; u++) { + i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1; + while((code >>= 1)) i++; + strcat(name, names_short[i]); + } + return name; + } +} + + +static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param) +{ + char *str, str24[24]; + + switch (entry->id) + { + case MA_OPT_RENDERER: + if (currentConfig.PicoOpt&0x10) + str = " 8bit fast"; + else if (currentConfig.EmuOpt&0x80) + str = "16bit accurate"; + else + str = " 8bit accurate"; + text_out16(x, y, "Renderer: %s", str); + break; + case MA_OPT_FRAMESKIP: + if (currentConfig.Frameskip < 0) + strcpy(str24, "Auto"); + else sprintf(str24, "%i", currentConfig.Frameskip); + text_out16(x, y, "Frameskip %s", str24); + break; + case MA_OPT_SOUND_QUALITY: + str = (currentConfig.PicoOpt&0x08)?"stereo":"mono"; + text_out16(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str); + break; + case MA_OPT_REGION: + text_out16(x, y, "Region: %s", region_name(currentConfig.PicoRegion)); + break; + case MA_OPT_CONFIRM_STATES: + switch ((currentConfig.EmuOpt >> 9) & 5) { + default: str = "OFF"; break; + case 1: str = "writes"; break; + case 4: str = "loads"; break; + case 5: str = "both"; break; + } + text_out16(x, y, "Confirm savestate %s", str); + break; + case MA_OPT_SAVECFG: + str24[0] = 0; + if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot); + text_out16(x, y, "Save cfg as default%s", str24); + break; + case MA_OPT_LOADCFG: + text_out16(x, y, "Load cfg from profile %i", config_slot); + break; + default: + lprintf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id); + break; + } +} + + + +static void draw_menu_options(int menu_sel) +{ + int tl_x = 25, tl_y = 24; + + menu_draw_begin(1); + + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284); + + me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL); + + menu_draw_end(); +} + +static int sndrate_prevnext(int rate, int dir) +{ + int i, rates[] = { 8000, 11025, 16000, 22050, 44100 }; + + for (i = 0; i < 5; i++) + if (rates[i] == rate) break; + + i += dir ? 1 : -1; + if (i > 4) return dir ? 44100 : 22050; + if (i < 0) return dir ? 11025 : 8000; + return rates[i]; +} + +static void region_prevnext(int right) +{ + // jp_ntsc=1, jp_pal=2, usa=4, eu=8 + static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 }; + int i; + if (right) { + if (!currentConfig.PicoRegion) { + for (i = 0; i < 6; i++) + if (rgn_orders[i] == PicoAutoRgnOrder) break; + if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1]; + else currentConfig.PicoRegion=1; + } + else currentConfig.PicoRegion<<=1; + if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8; + } else { + if (!currentConfig.PicoRegion) { + for (i = 0; i < 6; i++) + if (rgn_orders[i] == PicoAutoRgnOrder) break; + if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1]; + } + else currentConfig.PicoRegion>>=1; + } +} + +static void menu_options_save(void) +{ + PicoOpt = currentConfig.PicoOpt; + PsndRate = currentConfig.PsndRate; + PicoRegionOverride = currentConfig.PicoRegion; + if (!(PicoOpt & 0x20)) { + // unbind XYZ MODE, just in case + unbind_action(0xf00); + } + scaling_update(); +} + +static int menu_loop_options(void) +{ + static int menu_sel = 0; + int menu_sel_max, ret; + unsigned long inp = 0; + menu_id selected_id; + + currentConfig.PicoOpt = PicoOpt; + currentConfig.PsndRate = PsndRate; + currentConfig.PicoRegion = PicoRegionOverride; + + me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL); + me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current); + menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1; + if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; + + while (1) + { + draw_menu_options(menu_sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW); + if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel); + if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise + if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) { + switch (selected_id) { + case MA_OPT_RENDERER: + if (inp & BTN_LEFT) { + if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10; + else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80; + else if ( currentConfig.EmuOpt &0x80) break; + } else { + if ( currentConfig.PicoOpt&0x10) break; + else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10; + else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80; + } + break; + case MA_OPT_SOUND_QUALITY: + if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) { + currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08; + } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) { + currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08; + } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT); + break; + case MA_OPT_REGION: + region_prevnext(inp & BTN_RIGHT); + break; + case MA_OPT_CONFIRM_STATES: { + int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2); + n += (inp & BTN_LEFT) ? -1 : 1; + if (n < 0) n = 0; else if (n > 3) n = 3; + n |= n << 1; n &= ~2; + currentConfig.EmuOpt &= ~0xa00; + currentConfig.EmuOpt |= n << 9; + break; + } + case MA_OPT_SAVE_SLOT: + if (inp & BTN_RIGHT) { + state_slot++; if (state_slot > 9) state_slot = 0; + } else {state_slot--; if (state_slot < 0) state_slot = 9; + } + break; + case MA_OPT_SAVECFG: + case MA_OPT_SAVECFG_GAME: + case MA_OPT_LOADCFG: + config_slot += (inp&BTN_RIGHT) ? 1 : -1; + if (config_slot > 9) config_slot = 0; + if (config_slot < 0) config_slot = 9; + me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current); + menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1; + if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; + break; + default: + //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id); + break; + } + } + } + if (inp & BTN_PLAY) { + if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1)) + { + switch (selected_id) + { + case MA_OPT_SCD_OPTS: + cd_menu_loop_options(); + if (engineState == PGS_ReloadRom) + return 0; // test BIOS + break; + case MA_OPT_ADV_OPTS: + amenu_loop_options(); + break; + case MA_OPT_SAVECFG: // done (update and write) + menu_options_save(); + if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved"); + else strcpy(menuErrorMsg, "failed to write config"); + return 1; + case MA_OPT_SAVECFG_GAME: // done (update and write for current game) + menu_options_save(); + if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved"); + else strcpy(menuErrorMsg, "failed to write config"); + return 1; + case MA_OPT_LOADCFG: + ret = emu_ReadConfig(1, 1); + if (!ret) ret = emu_ReadConfig(0, 1); + if (ret) strcpy(menuErrorMsg, "config loaded"); + else strcpy(menuErrorMsg, "failed to load config"); + return 1; + default: + //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id); + break; + } + } + } + if(inp & (BTN_STOP|BTN_REW)) { + menu_options_save(); + return 0; // done (update, no write) + } + } +} + +// -------------- credits -------------- + +static void draw_menu_credits(void) +{ + int tl_x = 15, tl_y = 64, y; + menu_draw_begin(1); + + text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007"); + y = tl_y; + text_out16(tl_x, y, "Credits:"); + text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,"); + text_out16(tl_x, (y+=10), " base code of PicoDrive"); + text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core"); + text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores"); + text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs"); + text_out16(tl_x, (y+=10), "Stephane Dallongeville:"); + text_out16(tl_x, (y+=10), " opensource Gens"); + text_out16(tl_x, (y+=10), "Haze: Genesis hw info"); + text_out16(tl_x, (y+=10), "Reesy: TODO"); + text_out16(tl_x, (y+=10), "TODO: gizmondo hardware"); + text_out16(tl_x, (y+=10), "ketchupgun: skin design"); + + menu_draw_end(); +} + + +// -------------- root menu -------------- + +menu_entry main_entries[] = +{ + { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 }, + { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 }, + { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 }, + { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 }, + { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 }, + { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 }, + { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 }, + { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 }, + { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 }, + { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 } +}; + +#define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0])) + +static void draw_menu_root(int menu_sel) +{ + const int tl_x = 70, tl_y = 70; + + menu_draw_begin(1); + + text_out16(tl_x, 20, "PicoDrive v" VERSION); + + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146); + + me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL); + + // error + if (menuErrorMsg[0]) { + memset((char *)giz_screen + 321*224*2, 0, 321*16*2); + text_out16(5, 226, menuErrorMsg); + } + menu_draw_end(); +} + + +static void menu_loop_root(void) +{ + static int menu_sel = 0; + int ret, menu_sel_max; + unsigned long inp = 0; + + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_data != NULL); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_data != NULL); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_data != NULL); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL); + + menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1; + if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; + + /* make sure action buttons are not pressed on entering menu */ + draw_menu_root(menu_sel); + while (Framework_PollGetButtons(1) & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50); + + for (;;) + { + draw_menu_root(menu_sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R); + if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if(inp &(BTN_HOME|BTN_STOP)){ + if (rom_data) { + while (Framework_PollGetButtons(1) & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until select is released + engineState = PGS_Running; + break; + } + } + if(inp & BTN_PLAY) { + switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel)) + { + case MA_MAIN_RESUME_GAME: + if (rom_data) { + while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50); + engineState = PGS_Running; + return; + } + break; + case MA_MAIN_SAVE_STATE: + if (rom_data) { + if(savestate_menu_loop(0)) + continue; + engineState = PGS_Running; + return; + } + break; + case MA_MAIN_LOAD_STATE: + if (rom_data) { + if(savestate_menu_loop(1)) + continue; + engineState = PGS_Running; + return; + } + break; + case MA_MAIN_RESET_GAME: + if (rom_data) { + emu_ResetGame(); + engineState = PGS_Running; + return; + } + break; + case MA_MAIN_LOAD_ROM: + { + char curr_path[MAX_PATH], *selfname; + FILE *tstf; + if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) + { + fclose(tstf); + strcpy(curr_path, currentConfig.lastRomFile); + } + else + getcwd(curr_path, MAX_PATH); + selfname = romsel_loop(curr_path); + if (selfname) { + lprintf("selected file: %s\n", selfname); + engineState = PGS_ReloadRom; + return; + } + break; + } + case MA_MAIN_OPTIONS: + ret = menu_loop_options(); + if (ret == 1) continue; // status update + if (engineState == PGS_ReloadRom) + return; // BIOS test + break; + case MA_MAIN_CONTROLS: + kc_sel_loop(); + break; + case MA_MAIN_CREDITS: + draw_menu_credits(); + Sleep(500); + inp = wait_for_input(BTN_PLAY|BTN_STOP); + break; + case MA_MAIN_EXIT: + engineState = PGS_Quit; + return; + case MA_MAIN_PATCHES: + if (rom_data && PicoPatches) { + patches_menu_loop(); + PicoPatchApply(); + strcpy(menuErrorMsg, "Patches applied"); + continue; + } + break; + default: + lprintf("%s: something unknown selected\n", __FUNCTION__); + break; + } + } + menuErrorMsg[0] = 0; // clear error msg + } +} + +// warning: alignment +static void menu_darken_bg(void *dst, const void *src, int pixels, int darker) +{ + unsigned int *dest = dst; + const unsigned int *srce = src; + pixels /= 2; + if (darker) + { + while (pixels--) + { + unsigned int p = *srce++; + *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3); + } + } + else + { + while (pixels--) + { + unsigned int p = *srce++; + *dest++ = (p&0xf79ef79e)>>1; + } + } +} + +static void menu_prepare_bg(int use_game_bg) +{ + if (use_game_bg) + { + // darken the active framebuffer + memset(bg_buffer, 0, 321*8*2); + menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1); + memset(bg_buffer + 321*232*2, 0, 321*8*2); + } + else + { + // should really only happen once, on startup.. + readpng(bg_buffer, "skin/background.png", READPNG_BG); + } +} + +static void menu_gfx_prepare(void) +{ + menu_prepare_bg(rom_data != NULL); + + menu_draw_begin(1); + menu_draw_end(); +} + + +void menu_loop(void) +{ + menu_gfx_prepare(); + + menu_loop_root(); + + menuErrorMsg[0] = 0; +} + + +// --------- CD tray close menu ---------- + +static void draw_menu_tray(int menu_sel) +{ + int tl_x = 70, tl_y = 90, y; + + menu_draw_begin(1); + + text_out16(tl_x, 20, "The unit is about to"); + text_out16(tl_x, 30, "close the CD tray."); + + y = tl_y; + text_out16(tl_x, y, "Load new CD image"); + text_out16(tl_x, (y+=10), "Insert nothing"); + + // draw cursor + text_out16(tl_x - 16, tl_y + menu_sel*10, ">"); + // error + if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg); + menu_draw_end(); +} + + +int menu_loop_tray(void) +{ + int menu_sel = 0, menu_sel_max = 1; + unsigned long inp = 0; + char curr_path[MAX_PATH], *selfname; + FILE *tstf; + + menu_gfx_prepare(); + + if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) + { + fclose(tstf); + strcpy(curr_path, currentConfig.lastRomFile); + } + else + { + getcwd(curr_path, MAX_PATH); + } + + /* make sure action buttons are not pressed on entering menu */ + draw_menu_tray(menu_sel); + while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50); + + for (;;) + { + draw_menu_tray(menu_sel); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY); + if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if(inp & BTN_PLAY ) { + switch (menu_sel) { + case 0: // select image + selfname = romsel_loop(curr_path); + if (selfname) { + int ret = -1, cd_type; + cd_type = emu_cd_check(NULL); + if (cd_type > 0) + ret = Insert_CD(romFileName, cd_type == 2); + if (ret != 0) { + sprintf(menuErrorMsg, "Load failed, invalid CD image?"); + lprintf("%s\n", menuErrorMsg); + continue; + } + engineState = PGS_RestartRun; + return 1; + } + break; + case 1: // insert nothing + engineState = PGS_RestartRun; + return 0; + } + } + menuErrorMsg[0] = 0; // clear error msg + } +} + + diff --git a/platform/gizmondo/menu.h b/platform/gizmondo/menu.h new file mode 100644 index 00000000..ae1bccd0 --- /dev/null +++ b/platform/gizmondo/menu.h @@ -0,0 +1,19 @@ +// (c) Copyright 2006,2007 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + +extern char menuErrorMsg[40]; + +void menu_init(void); +void text_out16(int x, int y, const char *texto, ...); +void menu_loop(void); +int menu_loop_tray(void); +void menu_romload_prepare(const char *rom_name); +void menu_romload_end(void); + +// TODO: add more? +#define CONFIGURABLE_KEYS \ + (BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_STOP|BTN_PLAY|BTN_FWD|BTN_REW| \ + BTN_L|BTN_R) + diff --git a/platform/gizmondo/mp3.c b/platform/gizmondo/mp3.c new file mode 100644 index 00000000..086257c8 --- /dev/null +++ b/platform/gizmondo/mp3.c @@ -0,0 +1,8 @@ +#include + +int mp3_get_bitrate(FILE *f, int size){} +void mp3_start_play(FILE *f, int pos){} +int mp3_get_offset(void){} // 0-1023 +void mp3_update(int *buffer, int length, int stereo){} + + diff --git a/platform/gizmondo/port_config.h b/platform/gizmondo/port_config.h new file mode 100644 index 00000000..a6a15afc --- /dev/null +++ b/platform/gizmondo/port_config.h @@ -0,0 +1,18 @@ +// port specific settings + +#ifndef PORT_CONFIG_H +#define PORT_CONFIG_H + +#define CPU_CALL + +// draw2.c +#define START_ROW 0 // which row of tiles to start rendering at? +#define END_ROW 28 // ..end + +// pico.c +#define CAN_HANDLE_240_LINES 1 + +//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__) +#define dprintf(x...) + +#endif //PORT_CONFIG_H diff --git a/platform/gizmondo/port_config.s b/platform/gizmondo/port_config.s new file mode 100644 index 00000000..89c44d95 --- /dev/null +++ b/platform/gizmondo/port_config.s @@ -0,0 +1,10 @@ +@ vim:filetype=armasm + +@ .equiv START_ROW, 1 +@ .equiv END_ROW, 27 +@ one row means 8 pixels. If above example was used, (27-1)*8=208 lines would be rendered. +.equiv START_ROW, 0 +.equiv END_ROW, 28 + +@ this should be set to one only for GP2X port +.equiv EXTERNAL_YM2612, 0 diff --git a/platform/gizmondo/version.h b/platform/gizmondo/version.h new file mode 100644 index 00000000..a3ccbd30 --- /dev/null +++ b/platform/gizmondo/version.h @@ -0,0 +1,2 @@ +#define VERSION "1.33" + diff --git a/platform/gp2x/940ctl.c b/platform/gp2x/940ctl.c index 66a5d2b9..075b8278 100644 --- a/platform/gp2x/940ctl.c +++ b/platform/gp2x/940ctl.c @@ -14,8 +14,9 @@ #include "gp2x.h" #include "emu.h" #include "menu.h" -#include "asmutils.h" #include "mp3.h" +#include "../common/arm_utils.h" +#include "../common/menu.h" #include "../../Pico/PicoInt.h" #include "../../Pico/sound/mix.h" diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index 0eee0eb2..5b8b0398 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -48,10 +48,13 @@ LD = $(CROSS)ld OBJCOPY = $(CROSS)objcopy # frontend -OBJS += main.o menu.o fonts.o gp2x.o usbjoy.o emu.o squidgehack.o asmutils.o cpuctrl.o readpng.o +OBJS += main.o menu.o gp2x.o usbjoy.o emu.o squidgehack.o cpuctrl.o # 940 core control OBJS += 940ctl.o +# common +OBJS += ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o + # Pico ifeq "$(amalgamate)" "1" OBJS += ../../PicoAll.o @@ -148,7 +151,7 @@ up: PicoDrive.gpe # @cmd //C copy PicoDrive.gpe \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ -testrefr.gpe : test.o gp2x.o asmutils.o +testrefr.gpe : test.o gp2x.o @echo $@ @$(GCC) $(COPT) $^ -o $@ @$(STRIP) $@ diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index a9a931a6..adb10a35 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -18,9 +18,9 @@ #include "gp2x.h" #include "usbjoy.h" #include "menu.h" -#include "asmutils.h" +#include "../common/arm_utils.h" +#include "../common/fonts.h" #include "cpuctrl.h" -#include "fonts.h" #include #include @@ -52,7 +52,7 @@ static int combo_keys = 0, combo_acts = 0; // keys and actions which need button static int gp2x_old_gamma = 100; static unsigned char *movie_data = NULL; static int movie_size = 0; -unsigned char *framebuff = 0; // temporary buffer for alt renderer +unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer int state_slot = 0; int reset_timing = 0; int config_slot = 0, config_slot_current = 0; @@ -389,10 +389,10 @@ static void emu_msg_tray_open(void); void emu_Init(void) { // make temp buffer for alt renderer - framebuff = malloc((8+320)*(8+240+8)); - if (!framebuff) + PicoDraw2FB = malloc((8+320)*(8+240+8)); + if (!PicoDraw2FB) { - printf("framebuff == 0\n"); + printf("PicoDraw2FB == 0\n"); } // make dirs for saves, cfgs, etc. @@ -626,7 +626,7 @@ void emu_Deinit(void) } } - free(framebuff); + free(PicoDraw2FB); PicoExit(); @@ -768,7 +768,7 @@ static void blit(const char *fps, const char *notice) // feed new palette to our device gp2x_video_setpalette(localPal, 0x40); } - vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); + vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); } else if (!(emu_opt&0x80)) { // 8bit accurate renderer if (Pico.m.dirtyPal) { @@ -1112,7 +1112,7 @@ void emu_forced_frame(void) clearArea(1); } else vidCpyM2 = vidCpyM2_40col; - vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); + vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); */ diff --git a/platform/gp2x/gp2x.c b/platform/gp2x/gp2x.c index 3b5d125e..4995f08b 100644 --- a/platform/gp2x/gp2x.c +++ b/platform/gp2x/gp2x.c @@ -34,7 +34,7 @@ #include "gp2x.h" #include "usbjoy.h" -#include "asmutils.h" +#include "../common/arm_utils.h" volatile unsigned short *gp2x_memregs; //static diff --git a/platform/gp2x/main.c b/platform/gp2x/main.c index e4e3bcfa..13eb5a8e 100644 --- a/platform/gp2x/main.c +++ b/platform/gp2x/main.c @@ -11,6 +11,7 @@ #include "gp2x.h" #include "menu.h" +#include "../common/menu.h" #include "emu.h" #include "940ctl.h" #include "version.h" diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 71ddf688..a8d1f9e7 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -13,10 +13,10 @@ #include "gp2x.h" #include "emu.h" #include "menu.h" -#include "fonts.h" #include "usbjoy.h" -#include "asmutils.h" -#include "readpng.h" +#include "../common/arm_utils.h" +#include "../common/menu.h" +#include "../common/readpng.h" #include "version.h" #include @@ -33,389 +33,18 @@ extern int mmuhack_status; extern int state_slot; extern int config_slot, config_slot_current; -static unsigned char menu_font_data[10240]; -static char *gp2xKeyNames[] = { +static const char *gp2xKeyNames[] = { "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???", "START", "SELECT", "L", "R", "A", "B", "X", "Y", "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP", "???", "???", "???", "PUSH", "???", "???", "???", "???" }; -static int menu_text_color = 0xffff; // default to white -static int menu_sel_color = -1; // disabled char menuErrorMsg[40] = {0, }; static void menu_darken_bg(void *dst, int pixels, int darker); static void menu_prepare_bg(int use_game_bg); -// draws text to current bbp16 screen -static void text_out16_(int x, int y, const char *text, int color) -{ - int i, l, u, tr, tg, tb, len; - unsigned short *dest = (unsigned short *)gp2x_screen + x + y*320; - tr = (color & 0xf800) >> 8; - tg = (color & 0x07e0) >> 3; - tb = (color & 0x001f) << 3; - - if (text == (void *)1) - { - // selector symbol - text = ""; - len = 1; - } - else - len = strlen(text); - - for (i = 0; i < len; i++) - { - unsigned char *src = menu_font_data + (unsigned int)text[i]*4*10; - unsigned short *dst = dest; - for (l = 0; l < 10; l++, dst += 320-8) - { - for (u = 8/2; u > 0; u--, src++) - { - int c, r, g, b; - c = *src >> 4; - r = (*dst & 0xf800) >> 8; - g = (*dst & 0x07e0) >> 3; - b = (*dst & 0x001f) << 3; - r = (c^0xf)*r/15 + c*tr/15; - g = (c^0xf)*g/15 + c*tg/15; - b = (c^0xf)*b/15 + c*tb/15; - *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3); - c = *src & 0xf; - r = (*dst & 0xf800) >> 8; - g = (*dst & 0x07e0) >> 3; - b = (*dst & 0x001f) << 3; - r = (c^0xf)*r/15 + c*tr/15; - g = (c^0xf)*g/15 + c*tg/15; - b = (c^0xf)*b/15 + c*tb/15; - *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3); - } - } - dest += 8; - } -} - -void text_out16(int x, int y, const char *texto, ...) -{ - va_list args; - char buffer[512]; - - va_start(args,texto); - vsprintf(buffer,texto,args); - va_end(args); - - text_out16_(x,y,buffer,menu_text_color); -} - - -static void smalltext_out16(int x, int y, const char *texto, int color) -{ - int i; - unsigned char *src; - unsigned short *dst; - - for (i = 0;; i++, x += 6) - { - unsigned char c = (unsigned char) texto[i]; - int h = 8; - - if (!c) break; - - src = fontdata6x8[c]; - dst = (unsigned short *)gp2x_screen + x + y*320; - - while (h--) - { - int w = 0x20; - while (w) - { - if( *src & w ) *dst = color; - dst++; - w>>=1; - } - src++; - - dst += 320-6; - } - } -} - -static void smalltext_out16_lim(int x, int y, const char *texto, int color, int max) -{ - char buffer[320/6+1]; - - strncpy(buffer, texto, 320/6); - if (max > 320/6) max = 320/6; - if (max < 0) max = 0; - buffer[max] = 0; - - smalltext_out16(x, y, buffer, color); -} - -static void draw_selection(int x, int y, int w) -{ - int i, h; - unsigned short *dst, *dest; - - text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color); - - if (menu_sel_color < 0) return; // no selection hilight - - if (y > 0) y--; - dest = (unsigned short *)gp2x_screen + x + y*320 + 14; - for (h = 11; h > 0; h--) - { - dst = dest; - for (i = w; i > 0; i--) - *dst++ = menu_sel_color; - dest += 320; - } -} - -static void menu_flip(void) -{ - gp2x_video_flush_cache(); - gp2x_video_flip2(); -} - - -typedef enum -{ - MB_NONE = 1, /* no auto processing */ - MB_ONOFF, /* ON/OFF setting */ - MB_RANGE, /* [min-max] setting */ -} menu_behavior; - -typedef enum -{ - MA_NONE = 1, - MA_MAIN_RESUME_GAME, - MA_MAIN_SAVE_STATE, - MA_MAIN_LOAD_STATE, - MA_MAIN_RESET_GAME, - MA_MAIN_LOAD_ROM, - MA_MAIN_OPTIONS, - MA_MAIN_CONTROLS, - MA_MAIN_CREDITS, - MA_MAIN_PATCHES, - MA_MAIN_EXIT, - MA_OPT_RENDERER, - MA_OPT_SCALING, - MA_OPT_ACC_TIMING, - MA_OPT_ACC_SPRITES, - MA_OPT_SHOW_FPS, - MA_OPT_FRAMESKIP, - MA_OPT_ENABLE_SOUND, - MA_OPT_SOUND_QUALITY, - MA_OPT_ARM940_SOUND, - MA_OPT_6BUTTON_PAD, - MA_OPT_REGION, - MA_OPT_SRAM_STATES, - MA_OPT_CONFIRM_STATES, - MA_OPT_SAVE_SLOT, - MA_OPT_CPU_CLOCKS, - MA_OPT_SCD_OPTS, - MA_OPT_ADV_OPTS, - MA_OPT_SAVECFG, - MA_OPT_SAVECFG_GAME, - MA_OPT_LOADCFG, - MA_OPT2_GAMMA, - MA_OPT2_A_SN_GAMMA, - MA_OPT2_VSYNC, - MA_OPT2_ENABLE_Z80, - MA_OPT2_ENABLE_YM2612, - MA_OPT2_ENABLE_SN76496, - MA_OPT2_GZIP_STATES, - MA_OPT2_NO_LAST_ROM, - MA_OPT2_RAMTIMINGS, - MA_OPT2_SQUIDGEHACK, - MA_OPT2_DONE, - MA_CDOPT_TESTBIOS_USA, - MA_CDOPT_TESTBIOS_EUR, - MA_CDOPT_TESTBIOS_JAP, - MA_CDOPT_LEDS, - MA_CDOPT_CDDA, - MA_CDOPT_PCM, - MA_CDOPT_READAHEAD, - MA_CDOPT_SAVERAM, - MA_CDOPT_SCALEROT_CHIP, - MA_CDOPT_BETTER_SYNC, - MA_CDOPT_DONE, -} menu_id; - -typedef struct -{ - char *name; - menu_behavior beh; - menu_id id; - void *var; /* for on-off settings */ - int mask; - signed char min; /* for ranged integer settings, to be sign-extended */ - signed char max; - char enabled; -} menu_entry; - -static int me_id2offset(const menu_entry *entries, int count, menu_id id) -{ - int i; - for (i = 0; i < count; i++) - { - if (entries[i].id == id) return i; - } - - printf("%s: id %i not found\n", __FUNCTION__, id); - return 0; -} - -static void me_enable(menu_entry *entries, int count, menu_id id, int enable) -{ - int i = me_id2offset(entries, count, id); - entries[i].enabled = enable; -} - -static int me_count_enabled(const menu_entry *entries, int count) -{ - int i, ret = 0; - - for (i = 0; i < count; i++) - { - if (entries[i].enabled) ret++; - } - - return ret; -} - -static menu_id me_index2id(const menu_entry *entries, int count, int index) -{ - int i; - - for (i = 0; i < count; i++) - { - if (entries[i].enabled) - { - if (index == 0) break; - index--; - } - } - if (i >= count) i = count - 1; - return entries[i].id; -} - -typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param); - -static void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param) -{ - int i, y1 = y; - - for (i = 0; i < count; i++) - { - if (!entries[i].enabled) continue; - if (entries[i].name == NULL) - { - if (cust_draw != NULL) - cust_draw(&entries[i], x, y1, param); - y1 += 10; - continue; - } - text_out16(x, y1, entries[i].name); - if (entries[i].beh == MB_ONOFF) - text_out16(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF"); - else if (entries[i].beh == MB_RANGE) - text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var); - y1 += 10; - } -} - -static int me_process(menu_entry *entries, int count, menu_id id, int is_next) -{ - int i = me_id2offset(entries, count, id); - menu_entry *entry = &entries[i]; - switch (entry->beh) - { - case MB_ONOFF: - *(int *)entry->var ^= entry->mask; - return 1; - case MB_RANGE: - *(int *)entry->var += is_next ? 1 : -1; - if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min; - if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max; - return 1; - default: - return 0; - } -} - - -static int parse_hex_color(char *buff) -{ - char *endp = buff; - int t = (int) strtoul(buff, &endp, 16); - if (endp != buff) return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f); - return -1; -} - -void menu_init(void) -{ - int c, l; - unsigned char *fd = menu_font_data; - char buff[256]; - FILE *f; - - // generate default font from fontdata8x8 - memset(menu_font_data, 0, sizeof(menu_font_data)); - for (c = 0; c < 256; c++) - { - for (l = 0; l < 8; l++) - { - unsigned char fd8x8 = fontdata8x8[c*8+l]; - if (fd8x8&0x80) *fd |= 0xf0; - if (fd8x8&0x40) *fd |= 0x0f; fd++; - if (fd8x8&0x20) *fd |= 0xf0; - if (fd8x8&0x10) *fd |= 0x0f; fd++; - if (fd8x8&0x08) *fd |= 0xf0; - if (fd8x8&0x04) *fd |= 0x0f; fd++; - if (fd8x8&0x02) *fd |= 0xf0; - if (fd8x8&0x01) *fd |= 0x0f; fd++; - } - fd += 8*2/2; // 2 empty lines - } - - // load custom font and selector (stored as 1st symbol in font table) - readpng(menu_font_data, "skin/font.png", READPNG_FONT); - memcpy(menu_font_data, menu_font_data + ((int)'>')*4*10, 4*10); // default selector symbol is '>' - readpng(menu_font_data, "skin/selector.png", READPNG_SELECTOR); - - // load custom colors - f = fopen("skin/skin.txt", "r"); - if (f != NULL) - { - printf("found skin.txt\n"); - while (!feof(f)) - { - fgets(buff, sizeof(buff), f); - if (buff[0] == '#' || buff[0] == '/') continue; // comment - if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line - if (strncmp(buff, "text_color=", 11) == 0) - { - int tmp = parse_hex_color(buff+11); - if (tmp >= 0) menu_text_color = tmp; - else printf("skin.txt: parse error for text_color\n"); - } - else if (strncmp(buff, "selection_color=", 16) == 0) - { - int tmp = parse_hex_color(buff+16); - if (tmp >= 0) menu_sel_color = tmp; - else printf("skin.txt: parse error for selection_color\n"); - } - else - printf("skin.txt: parse error: %s\n", buff); - } - fclose(f); - } -} - static unsigned long inp_prev = 0; static int inp_prevjoy = 0; @@ -500,6 +129,11 @@ static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy) return ret; } +static void menu_flip(void) +{ + gp2x_video_flush_cache(); + gp2x_video_flip2(); +} // --------- loading ROM screen ---------- @@ -887,7 +521,7 @@ static void draw_savestate_menu(int menu_sel, int is_loading) text_out16(tl_x, 30, is_loading ? "Load state" : "Save state"); - draw_selection(tl_x - 16, tl_y + menu_sel*10, 108); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108); /* draw all 10 slots */ y = tl_y; @@ -1029,7 +663,7 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i x = 40; } - draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130); + menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130); y = tl_y; for (i = 0; i < opt_cnt; i++, y+=10) @@ -1110,7 +744,7 @@ static void draw_kc_sel(int menu_sel) y = tl_y; gp2x_pd_clone_buffer2(); - draw_selection(tl_x - 16, tl_y + menu_sel*10, 138); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138); text_out16(tl_x, y, "Player 1"); text_out16(tl_x, (y+=10), "Player 2"); @@ -1246,7 +880,7 @@ static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names) gp2x_pd_clone_buffer2(); - draw_selection(tl_x - 16, tl_y + menu_sel*10, 246); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246); me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names); @@ -1347,7 +981,7 @@ menu_entry opt2_entries[] = { { NULL, MB_NONE, MA_OPT2_GAMMA, NULL, 0, 0, 0, 1 }, { "A_SN's gamma curve", MB_ONOFF, MA_OPT2_A_SN_GAMMA, ¤tConfig.EmuOpt, 0x1000, 0, 0, 1 }, - { "Perfecf vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 }, + { "Perfect vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 }, { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 }, { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 }, { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 }, @@ -1377,7 +1011,7 @@ static void draw_amenu_options(int menu_sel) gp2x_pd_clone_buffer2(); - draw_selection(tl_x - 16, tl_y + menu_sel*10, 252); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252); me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL); @@ -1546,7 +1180,7 @@ static void draw_menu_options(int menu_sel) gp2x_pd_clone_buffer2(); - draw_selection(tl_x - 16, tl_y + menu_sel*10, 284); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284); me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL); @@ -1785,7 +1419,7 @@ static void draw_menu_root(int menu_sel) text_out16(tl_x, 20, "PicoDrive v" VERSION); - draw_selection(tl_x - 16, tl_y + menu_sel*10, 146); + menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146); me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL); @@ -2008,7 +1642,7 @@ int menu_loop_tray(void) char curr_path[PATH_MAX], *selfname; FILE *tstf; - gp2x_memset_all_buffers(0, 0xe0, 320*240); + gp2x_memset_all_buffers(0, 0, 320*240*2); menu_gfx_prepare(); if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) diff --git a/platform/gp2x/menu.h b/platform/gp2x/menu.h index 62ec051c..bd216a4a 100644 --- a/platform/gp2x/menu.h +++ b/platform/gp2x/menu.h @@ -5,8 +5,6 @@ extern char menuErrorMsg[40]; -void menu_init(void); -void text_out16(int x, int y, const char *texto, ...); void menu_loop(void); int menu_loop_tray(void); void menu_romload_prepare(const char *rom_name); diff --git a/platform/linux/Makefile b/platform/linux/Makefile index a85ef43b..3380ae9a 100644 --- a/platform/linux/Makefile +++ b/platform/linux/Makefile @@ -24,8 +24,12 @@ COPT += `pkg-config --cflags gthread-2.0` LDFLAGS += `pkg-config --libs gthread-2.0` # frontend -OBJS += ../gp2x/main.o ../gp2x/menu.o ../gp2x/fonts.o ../gp2x/emu.o ../gp2x/usbjoy.o blit.o \ - gp2x.o 940ctl_ym2612.o ../gp2x/readpng.o +OBJS += ../gp2x/main.o ../gp2x/menu.o ../gp2x/emu.o ../gp2x/usbjoy.o blit.o \ + gp2x.o 940ctl_ym2612.o + +# common +OBJS += ../common/menu.o ../common/fonts.o ../common/readpng.o + # Pico OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Memory.o ../../Pico/Misc.o \ ../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o \