X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fgp2x.c;h=89505a00fa98d5fd35af499be5250bf747b7a1f9;hb=fce20e73e7094060b29f1668b8f0032f75eb152e;hp=5f38314db1c1711d09fe656353caa6970bd94d49;hpb=838a5b02ee2a6e4c90459f07146ca13a35d6d816;p=libpicofe.git diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 5f38314..89505a0 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -28,14 +28,14 @@ #include #include #include -#include -#include #include #include #include "gp2x.h" -#include "usbjoy.h" +#include "../linux/usbjoy.h" +#include "../linux/sndout_oss.h" #include "../common/arm_utils.h" +#include "../common/arm_linux.h" volatile unsigned short *gp2x_memregs; //static @@ -44,7 +44,8 @@ static void *gp2x_screens[4]; static int screensel = 0; //static int memdev = 0; -static int sounddev = 0, mixerdev = 0; +static int touchdev = -1; +static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; void *gp2x_screen; @@ -161,9 +162,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); } @@ -210,62 +209,44 @@ unsigned long gp2x_joystick_read(int allow_usb_joy) if (allow_usb_joy && num_of_joys > 0) { // check the usb joy as well.. - gp2x_usbjoy_update(); + usbjoy_update(); for (i = 0; i < num_of_joys; i++) - value |= gp2x_usbjoy_check(i); + value |= usbjoy_check(i); } return value; } -static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0; - -void gp2x_start_sound(int rate, int bits, int stereo) +typedef struct ucb1x00_ts_event { - int frag = 0, bsize, buffers; - - // if no settings change, we don't need to do anything - if (rate == s_oldrate && s_oldbits == bits && s_oldstereo == stereo) return; - - if (sounddev > 0) close(sounddev); - sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC); - if (sounddev == -1) - printf("open(\"/dev/dsp\") failed with %i\n", errno); - - ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits); - ioctl(sounddev, SNDCTL_DSP_SPEED, &rate); - ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo); - // calculate buffer size - buffers = 16; - bsize = rate / 32; - if (rate > 22050) { bsize*=4; buffers*=2; } // 44k mode seems to be very demanding - while ((bsize>>=1)) frag++; - frag |= buffers<<16; // 16 buffers - ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag); - usleep(192*1024); - - printf("gp2x_set_sound: %i/%ibit/%s, %i buffers of %i bytes\n", - rate, bits, stereo?"stereo":"mono", frag>>16, 1<<(frag&0xffff)); - - s_oldrate = rate; s_oldbits = bits; s_oldstereo = stereo; -} + 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; -void gp2x_sound_write(void *buff, int len) -{ - write(sounddev, buff, len); -} + 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; -void gp2x_sound_sync(void) -{ - ioctl(sounddev, SOUND_PCM_SYNC, 0); -} + 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); -void gp2x_sound_volume(int l, int r) -{ - 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*/ + return zero_seen ? event.pressure : 0; } @@ -319,7 +300,7 @@ void gp2x_init(void) memdev = open("/dev/mem", O_RDWR); if (memdev == -1) { - printf("open(\"/dev/mem\") failed with %i\n", errno); + perror("open(\"/dev/mem\")"); exit(1); } @@ -327,15 +308,17 @@ void gp2x_init(void) printf("memregs are @ %p\n", gp2x_memregs); if(gp2x_memregs == MAP_FAILED) { - printf("mmap(memregs) failed with %i\n", errno); + 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, FRAMEBUFF_ADDR0); if(gp2x_screens[0] == MAP_FAILED) { - printf("mmap(gp2x_screen) failed with %i\n", errno); + perror("mmap(gp2x_screen)"); exit(1); } printf("framebuffers point to %p\n", gp2x_screens[0]); @@ -355,12 +338,22 @@ void gp2x_init(void) gp2x_memset_all_buffers(0, 0, 320*240*2); // snd - mixerdev = open("/dev/mixer", O_RDWR); - if (mixerdev == -1) - printf("open(\"/dev/mixer\") failed with %i\n", errno); + sndout_oss_init(); /* init usb joys -GnoStiC */ - gp2x_usbjoy_init(); + 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"); @@ -385,15 +378,15 @@ void gp2x_deinit(void) munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE); munmap((void *)gp2x_memregs, 0x10000); close(memdev); - close(mixerdev); - if (sounddev > 0) close(sounddev); + if (touchdev >= 0) close(touchdev); - gp2x_usbjoy_deinit(); + sndout_oss_exit(); + usbjoy_deinit(); printf("all done, running "); // Zaq121's alternative frontend support from MAME - if(ext_menu && ext_state) { + if (ext_menu && ext_state) { printf("%s -state %s\n", ext_menu, ext_state); execl(ext_menu, ext_menu, "-state", ext_state, NULL); } else if(ext_menu) {