start new makefile, migrate to libpicofe
authornotaz <notasas@gmail.com>
Sat, 22 Jun 2013 16:16:08 +0000 (19:16 +0300)
committernotaz <notasas@gmail.com>
Sat, 22 Jun 2013 16:16:08 +0000 (19:16 +0300)
47 files changed:
.gitignore
Makefile [new file with mode: 0644]
cpu/debug.h
pico/32x/memory.c
pico/cart.c
pico/pico.h
pico/sound/sound.c
platform/common/arm_linux.S [deleted file]
platform/common/arm_linux.h [deleted file]
platform/common/common.mak
platform/common/config.c
platform/common/emu.c
platform/common/emu.h
platform/common/fonts.c [deleted file]
platform/common/fonts.h [deleted file]
platform/common/in_sdl.c [deleted file]
platform/common/in_sdl.h [deleted file]
platform/common/input.c [deleted file]
platform/common/input.h [deleted file]
platform/common/input_pico.h [new file with mode: 0644]
platform/common/lprintf.h [deleted file]
platform/common/main.c
platform/common/menu.c [deleted file]
platform/common/menu.h [deleted file]
platform/common/menu_pico.c
platform/common/menu_pico.h
platform/common/plat.h [deleted file]
platform/common/posix.h [deleted file]
platform/common/readpng.c [deleted file]
platform/common/readpng.h [deleted file]
platform/common/revision.mak [deleted file]
platform/libpicofe
platform/linux/Makefile [deleted file]
platform/linux/emu.c
platform/linux/fbdev.c [deleted file]
platform/linux/fbdev.h [deleted file]
platform/linux/in_evdev.c [deleted file]
platform/linux/io.c
platform/linux/plat.c [deleted file]
platform/linux/sndout_oss.c [deleted file]
platform/linux/sndout_oss.h [deleted file]
platform/linux/xenv.c [deleted file]
platform/linux/xenv.h [deleted file]
platform/win32/direct.cpp [deleted file]
platform/win32/direct.h [deleted file]
platform/win32/dsnd.cpp [deleted file]
platform/win32/dsnd.h [deleted file]

index 3b63814..3c582d0 100644 (file)
@@ -5,3 +5,6 @@ cscope.out
 PicoDrive.map
 config.mak
 config.log
+cpu/musashi/m68kmake
+cpu/musashi/m68kops.c
+cpu/musashi/m68kops.h
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..a503980
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,77 @@
+# settings
+#use_fbdev = 1
+#fake_in_gp2x = 1
+
+use_musashi = 1
+#use_fame = 1
+use_cz80 = 1
+#use_sh2drc = 1
+use_sh2mame = 1
+
+#drc_debug = 3
+#drc_debug_interp = 1
+#profile = 1
+
+-include Makefile.local
+
+ifndef ARCH
+ARCH = x86
+endif
+
+CC ?= $(CROSS_COMPILE)gcc
+
+DEFINES = _UNZIP_SUPPORT IO_STATS IN_EVDEV
+CFLAGS += -ggdb -Wall -falign-functions=2
+CFLAGS += -I.
+CFLAGS += -Iplatform/linux/
+LDLIBS += -lm -lpng
+
+all: PicoDrive
+
+# frontend
+OBJS += platform/linux/io.o platform/linux/emu.o platform/linux/blit.o \
+       platform/linux/log_io.o
+
+# common
+OBJS += platform/common/main.o platform/common/emu.o platform/common/menu_pico.o \
+       platform/common/config.o
+
+# libpicofe
+OBJS += platform/libpicofe/input.o platform/libpicofe/readpng.o \
+       platform/libpicofe/fonts.o platform/libpicofe/linux/in_evdev.o \
+       platform/libpicofe/linux/plat.o platform/libpicofe/linux/sndout_oss.o
+
+OBJS += platform/libpicofe/plat_dummy.o
+
+ifeq "$(use_fbdev)" "1"
+DEFINES += FBDEV
+OBJS += fbdev.o
+else
+LDLIBS += -lpthread
+LDLIBS += -lX11
+endif
+
+ifeq "$(ARCH)" "arm"
+OBJS += pico/carthw/svp/stub_arm.o
+endif
+OBJS += pico/sound/mix.o
+OBJS += pico/carthw/svp/compiler.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 zlib/uncompr.o
+# unzip
+OBJS += unzip/unzip.o unzip/unzip_stream.o
+
+include platform/common/common.mak
+
+CFLAGS += $(addprefix -D,$(DEFINES))
+
+clean:
+       $(RM) PicoDrive $(OBJS)
+
+PicoDrive : $(OBJS)
+       $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDLIBS) -Wl,-Map=PicoDrive.map -o $@
+
+pprof: platform/linux/pprof.c
+       $(CC) -O2 -ggdb -DPPROF -DPPROF_TOOL -I../../ -I. $^ -o $@
index bf3e068..5aaa60e 100644 (file)
@@ -26,6 +26,6 @@ int pdb_net_connect(const char *host, const char *port);
 
 #else
 
-#define pdb_net_connect(a,b) 0
+static inline int pdb_net_connect(const char *host, const char *port) {return 0;}
 
 #endif
index c720547..7844acc 100644 (file)
@@ -1425,7 +1425,7 @@ void PicoMemSetup32x(void)
   unsigned int rs;
   int i;
 
-  Pico32xMem = plat_mmap(0x06000000, sizeof(*Pico32xMem));
+  Pico32xMem = plat_mmap(0x06000000, sizeof(*Pico32xMem), 0, 0);
   if (Pico32xMem == NULL) {
     elprintf(EL_STATUS, "OOM");
     return;
index 8ac330a..b060079 100644 (file)
@@ -458,7 +458,7 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms)
 \r
   // Allocate space for the rom plus padding\r
   // use special address for 32x dynarec\r
-  rom = plat_mmap(0x02000000, rom_alloc_size);\r
+  rom = plat_mmap(0x02000000, rom_alloc_size, 0, 0);\r
   return rom;\r
 }\r
 \r
index ac5eb05..da0a9a7 100644 (file)
@@ -33,7 +33,7 @@ extern void cache_flush_d_inval_i(const void *start_addr, const void *end_addr);
 \r
 // attempt to alloc mem at specified address.\r
 // alloc anywhere else if that fails (callers should handle that)\r
-extern void *plat_mmap(unsigned long addr, size_t size);\r
+extern void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);\r
 extern void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);\r
 extern void  plat_munmap(void *ptr, size_t size);\r
 \r
index 615e324..48ad409 100644 (file)
@@ -337,6 +337,7 @@ static int PsndRender(int offset, int length)
     memset32(buf32, 0, length<<stereo);\r
 \r
 //printf("active_chs: %02x\n", buf32_updated);\r
+  (void)buf32_updated;\r
 \r
   // CD: PCM sound\r
   if (do_pcm) {\r
diff --git a/platform/common/arm_linux.S b/platform/common/arm_linux.S
deleted file mode 100644 (file)
index 8b13ebb..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-@ vim:filetype=armasm
-#include <sys/syscall.h>
-
-
-.global cache_flush_d_inval_i @ const void *start_addr, const void *end_addr
-
-cache_flush_d_inval_i:
-    mov     r2, #0
-#ifdef __ARM_EABI__
-    /* EABI version */
-    str     r7, [sp, #-4]!
-    mov     r7, #(__ARM_NR_cacheflush & 0xff)
-#if (__ARM_NR_cacheflush & 0x00ff00)
-    orr     r7, r7, #(__ARM_NR_cacheflush & 0x00ff00)
-#endif
-#if (__ARM_NR_cacheflush & 0xff0000)
-    orr     r7, r7, #(__ARM_NR_cacheflush & 0xff0000)
-#endif
-    swi     0
-    ldr     r7, [sp], #4
-#else
-    /* OABI */
-    swi     __ARM_NR_cacheflush
-#endif
-    bx      lr
-
diff --git a/platform/common/arm_linux.h b/platform/common/arm_linux.h
deleted file mode 100644 (file)
index 99de912..0000000
+++ /dev/null
@@ -1 +0,0 @@
-extern void cache_flush_d_inval_i(const void *start_addr, const void *end_addr);
index 2a0354b..7d2599e 100644 (file)
@@ -1,6 +1,3 @@
-ifneq ($(DEBUG),)
-CFLAGS += -ggdb
-endif
 ifeq "$(profile)" "1"
 CFLAGS += -fprofile-generate
 endif
@@ -120,35 +117,28 @@ DIRS += platform platform/common pico pico/cd pico/pico pico/32x pico/sound pico
        @echo ">>>" $<
        $(CC) $(CFLAGS) -c $< -o $@
 
-clean_prof:
-       find ../.. -name '*.gcno' -delete
-       find ../.. -name '*.gcda' -delete
-
 mkdirs:
        mkdir -p $(DIRS)
 
-../../tools/textfilter: ../../tools/textfilter.c
-       make -C ../../tools/ textfilter
+tools/textfilter: tools/textfilter.c
+       make -C tools/ textfilter
 
 
 # random deps
-pico/carthw/svp/compiler.o : ../../cpu/drc/emit_$(ARCH).c
-cpu/sh2/compiler.o : ../../cpu/drc/emit_$(ARCH).c
-cpu/sh2/mame/sh2pico.o : ../../cpu/sh2/mame/sh2.c
-pico/pico.o pico/cd/pico.o : ../../pico/pico_cmn.c ../../pico/pico_int.h
-pico/memory.o pico/cd/memory.o : ../../pico/pico_int.h ../../pico/memory.h
-
-../../cpu/musashi/m68kops.c :
-       @make -C ../../cpu/musashi
+pico/carthw/svp/compiler.o : cpu/drc/emit_$(ARCH).c
+cpu/sh2/compiler.o : cpu/drc/emit_$(ARCH).c
+cpu/sh2/mame/sh2pico.o : cpu/sh2/mame/sh2.c
+pico/pico.o pico/cd/pico.o : pico/pico_cmn.c pico/pico_int.h
+pico/memory.o pico/cd/memory.o : pico/pico_int.h pico/memory.h
 
-../../cpu/mz80/mz80.asm :
-       @make -C ../../cpu/mz80/
+cpu/musashi/m68kops.c :
+       @make -C cpu/musashi
 
-cpu/fame/famec.o : ../../cpu/fame/famec.c ../../cpu/fame/famec_opcodes.h
+cpu/fame/famec.o : cpu/fame/famec.c cpu/fame/famec_opcodes.h
        @echo ">>>" $<
        $(CC) $(CFLAGS) -Wno-unused -c $< -o $@
 
-../../cpu/Cyclone/proj/Cyclone.s:
+cpu/Cyclone/proj/Cyclone.s:
        @echo building Cyclone...
-       @make -C ../../cpu/Cyclone/proj CONFIG_FILE=config_pico.h
+       @make -C cpu/Cyclone/proj CONFIG_FILE=config_pico.h
 
index 9950b13..35ba25b 100644 (file)
@@ -9,16 +9,16 @@
 #ifdef __EPOC32__
 #include <unistd.h>
 #endif
+
+#include "../libpicofe/input.h"
+#include "../libpicofe/plat.h"
+#include "../libpicofe/lprintf.h"
 #include "config.h"
-#include "plat.h"
-#include "input.h"
-#include "lprintf.h"
 
 static char *mystrip(char *str);
 
 #ifndef _MSC_VER
 
-#include "menu.h"
 #include "menu_pico.h"
 #include "emu.h"
 #include <pico/pico.h>
index 7d680b8..a417926 100644 (file)
 #include <unistd.h>\r
 #endif\r
 \r
+#include "../libpicofe/posix.h"\r
+#include "../libpicofe/input.h"\r
+#include "../libpicofe/fonts.h"\r
+#include "../libpicofe/lprintf.h"\r
+#include "../libpicofe/plat.h"\r
 #include "emu.h"\r
-#include "menu.h"\r
-#include "fonts.h"\r
-#include "lprintf.h"\r
+#include "input_pico.h"\r
+#include "menu_pico.h"\r
 #include "config.h"\r
-#include "plat.h"\r
-#include "input.h"\r
-#include "posix.h"\r
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
@@ -184,7 +185,7 @@ static int find_bios(int region, char **bios_file)
        } else {\r
                sprintf(static_buff, "no %s BIOS files found, read docs",\r
                        region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
-               me_update_msg(static_buff);\r
+               menu_update_msg(static_buff);\r
                return 0;\r
        }\r
 }\r
@@ -510,32 +511,32 @@ int emu_reload_rom(char *rom_fname)
                int dummy;\r
                FILE *movie_file = fopen(rom_fname, "rb");\r
                if (!movie_file) {\r
-                       me_update_msg("Failed to open movie.");\r
+                       menu_update_msg("Failed to open movie.");\r
                        return 0;\r
                }\r
                fseek(movie_file, 0, SEEK_END);\r
                movie_size = ftell(movie_file);\r
                fseek(movie_file, 0, SEEK_SET);\r
                if (movie_size < 64+3) {\r
-                       me_update_msg("Invalid GMV file.");\r
+                       menu_update_msg("Invalid GMV file.");\r
                        fclose(movie_file);\r
                        return 0;\r
                }\r
                movie_data = malloc(movie_size);\r
                if (movie_data == NULL) {\r
-                       me_update_msg("low memory.");\r
+                       menu_update_msg("low memory.");\r
                        fclose(movie_file);\r
                        return 0;\r
                }\r
                dummy = fread(movie_data, 1, movie_size, movie_file);\r
                fclose(movie_file);\r
                if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) {\r
-                       me_update_msg("Invalid GMV file.");\r
+                       menu_update_msg("Invalid GMV file.");\r
                        return 0;\r
                }\r
                dummy = try_rfn_cut(rom_fname) || try_rfn_cut(rom_fname);\r
                if (!dummy) {\r
-                       me_update_msg("Could't find a ROM for movie.");\r
+                       menu_update_msg("Could't find a ROM for movie.");\r
                        return 0;\r
                }\r
                get_ext(rom_fname, ext);\r
@@ -547,7 +548,7 @@ int emu_reload_rom(char *rom_fname)
                PicoPatchLoad(rom_fname);\r
                dummy = try_rfn_cut(rom_fname) || try_rfn_cut(rom_fname);\r
                if (!dummy) {\r
-                       me_update_msg("Could't find a ROM to patch.");\r
+                       menu_update_msg("Could't find a ROM to patch.");\r
                        return 0;\r
                }\r
                get_ext(rom_fname, ext);\r
@@ -555,7 +556,7 @@ int emu_reload_rom(char *rom_fname)
 \r
        media_type = detect_media(rom_fname);\r
        if (media_type == PM_BAD) {\r
-               me_update_msg("Not a ROM/CD img selected.");\r
+               menu_update_msg("Not a ROM/CD img selected.");\r
                return 0;\r
        }\r
 \r
@@ -590,7 +591,7 @@ int emu_reload_rom(char *rom_fname)
                        PicoAHW |= PAHW_MCD;\r
                }\r
                else {\r
-                       me_update_msg("Invalid CD image");\r
+                       menu_update_msg("Invalid CD image");\r
                        return 0;\r
                }\r
        }\r
@@ -601,7 +602,7 @@ int emu_reload_rom(char *rom_fname)
 \r
        rom = pm_open(used_rom_name);\r
        if (rom == NULL) {\r
-               me_update_msg("Failed to open ROM");\r
+               menu_update_msg("Failed to open ROM");\r
                return 0;\r
        }\r
 \r
@@ -611,9 +612,9 @@ int emu_reload_rom(char *rom_fname)
        ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoAHW & PAHW_SMS) ? 1 : 0);\r
        pm_close(rom);\r
        if (ret != 0) {\r
-               if      (ret == 2) me_update_msg("Out of memory");\r
-               else if (ret == 3) me_update_msg("Read failed");\r
-               else               me_update_msg("PicoCartLoad() failed.");\r
+               if      (ret == 2) menu_update_msg("Out of memory");\r
+               else if (ret == 3) menu_update_msg("Read failed");\r
+               else               menu_update_msg("PicoCartLoad() failed.");\r
                goto fail;\r
        }\r
 \r
@@ -629,7 +630,7 @@ int emu_reload_rom(char *rom_fname)
        }\r
 \r
        if (bad_rom) {\r
-               me_update_msg("Bad ROM detected.");\r
+               menu_update_msg("Bad ROM detected.");\r
                goto fail;\r
        }\r
 \r
@@ -643,7 +644,7 @@ int emu_reload_rom(char *rom_fname)
 \r
        emu_make_path(static_buff, "carthw.cfg", sizeof(static_buff));\r
        if (PicoCartInsert(rom_data, rom_size, static_buff)) {\r
-               me_update_msg("Failed to load ROM.");\r
+               menu_update_msg("Failed to load ROM.");\r
                goto fail;\r
        }\r
 \r
@@ -653,7 +654,7 @@ int emu_reload_rom(char *rom_fname)
                if (ret != 0) {\r
                        PicoCartUnload();\r
                        rom_data = NULL; // freed by unload\r
-                       me_update_msg("Insert_CD() failed, invalid CD image?");\r
+                       menu_update_msg("Insert_CD() failed, invalid CD image?");\r
                        goto fail;\r
                }\r
        }\r
@@ -716,7 +717,7 @@ int emu_swap_cd(const char *fname)
        if (cd_type != CIT_NOT_CD)\r
                ret = Insert_CD(fname, cd_type);\r
        if (ret != 0) {\r
-               me_update_msg("Load failed, invalid CD image?");\r
+               menu_update_msg("Load failed, invalid CD image?");\r
                return 0;\r
        }\r
 \r
index 75a5abe..0bbdcbd 100644 (file)
@@ -149,6 +149,34 @@ void  emu_status_msg(const char *format, ...);
 /* used by some (but not all) platforms */
 void  emu_cmn_forced_frame(int no_scale, int do_emu);
 
+/* stuff to be implemented by platform code */
+extern const char *renderer_names[];
+extern const char *renderer_names32x[];
+
+void pemu_prep_defconfig(void);
+void pemu_validate_config(void);
+void pemu_loop_prep(void);
+void pemu_loop_end(void);
+void pemu_forced_frame(int no_scale, int do_emu); // ..to g_menubg_src_ptr
+void pemu_finalize_frame(const char *fps, const char *notice_msg);
+
+void pemu_sound_start(void);
+void pemu_sound_stop(void);
+void pemu_sound_wait(void);
+
+void plat_early_init(void);
+void plat_init(void);
+void plat_finish(void);
+
+/* used before things blocking for a while (these funcs redraw on return) */
+void plat_status_msg_busy_first(const char *msg);
+void plat_status_msg_busy_next(const char *msg);
+void plat_status_msg_clear(void);
+
+void plat_video_toggle_renderer(int change, int menu_call);
+
+void plat_update_volume(int has_changed, int is_up);
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/platform/common/fonts.c b/platform/common/fonts.c
deleted file mode 100644 (file)
index ea65481..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-unsigned char fontdata8x8[64*16] =
-{
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-       0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C,
-       0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00,
-       0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00,
-       0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00,
-       0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00,
-       0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40,
-       0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00,
-       0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00,
-       0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00,
-       0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00,
-       0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00,
-       0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00,
-       0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00,
-       0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00,
-       0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,
-       0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00,
-       0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00,
-       0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00,
-       0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00,
-       0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00,
-       0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00,
-       0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30,
-       0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00,
-       0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00,
-       0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00,
-       0xFC,0xC6,0xC6,0xFC,0xC6,0xC6,0xFC,0x00,0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00,
-       0xF8,0xCC,0xC6,0xC6,0xC6,0xCC,0xF8,0x00,0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xFE,0x00,
-       0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xC0,0x00,0x3E,0x60,0xC0,0xCE,0xC6,0x66,0x3E,0x00,
-       0xC6,0xC6,0xC6,0xFE,0xC6,0xC6,0xC6,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,
-       0x06,0x06,0x06,0x06,0xC6,0xC6,0x7C,0x00,0xC6,0xCC,0xD8,0xF0,0xF8,0xDC,0xCE,0x00,
-       0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00,
-       0xC6,0xE6,0xF6,0xFE,0xDE,0xCE,0xC6,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00,
-       0xFC,0xC6,0xC6,0xC6,0xFC,0xC0,0xC0,0x00,0x7C,0xC6,0xC6,0xC6,0xDE,0xCC,0x7A,0x00,
-       0xFC,0xC6,0xC6,0xCE,0xF8,0xDC,0xCE,0x00,0x78,0xCC,0xC0,0x7C,0x06,0xC6,0x7C,0x00,
-       0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00,
-       0xC6,0xC6,0xC6,0xEE,0x7C,0x38,0x10,0x00,0xC6,0xC6,0xD6,0xFE,0xFE,0xEE,0xC6,0x00,
-       0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00,
-       0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,
-       0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,
-       0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
-       0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00,
-       0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00,
-       0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00,
-       0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C,
-       0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00,
-       0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00,
-       0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00,
-       0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00,
-       0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06,
-       0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00,
-       0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00,
-       0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00,
-       0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C,
-       0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00,
-       0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00,
-       0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00,
-};
-
-
-/* The font is generated from Xorg clR5x8.bdf */
-/*
-COMMENT  Copyright 1989 Dale Schumacher, dal@syntel.mn.org
-COMMENT                 399 Beacon Ave.
-COMMENT                 St. Paul, MN  55104-3527
-COMMENT
-COMMENT  Permission to use, copy, modify, and distribute this software and
-COMMENT  its documentation for any purpose and without fee is hereby
-COMMENT  granted, provided that the above copyright notice appear in all
-COMMENT  copies and that both that copyright notice and this permission
-COMMENT  notice appear in supporting documentation, and that the name of
-COMMENT  Dale Schumacher not be used in advertising or publicity pertaining to
-COMMENT  distribution of the software without specific, written prior
-COMMENT  permission.  Dale Schumacher makes no representations about the
-COMMENT  suitability of this software for any purpose.  It is provided "as
-COMMENT  is" without express or implied warranty.
-COMMENT
-*/
-unsigned char fontdata6x8[256][8] = {
-{ 0x7c>>2, 0x44>>2, 0x7c>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0xff>>2, 0x7c>>2, },
-{ 0x00>>2, 0x00>>2, 0x10>>2, 0x28>>2, 0x44>>2, 0x7c>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x78>>2, 0x44>>2, 0x78>>2, 0x44>>2, 0x78>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x38>>2, 0x44>>2, 0x40>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x78>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x7c>>2, 0x40>>2, 0x78>>2, 0x40>>2, 0x7c>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x7c>>2, 0x40>>2, 0x78>>2, 0x40>>2, 0x40>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x40>>2, 0x4c>>2, 0x44>>2, 0x3c>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x44>>2, 0x7c>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x38>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x1c>>2, 0x04>>2, 0x04>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x48>>2, 0x50>>2, 0x60>>2, 0x50>>2, 0x48>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x7c>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x6c>>2, 0x54>>2, 0x54>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x64>>2, 0x54>>2, 0x4c>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x38>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x78>>2, 0x44>>2, 0x78>>2, 0x40>>2, 0x40>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x38>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x0c>>2, },
-{ 0x00>>2, 0x00>>2, 0x78>>2, 0x44>>2, 0x78>>2, 0x50>>2, 0x4c>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x40>>2, 0x38>>2, 0x04>>2, 0x78>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x7c>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x44>>2, 0x28>>2, 0x28>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x54>>2, 0x54>>2, 0x6c>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x28>>2, 0x10>>2, 0x28>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x28>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x7c>>2, 0x08>>2, 0x10>>2, 0x20>>2, 0x7c>>2, 0x00>>2, },
-{ 0xe0>>2, 0x80>>2, 0xe0>>2, 0x8c>>2, 0xf0>>2, 0x10>>2, 0x10>>2, 0x0c>>2, },
-{ 0x00>>2, 0x10>>2, 0x38>>2, 0x7c>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x7c>>2, 0x38>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x18>>2, 0xfc>>2, 0x18>>2, 0x10>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x20>>2, 0x60>>2, 0xfc>>2, 0x60>>2, 0x20>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, 0x10>>2, 0x00>>2, },
-{ 0x28>>2, 0x28>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x28>>2, 0x7c>>2, 0x28>>2, 0x7c>>2, 0x28>>2, 0x00>>2, 0x00>>2, },
-{ 0x10>>2, 0x3c>>2, 0x50>>2, 0x38>>2, 0x14>>2, 0x78>>2, 0x10>>2, 0x00>>2, },
-{ 0x60>>2, 0x64>>2, 0x08>>2, 0x10>>2, 0x20>>2, 0x4c>>2, 0x0c>>2, 0x00>>2, },
-{ 0x38>>2, 0x40>>2, 0x40>>2, 0x20>>2, 0x54>>2, 0x48>>2, 0x34>>2, 0x00>>2, },
-{ 0x10>>2, 0x20>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x04>>2, 0x08>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x08>>2, 0x04>>2, 0x00>>2, },
-{ 0x40>>2, 0x20>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x20>>2, 0x40>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x54>>2, 0x38>>2, 0x54>>2, 0x10>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x10>>2, 0x7c>>2, 0x10>>2, 0x10>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x10>>2, 0x10>>2, 0x20>>2, },
-{ 0x00>>2, 0x00>>2, 0x00>>2, 0x7c>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x04>>2, 0x04>>2, 0x08>>2, 0x08>>2, 0x10>>2, 0x10>>2, 0x20>>2, 0x20>>2, },
-{ 0x38>>2, 0x44>>2, 0x4c>>2, 0x54>>2, 0x64>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x10>>2, 0x30>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x04>>2, 0x08>>2, 0x10>>2, 0x20>>2, 0x7c>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x04>>2, 0x18>>2, 0x04>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x18>>2, 0x18>>2, 0x28>>2, 0x28>>2, 0x7c>>2, 0x08>>2, 0x1c>>2, 0x00>>2, },
-{ 0x7c>>2, 0x40>>2, 0x78>>2, 0x04>>2, 0x04>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x18>>2, 0x20>>2, 0x40>>2, 0x78>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x7c>>2, 0x44>>2, 0x04>>2, 0x08>>2, 0x08>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x44>>2, 0x3c>>2, 0x04>>2, 0x08>>2, 0x30>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x10>>2, 0x00>>2, 0x00>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x10>>2, 0x00>>2, 0x00>>2, 0x10>>2, 0x10>>2, 0x20>>2, },
-{ 0x00>>2, 0x0c>>2, 0x30>>2, 0xc0>>2, 0x30>>2, 0x0c>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x7c>>2, 0x00>>2, 0x7c>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0xc0>>2, 0x30>>2, 0x0c>>2, 0x30>>2, 0xc0>>2, 0x00>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x04>>2, 0x08>>2, 0x10>>2, 0x00>>2, 0x10>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x5c>>2, 0x5c>>2, 0x58>>2, 0x40>>2, 0x38>>2, 0x00>>2, },
-{ 0x10>>2, 0x28>>2, 0x44>>2, 0x44>>2, 0x7c>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x78>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x70>>2, 0x48>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x48>>2, 0x70>>2, 0x00>>2, },
-{ 0x7c>>2, 0x40>>2, 0x40>>2, 0x78>>2, 0x40>>2, 0x40>>2, 0x7c>>2, 0x00>>2, },
-{ 0x7c>>2, 0x40>>2, 0x40>>2, 0x78>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x40>>2, 0x4c>>2, 0x44>>2, 0x44>>2, 0x3c>>2, 0x00>>2, },
-{ 0x44>>2, 0x44>>2, 0x44>>2, 0x7c>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x7c>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x7c>>2, 0x00>>2, },
-{ 0x1c>>2, 0x04>>2, 0x04>>2, 0x04>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x44>>2, 0x48>>2, 0x50>>2, 0x60>>2, 0x50>>2, 0x48>>2, 0x44>>2, 0x00>>2, },
-{ 0x40>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x7c>>2, 0x00>>2, },
-{ 0x44>>2, 0x6c>>2, 0x54>>2, 0x54>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x44>>2, 0x64>>2, 0x64>>2, 0x54>>2, 0x4c>>2, 0x4c>>2, 0x44>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x78>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x0c>>2, },
-{ 0x78>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x50>>2, 0x48>>2, 0x44>>2, 0x00>>2, },
-{ 0x38>>2, 0x44>>2, 0x40>>2, 0x38>>2, 0x04>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x7c>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x44>>2, 0x44>>2, 0x44>>2, 0x28>>2, 0x28>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x44>>2, 0x44>>2, 0x44>>2, 0x54>>2, 0x54>>2, 0x6c>>2, 0x44>>2, 0x00>>2, },
-{ 0x44>>2, 0x44>>2, 0x28>>2, 0x10>>2, 0x28>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x44>>2, 0x44>>2, 0x28>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x7c>>2, 0x04>>2, 0x08>>2, 0x10>>2, 0x20>>2, 0x40>>2, 0x7c>>2, 0x00>>2, },
-{ 0x1c>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x1c>>2, 0x00>>2, },
-{ 0x20>>2, 0x20>>2, 0x10>>2, 0x10>>2, 0x08>>2, 0x08>>2, 0x04>>2, 0x04>>2, },
-{ 0x70>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x70>>2, 0x00>>2, },
-{ 0x10>>2, 0x28>>2, 0x44>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0xfc>>2, 0x00>>2, },
-{ 0x10>>2, 0x08>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x44>>2, 0x44>>2, 0x4c>>2, 0x34>>2, 0x00>>2, },
-{ 0x40>>2, 0x40>>2, 0x78>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x3c>>2, 0x00>>2, },
-{ 0x04>>2, 0x04>>2, 0x3c>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x3c>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x38>>2, 0x44>>2, 0x7c>>2, 0x40>>2, 0x38>>2, 0x00>>2, },
-{ 0x1c>>2, 0x20>>2, 0x78>>2, 0x20>>2, 0x20>>2, 0x20>>2, 0x20>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x44>>2, 0x44>>2, 0x3c>>2, 0x04>>2, 0x38>>2, },
-{ 0x40>>2, 0x40>>2, 0x78>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x10>>2, 0x00>>2, 0x30>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x38>>2, 0x00>>2, },
-{ 0x08>>2, 0x00>>2, 0x38>>2, 0x08>>2, 0x08>>2, 0x08>>2, 0x08>>2, 0x70>>2, },
-{ 0x40>>2, 0x40>>2, 0x48>>2, 0x50>>2, 0x60>>2, 0x50>>2, 0x48>>2, 0x00>>2, },
-{ 0x30>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x68>>2, 0x54>>2, 0x54>>2, 0x54>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x58>>2, 0x64>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x38>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x38>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x78>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x78>>2, 0x40>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x3c>>2, 0x04>>2, },
-{ 0x00>>2, 0x00>>2, 0x58>>2, 0x60>>2, 0x40>>2, 0x40>>2, 0x40>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x3c>>2, 0x40>>2, 0x38>>2, 0x04>>2, 0x78>>2, 0x00>>2, },
-{ 0x10>>2, 0x10>>2, 0x7c>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x0c>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x4c>>2, 0x34>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x6c>>2, 0x28>>2, 0x28>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x54>>2, 0x54>>2, 0x54>>2, 0x28>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x28>>2, 0x10>>2, 0x28>>2, 0x44>>2, 0x00>>2, },
-{ 0x00>>2, 0x00>>2, 0x44>>2, 0x44>>2, 0x44>>2, 0x3c>>2, 0x04>>2, 0x38>>2, },
-{ 0x00>>2, 0x00>>2, 0x7c>>2, 0x08>>2, 0x10>>2, 0x20>>2, 0x7c>>2, 0x00>>2, },
-{ 0x04>>2, 0x08>>2, 0x08>>2, 0x10>>2, 0x08>>2, 0x08>>2, 0x04>>2, 0x00>>2, },
-{ 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x10>>2, 0x00>>2, },
-{ 0x40>>2, 0x20>>2, 0x20>>2, 0x10>>2, 0x20>>2, 0x20>>2, 0x40>>2, 0x00>>2, },
-{ 0x20>>2, 0x54>>2, 0x08>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, 0x00>>2, },
-{ 0x00>>2, 0x10>>2, 0x10>>2, 0x28>>2, 0x28>>2, 0x44>>2, 0x7c>>2, 0x00>>2, },
-};
-
diff --git a/platform/common/fonts.h b/platform/common/fonts.h
deleted file mode 100644 (file)
index dbbdd4c..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-
-extern unsigned char fontdata8x8[64*16];
-extern unsigned char fontdata6x8[256-32][8];
-
diff --git a/platform/common/in_sdl.c b/platform/common/in_sdl.c
deleted file mode 100644 (file)
index ce57536..0000000
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2012
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <stdio.h>
-#include <SDL.h>
-#include "input.h"
-#include "in_sdl.h"
-
-#define IN_SDL_PREFIX "sdl:"
-/* should be machine word for best performace */
-typedef unsigned long keybits_t;
-#define KEYBITS_WORD_BITS (sizeof(keybits_t) * 8)
-
-struct in_sdl_state {
-       SDL_Joystick *joy;
-       int joy_id;
-       int axis_keydown[2];
-       keybits_t keystate[SDLK_LAST / KEYBITS_WORD_BITS + 1];
-};
-
-static const char * const in_sdl_keys[SDLK_LAST] = {
-       [SDLK_BACKSPACE] = "backspace",
-       [SDLK_TAB] = "tab",
-       [SDLK_CLEAR] = "clear",
-       [SDLK_RETURN] = "return",
-       [SDLK_PAUSE] = "pause",
-       [SDLK_ESCAPE] = "escape",
-       [SDLK_SPACE] = "space",
-       [SDLK_EXCLAIM]  = "!",
-       [SDLK_QUOTEDBL]  = "\"",
-       [SDLK_HASH]  = "#",
-       [SDLK_DOLLAR]  = "$",
-       [SDLK_AMPERSAND]  = "&",
-       [SDLK_QUOTE] = "'",
-       [SDLK_LEFTPAREN] = "(",
-       [SDLK_RIGHTPAREN] = ")",
-       [SDLK_ASTERISK] = "*",
-       [SDLK_PLUS] = "+",
-       [SDLK_COMMA] = ",",
-       [SDLK_MINUS] = "-",
-       [SDLK_PERIOD] = ".",
-       [SDLK_SLASH] = "/",
-       [SDLK_0] = "0",
-       [SDLK_1] = "1",
-       [SDLK_2] = "2",
-       [SDLK_3] = "3",
-       [SDLK_4] = "4",
-       [SDLK_5] = "5",
-       [SDLK_6] = "6",
-       [SDLK_7] = "7",
-       [SDLK_8] = "8",
-       [SDLK_9] = "9",
-       [SDLK_COLON] = ":",
-       [SDLK_SEMICOLON] = ",",
-       [SDLK_LESS] = "<",
-       [SDLK_EQUALS] = "=",
-       [SDLK_GREATER] = ">",
-       [SDLK_QUESTION] = "?",
-       [SDLK_AT] = "@",
-       [SDLK_LEFTBRACKET] = "[",
-       [SDLK_BACKSLASH] = "\\",
-       [SDLK_RIGHTBRACKET] = "]",
-       [SDLK_CARET] = "^",
-       [SDLK_UNDERSCORE] = "_",
-       [SDLK_BACKQUOTE] = "`",
-       [SDLK_a] = "a",
-       [SDLK_b] = "b",
-       [SDLK_c] = "c",
-       [SDLK_d] = "d",
-       [SDLK_e] = "e",
-       [SDLK_f] = "f",
-       [SDLK_g] = "g",
-       [SDLK_h] = "h",
-       [SDLK_i] = "i",
-       [SDLK_j] = "j",
-       [SDLK_k] = "k",
-       [SDLK_l] = "l",
-       [SDLK_m] = "m",
-       [SDLK_n] = "n",
-       [SDLK_o] = "o",
-       [SDLK_p] = "p",
-       [SDLK_q] = "q",
-       [SDLK_r] = "r",
-       [SDLK_s] = "s",
-       [SDLK_t] = "t",
-       [SDLK_u] = "u",
-       [SDLK_v] = "v",
-       [SDLK_w] = "w",
-       [SDLK_x] = "x",
-       [SDLK_y] = "y",
-       [SDLK_z] = "z",
-       [SDLK_DELETE] = "delete",
-
-       [SDLK_KP0] = "[0]",
-       [SDLK_KP1] = "[1]",
-       [SDLK_KP2] = "[2]",
-       [SDLK_KP3] = "[3]",
-       [SDLK_KP4] = "[4]",
-       [SDLK_KP5] = "[5]",
-       [SDLK_KP6] = "[6]",
-       [SDLK_KP7] = "[7]",
-       [SDLK_KP8] = "[8]",
-       [SDLK_KP9] = "[9]",
-       [SDLK_KP_PERIOD] = "[.]",
-       [SDLK_KP_DIVIDE] = "[/]",
-       [SDLK_KP_MULTIPLY] = "[*]",
-       [SDLK_KP_MINUS] = "[-]",
-       [SDLK_KP_PLUS] = "[+]",
-       [SDLK_KP_ENTER] = "enter",
-       [SDLK_KP_EQUALS] = "equals",
-
-       [SDLK_UP] = "up",
-       [SDLK_DOWN] = "down",
-       [SDLK_RIGHT] = "right",
-       [SDLK_LEFT] = "left",
-       [SDLK_DOWN] = "down",
-       [SDLK_INSERT] = "insert",
-       [SDLK_HOME] = "home",
-       [SDLK_END] = "end",
-       [SDLK_PAGEUP] = "page up",
-       [SDLK_PAGEDOWN] = "page down",
-
-       [SDLK_F1] = "f1",
-       [SDLK_F2] = "f2",
-       [SDLK_F3] = "f3",
-       [SDLK_F4] = "f4",
-       [SDLK_F5] = "f5",
-       [SDLK_F6] = "f6",
-       [SDLK_F7] = "f7",
-       [SDLK_F8] = "f8",
-       [SDLK_F9] = "f9",
-       [SDLK_F10] = "f10",
-       [SDLK_F11] = "f11",
-       [SDLK_F12] = "f12",
-       [SDLK_F13] = "f13",
-       [SDLK_F14] = "f14",
-       [SDLK_F15] = "f15",
-
-       [SDLK_NUMLOCK] = "numlock",
-       [SDLK_CAPSLOCK] = "caps lock",
-       [SDLK_SCROLLOCK] = "scroll lock",
-       [SDLK_RSHIFT] = "right shift",
-       [SDLK_LSHIFT] = "left shift",
-       [SDLK_RCTRL] = "right ctrl",
-       [SDLK_LCTRL] = "left ctrl",
-       [SDLK_RALT] = "right alt",
-       [SDLK_LALT] = "left alt",
-       [SDLK_RMETA] = "right meta",
-       [SDLK_LMETA] = "left meta",
-       [SDLK_LSUPER] = "left super",   /* "Windows" keys */
-       [SDLK_RSUPER] = "right super",  
-       [SDLK_MODE] = "alt gr",
-       [SDLK_COMPOSE] = "compose",
-};
-
-static void in_sdl_probe(void)
-{
-       struct in_sdl_state *state;
-       SDL_Joystick *joy;
-       int i, joycount;
-       char name[256];
-
-       state = calloc(1, sizeof(*state));
-       if (state == NULL) {
-               fprintf(stderr, "in_sdl: OOM\n");
-               return;
-       }
-
-       in_register(IN_SDL_PREFIX "keys", -1, state, SDLK_LAST,
-               in_sdl_keys, 0);
-
-       /* joysticks go here too */
-       SDL_InitSubSystem(SDL_INIT_JOYSTICK);
-
-       joycount = SDL_NumJoysticks();
-       for (i = 0; i < joycount; i++) {
-               joy = SDL_JoystickOpen(i);
-               if (joy == NULL)
-                       continue;
-
-               state = calloc(1, sizeof(*state));
-               if (state == NULL) {
-                       fprintf(stderr, "in_sdl: OOM\n");
-                       break;
-               }
-               state->joy = joy;
-               state->joy_id = i;
-
-               snprintf(name, sizeof(name), IN_SDL_PREFIX "%s", SDL_JoystickName(i));
-               in_register(name, -1, state, SDLK_LAST, in_sdl_keys, 0);
-       }
-
-       if (joycount > 0)
-               SDL_JoystickEventState(SDL_ENABLE);
-}
-
-static void in_sdl_free(void *drv_data)
-{
-       struct in_sdl_state *state = drv_data;
-
-       if (state != NULL) {
-               if (state->joy != NULL)
-                       SDL_JoystickClose(state->joy);
-               free(state);
-       }
-}
-
-static const char * const *
-in_sdl_get_key_names(int *count)
-{
-       *count = SDLK_LAST;
-       return in_sdl_keys;
-}
-
-/* could use SDL_GetKeyState, but this gives better packing */
-static void update_keystate(keybits_t *keystate, int sym, int is_down)
-{
-       keybits_t *ks_word, mask;
-
-       mask = 1;
-       mask <<= sym & (KEYBITS_WORD_BITS - 1);
-       ks_word = keystate + sym / KEYBITS_WORD_BITS;
-       if (is_down)
-               *ks_word |= mask;
-       else
-               *ks_word &= ~mask;
-}
-
-static int handle_event(struct in_sdl_state *state, SDL_Event *event,
-       int *kc_out, int *down_out)
-{
-       if (event->type != SDL_KEYDOWN && event->type != SDL_KEYUP)
-               return 0;
-
-       update_keystate(state->keystate, event->key.keysym.sym,
-               event->type == SDL_KEYDOWN);
-       if (kc_out != NULL)
-               *kc_out = event->key.keysym.sym;
-       if (down_out != NULL)
-               *down_out = event->type == SDL_KEYDOWN;
-
-       return 1;
-}
-
-static int handle_joy_event(struct in_sdl_state *state, SDL_Event *event,
-       int *kc_out, int *down_out)
-{
-       int kc = -1, down = 0, ret = 0;
-
-       /* FIXME: should ckeck .which */
-       /* TODO: remaining axis */
-       switch (event->type) {
-       case SDL_JOYAXISMOTION:
-               if (event->jaxis.axis > 1)
-                       break;
-               if (-16384 <= event->jaxis.value && event->jaxis.value <= 16384) {
-                       kc = state->axis_keydown[event->jaxis.axis];
-                       state->axis_keydown[event->jaxis.axis] = 0;
-                       ret = 1;
-               }
-               else if (event->jaxis.value < -16384) {
-                       kc = state->axis_keydown[event->jaxis.axis];
-                       if (kc)
-                               update_keystate(state->keystate, kc, 0);
-                       kc = event->jaxis.axis ? SDLK_UP : SDLK_LEFT;
-                       state->axis_keydown[event->jaxis.axis] = kc;
-                       down = 1;
-                       ret = 1;
-               }
-               else if (event->jaxis.value > 16384) {
-                       kc = state->axis_keydown[event->jaxis.axis];
-                       if (kc)
-                               update_keystate(state->keystate, kc, 0);
-                       kc = event->jaxis.axis ? SDLK_DOWN : SDLK_RIGHT;
-                       state->axis_keydown[event->jaxis.axis] = kc;
-                       down = 1;
-                       ret = 1;
-               }
-               break;
-
-       case SDL_JOYBUTTONDOWN:
-       case SDL_JOYBUTTONUP:
-               kc = (int)event->jbutton.button + SDLK_WORLD_0;
-               down = event->jbutton.state == SDL_PRESSED;
-               ret = 1;
-               break;
-       }
-
-       if (ret)
-               update_keystate(state->keystate, kc, down);
-       if (kc_out != NULL)
-               *kc_out = kc;
-       if (down_out != NULL)
-               *down_out = down;
-
-       return ret;
-}
-
-#define JOY_EVENTS (SDL_JOYAXISMOTIONMASK | SDL_JOYBALLMOTIONMASK | SDL_JOYHATMOTIONMASK \
-                   | SDL_JOYBUTTONDOWNMASK | SDL_JOYBUTTONUPMASK)
-
-static int collect_events(struct in_sdl_state *state, int *one_kc, int *one_down)
-{
-       SDL_Event events[4];
-       Uint32 mask = state->joy ? JOY_EVENTS : (SDL_ALLEVENTS & ~JOY_EVENTS);
-       int count, maxcount;
-       int i, ret, retval = 0;
-
-       maxcount = (one_kc != NULL) ? 1 : sizeof(events) / sizeof(events[0]);
-
-       SDL_PumpEvents();
-       while (1) {
-               count = SDL_PeepEvents(events, maxcount, SDL_GETEVENT, mask);
-               if (count <= 0)
-                       break;
-               for (i = 0; i < count; i++) {
-                       if (state->joy)
-                               ret = handle_joy_event(state,
-                                       &events[i], one_kc, one_down);
-                       else
-                               ret = handle_event(state,
-                                       &events[i], one_kc, one_down);
-                       retval |= ret;
-                       if (one_kc != NULL && ret)
-                               goto out;
-               }
-       }
-
-out:
-       return retval;
-}
-
-static int in_sdl_update(void *drv_data, const int *binds, int *result)
-{
-       struct in_sdl_state *state = drv_data;
-       keybits_t mask;
-       int i, sym, bit, b;
-
-       collect_events(state, NULL, NULL);
-
-       for (i = 0; i < SDLK_LAST / KEYBITS_WORD_BITS + 1; i++) {
-               mask = state->keystate[i];
-               if (mask == 0)
-                       continue;
-               for (bit = 0; mask != 0; bit++, mask >>= 1) {
-                       if ((mask & 1) == 0)
-                               continue;
-                       sym = i * KEYBITS_WORD_BITS + bit;
-
-                       for (b = 0; b < IN_BINDTYPE_COUNT; b++)
-                               result[b] |= binds[IN_BIND_OFFS(sym, b)];
-               }
-       }
-
-       return 0;
-}
-
-static int in_sdl_update_keycode(void *drv_data, int *is_down)
-{
-       struct in_sdl_state *state = drv_data;
-       int ret_kc = -1, ret_down = 0;
-
-       collect_events(state, &ret_kc, &ret_down);
-
-       if (is_down != NULL)
-               *is_down = ret_down;
-
-       return ret_kc;
-}
-
-struct menu_keymap {
-       short key;
-       short pbtn;
-};
-
-static const struct menu_keymap key_pbtn_map[] =
-{
-       { SDLK_UP,      PBTN_UP },
-       { SDLK_DOWN,    PBTN_DOWN },
-       { SDLK_LEFT,    PBTN_LEFT },
-       { SDLK_RIGHT,   PBTN_RIGHT },
-       /* XXX: maybe better set this from it's plat code somehow */
-       { SDLK_RETURN,  PBTN_MOK },
-       { SDLK_ESCAPE,  PBTN_MBACK },
-       { SDLK_a,       PBTN_MA2 },
-       { SDLK_s,       PBTN_MA3 },
-       { SDLK_BACKSLASH,    PBTN_MENU },
-       { SDLK_LEFTBRACKET,  PBTN_L },
-       { SDLK_RIGHTBRACKET, PBTN_R },
-};
-#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-
-static const struct menu_keymap joybtn_pbtn_map[] =
-{
-       { SDLK_UP,      PBTN_UP },
-       { SDLK_DOWN,    PBTN_DOWN },
-       { SDLK_LEFT,    PBTN_LEFT },
-       { SDLK_RIGHT,   PBTN_RIGHT },
-       /* joystick */
-       { SDLK_WORLD_0, PBTN_MOK },
-       { SDLK_WORLD_1, PBTN_MBACK },
-       { SDLK_WORLD_2, PBTN_MA2 },
-       { SDLK_WORLD_3, PBTN_MA3 },
-};
-#define JOYBTN_PBTN_MAP_SIZE (sizeof(joybtn_pbtn_map) / sizeof(joybtn_pbtn_map[0]))
-
-static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode)
-{
-       struct in_sdl_state *state = drv_data;
-       const struct menu_keymap *map;
-       int map_len;
-       int ret = 0;
-       int i;
-
-       map = state->joy ? joybtn_pbtn_map : key_pbtn_map;
-       map_len = state->joy ? JOYBTN_PBTN_MAP_SIZE : KEY_PBTN_MAP_SIZE;
-
-       if (keycode < 0)
-       {
-               /* menu -> kc */
-               keycode = -keycode;
-               for (i = 0; i < map_len; i++)
-                       if (map[i].pbtn == keycode)
-                               return map[i].key;
-       }
-       else
-       {
-               for (i = 0; i < map_len; i++) {
-                       if (map[i].key == keycode) {
-                               ret = map[i].pbtn;
-                               break;
-                       }
-               }
-
-               if (charcode != NULL && (unsigned int)keycode < SDLK_LAST &&
-                   in_sdl_keys[keycode] != NULL && in_sdl_keys[keycode][1] == 0)
-               {
-                       ret |= PBTN_CHAR;
-                       *charcode = in_sdl_keys[keycode][0];
-               }
-       }
-
-       return ret;
-}
-
-static const in_drv_t in_sdl_drv = {
-       .prefix         = IN_SDL_PREFIX,
-       .probe          = in_sdl_probe,
-       .free           = in_sdl_free,
-       .get_key_names  = in_sdl_get_key_names,
-       .update         = in_sdl_update,
-       .update_keycode = in_sdl_update_keycode,
-       .menu_translate = in_sdl_menu_translate,
-};
-
-void in_sdl_init(const struct in_default_bind *defbinds)
-{
-       in_register_driver(&in_sdl_drv, defbinds);
-}
-
diff --git a/platform/common/in_sdl.h b/platform/common/in_sdl.h
deleted file mode 100644 (file)
index 47f7a83..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-struct in_default_bind;
-
-void in_sdl_init(const struct in_default_bind *defbinds);
diff --git a/platform/common/input.c b/platform/common/input.c
deleted file mode 100644 (file)
index 39d6783..0000000
+++ /dev/null
@@ -1,991 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2008-2011
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "input.h"
-#include "plat.h"
-#include "lprintf.h"
-
-#ifdef IN_GP2X
-#error needs update: in_gp2x_init in_gp2x_update
-#include "../gp2x/in_gp2x.h"
-#endif
-#ifdef IN_VK
-#error needs update: in_vk_init in_vk_update
-#include "../win32/in_vk.h"
-#endif
-
-typedef struct
-{
-       int drv_id;
-       int drv_fd_hnd;
-       void *drv_data;
-       char *name;
-       int key_count;
-       int *binds;     /* total = key_count * bindtypes * 2 */
-       const char * const *key_names;
-       unsigned int probed:1;
-       unsigned int does_combos:1;
-} in_dev_t;
-
-static in_drv_t *in_drivers;
-static in_dev_t in_devices[IN_MAX_DEVS];
-static int in_driver_count = 0;
-static int in_dev_count = 0;           /* probed + bind devices */
-static int in_have_async_devs = 0;
-static int in_probe_dev_id;
-static int menu_key_state = 0;
-static int menu_last_used_dev = 0;
-
-#define DRV(id) in_drivers[id]
-
-
-static int *in_alloc_binds(int drv_id, int key_count)
-{
-       const struct in_default_bind *defbinds;
-       int *binds;
-       int i;
-
-       binds = calloc(key_count * IN_BINDTYPE_COUNT * 2, sizeof(binds[0]));
-       if (binds == NULL)
-               return NULL;
-
-       defbinds = DRV(drv_id).defbinds;
-       if (defbinds != NULL) {
-               for (i = 0; ; i++) {
-                       if (defbinds[i].bit == 0 && defbinds[i].code == 0)
-                               break;
-                       binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] =
-                               1 << defbinds[i].bit;
-               }
-
-               /* always have a copy of defbinds */
-               memcpy(binds + key_count * IN_BINDTYPE_COUNT, binds,
-                       sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT);
-       }
-
-       return binds;
-}
-
-static void in_unprobe(in_dev_t *dev)
-{
-       if (dev->probed)
-               DRV(dev->drv_id).free(dev->drv_data);
-       dev->probed = 0;
-       dev->drv_data = NULL;
-}
-
-static void in_free(in_dev_t *dev)
-{
-       in_unprobe(dev);
-       free(dev->name);
-       dev->name = NULL;
-       free(dev->binds);
-       dev->binds = NULL;
-}
-
-/* to be called by drivers
- * async devices must set drv_fd_hnd to -1 */
-void in_register(const char *nname, int drv_fd_hnd, void *drv_data,
-               int key_count, const char * const *key_names, int combos)
-{
-       int i, ret, dupe_count = 0, *binds;
-       char name[256], *name_end, *tmp;
-
-       strncpy(name, nname, sizeof(name));
-       name[sizeof(name)-12] = 0;
-       name_end = name + strlen(name);
-
-       for (i = 0; i < in_dev_count; i++)
-       {
-               if (in_devices[i].name == NULL)
-                       continue;
-               if (strcmp(in_devices[i].name, name) == 0)
-               {
-                       if (in_devices[i].probed) {
-                               dupe_count++;
-                               sprintf(name_end, " [%d]", dupe_count);
-                               continue;
-                       }
-                       goto update;
-               }
-       }
-
-       if (i >= IN_MAX_DEVS)
-       {
-               /* try to find unused device */
-               for (i = 0; i < IN_MAX_DEVS; i++)
-                       if (!in_devices[i].probed) break;
-               if (i >= IN_MAX_DEVS) {
-                       lprintf("input: too many devices, can't add %s\n", name);
-                       return;
-               }
-               in_free(&in_devices[i]);
-       }
-
-       tmp = strdup(name);
-       if (tmp == NULL)
-               return;
-
-       binds = in_alloc_binds(in_probe_dev_id, key_count);
-       if (binds == NULL) {
-               free(tmp);
-               return;
-       }
-
-       in_devices[i].name = tmp;
-       in_devices[i].binds = binds;
-       in_devices[i].key_count = key_count;
-       if (i + 1 > in_dev_count)
-               in_dev_count = i + 1;
-
-       lprintf("input: new device #%d \"%s\"\n", i, name);
-update:
-       in_devices[i].probed = 1;
-       in_devices[i].does_combos = combos;
-       in_devices[i].drv_id = in_probe_dev_id;
-       in_devices[i].drv_fd_hnd = drv_fd_hnd;
-       in_devices[i].key_names = key_names;
-       in_devices[i].drv_data = drv_data;
-
-       if (in_devices[i].binds != NULL) {
-               ret = DRV(in_probe_dev_id).clean_binds(drv_data, in_devices[i].binds,
-                       in_devices[i].binds + key_count * IN_BINDTYPE_COUNT);
-               if (ret == 0) {
-                       /* no useable binds */
-                       free(in_devices[i].binds);
-                       in_devices[i].binds = NULL;
-               }
-       }
-}
-
-/* key combo handling, to be called by drivers that support it.
- * Only care about IN_BINDTYPE_EMU */
-void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts)
-{
-       int act, u;
-
-       *combo_keys = *combo_acts = 0;
-       for (act = 0; act < sizeof(binds[0]) * 8; act++)
-       {
-               int keyc = 0;
-               for (u = 0; u <= last_key; u++)
-                       if (binds[IN_BIND_OFFS(u, IN_BINDTYPE_EMU)] & (1 << act))
-                               keyc++;
-
-               if (keyc > 1)
-               {
-                       // loop again and mark those keys and actions as combo
-                       for (u = 0; u <= last_key; u++)
-                       {
-                               if (binds[IN_BIND_OFFS(u, IN_BINDTYPE_EMU)] & (1 << act)) {
-                                       *combo_keys |= 1 << u;
-                                       *combo_acts |= 1 << act;
-                               }
-                       }
-               }
-       }
-}
-
-int in_combos_do(int keys, const int *binds, int last_key, int combo_keys, int combo_acts)
-{
-       int i, ret = 0;
-
-       for (i = 0; i <= last_key; i++)
-       {
-               int acts, acts_c, u;
-
-               if (!(keys & (1 << i)))
-                       continue;
-
-               acts = binds[IN_BIND_OFFS(i, IN_BINDTYPE_EMU)];
-               if (!acts)
-                       continue;
-
-               if (!(combo_keys & (1 << i))) {
-                       ret |= acts;
-                       continue;
-               }
-
-               acts_c = acts & combo_acts;
-               u = last_key;
-               if (acts_c) {
-                       // let's try to find the other one
-                       for (u = i + 1; u <= last_key; u++)
-                               if ( (keys & (1 << u)) && (binds[IN_BIND_OFFS(u, IN_BINDTYPE_EMU)] & acts_c) ) {
-                                       ret |= acts_c & binds[IN_BIND_OFFS(u, IN_BINDTYPE_EMU)];
-                                       keys &= ~((1 << i) | (1 << u));
-                                       break;
-                               }
-               }
-               // add non-combo actions if combo ones were not found
-               if (u >= last_key)
-                       ret |= acts & ~combo_acts;
-       }
-
-       return ret;
-}
-
-void in_probe(void)
-{
-       int i;
-
-       in_have_async_devs = 0;
-       menu_key_state = 0;
-       menu_last_used_dev = 0;
-
-       for (i = 0; i < in_dev_count; i++)
-               in_unprobe(&in_devices[i]);
-
-       for (i = 0; i < in_driver_count; i++) {
-               in_probe_dev_id = i;
-               in_drivers[i].probe();
-       }
-
-       /* get rid of devs without binds and probes */
-       for (i = 0; i < in_dev_count; i++) {
-               if (!in_devices[i].probed && in_devices[i].binds == NULL) {
-                       in_dev_count--;
-                       if (i < in_dev_count) {
-                               free(in_devices[i].name);
-                               memmove(&in_devices[i], &in_devices[i+1],
-                                       (in_dev_count - i) * sizeof(in_devices[0]));
-                       }
-
-                       continue;
-               }
-
-               if (in_devices[i].probed && in_devices[i].drv_fd_hnd == -1)
-                       in_have_async_devs = 1;
-       }
-
-       if (in_have_async_devs)
-               lprintf("input: async-only devices detected..\n");
-
-       in_debug_dump();
-}
-
-/* async update */
-int in_update(int *result)
-{
-       int i, ret = 0;
-
-       for (i = 0; i < in_dev_count; i++) {
-               in_dev_t *dev = &in_devices[i];
-               if (dev->probed && dev->binds != NULL)
-                       ret |= DRV(dev->drv_id).update(dev->drv_data, dev->binds, result);
-       }
-
-       return ret;
-}
-
-static in_dev_t *get_dev(int dev_id)
-{
-       if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
-               return NULL;
-
-       return &in_devices[dev_id];
-}
-
-int in_update_analog(int dev_id, int axis_id, int *result)
-{
-       in_dev_t *dev = get_dev(dev_id);
-
-       if (dev == NULL || !dev->probed)
-               return -1;
-
-       return DRV(dev->drv_id).update_analog(dev->drv_data, axis_id, result);
-}
-
-static int in_update_kc_async(int *dev_id_out, int *is_down_out, int timeout_ms)
-{
-       int i, is_down, result;
-       unsigned int ticks;
-
-       ticks = plat_get_ticks_ms();
-
-       while (1)
-       {
-               for (i = 0; i < in_dev_count; i++) {
-                       in_dev_t *d = &in_devices[i];
-                       if (!d->probed)
-                               continue;
-
-                       result = DRV(d->drv_id).update_keycode(d->drv_data, &is_down);
-                       if (result == -1)
-                               continue;
-
-                       if (dev_id_out)
-                               *dev_id_out = i;
-                       if (is_down_out)
-                               *is_down_out = is_down;
-                       return result;
-               }
-
-               if (timeout_ms >= 0 && (int)(plat_get_ticks_ms() - ticks) > timeout_ms)
-                       break;
-
-               plat_sleep_ms(10);
-       }
-
-       return -1;
-}
-
-/* 
- * wait for a press, always return some keycode or -1 on timeout or error
- */
-int in_update_keycode(int *dev_id_out, int *is_down_out, char *charcode, int timeout_ms)
-{
-       int result = -1, dev_id = 0, is_down, result_menu;
-       int fds_hnds[IN_MAX_DEVS];
-       int i, ret, count = 0;
-       in_drv_t *drv = NULL;
-       unsigned int ticks;
-
-       if (in_have_async_devs) {
-               result = in_update_kc_async(&dev_id, &is_down, timeout_ms);
-               if (result == -1)
-                       return -1;
-               drv = &DRV(in_devices[dev_id].drv_id);
-               goto finish;
-       }
-
-       ticks = plat_get_ticks_ms();
-
-       for (i = 0; i < in_dev_count; i++) {
-               if (in_devices[i].probed)
-                       fds_hnds[count++] = in_devices[i].drv_fd_hnd;
-       }
-
-       if (count == 0) {
-               /* don't deadlock, fail */
-               lprintf("input: failed to find devices to read\n");
-               exit(1);
-       }
-
-       while (1)
-       {
-               ret = plat_wait_event(fds_hnds, count, timeout_ms);
-               if (ret < 0)
-                       break;
-
-               for (i = 0; i < in_dev_count; i++) {
-                       if (in_devices[i].drv_fd_hnd == ret) {
-                               dev_id = i;
-                               break;
-                       }
-               }
-
-               drv = &DRV(in_devices[dev_id].drv_id);
-               result = drv->update_keycode(in_devices[dev_id].drv_data, &is_down);
-               if (result >= 0)
-                       break;
-
-               if (result == -2) {
-                       lprintf("input: \"%s\" errored out, removing.\n", in_devices[dev_id].name);
-                       in_unprobe(&in_devices[dev_id]);
-                       break;
-               }
-
-               if (timeout_ms >= 0) {
-                       unsigned int ticks2 = plat_get_ticks_ms();
-                       timeout_ms -= ticks2 - ticks;
-                       ticks = ticks2;
-                       if (timeout_ms <= 0)
-                               break;
-               }
-       }
-
-       if (result < 0)
-               return -1;
-finish:
-       /* keep track of menu key state, to allow mixing
-        * in_update_keycode() and in_menu_wait_any() calls */
-       result_menu = drv->menu_translate(in_devices[dev_id].drv_data, result, charcode);
-       if (result_menu != 0) {
-               if (is_down)
-                       menu_key_state |=  result_menu;
-               else
-                       menu_key_state &= ~result_menu;
-       }
-
-       if (dev_id_out != NULL)
-               *dev_id_out = dev_id;
-       if (is_down_out != NULL)
-               *is_down_out = is_down;
-       return result;
-}
-
-/* same as above, only return bitfield of PBTN_*  */
-int in_menu_wait_any(char *charcode, int timeout_ms)
-{
-       int keys_old = menu_key_state;
-
-       while (1)
-       {
-               int code, is_down = 0, dev_id = 0;
-
-               code = in_update_keycode(&dev_id, &is_down, charcode, timeout_ms);
-               if (code < 0)
-                       break;
-
-               if (keys_old != menu_key_state) {
-                       menu_last_used_dev = dev_id;
-                       break;
-               }
-       }
-
-       return menu_key_state;
-}
-
-/* wait for menu input, do autorepeat */
-int in_menu_wait(int interesting, char *charcode, int autorep_delay_ms)
-{
-       static int inp_prev = 0;
-       static int repeats = 0;
-       int ret, release = 0, wait = 450;
-
-       if (repeats)
-               wait = autorep_delay_ms;
-
-       ret = in_menu_wait_any(charcode, wait);
-       if (ret == inp_prev)
-               repeats++;
-
-       while (!(ret & interesting)) {
-               ret = in_menu_wait_any(charcode, -1);
-               release = 1;
-       }
-
-       if (release || ret != inp_prev)
-               repeats = 0;
-
-       inp_prev = ret;
-
-       /* we don't need diagonals in menus */
-       if ((ret & PBTN_UP)   && (ret & PBTN_LEFT))  ret &= ~PBTN_LEFT;
-       if ((ret & PBTN_UP)   && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
-       if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT))  ret &= ~PBTN_LEFT;
-       if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
-
-       return ret;
-}
-
-const int *in_get_dev_binds(int dev_id)
-{
-       in_dev_t *dev = get_dev(dev_id);
-
-       return dev ? dev->binds : NULL;
-}
-
-const int *in_get_dev_def_binds(int dev_id)
-{
-       in_dev_t *dev = get_dev(dev_id);
-       if (dev == NULL)
-               return NULL;
-
-       return dev->binds + dev->key_count * IN_BINDTYPE_COUNT;
-}
-
-int in_get_config(int dev_id, int what, void *val)
-{
-       int *ival = val;
-       in_dev_t *dev;
-
-       dev = get_dev(dev_id);
-       if (dev == NULL || val == NULL)
-               return -1;
-
-       switch (what) {
-       case IN_CFG_BIND_COUNT:
-               *ival = dev->key_count;
-               break;
-       case IN_CFG_DOES_COMBOS:
-               *ival = dev->does_combos;
-               break;
-       case IN_CFG_BLOCKING:
-       case IN_CFG_KEY_NAMES:
-               return -1; /* not implemented */
-       default:
-               return DRV(dev->drv_id).get_config(dev->drv_data, what, ival);
-       }
-
-       return 0;
-}
-
-static int in_set_blocking(int is_blocking)
-{
-       int i, ret;
-
-       /* have_async_devs means we will have to do all reads async anyway.. */
-       if (!in_have_async_devs) {
-               for (i = 0; i < in_dev_count; i++) {
-                       if (in_devices[i].probed)
-                               DRV(in_devices[i].drv_id).set_config(in_devices[i].drv_data,
-                                                                    IN_CFG_BLOCKING, is_blocking);
-               }
-       }
-
-       menu_key_state = 0;
-
-       /* flush events */
-       do {
-               ret = in_update_keycode(NULL, NULL, NULL, 0);
-       } while (ret >= 0);
-
-       return 0;
-}
-
-int in_set_config(int dev_id, int what, const void *val, int size)
-{
-       const char * const *names;
-       const int *ival = val;
-       in_dev_t *dev;
-       int count;
-
-       if (what == IN_CFG_BLOCKING)
-               return in_set_blocking(*ival);
-
-       dev = get_dev(dev_id);
-       if (dev == NULL)
-               return -1;
-
-       switch (what) {
-       case IN_CFG_KEY_NAMES:
-               names = val;
-               count = size / sizeof(names[0]);
-
-               if (count < dev->key_count) {
-                       lprintf("input: set_key_names: not enough keys\n");
-                       return -1;
-               }
-
-               dev->key_names = names;
-               return 0;
-       case IN_CFG_DEFAULT_DEV:
-               /* just set last used dev, for now */
-               menu_last_used_dev = dev_id;
-               return 0;
-       default:
-               break;
-       }
-
-       if (dev->probed)
-               return DRV(dev->drv_id).set_config(dev->drv_data, what, *ival);
-
-       return -1;
-}
-
-const char *in_get_dev_name(int dev_id, int must_be_active, int skip_pfix)
-{
-       const char *name, *tmp;
-       in_dev_t *dev;
-
-       dev = get_dev(dev_id);
-       if (dev == NULL)
-               return NULL;
-
-       if (must_be_active && !dev->probed)
-               return NULL;
-
-       name = dev->name;
-       if (name == NULL || !skip_pfix)
-               return name;
-
-       /* skip prefix */
-       tmp = strchr(name, ':');
-       if (tmp != NULL)
-               name = tmp + 1;
-
-       return name;
-}
-
-int in_name_to_id(const char *dev_name)
-{
-       int i;
-
-       for (i = 0; i < in_dev_count; i++)
-               if (strcmp(dev_name, in_devices[i].name) == 0)
-                       break;
-
-       if (i >= in_dev_count) {
-               lprintf("input: in_name_to_id: no such device: %s\n", dev_name);
-               return -1;
-       }
-
-       return i;
-}
-
-/* never returns NULL */
-const char *in_get_key_name(int dev_id, int keycode)
-{
-       const char *name = NULL;
-       static char xname[16];
-       in_drv_t *drv;
-       in_dev_t *dev;
-
-       if (dev_id < 0)         /* want last used dev? */
-               dev_id = menu_last_used_dev;
-
-       dev = get_dev(dev_id);
-       if (dev == NULL)
-               return "Unkn0";
-
-       drv = &DRV(dev->drv_id);
-       if (keycode < 0)        /* want name for menu key? */
-               keycode = drv->menu_translate(dev->drv_data, keycode, NULL);
-
-       if (dev->key_names != NULL && 0 <= keycode && keycode < dev->key_count)
-               name = dev->key_names[keycode];
-       if (name != NULL)
-               return name;
-
-       if (drv->get_key_name != NULL)
-               name = drv->get_key_name(keycode);
-       if (name != NULL)
-               return name;
-
-       /* assume scancode */
-       if ((keycode >= '0' && keycode <= '9') || (keycode >= 'a' && keycode <= 'z')
-                       || (keycode >= 'A' && keycode <= 'Z'))
-               sprintf(xname, "%c", keycode);
-       else
-               sprintf(xname, "\\x%02X", keycode);
-       return xname;
-}
-
-int in_get_key_code(int dev_id, const char *key_name)
-{
-       in_dev_t *dev;
-       int i;
-
-       if (dev_id < 0)         /* want last used dev? */
-               dev_id = menu_last_used_dev;
-
-       dev = get_dev(dev_id);
-       if (dev == NULL)
-               return -1;
-
-       if (dev->key_names == NULL)
-               return -1;
-
-       for (i = 0; i < dev->key_count; i++)
-               if (dev->key_names[i] && strcasecmp(dev->key_names[i], key_name) == 0)
-                       return i;
-
-       return -1;
-}
-
-int in_bind_key(int dev_id, int keycode, int mask, int bind_type, int force_unbind)
-{
-       int ret, count;
-       in_dev_t *dev;
-
-       dev = get_dev(dev_id);
-       if (dev == NULL || bind_type >= IN_BINDTYPE_COUNT)
-               return -1;
-
-       count = dev->key_count;
-
-       if (dev->binds == NULL) {
-               if (force_unbind)
-                       return 0;
-               dev->binds = in_alloc_binds(dev->drv_id, count);
-               if (dev->binds == NULL)
-                       return -1;
-       }
-
-       if (keycode < 0 || keycode >= count)
-               return -1;
-       
-       if (force_unbind)
-               dev->binds[IN_BIND_OFFS(keycode, bind_type)] &= ~mask;
-       else
-               dev->binds[IN_BIND_OFFS(keycode, bind_type)] ^=  mask;
-       
-       ret = DRV(dev->drv_id).clean_binds(dev->drv_data, dev->binds,
-                               dev->binds + count * IN_BINDTYPE_COUNT);
-       if (ret == 0) {
-               free(dev->binds);
-               dev->binds = NULL;
-       }
-
-       return 0;
-}
-
-/*
- * Unbind act_mask on binds with type bind_type
- * - if dev_id_ < 0, affects all devices
- *   else only affects dev_id_
- * - if act_mask == -1, unbind all keys
- *   else only actions in mask
- */
-void in_unbind_all(int dev_id_, int act_mask, int bind_type)
-{
-       int dev_id = 0, dev_last = IN_MAX_DEVS - 1;
-       int i, count;
-       in_dev_t *dev;
-
-       if (dev_id_ >= 0)
-               dev_id = dev_last = dev_id_;
-
-       if (bind_type >= IN_BINDTYPE_COUNT)
-               return;
-
-       for (; dev_id <= dev_last; dev_id++) {
-               dev = &in_devices[dev_id];
-               count = dev->key_count;
-
-               if (dev->binds == NULL)
-                       continue;
-
-               if (act_mask != -1) {
-                       for (i = 0; i < count; i++)
-                               dev->binds[IN_BIND_OFFS(i, bind_type)] &= ~act_mask;
-               }
-               else
-                       memset(dev->binds, 0, sizeof(dev->binds[0]) * count * IN_BINDTYPE_COUNT);
-       }
-}
-
-/* returns device id, or -1 on error */
-int in_config_parse_dev(const char *name)
-{
-       int drv_id = -1, i;
-
-       for (i = 0; i < in_driver_count; i++) {
-               int len = strlen(in_drivers[i].prefix);
-               if (strncmp(name, in_drivers[i].prefix, len) == 0) {
-                       drv_id = i;
-                       break;
-               }
-       }
-
-       if (drv_id < 0) {
-               lprintf("input: missing driver for %s\n", name);
-               return -1;
-       }
-
-       for (i = 0; i < in_dev_count; i++)
-       {
-               if (in_devices[i].name == NULL)
-                       continue;
-               if (strcmp(in_devices[i].name, name) == 0)
-                       return i;
-       }
-
-       if (i >= IN_MAX_DEVS)
-       {
-               /* try to find unused device */
-               for (i = 0; i < IN_MAX_DEVS; i++)
-                       if (in_devices[i].name == NULL) break;
-               if (i >= IN_MAX_DEVS) {
-                       lprintf("input: too many devices, can't add %s\n", name);
-                       return -1;
-               }
-       }
-
-       memset(&in_devices[i], 0, sizeof(in_devices[i]));
-
-       in_devices[i].name = strdup(name);
-       if (in_devices[i].name == NULL)
-               return -1;
-
-       in_devices[i].key_names = DRV(drv_id).get_key_names(&in_devices[i].key_count);
-       in_devices[i].drv_id = drv_id;
-
-       if (i + 1 > in_dev_count)
-               in_dev_count = i + 1;
-
-       return i;
-}
-
-int in_config_bind_key(int dev_id, const char *key, int acts, int bind_type)
-{
-       in_dev_t *dev;
-       int i, offs, kc;
-
-       dev = get_dev(dev_id);
-       if (dev == NULL || bind_type >= IN_BINDTYPE_COUNT)
-               return -1;
-
-       /* maybe a raw code? */
-       if (key[0] == '\\' && key[1] == 'x') {
-               char *p = NULL;
-               kc = (int)strtoul(key + 2, &p, 16);
-               if (p == NULL || *p != 0)
-                       kc = -1;
-       }
-       else {
-               /* device specific key name */
-               if (dev->binds == NULL) {
-                       dev->binds = in_alloc_binds(dev->drv_id, dev->key_count);
-                       if (dev->binds == NULL)
-                               return -1;
-               }
-
-               kc = -1;
-               if (dev->key_names != NULL) {
-                       for (i = 0; i < dev->key_count; i++) {
-                               const char *k = dev->key_names[i];
-                               if (k != NULL && strcasecmp(k, key) == 0) {
-                                       kc = i;
-                                       break;
-                               }
-                       }
-               }
-
-               if (kc < 0)
-                       kc = DRV(dev->drv_id).get_key_code(key);
-               if (kc < 0 && strlen(key) == 1) {
-                       /* assume scancode */
-                       kc = key[0];
-               }
-       }
-
-       if (kc < 0 || kc >= dev->key_count) {
-               lprintf("input: bad key: %s\n", key);
-               return -1;
-       }
-
-       if (bind_type == IN_BINDTYPE_NONE) {
-               for (i = 0; i < IN_BINDTYPE_COUNT; i++)
-                       dev->binds[IN_BIND_OFFS(kc, i)] = 0;
-               return 0;
-       }
-
-       offs = IN_BIND_OFFS(kc, bind_type);
-       if (dev->binds[offs] == -1)
-               dev->binds[offs] = 0;
-       dev->binds[offs] |= acts;
-       return 0;
-}
-
-void in_clean_binds(void)
-{
-       int i;
-
-       for (i = 0; i < IN_MAX_DEVS; i++) {
-               int ret, count, *binds, *def_binds;
-               in_dev_t *dev = &in_devices[i];
-
-               if (dev->binds == NULL || dev->drv_data == NULL)
-                       continue;
-
-               count = dev->key_count;
-               binds = dev->binds;
-               def_binds = binds + count * IN_BINDTYPE_COUNT;
-
-               ret = DRV(dev->drv_id).clean_binds(dev->drv_data, binds, def_binds);
-               if (ret == 0) {
-                       /* no useable binds */
-                       free(dev->binds);
-                       dev->binds = NULL;
-               }
-       }
-}
-
-void in_debug_dump(void)
-{
-       int i;
-
-       lprintf("# drv probed binds name\n");
-       for (i = 0; i < IN_MAX_DEVS; i++) {
-               in_dev_t *d = &in_devices[i];
-               if (!d->probed && d->name == NULL && d->binds == NULL)
-                       continue;
-               lprintf("%d %3d %6c %5c %s\n", i, d->drv_id, d->probed ? 'y' : 'n',
-                       d->binds ? 'y' : 'n', d->name);
-       }
-}
-
-/* stubs for drivers that choose not to implement something */
-
-static void in_def_free(void *drv_data) {}
-static int  in_def_clean_binds(void *drv_data, int *b, int *db) { return 1; }
-static int  in_def_get_config(void *drv_data, int what, int *val) { return -1; }
-static int  in_def_set_config(void *drv_data, int what, int val) { return -1; }
-static int  in_def_update_analog(void *drv_data, int axis_id, int *result) { return -1; }
-static int  in_def_update_keycode(void *drv_data, int *is_down) { return 0; }
-static int  in_def_menu_translate(void *drv_data, int keycode, char *ccode) { return 0; }
-static int  in_def_get_key_code(const char *key_name) { return -1; }
-static const char *in_def_get_key_name(int keycode) { return NULL; }
-
-#define CHECK_ADD_STUB(d, f) \
-       if (d.f == NULL) d.f = in_def_##f
-
-/* to be called by drivers */
-int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds)
-{
-       int count_new = in_driver_count + 1;
-       in_drv_t *new_drivers;
-
-       new_drivers = realloc(in_drivers, count_new * sizeof(in_drivers[0]));
-       if (new_drivers == NULL) {
-               lprintf("input: in_register_driver OOM\n");
-               return -1;
-       }
-
-       memcpy(&new_drivers[in_driver_count], drv, sizeof(new_drivers[0]));
-
-       CHECK_ADD_STUB(new_drivers[in_driver_count], free);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], clean_binds);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], get_config);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], set_config);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], update_analog);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], update_keycode);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], menu_translate);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_name);
-       if (defbinds != NULL)
-               new_drivers[in_driver_count].defbinds = defbinds;
-       in_drivers = new_drivers;
-       in_driver_count = count_new;
-
-       return 0;
-}
-
-void in_init(void)
-{
-       in_drivers = NULL;
-       memset(in_devices, 0, sizeof(in_devices));
-       in_driver_count = 0;
-       in_dev_count = 0;
-}
-
-#if 0
-int main(void)
-{
-       int ret;
-
-       in_init();
-       in_probe();
-
-       in_set_blocking(1);
-
-#if 1
-       while (1) {
-               int dev = 0, down;
-               ret = in_update_keycode(&dev, &down);
-               lprintf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret));
-       }
-#else
-       while (1) {
-               ret = in_menu_wait_any();
-               lprintf("%08x\n", ret);
-       }
-#endif
-
-       return 0;
-}
-#endif
diff --git a/platform/common/input.h b/platform/common/input.h
deleted file mode 100644 (file)
index e87e6ea..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-#ifndef INCLUDE_uXt8Z4R7EMpuEEtvSibXjNhKH3741VNc
-#define INCLUDE_uXt8Z4R7EMpuEEtvSibXjNhKH3741VNc 1
-
-#define IN_MAX_DEVS 10
-#define IN_ABS_RANGE 1024      /* abs must be centered at 0, move upto +- this */
-
-/* unified menu keys */
-#define PBTN_UP    (1 <<  0)
-#define PBTN_DOWN  (1 <<  1)
-#define PBTN_LEFT  (1 <<  2)
-#define PBTN_RIGHT (1 <<  3)
-
-#define PBTN_MOK   (1 <<  4)
-#define PBTN_MBACK (1 <<  5)
-#define PBTN_MA2   (1 <<  6)   /* menu action 2 */
-#define PBTN_MA3   (1 <<  7)
-
-#define PBTN_L     (1 <<  8)
-#define PBTN_R     (1 <<  9)
-
-#define PBTN_MENU  (1 << 10)
-
-#define PBTN_CHAR  (1 << 11)   /* character (text input) */
-
-// TODO: move to pico
-#if 0
-
-/* ui events */
-#define PEVB_VOL_DOWN   30
-#define PEVB_VOL_UP     29
-#define PEVB_STATE_LOAD 28
-#define PEVB_STATE_SAVE 27
-#define PEVB_SWITCH_RND 26
-#define PEVB_SSLOT_PREV 25
-#define PEVB_SSLOT_NEXT 24
-#define PEVB_MENU       23
-#define PEVB_FF         22
-#define PEVB_PICO_PNEXT 21
-#define PEVB_PICO_PPREV 20
-#define PEVB_PICO_SWINP 19
-
-#define PEV_VOL_DOWN    (1 << PEVB_VOL_DOWN)
-#define PEV_VOL_UP      (1 << PEVB_VOL_UP)
-#define PEV_STATE_LOAD  (1 << PEVB_STATE_LOAD)
-#define PEV_STATE_SAVE  (1 << PEVB_STATE_SAVE)
-#define PEV_SWITCH_RND  (1 << PEVB_SWITCH_RND)
-#define PEV_SSLOT_PREV  (1 << PEVB_SSLOT_PREV)
-#define PEV_SSLOT_NEXT  (1 << PEVB_SSLOT_NEXT)
-#define PEV_MENU        (1 << PEVB_MENU)
-#define PEV_FF          (1 << PEVB_FF)
-#define PEV_PICO_PNEXT  (1 << PEVB_PICO_PNEXT)
-#define PEV_PICO_PPREV  (1 << PEVB_PICO_PPREV)
-#define PEV_PICO_SWINP  (1 << PEVB_PICO_SWINP)
-
-#define PEV_MASK 0x7ff80000
-
-#endif
-
-enum {
-       IN_CFG_BIND_COUNT = 0,
-       IN_CFG_DOES_COMBOS,
-       IN_CFG_BLOCKING,
-       IN_CFG_KEY_NAMES,
-       IN_CFG_ABS_DEAD_ZONE,   /* dead zone for analog-digital mapping */
-       IN_CFG_ABS_AXIS_COUNT,  /* number of abs axes (ro) */
-       IN_CFG_DEFAULT_DEV,
-};
-
-enum {
-       IN_BINDTYPE_NONE = -1,
-       IN_BINDTYPE_EMU = 0,
-       IN_BINDTYPE_PLAYER12,
-       IN_BINDTYPE_COUNT
-};
-
-#define IN_BIND_OFFS(key, btype) \
-       ((key) * IN_BINDTYPE_COUNT + (btype))
-
-typedef struct {
-       const char *prefix;
-       void (*probe)(void);
-       void (*free)(void *drv_data);
-       const char * const *
-            (*get_key_names)(int *count);
-       int  (*clean_binds)(void *drv_data, int *binds, int *def_finds);
-       int  (*get_config)(void *drv_data, int what, int *val);
-       int  (*set_config)(void *drv_data, int what, int val);
-       int  (*update)(void *drv_data, const int *binds, int *result);
-       int  (*update_analog)(void *drv_data, int axis_id, int *result);
-       /* return -1 on no event, -2 on error */
-       int  (*update_keycode)(void *drv_data, int *is_down);
-       int  (*menu_translate)(void *drv_data, int keycode, char *charcode);
-       int  (*get_key_code)(const char *key_name);
-       const char * (*get_key_name)(int keycode);
-
-       const struct in_default_bind *defbinds;
-} in_drv_t;
-
-struct in_default_bind {
-       unsigned short code;
-       unsigned char btype;    /* IN_BINDTYPE_* */
-       unsigned char bit;
-};
-
-/* to be called by drivers */
-int  in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds);
-void in_register(const char *nname, int drv_fd_hnd, void *drv_data,
-               int key_count, const char * const *key_names, int combos);
-void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts);
-int  in_combos_do(int keys, const int *binds, int last_key, int combo_keys, int combo_acts);
-
-void in_init(void);
-void in_probe(void);
-int  in_update(int *result);
-int  in_update_analog(int dev_id, int axis_id, int *value);
-int  in_update_keycode(int *dev_id, int *is_down, char *charcode, int timeout_ms);
-int  in_menu_wait_any(char *charcode, int timeout_ms);
-int  in_menu_wait(int interesting, char *charcode, int autorep_delay_ms);
-int  in_config_parse_dev(const char *dev_name);
-int  in_config_bind_key(int dev_id, const char *key, int binds, int bind_type);
-int  in_get_config(int dev_id, int what, void *val);
-int  in_set_config(int dev_id, int what, const void *val, int size);
-int  in_get_key_code(int dev_id, const char *key_name);
-int  in_name_to_id(const char *dev_name);
-int  in_bind_key(int dev_id, int keycode, int mask, int bind_type, int force_unbind);
-void in_unbind_all(int dev_id, int act_mask, int bind_type);
-void in_clean_binds(void);
-void in_debug_dump(void);
-
-const int  *in_get_dev_binds(int dev_id);
-const int  *in_get_dev_def_binds(int dev_id);
-const char *in_get_dev_name(int dev_id, int must_be_active, int skip_pfix);
-const char *in_get_key_name(int dev_id, int keycode);
-
-#define in_set_config_int(dev_id, what, v) { \
-       int val_ = v; \
-       in_set_config(dev_id, what, &val_, sizeof(val_)); \
-}
-
-#endif /* INCLUDE_uXt8Z4R7EMpuEEtvSibXjNhKH3741VNc */
diff --git a/platform/common/input_pico.h b/platform/common/input_pico.h
new file mode 100644 (file)
index 0000000..fbf328a
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef INCLUDE_c48097f3ff2a6a9af1cce8fd7a9b3f0c
+#define INCLUDE_c48097f3ff2a6a9af1cce8fd7a9b3f0c 1
+
+/* ui events */
+#define PEVB_VOL_DOWN   30
+#define PEVB_VOL_UP     29
+#define PEVB_STATE_LOAD 28
+#define PEVB_STATE_SAVE 27
+#define PEVB_SWITCH_RND 26
+#define PEVB_SSLOT_PREV 25
+#define PEVB_SSLOT_NEXT 24
+#define PEVB_MENU       23
+#define PEVB_FF         22
+#define PEVB_PICO_PNEXT 21
+#define PEVB_PICO_PPREV 20
+#define PEVB_PICO_SWINP 19
+
+#define PEV_VOL_DOWN    (1 << PEVB_VOL_DOWN)
+#define PEV_VOL_UP      (1 << PEVB_VOL_UP)
+#define PEV_STATE_LOAD  (1 << PEVB_STATE_LOAD)
+#define PEV_STATE_SAVE  (1 << PEVB_STATE_SAVE)
+#define PEV_SWITCH_RND  (1 << PEVB_SWITCH_RND)
+#define PEV_SSLOT_PREV  (1 << PEVB_SSLOT_PREV)
+#define PEV_SSLOT_NEXT  (1 << PEVB_SSLOT_NEXT)
+#define PEV_MENU        (1 << PEVB_MENU)
+#define PEV_FF          (1 << PEVB_FF)
+#define PEV_PICO_PNEXT  (1 << PEVB_PICO_PNEXT)
+#define PEV_PICO_PPREV  (1 << PEVB_PICO_PPREV)
+#define PEV_PICO_SWINP  (1 << PEVB_PICO_SWINP)
+
+#define PEV_MASK 0x7ff80000
+
+#endif /* INCLUDE_c48097f3ff2a6a9af1cce8fd7a9b3f0c */
diff --git a/platform/common/lprintf.h b/platform/common/lprintf.h
deleted file mode 100644 (file)
index 48b8d57..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void lprintf(const char *fmt, ...);
-
-#ifdef __cplusplus
-}
-#endif
-
index 48f218f..5f31b06 100644 (file)
@@ -8,11 +8,11 @@
 #include <string.h>\r
 #include <strings.h>\r
 \r
-#include "menu.h"\r
+#include "../libpicofe/input.h"\r
+#include "../libpicofe/plat.h"\r
+#include "menu_pico.h"\r
 #include "emu.h"\r
 #include "config.h"\r
-#include "input.h"\r
-#include "plat.h"\r
 #include <cpu/debug.h>\r
 #include <version.h>\r
 \r
@@ -72,12 +72,12 @@ int main(int argc, char *argv[])
 {\r
        g_argv = argv;\r
 \r
-       plat_early_init();\r
+       //plat_early_init();\r
 \r
        in_init();\r
        in_probe();\r
 \r
-       plat_init();\r
+       plat_target_init();\r
 \r
        emu_prep_defconfig(); // depends on input\r
        emu_read_config(NULL, 0);\r
@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
        endloop:\r
 \r
        emu_finish();\r
-       plat_finish();\r
+       plat_target_finish();\r
 \r
        return 0;\r
 }\r
diff --git a/platform/common/menu.c b/platform/common/menu.c
deleted file mode 100644 (file)
index 3acab62..0000000
+++ /dev/null
@@ -1,1327 +0,0 @@
-/*\r
- * (C) Gražvydas "notaz" Ignotas, 2006-2011\r
- *\r
- * This work is licensed under the terms of any of these licenses\r
- * (at your option):\r
- *  - GNU GPL, version 2 or later.\r
- *  - GNU LGPL, version 2.1 or later.\r
- * See the COPYING file in the top-level directory.\r
- */\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-#include <time.h>\r
-#include <locale.h> // savestate date\r
-\r
-#include "menu.h"\r
-#include "fonts.h"\r
-#include "readpng.h"\r
-#include "lprintf.h"\r
-#include "input.h"\r
-#include "plat.h"\r
-#include "posix.h"\r
-\r
-static char static_buff[64];\r
-static int  menu_error_time = 0;\r
-char menu_error_msg[64] = { 0, };\r
-void *g_menuscreen_ptr;\r
-void *g_menubg_src_ptr;\r
-void *g_menubg_ptr;\r
-\r
-#if !MSCREEN_SIZE_FIXED\r
-int g_menuscreen_w;\r
-int g_menuscreen_h;\r
-#endif\r
-\r
-static unsigned char *menu_font_data = NULL;\r
-static int menu_text_color = 0xffff; // default to white\r
-static int menu_sel_color = -1; // disabled\r
-\r
-/* note: these might become non-constant in future */\r
-#if MENU_X2\r
-static const int me_mfont_w = 16, me_mfont_h = 20;\r
-static const int me_sfont_w = 12, me_sfont_h = 20;\r
-#else\r
-static const int me_mfont_w = 8, me_mfont_h = 10;\r
-static const int me_sfont_w = 6, me_sfont_h = 10;\r
-#endif\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, lh, tr, tg, tb, len;\r
-       unsigned short *dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w;\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
-       {\r
-               const char *p;\r
-               for (p = text; *p != 0 && *p != '\n'; p++)\r
-                       ;\r
-               len = p - text;\r
-       }\r
-\r
-       lh = me_mfont_h;\r
-       if (y + lh > g_menuscreen_h)\r
-               lh = g_menuscreen_h - y;\r
-\r
-       for (i = 0; i < len; i++)\r
-       {\r
-               unsigned char  *src = menu_font_data + (unsigned int)text[i] * me_mfont_w * me_mfont_h / 2;\r
-               unsigned short *dst = dest;\r
-               int u, l;\r
-\r
-               for (l = 0; l < lh; l++, dst += g_menuscreen_w - me_mfont_w)\r
-               {\r
-                       for (u = me_mfont_w / 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 += me_mfont_w;\r
-       }\r
-}\r
-\r
-void text_out16(int x, int y, const char *texto, ...)\r
-{\r
-       va_list args;\r
-       char    buffer[256];\r
-       int     maxw = (g_menuscreen_w - x) / me_mfont_w;\r
-\r
-       if (maxw < 0)\r
-               return;\r
-\r
-       va_start(args, texto);\r
-       vsnprintf(buffer, sizeof(buffer), texto, args);\r
-       va_end(args);\r
-\r
-       if (maxw > sizeof(buffer) - 1)\r
-               maxw = sizeof(buffer) - 1;\r
-       buffer[maxw] = 0;\r
-\r
-       text_out16_(x,y,buffer,menu_text_color);\r
-}\r
-\r
-/* draws in 6x8 font, might multiply size by integer */\r
-static void smalltext_out16_(int x, int y, const char *texto, int color)\r
-{\r
-       unsigned char  *src;\r
-       unsigned short *dst;\r
-       int multiplier = me_sfont_w / 6;\r
-       int i;\r
-\r
-       for (i = 0;; i++, x += me_sfont_w)\r
-       {\r
-               unsigned char c = (unsigned char) texto[i];\r
-               int h = 8;\r
-\r
-               if (!c || c == '\n')\r
-                       break;\r
-\r
-               src = fontdata6x8[c];\r
-               dst = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w;\r
-\r
-               while (h--)\r
-               {\r
-                       int m, w2, h2;\r
-                       for (h2 = multiplier; h2 > 0; h2--)\r
-                       {\r
-                               for (m = 0x20; m; m >>= 1) {\r
-                                       if (*src & m)\r
-                                               for (w2 = multiplier; w2 > 0; w2--)\r
-                                                       *dst++ = color;\r
-                                       else\r
-                                               dst += multiplier;\r
-                               }\r
-\r
-                               dst += g_menuscreen_w - me_sfont_w;\r
-                       }\r
-                       src++;\r
-               }\r
-       }\r
-}\r
-\r
-static void smalltext_out16(int x, int y, const char *texto, int color)\r
-{\r
-       char buffer[128];\r
-       int maxw = (g_menuscreen_w - x) / me_sfont_w;\r
-\r
-       if (maxw < 0)\r
-               return;\r
-\r
-       strncpy(buffer, texto, sizeof(buffer));\r
-       if (maxw > sizeof(buffer) - 1)\r
-               maxw = sizeof(buffer) - 1;\r
-       buffer[maxw] = 0;\r
-\r
-       smalltext_out16_(x, y, buffer, color);\r
-}\r
-\r
-static 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 *)g_menuscreen_ptr + x + y * g_menuscreen_w + me_mfont_w * 2 - 2;\r
-       for (h = me_mfont_h + 1; h > 0; h--)\r
-       {\r
-               dst = dest;\r
-               for (i = w - (me_mfont_w * 2 - 2); i > 0; i--)\r
-                       *dst++ = menu_sel_color;\r
-               dest += g_menuscreen_w;\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)\r
-#ifdef PSP\r
-               return ((t<<8)&0xf800) | ((t>>5)&0x07e0) | ((t>>19)&0x1f);\r
-#else\r
-               return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f);\r
-#endif\r
-       return -1;\r
-}\r
-\r
-static char tolower_simple(char c)\r
-{\r
-       if ('A' <= c && c <= 'Z')\r
-               c = c - 'A' + 'a';\r
-       return c;\r
-}\r
-\r
-void menu_init(void)\r
-{\r
-       int i, c, l;\r
-       unsigned char *fd, *fds;\r
-       char buff[256];\r
-       FILE *f;\r
-\r
-       if (menu_font_data != NULL)\r
-               free(menu_font_data);\r
-\r
-       menu_font_data = calloc((MENU_X2 ? 256 * 320 : 128 * 160) / 2, 1);\r
-       if (menu_font_data == NULL)\r
-               return;\r
-\r
-       // generate default 8x10 font from fontdata8x8\r
-       for (c = 0, fd = menu_font_data; 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
-       if (MENU_X2) {\r
-               // expand default font\r
-               fds = menu_font_data + 128 * 160 / 2 - 4;\r
-               fd  = menu_font_data + 256 * 320 / 2 - 1;\r
-               for (c = 255; c >= 0; c--)\r
-               {\r
-                       for (l = 9; l >= 0; l--, fds -= 4)\r
-                       {\r
-                               for (i = 3; i >= 0; i--) {\r
-                                       int px = fds[i] & 0x0f;\r
-                                       *fd-- = px | (px << 4);\r
-                                       px = (fds[i] >> 4) & 0x0f;\r
-                                       *fd-- = px | (px << 4);\r
-                               }\r
-                               for (i = 3; i >= 0; i--) {\r
-                                       int px = fds[i] & 0x0f;\r
-                                       *fd-- = px | (px << 4);\r
-                                       px = (fds[i] >> 4) & 0x0f;\r
-                                       *fd-- = px | (px << 4);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       // load custom font and selector (stored as 1st symbol in font table)\r
-       emu_make_path(buff, "skin/font.png", sizeof(buff));\r
-       readpng(menu_font_data, buff, READPNG_FONT,\r
-               MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160);\r
-       // default selector symbol is '>'\r
-       memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,\r
-               me_mfont_w * me_mfont_h / 2);\r
-       emu_make_path(buff, "skin/selector.png", sizeof(buff));\r
-       readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h);\r
-\r
-       // load custom colors\r
-       emu_make_path(buff, "skin/skin.txt", sizeof(buff));\r
-       f = fopen(buff, "r");\r
-       if (f != NULL)\r
-       {\r
-               lprintf("found skin.txt\n");\r
-               while (!feof(f))\r
-               {\r
-                       if (fgets(buff, sizeof(buff), f) == NULL)\r
-                               break;\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
-       // use user's locale for savestate date display\r
-       setlocale(LC_TIME, "");\r
-}\r
-\r
-static void menu_draw_begin(int need_bg)\r
-{\r
-       plat_video_menu_begin();\r
-       if (need_bg)\r
-               memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2);\r
-}\r
-\r
-static void menu_draw_end(void)\r
-{\r
-       plat_video_menu_end();\r
-}\r
-\r
-static void menu_darken_bg(void *dst, void *src, int pixels, int darker)\r
-{\r
-       unsigned int *dest = dst;\r
-       unsigned int *sorc = src;\r
-       pixels /= 2;\r
-       if (darker)\r
-       {\r
-               while (pixels--)\r
-               {\r
-                       unsigned int p = *sorc++;\r
-                       *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);\r
-               }\r
-       }\r
-       else\r
-       {\r
-               while (pixels--)\r
-               {\r
-                       unsigned int p = *sorc++;\r
-                       *dest++ = (p&0xf79ef79e)>>1;\r
-               }\r
-       }\r
-}\r
-\r
-static int me_id2offset(const menu_entry *ent, menu_id id)\r
-{\r
-       int i;\r
-       for (i = 0; ent->name; ent++, i++)\r
-               if (ent->id == id) return i;\r
-\r
-       lprintf("%s: id %i not found\n", __FUNCTION__, id);\r
-       return 0;\r
-}\r
-\r
-static void me_enable(menu_entry *entries, menu_id id, int enable)\r
-{\r
-       int i = me_id2offset(entries, id);\r
-       entries[i].enabled = enable;\r
-}\r
-\r
-static int me_count(const menu_entry *ent)\r
-{\r
-       int ret;\r
-\r
-       for (ret = 0; ent->name; ent++, ret++)\r
-               ;\r
-\r
-       return ret;\r
-}\r
-\r
-static unsigned int me_read_onoff(const menu_entry *ent)\r
-{\r
-       // guess var size based on mask to avoid reading too much\r
-       if (ent->mask & 0xffff0000)\r
-               return *(unsigned int *)ent->var & ent->mask;\r
-       else if (ent->mask & 0xff00)\r
-               return *(unsigned short *)ent->var & ent->mask;\r
-       else\r
-               return *(unsigned char *)ent->var & ent->mask;\r
-}\r
-\r
-static void me_toggle_onoff(menu_entry *ent)\r
-{\r
-       // guess var size based on mask to avoid reading too much\r
-       if (ent->mask & 0xffff0000)\r
-               *(unsigned int *)ent->var ^= ent->mask;\r
-       else if (ent->mask & 0xff00)\r
-               *(unsigned short *)ent->var ^= ent->mask;\r
-       else\r
-               *(unsigned char *)ent->var ^= ent->mask;\r
-}\r
-\r
-static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))\r
-{\r
-       const menu_entry *ent, *ent_sel = entries;\r
-       int x, y, w = 0, h = 0;\r
-       int offs, col2_offs = 27 * me_mfont_w;\r
-       int vi_sel_ln = 0;\r
-       const char *name;\r
-       int i, n;\r
-\r
-       /* calculate size of menu rect */\r
-       for (ent = entries, i = n = 0; ent->name; ent++, i++)\r
-       {\r
-               int wt;\r
-\r
-               if (!ent->enabled)\r
-                       continue;\r
-\r
-               if (i == sel) {\r
-                       ent_sel = ent;\r
-                       vi_sel_ln = n;\r
-               }\r
-\r
-               name = NULL;\r
-               wt = strlen(ent->name) * me_mfont_w;\r
-               if (wt == 0 && ent->generate_name)\r
-                       name = ent->generate_name(ent->id, &offs);\r
-               if (name != NULL)\r
-                       wt = strlen(name) * me_mfont_w;\r
-\r
-               if (ent->beh != MB_NONE)\r
-               {\r
-                       if (wt > col2_offs)\r
-                               col2_offs = wt + me_mfont_w;\r
-                       wt = col2_offs;\r
-\r
-                       switch (ent->beh) {\r
-                       case MB_NONE:\r
-                               break;\r
-                       case MB_OPT_ONOFF:\r
-                       case MB_OPT_RANGE:\r
-                               wt += me_mfont_w * 3;\r
-                               break;\r
-                       case MB_OPT_CUSTOM:\r
-                       case MB_OPT_CUSTONOFF:\r
-                       case MB_OPT_CUSTRANGE:\r
-                               name = NULL;\r
-                               offs = 0;\r
-                               if (ent->generate_name != NULL)\r
-                                       name = ent->generate_name(ent->id, &offs);\r
-                               if (name != NULL)\r
-                                       wt += (strlen(name) + offs) * me_mfont_w;\r
-                               break;\r
-                       case MB_OPT_ENUM:\r
-                               wt += 10 * me_mfont_w;\r
-                               break;\r
-                       }\r
-               }\r
-\r
-               if (wt > w)\r
-                       w = wt;\r
-               n++;\r
-       }\r
-       h = n * me_mfont_h;\r
-       w += me_mfont_w * 2; /* selector */\r
-\r
-       if (w > g_menuscreen_w) {\r
-               lprintf("width %d > %d\n", w, g_menuscreen_w);\r
-               w = g_menuscreen_w;\r
-       }\r
-       if (h > g_menuscreen_h) {\r
-               lprintf("height %d > %d\n", w, g_menuscreen_h);\r
-               h = g_menuscreen_h;\r
-       }\r
-\r
-       x = g_menuscreen_w / 2 - w / 2;\r
-       y = g_menuscreen_h / 2 - h / 2;\r
-#ifdef MENU_ALIGN_LEFT\r
-       if (x > 12) x = 12;\r
-#endif\r
-\r
-       /* draw */\r
-       menu_draw_begin(1);\r
-       menu_draw_selection(x, y + vi_sel_ln * me_mfont_h, w);\r
-       x += me_mfont_w * 2;\r
-\r
-       for (ent = entries; ent->name; ent++)\r
-       {\r
-               const char **names;\r
-               int len, leftname_end = 0;\r
-\r
-               if (!ent->enabled)\r
-                       continue;\r
-\r
-               name = ent->name;\r
-               if (strlen(name) == 0) {\r
-                       if (ent->generate_name)\r
-                               name = ent->generate_name(ent->id, &offs);\r
-               }\r
-               if (name != NULL) {\r
-                       text_out16(x, y, name);\r
-                       leftname_end = x + (strlen(name) + 1) * me_mfont_w;\r
-               }\r
-\r
-               switch (ent->beh) {\r
-               case MB_NONE:\r
-                       break;\r
-               case MB_OPT_ONOFF:\r
-                       text_out16(x + col2_offs, y, me_read_onoff(ent) ? "ON" : "OFF");\r
-                       break;\r
-               case MB_OPT_RANGE:\r
-                       text_out16(x + col2_offs, y, "%i", *(int *)ent->var);\r
-                       break;\r
-               case MB_OPT_CUSTOM:\r
-               case MB_OPT_CUSTONOFF:\r
-               case MB_OPT_CUSTRANGE:\r
-                       name = NULL;\r
-                       offs = 0;\r
-                       if (ent->generate_name)\r
-                               name = ent->generate_name(ent->id, &offs);\r
-                       if (name != NULL)\r
-                               text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", name);\r
-                       break;\r
-               case MB_OPT_ENUM:\r
-                       names = (const char **)ent->data;\r
-                       for (i = 0; names[i] != NULL; i++) {\r
-                               offs = x + col2_offs;\r
-                               len = strlen(names[i]);\r
-                               if (len > 10)\r
-                                       offs += (10 - len - 2) * me_mfont_w;\r
-                               if (offs < leftname_end)\r
-                                       offs = leftname_end;\r
-                               if (i == *(unsigned char *)ent->var) {\r
-                                       text_out16(offs, y, "%s", names[i]);\r
-                                       break;\r
-                               }\r
-                       }\r
-                       break;\r
-               }\r
-\r
-               y += me_mfont_h;\r
-       }\r
-\r
-       /* display help or message if we have one */\r
-       h = (g_menuscreen_h - h) / 2; // bottom area height\r
-       if (menu_error_msg[0] != 0) {\r
-               if (h >= me_mfont_h + 4)\r
-                       text_out16(5, g_menuscreen_h - me_mfont_h - 4, menu_error_msg);\r
-               else\r
-                       lprintf("menu msg doesn't fit!\n");\r
-\r
-               if (plat_get_ticks_ms() - menu_error_time > 2048)\r
-                       menu_error_msg[0] = 0;\r
-       }\r
-       else if (ent_sel->help != NULL) {\r
-               const char *tmp = ent_sel->help;\r
-               int l;\r
-               for (l = 0; tmp != NULL && *tmp != 0; l++)\r
-                       tmp = strchr(tmp + 1, '\n');\r
-               if (h >= l * me_sfont_h + 4)\r
-                       for (tmp = ent_sel->help; l > 0; l--, tmp = strchr(tmp, '\n') + 1)\r
-                               smalltext_out16(5, g_menuscreen_h - (l * me_sfont_h + 4), tmp, 0xffff);\r
-       }\r
-\r
-       if (draw_more != NULL)\r
-               draw_more();\r
-\r
-       menu_draw_end();\r
-}\r
-\r
-static int me_process(menu_entry *entry, int is_next, int is_lr)\r
-{\r
-       const char **names;\r
-       int c;\r
-       switch (entry->beh)\r
-       {\r
-               case MB_OPT_ONOFF:\r
-               case MB_OPT_CUSTONOFF:\r
-                       me_toggle_onoff(entry);\r
-                       return 1;\r
-               case MB_OPT_RANGE:\r
-               case MB_OPT_CUSTRANGE:\r
-                       c = is_lr ? 10 : 1;\r
-                       *(int *)entry->var += is_next ? c : -c;\r
-                       if (*(int *)entry->var < (int)entry->min)\r
-                               *(int *)entry->var = (int)entry->max;\r
-                       if (*(int *)entry->var > (int)entry->max)\r
-                               *(int *)entry->var = (int)entry->min;\r
-                       return 1;\r
-               case MB_OPT_ENUM:\r
-                       names = (const char **)entry->data;\r
-                       for (c = 0; names[c] != NULL; c++)\r
-                               ;\r
-                       *(signed char *)entry->var += is_next ? 1 : -1;\r
-                       if (*(signed char *)entry->var < 0)\r
-                               *(signed char *)entry->var = 0;\r
-                       if (*(signed char *)entry->var >= c)\r
-                               *(signed char *)entry->var = c - 1;\r
-                       return 1;\r
-               default:\r
-                       return 0;\r
-       }\r
-}\r
-\r
-static void debug_menu_loop(void);\r
-\r
-static int me_loop_d(menu_entry *menu, int *menu_sel, void (*draw_prep)(void), void (*draw_more)(void))\r
-{\r
-       int ret = 0, inp, sel = *menu_sel, menu_sel_max;\r
-\r
-       menu_sel_max = me_count(menu) - 1;\r
-       if (menu_sel_max < 0) {\r
-               lprintf("no enabled menu entries\n");\r
-               return 0;\r
-       }\r
-\r
-       while ((!menu[sel].enabled || !menu[sel].selectable) && sel < menu_sel_max)\r
-               sel++;\r
-\r
-       /* make sure action buttons are not pressed on entering menu */\r
-       me_draw(menu, sel, NULL);\r
-       while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
-\r
-       for (;;)\r
-       {\r
-               if (draw_prep != NULL)\r
-                       draw_prep();\r
-\r
-               me_draw(menu, sel, draw_more);\r
-               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
-                       PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, NULL, 70);\r
-               if (inp & (PBTN_MENU|PBTN_MBACK))\r
-                       break;\r
-\r
-               if (inp & PBTN_UP  ) {\r
-                       do {\r
-                               sel--;\r
-                               if (sel < 0)\r
-                                       sel = menu_sel_max;\r
-                       }\r
-                       while (!menu[sel].enabled || !menu[sel].selectable);\r
-               }\r
-               if (inp & PBTN_DOWN) {\r
-                       do {\r
-                               sel++;\r
-                               if (sel > menu_sel_max)\r
-                                       sel = 0;\r
-                       }\r
-                       while (!menu[sel].enabled || !menu[sel].selectable);\r
-               }\r
-\r
-               /* a bit hacky but oh well */\r
-               if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R))\r
-                       debug_menu_loop();\r
-\r
-               if (inp & (PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { /* multi choice */\r
-                       if (me_process(&menu[sel], (inp & (PBTN_RIGHT|PBTN_R)) ? 1 : 0,\r
-                                               inp & (PBTN_L|PBTN_R)))\r
-                               continue;\r
-               }\r
-\r
-               if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R))\r
-               {\r
-                       /* require PBTN_MOK for MB_NONE */\r
-                       if (menu[sel].handler != NULL && (menu[sel].beh != MB_NONE || (inp & PBTN_MOK))) {\r
-                               ret = menu[sel].handler(menu[sel].id, inp);\r
-                               if (ret) break;\r
-                               menu_sel_max = me_count(menu) - 1; /* might change, so update */\r
-                       }\r
-               }\r
-       }\r
-       *menu_sel = sel;\r
-\r
-       return ret;\r
-}\r
-\r
-static int me_loop(menu_entry *menu, int *menu_sel)\r
-{\r
-       return me_loop_d(menu, menu_sel, NULL, NULL);\r
-}\r
-\r
-/* ***************************************** */\r
-\r
-static void draw_menu_message(const char *msg, void (*draw_more)(void))\r
-{\r
-       int x, y, h, w, wt;\r
-       const char *p;\r
-\r
-       p = msg;\r
-       for (h = 1, w = 0; *p != 0; h++) {\r
-               for (wt = 0; *p != 0 && *p != '\n'; p++)\r
-                       wt++;\r
-\r
-               if (wt > w)\r
-                       w = wt;\r
-               if (*p == 0)\r
-                       break;\r
-               p++;\r
-       }\r
-\r
-       x = g_menuscreen_w / 2 - w * me_mfont_w / 2;\r
-       y = g_menuscreen_h / 2 - h * me_mfont_h / 2;\r
-       if (x < 0) x = 0;\r
-       if (y < 0) y = 0;\r
-\r
-       menu_draw_begin(1);\r
-\r
-       for (p = msg; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) {\r
-               text_out16(x, y, p);\r
-\r
-               for (; *p != 0 && *p != '\n'; p++)\r
-                       ;\r
-               if (*p != 0)\r
-                       p++;\r
-       }\r
-\r
-       if (draw_more != NULL)\r
-               draw_more();\r
-\r
-       menu_draw_end();\r
-}\r
-\r
-// -------------- del confirm ---------------\r
-\r
-static void do_delete(const char *fpath, const char *fname)\r
-{\r
-       int len, mid, inp;\r
-       const char *nm;\r
-       char tmp[64];\r
-\r
-       menu_draw_begin(1);\r
-\r
-       len = strlen(fname);\r
-       if (len > g_menuscreen_w / me_sfont_w)\r
-               len = g_menuscreen_w / me_sfont_w;\r
-\r
-       mid = g_menuscreen_w / 2;\r
-       text_out16(mid - me_mfont_w * 15 / 2,  8 * me_mfont_h, "About to delete");\r
-       smalltext_out16(mid - len * me_sfont_w / 2, 9 * me_mfont_h + 5, fname, 0xbdff);\r
-       text_out16(mid - me_mfont_w * 13 / 2, 11 * me_mfont_h, "Are you sure?");\r
-\r
-       nm = in_get_key_name(-1, -PBTN_MA3);\r
-       snprintf(tmp, sizeof(tmp), "(%s - confirm, ", nm);\r
-       len = strlen(tmp);\r
-       nm = in_get_key_name(-1, -PBTN_MBACK);\r
-       snprintf(tmp + len, sizeof(tmp) - len, "%s - cancel)", nm);\r
-       len = strlen(tmp);\r
-\r
-       text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp);\r
-       menu_draw_end();\r
-\r
-       while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MA2));\r
-       inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, NULL, 100);\r
-       if (inp & PBTN_MA3)\r
-               remove(fpath);\r
-}\r
-\r
-// -------------- ROM selector --------------\r
-\r
-static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
-{\r
-       int max_cnt, start, i, x, pos;\r
-       void *darken_ptr;\r
-\r
-       max_cnt = g_menuscreen_h / me_sfont_h;\r
-       start = max_cnt / 2 - sel;\r
-       n--; // exclude current dir (".")\r
-\r
-       menu_draw_begin(1);\r
-\r
-//     if (!rom_loaded)\r
-//             menu_darken_bg(gp2x_screen, 320*240, 0);\r
-\r
-       darken_ptr = (short *)g_menuscreen_ptr + g_menuscreen_w * max_cnt/2 * me_sfont_h;\r
-       menu_darken_bg(darken_ptr, darken_ptr, g_menuscreen_w * me_sfont_h * 8 / 10, 0);\r
-\r
-       x = 5 + me_mfont_w + 1;\r
-       if (start - 2 >= 0)\r
-               smalltext_out16(14, (start - 2) * me_sfont_h, curdir, 0xffff);\r
-       for (i = 0; i < n; i++) {\r
-               pos = start + i;\r
-               if (pos < 0)  continue;\r
-               if (pos >= max_cnt) break;\r
-               if (namelist[i+1]->d_type == DT_DIR) {\r
-                       smalltext_out16(x, pos * me_sfont_h, "/", 0xfff6);\r
-                       smalltext_out16(x + me_sfont_w, pos * me_sfont_h, namelist[i+1]->d_name, 0xfff6);\r
-               } else {\r
-                       unsigned short color = fname2color(namelist[i+1]->d_name);\r
-                       smalltext_out16(x, pos * me_sfont_h, namelist[i+1]->d_name, color);\r
-               }\r
-       }\r
-       smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", 0xffff);\r
-       menu_draw_end();\r
-}\r
-\r
-static int scandir_cmp(const void *p1, const void *p2)\r
-{\r
-       const struct dirent **d1 = (const struct dirent **)p1;\r
-       const struct dirent **d2 = (const struct dirent **)p2;\r
-       if ((*d1)->d_type == (*d2)->d_type)\r
-               return alphasort(d1, d2);\r
-       if ((*d1)->d_type == DT_DIR)\r
-               return -1; // put before\r
-       if ((*d2)->d_type == DT_DIR)\r
-               return  1;\r
-\r
-       return alphasort(d1, d2);\r
-}\r
-\r
-static int scandir_filter(const struct dirent *ent)\r
-{\r
-       const char *p;\r
-       int i;\r
-\r
-       if (ent == NULL || ent->d_name == NULL) return 0;\r
-       if (strlen(ent->d_name) < 5) return 1;\r
-\r
-       p = ent->d_name + strlen(ent->d_name) - 4;\r
-\r
-       for (i = 0; i < array_size(filter_exts); i++)\r
-               if (strcmp(p, filter_exts[i]) == 0)\r
-                       return 0;\r
-\r
-       return 1;\r
-}\r
-\r
-static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)\r
-{\r
-       int i;\r
-\r
-       sel++;\r
-       for (i = sel + 1; i != sel; i++) {\r
-               if (i >= len)\r
-                       i = 1;\r
-\r
-               if (tolower_simple(namelist[i]->d_name[0]) == c)\r
-                       break;\r
-       }\r
-\r
-       return i - 1;\r
-}\r
-\r
-static char *menu_loop_romsel(char *curr_path, int len)\r
-{\r
-       struct dirent **namelist;\r
-       int n, inp, sel = 0;\r
-       char *ret = NULL, *fname = NULL;\r
-       char cinp;\r
-\r
-rescan:\r
-       // is this a dir or a full path?\r
-       if (!plat_is_dir(curr_path)) {\r
-               char *p = curr_path + strlen(curr_path) - 1;\r
-               for (; p > curr_path && *p != '/'; p--)\r
-                       ;\r
-               *p = 0;\r
-               fname = p+1;\r
-       }\r
-\r
-       n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
-       if (n < 0) {\r
-               char *t;\r
-               lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
-\r
-               // try root\r
-               t = getcwd(curr_path, len);\r
-               if (t == NULL)\r
-                       plat_get_root_dir(curr_path, len);\r
-               n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
-               if (n < 0) {\r
-                       // oops, we failed\r
-                       lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
-                       return NULL;\r
-               }\r
-       }\r
-\r
-       // try to find sel\r
-       // note: we don't show '.' so sel is namelist index - 1\r
-       if (fname != NULL) {\r
-               int i;\r
-               for (i = 1; i < n; i++) {\r
-                       char *dname = namelist[i]->d_name;\r
-                       if (dname[0] == fname[0] && strcmp(dname, fname) == 0) {\r
-                               sel = i - 1;\r
-                               break;\r
-                       }\r
-               }\r
-       }\r
-\r
-       /* make sure action buttons are not pressed on entering menu */\r
-       draw_dirlist(curr_path, namelist, n, sel);\r
-       while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))\r
-               ;\r
-\r
-       for (;;)\r
-       {\r
-               draw_dirlist(curr_path, namelist, n, sel);\r
-               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
-                       PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_CHAR, &cinp, 33);\r
-               if (inp & PBTN_UP  )  { sel--;   if (sel < 0)   sel = n-2; }\r
-               if (inp & PBTN_DOWN)  { sel++;   if (sel > n-2) sel = 0; }\r
-               if (inp & PBTN_LEFT)  { sel-=10; if (sel < 0)   sel = 0; }\r
-               if (inp & PBTN_L)     { sel-=24; if (sel < 0)   sel = 0; }\r
-               if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
-               if (inp & PBTN_R)     { sel+=24; if (sel > n-2) sel = n-2; }\r
-               if (inp & PBTN_CHAR)  sel = dirent_seek_char(namelist, n, sel, cinp);\r
-               if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))\r
-               {\r
-                       again:\r
-                       if (namelist[sel+1]->d_type == DT_REG)\r
-                       {\r
-                               strcpy(rom_fname_reload, curr_path);\r
-                               strcat(rom_fname_reload, "/");\r
-                               strcat(rom_fname_reload, namelist[sel+1]->d_name);\r
-                               if (inp & PBTN_MOK) { // return sel\r
-                                       ret = rom_fname_reload;\r
-                                       break;\r
-                               }\r
-                               do_delete(rom_fname_reload, namelist[sel+1]->d_name);\r
-                               if (n > 0) {\r
-                                       while (n--) free(namelist[n]);\r
-                                       free(namelist);\r
-                               }\r
-                               goto rescan;\r
-                       }\r
-                       else if (namelist[sel+1]->d_type == DT_DIR)\r
-                       {\r
-                               int newlen;\r
-                               char *p, *newdir;\r
-                               if (!(inp & PBTN_MOK))\r
-                                       continue;\r
-                               newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
-                               newdir = malloc(newlen);\r
-                               if (newdir == NULL)\r
-                                       break;\r
-                               if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
-                                       char *start = curr_path;\r
-                                       p = start + strlen(start) - 1;\r
-                                       while (*p == '/' && p > start) p--;\r
-                                       while (*p != '/' && p > start) p--;\r
-                                       if (p <= start) strcpy(newdir, "/");\r
-                                       else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r
-                               } else {\r
-                                       strcpy(newdir, curr_path);\r
-                                       p = newdir + strlen(newdir) - 1;\r
-                                       while (*p == '/' && p >= newdir) *p-- = 0;\r
-                                       strcat(newdir, "/");\r
-                                       strcat(newdir, namelist[sel+1]->d_name);\r
-                               }\r
-                               ret = menu_loop_romsel(newdir, newlen);\r
-                               free(newdir);\r
-                               break;\r
-                       }\r
-                       else\r
-                       {\r
-                               // unknown file type, happens on NTFS mounts. Try to guess.\r
-                               FILE *tstf; int tmp;\r
-                               strcpy(rom_fname_reload, curr_path);\r
-                               strcat(rom_fname_reload, "/");\r
-                               strcat(rom_fname_reload, namelist[sel+1]->d_name);\r
-                               tstf = fopen(rom_fname_reload, "rb");\r
-                               if (tstf != NULL)\r
-                               {\r
-                                       if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r
-                                               namelist[sel+1]->d_type = DT_REG;\r
-                                       else    namelist[sel+1]->d_type = DT_DIR;\r
-                                       fclose(tstf);\r
-                                       goto again;\r
-                               }\r
-                       }\r
-               }\r
-               if (inp & PBTN_MBACK)\r
-                       break;\r
-       }\r
-\r
-       if (n > 0) {\r
-               while (n--) free(namelist[n]);\r
-               free(namelist);\r
-       }\r
-\r
-       // restore curr_path\r
-       if (fname != NULL) {\r
-               n = strlen(curr_path);\r
-               if (curr_path + n + 1 == fname)\r
-                       curr_path[n] = '/';\r
-       }\r
-\r
-       return ret;\r
-}\r
-\r
-// ------------ savestate loader ------------\r
-\r
-#define STATE_SLOT_COUNT 10\r
-\r
-static int state_slot_flags = 0;\r
-static int state_slot_times[STATE_SLOT_COUNT];\r
-\r
-static void state_check_slots(void)\r
-{\r
-       int slot;\r
-\r
-       state_slot_flags = 0;\r
-\r
-       for (slot = 0; slot < STATE_SLOT_COUNT; slot++) {\r
-               state_slot_times[slot] = 0;\r
-               if (emu_check_save_file(slot, &state_slot_times[slot]))\r
-                       state_slot_flags |= 1 << slot;\r
-       }\r
-}\r
-\r
-static void draw_savestate_bg(int slot);\r
-\r
-static void draw_savestate_menu(int menu_sel, int is_loading)\r
-{\r
-       int i, x, y, w, h;\r
-       char time_buf[32];\r
-\r
-       if (state_slot_flags & (1 << menu_sel))\r
-               draw_savestate_bg(menu_sel);\r
-\r
-       w = (13 + 2) * me_mfont_w;\r
-       h = (1+2+STATE_SLOT_COUNT+1) * me_mfont_h;\r
-       x = g_menuscreen_w / 2 - w / 2;\r
-       if (x < 0) x = 0;\r
-       y = g_menuscreen_h / 2 - h / 2;\r
-       if (y < 0) y = 0;\r
-#ifdef MENU_ALIGN_LEFT\r
-       if (x > 12 + me_mfont_w * 2)\r
-               x = 12 + me_mfont_w * 2;\r
-#endif\r
-\r
-       menu_draw_begin(1);\r
-\r
-       text_out16(x, y, is_loading ? "Load state" : "Save state");\r
-       y += 3 * me_mfont_h;\r
-\r
-       menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (23 + 2) * me_mfont_w + 4);\r
-\r
-       /* draw all slots */\r
-       for (i = 0; i < STATE_SLOT_COUNT; i++, y += me_mfont_h)\r
-       {\r
-               if (!(state_slot_flags & (1 << i)))\r
-                       strcpy(time_buf, "free");\r
-               else {\r
-                       strcpy(time_buf, "USED");\r
-                       if (state_slot_times[i] != 0) {\r
-                               time_t time = state_slot_times[i];\r
-                               struct tm *t = localtime(&time);\r
-                               strftime(time_buf, sizeof(time_buf), "%x %R", t);\r
-                       }\r
-               }\r
-\r
-               text_out16(x, y, "SLOT %i (%s)", i, time_buf);\r
-       }\r
-       text_out16(x, y, "back");\r
-\r
-       menu_draw_end();\r
-}\r
-\r
-static int menu_loop_savestate(int is_loading)\r
-{\r
-       static int menu_sel = STATE_SLOT_COUNT;\r
-       int menu_sel_max = STATE_SLOT_COUNT;\r
-       unsigned long inp = 0;\r
-       int ret = 0;\r
-\r
-       state_check_slots();\r
-\r
-       if (!(state_slot_flags & (1 << menu_sel)) && is_loading)\r
-               menu_sel = menu_sel_max;\r
-\r
-       for (;;)\r
-       {\r
-               draw_savestate_menu(menu_sel, is_loading);\r
-               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, NULL, 100);\r
-               if (inp & PBTN_UP) {\r
-                       do {\r
-                               menu_sel--;\r
-                               if (menu_sel < 0)\r
-                                       menu_sel = menu_sel_max;\r
-                       } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
-               }\r
-               if (inp & PBTN_DOWN) {\r
-                       do {\r
-                               menu_sel++;\r
-                               if (menu_sel > menu_sel_max)\r
-                                       menu_sel = 0;\r
-                       } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
-               }\r
-               if (inp & PBTN_MOK) { // save/load\r
-                       if (menu_sel < STATE_SLOT_COUNT) {\r
-                               state_slot = menu_sel;\r
-                               if (emu_save_load_game(is_loading, 0)) {\r
-                                       me_update_msg(is_loading ? "Load failed" : "Save failed");\r
-                                       break;\r
-                               }\r
-                               ret = 1;\r
-                               break;\r
-                       }\r
-                       break;\r
-               }\r
-               if (inp & PBTN_MBACK)\r
-                       break;\r
-       }\r
-\r
-       return ret;\r
-}\r
-\r
-// -------------- key config --------------\r
-\r
-static char *action_binds(int player_idx, int action_mask, int dev_id)\r
-{\r
-       int dev = 0, dev_last = IN_MAX_DEVS - 1;\r
-       int can_combo = 1, type;\r
-\r
-       static_buff[0] = 0;\r
-\r
-       type = IN_BINDTYPE_EMU;\r
-       if (player_idx >= 0) {\r
-               can_combo = 0;\r
-               type = IN_BINDTYPE_PLAYER12;\r
-       }\r
-       if (player_idx == 1)\r
-               action_mask <<= 16;\r
-\r
-       if (dev_id >= 0)\r
-               dev = dev_last = dev_id;\r
-\r
-       for (; dev <= dev_last; dev++) {\r
-               int k, count = 0, combo = 0;\r
-               const int *binds;\r
-\r
-               binds = in_get_dev_binds(dev);\r
-               if (binds == NULL)\r
-                       continue;\r
-\r
-               in_get_config(dev, IN_CFG_BIND_COUNT, &count);\r
-               in_get_config(dev, IN_CFG_DOES_COMBOS, &combo);\r
-               combo = combo && can_combo;\r
-\r
-               for (k = 0; k < count; k++) {\r
-                       const char *xname;\r
-                       int len;\r
-\r
-                       if (!(binds[IN_BIND_OFFS(k, type)] & action_mask))\r
-                               continue;\r
-\r
-                       xname = in_get_key_name(dev, k);\r
-                       len = strlen(static_buff);\r
-                       if (len) {\r
-                               strncat(static_buff, combo ? " + " : ", ",\r
-                                       sizeof(static_buff) - len - 1);\r
-                               len += combo ? 3 : 2;\r
-                       }\r
-                       strncat(static_buff, xname, sizeof(static_buff) - len - 1);\r
-               }\r
-       }\r
-\r
-       return static_buff;\r
-}\r
-\r
-static int count_bound_keys(int dev_id, int action_mask, int bindtype)\r
-{\r
-       const int *binds;\r
-       int k, keys = 0;\r
-       int count = 0;\r
-\r
-       binds = in_get_dev_binds(dev_id);\r
-       if (binds == NULL)\r
-               return 0;\r
-\r
-       in_get_config(dev_id, IN_CFG_BIND_COUNT, &count);\r
-       for (k = 0; k < count; k++)\r
-       {\r
-               if (binds[IN_BIND_OFFS(k, bindtype)] & action_mask)\r
-                       keys++;\r
-       }\r
-\r
-       return keys;\r
-}\r
-\r
-static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,\r
-               int sel, int dev_id, int dev_count, int is_bind)\r
-{\r
-       char buff[64], buff2[32];\r
-       const char *dev_name;\r
-       int x, y, w, i;\r
-\r
-       w = ((player_idx >= 0) ? 20 : 30) * me_mfont_w;\r
-       x = g_menuscreen_w / 2 - w / 2;\r
-       y = (g_menuscreen_h - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2;\r
-       if (x < me_mfont_w * 2)\r
-               x = me_mfont_w * 2;\r
-\r
-       menu_draw_begin(1);\r
-       if (player_idx >= 0)\r
-               text_out16(x, y, "Player %i controls", player_idx + 1);\r
-       else\r
-               text_out16(x, y, "Emulator controls");\r
-\r
-       y += 2 * me_mfont_h;\r
-       menu_draw_selection(x - me_mfont_w * 2, y + sel * me_mfont_h, w + 2 * me_mfont_w);\r
-\r
-       for (i = 0; i < opt_cnt; i++, y += me_mfont_h)\r
-               text_out16(x, y, "%s : %s", opts[i].name,\r
-                       action_binds(player_idx, opts[i].mask, dev_id));\r
-\r
-       if (dev_id < 0)\r
-               dev_name = "(all devices)";\r
-       else\r
-               dev_name = in_get_dev_name(dev_id, 1, 1);\r
-       w = strlen(dev_name) * me_mfont_w;\r
-       if (w < 30 * me_mfont_w)\r
-               w = 30 * me_mfont_w;\r
-       if (w > g_menuscreen_w)\r
-               w = g_menuscreen_w;\r
-\r
-       x = g_menuscreen_w / 2 - w / 2;\r
-\r
-       if (!is_bind) {\r
-               snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK));\r
-               snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2,\r
-                               in_get_key_name(-1, -PBTN_MA2));\r
-               text_out16(x, g_menuscreen_h - 4 * me_mfont_h, buff);\r
-       }\r
-       else\r
-               text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "Press a button to bind/unbind");\r
-\r
-       if (dev_count > 1) {\r
-               text_out16(x, g_menuscreen_h - 3 * me_mfont_h, dev_name);\r
-               text_out16(x, g_menuscreen_h - 2 * me_mfont_h, "Press left/right for other devs");\r
-       }\r
-\r
-       menu_draw_end();\r
-}\r
-\r
-static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
-{\r
-       int i, sel = 0, menu_sel_max = opt_cnt - 1, does_combos = 0;\r
-       int dev_id, bind_dev_id, dev_count, kc, is_down, mkey;\r
-       int unbind, bindtype, mask_shift;\r
-\r
-       for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {\r
-               if (in_get_dev_name(i, 1, 0) != NULL) {\r
-                       dev_count++;\r
-                       if (dev_id < 0)\r
-                               dev_id = i;\r
-               }\r
-       }\r
-\r
-       if (dev_id == -1) {\r
-               lprintf("no devs, can't do config\n");\r
-               return;\r
-       }\r
-\r
-       dev_id = -1; // show all\r
-       mask_shift = 0;\r
-       if (player_idx == 1)\r
-               mask_shift = 16;\r
-       bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU;\r
-\r
-       for (;;)\r
-       {\r
-               draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);\r
-               mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT\r
-                               |PBTN_MBACK|PBTN_MOK|PBTN_MA2, NULL, 100);\r
-               switch (mkey) {\r
-                       case PBTN_UP:   sel--; if (sel < 0) sel = menu_sel_max; continue;\r
-                       case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
-                       case PBTN_LEFT:\r
-                               for (i = 0, dev_id--; i < IN_MAX_DEVS + 1; i++, dev_id--) {\r
-                                       if (dev_id < -1)\r
-                                               dev_id = IN_MAX_DEVS - 1;\r
-                                       if (dev_id == -1 || in_get_dev_name(dev_id, 1, 0) != NULL)\r
-                                               break;\r
-                               }\r
-                               continue;\r
-                       case PBTN_RIGHT:\r
-                               for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) {\r
-                                       if (dev_id >= IN_MAX_DEVS)\r
-                                               dev_id = -1;\r
-                                       if (dev_id == -1 || in_get_dev_name(dev_id, 1, 0) != NULL)\r
-                                               break;\r
-                               }\r
-                               continue;\r
-                       case PBTN_MBACK:\r
-                               return;\r
-                       case PBTN_MOK:\r
-                               if (sel >= opt_cnt)\r
-                                       return;\r
-                               while (in_menu_wait_any(NULL, 30) & PBTN_MOK)\r
-                                       ;\r
-                               break;\r
-                       case PBTN_MA2:\r
-                               in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype);\r
-                               continue;\r
-                       default:continue;\r
-               }\r
-\r
-               draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 1);\r
-\r
-               /* wait for some up event */\r
-               for (is_down = 1; is_down; )\r
-                       kc = in_update_keycode(&bind_dev_id, &is_down, NULL, -1);\r
-\r
-               i = count_bound_keys(bind_dev_id, opts[sel].mask << mask_shift, bindtype);\r
-               unbind = (i > 0);\r
-\r
-               /* allow combos if device supports them */\r
-               in_get_config(bind_dev_id, IN_CFG_DOES_COMBOS, &does_combos);\r
-               if (i == 1 && bindtype == IN_BINDTYPE_EMU && does_combos)\r
-                       unbind = 0;\r
-\r
-               if (unbind)\r
-                       in_unbind_all(bind_dev_id, opts[sel].mask << mask_shift, bindtype);\r
-\r
-               in_bind_key(bind_dev_id, kc, opts[sel].mask << mask_shift, bindtype, 0);\r
-       }\r
-}\r
-\r
diff --git a/platform/common/menu.h b/platform/common/menu.h
deleted file mode 100644 (file)
index 79b8278..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2006-2010
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-typedef enum
-{
-       MB_NONE = 1,            /* no auto processing */
-       MB_OPT_ONOFF,           /* ON/OFF setting */
-       MB_OPT_RANGE,           /* [min-max] setting */
-       MB_OPT_CUSTOM,          /* custom value */
-       MB_OPT_CUSTONOFF,
-       MB_OPT_CUSTRANGE,
-       MB_OPT_ENUM,
-} menu_behavior;
-
-typedef struct
-{
-       const char *name;
-       menu_behavior beh;
-       int id;
-       void *var;              /* for on-off/range settings */
-       int mask;               /* bit to toggle for on/off */
-       signed short min;       /* for ranged integer settings, to be sign-extended */
-       signed short max;
-       unsigned int enabled:1;
-       unsigned int need_to_save:1;
-       unsigned int selectable:1;
-       int (*handler)(int id, int keys);
-       const char * (*generate_name)(int id, int *offs);
-       const void *data;
-       const char *help;
-} menu_entry;
-
-#define mee_handler_id_h(name, id, handler, help) \
-       { name, MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, NULL, NULL, help }
-
-#define mee_handler_id(name, id, handler) \
-       mee_handler_id_h(name, id, handler, NULL)
-
-#define mee_handler(name, handler) \
-       mee_handler_id(name, MA_NONE, handler)
-
-#define mee_handler_h(name, handler, help) \
-       mee_handler_id_h(name, MA_NONE, handler, help)
-
-#define mee_label(name) \
-       { name, MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0, 0, NULL, NULL, NULL, NULL }
-
-#define mee_label_mk(id, name_func) \
-       { "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 0, NULL, name_func, NULL, NULL }
-
-#define mee_onoff_h(name, id, var, mask, help) \
-       { name, MB_OPT_ONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, NULL, NULL, help }
-
-#define mee_onoff(name, id, var, mask) \
-       mee_onoff_h(name, id, var, mask, NULL)
-
-#define mee_range_h(name, id, var, min, max, help) \
-       { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL, NULL, help }
-
-#define mee_range(name, id, var, min, max) \
-       mee_range_h(name, id, var, min, max, NULL)
-
-#define mee_range_hide(name, id, var, min, max) \
-       { name, MB_OPT_RANGE, id, &(var), 0, min, max, 0, 1, 0, NULL, NULL, NULL, NULL }
-
-#define mee_cust_s_h(name, id, need_save, handler, name_func, help) \
-       { name, MB_OPT_CUSTOM, id, NULL, 0, 0, 0, 1, need_save, 1, handler, name_func, NULL, help }
-
-#define mee_cust_h(name, id, handler, name_func, help) \
-       mee_cust_s_h(name, id, 1, handler, name_func, help)
-
-#define mee_cust(name, id, handler, name_func) \
-       mee_cust_h(name, id, handler, name_func, NULL)
-
-#define mee_cust_nosave(name, id, handler, name_func) \
-       mee_cust_s_h(name, id, 0, handler, name_func, NULL)
-
-#define mee_onoff_cust(name, id, var, mask, name_func) \
-       { name, MB_OPT_CUSTONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, name_func, NULL, NULL }
-
-#define mee_range_cust(name, id, var, min, max, name_func) \
-       { name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func, NULL, NULL }
-
-#define mee_enum_h(name, id, var, names_list, help) \
-       { name, MB_OPT_ENUM, id, &(var), 0, 0, 0, 1, 1, 1, NULL, NULL, names_list, help }
-
-#define mee_enum(name, id, var, names_list) \
-       mee_enum_h(name, id, var, names_list, NULL)
-
-#define mee_end \
-       { NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
-
-typedef struct
-{
-       char *name;
-       int mask;
-} me_bind_action;
-
-extern me_bind_action me_ctrl_actions[];
-extern me_bind_action emuctrl_actions[];       // platform code
-
-extern void *g_menubg_src_ptr;
-extern void *g_menubg_ptr;
-extern void *g_menuscreen_ptr;
-#if MSCREEN_SIZE_FIXED
-#define g_menuscreen_w MSCREEN_WIDTH
-#define g_menuscreen_h MSCREEN_HEIGHT
-#else
-extern int g_menuscreen_w;
-extern int g_menuscreen_h;
-#endif
-
-void menu_init(void);
-void text_out16(int x, int y, const char *texto, ...);
-void me_update_msg(const char *msg);
-
-void menu_romload_prepare(const char *rom_name);
-void menu_romload_end(void);
-
-void menu_loop(void);
-int  menu_loop_tray(void);
-
-menu_entry *me_list_get_first(void);
-menu_entry *me_list_get_next(void);
-
index f6e9b26..da1a6be 100644 (file)
@@ -2,35 +2,37 @@
 
 #include "emu.h"
 #include "menu_pico.h"
+#include "input_pico.h"
 
 #include <version.h>
-#include <revision.h>
 
 #include <pico/pico.h>
 #include <pico/patch.h>
 
+// FIXME
+#define REVISION "0"
+
+static const char *rom_exts[] = {
+       "zip", "bin", "smd", "gen",
+       "iso", "cso", "cue", NULL
+};
+
 // rrrr rggg gggb bbbb
 static unsigned short fname2color(const char *fname)
 {
        const char *ext = fname + strlen(fname) - 3;
-       static const char *rom_exts[]   = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" };
        static const char *other_exts[] = { "gmv", "pat" };
        int i;
 
        if (ext < fname) ext = fname;
-       for (i = 0; i < array_size(rom_exts); i++)
+       for (i = 0; rom_exts[i] != NULL; i++)
                if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
        for (i = 0; i < array_size(other_exts); i++)
                if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
        return 0xffff;
 }
 
-static const char *filter_exts[] = {
-       ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
-       ".jpg", ".gpe"
-};
-
-#include "menu.c"
+#include "../libpicofe/menu.c"
 
 /* platform specific options and handlers */
 #if   defined(__GP2X__)
@@ -96,7 +98,7 @@ static void load_progress_cb(int percent)
        if (len > g_menuscreen_w)
                len = g_menuscreen_w;
 
-       menu_draw_begin(0);
+       menu_draw_begin(0, 1);
        dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
        for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
                memset(dst, 0xff, len * 2);
@@ -108,7 +110,7 @@ static void cdload_progress_cb(const char *fname, int percent)
        int ln, len = percent * g_menuscreen_w / 100;
        unsigned short *dst;
 
-       menu_draw_begin(0);
+       menu_draw_begin(0, 1);
        dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
        memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
 
@@ -136,7 +138,7 @@ void menu_romload_prepare(const char *rom_name)
 
        /* fill all buffers, callbacks won't update in full */
        for (i = 0; i < 3; i++) {
-               menu_draw_begin(1);
+               menu_draw_begin(1, 1);
                smalltext_out16(1, 1, "Loading", 0xffff);
                smalltext_out16(1, me_sfont_h, p, 0xffff);
                menu_draw_end();
@@ -152,7 +154,7 @@ void menu_romload_end(void)
        PicoCartLoadProgressCB = NULL;
        PicoCDLoadProgressCB = NULL;
 
-       menu_draw_begin(0);
+       menu_draw_begin(0, 1);
        smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
                "Starting emulation...", 0xffff);
        menu_draw_end();
@@ -167,7 +169,7 @@ static void draw_patchlist(int sel)
        max_cnt = g_menuscreen_h / me_sfont_h;
        start = max_cnt / 2 - sel;
 
-       menu_draw_begin(1);
+       menu_draw_begin(1, 0);
 
        for (i = 0; i < PicoPatchCount; i++) {
                pos = start + i;
@@ -565,15 +567,15 @@ static int mh_saveloadcfg(int id, int keys)
        case MA_OPT_SAVECFG:
        case MA_OPT_SAVECFG_GAME:
                if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
-                       me_update_msg("config saved");
+                       menu_update_msg("config saved");
                else
-                       me_update_msg("failed to write config");
+                       menu_update_msg("failed to write config");
                break;
        case MA_OPT_LOADCFG:
                ret = emu_read_config(rom_fname_loaded, 1);
                if (!ret) ret = emu_read_config(NULL, 1);
-               if (ret)  me_update_msg("config loaded");
-               else      me_update_msg("failed to load config");
+               if (ret)  menu_update_msg("config loaded");
+               else      menu_update_msg("failed to load config");
                break;
        default:
                return 0;
@@ -585,7 +587,7 @@ static int mh_saveloadcfg(int id, int keys)
 static int mh_restore_defaults(int id, int keys)
 {
        emu_set_defconfig();
-       me_update_msg("defaults restored");
+       menu_update_msg("defaults restored");
        return 1;
 }
 
@@ -759,7 +761,7 @@ static void debug_menu_loop(void)
 
        while (1)
        {
-               menu_draw_begin(1);
+               menu_draw_begin(1, 0);
                switch (mode)
                {
                        case 0: tmp = PDebugMain();
@@ -857,23 +859,24 @@ static const char credits[] =
        " Lordus, Exophase, Rokas,\n"
        " Nemesis, Tasco Deluxe";
 
-static char *romsel_run(void)
+static const char *romsel_run(void)
 {
-       char *ret, *sel_name;
+       const char *ret;
+       char *sel_name;
 
        sel_name = malloc(sizeof(rom_fname_loaded));
        if (sel_name == NULL)
                return NULL;
        strcpy(sel_name, rom_fname_loaded);
 
-       ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));
+       ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded), rom_exts, NULL);
        free(sel_name);
        return ret;
 }
 
 static int main_menu_handler(int id, int keys)
 {
-       char *ret_name;
+       const char *ret_name;
 
        switch (id)
        {
@@ -914,7 +917,7 @@ static int main_menu_handler(int id, int keys)
                if (rom_loaded && PicoPatches) {
                        menu_loop_patches();
                        PicoPatchApply();
-                       me_update_msg("Patches applied");
+                       menu_update_msg("Patches applied");
                }
                break;
        default:
@@ -973,7 +976,7 @@ void menu_loop(void)
 
 static int mh_tray_load_cd(int id, int keys)
 {
-       char *ret_name;
+       const char *ret_name;
 
        ret_name = romsel_run();
        if (ret_name == NULL)
@@ -1018,7 +1021,7 @@ int menu_loop_tray(void)
        return ret;
 }
 
-void me_update_msg(const char *msg)
+void menu_update_msg(const char *msg)
 {
        strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
        menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
@@ -1078,3 +1081,7 @@ menu_entry *me_list_get_next(void)
        return me_list_i;
 }
 
+void menu_init(void)
+{
+       menu_init_base();
+}
index a8aeb64..31cee72 100644 (file)
@@ -1,3 +1,8 @@
+#ifndef __MENU_PICO_H__
+#define __MENU_PICO_H__
+
+#include "../libpicofe/menu.h"
+
 typedef enum
 {
        MA_NONE = 1,
@@ -92,3 +97,10 @@ typedef enum
        MA_CTRL_DONE,
 } menu_id;
 
+void menu_init(void);
+void menu_loop(void);
+int menu_loop_tray(void);
+void menu_romload_prepare(const char *rom_name);
+void menu_romload_end(void);
+
+#endif // __MENU_PICO_H__
diff --git a/platform/common/plat.h b/platform/common/plat.h
deleted file mode 100644 (file)
index 1fb8767..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* stuff to be implemented by platform code */
-extern const char *renderer_names[];
-extern const char *renderer_names32x[];
-
-void pemu_prep_defconfig(void);
-void pemu_validate_config(void);
-void pemu_loop_prep(void);
-void pemu_loop_end(void);
-void pemu_forced_frame(int no_scale, int do_emu); // ..to g_menubg_src_ptr
-void pemu_finalize_frame(const char *fps, const char *notice_msg);
-
-void pemu_sound_start(void);
-void pemu_sound_stop(void);
-void pemu_sound_wait(void);
-
-void plat_early_init(void);
-void plat_init(void);
-void plat_finish(void);
-
-/* return the dir/ where configs, saves, bios, etc. are found */
-int  plat_get_root_dir(char *dst, int len);
-
-/* used before things blocking for a while (these funcs redraw on return) */
-void plat_status_msg_busy_first(const char *msg);
-void plat_status_msg_busy_next(const char *msg);
-void plat_status_msg_clear(void);
-
-/* menu: enter (switch bpp, etc), begin/end drawing */
-void plat_video_menu_enter(int is_rom_loaded);
-void plat_video_menu_begin(void);
-void plat_video_menu_end(void);
-void plat_video_menu_leave(void);
-
-void plat_video_flip(void);
-void plat_video_wait_vsync(void);
-void plat_video_toggle_renderer(int change, int menu_call);
-
-void plat_update_volume(int has_changed, int is_up);
-
-int  plat_is_dir(const char *path);
-int  plat_wait_event(int *fds_hnds, int count, int timeout_ms);
-void plat_sleep_ms(int ms);
-
-void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);
-void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);
-void  plat_munmap(void *ptr, size_t size);
-
-/* timers, to be used for time diff and must refer to the same clock */
-unsigned int plat_get_ticks_ms(void);
-unsigned int plat_get_ticks_us(void);
-void plat_wait_till_us(unsigned int us);
-
-void plat_debug_cat(char *str);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
diff --git a/platform/common/posix.h b/platform/common/posix.h
deleted file mode 100644 (file)
index 33ca96c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* define POSIX stuff: dirent, scandir, getcwd, mkdir */
-#if defined(__linux__) || defined(__MINGW32__)
-
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#ifdef __MINGW32__
-#warning hacks!
-#define mkdir(pathname,mode) mkdir(pathname)
-#define d_type d_ino
-#define DT_REG 0
-#define DT_DIR 0
-#endif
-
-#else
-
-#error "must provide posix"
-
-#endif
-
-
diff --git a/platform/common/readpng.c b/platform/common/readpng.c
deleted file mode 100644 (file)
index cad1217..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2008-2011
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <png.h>
-#include "readpng.h"
-#include "lprintf.h"
-
-int readpng(void *dest, const char *fname, readpng_what what, int req_w, int req_h)
-{
-       FILE *fp;
-       png_structp png_ptr = NULL;
-       png_infop info_ptr = NULL;
-       png_bytepp row_ptr = NULL;
-       int ret = -1;
-
-       if (dest == NULL || fname == NULL)
-       {
-               return -1;
-       }
-
-       fp = fopen(fname, "rb");
-       if (fp == NULL)
-       {
-               lprintf(__FILE__ ": failed to open: %s\n", fname);
-               return -1;
-       }
-
-       png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-       if (!png_ptr)
-       {
-               lprintf(__FILE__ ": png_create_read_struct() failed\n");
-               fclose(fp);
-               return -1;
-       }
-
-       info_ptr = png_create_info_struct(png_ptr);
-       if (!info_ptr)
-       {
-               lprintf(__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)
-       {
-               lprintf(__FILE__ ": png_get_rows() failed\n");
-               goto done;
-       }
-
-       // lprintf("%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)
-                       {
-                               lprintf(__FILE__ ": bg image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth);
-                               break;
-                       }
-                       height = info_ptr->height;
-                       if (height > req_h)
-                               height = req_h;
-                       width = info_ptr->width;
-                       if (width > req_w)
-                               width = req_w;
-
-                       for (h = 0; h < height; h++)
-                       {
-                               unsigned char *src = row_ptr[h];
-                               int len = width;
-                               while (len--)
-                               {
-#ifdef PSP
-                                       *dst++ = ((src[2]&0xf8)<<8) | ((src[1]&0xf8)<<3) | (src[0] >> 3); // BGR
-#else
-                                       *dst++ = ((src[0]&0xf8)<<8) | ((src[1]&0xf8)<<3) | (src[2] >> 3); // RGB
-#endif
-                                       src += 3;
-                               }
-                               dst += req_w - width;
-                       }
-                       break;
-               }
-
-               case READPNG_FONT:
-               {
-                       int x, y, x1, y1;
-                       unsigned char *dst = dest;
-                       if (info_ptr->width != req_w || info_ptr->height != req_h)
-                       {
-                               lprintf(__FILE__ ": unexpected font image size %dx%d, needed %dx%d\n",
-                                       (int)info_ptr->width, (int)info_ptr->height, req_w, req_h);
-                               break;
-                       }
-                       if (info_ptr->pixel_depth != 8)
-                       {
-                               lprintf(__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++)
-                               {
-                                       /* 16x16 grid of syms */
-                                       int sym_w = req_w / 16;
-                                       int sym_h = req_h / 16;
-                                       for (y1 = 0; y1 < sym_h; y1++)
-                                       {
-                                               unsigned char *src = row_ptr[y*sym_h + y1] + x*sym_w;
-                                               for (x1 = sym_w/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 != req_w || info_ptr->height != req_h)
-                       {
-                               lprintf(__FILE__ ": unexpected selector image size %ix%i, needed %dx%d\n",
-                                       (int)info_ptr->width, (int)info_ptr->height, req_w, req_h);
-                               break;
-                       }
-                       if (info_ptr->pixel_depth != 8)
-                       {
-                               lprintf(__FILE__ ": selector image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth);
-                               break;
-                       }
-                       for (y1 = 0; y1 < req_h; y1++)
-                       {
-                               unsigned char *src = row_ptr[y1];
-                               for (x1 = req_w/2; x1 > 0; x1--, src+=2)
-                                       *dst++ = ((src[0]^0xff) & 0xf0) | ((src[1]^0xff) >> 4);
-                       }
-                       break;
-               }
-
-               case READPNG_24:
-               {
-                       int height, width, h;
-                       unsigned char *dst = dest;
-                       if (info_ptr->pixel_depth != 24)
-                       {
-                               lprintf(__FILE__ ": image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth);
-                               break;
-                       }
-                       height = info_ptr->height;
-                       if (height > req_h)
-                               height = req_h;
-                       width = info_ptr->width;
-                       if (width > req_w)
-                               width = req_w;
-
-                       for (h = 0; h < height; h++)
-                       {
-                               int len = width;
-                               unsigned char *src = row_ptr[h];
-                               dst += (req_w - width) * 3;
-                               for (len = width; len > 0; len--, dst+=3, src+=3)
-                                       dst[0] = src[2], dst[1] = src[1], dst[2] = src[0];
-                       }
-                       break;
-               }
-       }
-
-
-       ret = 0;
-done:
-       png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : NULL, (png_infopp)NULL);
-       fclose(fp);
-       return ret;
-}
-
-int writepng(const char *fname, unsigned short *src, int w, int h)
-{
-       png_structp png_ptr = NULL;
-       png_infop info_ptr = NULL;
-       png_bytepp row_pointers;
-       int i, j, ret = -1;
-       FILE *f;
-
-       f = fopen(fname, "wb");
-       if (f == NULL) {
-               lprintf(__FILE__ ": failed to open \"%s\"\n", fname);
-               return -1;
-       }
-
-       row_pointers = calloc(h, sizeof(row_pointers[0]));
-       if (row_pointers == NULL)
-               goto end1;
-
-       for (i = 0; i < h; i++) {
-               unsigned char *dst = malloc(w * 3);
-               if (dst == NULL)
-                       goto end2;
-               row_pointers[i] = dst;
-               for (j = 0; j < w; j++, src++, dst += 3) {
-                       dst[0] = (*src & 0xf800) >> 8;
-                       dst[1] = (*src & 0x07e0) >> 3;
-                       dst[2] = (*src & 0x001f) << 3;
-               }
-       }
-
-       /* initialize stuff */
-       png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-       if (png_ptr == NULL) {
-               fprintf(stderr, "png_create_write_struct() failed");
-               goto end2;
-       }
-
-       info_ptr = png_create_info_struct(png_ptr);
-       if (info_ptr == NULL) {
-               fprintf(stderr, "png_create_info_struct() failed");
-               goto end3;
-       }
-
-       if (setjmp(png_jmpbuf(png_ptr)) != 0) {
-               fprintf(stderr, "error in png code\n");
-               goto end4;
-       }
-
-       png_init_io(png_ptr, f);
-
-       png_set_IHDR(png_ptr, info_ptr, w, h,
-               8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
-               PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
-
-       png_write_info(png_ptr, info_ptr);
-       png_write_image(png_ptr, row_pointers);
-       png_write_end(png_ptr, NULL);
-
-       ret = 0;
-
-end4:
-//     png_destroy_info_struct(png_ptr, &info_ptr); // freed below
-end3:
-       png_destroy_write_struct(&png_ptr, &info_ptr);
-end2:
-       for (i = 0; i < h; i++)
-               free(row_pointers[i]);
-       free(row_pointers);
-end1:
-       fclose(f);
-       return ret;
-}
-
diff --git a/platform/common/readpng.h b/platform/common/readpng.h
deleted file mode 100644 (file)
index 924b341..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-typedef enum
-{
-       READPNG_BG = 1,
-       READPNG_FONT,
-       READPNG_SELECTOR,
-       READPNG_24,
-}
-readpng_what;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int readpng(void *dest, const char *fname, readpng_what what, int w, int h);
-int writepng(const char *fname, unsigned short *src, int w, int h);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/platform/common/revision.mak b/platform/common/revision.mak
deleted file mode 100644 (file)
index 2e92875..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-platform/common/menu.o : revision.h
-
-revision.h: FORCE
-ifndef NOREVISION
-       @echo "#define REVISION \"`svn info -r HEAD | grep Revision | cut -c 11-`\"" > /tmp/r.tmp
-else
-       @echo "#define REVISION \"0\"" > /tmp/r.tmp
-endif
-       @diff -q $@ /tmp/r.tmp > /dev/null 2>&1 || mv -f /tmp/r.tmp $@
-
-FORCE:
-
index da0cc55..7bf7acb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit da0cc55643353ab15725194be64a3d8460fe48b1
+Subproject commit 7bf7acb6d60e16e9eaa208761d019c39da396fc0
diff --git a/platform/linux/Makefile b/platform/linux/Makefile
deleted file mode 100644 (file)
index 34856ac..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-# settings
-#use_fbdev = 1
-#fake_in_gp2x = 1
-
-use_musashi = 1
-#use_fame = 1
-use_cz80 = 1
-use_sh2drc = 1
-#use_sh2mame = 1
-
-#drc_debug = 3
-#drc_debug_interp = 1
-#profile = 1
-
-all: mkdirs PicoDrive
-
--include Makefile.local
-
-ifndef ARCH
-ARCH = x86
-endif
-
-DEFINES = _UNZIP_SUPPORT IO_STATS IN_EVDEV
-CFLAGS += -ggdb -Wall -falign-functions=2
-CFLAGS += -I../.. -I.
-LDFLAGS += -lm -lpng
-ifeq "$(ARCH)" "arm"
-CFLAGS += -mcpu=arm920t
-DEFINES += ARM
-endif
-
-CC ?= $(CROSS)gcc
-
-# frontend
-OBJS += io.o emu.o blit.o in_evdev.o plat.o sndout_oss.o log_io.o
-
-# common
-OBJS += platform/common/main.o platform/common/emu.o platform/common/menu_pico.o \
-       platform/common/config.o platform/common/fonts.o platform/common/readpng.o \
-       platform/common/input.o
-
-ifeq "$(use_fbdev)" "1"
-DEFINES += FBDEV
-OBJS += fbdev.o
-else
-LDFLAGS += -lpthread
-LDFLAGS += -lX11
-endif
-
-ifeq "$(fake_in_gp2x)" "1"
-DEFINES += IN_GP2X FAKE_IN_GP2X
-OBJS += platform/gp2x/in_gp2x.o
-DIRS += platform/gp2x
-endif
-
-ifeq "$(ARCH)" "arm"
-OBJS += pico/carthw/svp/stub_arm.o
-endif
-OBJS += pico/sound/mix.o
-OBJS += pico/carthw/svp/compiler.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 zlib/uncompr.o
-# unzip
-OBJS += unzip/unzip.o unzip/unzip_stream.o
-
-vpath %.c = ../..
-vpath %.s = ../..
-vpath %.S = ../..
-vpath %.asm = ../..
-
-DIRS += platform/linux zlib unzip
-
-include ../common/common.mak
-include ../common/revision.mak
-
-CFLAGS += $(addprefix -D,$(DEFINES))
-
-clean: tidy
-       @$(RM) PicoDrive
-tidy:
-       $(RM) $(OBJS)
-       rm -rf $(DIRS)
-       @make -C ../../cpu/mz80/ clean
-
-PicoDrive : $(OBJS)
-       @echo ">>>" $@
-       $(CC) $(CFLAGS) $^ $(LDFLAGS) -Wl,-Map=PicoDrive.map -o $@
-
-pprof: pprof.c
-       $(CROSS)gcc -O2 -ggdb -DPPROF -DPPROF_TOOL -I../../ -I. $^ -o $@
-
-%.o : %.asm
-       @echo ">>>" $<
-       nasm -f elf $< -o $@
-
index 95666ad..cf05dbc 100644 (file)
@@ -6,11 +6,11 @@
 #include <stdio.h>\r
 #include <unistd.h>\r
 \r
+#include "../libpicofe/menu.h"\r
+#include "../libpicofe/plat.h"\r
+#include "../libpicofe/linux/sndout_oss.h"\r
 #include "../common/emu.h"\r
-#include "../common/menu.h"\r
-#include "../common/plat.h"\r
 #include "../common/arm_utils.h"\r
-#include "../linux/sndout_oss.h"\r
 #include "version.h"\r
 \r
 #include <pico/pico_int.h>\r
diff --git a/platform/linux/fbdev.c b/platform/linux/fbdev.c
deleted file mode 100644 (file)
index ec3d5c7..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2009-2010
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <linux/fb.h>
-#include <linux/matroxfb.h>
-
-#include "fbdev.h"
-
-#define PFX "fbdev: "
-
-struct vout_fbdev {
-       int     fd;
-       void    *mem;
-       size_t  mem_size;
-       struct  fb_var_screeninfo fbvar_old;
-       struct  fb_var_screeninfo fbvar_new;
-       int     buffer_write;
-       int     fb_size;
-       int     buffer_count;
-       int     top_border, bottom_border;
-       void    *mem_saved;
-       size_t  mem_saved_size;
-};
-
-void *vout_fbdev_flip(struct vout_fbdev *fbdev)
-{
-       int draw_buf;
-
-       if (fbdev->buffer_count < 2)
-               return fbdev->mem;
-
-       draw_buf = fbdev->buffer_write;
-       fbdev->buffer_write++;
-       if (fbdev->buffer_write >= fbdev->buffer_count)
-               fbdev->buffer_write = 0;
-
-       fbdev->fbvar_new.yoffset = 
-               (fbdev->top_border + fbdev->fbvar_new.yres + fbdev->bottom_border) * draw_buf +
-               fbdev->top_border;
-
-       ioctl(fbdev->fd, FBIOPAN_DISPLAY, &fbdev->fbvar_new);
-
-       return (char *)fbdev->mem + fbdev->fb_size * fbdev->buffer_write;
-}
-
-void vout_fbdev_wait_vsync(struct vout_fbdev *fbdev)
-{
-       int arg = 0;
-       ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &arg);
-}
-
-/* it is recommended to call vout_fbdev_clear() before this */
-void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
-                     int left_border, int right_border, int top_border, int bottom_border, int buffer_cnt)
-{
-       int w_total = left_border + w + right_border;
-       int h_total = top_border + h + bottom_border;
-       size_t mem_size;
-       int ret;
-
-       // unblank to be sure the mode is really accepted
-       ioctl(fbdev->fd, FBIOBLANK, FB_BLANK_UNBLANK);
-
-       if (fbdev->fbvar_new.bits_per_pixel != bpp ||
-                       fbdev->fbvar_new.xres != w ||
-                       fbdev->fbvar_new.yres != h ||
-                       fbdev->fbvar_new.xres_virtual != w_total||
-                       fbdev->fbvar_new.yres_virtual < h_total ||
-                       fbdev->fbvar_new.xoffset != left_border ||
-                       fbdev->buffer_count != buffer_cnt)
-       {
-               if (fbdev->fbvar_new.bits_per_pixel != bpp ||
-                               w != fbdev->fbvar_new.xres || h != fbdev->fbvar_new.yres)
-                       printf(PFX "switching to %dx%d@%d\n", w, h, bpp);
-
-               fbdev->fbvar_new.xres = w;
-               fbdev->fbvar_new.yres = h;
-               fbdev->fbvar_new.xres_virtual = w_total;
-               fbdev->fbvar_new.yres_virtual = h_total * buffer_cnt;
-               fbdev->fbvar_new.xoffset = left_border;
-               fbdev->fbvar_new.yoffset = top_border;
-               fbdev->fbvar_new.bits_per_pixel = bpp;
-               fbdev->fbvar_new.nonstd = 0; // can set YUV here on omapfb
-               fbdev->buffer_count = buffer_cnt;
-               fbdev->buffer_write = buffer_cnt > 1 ? 1 : 0;
-
-               // seems to help a bit to avoid glitches
-               vout_fbdev_wait_vsync(fbdev);
-
-               ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
-               if (ret == -1) {
-                       // retry with no multibuffering
-                       fbdev->fbvar_new.yres_virtual = h_total;
-                       ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
-                       if (ret == -1) {
-                               perror(PFX "FBIOPUT_VSCREENINFO ioctl");
-                               return NULL;
-                       }
-                       fbdev->buffer_count = 1;
-                       fbdev->buffer_write = 0;
-                       fprintf(stderr, PFX "Warning: failed to increase virtual resolution, "
-                                       "multibuffering disabled\n");
-               }
-
-       }
-
-       fbdev->fb_size = w_total * h_total * bpp / 8;
-       fbdev->top_border = top_border;
-       fbdev->bottom_border = bottom_border;
-
-       mem_size = fbdev->fb_size * fbdev->buffer_count;
-       if (fbdev->mem_size >= mem_size)
-               goto out;
-
-       if (fbdev->mem != NULL)
-               munmap(fbdev->mem, fbdev->mem_size);
-
-       fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
-       if (fbdev->mem == MAP_FAILED && fbdev->buffer_count > 1) {
-               fprintf(stderr, PFX "Warning: can't map %zd bytes, doublebuffering disabled\n", mem_size);
-               fbdev->buffer_count = 1;
-               fbdev->buffer_write = 0;
-               mem_size = fbdev->fb_size;
-               fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
-       }
-       if (fbdev->mem == MAP_FAILED) {
-               fbdev->mem = NULL;
-               fbdev->mem_size = 0;
-               perror(PFX "mmap framebuffer");
-               return NULL;
-       }
-
-       fbdev->mem_size = mem_size;
-
-out:
-       return (char *)fbdev->mem + fbdev->fb_size * fbdev->buffer_write;
-}
-
-void vout_fbdev_clear(struct vout_fbdev *fbdev)
-{
-       memset(fbdev->mem, 0, fbdev->mem_size);
-}
-
-void vout_fbdev_clear_lines(struct vout_fbdev *fbdev, int y, int count)
-{
-       int stride = fbdev->fbvar_new.xres_virtual * fbdev->fbvar_new.bits_per_pixel / 8;
-       int i;
-
-       if (y + count > fbdev->top_border + fbdev->fbvar_new.yres)
-               count = fbdev->top_border + fbdev->fbvar_new.yres - y;
-
-       if (y >= 0 && count > 0)
-               for (i = 0; i < fbdev->buffer_count; i++)
-                       memset((char *)fbdev->mem + fbdev->fb_size * i + y * stride, 0, stride * count);
-}
-
-int vout_fbdev_get_fd(struct vout_fbdev *fbdev)
-{
-       return fbdev->fd;
-}
-
-struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int bpp, int buffer_cnt)
-{
-       struct vout_fbdev *fbdev;
-       int req_w, req_h;
-       void *pret;
-       int ret;
-
-       fbdev = calloc(1, sizeof(*fbdev));
-       if (fbdev == NULL)
-               return NULL;
-
-       fbdev->fd = open(fbdev_name, O_RDWR);
-       if (fbdev->fd == -1) {
-               fprintf(stderr, PFX "%s: ", fbdev_name);
-               perror("open");
-               goto fail_open;
-       }
-
-       ret = ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->fbvar_old);
-       if (ret == -1) {
-               perror(PFX "FBIOGET_VSCREENINFO ioctl");
-               goto fail;
-       }
-
-       fbdev->fbvar_new = fbdev->fbvar_old;
-
-       req_w = fbdev->fbvar_new.xres;
-       if (*w != 0)
-               req_w = *w;
-       req_h = fbdev->fbvar_new.yres;
-       if (*h != 0)
-               req_h = *h;
-
-       pret = vout_fbdev_resize(fbdev, req_w, req_h, bpp, 0, 0, 0, 0, buffer_cnt);
-       if (pret == NULL)
-               goto fail;
-
-       printf(PFX "%s: %ix%i@%d\n", fbdev_name, fbdev->fbvar_new.xres,
-               fbdev->fbvar_new.yres, fbdev->fbvar_new.bits_per_pixel);
-       *w = fbdev->fbvar_new.xres;
-       *h = fbdev->fbvar_new.yres;
-
-       memset(fbdev->mem, 0, fbdev->mem_size);
-
-       // some checks
-       ret = 0;
-       ret = ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &ret);
-       if (ret != 0)
-               fprintf(stderr, PFX "Warning: vsync doesn't seem to be supported\n");
-
-       if (fbdev->buffer_count > 1) {
-               fbdev->buffer_write = 0;
-               fbdev->fbvar_new.yoffset = fbdev->fbvar_new.yres * (fbdev->buffer_count - 1);
-               ret = ioctl(fbdev->fd, FBIOPAN_DISPLAY, &fbdev->fbvar_new);
-               if (ret != 0) {
-                       fbdev->buffer_count = 1;
-                       fprintf(stderr, PFX "Warning: can't pan display, doublebuffering disabled\n");
-               }
-       }
-
-       printf("fbdev initialized.\n");
-       return fbdev;
-
-fail:
-       close(fbdev->fd);
-fail_open:
-       free(fbdev);
-       return NULL;
-}
-
-static void vout_fbdev_release(struct vout_fbdev *fbdev)
-{
-       ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_old);
-       if (fbdev->mem != MAP_FAILED)
-               munmap(fbdev->mem, fbdev->mem_size);
-       fbdev->mem = NULL;
-}
-
-int vout_fbdev_save(struct vout_fbdev *fbdev)
-{
-       void *tmp;
-
-       if (fbdev == NULL || fbdev->mem == NULL || fbdev->mem == MAP_FAILED) {
-               fprintf(stderr, PFX "bad args for save\n");
-               return -1;
-       }
-
-       if (fbdev->mem_saved_size < fbdev->mem_size) {
-               tmp = realloc(fbdev->mem_saved, fbdev->mem_size);
-               if (tmp == NULL)
-                       return -1;
-               fbdev->mem_saved = tmp;
-       }
-       memcpy(fbdev->mem_saved, fbdev->mem, fbdev->mem_size);
-       fbdev->mem_saved_size = fbdev->mem_size;
-
-       vout_fbdev_release(fbdev);
-       return 0;
-}
-
-int vout_fbdev_restore(struct vout_fbdev *fbdev)
-{
-       int ret;
-
-       if (fbdev == NULL || fbdev->mem != NULL) {
-               fprintf(stderr, PFX "bad args/state for restore\n");
-               return -1;
-       }
-
-       fbdev->mem = mmap(0, fbdev->mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
-       if (fbdev->mem == MAP_FAILED) {
-               perror(PFX "restore: memory restore failed");
-               return -1;
-       }
-       memcpy(fbdev->mem, fbdev->mem_saved, fbdev->mem_size);
-
-       ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
-       if (ret == -1) {
-               perror(PFX "restore: FBIOPUT_VSCREENINFO");
-               return -1;
-       }
-
-       return 0;
-}
-
-void vout_fbdev_finish(struct vout_fbdev *fbdev)
-{
-       vout_fbdev_release(fbdev);
-       if (fbdev->fd >= 0)
-               close(fbdev->fd);
-       fbdev->fd = -1;
-       free(fbdev);
-}
-
diff --git a/platform/linux/fbdev.h b/platform/linux/fbdev.h
deleted file mode 100644 (file)
index 88cd519..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-struct vout_fbdev;
-
-struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int bpp, int buffer_count);
-void *vout_fbdev_flip(struct vout_fbdev *fbdev);
-void  vout_fbdev_wait_vsync(struct vout_fbdev *fbdev);
-void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
-                       int left_border, int right_border, int top_border, int bottom_border,
-                       int buffer_count);
-void  vout_fbdev_clear(struct vout_fbdev *fbdev);
-void  vout_fbdev_clear_lines(struct vout_fbdev *fbdev, int y, int count);
-int   vout_fbdev_get_fd(struct vout_fbdev *fbdev);
-int   vout_fbdev_save(struct vout_fbdev *fbdev);
-int   vout_fbdev_restore(struct vout_fbdev *fbdev);
-void  vout_fbdev_finish(struct vout_fbdev *fbdev);
diff --git a/platform/linux/in_evdev.c b/platform/linux/in_evdev.c
deleted file mode 100644 (file)
index b447da1..0000000
+++ /dev/null
@@ -1,655 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2008-2010
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <linux/input.h>
-#include <errno.h>
-
-#include "../common/input.h"
-#include "in_evdev.h"
-
-#define MAX_ABS_DEVS 8
-
-typedef struct {
-       int fd;
-       int *kbits;
-       int abs_min_x; /* abs->digital mapping */
-       int abs_max_x;
-       int abs_min_y;
-       int abs_max_y;
-       int abs_lzone;
-       int abs_lastx;
-       int abs_lasty;
-       int kc_first;
-       int kc_last;
-       unsigned int abs_count;
-       int abs_mult[MAX_ABS_DEVS]; /* 16.16 multiplier to IN_ABS_RANGE */
-       int abs_adj[MAX_ABS_DEVS];  /* adjust for centering */
-       unsigned int abs_to_digital:1;
-} in_evdev_t;
-
-#ifndef KEY_CNT
-#define KEY_CNT (KEY_MAX + 1)
-#endif
-
-#define KEYBITS_BIT(x) (keybits[(x)/sizeof(keybits[0])/8] & \
-       (1 << ((x) & (sizeof(keybits[0])*8-1))))
-
-#define KEYBITS_BIT_SET(x) (keybits[(x)/sizeof(keybits[0])/8] |= \
-       (1 << ((x) & (sizeof(keybits[0])*8-1))))
-
-#define KEYBITS_BIT_CLEAR(x) (keybits[(x)/sizeof(keybits[0])/8] &= \
-       ~(1 << ((x) & (sizeof(keybits[0])*8-1))))
-
-int in_evdev_allow_abs_only;
-
-#define IN_EVDEV_PREFIX "evdev:"
-
-static const char * const in_evdev_keys[KEY_CNT] = {
-       [0 ... KEY_MAX] = NULL,
-       [KEY_RESERVED] = "Reserved",            [KEY_ESC] = "Esc",
-       [KEY_1] = "1",                          [KEY_2] = "2",
-       [KEY_3] = "3",                          [KEY_4] = "4",
-       [KEY_5] = "5",                          [KEY_6] = "6",
-       [KEY_7] = "7",                          [KEY_8] = "8",
-       [KEY_9] = "9",                          [KEY_0] = "0",
-       [KEY_MINUS] = "Minus",                  [KEY_EQUAL] = "Equal",
-       [KEY_BACKSPACE] = "Backspace",          [KEY_TAB] = "Tab",
-       [KEY_Q] = "Q",                          [KEY_W] = "W",
-       [KEY_E] = "E",                          [KEY_R] = "R",
-       [KEY_T] = "T",                          [KEY_Y] = "Y",
-       [KEY_U] = "U",                          [KEY_I] = "I",
-       [KEY_O] = "O",                          [KEY_P] = "P",
-       [KEY_LEFTBRACE] = "LeftBrace",          [KEY_RIGHTBRACE] = "RightBrace",
-       [KEY_ENTER] = "Enter",                  [KEY_LEFTCTRL] = "LeftControl",
-       [KEY_A] = "A",                          [KEY_S] = "S",
-       [KEY_D] = "D",                          [KEY_F] = "F",
-       [KEY_G] = "G",                          [KEY_H] = "H",
-       [KEY_J] = "J",                          [KEY_K] = "K",
-       [KEY_L] = "L",                          [KEY_SEMICOLON] = "Semicolon",
-       [KEY_APOSTROPHE] = "Apostrophe",        [KEY_GRAVE] = "Grave",
-       [KEY_LEFTSHIFT] = "LeftShift",          [KEY_BACKSLASH] = "BackSlash",
-       [KEY_Z] = "Z",                          [KEY_X] = "X",
-       [KEY_C] = "C",                          [KEY_V] = "V",
-       [KEY_B] = "B",                          [KEY_N] = "N",
-       [KEY_M] = "M",                          [KEY_COMMA] = "Comma",
-       [KEY_DOT] = "Dot",                      [KEY_SLASH] = "Slash",
-       [KEY_RIGHTSHIFT] = "RightShift",        [KEY_KPASTERISK] = "KPAsterisk",
-       [KEY_LEFTALT] = "LeftAlt",              [KEY_SPACE] = "Space",
-       [KEY_CAPSLOCK] = "CapsLock",            [KEY_F1] = "F1",
-       [KEY_F2] = "F2",                        [KEY_F3] = "F3",
-       [KEY_F4] = "F4",                        [KEY_F5] = "F5",
-       [KEY_F6] = "F6",                        [KEY_F7] = "F7",
-       [KEY_F8] = "F8",                        [KEY_F9] = "F9",
-       [KEY_F10] = "F10",                      [KEY_NUMLOCK] = "NumLock",
-       [KEY_SCROLLLOCK] = "ScrollLock",        [KEY_KP7] = "KP7",
-       [KEY_KP8] = "KP8",                      [KEY_KP9] = "KP9",
-       [KEY_KPMINUS] = "KPMinus",              [KEY_KP4] = "KP4",
-       [KEY_KP5] = "KP5",                      [KEY_KP6] = "KP6",
-       [KEY_KPPLUS] = "KPPlus",                [KEY_KP1] = "KP1",
-       [KEY_KP2] = "KP2",                      [KEY_KP3] = "KP3",
-       [KEY_KP0] = "KP0",                      [KEY_KPDOT] = "KPDot",
-       [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
-       [KEY_F11] = "F11",                      [KEY_F12] = "F12",
-       [KEY_KPJPCOMMA] = "KPJpComma",          [KEY_KPENTER] = "KPEnter",
-       [KEY_RIGHTCTRL] = "RightCtrl",          [KEY_KPSLASH] = "KPSlash",
-       [KEY_SYSRQ] = "SysRq",                  [KEY_RIGHTALT] = "RightAlt",
-       [KEY_LINEFEED] = "LineFeed",            [KEY_HOME] = "Home",
-       [KEY_UP] = "Up",                        [KEY_PAGEUP] = "PageUp",
-       [KEY_LEFT] = "Left",                    [KEY_RIGHT] = "Right",
-       [KEY_END] = "End",                      [KEY_DOWN] = "Down",
-       [KEY_PAGEDOWN] = "PageDown",            [KEY_INSERT] = "Insert",
-       [KEY_DELETE] = "Delete",                [KEY_MACRO] = "Macro",
-       [KEY_HELP] = "Help",                    [KEY_MENU] = "Menu",
-       [KEY_COFFEE] = "Coffee",                [KEY_DIRECTION] = "Direction",
-       [BTN_0] = "Btn0",                       [BTN_1] = "Btn1",
-       [BTN_2] = "Btn2",                       [BTN_3] = "Btn3",
-       [BTN_4] = "Btn4",                       [BTN_5] = "Btn5",
-       [BTN_6] = "Btn6",                       [BTN_7] = "Btn7",
-       [BTN_8] = "Btn8",                       [BTN_9] = "Btn9",
-       [BTN_LEFT] = "LeftBtn",                 [BTN_RIGHT] = "RightBtn",
-       [BTN_MIDDLE] = "MiddleBtn",             [BTN_SIDE] = "SideBtn",
-       [BTN_EXTRA] = "ExtraBtn",               [BTN_FORWARD] = "ForwardBtn",
-       [BTN_BACK] = "BackBtn",                 [BTN_TASK] = "TaskBtn",
-       [BTN_TRIGGER] = "Trigger",              [BTN_THUMB] = "ThumbBtn",
-       [BTN_THUMB2] = "ThumbBtn2",             [BTN_TOP] = "TopBtn",
-       [BTN_TOP2] = "TopBtn2",                 [BTN_PINKIE] = "PinkieBtn",
-       [BTN_BASE] = "BaseBtn",                 [BTN_BASE2] = "BaseBtn2",
-       [BTN_BASE3] = "BaseBtn3",               [BTN_BASE4] = "BaseBtn4",
-       [BTN_BASE5] = "BaseBtn5",               [BTN_BASE6] = "BaseBtn6",
-       [BTN_DEAD] = "BtnDead",                 [BTN_A] = "BtnA",
-       [BTN_B] = "BtnB",                       [BTN_C] = "BtnC",
-       [BTN_X] = "BtnX",                       [BTN_Y] = "BtnY",
-       [BTN_Z] = "BtnZ",                       [BTN_TL] = "BtnTL",
-       [BTN_TR] = "BtnTR",                     [BTN_TL2] = "BtnTL2",
-       [BTN_TR2] = "BtnTR2",                   [BTN_SELECT] = "BtnSelect",
-       [BTN_START] = "BtnStart",               [BTN_MODE] = "BtnMode",
-       [BTN_THUMBL] = "BtnThumbL",             [BTN_THUMBR] = "BtnThumbR",
-       [BTN_TOUCH] = "Touch",                  [BTN_STYLUS] = "Stylus",
-       [BTN_STYLUS2] = "Stylus2",              [BTN_TOOL_DOUBLETAP] = "Tool Doubletap",
-       [BTN_TOOL_TRIPLETAP] = "Tool Tripletap", [BTN_GEAR_DOWN] = "WheelBtn",
-       [BTN_GEAR_UP] = "Gear up",              [KEY_OK] = "Ok",
-};
-
-
-static void in_evdev_probe(void)
-{
-       long keybits[KEY_CNT / sizeof(long) / 8];
-       long absbits[(ABS_MAX+1) / sizeof(long) / 8];
-       int i;
-
-       // the kernel might support and return less keys then we know about,
-       // so make sure the buffers are clear.
-       memset(keybits, 0, sizeof(keybits));
-       memset(absbits, 0, sizeof(absbits));
-
-       for (i = 0;; i++)
-       {
-               int support = 0, count = 0;
-               int u, ret, fd, kc_first = KEY_MAX, kc_last = 0, have_abs = 0;
-               in_evdev_t *dev;
-               char name[64];
-
-               snprintf(name, sizeof(name), "/dev/input/event%d", i);
-               fd = open(name, O_RDONLY|O_NONBLOCK);
-               if (fd == -1) {
-                       if (errno == EACCES)
-                               continue;       /* maybe we can access next one */
-                       break;
-               }
-
-               /* check supported events */
-               ret = ioctl(fd, EVIOCGBIT(0, sizeof(support)), &support);
-               if (ret == -1) {
-                       printf("in_evdev: ioctl failed on %s\n", name);
-                       goto skip;
-               }
-
-               if (support & (1 << EV_KEY)) {
-                       ret = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
-                       if (ret == -1) {
-                               printf("in_evdev: ioctl failed on %s\n", name);
-                               goto skip;
-                       }
-
-                       /* check for interesting keys */
-                       for (u = 0; u < KEY_CNT; u++) {
-                               if (KEYBITS_BIT(u)) {
-                                       if (u < kc_first)
-                                               kc_first = u;
-                                       if (u > kc_last)
-                                               kc_last = u;
-                                       if (u != KEY_POWER && u != KEY_SLEEP && u != BTN_TOUCH)
-                                               count++;
-                                       if (u == BTN_TOUCH) /* we can't deal with ts currently */
-                                               goto skip;
-                               }
-                       }
-               }
-
-               dev = calloc(1, sizeof(*dev));
-               if (dev == NULL)
-                       goto skip;
-
-               ret = ioctl(fd, EVIOCGKEY(sizeof(keybits)), keybits);
-               if (ret == -1) {
-                       printf("Warning: EVIOCGKEY not supported, will have to track state\n");
-                       dev->kbits = calloc(KEY_CNT, sizeof(int));
-                       if (dev->kbits == NULL) {
-                               free(dev);
-                               goto skip;
-                       }
-               }
-
-               /* check for abs too */
-               if (support & (1 << EV_ABS)) {
-                       struct input_absinfo ainfo;
-                       int dist;
-                       ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits);
-                       if (ret == -1)
-                               goto no_abs;
-                       if (absbits[0] & (1 << ABS_X)) {
-                               ret = ioctl(fd, EVIOCGABS(ABS_X), &ainfo);
-                               if (ret == -1)
-                                       goto no_abs;
-                               dist = ainfo.maximum - ainfo.minimum;
-                               dev->abs_lzone = dist / 4;
-                               dev->abs_min_x = ainfo.minimum;
-                               dev->abs_max_x = ainfo.maximum;
-                       }
-                       if (absbits[0] & (1 << ABS_Y)) {
-                               ret = ioctl(fd, EVIOCGABS(ABS_Y), &ainfo);
-                               if (ret == -1)
-                                       goto no_abs;
-                               dist = ainfo.maximum - ainfo.minimum;
-                               dev->abs_min_y = ainfo.minimum;
-                               dev->abs_max_y = ainfo.maximum;
-                       }
-                       for (u = 0; u < MAX_ABS_DEVS; u++) {
-                               ret = ioctl(fd, EVIOCGABS(u), &ainfo);
-                               if (ret == -1)
-                                       break;
-                               dist = ainfo.maximum - ainfo.minimum;
-                               if (dist != 0)
-                                       dev->abs_mult[u] = IN_ABS_RANGE * 2 * 65536 / dist;
-                               dev->abs_adj[u] = -(ainfo.maximum + ainfo.minimum + 1) / 2;
-                               have_abs = 1;
-                       }
-                       dev->abs_count = u;
-               }
-
-no_abs:
-               if (count == 0 && !have_abs) {
-                       free(dev);
-                       goto skip;
-               }
-
-               dev->fd = fd;
-               dev->kc_first = kc_first;
-               dev->kc_last = kc_last;
-               if (count > 0 || in_evdev_allow_abs_only)
-                       dev->abs_to_digital = 1;
-               strcpy(name, IN_EVDEV_PREFIX);
-               ioctl(fd, EVIOCGNAME(sizeof(name)-6), name+6);
-               printf("in_evdev: found \"%s\" with %d events (type %08x)\n",
-                       name+6, count, support);
-               in_register(name, fd, dev, KEY_CNT, in_evdev_keys, 0);
-               continue;
-
-skip:
-               close(fd);
-       }
-}
-
-static void in_evdev_free(void *drv_data)
-{
-       in_evdev_t *dev = drv_data;
-       if (dev == NULL)
-               return;
-       close(dev->fd);
-       free(dev);
-}
-
-static const char * const *
-in_evdev_get_key_names(int *count)
-{
-       *count = KEY_CNT;
-       return in_evdev_keys;
-}
-
-static void or_binds(const int *binds, int key, int *result)
-{
-       int t;
-       for (t = 0; t < IN_BINDTYPE_COUNT; t++)
-               result[t] |= binds[IN_BIND_OFFS(key, t)];
-}
-
-/* ORs result with binds of pressed buttons
- * XXX: should measure performance hit of this func, might need to optimize */
-static int in_evdev_update(void *drv_data, const int *binds, int *result)
-{
-       struct input_event ev[16];
-       struct input_absinfo ainfo;
-       int keybits_[KEY_CNT / sizeof(int)];
-       int *keybits = keybits_;
-       in_evdev_t *dev = drv_data;
-       int rd, ret, u, lzone;
-
-       if (dev->kbits == NULL) {
-               ret = ioctl(dev->fd, EVIOCGKEY(sizeof(keybits_)), keybits_);
-               if (ret == -1) {
-                       perror("in_evdev: ioctl failed");
-                       return -1;
-               }
-       }
-       else {
-               keybits = dev->kbits;
-               while (1) {
-                       rd = read(dev->fd, ev, sizeof(ev));
-                       if (rd < (int)sizeof(ev[0])) {
-                               if (errno != EAGAIN)
-                                       perror("in_evdev: read failed");
-                               break;
-                       }
-                       for (u = 0; u < rd / sizeof(ev[0]); u++) {
-                               if (ev[u].type != EV_KEY)
-                                       continue;
-                               else if (ev[u].value == 1)
-                                       KEYBITS_BIT_SET(ev[u].code);
-                               else if (ev[u].value == 0)
-                                       KEYBITS_BIT_CLEAR(ev[u].code);
-                       }
-               }
-       }
-
-       for (u = dev->kc_first; u <= dev->kc_last; u++) {
-               if (KEYBITS_BIT(u))
-                       or_binds(binds, u, result);
-       }
-
-       /* map X and Y absolute to UDLR */
-       lzone = dev->abs_lzone;
-       if (dev->abs_to_digital && lzone != 0) {
-               ret = ioctl(dev->fd, EVIOCGABS(ABS_X), &ainfo);
-               if (ret != -1) {
-                       if (ainfo.value < dev->abs_min_x + lzone) or_binds(binds, KEY_LEFT, result);
-                       if (ainfo.value > dev->abs_max_x - lzone) or_binds(binds, KEY_RIGHT, result);
-               }
-               ret = ioctl(dev->fd, EVIOCGABS(ABS_Y), &ainfo);
-               if (ret != -1) {
-                       if (ainfo.value < dev->abs_min_y + lzone) or_binds(binds, KEY_UP, result);
-                       if (ainfo.value > dev->abs_max_y - lzone) or_binds(binds, KEY_DOWN, result);
-               }
-       }
-
-       return 0;
-}
-
-static int in_evdev_update_analog(void *drv_data, int axis_id, int *result)
-{
-       struct input_absinfo ainfo;
-       in_evdev_t *dev = drv_data;
-       int ret;
-
-       if ((unsigned int)axis_id >= MAX_ABS_DEVS)
-               return -1;
-
-       ret = ioctl(dev->fd, EVIOCGABS(axis_id), &ainfo);
-       if (ret != 0)
-               return ret;
-
-       *result = (ainfo.value + dev->abs_adj[axis_id]) * dev->abs_mult[axis_id];
-       *result >>= 16;
-       return 0;
-}
-
-static int in_evdev_set_blocking(in_evdev_t *dev, int y)
-{
-       long flags;
-       int ret;
-
-       flags = (long)fcntl(dev->fd, F_GETFL);
-       if ((int)flags == -1) {
-               perror("in_evdev: F_GETFL fcntl failed");
-               return -1;
-       }
-
-       if (flags & O_NONBLOCK) {
-               /* flush the event queue */
-               struct input_event ev;
-               do {
-                       ret = read(dev->fd, &ev, sizeof(ev));
-               }
-               while (ret == sizeof(ev));
-       }
-
-       if (y)
-               flags &= ~O_NONBLOCK;
-       else
-               flags |=  O_NONBLOCK;
-       ret = fcntl(dev->fd, F_SETFL, flags);
-       if (ret == -1) {
-               perror("in_evdev: F_SETFL fcntl failed");
-               return -1;
-       }
-
-       return 0;
-}
-
-static int in_evdev_get_config(void *drv_data, int what, int *val)
-{
-       in_evdev_t *dev = drv_data;
-
-       switch (what) {
-       case IN_CFG_ABS_AXIS_COUNT:
-               *val = dev->abs_count;
-               break;
-       default:
-               return -1;
-       }
-
-       return 0;
-}
-
-static int in_evdev_set_config(void *drv_data, int what, int val)
-{
-       in_evdev_t *dev = drv_data;
-       int tmp;
-
-       switch (what) {
-       case IN_CFG_BLOCKING:
-               return in_evdev_set_blocking(dev, val);
-       case IN_CFG_ABS_DEAD_ZONE:
-               if (val < 1 || val > 99 || dev->abs_lzone == 0)
-                       return -1;
-               /* XXX: based on X axis only, for now.. */
-               tmp = (dev->abs_max_x - dev->abs_min_x) / 2;
-               dev->abs_lzone = tmp - tmp * val / 100;
-               if (dev->abs_lzone < 1)
-                       dev->abs_lzone = 1;
-               else if (dev->abs_lzone >= tmp)
-                       dev->abs_lzone = tmp - 1;
-               break;
-       default:
-               return -1;
-       }
-
-       return 0;
-}
-
-static int in_evdev_update_keycode(void *data, int *is_down)
-{
-       int ret_kc = -1, ret_down = 0;
-       in_evdev_t *dev = data;
-       struct input_event ev;
-       int rd;
-
-       /* do single event, the caller sometimes wants
-        * to do select() in blocking mode */
-       rd = read(dev->fd, &ev, sizeof(ev));
-       if (rd < (int) sizeof(ev)) {
-               if (errno != EAGAIN) {
-                       perror("in_evdev: error reading");
-                       //sleep(1);
-                       ret_kc = -2;
-               }
-               goto out;
-       }
-
-       if (ev.type == EV_KEY) {
-               if (ev.value < 0 || ev.value > 1)
-                       goto out;
-               ret_kc = ev.code;
-               ret_down = ev.value;
-               goto out;
-       }
-       else if (ev.type == EV_ABS && dev->abs_to_digital)
-       {
-               int lzone = dev->abs_lzone, down = 0, *last;
-
-               // map absolute to up/down/left/right
-               if (lzone != 0 && ev.code == ABS_X) {
-                       if (ev.value < dev->abs_min_x + lzone)
-                               down = KEY_LEFT;
-                       else if (ev.value > dev->abs_max_x - lzone)
-                               down = KEY_RIGHT;
-                       last = &dev->abs_lastx;
-               }
-               else if (lzone != 0 && ev.code == ABS_Y) {
-                       if (ev.value < dev->abs_min_y + lzone)
-                               down = KEY_UP;
-                       else if (ev.value > dev->abs_max_y - lzone)
-                               down = KEY_DOWN;
-                       last = &dev->abs_lasty;
-               }
-               else
-                       goto out;
-
-               if (down == *last)
-                       goto out;
-
-               if (down == 0 || *last != 0) {
-                       /* key up or direction change, return up event for old key */
-                       ret_kc = *last;
-                       ret_down = 0;
-                       *last = 0;
-                       goto out;
-               }
-               ret_kc = *last = down;
-               ret_down = 1;
-               goto out;
-       }
-
-out:
-       if (is_down != NULL)
-               *is_down = ret_down;
-
-       return ret_kc;
-}
-
-static const struct {
-       short key;
-       short pbtn;
-} key_pbtn_map[] =
-{
-       { KEY_UP,       PBTN_UP },
-       { KEY_DOWN,     PBTN_DOWN },
-       { KEY_LEFT,     PBTN_LEFT },
-       { KEY_RIGHT,    PBTN_RIGHT },
-       /* XXX: maybe better set this from it's plat code somehow */
-       /* Pandora */
-       { KEY_END,      PBTN_MOK },
-       { KEY_PAGEDOWN, PBTN_MBACK },
-       { KEY_HOME,     PBTN_MA2 },
-       { KEY_PAGEUP,   PBTN_MA3 },
-       { KEY_LEFTCTRL,   PBTN_MENU },
-       { KEY_RIGHTSHIFT, PBTN_L },
-       { KEY_RIGHTCTRL,  PBTN_R },
-       /* Caanoo */
-       { BTN_THUMB2,   PBTN_MOK },
-       { BTN_THUMB,    PBTN_MBACK },
-       { BTN_TRIGGER,  PBTN_MA2 },
-       { BTN_TOP,      PBTN_MA3 },
-       { BTN_BASE,     PBTN_MENU },
-       { BTN_TOP2,     PBTN_L },
-       { BTN_PINKIE,   PBTN_R },
-       /* "normal" keyboards */
-       { KEY_ENTER,    PBTN_MOK },
-       { KEY_ESC,      PBTN_MBACK },
-       { KEY_A,        PBTN_MA2 },
-       { KEY_S,        PBTN_MA3 },
-       { KEY_BACKSLASH,  PBTN_MENU },
-       { KEY_LEFTBRACE,  PBTN_L },
-       { KEY_RIGHTBRACE, PBTN_R },
-};
-
-#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-
-static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
-{
-       in_evdev_t *dev = drv_data;
-       int ret = 0;
-       int i;
-
-       if (keycode < 0)
-       {
-               /* menu -> kc */
-               keycode = -keycode;
-               for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
-                       if (key_pbtn_map[i].pbtn == keycode) {
-                               int k = key_pbtn_map[i].key;
-                               /* should really check EVIOCGBIT, but this is enough for now */
-                               if (dev->kc_first <= k && k <= dev->kc_last)
-                                       return k;
-                       }
-       }
-       else
-       {
-               for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) {
-                       if (key_pbtn_map[i].key == keycode) {
-                               ret = key_pbtn_map[i].pbtn;
-                               break;
-                       }
-               }
-
-               if (charcode != NULL && (unsigned int)keycode < KEY_CNT &&
-                   in_evdev_keys[keycode] != NULL && in_evdev_keys[keycode][1] == 0)
-               {
-                       char c = in_evdev_keys[keycode][0];
-                       if ('A' <= c && c <= 'Z')
-                               c = 'a' + c - 'A';
-                       ret |= PBTN_CHAR;
-                       *charcode = c;
-               }
-       }
-
-       return ret;
-}
-
-/* remove binds of missing keys, count remaining ones */
-static int in_evdev_clean_binds(void *drv_data, int *binds, int *def_binds)
-{
-       int keybits[KEY_CNT / sizeof(int)];
-       in_evdev_t *dev = drv_data;
-       int i, t, ret, offs, count = 0;
-
-       memset(keybits, 0, sizeof(keybits));
-       ret = ioctl(dev->fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
-       if (ret == -1) {
-               perror("in_evdev: ioctl failed");
-               // memset(keybits, 0xff, sizeof(keybits)); /* mark all as good */
-       }
-
-       if (dev->abs_to_digital && dev->abs_lzone != 0) {
-               KEYBITS_BIT_SET(KEY_LEFT);
-               KEYBITS_BIT_SET(KEY_RIGHT);
-               KEYBITS_BIT_SET(KEY_UP);
-               KEYBITS_BIT_SET(KEY_DOWN);
-       }
-
-       for (i = 0; i < KEY_CNT; i++) {
-               for (t = 0; t < IN_BINDTYPE_COUNT; t++) {
-                       offs = IN_BIND_OFFS(i, t);
-                       if (!KEYBITS_BIT(i))
-                               binds[offs] = def_binds[offs] = 0;
-                       if (binds[offs])
-                               count++;
-               }
-       }
-
-       return count;
-}
-
-static const in_drv_t in_evdev_drv = {
-       .prefix         = IN_EVDEV_PREFIX,
-       .probe          = in_evdev_probe,
-       .free           = in_evdev_free,
-       .get_key_names  = in_evdev_get_key_names,
-       .clean_binds    = in_evdev_clean_binds,
-       .get_config     = in_evdev_get_config,
-       .set_config     = in_evdev_set_config,
-       .update         = in_evdev_update,
-       .update_analog  = in_evdev_update_analog,
-       .update_keycode = in_evdev_update_keycode,
-       .menu_translate = in_evdev_menu_translate,
-};
-
-void in_evdev_init(const struct in_default_bind *defbinds)
-{
-       in_register_driver(&in_evdev_drv, defbinds);
-}
-
index 2767e68..5e2d5e3 100644 (file)
@@ -2,11 +2,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "../libpicofe/menu.h"
+#include "../libpicofe/input.h"
+#include "../libpicofe/linux/sndout_oss.h"
 #include "../common/emu.h"
-#include "../common/menu.h"
-#include "../common/plat.h"
-#include "../common/input.h"
-#include "sndout_oss.h"
+#include "../common/input_pico.h"
 #include "version.h"
 
 #include "log_io.h"
diff --git a/platform/linux/plat.c b/platform/linux/plat.c
deleted file mode 100644 (file)
index 4ed1e65..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2008-2010
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#define _GNU_SOURCE 1
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <dirent.h>
-#include <sys/time.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <errno.h>
-
-#include "../common/plat.h"
-
-/* XXX: maybe unhardcode pagesize? */
-#define HUGETLB_PAGESIZE (2 * 1024 * 1024)
-#define HUGETLB_THRESHOLD (HUGETLB_PAGESIZE / 2)
-#ifndef MAP_HUGETLB
-#define MAP_HUGETLB 0x40000 /* arch specific */
-#endif
-
-
-int plat_is_dir(const char *path)
-{
-       DIR *dir;
-       if ((dir = opendir(path))) {
-               closedir(dir);
-               return 1;
-       }
-       return 0;
-}
-
-int plat_get_root_dir(char *dst, int len)
-{
-       int j, ret;
-
-       ret = readlink("/proc/self/exe", dst, len - 1);
-       if (ret < 0) {
-               perror("readlink");
-               ret = 0;
-       }
-       dst[ret] = 0;
-
-       for (j = strlen(dst); j > 0; j--)
-               if (dst[j] == '/') {
-                       dst[++j] = 0;
-                       break;
-               }
-
-       return j;
-}
-
-#ifdef __GP2X__
-/* Wiz has a borked gettimeofday().. */
-#define plat_get_ticks_ms plat_get_ticks_ms_good
-#define plat_get_ticks_us plat_get_ticks_us_good
-#endif
-
-unsigned int plat_get_ticks_ms(void)
-{
-       struct timeval tv;
-       unsigned int ret;
-
-       gettimeofday(&tv, NULL);
-
-       ret = (unsigned)tv.tv_sec * 1000;
-       /* approximate /= 1000 */
-       ret += ((unsigned)tv.tv_usec * 4195) >> 22;
-
-       return ret;
-}
-
-unsigned int plat_get_ticks_us(void)
-{
-       struct timeval tv;
-       unsigned int ret;
-
-       gettimeofday(&tv, NULL);
-
-       ret = (unsigned)tv.tv_sec * 1000000;
-       ret += (unsigned)tv.tv_usec;
-
-       return ret;
-}
-
-void plat_sleep_ms(int ms)
-{
-       usleep(ms * 1000);
-}
-
-int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
-{
-       struct timeval tv, *timeout = NULL;
-       int i, ret, fdmax = -1;
-       fd_set fdset;
-
-       if (timeout_ms >= 0) {
-               tv.tv_sec = timeout_ms / 1000;
-               tv.tv_usec = (timeout_ms % 1000) * 1000;
-               timeout = &tv;
-       }
-
-       FD_ZERO(&fdset);
-       for (i = 0; i < count; i++) {
-               if (fds_hnds[i] > fdmax) fdmax = fds_hnds[i];
-               FD_SET(fds_hnds[i], &fdset);
-       }
-
-       ret = select(fdmax + 1, &fdset, NULL, NULL, timeout);
-       if (ret == -1)
-       {
-               perror("plat_wait_event: select failed");
-               sleep(1);
-               return -1;
-       }
-
-       if (ret == 0)
-               return -1; /* timeout */
-
-       ret = -1;
-       for (i = 0; i < count; i++)
-               if (FD_ISSET(fds_hnds[i], &fdset))
-                       ret = fds_hnds[i];
-
-       return ret;
-}
-
-void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
-{
-       static int hugetlb_disabled;
-       int prot = PROT_READ | PROT_WRITE;
-       int flags = MAP_PRIVATE | MAP_ANONYMOUS;
-       void *req, *ret;
-
-       req = (void *)addr;
-       if (need_exec)
-               prot |= PROT_EXEC;
-       if (is_fixed)
-               flags |= MAP_FIXED;
-       if (size >= HUGETLB_THRESHOLD && !hugetlb_disabled)
-               flags |= MAP_HUGETLB;
-
-       ret = mmap(req, size, prot, flags, -1, 0);
-       if (ret == MAP_FAILED && (flags & MAP_HUGETLB)) {
-               fprintf(stderr,
-                       "warning: failed to do hugetlb mmap (%p, %zu): %d\n",
-                       req, size, errno);
-               hugetlb_disabled = 1;
-               flags &= ~MAP_HUGETLB;
-               ret = mmap(req, size, prot, flags, -1, 0);
-       }
-       if (ret == MAP_FAILED)
-               return NULL;
-
-       if (req != NULL && ret != req)
-               fprintf(stderr,
-                       "warning: mmaped to %p, requested %p\n", ret, req);
-
-       return ret;
-}
-
-void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
-{
-       void *ret;
-
-       ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
-       if (ret == MAP_FAILED)
-               return NULL;
-       if (ret != ptr)
-               printf("warning: mremap moved: %p -> %p\n", ptr, ret);
-
-       return ret;
-}
-
-void plat_munmap(void *ptr, size_t size)
-{
-       int ret;
-
-       ret = munmap(ptr, size);
-       if (ret != 0 && (size & (HUGETLB_PAGESIZE - 1))) {
-               // prehaps an autorounded hugetlb mapping?
-               size = (size + HUGETLB_PAGESIZE - 1) & ~(HUGETLB_PAGESIZE - 1);
-               ret = munmap(ptr, size);
-       }
-       if (ret != 0) {
-               fprintf(stderr,
-                       "munmap(%p, %zu) failed: %d\n", ptr, size, errno);
-       }
-}
-
-/* lprintf */
-void lprintf(const char *fmt, ...)
-{
-       va_list vl;
-
-       va_start(vl, fmt);
-       vprintf(fmt, vl);
-       va_end(vl);
-}
-
diff --git a/platform/linux/sndout_oss.c b/platform/linux/sndout_oss.c
deleted file mode 100644 (file)
index 2313d3f..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/* sound output via OSS */
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/soundcard.h>
-#include <unistd.h>
-
-#include "sndout_oss.h"
-
-static int sounddev = -1, mixerdev = -1;
-static int can_write_safe;
-
-#define FRAG_COUNT 4
-
-int sndout_oss_init(void)
-{
-       if (mixerdev >= 0) close(mixerdev);
-       mixerdev = open("/dev/mixer", O_RDWR);
-       if (mixerdev == -1)
-       {
-               perror("open(\"/dev/mixer\")");
-       }
-
-       return 0;
-}
-
-void sndout_oss_stop(void)
-{
-       if (sounddev < 0)
-               return;
-
-       ioctl(sounddev, SOUND_PCM_SYNC, 0);
-       close(sounddev);
-       sounddev = -1;
-}
-
-int sndout_oss_start(int rate, int stereo, int frames_in_frag)
-{
-       static int s_oldrate = 0, s_oldstereo = 0;
-       int frag, bsize, bits, ret;
-
-       // GP2X: if no settings change, we don't need to do anything,
-       // since audio is never stopped there
-       if (sounddev >= 0 && rate == s_oldrate && s_oldstereo == stereo)
-               return 0;
-
-       sndout_oss_stop();
-       sounddev = open("/dev/dsp", O_WRONLY);
-       if (sounddev == -1)
-       {
-               perror("open(\"/dev/dsp\")");
-               sounddev = open("/dev/dsp1", O_WRONLY);
-               if (sounddev == -1) {
-                       perror("open(\"/dev/dsp1\")");
-                       return -1;
-               }
-       }
-
-       // try to fit frames_in_frag frames worth of data in fragment
-       // ignore mono because it's unlikely to be used and
-       // both GP2X and Wiz mixes mono to stereo anyway.
-       bsize = (frames_in_frag * rate / 50) * 4;
-
-       for (frag = 0; bsize; bsize >>= 1, frag++)
-               ;
-
-       frag |= FRAG_COUNT << 16;       // fragment count
-       ret = ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag);
-       if (ret < 0)
-               perror("SNDCTL_DSP_SETFRAGMENT failed");
-
-       bits = 16;
-       ret = ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo);
-       if (ret == 0)
-               ret = ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits);
-       if (ret == 0)
-               ret = ioctl(sounddev, SNDCTL_DSP_SPEED, &rate);
-       if (ret < 0)
-               perror("failed to set audio format");
-
-#ifdef __GP2X__
-       // not sure if this is still needed (avoiding driver bugs?)
-       usleep(192*1024);
-#endif
-
-       printf("sndout_oss_start: %d/%dbit/%s, %d buffers of %i bytes\n",
-               rate, bits, stereo ? "stereo" : "mono", frag >> 16, 1 << (frag & 0xffff));
-
-       s_oldrate = rate; s_oldstereo = stereo;
-       can_write_safe = 0;
-       return 0;
-}
-
-int sndout_oss_write(const void *buff, int len)
-{
-       return write(sounddev, buff, len);
-}
-
-#include "../common/plat.h"
-
-/* not really non-blocking, just detects if blocking occurs
- * and starts skipping writes in case it does. */
-int sndout_oss_write_nb(const void *buff, int len)
-{
-       static int lag_counter, skip_counter;
-       unsigned int t;
-       int ret;
-
-       if (lag_counter > 2) {
-               // skip writes if audio starts blocking
-               lag_counter = 0;
-               skip_counter = FRAG_COUNT;
-       }
-
-       if (skip_counter > 0) {
-               skip_counter--;
-               return len;
-       }
-
-       t = plat_get_ticks_ms();
-       ret = sndout_oss_write(buff, len);
-       t = plat_get_ticks_ms() - t;
-       if (t > 1) {
-               // this shouldn't really happen, most likely audio is out of sync
-               lag_counter++;
-               if (lag_counter > 2)
-                       printf("audio lag %u\n", t);
-       }
-       else
-               lag_counter = 0;
-
-       return ret;
-}
-
-int sndout_oss_can_write(int bytes)
-{
-       audio_buf_info bi;
-       int ret;
-
-#ifdef __GP2X__
-       // note: SNDCTL_DSP_GETOSPACE crashes F100 kernel for some reason
-       // if called too early, so we work around here
-       if (can_write_safe++ < 8)
-               return 1;
-#endif
-       ret = ioctl(sounddev, SNDCTL_DSP_GETOSPACE, &bi);
-       if (ret < 0)
-               return 1;
-
-       // have enough bytes to write + 1 frag
-       return bi.bytes - bi.fragsize >= bytes ? 1 : 0;
-}
-
-void sndout_oss_sync(void)
-{
-       ioctl(sounddev, SOUND_PCM_SYNC, 0);
-}
-
-void sndout_oss_setvol(int l, int r)
-{
-       if (mixerdev < 0) return;
-
-       l=l<0?0:l; l=l>255?255:l; r=r<0?0:r; r=r>255?255:r;
-       l<<=8; l|=r;
-       ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &l); /*SOUND_MIXER_WRITE_VOLUME*/
-}
-
-void sndout_oss_exit(void)
-{
-       if (sounddev >= 0) close(sounddev); sounddev = -1;
-       if (mixerdev >= 0) close(mixerdev); mixerdev = -1;
-}
-
diff --git a/platform/linux/sndout_oss.h b/platform/linux/sndout_oss.h
deleted file mode 100644 (file)
index 0b3fe6c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-int  sndout_oss_init(void);
-int  sndout_oss_start(int rate, int stereo, int frames_in_frag);
-void sndout_oss_stop(void);
-int  sndout_oss_write(const void *buff, int len);
-int  sndout_oss_write_nb(const void *buff, int len);
-int  sndout_oss_can_write(int bytes);
-void sndout_oss_sync(void);
-void sndout_oss_setvol(int l, int r);
-void sndout_oss_exit(void);
diff --git a/platform/linux/xenv.c b/platform/linux/xenv.c
deleted file mode 100644 (file)
index 40bf92c..0000000
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2009-2012
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-
-#include <dlfcn.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/XKBlib.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <termios.h>
-#include <linux/kd.h>
-
-#include "xenv.h"
-
-#define PFX "xenv: "
-
-#define FPTR(f) typeof(f) * p##f
-#define FPTR_LINK(xf, dl, f) { \
-       xf.p##f = dlsym(dl, #f); \
-       if (xf.p##f == NULL) { \
-               fprintf(stderr, "missing symbol: %s\n", #f); \
-               goto fail; \
-       } \
-}
-
-struct xstuff {
-       Display *display;
-       Window window;
-       FPTR(XCreateBitmapFromData);
-       FPTR(XCreatePixmapCursor);
-       FPTR(XFreePixmap);
-       FPTR(XOpenDisplay);
-       FPTR(XDisplayName);
-       FPTR(XCloseDisplay);
-       FPTR(XCreateSimpleWindow);
-       FPTR(XChangeWindowAttributes);
-       FPTR(XSelectInput);
-       FPTR(XMapWindow);
-       FPTR(XNextEvent);
-       FPTR(XCheckTypedEvent);
-       FPTR(XWithdrawWindow);
-       FPTR(XGrabKeyboard);
-       FPTR(XPending);
-       FPTR(XLookupKeysym);
-       FPTR(XkbSetDetectableAutoRepeat);
-       FPTR(XStoreName);
-       FPTR(XIconifyWindow);
-       FPTR(XMoveResizeWindow);
-       FPTR(XInternAtom);
-       FPTR(XSetWMHints);
-       FPTR(XSync);
-};
-
-static struct xstuff g_xstuff;
-
-static Cursor transparent_cursor(struct xstuff *xf, Display *display, Window win)
-{
-       Cursor cursor;
-       Pixmap pix;
-       XColor dummy;
-       char d = 0;
-
-       memset(&dummy, 0, sizeof(dummy));
-       pix = xf->pXCreateBitmapFromData(display, win, &d, 1, 1);
-       cursor = xf->pXCreatePixmapCursor(display, pix, pix,
-                       &dummy, &dummy, 0, 0);
-       xf->pXFreePixmap(display, pix);
-       return cursor;
-}
-
-static int x11h_init(int *xenv_flags, const char *window_title)
-{
-       unsigned int display_width, display_height;
-       Display *display;
-       XSetWindowAttributes attributes;
-       Window win;
-       Visual *visual;
-       long evt_mask;
-       void *x11lib;
-       int screen;
-
-       memset(&g_xstuff, 0, sizeof(g_xstuff));
-       x11lib = dlopen("libX11.so.6", RTLD_LAZY);
-       if (x11lib == NULL) {
-               fprintf(stderr, "libX11.so load failed:\n%s\n", dlerror());
-               goto fail;
-       }
-       FPTR_LINK(g_xstuff, x11lib, XCreateBitmapFromData);
-       FPTR_LINK(g_xstuff, x11lib, XCreatePixmapCursor);
-       FPTR_LINK(g_xstuff, x11lib, XFreePixmap);
-       FPTR_LINK(g_xstuff, x11lib, XOpenDisplay);
-       FPTR_LINK(g_xstuff, x11lib, XDisplayName);
-       FPTR_LINK(g_xstuff, x11lib, XCloseDisplay);
-       FPTR_LINK(g_xstuff, x11lib, XCreateSimpleWindow);
-       FPTR_LINK(g_xstuff, x11lib, XChangeWindowAttributes);
-       FPTR_LINK(g_xstuff, x11lib, XSelectInput);
-       FPTR_LINK(g_xstuff, x11lib, XMapWindow);
-       FPTR_LINK(g_xstuff, x11lib, XNextEvent);
-       FPTR_LINK(g_xstuff, x11lib, XCheckTypedEvent);
-       FPTR_LINK(g_xstuff, x11lib, XWithdrawWindow);
-       FPTR_LINK(g_xstuff, x11lib, XGrabKeyboard);
-       FPTR_LINK(g_xstuff, x11lib, XPending);
-       FPTR_LINK(g_xstuff, x11lib, XLookupKeysym);
-       FPTR_LINK(g_xstuff, x11lib, XkbSetDetectableAutoRepeat);
-       FPTR_LINK(g_xstuff, x11lib, XStoreName);
-       FPTR_LINK(g_xstuff, x11lib, XIconifyWindow);
-       FPTR_LINK(g_xstuff, x11lib, XMoveResizeWindow);
-       FPTR_LINK(g_xstuff, x11lib, XInternAtom);
-       FPTR_LINK(g_xstuff, x11lib, XSetWMHints);
-       FPTR_LINK(g_xstuff, x11lib, XSync);
-
-       //XInitThreads();
-
-       g_xstuff.display = display = g_xstuff.pXOpenDisplay(NULL);
-       if (display == NULL)
-       {
-               fprintf(stderr, "cannot connect to X server %s, X handling disabled.\n",
-                               g_xstuff.pXDisplayName(NULL));
-               goto fail2;
-       }
-
-       visual = DefaultVisual(display, 0);
-       if (visual->class != TrueColor)
-               fprintf(stderr, PFX "warning: non true color visual\n");
-
-       printf(PFX "X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display),
-               VendorRelease(display), DisplayString(display), ProtocolVersion(display),
-               ProtocolRevision(display));
-
-       screen = DefaultScreen(display);
-
-       display_width = DisplayWidth(display, screen);
-       display_height = DisplayHeight(display, screen);
-       printf(PFX "display is %dx%d\n", display_width, display_height);
-
-       g_xstuff.window = win = g_xstuff.pXCreateSimpleWindow(display,
-               RootWindow(display, screen), 0, 0, display_width, display_height,
-               0, BlackPixel(display, screen), BlackPixel(display, screen));
-
-       attributes.override_redirect = True;
-       attributes.cursor = transparent_cursor(&g_xstuff, display, win);
-       g_xstuff.pXChangeWindowAttributes(display, win, CWOverrideRedirect | CWCursor, &attributes);
-
-       if (window_title != NULL)
-               g_xstuff.pXStoreName(display, win, window_title);
-       evt_mask = ExposureMask | FocusChangeMask | PropertyChangeMask;
-       if (xenv_flags && (*xenv_flags & XENV_CAP_KEYS))
-               evt_mask |= KeyPressMask | KeyReleaseMask;
-       if (xenv_flags && (*xenv_flags & XENV_CAP_MOUSE))
-               evt_mask |= ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
-       g_xstuff.pXSelectInput(display, win, evt_mask);
-       g_xstuff.pXMapWindow(display, win);
-       g_xstuff.pXGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
-       g_xstuff.pXkbSetDetectableAutoRepeat(display, 1, NULL);
-       // XSetIOErrorHandler
-
-       // we don't know when event dispatch will be called, so sync now
-       g_xstuff.pXSync(display, False);
-
-       return 0;
-fail2:
-       dlclose(x11lib);
-fail:
-       g_xstuff.display = NULL;
-       fprintf(stderr, "x11 handling disabled.\n");
-       return -1;
-}
-
-static void x11h_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed),
-                       int (*mouseb_cb)(void *cb_arg, int x, int y, int button, int is_pressed),
-                       int (*mousem_cb)(void *cb_arg, int x, int y),
-                       void *cb_arg)
-{
-       XEvent evt;
-       int keysym;
-
-       while (g_xstuff.pXPending(g_xstuff.display))
-       {
-               g_xstuff.pXNextEvent(g_xstuff.display, &evt);
-               switch (evt.type)
-               {
-               case Expose:
-                       while (g_xstuff.pXCheckTypedEvent(g_xstuff.display, Expose, &evt))
-                               ;
-                       break;
-
-               case KeyPress:
-                       keysym = g_xstuff.pXLookupKeysym(&evt.xkey, 0);
-                       if (key_cb != NULL)
-                               key_cb(cb_arg, keysym, 1);
-                       break;
-
-               case KeyRelease:
-                       keysym = g_xstuff.pXLookupKeysym(&evt.xkey, 0);
-                       if (key_cb != NULL)
-                               key_cb(cb_arg, keysym, 0);
-                       break;
-
-               case ButtonPress:
-                       if (mouseb_cb != NULL)
-                               mouseb_cb(cb_arg, evt.xbutton.x, evt.xbutton.y,
-                                         evt.xbutton.button, 1);
-                       break;
-
-               case ButtonRelease:
-                       if (mouseb_cb != NULL)
-                               mouseb_cb(cb_arg, evt.xbutton.x, evt.xbutton.y,
-                                         evt.xbutton.button, 0);
-                       break;
-
-               case MotionNotify:
-                       if (mousem_cb != NULL)
-                               mousem_cb(cb_arg, evt.xmotion.x, evt.xmotion.y);
-                       break;
-               }
-       }
-}
-
-static void x11h_wait_vmstate(void)
-{
-       Atom wm_state = g_xstuff.pXInternAtom(g_xstuff.display, "WM_STATE", False);
-       XEvent evt;
-       int i;
-
-       usleep(20000);
-
-       for (i = 0; i < 20; i++) {
-               while (g_xstuff.pXPending(g_xstuff.display)) {
-                       g_xstuff.pXNextEvent(g_xstuff.display, &evt);
-                       // printf("w event %d\n", evt.type);
-                       if (evt.type == PropertyNotify && evt.xproperty.atom == wm_state)
-                               return;
-               }
-               usleep(200000);
-       }
-
-       fprintf(stderr, PFX "timeout waiting for wm_state change\n");
-}
-
-static int x11h_minimize(void)
-{
-       XSetWindowAttributes attributes;
-       Display *display = g_xstuff.display;
-       Window window = g_xstuff.window;
-       int screen = DefaultScreen(g_xstuff.display);
-       int display_width, display_height;
-       XWMHints wm_hints;
-       XEvent evt;
-
-       g_xstuff.pXWithdrawWindow(display, window, screen);
-
-       attributes.override_redirect = False;
-       g_xstuff.pXChangeWindowAttributes(display, window,
-               CWOverrideRedirect, &attributes);
-
-       wm_hints.flags = StateHint;
-       wm_hints.initial_state = IconicState;
-       g_xstuff.pXSetWMHints(display, window, &wm_hints);
-
-       g_xstuff.pXMapWindow(display, window);
-
-       while (g_xstuff.pXNextEvent(display, &evt) == 0)
-       {
-               // printf("m event %d\n", evt.type);
-               switch (evt.type)
-               {
-                       case FocusIn:
-                               goto out;
-                       default:
-                               break;
-               }
-       }
-
-out:
-       g_xstuff.pXWithdrawWindow(display, window, screen);
-
-       // must wait for some magic vmstate property change before setting override_redirect
-       x11h_wait_vmstate();
-
-       attributes.override_redirect = True;
-       g_xstuff.pXChangeWindowAttributes(display, window,
-               CWOverrideRedirect, &attributes);
-
-       // fixup window after resize on override_redirect loss
-       display_width = DisplayWidth(display, screen);
-       display_height = DisplayHeight(display, screen);
-       g_xstuff.pXMoveResizeWindow(display, window, 0, 0, display_width, display_height);
-
-       g_xstuff.pXMapWindow(display, window);
-       g_xstuff.pXGrabKeyboard(display, window, False, GrabModeAsync, GrabModeAsync, CurrentTime);
-       g_xstuff.pXkbSetDetectableAutoRepeat(display, 1, NULL);
-
-       // we don't know when event dispatch will be called, so sync now
-       g_xstuff.pXSync(display, False);
-
-       return 0;
-}
-
-static struct termios g_kbd_termios_saved;
-static int g_kbdfd = -1;
-
-static int tty_init(void)
-{
-       struct termios kbd_termios;
-       int mode;
-
-       g_kbdfd = open("/dev/tty", O_RDWR);
-       if (g_kbdfd == -1) {
-               perror(PFX "open /dev/tty");
-               return -1;
-       }
-
-       if (ioctl(g_kbdfd, KDGETMODE, &mode) == -1) {
-               perror(PFX "(not hiding FB): KDGETMODE");
-               goto fail;
-       }
-
-       if (tcgetattr(g_kbdfd, &kbd_termios) == -1) {
-               perror(PFX "tcgetattr");
-               goto fail;
-       }
-
-       g_kbd_termios_saved = kbd_termios;
-       kbd_termios.c_lflag &= ~(ICANON | ECHO); // | ISIG);
-       kbd_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
-       kbd_termios.c_cc[VMIN] = 0;
-       kbd_termios.c_cc[VTIME] = 0;
-
-       if (tcsetattr(g_kbdfd, TCSAFLUSH, &kbd_termios) == -1) {
-               perror(PFX "tcsetattr");
-               goto fail;
-       }
-
-       if (ioctl(g_kbdfd, KDSETMODE, KD_GRAPHICS) == -1) {
-               perror(PFX "KDSETMODE KD_GRAPHICS");
-               tcsetattr(g_kbdfd, TCSAFLUSH, &g_kbd_termios_saved);
-               goto fail;
-       }
-
-       return 0;
-
-fail:
-       close(g_kbdfd);
-       g_kbdfd = -1;
-       return -1;
-}
-
-static void tty_end(void)
-{
-       if (g_kbdfd < 0)
-               return;
-
-       if (ioctl(g_kbdfd, KDSETMODE, KD_TEXT) == -1)
-               perror(PFX "KDSETMODE KD_TEXT");
-
-       if (tcsetattr(g_kbdfd, TCSAFLUSH, &g_kbd_termios_saved) == -1)
-               perror(PFX "tcsetattr");
-
-       close(g_kbdfd);
-       g_kbdfd = -1;
-}
-
-int xenv_init(int *xenv_flags, const char *window_title)
-{
-       int ret;
-
-       ret = x11h_init(xenv_flags, window_title);
-       if (ret == 0)
-               goto out;
-
-       if (xenv_flags != NULL)
-               *xenv_flags &= ~(XENV_CAP_KEYS | XENV_CAP_MOUSE); /* TODO? */
-       ret = tty_init();
-       if (ret == 0)
-               goto out;
-
-       fprintf(stderr, PFX "error: both x11h_init and tty_init failed\n");
-       ret = -1;
-out:
-       return ret;
-}
-
-int xenv_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed),
-               int (*mouseb_cb)(void *cb_arg, int x, int y, int button, int is_pressed),
-               int (*mousem_cb)(void *cb_arg, int x, int y),
-               void *cb_arg)
-{
-       if (g_xstuff.display) {
-               x11h_update(key_cb, mouseb_cb, mousem_cb, cb_arg);
-               return 0;
-       }
-
-       // TODO: read tty?
-       return -1;
-}
-
-/* blocking minimize until user maximizes again */
-int xenv_minimize(void)
-{
-       int ret;
-
-       if (g_xstuff.display) {
-               xenv_update(NULL, NULL, NULL, NULL);
-               ret = x11h_minimize();
-               xenv_update(NULL, NULL, NULL, NULL);
-               return ret;
-       }
-
-       return -1;
-}
-
-void xenv_finish(void)
-{
-       // TODO: cleanup X?
-       tty_end();
-}
-
-#if 0
-int main()
-{
-       int i, r, d;
-
-       xenv_init("just a test");
-
-       for (i = 0; i < 5; i++) {
-               while ((r = xenv_update(&d)) > 0)
-                       printf("%d %x %d\n", d, r, r);
-               sleep(1);
-
-               if (i == 1)
-                       xenv_minimize();
-               printf("ll %d\n", i);
-       }
-
-       printf("xenv_finish..\n");
-       xenv_finish();
-
-       return 0;
-}
-#endif
diff --git a/platform/linux/xenv.h b/platform/linux/xenv.h
deleted file mode 100644 (file)
index 6abda19..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-
-#define XENV_CAP_KEYS  (1<<0)
-#define XENV_CAP_MOUSE (1<<1)
-
-/* xenv_flags specify if we need keys and mouse,
- * on return, flag is removed if input is not available */
-int  xenv_init(int *xenv_flags, const char *window_title);
-
-/* read events from X, calling key_cb for key, mouseb_cb for mouse button
- * and mousem_cb for mouse motion events */
-int  xenv_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed),
-                int (*mouseb_cb)(void *cb_arg, int x, int y, int button, int is_pressed),
-                int (*mousem_cb)(void *cb_arg, int x, int y),
-                void *cb_arg);
-
-int  xenv_minimize(void);
-void xenv_finish(void);
-
diff --git a/platform/win32/direct.cpp b/platform/win32/direct.cpp
deleted file mode 100644 (file)
index 033f87c..0000000
+++ /dev/null
@@ -1,410 +0,0 @@
-// ddraw\r
-#include <ddraw.h>\r
-#include "../common/lprintf.h"\r
-#include "direct.h"\r
-#include "main.h"\r
-\r
-#define EmuWidth 320\r
-#define EmuHeight 240\r
-\r
-#define RELEASE(x) if (x) x->Release();  x=NULL;\r
-#define LOGFAIL() lprintf("fail: %s %s:%i\n", __FUNCTION__, __FILE__, __LINE__)\r
-\r
-static LPDIRECTDRAW7        m_pDD = NULL;\r
-static LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer = NULL;\r
-static LPDIRECTDRAWSURFACE7 m_pddsBackBuffer = NULL;\r
-\r
-// quick and dirty stuff..\r
-void DirectExit(void)\r
-{\r
-  RELEASE(m_pddsBackBuffer);\r
-  RELEASE(m_pddsFrontBuffer);\r
-  RELEASE(m_pDD);\r
-}\r
-\r
-int DirectInit(void)\r
-{\r
-  HRESULT ret;\r
-  LPDIRECTDRAWCLIPPER pcClipper = NULL;\r
-  DDSURFACEDESC2 ddsd;\r
-\r
-  ret = DirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL);\r
-  if (ret) { LOGFAIL(); return 1; }\r
-\r
-  // Set cooperative level\r
-  ret = m_pDD->SetCooperativeLevel( FrameWnd, DDSCL_NORMAL );\r
-  if (ret) { LOGFAIL(); goto fail; }\r
-\r
-  // Create the primary surface\r
-  ZeroMemory( &ddsd, sizeof( ddsd ) );\r
-  ddsd.dwSize         = sizeof( ddsd );\r
-  ddsd.dwFlags        = DDSD_CAPS;\r
-  ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;\r
-\r
-  ret = m_pDD->CreateSurface( &ddsd, &m_pddsFrontBuffer, NULL );\r
-  if (ret) { LOGFAIL(); goto fail; }\r
-\r
-  // Create the backbuffer surface\r
-  ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;\r
-  ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;\r
-  ddsd.dwWidth        = EmuWidth;\r
-  ddsd.dwHeight       = EmuHeight;\r
-\r
-  ret = m_pDD->CreateSurface( &ddsd, &m_pddsBackBuffer, NULL );\r
-  if (ret) { LOGFAIL(); goto fail; }\r
-\r
-  // clipper\r
-  ret = m_pDD->CreateClipper( 0, &pcClipper, NULL );\r
-  if (ret) { LOGFAIL(); goto fail; }\r
-\r
-  ret = pcClipper->SetHWnd( 0, FrameWnd );\r
-  if (ret) { LOGFAIL(); goto fail; }\r
-\r
-  ret = m_pddsFrontBuffer->SetClipper( pcClipper );\r
-  if (ret) { LOGFAIL(); goto fail; }\r
-\r
-  RELEASE(pcClipper);\r
-  return 0;\r
-\r
-fail:\r
-  RELEASE(pcClipper);\r
-  DirectExit();\r
-  return 1;\r
-}\r
-\r
-int DirectScreen(const void *emu_screen)\r
-{\r
-  const unsigned short *ps = (const unsigned short *)emu_screen;\r
-  DDSURFACEDESC2 sd;\r
-  int ret, x, y;\r
-\r
-  memset(&sd, 0, sizeof(sd));\r
-  sd.dwSize = sizeof(sd);\r
-  ret = m_pddsBackBuffer->Lock(NULL, &sd, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL);\r
-  if (ret) { LOGFAIL(); return 1; }\r
-\r
-  //lprintf("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount);\r
-\r
-  if (sd.ddpfPixelFormat.dwRGBBitCount == 32)\r
-  {\r
-    int *dst = (int *)sd.lpSurface;\r
-    for (y = 0; y < EmuHeight; y++)\r
-    {\r
-      for (x = 0; x < EmuWidth; x++)\r
-      {\r
-        int s = *ps++;\r
-        dst[x] = ((s&0xf800)<<8) | ((s&0x07e0)<<5) | ((s&0x001f)<<3);\r
-      }\r
-      dst = (int *)((char *)dst + sd.lPitch);\r
-    }\r
-  }\r
-  else if (sd.ddpfPixelFormat.dwRGBBitCount == 24) /* wine uses this for me */\r
-  {\r
-    void *dst = sd.lpSurface;\r
-    for (y = 0; y < EmuHeight; y++)\r
-    {\r
-      unsigned char *dst1 = (unsigned char *) dst;\r
-      for (x = 0; x < EmuWidth; x++, dst1 += 3)\r
-      {\r
-        int s = *ps++;\r
-       dst1[2] = (s&0xf800)>>8; dst1[1] = (s&0x07e0)>>3; dst1[0] = s<<3; // BGR\r
-      }\r
-      dst = (void *)((char *)dst + sd.lPitch);\r
-    }\r
-  }\r
-  else if (sd.ddpfPixelFormat.dwRGBBitCount == 16)\r
-  {\r
-    unsigned short *dst = (unsigned short *)sd.lpSurface;\r
-    for (y = 0; y < EmuHeight; y++)\r
-    {\r
-      memcpy(dst, ps, EmuWidth*2);\r
-      ps += EmuWidth;\r
-      dst = (unsigned short *)((char *)dst + sd.lPitch);\r
-    }\r
-  }\r
-  else\r
-  {\r
-    LOGFAIL();\r
-  }\r
-\r
-  ret = m_pddsBackBuffer->Unlock(NULL);\r
-  if (ret) { LOGFAIL(); return 1; }\r
-  return 0;\r
-}\r
-\r
-int DirectClear(unsigned int colour)\r
-{\r
-  int ret = 0;\r
-  DDBLTFX ddbltfx;\r
-  ZeroMemory( &ddbltfx, sizeof(ddbltfx) );\r
-  ddbltfx.dwSize      = sizeof(ddbltfx);\r
-  ddbltfx.dwFillColor = colour;\r
-\r
-  if (m_pddsBackBuffer != NULL)\r
-    ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );\r
-  if (ret) { LOGFAIL(); return 1; }\r
-  return 0;\r
-}\r
-\r
-int DirectPresent(void)\r
-{\r
-  int ret = 0;\r
-  if (FrameRectMy.right - FrameRectMy.left > 0 && FrameRectMy.bottom - FrameRectMy.top > 0)\r
-    ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, &EmuScreenRect, DDBLT_WAIT, NULL);\r
-  if (ret) { LOGFAIL(); return 1; }\r
-  return 0;\r
-}\r
-\r
-\r
-/* D3D */\r
-#ifdef USE_D3D\r
-static IDirect3D8 *Direct3D=NULL;\r
-IDirect3DDevice8 *Device=NULL;\r
-IDirect3DSurface8 *DirectBack=NULL; // Back Buffer\r
-\r
-static IDirect3DVertexBuffer8 *VertexBuffer=NULL;\r
-\r
-struct CustomVertex\r
-{\r
-  float x,y,z; // Vertex cordinates\r
-  unsigned int colour;\r
-  float u,v; // Texture coordinates\r
-};\r
-#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)\r
-\r
-static CustomVertex VertexList[4];\r
-\r
-int DirectInit()\r
-{\r
-  D3DPRESENT_PARAMETERS d3dpp;\r
-  D3DDISPLAYMODE mode;\r
-  int i,u,ret=0;\r
-\r
-  memset(&d3dpp,0,sizeof(d3dpp));\r
-  memset(&mode,0,sizeof(mode));\r
-\r
-  Direct3D=Direct3DCreate8(D3D_SDK_VERSION); if (Direct3D==NULL) return 1;\r
-\r
-  // Set up the structure used to create the D3D device:\r
-  d3dpp.BackBufferWidth =MainWidth;\r
-  d3dpp.BackBufferHeight=MainHeight;\r
-  d3dpp.BackBufferCount =1;\r
-  d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;\r
-  d3dpp.MultiSampleType =D3DMULTISAMPLE_NONE;\r
-\r
-#ifdef _XBOX\r
-  d3dpp.BackBufferFormat=D3DFMT_X8R8G8B8;\r
-  d3dpp.FullScreen_RefreshRateInHz=60;\r
-#else\r
-  Direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&mode);\r
-  d3dpp.BackBufferFormat=mode.Format;\r
-  d3dpp.Windowed=1;\r
-  d3dpp.hDeviceWindow=FrameWnd;\r
-#endif\r
-\r
-  // Try to create a device with hardware vertex processing:\r
-  for (i=0;i<3;i++)\r
-  {\r
-    int behave=D3DCREATE_HARDWARE_VERTEXPROCESSING;\r
-\r
-    // Try software vertex processing:\r
-    if (i==1) behave=D3DCREATE_MIXED_VERTEXPROCESSING;\r
-    if (i==2) behave=D3DCREATE_SOFTWARE_VERTEXPROCESSING;\r
-\r
-    Direct3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,FrameWnd,\r
-        behave|D3DCREATE_MULTITHREADED,&d3dpp,&Device);\r
-    if (Device) break;\r
-  }\r
-\r
-  if (Device==NULL)\r
-  {\r
-#if 0\r
-    // try ref\r
-    Direct3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF,FrameWnd,\r
-        D3DCREATE_SOFTWARE_VERTEXPROCESSING|D3DCREATE_MULTITHREADED,&d3dpp,&Device);\r
-    if (Device==NULL) goto fail0;\r
-    HMODULE test = LoadLibrary("d3d8d.dll");\r
-    if (test != NULL) FreeLibrary(test);\r
-    else {\r
-      error("Sorry, but this program requires Direct3D with hardware acceleration.\n\n"\r
-            "You can try using Direct3D software emulation, but you have to install "\r
-            "DirectX SDK for it to work\n(it seems to be missing now).");\r
-      goto fail1;\r
-    }\r
-#else\r
-    goto fail1;\r
-#endif\r
-  }\r
-\r
-  Device->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&DirectBack);\r
-  if (DirectBack==NULL) goto fail1;\r
-\r
-  Device->CreateVertexBuffer(sizeof(VertexList),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBuffer);\r
-  if (VertexBuffer==NULL) goto fail2;\r
-\r
-  ret=TexScreenInit(); if (ret) goto fail3;\r
-\r
-  //FontInit();\r
-\r
-  Device->SetRenderState(D3DRS_LIGHTING,0); // Turn off lighting\r
-\r
-  // Set up texture modes:\r
-  Device->SetTextureStageState(0,D3DTSS_ADDRESSU,D3DTADDRESS_CLAMP);\r
-  Device->SetTextureStageState(0,D3DTSS_ADDRESSV,D3DTADDRESS_CLAMP);\r
-\r
-  return 0;\r
-\r
-fail3:\r
-  RELEASE(VertexBuffer)\r
-fail2:\r
-  RELEASE(DirectBack)\r
-fail1:\r
-  RELEASE(Device)\r
-fail0:\r
-  RELEASE(Direct3D)\r
-\r
-  return 1;\r
-}\r
-\r
-void DirectExit()\r
-{\r
-  TexScreenExit();\r
-\r
-  // d3d\r
-  RELEASE(VertexBuffer)\r
-  RELEASE(DirectBack)\r
-  RELEASE(Device)\r
-  RELEASE(Direct3D)\r
-}\r
-\r
-int DirectClear(unsigned int colour)\r
-{\r
-  if (Device != NULL) {\r
-    Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0);\r
-    return 0;\r
-  }\r
-\r
-  return 1;\r
-}\r
-\r
-int DirectPresent()\r
-{\r
-  if (Device != NULL) {\r
-    Device->Present(NULL,NULL,NULL,NULL);\r
-    return 0;\r
-  }\r
-\r
-  return 1;\r
-}\r
-\r
-#define PI 3.14159265f\r
-\r
-static int MakeVertexList()\r
-{\r
-  struct CustomVertex *vert=NULL,*pv=NULL;\r
-  float dist=0.0f;\r
-  float scalex=0.0f,scaley=0.0f;\r
-  unsigned int colour=0xffffff;\r
-  float right=0.0f,bottom=0.0f;\r
-\r
-  if (LoopMode!=8) colour=0x102040;\r
-\r
-  dist=10.0f; scalex=dist*1.3333f; scaley=dist;\r
-\r
-  scalex*=640.0f/(float)MainWidth;\r
-  scaley*=448.0f/(float)MainHeight;\r
-\r
-  vert=VertexList;\r
-\r
-  // Put the vertices for the corners of the screen:\r
-  pv=vert;\r
-  pv->z=dist;\r
-  pv->x=-scalex; pv->y=scaley;\r
-  pv->colour=colour; pv++;\r
-\r
-  *pv=vert[0]; pv->x= scalex; pv->y= scaley; pv++;\r
-  *pv=vert[0]; pv->x=-scalex; pv->y=-scaley; pv++;\r
-  *pv=vert[0]; pv->x= scalex; pv->y=-scaley; pv++;\r
-\r
-  // Find where the screen images ends on the texture\r
-  right =(float)EmuWidth /(float)TexWidth;\r
-  bottom=(float)EmuHeight/(float)TexHeight;\r
-\r
-  // Write texture coordinates:\r
-  pv=vert;\r
-  pv->u=0.0f;  pv->v=0.00f;  pv++;\r
-  pv->u=right; pv->v=0.00f;  pv++;\r
-  pv->u=0.0f;  pv->v=bottom; pv++;\r
-  pv->u=right; pv->v=bottom; pv++;\r
-\r
-  return 0;\r
-}\r
-\r
-static int SetupMatrices()\r
-{\r
-  D3DXVECTOR3 eye ( 0.0f, 0.0f, 0.0f );\r
-  D3DXVECTOR3 look( 0.0f, 0.0f, 0.0f );\r
-  D3DXVECTOR3 up  ( 0.0f, 1.0f, 0.0f );\r
-  D3DXMATRIX mat;\r
-  float nudgex=0.0f,nudgey=0.0f;\r
-\r
-  memset(&mat,0,sizeof(mat));\r
-\r
-  mat.m[0][0]=mat.m[1][1]=mat.m[2][2]=mat.m[3][3]=1.0f;\r
-  Device->SetTransform(D3DTS_WORLD,&mat);\r
-\r
-  look.x=(float)Inp.axis[2]/2457.6f;\r
-  look.y=(float)Inp.axis[3]/2457.6f;\r
-  look.z=10.0f;\r
-\r
-  // Nudge pixels to the centre of each screen pixel:\r
-  nudgex=13.3333f/(float)(MainWidth <<1);\r
-  nudgey=10.0000f/(float)(MainHeight<<1);\r
-  eye.x +=nudgex; eye.y +=nudgey;\r
-  look.x+=nudgex; look.y+=nudgey;\r
-\r
-  D3DXMatrixLookAtLH(&mat,&eye,&look,&up);\r
-  Device->SetTransform(D3DTS_VIEW,&mat);\r
-\r
-  D3DXMatrixPerspectiveFovLH(&mat, 0.5f*PI, 1.3333f, 0.2f, 1000.0f);\r
-  Device->SetTransform(D3DTS_PROJECTION,&mat);\r
-  return 0;\r
-}\r
-\r
-int DirectScreen()\r
-{\r
-  unsigned char *lock=NULL;\r
-  int ret;\r
-\r
-  if (Device == NULL)\r
-    return DirectScreenDDraw();\r
-\r
-  // Copy the screen to the screen texture:\r
-#ifdef _XBOX\r
-  TexScreenSwizzle();\r
-#else\r
-  ret=TexScreenLinear();\r
-  if (ret) lprintf("TexScreenLinear failed\n");\r
-#endif\r
-\r
-  SetupMatrices();\r
-\r
-  MakeVertexList();\r
-\r
-  // Copy vertices in:\r
-  VertexBuffer->Lock(0,sizeof(VertexList),&lock,0);\r
-  if (lock==NULL) { lprintf("VertexBuffer->Lock failed\n"); return 1; }\r
-  memcpy(lock,VertexList,sizeof(VertexList));\r
-  VertexBuffer->Unlock();\r
-\r
-  Device->BeginScene();\r
-  Device->SetTexture(0,TexScreen);\r
-  Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));\r
-  Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);\r
-  Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);\r
-  Device->EndScene();\r
-\r
-  return 0;\r
-}\r
-#endif\r
-\r
diff --git a/platform/win32/direct.h b/platform/win32/direct.h
deleted file mode 100644 (file)
index a064b3f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int  DirectInit(void);
-void DirectExit(void);
-
-int  DirectScreen(const void *emu_screen);
-int  DirectClear(unsigned int colour);
-int  DirectPresent(void);
-
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/platform/win32/dsnd.cpp b/platform/win32/dsnd.cpp
deleted file mode 100644 (file)
index 4e1930e..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-//#pragma warning (disable:4201)\r
-#include <stdlib.h>\r
-#define WIN32_LEAN_AND_MEAN\r
-#include <windows.h>\r
-#include <mmsystem.h>\r
-#include <dsound.h>\r
-\r
-#include "dsnd.h"\r
-#include "../common/lprintf.h"\r
-\r
-#define NSEGS 4\r
-#define RELEASE(x) if (x) x->Release();  x=NULL;\r
-\r
-static LPDIRECTSOUND DSound;\r
-static LPDIRECTSOUNDBUFFER LoopBuffer;\r
-static LPDIRECTSOUNDNOTIFY DSoundNotify;\r
-static HANDLE seg_played_event;\r
-static int LoopLen, LoopWrite, LoopSeg; // bytes\r
-\r
-static int LoopBlank(void)\r
-{\r
-  void *mema=NULL,*memb=NULL;\r
-  DWORD sizea=0,sizeb=0;\r
-\r
-  LoopBuffer->Lock(0, LoopLen, &mema,&sizea, &memb,&sizeb, 0);\r
-  \r
-  if (mema) memset(mema,0,sizea);\r
-\r
-  LoopBuffer->Unlock(mema,sizea, memb,sizeb);\r
-\r
-  return 0;\r
-}\r
-\r
-int DSoundInit(HWND wnd_coop, int rate, int stereo, int seg_samples)\r
-{\r
-  DSBUFFERDESC dsbd;\r
-  WAVEFORMATEX wfx;\r
-  DSBPOSITIONNOTIFY notifies[NSEGS];\r
-  int i;\r
-\r
-  memset(&dsbd,0,sizeof(dsbd));\r
-  memset(&wfx,0,sizeof(wfx));\r
-\r
-  // Make wave format:\r
-  wfx.wFormatTag=WAVE_FORMAT_PCM;\r
-  wfx.nChannels=stereo ? 2 : 1;\r
-  wfx.nSamplesPerSec=rate;\r
-  wfx.wBitsPerSample=16;\r
-\r
-  wfx.nBlockAlign=(WORD)((wfx.nChannels*wfx.wBitsPerSample)>>3);\r
-  wfx.nAvgBytesPerSec=wfx.nBlockAlign*wfx.nSamplesPerSec;\r
-\r
-  // Create the DirectSound interface:\r
-  DirectSoundCreate(NULL,&DSound,NULL);\r
-  if (DSound==NULL) return 1;\r
-\r
-  LoopSeg = seg_samples * 2;\r
-  if (stereo)\r
-    LoopSeg *= 2;\r
-\r
-  LoopLen = LoopSeg * NSEGS;\r
-\r
-  DSound->SetCooperativeLevel(wnd_coop, DSSCL_PRIORITY);\r
-  dsbd.dwFlags=DSBCAPS_GLOBALFOCUS;  // Play in background\r
-  dsbd.dwFlags|=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLPOSITIONNOTIFY;\r
-\r
-  // Create the looping buffer:\r
-  dsbd.dwSize=sizeof(dsbd);\r
-  dsbd.dwBufferBytes=LoopLen;\r
-  dsbd.lpwfxFormat=&wfx;\r
-\r
-  DSound->CreateSoundBuffer(&dsbd,&LoopBuffer,NULL);\r
-  if (LoopBuffer==NULL) return 1;\r
-\r
-  LoopBuffer->QueryInterface(IID_IDirectSoundNotify, (LPVOID*)&DSoundNotify);\r
-  if (DSoundNotify == NULL) {\r
-    lprintf("QueryInterface(IID_IDirectSoundNotify) failed\n");\r
-    goto out;\r
-  }\r
-\r
-  seg_played_event = CreateEvent(NULL, 0, 0, NULL);\r
-  if (seg_played_event == NULL)\r
-    goto out;\r
-\r
-  for (i = 0; i < NSEGS; i++) {\r
-    notifies[i].dwOffset = i * LoopSeg;\r
-    notifies[i].hEventNotify = seg_played_event;\r
-  }\r
-  i = DSoundNotify->SetNotificationPositions(NSEGS, notifies);\r
-  if (i != DS_OK) {\r
-    lprintf("SetNotificationPositions failed\n");\r
-    goto out;\r
-  }\r
-\r
-out:\r
-  LoopBlank();\r
-  LoopBuffer->Play(0, 0, DSBPLAY_LOOPING);\r
-  return 0;\r
-}\r
-\r
-void DSoundExit(void)\r
-{\r
-  if (LoopBuffer)\r
-    LoopBuffer->Stop();\r
-  RELEASE(DSoundNotify);\r
-  RELEASE(LoopBuffer)\r
-  RELEASE(DSound)\r
-  CloseHandle(seg_played_event);\r
-  seg_played_event = NULL;\r
-}\r
-\r
-static int WriteSeg(const void *buff)\r
-{\r
-  void *mema=NULL,*memb=NULL;\r
-  DWORD sizea=0,sizeb=0;\r
-  int ret;\r
-\r
-  // Lock the segment at 'LoopWrite' and copy the next segment in\r
-  ret = LoopBuffer->Lock(LoopWrite, LoopSeg, &mema, &sizea, &memb, &sizeb, 0);\r
-  if (ret != DS_OK)\r
-    lprintf("LoopBuffer->Lock() failed: %i\n", ret);\r
-\r
-  if (mema) memcpy(mema,buff,sizea);\r
-//  if (memb) memcpy(memb,DSoundNext+sizea,sizeb);\r
-  if (sizeb != 0) lprintf("sizeb is not 0! (%i)\n", sizeb);\r
-\r
-  ret = LoopBuffer->Unlock(mema,sizea, memb, sizeb);\r
-  if (ret != DS_OK)\r
-    lprintf("LoopBuffer->Unlock() failed: %i\n", ret);\r
-\r
-  return 0;\r
-}\r
-\r
-int DSoundUpdate(const void *buff, int blocking)\r
-{\r
-  DWORD play = 0;\r
-  int pos;\r
-\r
-  LoopBuffer->GetCurrentPosition(&play, NULL);\r
-  pos = play;\r
-\r
-  // 'LoopWrite' is the next seg in the loop that we want to write\r
-  // First check that the sound 'play' pointer has moved out of it:\r
-  if (blocking) {\r
-    while (LoopWrite <= pos && pos < LoopWrite + LoopSeg) {\r
-      WaitForSingleObject(seg_played_event, 5000);\r
-      LoopBuffer->GetCurrentPosition(&play, NULL);\r
-      pos = play;\r
-    }\r
-  }\r
-  else {\r
-    if (LoopWrite <= pos && pos < LoopWrite + LoopSeg)\r
-      return 1;\r
-  }\r
-\r
-  WriteSeg(buff);\r
-\r
-  // Advance LoopWrite to next seg:\r
-  LoopWrite += LoopSeg;\r
-  if (LoopWrite + LoopSeg > LoopLen)\r
-    LoopWrite = 0;\r
-\r
-  return 0;\r
-}\r
-\r
diff --git a/platform/win32/dsnd.h b/platform/win32/dsnd.h
deleted file mode 100644 (file)
index 9132bcb..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int  DSoundInit(HWND wnd_coop, int rate, int stereo, int seg_samples);
-void DSoundExit(void);
-int  DSoundUpdate(const void *buff, int blocking);
-
-extern short *DSoundNext;
-
-#ifdef __cplusplus
-}
-#endif
-