#endif\r
 \r
 \r
-static u32 PicoCheckPc(u32 pc)\r
+PICO_INTERNAL u32 PicoCheckPc(u32 pc)\r
 {\r
   u32 ret=0;\r
 #if defined(EMU_C68K)\r
 
 extern int  (*PicoMCDcloseTray)(void);\r
 extern int PicoCDBuffers;\r
 \r
+// Pico/Pico.c\r
+extern int PicoPicoPenPos[2]; // x: 0x03c-0x17d, y: 0x200-0x2d8\r
+extern int PicoPicoPage;\r
+\r
 // Area.c\r
 typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file);\r
 typedef size_t (areaeof)(void *file);\r
 
     goto end;
   }
 
-  elprintf(EL_UIO, "r8 : %06x,   %02x @%06x", a&0xffffff, (u8)d, SekPc);
+  if ((a&0xffffe0)==0x800000) // Pico I/O
+  {
+    switch (a & 0x1f)
+    {
+      case 0x03:
+        d  =  PicoPad[0]&0x0f; // d-pad
+        d |= (PicoPad[0]&0x20) >> 1; // red button -> C
+        d |= (PicoPad[0]&0x40) << 1; // pen tap -> A
+        d  = ~d;
+        break;
+
+      case 0x05: d = (PicoPicoPenPos[0] >> 8) & 3; break; // what is MS bit for? Games read it..
+      case 0x07: d =  PicoPicoPenPos[0] & 0xff;    break;
+      case 0x09: d = (PicoPicoPenPos[1] >> 8) & 3; break;
+      case 0x0b: d =  PicoPicoPenPos[1] & 0xff;    break;
+      case 0x0d: d = (1 << (PicoPicoPage & 7)) - 1;break;
+      case 0x12: d = 0x80; break;
+      default:
+        elprintf(EL_UIO, "r8 : %06x,   %02x @%06x", a&0xffffff, (u8)d, SekPc);
+        break;
+    }
+  }
+
+//  elprintf(EL_UIO, "r8 : %06x,   %02x @%06x", a&0xffffff, (u8)d, SekPc);
 
 end:
   elprintf(EL_IO, "r8 : %06x,   %02x @%06x", a&0xffffff, (u8)d, SekPc);
     goto end;
   }
 
-  elprintf(EL_UIO, "r16: %06x, %04x  @%06x", a&0xffffff, d, SekPc);
+  if (a == 0x800010) d = 0x0f;
+
+  elprintf(EL_UIO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
 
 end:
-  elprintf(EL_IO, "r16: %06x, %04x  @%06x", a&0xffffff, d, SekPc);
+  elprintf(EL_IO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc);
   return d;
 }
 
 // -----------------------------------------------------------------
 //                            Write Ram
 
+void dump(u16 w)
+{
+  FILE *f = fopen("dump.bin", "a");
+  fwrite(&w, 1, 2, f);
+  fclose(f);
+}
+
+
 static void PicoWritePico8(u32 a,u8 d)
 {
   elprintf(EL_IO, "w8 : %06x,   %02x @%06x", a&0xffffff, d, SekPc);
   a&=0xfffffe;
   if ((a&0xffffe0)==0xc00000) { PicoVideoWrite(a,(u16)d); return; } // VDP
 
+//  if (a == 0x800010) dump(d);
+
   elprintf(EL_UIO, "w16: %06x, %04x", a&0xffffff, d);
 }
 
 
 PICO_INTERNAL void PicoMemSetupPico(void)
 {
+#ifdef EMU_C68K
+  PicoCpuCM68k.checkpc=PicoCheckPc;
+  PicoCpuCM68k.fetch8 =PicoCpuCM68k.read8 =PicoReadPico8;
+  PicoCpuCM68k.fetch16=PicoCpuCM68k.read16=PicoReadPico16;
+  PicoCpuCM68k.fetch32=PicoCpuCM68k.read32=PicoReadPico32;
+  PicoCpuCM68k.write8 =PicoWritePico8;
+  PicoCpuCM68k.write16=PicoWritePico16;
+  PicoCpuCM68k.write32=PicoWritePico32;
+#endif
 #ifdef EMU_M68K
   pm68k_read_memory_8  = PicoReadPico8;
   pm68k_read_memory_16 = PicoReadPico16;
 
 #include "../PicoInt.h"
 
+// x: 0x03c - 0x19d
+// y: 0x1fc - 0x2f7
+//    0x2f8 - 0x3f3
+int PicoPicoPenPos[2] = { 0x3c, 0x200 };
+int PicoPicoPage = 0; // 0-6
+
 PICO_INTERNAL int PicoInitPico(void)
 {
   elprintf(EL_STATUS, "Pico detected");
   PicoAHW = PAHW_PICO;
+  PicoPicoPage = 0;
 
   return 0;
 }
 
 \r
 // Memory.c\r
 PICO_INTERNAL int PicoInitPc(unsigned int pc);\r
+PICO_INTERNAL unsigned int PicoCheckPc(unsigned int pc);\r
 PICO_INTERNAL_ASM unsigned int PicoRead32(unsigned int a);\r
 PICO_INTERNAL void PicoMemSetup(void);\r
 PICO_INTERNAL_ASM void PicoMemReset(void);\r
 
 unsigned char *PicoDraw2FB = NULL;  // temporary buffer for alt renderer\r
 int reset_timing = 0;\r
 \r
+static int pico_pen_x = 0, pico_pen_y = 0, pico_inp_mode = 0;\r
+\r
 static void emu_msg_cb(const char *msg);\r
 static void emu_msg_tray_open(void);\r
 \r
        gettimeofday(¬iceMsgTime, 0);\r
 }\r
 \r
+static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
+{\r
+       if (events & (1 << 3)) {\r
+               pico_inp_mode++;\r
+               if (pico_inp_mode > 2) pico_inp_mode = 0;\r
+               switch (pico_inp_mode) {\r
+                       case 0: strcpy(noticeMsg, "Input: Joytick         "); break;\r
+                       case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break;\r
+                       case 2: strcpy(noticeMsg, "Input: Pen on Pad      "); break;\r
+               }\r
+               gettimeofday(¬iceMsgTime, 0);\r
+       }\r
+       if (events & (1 << 4)) {\r
+               PicoPicoPage--;\r
+               if (PicoPicoPage < 0) PicoPicoPage = 0;\r
+               sprintf(noticeMsg, "Page %i                 ", PicoPicoPage);\r
+               gettimeofday(¬iceMsgTime, 0);\r
+       }\r
+       if (events & (1 << 5)) {\r
+               PicoPicoPage++;\r
+               if (PicoPicoPage > 6) PicoPicoPage = 6;\r
+               sprintf(noticeMsg, "Page %i                 ", PicoPicoPage);\r
+               gettimeofday(¬iceMsgTime, 0);\r
+       }\r
+       if (pico_inp_mode != 0) {\r
+               PicoPad[0] &= ~0x0f; // release UDLR\r
+               if (gp2x_keys & GP2X_UP)   { pico_pen_y--; if (pico_pen_y <   0) pico_pen_y =   0; }\r
+               if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 251) pico_pen_y = 251; }\r
+               if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x <   0) pico_pen_x =   0; }\r
+               if (gp2x_keys & GP2X_RIGHT){ pico_pen_x++; if (pico_pen_x > 353) pico_pen_x = 353; }\r
+               PicoPicoPenPos[0] = 0x03c + pico_pen_x;\r
+               PicoPicoPenPos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
+       }\r
+}\r
+\r
 static void update_volume(int has_changed, int is_up)\r
 {\r
        static int prev_frame = 0, wait_frames = 0;\r
 \r
 static void updateKeys(void)\r
 {\r
-       unsigned long keys, allActions[2] = { 0, 0 }, events;\r
-       static unsigned long prevEvents = 0;\r
+       unsigned int keys, keys2, allActions[2] = { 0, 0 }, events;\r
+       static unsigned int prevEvents = 0;\r
        int joy, i;\r
 \r
        keys = gp2x_joystick_read(0);\r
        }\r
 \r
        keys &= CONFIGURABLE_KEYS;\r
+       keys2 = keys;\r
 \r
        for (i = 0; i < 32; i++)\r
        {\r
-               if (keys & (1 << i))\r
+               if (keys2 & (1 << i))\r
                {\r
                        int pl, acts = currentConfig.KeyBinds[i];\r
                        if (!acts) continue;\r
                                // let's try to find the other one\r
                                if (acts_c) {\r
                                        for (; u < 32; u++)\r
-                                               if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
+                                               if ( (keys2 & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
                                                        allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
-                                                       keys &= ~((1 << i) | (1 << u));\r
+                                                       keys2 &= ~((1 << i) | (1 << u));\r
                                                        break;\r
                                                }\r
                                }\r
        {\r
                gp2x_usbjoy_update();\r
                for (joy = 0; joy < num_of_joys; joy++) {\r
-                       int keys = gp2x_usbjoy_check2(joy);\r
+                       int btns = gp2x_usbjoy_check2(joy);\r
                        for (i = 0; i < 32; i++) {\r
-                               if (keys & (1 << i)) {\r
+                               if (btns & (1 << i)) {\r
                                        int acts = currentConfig.JoyBinds[joy][i];\r
                                        int pl = (acts >> 16) & 1;\r
                                        allActions[pl] |= acts;\r
                change_fast_forward(events & 0x40);\r
 \r
        events &= ~prevEvents;\r
+\r
+       if (PicoAHW == PAHW_PICO)\r
+               RunEventsPico(events, keys);\r
+\r
        if (events) RunEvents(events);\r
        if (movie_data) emu_updateMovie();\r
 \r
 
                x = 40;\r
        }\r
 \r
-       menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);\r
+       menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 140);\r
 \r
        y = tl_y;\r
        for (i = 0; i < opt_cnt; i++, y+=10)\r
 }\r
 \r
 \r
-// player2_flag, ?, ?, ?, ?, ?, ?, menu\r
+// player2_flag, reserved, ?, ?,\r
+// ?, ?, fast forward, menu\r
 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r
 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
 me_bind_action emuctrl_actions[] =\r
 {\r
-       { "Load State     ", 1<<28 },\r
-       { "Save State     ", 1<<27 },\r
-       { "Prev Save Slot ", 1<<25 },\r
-       { "Next Save Slot ", 1<<24 },\r
-       { "Switch Renderer", 1<<26 },\r
-       { "Volume Down    ", 1<<30 },\r
-       { "Volume Up      ", 1<<29 },\r
-       { "Fast forward   ", 1<<22 },\r
-       { "Enter Menu     ", 1<<23 },\r
-       { NULL,              0     }\r
+       { "Load State       ", 1<<28 },\r
+       { "Save State       ", 1<<27 },\r
+       { "Prev Save Slot   ", 1<<25 },\r
+       { "Next Save Slot   ", 1<<24 },\r
+       { "Switch Renderer  ", 1<<26 },\r
+       { "Volume Down      ", 1<<30 },\r
+       { "Volume Up        ", 1<<29 },\r
+       { "Fast forward     ", 1<<22 },\r
+       { "Enter Menu       ", 1<<23 },\r
+       { "Pico Next page   ", 1<<21 },\r
+       { "Pico Prev page   ", 1<<20 },\r
+       { "Pico Switch input", 1<<19 },\r
+       { NULL,                0     }\r
 };\r
 \r
 static void kc_sel_loop(void)\r