From 23e113e72ad843db89912e02e22d4fa87e5a7fb8 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Wed, 20 Dec 2017 21:52:28 -0600 Subject: [PATCH] Add video mode switcher to handle logical sizes --- include/apple2.h | 15 +++++++++++++++ src/apple2.c | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/apple2.h b/include/apple2.h index 67e0143..3804e03 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -5,6 +5,13 @@ #include "mos6502.h" #include "vm_screen.h" +enum video_modes { + VIDEO_LORES, + VIDEO_HIRES, + VIDEO_DOUBLE_LORES, + VIDEO_DOUBLE_HIRES, +}; + typedef struct { /* * The apple 2 hardware used an MOS-6502 processor. @@ -23,6 +30,13 @@ typedef struct { */ vm_screen *screen; + /* + * This is the mode in which we must interpret graphics. This will + * tell us not only if we're in lo- or hi-res, but also if we are in + * single or double view mode. + */ + int video_mode; + /* * Our two disk drives. */ @@ -37,5 +51,6 @@ extern void apple2_clear_strobe(apple2 *); extern void apple2_release_key(apple2 *); extern int apple2_boot(apple2 *); extern void apple2_run_loop(apple2 *); +extern void apple2_set_video(apple2 *, int); #endif diff --git a/src/apple2.c b/src/apple2.c index 096b492..190a5c9 100644 --- a/src/apple2.c +++ b/src/apple2.c @@ -156,3 +156,28 @@ apple2_boot(apple2 *mach) return OK; } + +void +apple2_set_video(apple2 *mach, int mode) +{ + int width, height; + + mach->video_mode = mode; + + // In the traditional video modes that Apple II first came in, you + // would have a maximum width of 280 pixels. (In lo-res, you have + // fewer pixels, but that is something we have to handle in our + // drawing functions rather than by changing the logical size.) + width = 280; + height = 192; + + // In double video modes, the width is effectively doubled, but the + // height is untouched. + if (mach->video_mode == VIDEO_DOUBLE_LORES || + mach->video_mode == VIDEO_DOUBLE_HIRES + ) { + width = 560; + } + + vm_screen_set_logical_coords(mach->screen, width, height); +}