Skip to content

Commit e48be7e

Browse files
committed
Add an enable flag for the Videx support
1 parent 2549026 commit e48be7e

File tree

6 files changed

+83
-4
lines changed

6 files changed

+83
-4
lines changed

docs/Usage.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ After you load on the firmware for your respective Apple II system (II+ or IIe)
44
the VGA card is generally plug-and-play. Plug it in, power on your Apple II
55
and that's it.
66

7+
There are some optional features and other controls that can be changed using the
8+
menu-based Configuration disk or by directly using `POKE` commands.
9+
710

811
## Soft Monochrome Mode
912

@@ -56,7 +59,9 @@ This register controls enablement of some features of the card
5659

5760
| bit(s) | Description
5861
| ------ | -----------
59-
| 7:2 | reserved
62+
| 7:4 | reserved
63+
| 3 | Setting to 1 will disable Videx VideoTerm support (II+ only)
64+
| 2 | Setting to 1 will enable Videx VideoTerm support (II+ only)
6065
| 1 | Setting to 1 will disable simulated scanline rendering
6166
| 0 | Setting to 1 will enable simulated scanline rendering
6267

pico/config.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "buffers.h"
88
#include "colors.h"
99
#include "textfont/textfont.h"
10+
#ifdef APPLE_MODEL_IIPLUS
11+
#include "videx_vterm.h"
12+
#endif
1013

1114

1215
// A block of flash is reserved for storing configuration persistently across power cycles
@@ -32,11 +35,18 @@ struct config {
3235

3336
// magic word determines if the stored configuration is valid
3437
uint32_t magic_word;
38+
39+
// Add new fields after here. When reading the config use the IS_STORED_IN_CONFIG macro
40+
// to determine if the field you're looking for is actually present in the stored config.
41+
42+
uint8_t videx_vterm_enabled;
3543
};
3644

3745
// This is a compile-time check to ensure the size of the config struct fits within one flash erase sector
3846
typedef char config_struct_size_check[(sizeof(struct config) <= FLASH_SECTOR_SIZE) - 1];
3947

48+
#define IS_STORED_IN_CONFIG(cfg, field) ((offsetof(struct config, field) + sizeof((cfg)->field)) <= (cfg)->size)
49+
4050

4151
extern uint8_t __persistent_data_start[];
4252
static struct config *cfg = (struct config *)__persistent_data_start;
@@ -54,6 +64,16 @@ void config_load() {
5464
mono_bg_color = cfg->mono_bg_color;
5565
mono_fg_color = cfg->mono_fg_color;
5666
memcpy(character_rom, cfg->character_rom, CHARACTER_ROM_SIZE);
67+
68+
#ifdef APPLE_MODEL_IIPLUS
69+
if(IS_STORED_IN_CONFIG(cfg, videx_vterm_enabled)) {
70+
if(cfg->videx_vterm_enabled) {
71+
videx_vterm_enable();
72+
} else {
73+
videx_vterm_disable();
74+
}
75+
}
76+
#endif
5777
}
5878

5979

@@ -63,6 +83,9 @@ void config_load_defaults() {
6383
mono_bg_color = mono_bg_colors[1];
6484
mono_fg_color = mono_fg_colors[1];
6585
memcpy(character_rom, default_character_rom, CHARACTER_ROM_SIZE);
86+
#ifdef APPLE_MODEL_IIPLUS
87+
videx_vterm_disable();
88+
#endif
6689
}
6790

6891

@@ -71,6 +94,7 @@ void config_save() {
7194
const int new_config_size = (sizeof(struct config) + FLASH_PAGE_SIZE - 1) & -FLASH_PAGE_SIZE;
7295
struct config *new_config = malloc(new_config_size);
7396
memset(new_config, 0xff, new_config_size);
97+
memset(new_config, 0, sizeof(struct config));
7498

7599
new_config->size = sizeof(struct config);
76100
new_config->scanline_emulation = soft_scanline_emulation;
@@ -79,6 +103,9 @@ void config_save() {
79103
new_config->mono_fg_color = mono_fg_color;
80104
memcpy(new_config->character_rom, character_rom, CHARACTER_ROM_SIZE);
81105
new_config->magic_word = MAGIC_WORD_VALUE;
106+
#ifdef APPLE_MODEL_IIPLUS
107+
new_config->videx_vterm_enabled = videx_vterm_enabled;
108+
#endif
82109

83110
const uint32_t flash_offset = (uint32_t)cfg - XIP_BASE;
84111
flash_range_erase(flash_offset, FLASH_SECTOR_SIZE);

pico/device_regs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "colors.h"
66
#include "config.h"
77
#include "textfont/textfont.h"
8+
#ifdef APPLE_MODEL_IIPLUS
9+
#include "videx_vterm.h"
10+
#endif
811

912

1013
static unsigned int char_write_offset;
@@ -18,6 +21,12 @@ void device_write(uint_fast8_t reg, uint_fast8_t data) {
1821
soft_scanline_emulation = true;
1922
if(data & 0x02)
2023
soft_scanline_emulation = false;
24+
#ifdef APPLE_MODEL_IIPLUS
25+
if(data & 0x04)
26+
videx_vterm_enable();
27+
if(data & 0x08)
28+
videx_vterm_disable();
29+
#endif
2130
break;
2231

2332
// soft-monochrome color setting
@@ -55,7 +64,7 @@ void device_write(uint_fast8_t reg, uint_fast8_t data) {
5564
// command value.
5665
//
5766
// Note: some of these commands could take a long time (relative to 6502 bus cycles) so
58-
// some bus activity may be missed. Other projects like the Analog-V2 delegate this execution
67+
// some bus activity may be missed. Other projects like the V2-Analog delegate this execution
5968
// to the other (VGA) core to avoid this. Maybe do this if the missed bus cycles become a noticable
6069
// issue; I only expect it would happen when some config is being saved, which is not done often.
6170
void execute_device_command(uint_fast8_t cmd) {

pico/render.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void render_loop() {
3737
break;
3838
default:
3939
#ifdef APPLE_MODEL_IIPLUS
40-
if(videx_vterm_80col_enabled) {
40+
if(videx_vterm_enabled && videx_vterm_80col_enabled) {
4141
render_videx_text();
4242
} else
4343
#endif

pico/videx_vterm.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "vga.h"
88

99

10+
volatile bool videx_vterm_enabled; // true -> the videx card is enabled
1011
volatile bool videx_vterm_80col_enabled; // true -> the annunciator to enable 80-columns is on
1112
volatile bool videx_vterm_mem_selected; // true -> videx memory is accessible at $C800-$CFFF
1213
volatile uint8_t videx_vram[2048];
@@ -40,8 +41,10 @@ static uint_fast32_t videx_cursor_mask = 0;
4041
static uint64_t videx_next_flash_tick = 0;
4142

4243

44+
// Initialize VideoTerm state
45+
//
46+
// Only called from the abus core
4347
void videx_vterm_init() {
44-
// initializing registers
4548
videx_banknum = 0;
4649
videx_crtc_idx = 0;
4750
videx_crtc_regs[0] = 0x7b;
@@ -63,8 +66,29 @@ void videx_vterm_init() {
6366
}
6467

6568

69+
// Enable the VideoTerm support
70+
//
71+
// Only called from the abus core
72+
void videx_vterm_enable() {
73+
videx_vterm_enabled = true;
74+
}
75+
76+
77+
// Disable the VideoTerm support
78+
//
79+
// Only called from the abus core
80+
void videx_vterm_disable() {
81+
videx_vterm_enabled = false;
82+
}
83+
84+
6685
// Shadow accesses to card registers in $C0n0 - $C0nF range
86+
//
87+
// Only called from the abus core
6788
void videx_vterm_shadow_register(bool is_write, uint_fast16_t address, uint_fast8_t data) {
89+
if(!videx_vterm_enabled)
90+
return;
91+
6892
// select the video memory bank
6993
videx_banknum = (address & 0x000c) >> 2;
7094

@@ -84,7 +108,12 @@ void videx_vterm_shadow_register(bool is_write, uint_fast16_t address, uint_fast
84108

85109

86110
// Shadow bus accesses to the $C800-$CFFF memory space
111+
//
112+
// Only called from the abus core
87113
void videx_vterm_shadow_c8xx(bool is_write, uint_fast16_t address, uint_fast8_t value) {
114+
if(!videx_vterm_enabled)
115+
return;
116+
88117
if(!videx_vterm_mem_selected)
89118
return;
90119

@@ -104,6 +133,9 @@ void videx_vterm_shadow_c8xx(bool is_write, uint_fast16_t address, uint_fast8_t
104133
}
105134

106135

136+
// Update the internal VideoTerm flashing state
137+
//
138+
// Only called from the render core
107139
void videx_vterm_update_flasher() {
108140
uint64_t now = time_us_64();
109141
if(now > videx_next_flash_tick) {
@@ -196,6 +228,9 @@ static void render_videx_text_line(unsigned int line, uint text_base_addr, uint
196228
}
197229

198230

231+
// Render a screen of VideoTerm text mode
232+
//
233+
// Only called from the render core
199234
void render_videx_text() {
200235
vga_prepare_frame();
201236
// Skip 25 lines to center vertically

pico/videx_vterm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#include <stdbool.h>
55

66

7+
extern volatile bool videx_vterm_enabled;
78
extern volatile bool videx_vterm_80col_enabled;
89
extern volatile bool videx_vterm_mem_selected;
910

1011
extern void videx_vterm_init();
12+
extern void videx_vterm_enable();
13+
extern void videx_vterm_disable();
1114
extern void videx_vterm_shadow_register(bool is_write, uint_fast16_t address, uint_fast8_t data);
1215
extern void videx_vterm_shadow_c8xx(bool is_write, uint_fast16_t address, uint_fast8_t value);
1316

0 commit comments

Comments
 (0)