X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fgp2x.c;h=0276038b5ad96b54f7f699f1b540dabb497781bf;hb=095a240bd91548be4b9770d28d5d6c3e97637094;hp=7a5156c78f22f35be68b562977337d1e4b85802a;hpb=0480e6c9696e4d4cbd451a91a7ef63d96f60542d;p=libpicofe.git diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 7a5156c..0276038 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -36,6 +36,7 @@ #include "gp2x.h" #include "usbjoy.h" #include "../common/arm_utils.h" +#include "../common/arm_linux.h" volatile unsigned short *gp2x_memregs; //static @@ -44,7 +45,8 @@ static void *gp2x_screens[4]; static int screensel = 0; //static int memdev = 0; -static int sounddev = 0, mixerdev = 0; +static int sounddev = -1, mixerdev = -1, touchdev = -1; +static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; void *gp2x_screen; @@ -161,9 +163,7 @@ void gp2x_video_wait_vsync(void) void gp2x_video_flush_cache(void) { // since we are using the mmu hack, we must flush the cache first - // (the params are most likely wrong, but they seem to work somehow) - //flushcache(addr, addr + 320*240*2, 0); - flushcache(gp2x_screen, (char *)gp2x_screen + 320*240*2, 0); + cache_flush_d_inval_i(gp2x_screen, (char *)gp2x_screen + 320*240*2); } @@ -201,12 +201,12 @@ void gp2x_pd_clone_buffer2(void) unsigned long gp2x_joystick_read(int allow_usb_joy) { int i; - unsigned long value=(gp2x_memregs[0x1198>>1] & 0x00FF); + unsigned long value=(gp2x_memregs[0x1198>>1] & 0x00FF); // GPIO M if(value==0xFD) value=0xFA; if(value==0xF7) value=0xEB; if(value==0xDF) value=0xAF; if(value==0x7F) value=0xBE; - value = ~((gp2x_memregs[0x1184>>1] & 0xFF00) | value | (gp2x_memregs[0x1186>>1] << 16)); + value = ~((gp2x_memregs[0x1184>>1] & 0xFF00) | value | (gp2x_memregs[0x1186>>1] << 16)); // C D if (allow_usb_joy && num_of_joys > 0) { // check the usb joy as well.. @@ -218,6 +218,39 @@ unsigned long gp2x_joystick_read(int allow_usb_joy) return value; } +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) { + printf("touch read failed %i %i\n", retval, errno); + 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 int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0; void gp2x_start_sound(int rate, int bits, int stereo) @@ -284,6 +317,31 @@ void Reset940(int yes, int bank) gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03); } +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); +} /* common */ @@ -307,6 +365,8 @@ void gp2x_init(void) } 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, FRAMEBUFF_ADDR0); if(gp2x_screens[0] == MAP_FAILED) { @@ -337,6 +397,22 @@ void gp2x_init(void) /* init usb joys -GnoStiC */ gp2x_usbjoy_init(); + // 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"); + printf("exitting init()\n"); fflush(stdout); } @@ -357,7 +433,8 @@ void gp2x_deinit(void) munmap((void *)gp2x_memregs, 0x10000); close(memdev); close(mixerdev); - if (sounddev > 0) close(sounddev); + if (sounddev >= 0) close(sounddev); + if (touchdev >= 0) close(touchdev); gp2x_usbjoy_deinit();