diff render_sdl.c @ 342:13f994c88c34

Get frame time correct and frame rate sort of correct for EUR region
author Mike Pavone <pavone@retrodev.com>
date Thu, 16 May 2013 09:37:53 -0700
parents 58a085cfc6bd
children 15dd6418fe67
line wrap: on
line diff
--- a/render_sdl.c	Wed May 15 23:51:22 2013 -0700
+++ b/render_sdl.c	Thu May 16 09:37:53 2013 -0700
@@ -14,6 +14,7 @@
 uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255};
 
 uint32_t min_delay;
+uint32_t frame_delay = 1000/60;
 
 void render_init(int width, int height, char * title)
 {
@@ -229,8 +230,6 @@
 #define BUTTON_START 0x20
 #define BUTTON_C     0x20
 
-#define FRAME_DELAY 16
-#define MIN_DELAY 5
 uint32_t frame_counter = 0;
 uint32_t start = 0;
 int wait_render_frame(vdp_context * context, int frame_limit)
@@ -362,12 +361,11 @@
 	if (frame_limit) {
 		//TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS
 		uint32_t current = SDL_GetTicks();
-		uint32_t desired = last_frame + FRAME_DELAY;
+		uint32_t desired = last_frame + frame_delay;
 		if (current < desired) {
-			uint32_t delay = last_frame + FRAME_DELAY - current;
-			//TODO: Calculate MIN_DELAY at runtime
-			if (delay > MIN_DELAY) {
-				SDL_Delay((delay/MIN_DELAY)*MIN_DELAY);
+			uint32_t delay = last_frame + frame_delay - current;
+			if (delay > min_delay) {
+				SDL_Delay((delay/min_delay)*min_delay);
 			}
 			while ((desired) >= SDL_GetTicks()) {
 			}
@@ -389,4 +387,9 @@
 	return ret;
 }
 
+void render_fps(uint32_t fps)
+{
+	frame_delay = 1000/fps;
+}
 
+