From e5ba9cb62c62a4a9cb9012dfd45870bc5b988def Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 1 Jun 2023 22:36:51 +0100 Subject: Add function to wait for VGA's vsync --- TODO.md | 2 -- src/main.c | 1 + src/vga.c | 6 ++++++ src/vga.h | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index a1ccdc3..7715c19 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ - drawing - sw blitter - time - - vga vsync - tick counter - input - keyboard @@ -16,7 +15,6 @@ - MOD player? - ADLIB music? - data (embedded in EXE) - - image data: PNG - map data: JSON - screens - menu diff --git a/src/main.c b/src/main.c index a8a6b77..2b01d3f 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,7 @@ int main(int argc, char *argv[]) for (int i = 0; i < 16; i++) { + wait_vsync(); memset(screen, i, 320 * 200); getch(); } diff --git a/src/vga.c b/src/vga.c index a6524bd..981ad6f 100644 --- a/src/vga.c +++ b/src/vga.c @@ -24,6 +24,12 @@ void set_mode(uint8_t mode) __dpmi_int(0x10, ®s); } +void wait_vsync() +{ + while (inportb(0x3da) & 8); + while (!(inportb(0x3da) & 8)); +} + void set_palette(const uint8_t *palette) { outportb(0x3c8, 0); diff --git a/src/vga.h b/src/vga.h index a9c46c6..2332413 100644 --- a/src/vga.h +++ b/src/vga.h @@ -5,6 +5,7 @@ uint8_t *open_framebuffer(); void close_framebuffer(); void set_mode(uint8_t mode); +void wait_vsync(); /* the palette is expected to be 8 bit per color, and will be converted to VGA's 6 bit per color */ void set_palette(const uint8_t *palette); -- cgit v1.2.3