Skip to content

Commit

Permalink
allow force-loading a built-in charset
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Nov 7, 2021
1 parent b242cca commit 96a938f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/frontend_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static void posix_zzt_help(int argc, char **argv) {
fprintf(stderr, " available types/formats: \n");
fprintf(stderr, " - charset:\n");
fprintf(stderr, " - chr (MegaZeux-like; 8x[height], 256 chars)\n");
fprintf(stderr, " - default (builtin font; ega or cga)\n");
fprintf(stderr, " - palette:\n");
fprintf(stderr, " - pal (MegaZeux-like; 16 colors ranged 00-3F)\n");
fprintf(stderr, " - pld (Toshiba UPAL; 64 EGA colors ranged 00-3F)\n");
Expand Down Expand Up @@ -163,6 +164,15 @@ static int posix_zzt_init(int argc, char **argv) {
type[filename - type - 1] = '\0';
}

if (strcmp(type, "charset:default") == 0) {
if (strcmp(filename, "ega") == 0) {
zzt_force_default_charset(DEFAULT_CHARSET_STYLE_EGA);
} else if (strcmp(filename, "cga") == 0) {
zzt_force_default_charset(DEFAULT_CHARSET_STYLE_CGA);
}
continue;
}

FILE *file = fopen(filename, "rb");
if (!file) {
fprintf(stderr, "Could not open %s!\n", filename);
Expand Down
13 changes: 13 additions & 0 deletions src/zzt.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ static void zzt_load_charset_default() {
}
}

USER_FUNCTION
void zzt_force_default_charset(zzt_default_charset_style_t style) {
if (style == DEFAULT_CHARSET_STYLE_CGA) {
zzt_load_charset(8, 16, res_8x8dbl_bin, true);
} else if (style == DEFAULT_CHARSET_STYLE_EGA) {
zzt_load_charset(8, 14, res_8x14_bin, true);
} else {
return;
}

zzt.charset_default = false;
}

static u16 cpu_func_port_in_main(cpu_state* cpu, u16 addr) {
zzt_state* zzt = (zzt_state*) cpu;

Expand Down
7 changes: 7 additions & 0 deletions src/zzt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#define MAX_FILES 16
#define TEXT_ADDR(x,y) (0xB8000 + ((y)*160) + ((x)*2))

typedef enum {
DEFAULT_CHARSET_STYLE_EGA,
DEFAULT_CHARSET_STYLE_CGA
} zzt_default_charset_style_t;

// the long story:
// 3.579545 MHz - NTSC dotclock
// dotclock * 4 = 14.31818
Expand Down Expand Up @@ -97,6 +102,8 @@ int zzt_get_blink(void);
USER_FUNCTION
int zzt_load_charset(int width, int height, u8* data, bool is_default);
USER_FUNCTION
void zzt_force_default_charset(zzt_default_charset_style_t style);
USER_FUNCTION
int zzt_load_palette(u32* colors);
USER_FUNCTION
int zzt_load_ega_palette(u8* colors);
Expand Down

0 comments on commit 96a938f

Please sign in to comment.