From 9f09be93a93ac2570da23bc07f36558b232b7e79 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Wed, 7 Mar 2018 16:20:29 -0600 Subject: [PATCH] Implement (true? better?) framerate cycle --- include/apple2.draw.h | 3 ++- include/apple2.h | 3 ++- src/apple2.c | 1 + src/apple2.dbuf.c | 2 +- src/apple2.draw.c | 25 +++++++++++++++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/apple2.draw.h b/include/apple2.draw.h index 86e73f5..2c1b9fa 100644 --- a/include/apple2.draw.h +++ b/include/apple2.draw.h @@ -4,7 +4,8 @@ #include "apple2.h" #include "vm_bits.h" -extern void apple2_draw_pixel(apple2 *, vm_16bit); +extern void apple2_draw(apple2 *); extern void apple2_draw_40col(apple2 *); +extern void apple2_draw_pixel(apple2 *, vm_16bit); #endif diff --git a/include/apple2.h b/include/apple2.h index 1ebd61d..1a94e83 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -350,13 +350,14 @@ extern bool apple2_is_double_video(apple2 *); extern int apple2_boot(apple2 *); extern void apple2_clear_strobe(apple2 *); extern void apple2_free(apple2 *); +extern void apple2_notify_refresh(apple2 *); extern void apple2_press_key(apple2 *, vm_8bit); extern void apple2_release_key(apple2 *); extern void apple2_reset(apple2 *); extern void apple2_run_loop(apple2 *); extern void apple2_set_bank_switch(apple2 *, vm_8bit); extern void apple2_set_color(apple2 *, int); -extern void apple2_set_memory_mode(apple2 *, vm_8bit); extern void apple2_set_display(apple2 *, vm_8bit); +extern void apple2_set_memory_mode(apple2 *, vm_8bit); #endif diff --git a/src/apple2.c b/src/apple2.c index 549b5b0..76cd814 100644 --- a/src/apple2.c +++ b/src/apple2.c @@ -391,6 +391,7 @@ apple2_run_loop(apple2 *mach) mos6502_execute(mach->cpu); if (vm_screen_dirty(mach->screen)) { + apple2_draw(mach); vm_screen_refresh(mach->screen); } } diff --git a/src/apple2.dbuf.c b/src/apple2.dbuf.c index c1220e0..93a33de 100644 --- a/src/apple2.dbuf.c +++ b/src/apple2.dbuf.c @@ -100,7 +100,7 @@ SEGMENT_WRITER(apple2_dbuf_write) segment->memory[addr] = value; if (mach->display_mode & DISPLAY_TEXT) { - apple2_draw_40col(mach); + apple2_notify_refresh(mach); } } diff --git a/src/apple2.draw.c b/src/apple2.draw.c index 2db81ca..c79cb25 100644 --- a/src/apple2.draw.c +++ b/src/apple2.draw.c @@ -102,3 +102,28 @@ apple2_draw_40col(apple2 *mach) apple2_text_draw(mach, addr); } } + +/* + * Find the right draw method for the machine, based on its display + * mode, and use that to refresh the screen. + */ +void +apple2_draw(apple2 *mach) +{ + if (mach->display_mode & DISPLAY_TEXT) { + apple2_draw_40col(mach); + } +} + +/* + * Tell the screen that it has a change ready to be displayed. This + * function will not immediately redraw the screen, and when the screen + * is redrawn is up to our framerate cycle. + */ +void +apple2_notify_refresh(apple2 *mach) +{ + if (mach && mach->screen) { + mach->screen->dirty = true; + } +}