Skip to content

Commit

Permalink
Added support for multiple fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-jonsson committed Nov 4, 2023
1 parent 3510267 commit 0386856
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 275 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Browser version is avalible [here](https://realmode.games).

* Intel 8088 or NEC V20 CPU
* Hardware CPU validator
* CGA/HGC compatible graphics
* VGA and CGA compatible graphics
* GLaBIOS or Turbo XT BIOS 3.1 with extensions
* Keyboard controller with 83-key XT-style keyboard
* Serial port with Microsoft 2-button mouse
Expand Down
4 changes: 2 additions & 2 deletions modules/cga/cga.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static void out(struct cga_video *c, vxt_word port, vxt_byte data) {
case 0x3BF: // Enable HGC.
// Set bit 0 to enable bit 1 of 3B8.
// Set bit 1 to enable bit 7 of 3B8 and the second 32k of RAM ("Full" mode).
#ifndef VXTU_CGA_NO_HGC
#ifndef CGA_NO_HGC
c->hgc_enable = data & 3;
#endif
break;
Expand Down Expand Up @@ -250,7 +250,7 @@ static vxt_error reset(struct cga_video *c) {
static const char *name(struct cga_video *c) {
(void)c;
return "CGA"
#ifndef VXTU_CGA_NO_HGC
#ifndef CGA_NO_HGC
"/HGC"
#endif
" Compatible Device";
Expand Down
4 changes: 4 additions & 0 deletions modules/cga/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
files {
"*.c", "*.h"
}

-- Make sure to run with no more then 640K
-- of memory if Hercules mode is enabled.
defines "CGA_NO_HGC"
260 changes: 0 additions & 260 deletions modules/vga/font.h

This file was deleted.

6 changes: 2 additions & 4 deletions modules/vga/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
files {
"vga.c",
"render.inl",
"font.h",
"palette.h"
}
"render.inl"
}
19 changes: 15 additions & 4 deletions modules/vga/render.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static vxt_dword color_lookup(struct snapshot *snap, vxt_byte index) {
}

static void blit_char(struct vga_video *v, int ch, vxt_byte attr, int x, int y) {
struct snapshot *snap = &v->snap;
struct snapshot * const snap = &v->snap;

int bg_color_index = (attr & 0x70) >> 4;
int fg_color_index = attr & 0xF;
Expand All @@ -52,6 +52,9 @@ static void blit_char(struct vga_video *v, int ch, vxt_byte attr, int x, int y)

vxt_dword bg_color = color_lookup(snap, bg_color_index);
vxt_dword fg_color = color_lookup(snap, fg_color_index);
int font = (attr & 8) ? snap->font_b : snap->font_a;

// TODO: Fix this! We only run at 640 in textmode.
int width = (snap->width >= 640) ? 640 : 320;
int start = 0;
int end = 15;
Expand All @@ -64,7 +67,7 @@ static void blit_char(struct vga_video *v, int ch, vxt_byte attr, int x, int y)

for (int i = start; true; i++) {
int n = i % 16;
vxt_byte glyph_line = vga_font[ch * 16 + n];
vxt_byte glyph_line = snap->mem[font + ch * 32 + n];

for (int j = 0; j < 8; j++) {
vxt_byte mask = 0x80 >> j;
Expand All @@ -85,13 +88,21 @@ static bool snapshot(struct vxt_pirepheral *p) {

memcpy(v->snap.mem, v->mem, MEMORY_SIZE);
memcpy(v->snap.palette, v->palette, sizeof(v->snap.palette));
memcpy(v->snap.pal_reg, v->reg.attr_reg, 16);
memcpy(v->snap.pal_reg, v->reg.attr_reg, 16);

v->snap.width = v->width;
v->snap.height = v->height;
v->snap.bpp = v->bpp;
v->snap.textmode = v->textmode;

vxt_byte char_map_reg = v->reg.seq_reg[0x3];
vxt_byte fa = ((char_map_reg >> 3) & 4) | ((char_map_reg >> 2) & 3);
vxt_byte fb = ((char_map_reg >> 2) & 4) | (char_map_reg & 3);

const int font_offsets[] = { 0x0000, 0x4000, 0x8000, 0xC000, 0x2000, 0x6000, 0xA000, 0xE000 };
v->snap.font_a = font_offsets[fa];
v->snap.font_b = font_offsets[fb];

v->snap.video_page = ((int)v->reg.crt_reg[0xC] << 8) + (int)v->reg.crt_reg[0xD];
v->snap.plane_mode = !(v->reg.seq_reg[0x4] & 6);
v->snap.mode_ctrl = v->reg.attr_reg[0x10];
Expand All @@ -110,7 +121,7 @@ static bool snapshot(struct vxt_pirepheral *p) {

static int render(struct vxt_pirepheral *p, int (*f)(int,int,const vxt_byte*,void*), void *userdata) {
struct vga_video *v = VXT_GET_DEVICE(vga_video, p);
struct snapshot *snap = &v->snap;
struct snapshot * const snap = &v->snap;

if (snap->textmode) {
int num_col = (snap->width < 640) ? 40 : 80;
Expand Down
6 changes: 2 additions & 4 deletions modules/vga/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ References: https://www.scs.stanford.edu/10wi-cs140/pintos/specs/freevga/vga/vga
*/

#include <vxt/vxtu.h>

#include <frontend.h>

#include "font.h"

#include <string.h>

#define PLANE_SIZE 0x10000
Expand Down Expand Up @@ -82,6 +78,8 @@ struct snapshot {
vxt_word height;
vxt_byte bpp;
bool textmode;
int font_a;
int font_b;

int video_page;
int pixel_shift;
Expand Down

0 comments on commit 0386856

Please sign in to comment.