-/**\r
- * All this is mostly based on rlyeh's minimal library.\r
- * Copied here to review all his code and understand what's going on.\r
-**/\r
-\r
-/*\r
-\r
- GP2X minimal library v0.A by rlyeh, (c) 2005. emulnation.info@rlyeh (swap it!)\r
-\r
- Thanks to Squidge, Robster, snaff, Reesy and NK, for the help & previous work! :-)\r
-\r
- License\r
- =======\r
-\r
- Free for non-commercial projects (it would be nice receiving a mail from you).\r
- Other cases, ask me first.\r
-\r
- GamePark Holdings is not allowed to use this library and/or use parts from it.\r
-\r
-*/\r
-\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-#include <string.h>\r
-#include <unistd.h>\r
-#include <sys/mman.h>\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#include <fcntl.h>\r
-#include <errno.h>\r
-\r
-#include "gp2x.h"\r
-#include "../linux/sndout_oss.h"\r
-#include "../common/arm_utils.h"\r
-#include "../common/arm_linux.h"\r
-#include "../common/emu.h"\r
-\r
-volatile unsigned short *gp2x_memregs;\r
-//static\r
-volatile unsigned long *gp2x_memregl;\r
-static void *gp2x_screens[4];\r
-static int screensel = 0;\r
-//static\r
-int memdev = 0;\r
-static int touchdev = -1;\r
-static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };\r
-\r
-#define FRAMEBUFF_WHOLESIZE (0x30000*4) // 320*240*2 + some more\r
-#define FRAMEBUFF_ADDR0 (0x4000000-FRAMEBUFF_WHOLESIZE)\r
-#define FRAMEBUFF_ADDR1 (FRAMEBUFF_ADDR0+0x30000)\r
-#define FRAMEBUFF_ADDR2 (FRAMEBUFF_ADDR1+0x30000)\r
-#define FRAMEBUFF_ADDR3 (FRAMEBUFF_ADDR2+0x30000)\r
-\r
-static const int gp2x_screenaddrs[4] = { FRAMEBUFF_ADDR0, FRAMEBUFF_ADDR1, FRAMEBUFF_ADDR2, FRAMEBUFF_ADDR3 };\r
-static int gp2x_screenaddrs_use[4];\r
-static unsigned short gp2x_screenaddr_old[4];\r
-\r
-\r
-/* video stuff */\r
-void gp2x_video_flip(void)\r
-{\r
- unsigned short lsw = (unsigned short) gp2x_screenaddrs_use[screensel&3];\r
- unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&3] >> 16);\r
-\r
- gp2x_memregs[0x2910>>1] = msw;\r
- gp2x_memregs[0x2914>>1] = msw;\r
- gp2x_memregs[0x290E>>1] = lsw;\r
- gp2x_memregs[0x2912>>1] = lsw;\r
-\r
- // jump to other buffer:\r
- g_screen_ptr = gp2x_screens[++screensel&3];\r
-}\r
-\r
-/* doulblebuffered flip */\r
-void gp2x_video_flip2(void)\r
-{\r
- unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&1] >> 16);\r
-\r
- gp2x_memregs[0x2910>>1] = msw;\r
- gp2x_memregs[0x2914>>1] = msw;\r
- gp2x_memregs[0x290E>>1] = 0;\r
- gp2x_memregs[0x2912>>1] = 0;\r
-\r
- // jump to other buffer:\r
- g_screen_ptr = gp2x_screens[++screensel&1];\r
-}\r
-\r
-\r
-void gp2x_video_changemode2(int bpp)\r
-{\r
- gp2x_memregs[0x28DA>>1]=(((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/\r
- gp2x_memregs[0x290C>>1]=320*((bpp+1)/8); /*line width in bytes*/\r
-}\r
-\r
-\r
-void gp2x_video_changemode(int bpp)\r
-{\r
- gp2x_video_changemode2(bpp);\r
-\r
- gp2x_memset_all_buffers(0, 0, 320*240*2);\r
- gp2x_video_flip();\r
-}\r
-\r
-\r
-void gp2x_video_setpalette(int *pal, int len)\r
-{\r
- unsigned short *g=(unsigned short *)pal;\r
- volatile unsigned short *memreg = &gp2x_memregs[0x295A>>1];\r
- gp2x_memregs[0x2958>>1] = 0;\r
-\r
- len *= 2;\r
- while(len--) *memreg=*g++;\r
-}\r
-\r
-\r
-// TV Compatible function //\r
-void gp2x_video_RGB_setscaling(int ln_offs, int W, int H)\r
-{\r
- float escalaw, escalah;\r
- int bpp = (gp2x_memregs[0x28DA>>1]>>9)&0x3;\r
- unsigned short scalw;\r
-\r
- // set offset\r
- gp2x_screenaddrs_use[0] = gp2x_screenaddrs[0] + ln_offs * 320 * bpp;\r
- gp2x_screenaddrs_use[1] = gp2x_screenaddrs[1] + ln_offs * 320 * bpp;\r
- gp2x_screenaddrs_use[2] = gp2x_screenaddrs[2] + ln_offs * 320 * bpp;\r
- gp2x_screenaddrs_use[3] = gp2x_screenaddrs[3] + ln_offs * 320 * bpp;\r
-\r
- escalaw = 1024.0; // RGB Horiz LCD\r
- escalah = 320.0; // RGB Vert LCD\r
-\r
- if(gp2x_memregs[0x2800>>1]&0x100) //TV-Out\r
- {\r
- escalaw=489.0; // RGB Horiz TV (PAL, NTSC)\r
- if (gp2x_memregs[0x2818>>1] == 287) //PAL\r
- escalah=274.0; // RGB Vert TV PAL\r
- else if (gp2x_memregs[0x2818>>1] == 239) //NTSC\r
- escalah=331.0; // RGB Vert TV NTSC\r
- }\r
-\r
- // scale horizontal\r
- scalw = (unsigned short)((float)escalaw *(W/320.0));\r
- /* if there is no horizontal scaling, vertical doesn't work. Here is a nasty wrokaround... */\r
- if (H != 240 && W == 320) scalw--;\r
- gp2x_memregs[0x2906>>1]=scalw;\r
- // scale vertical\r
- gp2x_memregl[0x2908>>2]=(unsigned long)((float)escalah *bpp *(H/240.0));\r
-}\r
-\r
-\r
-void gp2x_video_wait_vsync(void)\r
-{\r
- unsigned short v = gp2x_memregs[0x1182>>1];\r
- while (!((v ^ gp2x_memregs[0x1182>>1]) & 0x10)) spend_cycles(1024);\r
-}\r
-\r
-\r
-void gp2x_video_flush_cache(void)\r
-{\r
- // since we are using the mmu hack, we must flush the cache first\r
- cache_flush_d_inval_i(g_screen_ptr, (char *)g_screen_ptr + 320*240*2);\r
-}\r
-\r
-\r
-void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)\r
-{\r
- char *dst;\r
- if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); }\r
- if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); }\r
- if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); }\r
- if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); }\r
-}\r
-\r
-\r
-void gp2x_memcpy_all_buffers(void *data, int offset, int len)\r
-{\r
- gp2x_memcpy_buffers(0xf, data, offset, len);\r
-}\r
-\r
-\r
-void gp2x_memset_all_buffers(int offset, int byte, int len)\r
-{\r
- memset((char *)gp2x_screens[0] + offset, byte, len);\r
- memset((char *)gp2x_screens[1] + offset, byte, len);\r
- memset((char *)gp2x_screens[2] + offset, byte, len);\r
- memset((char *)gp2x_screens[3] + offset, byte, len);\r
-}\r
-\r
-\r
-void gp2x_pd_clone_buffer2(void)\r
-{\r
- memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2);\r
-}\r
-\r
-\r
-typedef struct ucb1x00_ts_event\r
-{\r
- unsigned short pressure;\r
- unsigned short x;\r
- unsigned short y;\r
- unsigned short pad;\r
- struct timeval stamp;\r
-} UCB1X00_TS_EVENT;\r
-\r
-int gp2x_touchpad_read(int *x, int *y)\r
-{\r
- UCB1X00_TS_EVENT event;\r
- static int zero_seen = 0;\r
- int retval;\r
-\r
- if (touchdev < 0) return -1;\r
-\r
- retval = read(touchdev, &event, sizeof(event));\r
- if (retval <= 0) {\r
- printf("touch read failed %i %i\n", retval, errno);\r
- return -1;\r
- }\r
- // this is to ignore the messed-up 4.1.x driver\r
- if (event.pressure == 0) zero_seen = 1;\r
-\r
- if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16;\r
- if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16;\r
- // printf("read %i %i %i\n", event.pressure, *x, *y);\r
-\r
- return zero_seen ? event.pressure : 0;\r
-}\r
-\r
-\r
-/* 940 */\r
-void Pause940(int yes)\r
-{\r
- if(yes)\r
- gp2x_memregs[0x0904>>1] &= 0xFFFE;\r
- else\r
- gp2x_memregs[0x0904>>1] |= 1;\r
-}\r
-\r
-\r
-void Reset940(int yes, int bank)\r
-{\r
- gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03);\r
-}\r
-\r
-static void proc_set(const char *path, const char *val)\r
-{\r
- FILE *f;\r
- char tmp[16];\r
-\r
- f = fopen(path, "w");\r
- if (f == NULL) {\r
- printf("failed to open: %s\n", path);\r
- return;\r
- }\r
-\r
- fprintf(f, "0\n");\r
- fclose(f);\r
-\r
- printf("\"%s\" is set to: ", path);\r
- f = fopen(path, "r");\r
- if (f == NULL) {\r
- printf("(open failed)\n");\r
- return;\r
- }\r
-\r
- fgets(tmp, sizeof(tmp), f);\r
- printf("%s", tmp);\r
- fclose(f);\r
-}\r
-\r
-\r
-/* common */\r
-void gp2x_init(void)\r
-{\r
- printf("entering init()\n"); fflush(stdout);\r
-\r
- memdev = open("/dev/mem", O_RDWR);\r
- if (memdev == -1)\r
- {\r
- perror("open(\"/dev/mem\")");\r
- exit(1);\r
- }\r
-\r
- gp2x_memregs = mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000);\r
- printf("memregs are @ %p\n", gp2x_memregs);\r
- if(gp2x_memregs == MAP_FAILED)\r
- {\r
- perror("mmap(memregs)");\r
- exit(1);\r
- }\r
- gp2x_memregl = (unsigned long *) gp2x_memregs;\r
-\r
- gp2x_memregs[0x2880>>1] &= ~0x383; // disable cursor, subpict, osd, video layers\r
-\r
- gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED, memdev, FRAMEBUFF_ADDR0);\r
- if(gp2x_screens[0] == MAP_FAILED)\r
- {\r
- perror("mmap(g_screen_ptr)");\r
- exit(1);\r
- }\r
- printf("framebuffers point to %p\n", gp2x_screens[0]);\r
- gp2x_screens[1] = (char *) gp2x_screens[0]+0x30000;\r
- gp2x_screens[2] = (char *) gp2x_screens[1]+0x30000;\r
- gp2x_screens[3] = (char *) gp2x_screens[2]+0x30000;\r
-\r
- g_screen_ptr = gp2x_screens[0];\r
- screensel = 0;\r
-\r
- gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1];\r
- gp2x_screenaddr_old[1] = gp2x_memregs[0x2910>>1];\r
- gp2x_screenaddr_old[2] = gp2x_memregs[0x2912>>1];\r
- gp2x_screenaddr_old[3] = gp2x_memregs[0x2914>>1];\r
-\r
- memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs));\r
- gp2x_memset_all_buffers(0, 0, 320*240*2);\r
-\r
- // snd\r
- sndout_oss_init();\r
-\r
- // touchscreen\r
- touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);\r
- if (touchdev >= 0) {\r
- FILE *pcf = fopen("/etc/pointercal", "r");\r
- if (pcf) {\r
- fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1],\r
- &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]);\r
- fclose(pcf);\r
- }\r
- printf("found touchscreen/wm97xx\n");\r
- }\r
-\r
- /* disable Linux read-ahead */\r
- proc_set("/proc/sys/vm/max-readahead", "0\n");\r
- proc_set("/proc/sys/vm/min-readahead", "0\n");\r
-\r
- printf("exitting init()\n"); fflush(stdout);\r
-}\r
-\r
-char *ext_menu = 0, *ext_state = 0;\r
-\r
-void gp2x_deinit(void)\r
-{\r
- Reset940(1, 3);\r
- Pause940(1);\r
-\r
- gp2x_video_changemode(15);\r
- gp2x_memregs[0x290E>>1] = gp2x_screenaddr_old[0];\r
- gp2x_memregs[0x2910>>1] = gp2x_screenaddr_old[1];\r
- gp2x_memregs[0x2912>>1] = gp2x_screenaddr_old[2];\r
- gp2x_memregs[0x2914>>1] = gp2x_screenaddr_old[3];\r
-\r
- munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);\r
- munmap((void *)gp2x_memregs, 0x10000);\r
- close(memdev);\r
- if (touchdev >= 0) close(touchdev);\r
-\r
- sndout_oss_exit();\r
-\r
- printf("all done, running ");\r
-\r
- // Zaq121's alternative frontend support from MAME\r
- if (ext_menu && ext_state) {\r
- printf("%s -state %s\n", ext_menu, ext_state);\r
- execl(ext_menu, ext_menu, "-state", ext_state, NULL);\r
- } else if(ext_menu) {\r
- printf("%s\n", ext_menu);\r
- execl(ext_menu, ext_menu, NULL);\r
- } else {\r
- printf("gp2xmenu\n");\r
- chdir("/usr/gp2x");\r
- execl("gp2xmenu", "gp2xmenu", NULL);\r
- }\r
-}\r
-\r
-/* lprintf */\r
-void lprintf(const char *fmt, ...)\r
-{\r
- va_list vl;\r
-\r
- va_start(vl, fmt);\r
- vprintf(fmt, vl);\r
- va_end(vl);\r
-}\r
-\r
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include "soc.h"
+#include "soc_mmsp2.h"
+#include "gp2x.h"
+#include "../common/emu.h"
+#include "../common/arm_utils.h"
+
+volatile unsigned short *gp2x_memregs;
+volatile unsigned long *gp2x_memregl;
+extern void *gp2x_screens[4];
+static int screensel = 0;
+
+int memdev = 0; /* used by code940 */
+static int touchdev = -1;
+static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };
+
+#define FRAMEBUFF_SIZE 0x30000
+#define FRAMEBUFF_WHOLESIZE (FRAMEBUFF_SIZE*4) // 320*240*2 + some more
+#define FRAMEBUFF_ADDR0 (0x4000000 - FRAMEBUFF_WHOLESIZE)
+#define FRAMEBUFF_ADDR1 (FRAMEBUFF_ADDR0 + FRAMEBUFF_SIZE)
+#define FRAMEBUFF_ADDR2 (FRAMEBUFF_ADDR1 + FRAMEBUFF_SIZE)
+#define FRAMEBUFF_ADDR3 (FRAMEBUFF_ADDR2 + FRAMEBUFF_SIZE)
+
+static const int gp2x_screenaddrs[4] = { FRAMEBUFF_ADDR0, FRAMEBUFF_ADDR1, FRAMEBUFF_ADDR2, FRAMEBUFF_ADDR3 };
+static int gp2x_screenaddrs_use[4];
+static unsigned short gp2x_screenaddr_old[4];
+
+
+/* video stuff */
+void gp2x_video_flip(void)
+{
+ unsigned short lsw = (unsigned short) gp2x_screenaddrs_use[screensel&3];
+ unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&3] >> 16);
+
+ gp2x_memregs[0x2910>>1] = msw;
+ gp2x_memregs[0x2914>>1] = msw;
+ gp2x_memregs[0x290E>>1] = lsw;
+ gp2x_memregs[0x2912>>1] = lsw;
+
+ // jump to other buffer:
+ g_screen_ptr = gp2x_screens[++screensel&3];
+}
+
+/* doulblebuffered flip */
+void gp2x_video_flip2(void)
+{
+ unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&1] >> 16);
+
+ gp2x_memregs[0x2910>>1] = msw;
+ gp2x_memregs[0x2914>>1] = msw;
+ gp2x_memregs[0x290E>>1] = 0;
+ gp2x_memregs[0x2912>>1] = 0;
+
+ // jump to other buffer:
+ g_screen_ptr = gp2x_screens[++screensel&1];
+}
+
+void gp2x_video_changemode_ll(int bpp)
+{
+ gp2x_memregs[0x28DA>>1] = (((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/
+ gp2x_memregs[0x290C>>1] = 320*((bpp+1)/8); /*line width in bytes*/
+}
+
+void gp2x_video_setpalette(int *pal, int len)
+{
+ unsigned short *g = (unsigned short *)pal;
+ volatile unsigned short *memreg = &gp2x_memregs[0x295A>>1];
+
+ gp2x_memregs[0x2958>>1] = 0;
+
+ len *= 2;
+ while (len--)
+ *memreg = *g++;
+}
+
+// TV Compatible function //
+void gp2x_video_RGB_setscaling(int ln_offs, int W, int H)
+{
+ float escalaw, escalah;
+ int bpp = (gp2x_memregs[0x28DA>>1]>>9)&0x3;
+ unsigned short scalw;
+
+ // set offset
+ gp2x_screenaddrs_use[0] = gp2x_screenaddrs[0] + ln_offs * 320 * bpp;
+ gp2x_screenaddrs_use[1] = gp2x_screenaddrs[1] + ln_offs * 320 * bpp;
+ gp2x_screenaddrs_use[2] = gp2x_screenaddrs[2] + ln_offs * 320 * bpp;
+ gp2x_screenaddrs_use[3] = gp2x_screenaddrs[3] + ln_offs * 320 * bpp;
+
+ escalaw = 1024.0; // RGB Horiz LCD
+ escalah = 320.0; // RGB Vert LCD
+
+ if(gp2x_memregs[0x2800>>1]&0x100) //TV-Out
+ {
+ escalaw=489.0; // RGB Horiz TV (PAL, NTSC)
+ if (gp2x_memregs[0x2818>>1] == 287) //PAL
+ escalah=274.0; // RGB Vert TV PAL
+ else if (gp2x_memregs[0x2818>>1] == 239) //NTSC
+ escalah=331.0; // RGB Vert TV NTSC
+ }
+
+ // scale horizontal
+ scalw = (unsigned short)((float)escalaw *(W/320.0));
+ /* if there is no horizontal scaling, vertical doesn't work. Here is a nasty wrokaround... */
+ if (H != 240 && W == 320) scalw--;
+ gp2x_memregs[0x2906>>1]=scalw;
+ // scale vertical
+ gp2x_memregl[0x2908>>2]=(unsigned long)((float)escalah *bpp *(H/240.0));
+}
+
+void gp2x_video_wait_vsync(void)
+{
+ unsigned short v = gp2x_memregs[0x1182>>1];
+ while (!((v ^ gp2x_memregs[0x1182>>1]) & 0x10))
+ spend_cycles(1024);
+}
+
+/* 940 */
+void pause940(int yes)
+{
+ if (yes)
+ gp2x_memregs[0x0904>>1] &= 0xFFFE;
+ else
+ gp2x_memregs[0x0904>>1] |= 1;
+}
+
+void reset940(int yes, int bank)
+{
+ gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03);
+}
+
+
+/* these are not quite MMSP2 related,
+ * more to GP2X F100/F200 consoles themselves. */
+typedef struct ucb1x00_ts_event
+{
+ unsigned short pressure;
+ unsigned short x;
+ unsigned short y;
+ unsigned short pad;
+ struct timeval stamp;
+} UCB1X00_TS_EVENT;
+
+int gp2x_touchpad_read(int *x, int *y)
+{
+ UCB1X00_TS_EVENT event;
+ static int zero_seen = 0;
+ int retval;
+
+ if (touchdev < 0) return -1;
+
+ retval = read(touchdev, &event, sizeof(event));
+ if (retval <= 0) {
+ perror("touch read failed");
+ return -1;
+ }
+ // this is to ignore the messed-up 4.1.x driver
+ if (event.pressure == 0) zero_seen = 1;
+
+ if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16;
+ if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16;
+ // printf("read %i %i %i\n", event.pressure, *x, *y);
+
+ return zero_seen ? event.pressure : 0;
+}
+
+static void proc_set(const char *path, const char *val)
+{
+ FILE *f;
+ char tmp[16];
+
+ f = fopen(path, "w");
+ if (f == NULL) {
+ printf("failed to open: %s\n", path);
+ return;
+ }
+
+ fprintf(f, "0\n");
+ fclose(f);
+
+ printf("\"%s\" is set to: ", path);
+ f = fopen(path, "r");
+ if (f == NULL) {
+ printf("(open failed)\n");
+ return;
+ }
+
+ fgets(tmp, sizeof(tmp), f);
+ printf("%s", tmp);
+ fclose(f);
+}
+
+
+void mmsp2_init(void)
+{
+ int i;
+
+ memdev = open("/dev/mem", O_RDWR);
+ if (memdev == -1)
+ {
+ perror("open(\"/dev/mem\")");
+ exit(1);
+ }
+
+ gp2x_memregs = mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000);
+ if (gp2x_memregs == MAP_FAILED)
+ {
+ perror("mmap(memregs)");
+ exit(1);
+ }
+ gp2x_memregl = (unsigned long *) gp2x_memregs;
+
+ gp2x_memregs[0x2880>>1] &= ~0x383; // disable cursor, subpict, osd, video layers
+
+ gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED,
+ memdev, gp2x_screenaddrs[0]);
+ if (gp2x_screens[0] == MAP_FAILED)
+ {
+ perror("mmap(g_screen_ptr)");
+ exit(1);
+ }
+ printf("framebuffers:\n");
+ printf(" %08x -> %p\n", gp2x_screenaddrs[0], gp2x_screens[0]);
+ for (i = 1; i < 4; i++)
+ {
+ gp2x_screens[i] = (char *) gp2x_screens[i - 1] + FRAMEBUFF_SIZE;
+ printf(" %08x -> %p\n", gp2x_screenaddrs[i], gp2x_screens[i]);
+ }
+
+ g_screen_ptr = gp2x_screens[0];
+ screensel = 0;
+
+ gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1];
+ gp2x_screenaddr_old[1] = gp2x_memregs[0x2910>>1];
+ gp2x_screenaddr_old[2] = gp2x_memregs[0x2912>>1];
+ gp2x_screenaddr_old[3] = gp2x_memregs[0x2914>>1];
+
+ memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs));
+
+ // touchscreen
+ touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);
+ if (touchdev >= 0) {
+ FILE *pcf = fopen("/etc/pointercal", "r");
+ if (pcf) {
+ fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1],
+ &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]);
+ fclose(pcf);
+ }
+ printf("found touchscreen/wm97xx\n");
+ }
+
+ /* disable Linux read-ahead */
+ proc_set("/proc/sys/vm/max-readahead", "0\n");
+ proc_set("/proc/sys/vm/min-readahead", "0\n");
+}
+
+void mmsp2_finish(void)
+{
+ reset940(1, 3);
+ pause940(1);
+
+ gp2x_memregs[0x290E>>1] = gp2x_screenaddr_old[0];
+ gp2x_memregs[0x2910>>1] = gp2x_screenaddr_old[1];
+ gp2x_memregs[0x2912>>1] = gp2x_screenaddr_old[2];
+ gp2x_memregs[0x2914>>1] = gp2x_screenaddr_old[3];
+
+ munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);
+ munmap((void *)gp2x_memregs, 0x10000);
+ close(memdev);
+ if (touchdev >= 0)
+ close(touchdev);
+}
+