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
3846typedef 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
4151extern uint8_t __persistent_data_start [];
4252static 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 );
0 commit comments