X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fgp2x.c;h=f350352f66ba38966676d8fa867e1106f329f9a1;hb=82abf46f3db8ade517881c03327bdbc0de848eb2;hp=78e8561f857034c6a6bf16d7876238bfd3e4d2d9;hpb=3f2aaff20c940e90e970c008e56f5253d494a92c;p=libpicofe.git diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 78e8561..f350352 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/sndout_oss.h" #include "../common/arm_utils.h" +#include "../common/arm_linux.h" +#include "../common/emu.h" volatile unsigned short *gp2x_memregs; //static @@ -44,11 +44,9 @@ static void *gp2x_screens[4]; static int screensel = 0; //static int memdev = 0; -static int sounddev = -1, mixerdev = -1, touchdev = -1; +static int touchdev = -1; static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; -void *gp2x_screen; - #define FRAMEBUFF_WHOLESIZE (0x30000*4) // 320*240*2 + some more #define FRAMEBUFF_ADDR0 (0x4000000-FRAMEBUFF_WHOLESIZE) #define FRAMEBUFF_ADDR1 (FRAMEBUFF_ADDR0+0x30000) @@ -72,7 +70,7 @@ void gp2x_video_flip(void) gp2x_memregs[0x2912>>1] = lsw; // jump to other buffer: - gp2x_screen = gp2x_screens[++screensel&3]; + g_screen_ptr = gp2x_screens[++screensel&3]; } /* doulblebuffered flip */ @@ -86,7 +84,7 @@ void gp2x_video_flip2(void) gp2x_memregs[0x2912>>1] = 0; // jump to other buffer: - gp2x_screen = gp2x_screens[++screensel&1]; + g_screen_ptr = gp2x_screens[++screensel&1]; } @@ -162,9 +160,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(g_screen_ptr, (char *)g_screen_ptr + 320*240*2); } @@ -195,30 +191,10 @@ void gp2x_memset_all_buffers(int offset, int byte, int len) void gp2x_pd_clone_buffer2(void) { - memcpy(gp2x_screen, gp2x_screens[2], 320*240*2); + memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2); } -unsigned long gp2x_joystick_read(int allow_usb_joy) -{ - int i; - 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)); // C D - - if (allow_usb_joy && num_of_joys > 0) { - // check the usb joy as well.. - gp2x_usbjoy_update(); - for (i = 0; i < num_of_joys; i++) - value |= gp2x_usbjoy_check(i); - } - - return value; -} - typedef struct ucb1x00_ts_event { unsigned short pressure; @@ -231,72 +207,24 @@ typedef struct 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) { + 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 event.pressure; -} - - -static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0; - -void gp2x_start_sound(int rate, int bits, int stereo) -{ - 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; -} - - -void gp2x_sound_write(void *buff, int len) -{ - write(sounddev, buff, len); -} - -void gp2x_sound_sync(void) -{ - ioctl(sounddev, SOUND_PCM_SYNC, 0); -} - -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; } @@ -350,7 +278,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); } @@ -358,7 +286,7 @@ 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; @@ -368,7 +296,7 @@ void gp2x_init(void) 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(g_screen_ptr)"); exit(1); } printf("framebuffers point to %p\n", gp2x_screens[0]); @@ -376,7 +304,7 @@ void gp2x_init(void) gp2x_screens[2] = (char *) gp2x_screens[1]+0x30000; gp2x_screens[3] = (char *) gp2x_screens[2]+0x30000; - gp2x_screen = gp2x_screens[0]; + g_screen_ptr = gp2x_screens[0]; screensel = 0; gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1]; @@ -388,12 +316,7 @@ 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); - - /* init usb joys -GnoStiC */ - gp2x_usbjoy_init(); + sndout_oss_init(); // touchscreen touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY); @@ -430,16 +353,14 @@ 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(); 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) {