diff --git a/src/common/api.c b/src/common/api.c index 676cb24..d727b39 100644 --- a/src/common/api.c +++ b/src/common/api.c @@ -127,35 +127,6 @@ static struct GFX_Context { SDL_Surface* screen; } gfx; -/////////////////////////////// -// based on eggs Miyoo Mini GFX lib -// (any bad decisions are mine) - - -static pthread_t flip_pt; -static pthread_mutex_t flip_mx; -static pthread_cond_t flip_req; -static volatile uint32_t now_flipping; -static int flip_y = 0; - -static void* flip_thread(void* param) { - int last_y = 0; - pthread_mutex_lock(&flip_mx); - while (1) { - pthread_cond_wait(&flip_req, &flip_mx); - if (flip_y!=last_y) { - pthread_mutex_unlock(&flip_mx); - gfx.vinfo.yoffset = flip_y; - last_y = flip_y; - int arg = 0; - ioctl(gfx.fb, FBIO_WAITFORVSYNC, &arg); // TODO: disable this when fast forwarding - ioctl(gfx.fb, FBIOPAN_DISPLAY, &gfx.vinfo); - pthread_mutex_lock(&flip_mx); - } - } - return NULL; -} - /////////////////////////////// SDL_Surface* GFX_init(void) { @@ -313,7 +284,11 @@ SDL_Surface* GFX_init(void) { // disp.mHeight = SCREEN_HEIGHT; // buffer tracking +#ifdef GFX_ENABLE_BUFFER gfx.buffer = 1; +#else + gfx.buffer = 0; +#endif gfx.buffer_size = SCREEN_PITCH * SCREEN_HEIGHT; // #ifdef GFX_ENABLE_BUFFER @@ -322,13 +297,8 @@ SDL_Surface* GFX_init(void) { // printf("buffer needs: %i available: %i joy: %i\n", gfx.buffer_size, gfx.map_size, gfx.map_size>=gfx.buffer_size?1:0); // #endif - flip_mx = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; - flip_req = (pthread_cond_t)PTHREAD_COND_INITIALIZER; - now_flipping = 0; - pthread_create(&flip_pt, NULL, flip_thread, NULL); - // return screen - gfx.screen = SDL_CreateRGBSurfaceFrom(gfx.map + gfx.buffer_size, SCREEN_WIDTH,SCREEN_HEIGHT, SCREEN_DEPTH,SCREEN_PITCH, 0,0,0,0); + gfx.screen = SDL_CreateRGBSurfaceFrom(gfx.map + gfx.buffer_size * gfx.buffer, SCREEN_WIDTH,SCREEN_HEIGHT, SCREEN_DEPTH,SCREEN_PITCH, 0,0,0,0); return gfx.screen; } void GFX_clear(SDL_Surface* screen) { @@ -339,44 +309,32 @@ void GFX_clearAll(void) { } void GFX_flip(SDL_Surface* screen) { - pthread_mutex_lock(&flip_mx); - flip_y = gfx.buffer * SCREEN_HEIGHT; - pthread_cond_signal(&flip_req); - pthread_mutex_unlock(&flip_mx); - + // struct fb_vblank vblank; + // ioctl(gfx.fb, FBIOGET_VBLANK, &vblank); + // printf("flags: %i\n", vblank.flags); + // printf("count: %i\n", vblank.count); + // printf("vcount: %i\n", vblank.vcount); + // printf("hcount: %i\n", vblank.hcount); +#ifdef GFX_ENABLE_VSYNC + int arg = 1; + ioctl(gfx.fb, OWLFB_WAITFORVSYNC, &arg); // TODO: this doesn't wait but it also doesn't error out like FBIO_WAITFORVSYNC... +#endif + +#ifdef GFX_ENABLE_BUFFER + // TODO: this would be moved to a thread + // I'm not clear on why that would be necessary + // if it's non-blocking and the pan will wait + // until the next vblank... + // what if the scaling was also moved to a thread? + gfx.vinfo.yoffset = gfx.buffer * SCREEN_HEIGHT; + ioctl(gfx.fb, FBIOPAN_DISPLAY, &gfx.vinfo); + gfx.buffer += 1; if (gfx.buffer>=GFX_BUFFER_COUNT) gfx.buffer -= GFX_BUFFER_COUNT; - screen->pixels = gfx.map + (gfx.buffer * gfx.buffer_size); - -// // struct fb_vblank vblank; -// // ioctl(gfx.fb, FBIOGET_VBLANK, &vblank); -// // printf("flags: %i\n", vblank.flags); -// // printf("count: %i\n", vblank.count); -// // printf("vcount: %i\n", vblank.vcount); -// // printf("hcount: %i\n", vblank.hcount); -// #ifdef GFX_ENABLE_VSYNC -// int arg = 1; -// ioctl(gfx.fb, OWLFB_WAITFORVSYNC, &arg); // TODO: this doesn't wait but it also doesn't error out like FBIO_WAITFORVSYNC... -// #endif -// -// #ifdef GFX_ENABLE_BUFFER -// // TODO: this would be moved to a thread -// // I'm not clear on why that would be necessary -// // if it's non-blocking and the pan will wait -// // until the next vblank... -// // what if the scaling was also moved to a thread? -// gfx.vinfo.yoffset = gfx.buffer * SCREEN_HEIGHT; -// ioctl(gfx.fb, FBIOPAN_DISPLAY, &gfx.vinfo); -// -// gfx.buffer += 1; -// if (gfx.buffer>=GFX_BUFFER_COUNT) gfx.buffer -= GFX_BUFFER_COUNT; -// screen->pixels = gfx.map + (gfx.buffer * gfx.buffer_size); -// #endif + screen->pixels = gfx.map + (gfx.buffer * gfx.buffer_size); +#endif } void GFX_quit(void) { - pthread_cancel(flip_pt); - pthread_join(flip_pt, NULL); - GFX_clearAll(); munmap(gfx.map, gfx.map_size); close(gfx.fb);