--- /dev/null
+#if defined(__GP2X__)
+#define lprintf printf
+#else
+#include "giz.h"
+#endif
+
--- /dev/null
+// (c) Copyright 2006,2007 notaz, All rights reserved.\r
+// Free for non-commercial use.\r
+\r
+// For commercial use, separate licencing terms must be obtained.\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdarg.h>\r
+\r
+#include "menu.h"\r
+#include "fonts.h"\r
+#include "readpng.h"\r
+#include "lprintf.h"\r
+\r
+#if defined(__GP2X__)\r
+#include "../gp2x/gp2x.h"\r
+#define SCREEN_WIDTH 320\r
+#define SCREEN_BUFFER gp2x_screen\r
+#elif defined(__GIZ__)\r
+#include "../gizmondo/giz.h"\r
+#define SCREEN_WIDTH 321\r
+#define SCREEN_BUFFER giz_screen\r
+#endif\r
+\r
+static unsigned char menu_font_data[10240];\r
+static int menu_text_color = 0xffff; // default to white\r
+static int menu_sel_color = -1; // disabled\r
+\r
+// draws text to current bbp16 screen\r
+static void text_out16_(int x, int y, const char *text, int color)\r
+{\r
+ int i, l, u, tr, tg, tb, len;\r
+ unsigned short *dest = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH;\r
+ tr = (color & 0xf800) >> 8;\r
+ tg = (color & 0x07e0) >> 3;\r
+ tb = (color & 0x001f) << 3;\r
+\r
+ if (text == (void *)1)\r
+ {\r
+ // selector symbol\r
+ text = "";\r
+ len = 1;\r
+ }\r
+ else\r
+ len = strlen(text);\r
+\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ unsigned char *src = menu_font_data + (unsigned int)text[i]*4*10;\r
+ unsigned short *dst = dest;\r
+ for (l = 0; l < 10; l++, dst += SCREEN_WIDTH-8)\r
+ {\r
+ for (u = 8/2; u > 0; u--, src++)\r
+ {\r
+ int c, r, g, b;\r
+ c = *src >> 4;\r
+ r = (*dst & 0xf800) >> 8;\r
+ g = (*dst & 0x07e0) >> 3;\r
+ b = (*dst & 0x001f) << 3;\r
+ r = (c^0xf)*r/15 + c*tr/15;\r
+ g = (c^0xf)*g/15 + c*tg/15;\r
+ b = (c^0xf)*b/15 + c*tb/15;\r
+ *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);\r
+ c = *src & 0xf;\r
+ r = (*dst & 0xf800) >> 8;\r
+ g = (*dst & 0x07e0) >> 3;\r
+ b = (*dst & 0x001f) << 3;\r
+ r = (c^0xf)*r/15 + c*tr/15;\r
+ g = (c^0xf)*g/15 + c*tg/15;\r
+ b = (c^0xf)*b/15 + c*tb/15;\r
+ *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);\r
+ }\r
+ }\r
+ dest += 8;\r
+ }\r
+}\r
+\r
+void text_out16(int x, int y, const char *texto, ...)\r
+{\r
+ va_list args;\r
+ char buffer[512];\r
+\r
+ va_start(args,texto);\r
+ vsprintf(buffer,texto,args);\r
+ va_end(args);\r
+\r
+ text_out16_(x,y,buffer,menu_text_color);\r
+}\r
+\r
+\r
+void smalltext_out16(int x, int y, const char *texto, int color)\r
+{\r
+ int i;\r
+ unsigned char *src;\r
+ unsigned short *dst;\r
+\r
+ for (i = 0;; i++, x += 6)\r
+ {\r
+ unsigned char c = (unsigned char) texto[i];\r
+ int h = 8;\r
+\r
+ if (!c) break;\r
+\r
+ src = fontdata6x8[c];\r
+ dst = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH;\r
+\r
+ while (h--)\r
+ {\r
+ int w = 0x20;\r
+ while (w)\r
+ {\r
+ if( *src & w ) *dst = color;\r
+ dst++;\r
+ w>>=1;\r
+ }\r
+ src++;\r
+\r
+ dst += SCREEN_WIDTH-6;\r
+ }\r
+ }\r
+}\r
+\r
+void smalltext_out16_lim(int x, int y, const char *texto, int color, int max)\r
+{\r
+ char buffer[SCREEN_WIDTH/6+1];\r
+\r
+ strncpy(buffer, texto, SCREEN_WIDTH/6);\r
+ if (max > SCREEN_WIDTH/6) max = SCREEN_WIDTH/6;\r
+ if (max < 0) max = 0;\r
+ buffer[max] = 0;\r
+\r
+ smalltext_out16(x, y, buffer, color);\r
+}\r
+\r
+void menu_draw_selection(int x, int y, int w)\r
+{\r
+ int i, h;\r
+ unsigned short *dst, *dest;\r
+\r
+ text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color);\r
+\r
+ if (menu_sel_color < 0) return; // no selection hilight\r
+\r
+ if (y > 0) y--;\r
+ dest = (unsigned short *)SCREEN_BUFFER + x + y*SCREEN_WIDTH + 14;\r
+ for (h = 11; h > 0; h--)\r
+ {\r
+ dst = dest;\r
+ for (i = w; i > 0; i--)\r
+ *dst++ = menu_sel_color;\r
+ dest += SCREEN_WIDTH;\r
+ }\r
+}\r
+\r
+static int parse_hex_color(char *buff)\r
+{\r
+ char *endp = buff;\r
+ int t = (int) strtoul(buff, &endp, 16);\r
+ if (endp != buff) return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f);\r
+ return -1;\r
+}\r
+\r
+void menu_init(void)\r
+{\r
+ int c, l;\r
+ unsigned char *fd = menu_font_data;\r
+ char buff[256];\r
+ FILE *f;\r
+\r
+ // generate default font from fontdata8x8\r
+ memset(menu_font_data, 0, sizeof(menu_font_data));\r
+ for (c = 0; c < 256; c++)\r
+ {\r
+ for (l = 0; l < 8; l++)\r
+ {\r
+ unsigned char fd8x8 = fontdata8x8[c*8+l];\r
+ if (fd8x8&0x80) *fd |= 0xf0;\r
+ if (fd8x8&0x40) *fd |= 0x0f; fd++;\r
+ if (fd8x8&0x20) *fd |= 0xf0;\r
+ if (fd8x8&0x10) *fd |= 0x0f; fd++;\r
+ if (fd8x8&0x08) *fd |= 0xf0;\r
+ if (fd8x8&0x04) *fd |= 0x0f; fd++;\r
+ if (fd8x8&0x02) *fd |= 0xf0;\r
+ if (fd8x8&0x01) *fd |= 0x0f; fd++;\r
+ }\r
+ fd += 8*2/2; // 2 empty lines\r
+ }\r
+\r
+ // load custom font and selector (stored as 1st symbol in font table)\r
+ readpng(menu_font_data, "skin/font.png", READPNG_FONT);\r
+ memcpy(menu_font_data, menu_font_data + ((int)'>')*4*10, 4*10); // default selector symbol is '>'\r
+ readpng(menu_font_data, "skin/selector.png", READPNG_SELECTOR);\r
+\r
+ // load custom colors\r
+ f = fopen("skin/skin.txt", "r");\r
+ if (f != NULL)\r
+ {\r
+ lprintf("found skin.txt\n");\r
+ while (!feof(f))\r
+ {\r
+ fgets(buff, sizeof(buff), f);\r
+ if (buff[0] == '#' || buff[0] == '/') continue; // comment\r
+ if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line\r
+ if (strncmp(buff, "text_color=", 11) == 0)\r
+ {\r
+ int tmp = parse_hex_color(buff+11);\r
+ if (tmp >= 0) menu_text_color = tmp;\r
+ else lprintf("skin.txt: parse error for text_color\n");\r
+ }\r
+ else if (strncmp(buff, "selection_color=", 16) == 0)\r
+ {\r
+ int tmp = parse_hex_color(buff+16);\r
+ if (tmp >= 0) menu_sel_color = tmp;\r
+ else lprintf("skin.txt: parse error for selection_color\n");\r
+ }\r
+ else\r
+ lprintf("skin.txt: parse error: %s\n", buff);\r
+ }\r
+ fclose(f);\r
+ }\r
+}\r
+\r
+\r
+int me_id2offset(const menu_entry *entries, int count, menu_id id)\r
+{\r
+ int i;\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ if (entries[i].id == id) return i;\r
+ }\r
+\r
+ lprintf("%s: id %i not found\n", __FUNCTION__, id);\r
+ return 0;\r
+}\r
+\r
+void me_enable(menu_entry *entries, int count, menu_id id, int enable)\r
+{\r
+ int i = me_id2offset(entries, count, id);\r
+ entries[i].enabled = enable;\r
+}\r
+\r
+int me_count_enabled(const menu_entry *entries, int count)\r
+{\r
+ int i, ret = 0;\r
+\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ if (entries[i].enabled) ret++;\r
+ }\r
+\r
+ return ret;\r
+}\r
+\r
+menu_id me_index2id(const menu_entry *entries, int count, int index)\r
+{\r
+ int i;\r
+\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ if (entries[i].enabled)\r
+ {\r
+ if (index == 0) break;\r
+ index--;\r
+ }\r
+ }\r
+ if (i >= count) i = count - 1;\r
+ return entries[i].id;\r
+}\r
+\r
+void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param)\r
+{\r
+ int i, y1 = y;\r
+\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ if (!entries[i].enabled) continue;\r
+ if (entries[i].name == NULL)\r
+ {\r
+ if (cust_draw != NULL)\r
+ cust_draw(&entries[i], x, y1, param);\r
+ y1 += 10;\r
+ continue;\r
+ }\r
+ text_out16(x, y1, entries[i].name);\r
+ if (entries[i].beh == MB_ONOFF)\r
+ text_out16(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\r
+ else if (entries[i].beh == MB_RANGE)\r
+ text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
+ y1 += 10;\r
+ }\r
+}\r
+\r
+int me_process(menu_entry *entries, int count, menu_id id, int is_next)\r
+{\r
+ int i = me_id2offset(entries, count, id);\r
+ menu_entry *entry = &entries[i];\r
+ switch (entry->beh)\r
+ {\r
+ case MB_ONOFF:\r
+ *(int *)entry->var ^= entry->mask;\r
+ return 1;\r
+ case MB_RANGE:\r
+ *(int *)entry->var += is_next ? 1 : -1;\r
+ if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min;\r
+ if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max;\r
+ return 1;\r
+ default:\r
+ return 0;\r
+ }\r
+}\r
+\r
+\r
+\r
--- /dev/null
+// (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);
+
+
#include <string.h>
#include <png.h>
#include "readpng.h"
+#include "lprintf.h"
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;
}
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;
}
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)
{
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;
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++)
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++)
#include "gp2x.h"\r
#include "emu.h"\r
#include "menu.h"\r
-#include "asmutils.h"\r
#include "mp3.h"\r
+#include "../common/arm_utils.h"\r
+#include "../common/menu.h"\r
#include "../../Pico/PicoInt.h"\r
#include "../../Pico/sound/mix.h"\r
\r
OBJCOPY = $(CROSS)objcopy\r
\r
# frontend\r
-OBJS += main.o menu.o fonts.o gp2x.o usbjoy.o emu.o squidgehack.o asmutils.o cpuctrl.o readpng.o\r
+OBJS += main.o menu.o gp2x.o usbjoy.o emu.o squidgehack.o cpuctrl.o\r
# 940 core control\r
OBJS += 940ctl.o\r
\r
+# common\r
+OBJS += ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o\r
+\r
# Pico\r
ifeq "$(amalgamate)" "1"\r
OBJS += ../../PicoAll.o\r
# @cmd //C copy PicoDrive.gpe \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\\r
\r
\r
-testrefr.gpe : test.o gp2x.o asmutils.o\r
+testrefr.gpe : test.o gp2x.o\r
@echo $@\r
@$(GCC) $(COPT) $^ -o $@\r
@$(STRIP) $@\r
#include "gp2x.h"\r
#include "usbjoy.h"\r
#include "menu.h"\r
-#include "asmutils.h"\r
+#include "../common/arm_utils.h"\r
+#include "../common/fonts.h"\r
#include "cpuctrl.h"\r
-#include "fonts.h"\r
\r
#include <Pico/PicoInt.h>\r
#include <Pico/Patch.h>\r
static int gp2x_old_gamma = 100;\r
static unsigned char *movie_data = NULL;\r
static int movie_size = 0;\r
-unsigned char *framebuff = 0; // temporary buffer for alt renderer\r
+unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer\r
int state_slot = 0;\r
int reset_timing = 0;\r
int config_slot = 0, config_slot_current = 0;\r
void emu_Init(void)\r
{\r
// make temp buffer for alt renderer\r
- framebuff = malloc((8+320)*(8+240+8));\r
- if (!framebuff)\r
+ PicoDraw2FB = malloc((8+320)*(8+240+8));\r
+ if (!PicoDraw2FB)\r
{\r
- printf("framebuff == 0\n");\r
+ printf("PicoDraw2FB == 0\n");\r
}\r
\r
// make dirs for saves, cfgs, etc.\r
}\r
}\r
\r
- free(framebuff);\r
+ free(PicoDraw2FB);\r
\r
PicoExit();\r
\r
// feed new palette to our device\r
gp2x_video_setpalette(localPal, 0x40);\r
}\r
- vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
+ vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8);\r
} else if (!(emu_opt&0x80)) {\r
// 8bit accurate renderer\r
if (Pico.m.dirtyPal) {\r
clearArea(1);\r
} else vidCpyM2 = vidCpyM2_40col;\r
\r
- vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
+ vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8);\r
vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
gp2x_video_setpalette(localPal, 0x40);\r
*/\r
\r
#include "gp2x.h"\r
#include "usbjoy.h"\r
-#include "asmutils.h"\r
+#include "../common/arm_utils.h"\r
\r
volatile unsigned short *gp2x_memregs;\r
//static\r
\r
#include "gp2x.h"\r
#include "menu.h"\r
+#include "../common/menu.h"\r
#include "emu.h"\r
#include "940ctl.h"\r
#include "version.h"\r
#include "gp2x.h"\r
#include "emu.h"\r
#include "menu.h"\r
-#include "fonts.h"\r
#include "usbjoy.h"\r
-#include "asmutils.h"\r
-#include "readpng.h"\r
+#include "../common/arm_utils.h"\r
+#include "../common/menu.h"\r
+#include "../common/readpng.h"\r
#include "version.h"\r
\r
#include <Pico/PicoInt.h>\r
extern int state_slot;\r
extern int config_slot, config_slot_current;\r
\r
-static unsigned char menu_font_data[10240];\r
-static char *gp2xKeyNames[] = {\r
+static const char *gp2xKeyNames[] = {\r
"UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",\r
"START", "SELECT", "L", "R", "A", "B", "X", "Y",\r
"???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",\r
"???", "???", "???", "PUSH", "???", "???", "???", "???"\r
};\r
-static int menu_text_color = 0xffff; // default to white\r
-static int menu_sel_color = -1; // disabled\r
\r
char menuErrorMsg[40] = {0, };\r
\r
static void menu_darken_bg(void *dst, int pixels, int darker);\r
static void menu_prepare_bg(int use_game_bg);\r
\r
-// draws text to current bbp16 screen\r
-static void text_out16_(int x, int y, const char *text, int color)\r
-{\r
- int i, l, u, tr, tg, tb, len;\r
- unsigned short *dest = (unsigned short *)gp2x_screen + x + y*320;\r
- tr = (color & 0xf800) >> 8;\r
- tg = (color & 0x07e0) >> 3;\r
- tb = (color & 0x001f) << 3;\r
-\r
- if (text == (void *)1)\r
- {\r
- // selector symbol\r
- text = "";\r
- len = 1;\r
- }\r
- else\r
- len = strlen(text);\r
-\r
- for (i = 0; i < len; i++)\r
- {\r
- unsigned char *src = menu_font_data + (unsigned int)text[i]*4*10;\r
- unsigned short *dst = dest;\r
- for (l = 0; l < 10; l++, dst += 320-8)\r
- {\r
- for (u = 8/2; u > 0; u--, src++)\r
- {\r
- int c, r, g, b;\r
- c = *src >> 4;\r
- r = (*dst & 0xf800) >> 8;\r
- g = (*dst & 0x07e0) >> 3;\r
- b = (*dst & 0x001f) << 3;\r
- r = (c^0xf)*r/15 + c*tr/15;\r
- g = (c^0xf)*g/15 + c*tg/15;\r
- b = (c^0xf)*b/15 + c*tb/15;\r
- *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);\r
- c = *src & 0xf;\r
- r = (*dst & 0xf800) >> 8;\r
- g = (*dst & 0x07e0) >> 3;\r
- b = (*dst & 0x001f) << 3;\r
- r = (c^0xf)*r/15 + c*tr/15;\r
- g = (c^0xf)*g/15 + c*tg/15;\r
- b = (c^0xf)*b/15 + c*tb/15;\r
- *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);\r
- }\r
- }\r
- dest += 8;\r
- }\r
-}\r
-\r
-void text_out16(int x, int y, const char *texto, ...)\r
-{\r
- va_list args;\r
- char buffer[512];\r
-\r
- va_start(args,texto);\r
- vsprintf(buffer,texto,args);\r
- va_end(args);\r
-\r
- text_out16_(x,y,buffer,menu_text_color);\r
-}\r
-\r
-\r
-static void smalltext_out16(int x, int y, const char *texto, int color)\r
-{\r
- int i;\r
- unsigned char *src;\r
- unsigned short *dst;\r
-\r
- for (i = 0;; i++, x += 6)\r
- {\r
- unsigned char c = (unsigned char) texto[i];\r
- int h = 8;\r
-\r
- if (!c) break;\r
-\r
- src = fontdata6x8[c];\r
- dst = (unsigned short *)gp2x_screen + x + y*320;\r
-\r
- while (h--)\r
- {\r
- int w = 0x20;\r
- while (w)\r
- {\r
- if( *src & w ) *dst = color;\r
- dst++;\r
- w>>=1;\r
- }\r
- src++;\r
-\r
- dst += 320-6;\r
- }\r
- }\r
-}\r
-\r
-static void smalltext_out16_lim(int x, int y, const char *texto, int color, int max)\r
-{\r
- char buffer[320/6+1];\r
-\r
- strncpy(buffer, texto, 320/6);\r
- if (max > 320/6) max = 320/6;\r
- if (max < 0) max = 0;\r
- buffer[max] = 0;\r
-\r
- smalltext_out16(x, y, buffer, color);\r
-}\r
-\r
-static void draw_selection(int x, int y, int w)\r
-{\r
- int i, h;\r
- unsigned short *dst, *dest;\r
-\r
- text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color);\r
-\r
- if (menu_sel_color < 0) return; // no selection hilight\r
-\r
- if (y > 0) y--;\r
- dest = (unsigned short *)gp2x_screen + x + y*320 + 14;\r
- for (h = 11; h > 0; h--)\r
- {\r
- dst = dest;\r
- for (i = w; i > 0; i--)\r
- *dst++ = menu_sel_color;\r
- dest += 320;\r
- }\r
-}\r
-\r
-static void menu_flip(void)\r
-{\r
- gp2x_video_flush_cache();\r
- gp2x_video_flip2();\r
-}\r
-\r
-\r
-typedef enum\r
-{\r
- MB_NONE = 1, /* no auto processing */\r
- MB_ONOFF, /* ON/OFF setting */\r
- MB_RANGE, /* [min-max] setting */\r
-} menu_behavior;\r
-\r
-typedef enum\r
-{\r
- MA_NONE = 1,\r
- MA_MAIN_RESUME_GAME,\r
- MA_MAIN_SAVE_STATE,\r
- MA_MAIN_LOAD_STATE,\r
- MA_MAIN_RESET_GAME,\r
- MA_MAIN_LOAD_ROM,\r
- MA_MAIN_OPTIONS,\r
- MA_MAIN_CONTROLS,\r
- MA_MAIN_CREDITS,\r
- MA_MAIN_PATCHES,\r
- MA_MAIN_EXIT,\r
- MA_OPT_RENDERER,\r
- MA_OPT_SCALING,\r
- MA_OPT_ACC_TIMING,\r
- MA_OPT_ACC_SPRITES,\r
- MA_OPT_SHOW_FPS,\r
- MA_OPT_FRAMESKIP,\r
- MA_OPT_ENABLE_SOUND,\r
- MA_OPT_SOUND_QUALITY,\r
- MA_OPT_ARM940_SOUND,\r
- MA_OPT_6BUTTON_PAD,\r
- MA_OPT_REGION,\r
- MA_OPT_SRAM_STATES,\r
- MA_OPT_CONFIRM_STATES,\r
- MA_OPT_SAVE_SLOT,\r
- MA_OPT_CPU_CLOCKS,\r
- MA_OPT_SCD_OPTS,\r
- MA_OPT_ADV_OPTS,\r
- MA_OPT_SAVECFG,\r
- MA_OPT_SAVECFG_GAME,\r
- MA_OPT_LOADCFG,\r
- MA_OPT2_GAMMA,\r
- MA_OPT2_A_SN_GAMMA,\r
- MA_OPT2_VSYNC,\r
- MA_OPT2_ENABLE_Z80,\r
- MA_OPT2_ENABLE_YM2612,\r
- MA_OPT2_ENABLE_SN76496,\r
- MA_OPT2_GZIP_STATES,\r
- MA_OPT2_NO_LAST_ROM,\r
- MA_OPT2_RAMTIMINGS,\r
- MA_OPT2_SQUIDGEHACK,\r
- MA_OPT2_DONE,\r
- MA_CDOPT_TESTBIOS_USA,\r
- MA_CDOPT_TESTBIOS_EUR,\r
- MA_CDOPT_TESTBIOS_JAP,\r
- MA_CDOPT_LEDS,\r
- MA_CDOPT_CDDA,\r
- MA_CDOPT_PCM,\r
- MA_CDOPT_READAHEAD,\r
- MA_CDOPT_SAVERAM,\r
- MA_CDOPT_SCALEROT_CHIP,\r
- MA_CDOPT_BETTER_SYNC,\r
- MA_CDOPT_DONE,\r
-} menu_id;\r
-\r
-typedef struct\r
-{\r
- char *name;\r
- menu_behavior beh;\r
- menu_id id;\r
- void *var; /* for on-off settings */\r
- int mask;\r
- signed char min; /* for ranged integer settings, to be sign-extended */\r
- signed char max;\r
- char enabled;\r
-} menu_entry;\r
-\r
-static int me_id2offset(const menu_entry *entries, int count, menu_id id)\r
-{\r
- int i;\r
- for (i = 0; i < count; i++)\r
- {\r
- if (entries[i].id == id) return i;\r
- }\r
-\r
- printf("%s: id %i not found\n", __FUNCTION__, id);\r
- return 0;\r
-}\r
-\r
-static void me_enable(menu_entry *entries, int count, menu_id id, int enable)\r
-{\r
- int i = me_id2offset(entries, count, id);\r
- entries[i].enabled = enable;\r
-}\r
-\r
-static int me_count_enabled(const menu_entry *entries, int count)\r
-{\r
- int i, ret = 0;\r
-\r
- for (i = 0; i < count; i++)\r
- {\r
- if (entries[i].enabled) ret++;\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-static menu_id me_index2id(const menu_entry *entries, int count, int index)\r
-{\r
- int i;\r
-\r
- for (i = 0; i < count; i++)\r
- {\r
- if (entries[i].enabled)\r
- {\r
- if (index == 0) break;\r
- index--;\r
- }\r
- }\r
- if (i >= count) i = count - 1;\r
- return entries[i].id;\r
-}\r
-\r
-typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param);\r
-\r
-static void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param)\r
-{\r
- int i, y1 = y;\r
-\r
- for (i = 0; i < count; i++)\r
- {\r
- if (!entries[i].enabled) continue;\r
- if (entries[i].name == NULL)\r
- {\r
- if (cust_draw != NULL)\r
- cust_draw(&entries[i], x, y1, param);\r
- y1 += 10;\r
- continue;\r
- }\r
- text_out16(x, y1, entries[i].name);\r
- if (entries[i].beh == MB_ONOFF)\r
- text_out16(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\r
- else if (entries[i].beh == MB_RANGE)\r
- text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
- y1 += 10;\r
- }\r
-}\r
-\r
-static int me_process(menu_entry *entries, int count, menu_id id, int is_next)\r
-{\r
- int i = me_id2offset(entries, count, id);\r
- menu_entry *entry = &entries[i];\r
- switch (entry->beh)\r
- {\r
- case MB_ONOFF:\r
- *(int *)entry->var ^= entry->mask;\r
- return 1;\r
- case MB_RANGE:\r
- *(int *)entry->var += is_next ? 1 : -1;\r
- if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min;\r
- if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max;\r
- return 1;\r
- default:\r
- return 0;\r
- }\r
-}\r
-\r
-\r
-static int parse_hex_color(char *buff)\r
-{\r
- char *endp = buff;\r
- int t = (int) strtoul(buff, &endp, 16);\r
- if (endp != buff) return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f);\r
- return -1;\r
-}\r
-\r
-void menu_init(void)\r
-{\r
- int c, l;\r
- unsigned char *fd = menu_font_data;\r
- char buff[256];\r
- FILE *f;\r
-\r
- // generate default font from fontdata8x8\r
- memset(menu_font_data, 0, sizeof(menu_font_data));\r
- for (c = 0; c < 256; c++)\r
- {\r
- for (l = 0; l < 8; l++)\r
- {\r
- unsigned char fd8x8 = fontdata8x8[c*8+l];\r
- if (fd8x8&0x80) *fd |= 0xf0;\r
- if (fd8x8&0x40) *fd |= 0x0f; fd++;\r
- if (fd8x8&0x20) *fd |= 0xf0;\r
- if (fd8x8&0x10) *fd |= 0x0f; fd++;\r
- if (fd8x8&0x08) *fd |= 0xf0;\r
- if (fd8x8&0x04) *fd |= 0x0f; fd++;\r
- if (fd8x8&0x02) *fd |= 0xf0;\r
- if (fd8x8&0x01) *fd |= 0x0f; fd++;\r
- }\r
- fd += 8*2/2; // 2 empty lines\r
- }\r
-\r
- // load custom font and selector (stored as 1st symbol in font table)\r
- readpng(menu_font_data, "skin/font.png", READPNG_FONT);\r
- memcpy(menu_font_data, menu_font_data + ((int)'>')*4*10, 4*10); // default selector symbol is '>'\r
- readpng(menu_font_data, "skin/selector.png", READPNG_SELECTOR);\r
-\r
- // load custom colors\r
- f = fopen("skin/skin.txt", "r");\r
- if (f != NULL)\r
- {\r
- printf("found skin.txt\n");\r
- while (!feof(f))\r
- {\r
- fgets(buff, sizeof(buff), f);\r
- if (buff[0] == '#' || buff[0] == '/') continue; // comment\r
- if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line\r
- if (strncmp(buff, "text_color=", 11) == 0)\r
- {\r
- int tmp = parse_hex_color(buff+11);\r
- if (tmp >= 0) menu_text_color = tmp;\r
- else printf("skin.txt: parse error for text_color\n");\r
- }\r
- else if (strncmp(buff, "selection_color=", 16) == 0)\r
- {\r
- int tmp = parse_hex_color(buff+16);\r
- if (tmp >= 0) menu_sel_color = tmp;\r
- else printf("skin.txt: parse error for selection_color\n");\r
- }\r
- else\r
- printf("skin.txt: parse error: %s\n", buff);\r
- }\r
- fclose(f);\r
- }\r
-}\r
-\r
static unsigned long inp_prev = 0;\r
static int inp_prevjoy = 0;\r
\r
return ret;\r
}\r
\r
+static void menu_flip(void)\r
+{\r
+ gp2x_video_flush_cache();\r
+ gp2x_video_flip2();\r
+}\r
\r
\r
// --------- loading ROM screen ----------\r
\r
text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");\r
\r
- draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);\r
+ menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);\r
\r
/* draw all 10 slots */\r
y = tl_y;\r
x = 40;\r
}\r
\r
- draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);\r
+ menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);\r
\r
y = tl_y;\r
for (i = 0; i < opt_cnt; i++, y+=10)\r
\r
y = tl_y;\r
gp2x_pd_clone_buffer2();\r
- draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);\r
+ menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);\r
\r
text_out16(tl_x, y, "Player 1");\r
text_out16(tl_x, (y+=10), "Player 2");\r
\r
gp2x_pd_clone_buffer2();\r
\r
- draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);\r
+ menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);\r
\r
me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);\r
\r
{\r
{ NULL, MB_NONE, MA_OPT2_GAMMA, NULL, 0, 0, 0, 1 },\r
{ "A_SN's gamma curve", MB_ONOFF, MA_OPT2_A_SN_GAMMA, ¤tConfig.EmuOpt, 0x1000, 0, 0, 1 },\r
- { "Perfecf vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 },\r
+ { "Perfect vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 },\r
{ "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 },\r
{ "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 },\r
{ "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 },\r
\r
gp2x_pd_clone_buffer2();\r
\r
- draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);\r
+ menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);\r
\r
me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);\r
\r
\r
gp2x_pd_clone_buffer2();\r
\r
- draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);\r
+ menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);\r
\r
me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);\r
\r
\r
text_out16(tl_x, 20, "PicoDrive v" VERSION);\r
\r
- draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);\r
+ menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);\r
\r
me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);\r
\r
char curr_path[PATH_MAX], *selfname;\r
FILE *tstf;\r
\r
- gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
+ gp2x_memset_all_buffers(0, 0, 320*240*2);\r
menu_gfx_prepare();\r
\r
if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
\r
extern char menuErrorMsg[40];\r
\r
-void menu_init(void);\r
-void text_out16(int x, int y, const char *texto, ...);\r
void menu_loop(void);\r
int menu_loop_tray(void);\r
void menu_romload_prepare(const char *rom_name);\r
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 \