some skinning capabilities
authornotaz <notasas@gmail.com>
Fri, 24 Aug 2007 20:47:28 +0000 (20:47 +0000)
committernotaz <notasas@gmail.com>
Fri, 24 Aug 2007 20:47:28 +0000 (20:47 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@225 be3aeb3a-fb24-0410-a615-afba39da0efa

21 files changed:
Pico/Pico.c
Pico/Pico.h
platform/gp2x/940ctl.c
platform/gp2x/Makefile
platform/gp2x/asmutils.h
platform/gp2x/asmutils.s
platform/gp2x/emu.c
platform/gp2x/gp2x.c
platform/gp2x/gp2x.h
platform/gp2x/main.c
platform/gp2x/menu.c
platform/gp2x/menu.h
platform/gp2x/readpng.c [new file with mode: 0644]
platform/gp2x/readpng.h [new file with mode: 0644]
platform/linux/Makefile
platform/linux/gp2x.c
platform/readme.txt
skin/background.png [new file with mode: 0644]
skin/font.png [new file with mode: 0644]
skin/selector.png [new file with mode: 0644]
skin/skin.txt [new file with mode: 0644]

index 62b1b48..e6a3b29 100644 (file)
@@ -653,6 +653,13 @@ int PicoFrame(void)
   return 0;\r
 }\r
 \r
+void PicoFrameDrawOnly(void)\r
+{\r
+  int y;\r
+  PicoFrameStart();\r
+  for (y=0;y<224;y++) PicoLine(y);\r
+}\r
+\r
 // callback to output message from emu\r
 void (*PicoMessage)(const char *msg)=NULL;\r
 \r
index ec5148b..a646d5b 100644 (file)
@@ -41,6 +41,7 @@ int PicoInit(void);
 void PicoExit(void);\r
 int PicoReset(int hard);\r
 int PicoFrame(void);\r
+void PicoFrameDrawOnly(void);\r
 extern int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU\r
 extern void (*PicoWriteSound)(int len); // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
 extern void (*PicoMessage)(const char *msg); // callback to output text message from emu\r
index 54b83b6..66a5d2b 100644 (file)
@@ -415,10 +415,10 @@ void YM2612Init_940(int baseclock, int rate)
                fp = fopen(binpath, "rb");\r
                if(!fp)\r
                {\r
-                       memset(gp2x_screen, 0, 320*240);\r
-                       gp2x_text_out8(10, 100, "failed to open required file:");\r
-                       gp2x_text_out8(10, 110, CODE940_FILE);\r
-                       gp2x_video_flip();\r
+                       memset(gp2x_screen, 0, 320*240*2);\r
+                       text_out16(10, 100, "failed to open required file:");\r
+                       text_out16(10, 110, CODE940_FILE);\r
+                       gp2x_video_flip2();\r
                        printf("failed to open %s\n", binpath);\r
                        exit(1);\r
                }\r
index 489d62f..e9ffd46 100644 (file)
@@ -47,7 +47,7 @@ LD = $(CROSS)ld
 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\r
+OBJS += main.o menu.o fonts.o gp2x.o usbjoy.o emu.o squidgehack.o asmutils.o cpuctrl.o readpng.o\r
 # 940 core control\r
 OBJS += 940ctl.o\r
 # Pico\r
@@ -121,7 +121,7 @@ all: PicoDrive.gpe
 \r
 PicoDrive.gpe : $(OBJS) helix/helix_mp3.a\r
        @echo $@\r
-       @$(GCC) -o $@ $(COPT) $^ -lm -Wl,-Map=PicoDrive.map\r
+       @$(GCC) -o $@ $(COPT) $^ -lm -lpng -Wl,-Map=PicoDrive.map\r
 ifeq ($(DEBUG),)\r
        @$(STRIP) $@\r
 endif\r
@@ -212,6 +212,7 @@ endif
 \r
 rel: PicoDrive.gpe code940/pico940.bin ../readme.txt config.txt PicoDrive.man.txt PicoDrive.png\r
        zip -9 -j ../../PicoDrive_$(VER).zip $^ mmuhack.o\r
+       zip -9 PicoDrive_$(VER).zip skin\r
 \r
 code940/code940.bin:\r
        make -C code940/\r
index cade08c..902064a 100644 (file)
@@ -10,5 +10,5 @@ void vidCpyM2_40col(void *dest, void *src);
 void vidCpyM2_32col(void *dest, void *src);\r
 void vidCpyM2_32col_nobord(void *dest, void *src);\r
 void spend_cycles(int c); // utility\r
-void flushcache(void);\r
+void flushcache(void *beginning_addr, void *end_addr, unsigned int flags);\r
 \r
index e4402ff..787ecb9 100644 (file)
@@ -211,7 +211,6 @@ spend_cycles:
     bx      lr\r
 \r
 \r
-@ test\r
 .global flushcache\r
 \r
 flushcache:\r
index bfbc0c1..939ba93 100644 (file)
@@ -20,6 +20,7 @@
 #include "menu.h"\r
 #include "asmutils.h"\r
 #include "cpuctrl.h"\r
+#include "fonts.h"\r
 \r
 #include <Pico/PicoInt.h>\r
 #include <Pico/Patch.h>\r
@@ -634,6 +635,53 @@ void emu_Deinit(void)
                set_gamma(100, 0);\r
 }\r
 \r
+static void text_out8_builtin(int x, int y, const char *text)\r
+{\r
+       int i,l,len=strlen(text);\r
+       unsigned char *screen = (unsigned char *)gp2x_screen + x + y*320;\r
+\r
+       /* always using built-in font */\r
+       for (i = 0; i < len; i++)\r
+       {\r
+               for (l=0;l<8;l++)\r
+               {\r
+                       unsigned char fd = fontdata8x8[((text[i])*8)+l];\r
+                       if (fd&0x80) screen[l*320+0]=0xf0;\r
+                       if (fd&0x40) screen[l*320+1]=0xf0;\r
+                       if (fd&0x20) screen[l*320+2]=0xf0;\r
+                       if (fd&0x10) screen[l*320+3]=0xf0;\r
+                       if (fd&0x08) screen[l*320+4]=0xf0;\r
+                       if (fd&0x04) screen[l*320+5]=0xf0;\r
+                       if (fd&0x02) screen[l*320+6]=0xf0;\r
+                       if (fd&0x01) screen[l*320+7]=0xf0;\r
+               }\r
+               screen += 8;\r
+       }\r
+}\r
+\r
+static void text_out16_builtin(int x, int y, const char *text)\r
+{\r
+       int i,l,len=strlen(text);\r
+       unsigned short *screen = (unsigned short *)gp2x_screen + x + y*320;\r
+\r
+       for (i = 0; i < len; i++)\r
+       {\r
+               for (l=0;l<8;l++)\r
+               {\r
+                       unsigned char fd = fontdata8x8[((text[i])*8)+l];\r
+                       if(fd&0x80) screen[l*320+0]=0xffff;\r
+                       if(fd&0x40) screen[l*320+1]=0xffff;\r
+                       if(fd&0x20) screen[l*320+2]=0xffff;\r
+                       if(fd&0x10) screen[l*320+3]=0xffff;\r
+                       if(fd&0x08) screen[l*320+4]=0xffff;\r
+                       if(fd&0x04) screen[l*320+5]=0xffff;\r
+                       if(fd&0x02) screen[l*320+6]=0xffff;\r
+                       if(fd&0x01) screen[l*320+7]=0xffff;\r
+               }\r
+               screen += 8;\r
+       }\r
+}\r
+\r
 \r
 void osd_text(int x, int y, const char *text)\r
 {\r
@@ -647,7 +695,7 @@ void osd_text(int x, int y, const char *text)
                        p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h));\r
                        for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
                }\r
-               gp2x_text_out8_2(x, y, text, 0xf0);\r
+               text_out8_builtin(x, y, text);\r
        } else {\r
                int *p, i, h;\r
                x &= ~1; // align x\r
@@ -656,7 +704,7 @@ void osd_text(int x, int y, const char *text)
                        p = (int *) ((unsigned short *) gp2x_screen+x+320*(y+h));\r
                        for (i = len; i; i--, p++) *p = (*p>>2)&0x39e7;\r
                }\r
-               gp2x_text_out15(x, y, text);\r
+               text_out16_builtin(x, y, text);\r
        }\r
 }\r
 \r
@@ -794,7 +842,7 @@ static void vidResetMode(void)
        if (PicoOpt&0x10) {\r
                gp2x_video_changemode(8);\r
        } else if (currentConfig.EmuOpt&0x80) {\r
-               gp2x_video_changemode(15);\r
+               gp2x_video_changemode(16);\r
                PicoDrawSetColorFormat(1);\r
                PicoScan = EmuScan16;\r
                PicoScan(0, 0);\r
@@ -1045,10 +1093,20 @@ static void SkipFrame(int do_audio)
 void emu_forced_frame(void)\r
 {\r
        int po_old = PicoOpt;\r
+       int eo_old = currentConfig.EmuOpt;\r
+\r
+       PicoOpt &= ~0x0010;\r
+       PicoOpt |=  0x4080; // soft_scale | acc_sprites\r
+       currentConfig.EmuOpt |= 0x80;\r
 \r
-       PicoOpt |= 0x10;\r
-       PicoFrameFull();\r
+       //vidResetMode();\r
+       PicoDrawSetColorFormat(1);\r
+       PicoScan = EmuScan16;\r
+       PicoScan(0, 0);\r
+       Pico.m.dirtyPal = 1;\r
+       PicoFrameDrawOnly();\r
 \r
+/*\r
        if (!(Pico.video.reg[12]&1)) {\r
                vidCpyM2 = vidCpyM2_32col;\r
                clearArea(1);\r
@@ -1057,8 +1115,9 @@ void emu_forced_frame(void)
        vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
        vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
        gp2x_video_setpalette(localPal, 0x40);\r
-\r
+*/\r
        PicoOpt = po_old;\r
+       currentConfig.EmuOpt = eo_old;\r
 }\r
 \r
 static void simpleWait(int thissec, int lim_time)\r
@@ -1375,12 +1434,9 @@ if (Pico.m.frame_count == 31563) {
                SRam.changed = 0;\r
        }\r
 \r
-       // if in 16bit mode, generate 8it image for menu background\r
-       if (!(PicoOpt&0x10) && (currentConfig.EmuOpt&0x80))\r
+       // if in 8bit mode, generate 16bit image for menu background\r
+       if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80))\r
                emu_forced_frame();\r
-\r
-       // for menu bg\r
-       gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);\r
 }\r
 \r
 \r
index c0396d9..3b5d125 100644 (file)
@@ -157,6 +157,15 @@ void gp2x_video_wait_vsync(void)
 }\r
 \r
 \r
+void gp2x_video_flush_cache(void)\r
+{\r
+       // since we are using the mmu hack, we must flush the cache first\r
+       // (the params are most likely wrong, but they seem to work somehow)\r
+       //flushcache(addr, addr + 320*240*2, 0);\r
+       flushcache(gp2x_screen, (char *)gp2x_screen + 320*240*2, 0);\r
+}\r
+\r
+\r
 void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)\r
 {\r
        char *dst;\r
@@ -184,9 +193,7 @@ void gp2x_memset_all_buffers(int offset, int byte, int len)
 \r
 void gp2x_pd_clone_buffer2(void)\r
 {\r
-       memcpy(gp2x_screen, gp2x_screens[2], 320*240);\r
-       memset(gp2x_screen, 0xe0, 320*8);\r
-       memset(gp2x_screen + 320*232, 0xe0, 320*8);\r
+       memcpy(gp2x_screen, gp2x_screens[2], 320*240*2);\r
 }\r
 \r
 \r
index 349b898..2d2e535 100644 (file)
@@ -14,6 +14,7 @@ void gp2x_video_changemode2(int bpp);
 void gp2x_video_setpalette(int *pal, int len);\r
 void gp2x_video_RGB_setscaling(int ln_offs, int W, int H);\r
 void gp2x_video_wait_vsync(void);\r
+void gp2x_video_flush_cache(void);\r
 void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len);\r
 void gp2x_memcpy_all_buffers(void *data, int offset, int len);\r
 void gp2x_memset_all_buffers(int offset, int byte, int len);\r
index d6438f6..e4e3bcf 100644 (file)
@@ -97,6 +97,7 @@ int main(int argc, char *argv[])
        }\r
        sharedmem_init();\r
        emu_Init();\r
+       menu_init();\r
 \r
        engineState = PGS_Menu;\r
 \r
index 06a3e3d..b45b295 100644 (file)
@@ -16,6 +16,7 @@
 #include "fonts.h"\r
 #include "usbjoy.h"\r
 #include "asmutils.h"\r
+#include "readpng.h"\r
 #include "version.h"\r
 \r
 #include <Pico/PicoInt.h>\r
@@ -32,66 +33,71 @@ extern int  mmuhack_status;
 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
        "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);\r
+static void menu_prepare_bg(int use_game_bg);\r
 \r
-static void gp2x_text(unsigned char *screen, int x, int y, const char *text, int color)\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;\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
-       screen = screen + x + y*320;\r
-\r
-       for (i = 0; i < strlen(text); i++)\r
+       if (text == (void *)1)\r
        {\r
-               for (l=0;l<8;l++)\r
-               {\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;\r
-               }\r
-               screen += 8;\r
+               // selector symbol\r
+               text = "";\r
+               len = 1;\r
        }\r
-}\r
-\r
-// draws white text to current bbp15 screen\r
-void gp2x_text_out15(int x, int y, const char *text)\r
-{\r
-       int i,l;\r
-       unsigned short *screen = gp2x_screen;\r
-\r
-       screen = screen + x + y*320;\r
+       else\r
+               len = strlen(text);\r
 \r
-       for (i = 0; i < strlen(text); i++)\r
+       for (i = 0; i < len; i++)\r
        {\r
-               for (l=0;l<8;l++)\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
-                       if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;\r
-                       if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;\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
-               screen += 8;\r
+               dest += 8;\r
        }\r
 }\r
 \r
-\r
-void gp2x_text_out8(int x, int y, const char *texto, ...)\r
+void text_out16(int x, int y, const char *texto, ...)\r
 {\r
        va_list args;\r
        char    buffer[512];\r
@@ -100,31 +106,15 @@ void gp2x_text_out8(int x, int y, const char *texto, ...)
        vsprintf(buffer,texto,args);\r
        va_end(args);\r
 \r
-       gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r
-}\r
-\r
-\r
-void gp2x_text_out8_2(int x, int y, const char *texto, int color)\r
-{\r
-       gp2x_text(gp2x_screen, x, y, texto, color);\r
+       text_out16_(x,y,buffer,menu_text_color);\r
 }\r
 \r
-void gp2x_text_out8_lim(int x, int y, const char *texto, int max)\r
-{\r
-       char    buffer[320/8+1];\r
-\r
-       strncpy(buffer, texto, 320/8);\r
-       if (max > 320/8) max = 320/8;\r
-       if (max < 0) max = 0;\r
-       buffer[max] = 0;\r
 \r
-       gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r
-}\r
-\r
-static void gp2x_smalltext8(int x, int y, const char *texto)\r
+static void smalltext_out16(int x, int y, const char *texto, int color)\r
 {\r
        int i;\r
-       unsigned char *src, *dst;\r
+       unsigned char  *src;\r
+       unsigned short *dst;\r
 \r
        for (i = 0;; i++, x += 6)\r
        {\r
@@ -134,14 +124,14 @@ static void gp2x_smalltext8(int x, int y, const char *texto)
                if (!c) break;\r
 \r
                src = fontdata6x8[c];\r
-               dst = (unsigned char *)gp2x_screen + x + y*320;\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 = 0xf0;\r
+                               if( *src & w ) *dst = color;\r
                                dst++;\r
                                w>>=1;\r
                        }\r
@@ -152,7 +142,7 @@ static void gp2x_smalltext8(int x, int y, const char *texto)
        }\r
 }\r
 \r
-static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)\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
@@ -161,7 +151,33 @@ static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)
        if (max < 0) max = 0;\r
        buffer[max] = 0;\r
 \r
-       gp2x_smalltext8(x, y, buffer);\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
@@ -303,11 +319,11 @@ static void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_
                        y1 += 10;\r
                        continue;\r
                }\r
-               gp2x_text_out8(x, y1, entries[i].name);\r
+               text_out16(x, y1, entries[i].name);\r
                if (entries[i].beh == MB_ONOFF)\r
-                       gp2x_text_out8(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\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
-                       gp2x_text_out8(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
+                       text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
                y1 += 10;\r
        }\r
 }\r
@@ -332,7 +348,73 @@ static int me_process(menu_entry *entries, int count, menu_id id, int is_next)
 }\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
@@ -425,12 +507,12 @@ static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
 static void load_progress_cb(int percent)\r
 {\r
        int ln, len = percent * 320 / 100;\r
-       unsigned char *dst = (unsigned char *)gp2x_screen + 320*20;\r
+       unsigned short *dst = (unsigned short *)gp2x_screen + 320*20;\r
 \r
        if (len > 320) len = 320;\r
        for (ln = 10; ln > 0; ln--, dst += 320)\r
-               memset(dst, 0xf0, len);\r
-       gp2x_video_flip2();\r
+               memset(dst, 0xff, len*2);\r
+       menu_flip();\r
 }\r
 \r
 void menu_romload_prepare(const char *rom_name)\r
@@ -438,23 +520,41 @@ void menu_romload_prepare(const char *rom_name)
        const char *p = rom_name + strlen(rom_name);\r
        while (p > rom_name && *p != '/') p--;\r
 \r
-       gp2x_pd_clone_buffer2();\r
-       gp2x_smalltext8(1, 1, "Loading");\r
-       gp2x_smalltext8_lim(1, 10, p, 53);\r
-       gp2x_memcpy_buffers(3, gp2x_screen, 0, 320*240);\r
-       gp2x_video_flip2();\r
+       if (rom_data) gp2x_pd_clone_buffer2();\r
+       else memset(gp2x_screen, 0, 320*240*2);\r
+\r
+       smalltext_out16(1, 1, "Loading", 0xffff);\r
+       smalltext_out16_lim(1, 10, p, 0xffff, 53);\r
+       gp2x_memcpy_buffers(3, gp2x_screen, 0, 320*240*2);\r
+       menu_flip();\r
        PicoCartLoadProgressCB = load_progress_cb;\r
 }\r
 \r
 void menu_romload_end(void)\r
 {\r
        PicoCartLoadProgressCB = NULL;\r
-       gp2x_smalltext8(1, 30, "Starting emulation...");\r
-       gp2x_video_flip2();\r
+       smalltext_out16(1, 30, "Starting emulation...", 0xffff);\r
+       menu_flip();\r
 }\r
 \r
 // -------------- ROM selector --------------\r
 \r
+// rrrr rggg gggb bbbb\r
+static unsigned short file2color(const char *fname)\r
+{\r
+       const char *ext = fname + strlen(fname) - 3;\r
+       static const char *rom_exts[]   = { "zip", "bin", "smd", "gen", "iso" };\r
+       static const char *other_exts[] = { "gmv", "pat" };\r
+       int i;\r
+\r
+       if (ext < fname) ext = fname;\r
+       for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)\r
+               if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;\r
+       for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)\r
+               if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;\r
+       return 0xffff;\r
+}\r
+\r
 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
 {\r
        int start, i, pos;\r
@@ -462,23 +562,31 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
        start = 12 - sel;\r
        n--; // exclude current dir (".")\r
 \r
-       gp2x_pd_clone_buffer2();\r
+       if (rom_data)\r
+               gp2x_pd_clone_buffer2();\r
+       else {\r
+               memset(gp2x_screen, 0, 320*240*2);\r
+               memset((char *)gp2x_screen + 320*120*2, 0xff, 320*8*2);\r
+       }\r
+\r
+       menu_darken_bg((char *)gp2x_screen + 320*120*2, 320*8);\r
 \r
        if(start - 2 >= 0)\r
-               gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);\r
+               smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);\r
        for (i = 0; i < n; i++) {\r
                pos = start + i;\r
                if (pos < 0)  continue;\r
                if (pos > 23) break;\r
                if (namelist[i+1]->d_type == DT_DIR) {\r
-                       gp2x_smalltext8_lim(14,   pos*10, "/", 1);\r
-                       gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);\r
+                       smalltext_out16_lim(14,   pos*10, "/", 0xfff6, 1);\r
+                       smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);\r
                } else {\r
-                       gp2x_smalltext8_lim(14,   pos*10, namelist[i+1]->d_name, 53-2);\r
+                       unsigned short color = file2color(namelist[i+1]->d_name);\r
+                       smalltext_out16_lim(14,   pos*10, namelist[i+1]->d_name, color, 53-2);\r
                }\r
        }\r
-       gp2x_text_out8(5, 120, ">");\r
-       gp2x_video_flip2();\r
+       text_out16(5, 120, ">");\r
+       menu_flip();\r
 }\r
 \r
 static int scandir_cmp(const void *p1, const void *p2)\r
@@ -637,11 +745,11 @@ static void draw_debug(void)
                while (*p && *p != '\n') p++;\r
                len = p - str;\r
                if (len > 55) len = 55;\r
-               gp2x_smalltext8_lim(1, line*10, str, len);\r
+               smalltext_out16_lim(1, line*10, str, 0xffff, len);\r
                if (*p == 0) break;\r
                p++; str = p;\r
        }\r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 static void debug_menu_loop(void)\r
@@ -654,7 +762,7 @@ static void debug_menu_loop(void)
 \r
 static void draw_patchlist(int sel)\r
 {\r
-       int start, i, pos;\r
+       int start, i, pos, active;\r
 \r
        start = 12 - sel;\r
 \r
@@ -664,14 +772,15 @@ static void draw_patchlist(int sel)
                pos = start + i;\r
                if (pos < 0)  continue;\r
                if (pos > 23) break;\r
-               gp2x_smalltext8_lim(14,     pos*10, PicoPatches[i].active ? "ON " : "OFF", 3);\r
-               gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);\r
+               active = PicoPatches[i].active;\r
+               smalltext_out16_lim(14,     pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);\r
+               smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);\r
        }\r
        pos = start + i;\r
-       if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4);\r
+       if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);\r
 \r
-       gp2x_text_out8(5, 120, ">");\r
-       gp2x_video_flip2();\r
+       text_out16(5, 120, ">");\r
+       menu_flip();\r
 }\r
 \r
 \r
@@ -700,8 +809,6 @@ static void patches_menu_loop(void)
 \r
 // ------------ savestate loader ------------\r
 \r
-static void menu_prepare_bg(void);\r
-\r
 static int state_slot_flags = 0;\r
 \r
 static void state_check_slots(void)\r
@@ -762,8 +869,7 @@ static void draw_savestate_bg(int slot)
        }\r
 \r
        emu_forced_frame();\r
-       gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);\r
-       menu_prepare_bg();\r
+       menu_prepare_bg(1);\r
 \r
        memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
        memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));\r
@@ -780,20 +886,19 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
                draw_savestate_bg(menu_sel);\r
        gp2x_pd_clone_buffer2();\r
 \r
-       gp2x_text_out8(tl_x, 30, is_loading ? "Load state" : "Save state");\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
 \r
        /* draw all 10 slots */\r
        y = tl_y;\r
        for (i = 0; i < 10; i++, y+=10)\r
        {\r
-               gp2x_text_out8(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
+               text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
        }\r
-       gp2x_text_out8(tl_x, y, "back");\r
+       text_out16(tl_x, y, "back");\r
 \r
-       // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
-\r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 static int savestate_menu_loop(int is_loading)\r
@@ -918,33 +1023,32 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i
 \r
        gp2x_pd_clone_buffer2();\r
        if (player_idx >= 0) {\r
-               gp2x_text_out8(80, 20, "Player %i controls", player_idx + 1);\r
+               text_out16(80, 20, "Player %i controls", player_idx + 1);\r
                x = 100;\r
        } else {\r
-               gp2x_text_out8(80, 20, "Emulator controls");\r
+               text_out16(80, 20, "Emulator controls");\r
                x = 40;\r
        }\r
 \r
+       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
-               gp2x_text_out8(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));\r
+               text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));\r
 \r
-       gp2x_text_out8(x, y, "Done");\r
-\r
-       // draw cursor\r
-       gp2x_text_out8(x - 16, tl_y + sel*10, ">");\r
+       text_out16(x, y, "Done");\r
 \r
        if (sel < opt_cnt) {\r
-               gp2x_text_out8(30, 190, "Press a button to bind/unbind");\r
-               gp2x_text_out8(30, 200, "Use SELECT to clear");\r
-               gp2x_text_out8(30, 210, "To bind UP/DOWN, hold SELECT");\r
-               gp2x_text_out8(30, 220, "Select \"Done\" to exit");\r
+               text_out16(30, 180, "Press a button to bind/unbind");\r
+               text_out16(30, 190, "Use SELECT to clear");\r
+               text_out16(30, 200, "To bind UP/DOWN, hold SELECT");\r
+               text_out16(30, 210, "Select \"Done\" to exit");\r
        } else {\r
-               gp2x_text_out8(30, 200, "Use Options -> Save cfg");\r
-               gp2x_text_out8(30, 210, "to save controls");\r
-               gp2x_text_out8(30, 220, "Press B or X to exit");\r
+               text_out16(30, 190, "Use Options -> Save cfg");\r
+               text_out16(30, 200, "to save controls");\r
+               text_out16(30, 210, "Press B or X to exit");\r
        }\r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)\r
@@ -1007,26 +1111,25 @@ static void draw_kc_sel(int menu_sel)
 \r
        y = tl_y;\r
        gp2x_pd_clone_buffer2();\r
-       gp2x_text_out8(tl_x, y,       "Player 1");\r
-       gp2x_text_out8(tl_x, (y+=10), "Player 2");\r
-       gp2x_text_out8(tl_x, (y+=10), "Emulator controls");\r
-       gp2x_text_out8(tl_x, (y+=10), "Done");\r
+       draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);\r
 \r
-       // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+       text_out16(tl_x, y,       "Player 1");\r
+       text_out16(tl_x, (y+=10), "Player 2");\r
+       text_out16(tl_x, (y+=10), "Emulator controls");\r
+       text_out16(tl_x, (y+=10), "Done");\r
 \r
        tl_x = 25;\r
-       gp2x_text_out8(tl_x, (y=110), "USB joys detected:");\r
+       text_out16(tl_x, (y=110), "USB joys detected:");\r
        if (num_of_joys > 0) {\r
                for (i = 0; i < num_of_joys; i++) {\r
                        strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;\r
-                       gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);\r
+                       text_out16(tl_x, (y+=10), "%i: %s", i+1, joyname);\r
                }\r
        } else {\r
-               gp2x_text_out8(tl_x, (y+=10), "none");\r
+               text_out16(tl_x, (y+=10), "none");\r
        }\r
 \r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 \r
@@ -1052,13 +1155,13 @@ static bind_action_t ctrl_actions[] =
 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
 static bind_action_t emuctrl_actions[] =\r
 {\r
-       { "Volume Down    ", 1<<30 },\r
-       { "Volume Up      ", 1<<29 },\r
        { "Load State     ", 1<<28 },\r
        { "Save State     ", 1<<27 },\r
-       { "Switch Renderer", 1<<26 },\r
        { "Prev Save Slot ", 1<<25 },\r
        { "Next Save Slot ", 1<<24 },\r
+       { "Switch Renderer", 1<<26 },\r
+       { "Volume Down    ", 1<<30 },\r
+       { "Volume Up      ", 1<<29 },\r
        { "Enter Menu     ", 1<<23 },\r
 };\r
 \r
@@ -1121,13 +1224,13 @@ static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *pa
 \r
        switch (entry->id)\r
        {\r
-               case MA_CDOPT_TESTBIOS_USA: gp2x_text_out8(x, y, "USA BIOS:     %s", bios_names->us); break;\r
-               case MA_CDOPT_TESTBIOS_EUR: gp2x_text_out8(x, y, "EUR BIOS:     %s", bios_names->eu); break;\r
-               case MA_CDOPT_TESTBIOS_JAP: gp2x_text_out8(x, y, "JAP BIOS:     %s", bios_names->jp); break;\r
+               case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS:     %s", bios_names->us); break;\r
+               case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS:     %s", bios_names->eu); break;\r
+               case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS:     %s", bios_names->jp); break;\r
                case MA_CDOPT_READAHEAD:\r
                        if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r
                        else strcpy(ra_buff, "     OFF");\r
-                       gp2x_text_out8(x, y, "ReadAhead buffer      %s", ra_buff);\r
+                       text_out16(x, y, "ReadAhead buffer      %s", ra_buff);\r
                        break;\r
                default:break;\r
        }\r
@@ -1144,18 +1247,17 @@ static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)
 \r
        gp2x_pd_clone_buffer2();\r
 \r
-       me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);\r
+       draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);\r
 \r
-       // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+       me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);\r
 \r
        selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r
        if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||\r
                (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||\r
                (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))\r
-                       gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r
+                       text_out16(tl_x, 210, "Press start to test selected BIOS");\r
 \r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 static void cd_menu_loop_options(void)\r
@@ -1263,9 +1365,9 @@ menu_entry opt2_entries[] =
 static void menu_opt2_cust_draw(const menu_entry *entry, int x, int y, void *param)\r
 {\r
        if (entry->id == MA_OPT2_GAMMA)\r
-               gp2x_text_out8(x, y, "Gamma correction           %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r
+               text_out16(x, y, "Gamma correction           %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r
        else if (entry->id == MA_OPT2_SQUIDGEHACK)\r
-               gp2x_text_out8(x, y, "squidgehack (now %s %s", mmuhack_status ? "active)  " : "inactive)",\r
+               text_out16(x, y, "squidgehack (now %s %s", mmuhack_status ? "active)  " : "inactive)",\r
                        (currentConfig.EmuOpt&0x0010)?"ON":"OFF");\r
 }\r
 \r
@@ -1276,12 +1378,11 @@ static void draw_amenu_options(int menu_sel)
 \r
        gp2x_pd_clone_buffer2();\r
 \r
-       me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);\r
+       draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);\r
 \r
-       // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+       me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);\r
 \r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 static void amenu_loop_options(void)\r
@@ -1388,7 +1489,7 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
                                str = "16bit accurate";\r
                        else\r
                                str = " 8bit accurate";\r
-                       gp2x_text_out8(x, y, "Renderer:            %s", str);\r
+                       text_out16(x, y, "Renderer:            %s", str);\r
                        break;\r
                case MA_OPT_SCALING:\r
                        switch (currentConfig.scaling) {\r
@@ -1397,20 +1498,20 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
                                case 2:  str = "hw horiz. + vert."; break;\r
                                case 3:  str = "sw horizontal";     break;\r
                        }\r
-                       gp2x_text_out8(x, y, "Scaling:       %s", str);\r
+                       text_out16(x, y, "Scaling:       %s", str);\r
                        break;\r
                case MA_OPT_FRAMESKIP:\r
                        if (currentConfig.Frameskip < 0)\r
                             strcpy(str24, "Auto");\r
                        else sprintf(str24, "%i", currentConfig.Frameskip);\r
-                       gp2x_text_out8(x, y, "Frameskip                  %s", str24);\r
+                       text_out16(x, y, "Frameskip                  %s", str24);\r
                        break;\r
                case MA_OPT_SOUND_QUALITY:\r
                        str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";\r
-                       gp2x_text_out8(x, y, "Sound Quality:     %5iHz %s", currentConfig.PsndRate, str);\r
+                       text_out16(x, y, "Sound Quality:     %5iHz %s", currentConfig.PsndRate, str);\r
                        break;\r
                case MA_OPT_REGION:\r
-                       gp2x_text_out8(x, y, "Region:              %s", region_name(currentConfig.PicoRegion));\r
+                       text_out16(x, y, "Region:              %s", region_name(currentConfig.PicoRegion));\r
                        break;\r
                case MA_OPT_CONFIRM_STATES:\r
                        switch ((currentConfig.EmuOpt >> 9) & 5) {\r
@@ -1419,18 +1520,18 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
                                case 4:  str = "loads";  break;\r
                                case 5:  str = "both";   break;\r
                        }\r
-                       gp2x_text_out8(x, y, "Confirm savestate          %s", str);\r
+                       text_out16(x, y, "Confirm savestate          %s", str);\r
                        break;\r
                case MA_OPT_CPU_CLOCKS:\r
-                       gp2x_text_out8(x, y, "GP2X CPU clocks            %iMhz", currentConfig.CPUclock);\r
+                       text_out16(x, y, "GP2X CPU clocks            %iMhz", currentConfig.CPUclock);\r
                        break;\r
                case MA_OPT_SAVECFG:\r
                        str24[0] = 0;\r
                        if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);\r
-                       gp2x_text_out8(x, y, "Save cfg as default%s", str24);\r
+                       text_out16(x, y, "Save cfg as default%s", str24);\r
                        break;\r
                case MA_OPT_LOADCFG:\r
-                       gp2x_text_out8(x, y, "Load cfg from profile %i", config_slot);\r
+                       text_out16(x, y, "Load cfg from profile %i", config_slot);\r
                        break;\r
                default:\r
                        printf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);\r
@@ -1442,16 +1543,15 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
 \r
 static void draw_menu_options(int menu_sel)\r
 {\r
-       int tl_x = 25, tl_y = 32;\r
+       int tl_x = 25, tl_y = 24;\r
 \r
        gp2x_pd_clone_buffer2();\r
 \r
-       me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);\r
+       draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);\r
 \r
-       // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+       me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);\r
 \r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 static int sndrate_prevnext(int rate, int dir)\r
@@ -1635,28 +1735,28 @@ static int menu_loop_options(void)
 \r
 static void draw_menu_credits(void)\r
 {\r
-       int tl_x = 15, tl_y = 70, y;\r
-       //memset(gp2x_screen, 0, 320*240);\r
+       int tl_x = 15, tl_y = 64, y;\r
        gp2x_pd_clone_buffer2();\r
 \r
-       gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r
+       text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r
        y = tl_y;\r
-       gp2x_text_out8(tl_x, y, "Credits:");\r
-       gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r
-       gp2x_text_out8(tl_x, (y+=10), "      base code of PicoDrive");\r
-       gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r
-       gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r
-       gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r
-       gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");\r
-       gp2x_text_out8(tl_x, (y+=10), "      opensource Gens");\r
-       gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");\r
-       gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");\r
-       gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");\r
-       gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");\r
-       gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");\r
-       gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");\r
-\r
-       gp2x_video_flip2();\r
+       text_out16(tl_x, y, "Credits:");\r
+       text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r
+       text_out16(tl_x, (y+=10), "      base code of PicoDrive");\r
+       text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r
+       text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r
+       text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r
+       text_out16(tl_x, (y+=10), "Stephane Dallongeville:");\r
+       text_out16(tl_x, (y+=10), "      opensource Gens");\r
+       text_out16(tl_x, (y+=10), "Haze: Genesis hw info");\r
+       text_out16(tl_x, (y+=10), "rlyeh and others: minimal SDK");\r
+       text_out16(tl_x, (y+=10), "Squidge: squidgehack");\r
+       text_out16(tl_x, (y+=10), "Dzz: ARM940 sample");\r
+       text_out16(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");\r
+       text_out16(tl_x, (y+=10), "craigix: GP2X hardware");\r
+       text_out16(tl_x, (y+=10), "ketch: skin design");\r
+\r
+       menu_flip();\r
 }\r
 \r
 \r
@@ -1684,15 +1784,18 @@ static void draw_menu_root(int menu_sel)
 \r
        gp2x_pd_clone_buffer2();\r
 \r
-       gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);\r
+       text_out16(tl_x, 20, "PicoDrive v" VERSION);\r
+\r
+       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
-       // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
        // error\r
-       if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r
-       gp2x_video_flip2();\r
+       if (menuErrorMsg[0]) {\r
+               memset((char *)gp2x_screen + 320*224*2, 0, 320*16*2);\r
+               text_out16(5, 226, menuErrorMsg);\r
+       }\r
+       menu_flip();\r
 }\r
 \r
 \r
@@ -1701,18 +1804,6 @@ static void menu_loop_root(void)
        static int menu_sel = 0;\r
        int ret, menu_sel_max;\r
        unsigned long inp = 0;\r
-       char curr_path[PATH_MAX], *selfname;\r
-       FILE *tstf;\r
-\r
-       if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
-       {\r
-               fclose(tstf);\r
-               strcpy(curr_path, currentConfig.lastRomFile);\r
-       }\r
-       else\r
-       {\r
-               getcwd(curr_path, PATH_MAX);\r
-       }\r
 \r
        me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL);\r
        me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE,  rom_data != NULL);\r
@@ -1775,12 +1866,24 @@ static void menu_loop_root(void)
                                        }\r
                                        break;\r
                                case MA_MAIN_LOAD_ROM:\r
+                               {\r
+                                       char curr_path[PATH_MAX], *selfname;\r
+                                       FILE *tstf;\r
+                                       if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
+                                       {\r
+                                               fclose(tstf);\r
+                                               strcpy(curr_path, currentConfig.lastRomFile);\r
+                                       }\r
+                                       else\r
+                                               getcwd(curr_path, PATH_MAX);\r
                                        selfname = romsel_loop(curr_path);\r
                                        if (selfname) {\r
                                                printf("selected file: %s\n", selfname);\r
                                                engineState = PGS_ReloadRom;\r
+                                               return;\r
                                        }\r
-                                       return;\r
+                                       break;\r
+                               }\r
                                case MA_MAIN_OPTIONS:\r
                                        ret = menu_loop_options();\r
                                        if (ret == 1) continue; // status update\r
@@ -1815,31 +1918,45 @@ static void menu_loop_root(void)
        }\r
 }\r
 \r
-\r
-static void menu_prepare_bg(void)\r
+static void menu_darken_bg(void *dst, int pixels)\r
 {\r
-       extern int localPal[0x100];\r
-       int c, i;\r
+       unsigned int *screen = dst;\r
+       pixels /= 2;\r
+       while (pixels--)\r
+       {\r
+               unsigned int p = *screen;\r
+               *screen = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);\r
+               screen++;\r
+       }\r
+}\r
 \r
-       // don't clear old palette just for fun (but make it dark)\r
-       for (i = 0x100-1; i >= 0; i--) {\r
-               c = localPal[i];\r
-               localPal[i] = ((c >> 1) & 0x007f7f7f) - ((c >> 3) & 0x001f1f1f);\r
+static void menu_prepare_bg(int use_game_bg)\r
+{\r
+       if (use_game_bg)\r
+       {\r
+               // darken the active framebuffer\r
+               memset(gp2x_screen, 0, 320*8*2);\r
+               menu_darken_bg((char *)gp2x_screen + 320*8*2, 320*224);\r
+               memset((char *)gp2x_screen + 320*232*2, 0, 320*8*2);\r
+       }\r
+       else\r
+       {\r
+               // should really only happen once, on startup..\r
+               readpng(gp2x_screen, "skin/background.png", READPNG_BG);\r
        }\r
-       localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
-       localPal[0xf0] = 0x00ffffff;\r
 \r
-       gp2x_video_setpalette(localPal, 0x100);\r
+       // copy to buffer2\r
+       gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);\r
 }\r
 \r
 static void menu_gfx_prepare(void)\r
 {\r
-       menu_prepare_bg();\r
+       menu_prepare_bg(rom_data != NULL);\r
 \r
-       // switch to 8bpp\r
-       gp2x_video_changemode2(8);\r
+       // switch to 16bpp\r
+       gp2x_video_changemode2(16);\r
        gp2x_video_RGB_setscaling(0, 320, 240);\r
-       gp2x_video_flip2();\r
+       menu_flip();\r
 }\r
 \r
 \r
@@ -1858,20 +1975,20 @@ void menu_loop(void)
 static void draw_menu_tray(int menu_sel)\r
 {\r
        int tl_x = 70, tl_y = 90, y;\r
-       memset(gp2x_screen, 0xe0, 320*240);\r
+       memset(gp2x_screen, 0, 320*240*2);\r
 \r
-       gp2x_text_out8(tl_x, 20, "The unit is about to");\r
-       gp2x_text_out8(tl_x, 30, "close the CD tray.");\r
+       text_out16(tl_x, 20, "The unit is about to");\r
+       text_out16(tl_x, 30, "close the CD tray.");\r
 \r
        y = tl_y;\r
-       gp2x_text_out8(tl_x, y,       "Load new CD image");\r
-       gp2x_text_out8(tl_x, (y+=10), "Insert nothing");\r
+       text_out16(tl_x, y,       "Load new CD image");\r
+       text_out16(tl_x, (y+=10), "Insert nothing");\r
 \r
        // draw cursor\r
-       gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+       text_out16(tl_x - 16, tl_y + menu_sel*10, ">");\r
        // error\r
-       if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r
-       gp2x_video_flip2();\r
+       if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);\r
+       menu_flip();\r
 }\r
 \r
 \r
index 8c9e29b..62ec051 100644 (file)
@@ -1,13 +1,12 @@
-// (c) Copyright 2006 notaz, All rights reserved.\r
+// (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
 extern char menuErrorMsg[40];\r
 \r
-void gp2x_text_out8  (int x, int y, const char *texto, ...);\r
-void gp2x_text_out15 (int x, int y, const char *text);\r
-void gp2x_text_out8_2(int x, int y, const char *texto, int color);\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
diff --git a/platform/gp2x/readpng.c b/platform/gp2x/readpng.c
new file mode 100644 (file)
index 0000000..a890e4e
--- /dev/null
@@ -0,0 +1,143 @@
+#include <stdio.h>
+#include <string.h>
+#include <png.h>
+#include "readpng.h"
+
+void readpng(void *dest, const char *fname, readpng_what what)
+{
+       FILE *fp;
+       png_structp png_ptr = NULL;
+       png_infop info_ptr = NULL;
+       png_bytepp row_ptr = NULL;
+
+       if (dest == NULL || fname == NULL)
+       {
+               return;
+       }
+
+       fp = fopen(fname, "rb");
+       if (fp == NULL)
+       {
+               printf(__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");
+               fclose(fp);
+               return;
+       }
+
+       info_ptr = png_create_info_struct(png_ptr);
+       if (!info_ptr)
+       {
+               printf(__FILE__ ": png_create_info_struct() failed\n");
+               goto done;
+       }
+
+       // Start reading
+       png_init_io(png_ptr, fp);
+       png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_PACKING, NULL);
+       row_ptr = png_get_rows(png_ptr, info_ptr);
+       if (row_ptr == NULL)
+       {
+               printf(__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);
+
+       switch (what)
+       {
+               case READPNG_BG:
+               {
+                       int height, width, h;
+                       unsigned short *dst = dest;
+                       if (info_ptr->pixel_depth != 24)
+                       {
+                               printf(__FILE__ ": bg image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth);
+                               break;
+                       }
+                       height = info_ptr->height;
+                       if (height > 240) height = 240;
+                       width = info_ptr->width;
+                       if (width > 320) width = 320;
+
+                       for (h = 0; h < height; h++)
+                       {
+                               unsigned char *src = row_ptr[h];
+                               int len = width;
+                               while (len--)
+                               {
+                                       *dst++ = ((src[0]&0xf8)<<8) | ((src[1]&0xf8)<<3) | (src[2] >> 3);
+                                       src += 3;
+                               }
+                               dst += 320 - width;
+                       }
+                       break;
+               }
+
+               case READPNG_FONT:
+               {
+                       int x, y, x1, y1;
+                       unsigned char *dst = dest;
+                       if (info_ptr->width != 128 || info_ptr->height != 160)
+                       {
+                               printf(__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);
+                               break;
+                       }
+                       for (y = 0; y < 16; y++)
+                       {
+                               for (x = 0; x < 16; x++)
+                               {
+                                       for (y1 = 0; y1 < 10; y1++)
+                                       {
+                                               unsigned char *src = row_ptr[y*10 + y1] + x*8;
+                                               for (x1 = 8/2; x1 > 0; x1--, src+=2)
+                                                       *dst++ = ((src[0]^0xff) & 0xf0) | ((src[1]^0xff) >> 4);
+                                       }
+                               }
+                       }
+                       break;
+               }
+
+               case READPNG_SELECTOR:
+               {
+                       int x1, y1;
+                       unsigned char *dst = dest;
+                       if (info_ptr->width != 8 || info_ptr->height != 10)
+                       {
+                               printf(__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);
+                               break;
+                       }
+                       for (y1 = 0; y1 < 10; y1++)
+                       {
+                               unsigned char *src = row_ptr[y1];
+                               for (x1 = 8/2; x1 > 0; x1--, src+=2)
+                                       *dst++ = ((src[0]^0xff) & 0xf0) | ((src[1]^0xff) >> 4);
+                       }
+                       break;
+               }
+       }
+
+
+done:
+       png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : NULL, (png_infopp)NULL);
+       fclose(fp);
+}
+
+
diff --git a/platform/gp2x/readpng.h b/platform/gp2x/readpng.h
new file mode 100644 (file)
index 0000000..542a774
--- /dev/null
@@ -0,0 +1,10 @@
+typedef enum
+{
+       READPNG_BG = 1,
+       READPNG_FONT,
+       READPNG_SELECTOR
+}
+readpng_what;
+
+void readpng(void *dest, const char *fname, readpng_what what);
+
index 12b8860..5c85c5c 100644 (file)
@@ -24,7 +24,8 @@ 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
+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
 # Pico
 OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory.o ../../Pico/Misc.o \
                ../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o \
@@ -66,7 +67,7 @@ tidy:
 
 PicoDrive : $(OBJS) ../gp2x/helix/helix_mp3_x86.a
        @echo $@
-       @$(GCC) $(COPT) $^ $(LDFLAGS) -lm -Wl,-Map=PicoDrive.map -o $@
+       @$(GCC) $(COPT) $^ $(LDFLAGS) -lm -lpng -Wl,-Map=PicoDrive.map -o $@
 
 
 ../../cpu/mz80/mz80.o : ../../cpu/mz80/mz80.asm
index 199d69e..0a1c73b 100644 (file)
@@ -257,13 +257,18 @@ void gp2x_video_setpalette(int *pal, int len)
        memcpy(current_pal, pal, len*4);
 }
 
+void gp2x_video_flush_cache(void)
+{
+}
+
 void gp2x_video_RGB_setscaling(int v_offs, int W, int H)
 {
 }
 
 void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
 {
-       memcpy((char *)gp2x_screen + offset, data, len);
+       if ((char *)gp2x_screen + offset != data)
+               memcpy((char *)gp2x_screen + offset, data, len);
 }
 
 void gp2x_memcpy_all_buffers(void *data, int offset, int len)
@@ -279,7 +284,7 @@ void gp2x_memset_all_buffers(int offset, int byte, int len)
 
 void gp2x_pd_clone_buffer2(void)
 {
-       memset(gp2x_screen, 0, 320*240);
+       memset(gp2x_screen, 0, 320*240*2);
 }
 
 /* sound */
index 9a73187..4f4df8a 100644 (file)
@@ -243,6 +243,8 @@ Changelog
   + Config profiles added (press left/right when saving config).\r
   * Changed key configuration behaviour to the one from gpfce (should be more\r
     intuitive).\r
+  + Added some skinning capabilities to the menu system with default skin by\r
+    ketch. Delete skin directory if you want old behaviour.\r
 \r
 1.32\r
   + Added some new scaling options.\r
diff --git a/skin/background.png b/skin/background.png
new file mode 100644 (file)
index 0000000..7a1f5d3
Binary files /dev/null and b/skin/background.png differ
diff --git a/skin/font.png b/skin/font.png
new file mode 100644 (file)
index 0000000..c526a08
Binary files /dev/null and b/skin/font.png differ
diff --git a/skin/selector.png b/skin/selector.png
new file mode 100644 (file)
index 0000000..5062cc2
Binary files /dev/null and b/skin/selector.png differ
diff --git a/skin/skin.txt b/skin/skin.txt
new file mode 100644 (file)
index 0000000..1d67cee
--- /dev/null
@@ -0,0 +1,4 @@
+// html-style hex color codes, ex. ff0000 is red, 0000ff is blue, etc.
+text_color=ffffff
+selection_color=c00000
+