Browse Source

improve SYS_TIMER_TIME, blinking timing accuracy; fix blinking not updating the screen in OpenGL mode

master
asie 1 week ago
parent
commit
01d542a25b
5 changed files with 19 additions and 8 deletions
  1. 2
    1
      src/config.h
  2. 6
    3
      src/frontend_sdl.c
  3. 2
    2
      src/zzt.c
  4. 8
    1
      src/zzt.h
  5. 1
    1
      web/src/render.js

+ 2
- 1
src/config.h View File

@@ -27,7 +27,8 @@
27 27
 
28 28
 // SDL port configuration
29 29
 
30
-#define BLINK_TOGGLE_DURATION_MS 233
30
+// 60/16 Hz (blink every 16 frames at 60 Hz)
31
+#define BLINK_TOGGLE_DURATION_MS 267
31 32
 #define ENABLE_SCREENSHOTS
32 33
 #define USE_GETOPT
33 34
 #define USE_OPENGL

+ 6
- 3
src/frontend_sdl.c View File

@@ -460,8 +460,7 @@ static void deinit_opengl(void) {
460 460
 	free(ogl_buf_pos);
461 461
 }
462 462
 
463
-static void render_opengl(long curr_time, int regen_visuals) {
464
-	u8 blink_local = video_blink && sdl_is_blink_phase(curr_time);
463
+static void render_opengl(long curr_time, int regen_visuals, u8 blink_local) {
465 464
 	float texw, texh;
466 465
 	int width = (zzt_video_mode() & 2) ? 80 : 40;
467 466
 
@@ -712,6 +711,7 @@ int main(int argc, char **argv) {
712 711
 
713 712
 #ifdef USE_OPENGL
714 713
 	int should_render = 1;
714
+	u8 last_blink_local = 0xFF;
715 715
 #endif
716 716
 
717 717
 	while (cont_loop) {
@@ -882,7 +882,10 @@ int main(int argc, char **argv) {
882 882
 		curr_time = zeta_time_ms();
883 883
 		if (use_opengl) {
884 884
 #ifdef USE_OPENGL
885
-			render_opengl(curr_time, should_render);
885
+			u8 blink_local = video_blink && sdl_is_blink_phase(curr_time);
886
+			should_render |= (blink_local != last_blink_local);
887
+			render_opengl(curr_time, should_render, blink_local);
888
+			last_blink_local = blink_local;
886 889
 			SDL_GL_SwapWindow(window);
887 890
 #endif
888 891
 		} else {

+ 2
- 2
src/zzt.c View File

@@ -894,7 +894,7 @@ static void zzt_load_exe(int handle, const char *arg) {
894 894
 //	int size_pars = 40400;
895 895
 //	int offset_pars = mem_alloc(size_pars, 0);
896 896
 	int offset_pars = 0x100;
897
-	int size_pars = 0xA000 - 0x100;
897
+	int size_pars = 0xB800 - 0x100;
898 898
 
899 899
 	// location
900 900
 	zzt.cpu.seg[SEG_CS] = vfs_read16(handle, 0x16) + offset_pars + 0x10;
@@ -940,7 +940,7 @@ void zzt_load_binary(int handle, const char *arg) {
940 940
 
941 941
 	// assume com file
942 942
 	int offset_pars = 0x100;
943
-	int size_pars = 0xA000 - 0x100;
943
+	int size_pars = 0xB800 - 0x100;
944 944
 	zzt_load_build_psp(offset_pars, offset_pars + size_pars, arg);
945 945
 
946 946
 	zzt.cpu.seg[SEG_CS] = offset_pars;

+ 8
- 1
src/zzt.h View File

@@ -24,7 +24,14 @@
24 24
 
25 25
 #define MAX_FILES 16
26 26
 #define TEXT_ADDR(x,y) (0xB8000 + ((y)*160) + ((x)*2))
27
-#define SYS_TIMER_TIME 54.9451
27
+
28
+// the long story:
29
+// 3.579545 MHz - NTSC dotclock
30
+// dotclock * 4 = 14.31818
31
+// 14.31818 / 12 ~= 1.19318166 - PIT frequency
32
+// 65535 - maximum PIT cycle count before reload
33
+// (65535 / 1193181.66) = SYS_TIMER_TIME (seconds)
34
+#define SYS_TIMER_TIME 54.92457871
28 35
 
29 36
 USER_FUNCTION
30 37
 int zzt_video_mode(void);

+ 1
- 1
web/src/render.js View File

@@ -23,7 +23,7 @@ export class CanvasBasedRenderer {
23 23
 		this.ctx = canvas.getContext('2d', {alpha: false});
24 24
 		this.ctx.imageSmoothingEnabled = false;
25 25
 
26
-		this.blink_duration = Math.round(((options && options.blink_cycle_duration) || 0.466) * 1000);
26
+		this.blink_duration = Math.round(((options && options.blink_cycle_duration) || 0.534) * 1000);
27 27
 		this.video_blink = this.blink_duration > 0;
28 28
 
29 29
 		this.video_mode = -1;

Loading…
Cancel
Save