Skip to content

Commit a9e0425

Browse files
authored
Initial commit for firmware
Sorted directories User configurable color scheme
1 parent 7e02f4d commit a9e0425

File tree

4 files changed

+350
-136
lines changed

4 files changed

+350
-136
lines changed

firmware/file_types.h

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,54 @@ typedef struct
237237
u16 element; // Used if file is a T64 or D64
238238
} CFG_IMG_HEADER;
239239

240+
241+
// echto
242+
typedef enum {
243+
UI_COL_BLACK = 0,
244+
UI_COL_WHITE,
245+
UI_COL_RED,
246+
UI_COL_CYAN,
247+
UI_COL_PURPLE,
248+
UI_COL_GREEN,
249+
UI_COL_BLUE,
250+
UI_COL_YELLOW,
251+
UI_COL_ORANGE,
252+
UI_COL_BROWN,
253+
UI_COL_LIGHTRED,
254+
UI_COL_GRAY1, /* dark gray */
255+
UI_COL_GRAY2, /* medium gray (your SEARCHC uses COLOR_GRAY2) */
256+
UI_COL_LIGHTGREEN,
257+
UI_COL_LIGHTBLUE,
258+
UI_COL_GRAY3, /* light gray */
259+
UI_COL_MAX /* = 16 */
260+
} UI_COLOR_ID;
261+
262+
240263
typedef struct
241264
{
242-
u8 signature[5]; // CFG_SIGNATURE
243-
s8 phi2_offset;
244-
u8 flags; // CFG_FLAGS
265+
u8 signature[5]; // CFG_SIGNATURE
266+
s8 phi2_offset;
267+
u8 flags; // CFG_FLAGS
245268
u32 reserved; // Should be 0
246-
u8 boot_type; // CFG_BOOT_TYPE
269+
u8 boot_type; // CFG_BOOT_TYPE
247270

248-
union
249-
{
271+
union {
250272
CFG_CRT_HEADER crt; // boot_type is CFG_CRT
251273
CFG_IMG_HEADER img; // boot_type is CFG_PRG or CFG_DISK
252274
};
253275

254276
char path[750];
255277
char file[256];
278+
279+
/* --- NEW: UI color IDs (persisted) --- */
280+
u8 ui_color1_id; // header/frame
281+
u8 ui_color2_id; // normal text
282+
u8 ui_color3_id; // alt text
283+
u8 ui_color4_id; // background
284+
u8 ui_color5_id; // border
256285
} CFG_FILE;
286+
287+
257288
#pragma pack(pop)
258289

259290
#define CFG_SIGNATURE "KFF2\1"

firmware/loader.c

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
#define CFG_FILENAME "/.KFF2.cfg"
22-
22+
#define UI_COLOR_TAIL_BYTES 5 /* bytes at the end of dir->name reserved for color IDs */
2323
#define CRT_C64_SIGNATURE "C64 CARTRIDGE "
2424
#define CRT_C128_SIGNATURE "C128 CARTRIDGE "
2525
#define CRT_CHIP_SIGNATURE "CHIP"
@@ -29,6 +29,7 @@
2929
#define EAPI_OFFSET 0x3800
3030
#define EAPI_SIZE 0x300
3131

32+
3233
static u16 prg_load_file(FIL *file)
3334
{
3435
u16 len = file_read(file, dat_buf, sizeof(dat_buf));
@@ -412,24 +413,73 @@ static bool mount_sd_card(void)
412413
return dir_change("/");
413414
}
414415

416+
415417
static bool load_cfg(void)
416418
{
417-
bool result = true;
419+
bool ok = true;
418420
FIL file;
419-
if (!file_open(&file, CFG_FILENAME, FA_READ) ||
420-
file_read(&file, &cfg_file, sizeof(cfg_file)) != sizeof(cfg_file) ||
421-
memcmp(CFG_SIGNATURE, cfg_file.signature, sizeof(cfg_file.signature)) != 0)
422-
{
423-
wrn("%s file not found or invalid", CFG_FILENAME);
421+
FILINFO info;
422+
423+
/* Start clean + signature + DEFAULTS for new fields */
424+
memset(&cfg_file, 0, sizeof(cfg_file));
425+
memcpy(cfg_file.signature, CFG_SIGNATURE, sizeof(cfg_file.signature));
426+
427+
/* Defaults for first boot / older cfgs (IDs, not conio colors) */
428+
cfg_file.ui_color1_id = UI_COL_WHITE;
429+
cfg_file.ui_color2_id = UI_COL_WHITE;
430+
cfg_file.ui_color3_id = UI_COL_PURPLE;
431+
cfg_file.ui_color4_id = UI_COL_BLACK;
432+
cfg_file.ui_color5_id = UI_COL_BLACK;
433+
434+
/* If no file, keep defaults */
435+
if (!file_stat(CFG_FILENAME, &info) || !file_open(&file, CFG_FILENAME, FA_READ)) {
436+
wrn("%s file not found", CFG_FILENAME);
437+
return false;
438+
}
439+
440+
/* Read at most what's present in the file (older cfgs are shorter) */
441+
UINT want = (UINT)info.fsize;
442+
if (want > sizeof(cfg_file)) want = (UINT)sizeof(cfg_file);
443+
444+
UINT got = file_read(&file, &cfg_file, want);
445+
file_close(&file);
446+
if (got != want) {
447+
wrn("Failed to read %s", CFG_FILENAME);
448+
return false;
449+
}
450+
451+
/* Validate signature */
452+
if (memcmp(CFG_SIGNATURE, cfg_file.signature, sizeof(cfg_file.signature)) != 0) {
453+
wrn("%s invalid signature", CFG_FILENAME);
424454
memset(&cfg_file, 0, sizeof(cfg_file));
425455
memcpy(cfg_file.signature, CFG_SIGNATURE, sizeof(cfg_file.signature));
426-
result = false;
456+
cfg_file.ui_color1_id = UI_COL_WHITE;
457+
cfg_file.ui_color2_id = UI_COL_WHITE;
458+
cfg_file.ui_color3_id = UI_COL_PURPLE;
459+
cfg_file.ui_color4_id = UI_COL_BLACK;
460+
cfg_file.ui_color5_id = UI_COL_BLACK;
461+
ok = false;
427462
}
428463

429-
file_close(&file);
430-
return result;
464+
/* Clamp invalid IDs (in case of very old/garbage values) */
465+
if (cfg_file.ui_color1_id >= UI_COL_MAX) cfg_file.ui_color1_id = UI_COL_WHITE;
466+
if (cfg_file.ui_color2_id >= UI_COL_MAX) cfg_file.ui_color2_id = UI_COL_WHITE;
467+
if (cfg_file.ui_color3_id >= UI_COL_MAX) cfg_file.ui_color3_id = UI_COL_PURPLE;
468+
if (cfg_file.ui_color4_id >= UI_COL_MAX) cfg_file.ui_color4_id = UI_COL_BLACK;
469+
if (cfg_file.ui_color5_id >= UI_COL_MAX) cfg_file.ui_color5_id = UI_COL_BLACK;
470+
471+
/* --- Safety correction --- */
472+
/* If both Color2 and Color3 equal Color4, restore to readable defaults */
473+
if (cfg_file.ui_color2_id == cfg_file.ui_color4_id && cfg_file.ui_color3_id == cfg_file.ui_color4_id) {
474+
cfg_file.ui_color2_id = UI_COL_WHITE;
475+
cfg_file.ui_color3_id = UI_COL_PURPLE;
476+
477+
}
478+
479+
return ok;
431480
}
432481

482+
433483
static bool auto_boot(void)
434484
{
435485
bool result = false;

0 commit comments

Comments
 (0)