summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-09-23 03:15:47 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-09-23 03:15:47 -0700
commit7fca1904784040be5de4699217e7052d797a892a (patch)
treea4b9a9064e3a3c738ab8baff31e9bbf468baa885
parent92d422551c1502f1c43615008c5ae6c3ee826fb3 (diff)
downloadabc80sim-hwsurface.tar.gz
abc80sim-hwsurface.tar.xz
abc80sim-hwsurface.zip
sdlscrn: limit the frequency of updateshwsurface
On some platforms, SDL_Flip might actually wait synchronously for a vertical retrace, so don't call it more than once every 10 ms.
-rw-r--r--sdlscrn.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sdlscrn.c b/sdlscrn.c
index f6c57a3..ffcd228 100644
--- a/sdlscrn.c
+++ b/sdlscrn.c
@@ -13,6 +13,7 @@
#include "z80.h"
#include "clock.h"
#include "abcio.h"
+#include "nstime.h"
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
@@ -88,6 +89,7 @@ struct surface {
/* Keep track of what the dirty rectangle is */
unsigned int upd_x0, upd_y0, upd_x1, upd_y1;
int lock_count; /* Lock nesting count */
+ uint64_t updated; /* Time stamp of last update */
};
static struct surface rscreen;
@@ -233,8 +235,12 @@ put_screen(struct surface *s, unsigned int tx, unsigned int ty, bool blink)
/*
* Refresh rectangle and unlock screen
*/
-static void update_screen(struct surface *s)
+#define MIN_UPDATE_INTERVAL (10000000) /* 10 ms */
+
+static void update_screen(struct surface *s, bool force)
{
+ uint64_t now;
+
if (--s->lock_count > 0)
return;
@@ -243,6 +249,10 @@ static void update_screen(struct surface *s)
if (s->upd_x0 == UINT_MAX)
return;
+ now = nstime();
+ if (!force && (now - s->updated) < MIN_UPDATE_INTERVAL)
+ return;
+
if (s->surf->flags & SDL_DOUBLEBUF)
SDL_Flip(s->surf);
else
@@ -252,6 +262,7 @@ static void update_screen(struct surface *s)
((s->upd_x1-s->upd_x0+1)*FONT_XSIZE*FONT_XDUP) << mode40,
(s->upd_y1-s->upd_y0+1)*FONT_YSIZE*FONT_YDUP);
+ s->updated = now;
s->upd_x0 = s->upd_y0 = UINT_MAX;
s->upd_x1 = s->upd_y1 = 0;
}
@@ -272,7 +283,7 @@ static void refresh_screen(struct surface *s, bool blink)
for (x = 0; x < width; x++)
put_screen(s, x, y, blink);
- update_screen(s);
+ update_screen(s, true);
}
/*
@@ -304,7 +315,7 @@ void write_screen(uint8_t *p, uint8_t v)
put_screen(&rscreen, xy.x, xy.y, blink_on);
}
- update_screen(&rscreen);
+ update_screen(&rscreen, false);
}
static void do_set_mode40(bool m)
@@ -358,7 +369,7 @@ static bool set_blink(bool to_what)
break;
}
- update_screen(&rscreen);
+ update_screen(&rscreen, true);
return !to_what; /* We just flipped it... */
}