static int bios_video_initialized;
static int bios_graphics_visible;
+static int bios_graphics_text_mode;
static unsigned bios_graphics_columns, bios_graphics_rows;
static uint64_t bios_graphics_last_refresh;
static uint32_t bios_graphics_sample (CPU8086 *cpu, unsigned col, unsigned line, unsigned columns, unsigned lines) {
+ static const uint8_t vga16[16][3] = {
+
+ { 0, 0, 0 }, { 0, 0, 42 }, { 0, 42, 0 }, { 0, 42, 42 },
+ { 42, 0, 0 }, { 42, 0, 42 }, { 42, 21, 0 }, { 42, 42, 42 },
+ { 21, 21, 21 }, { 21, 21, 63 }, { 21, 63, 21 }, { 21, 63, 63 },
+ { 63, 21, 21 }, { 63, 21, 63 }, { 63, 63, 21 }, { 63, 63, 63 }
+
+ };
+
unsigned x0 = col * 320, x1 = (col + 1) * 320;
unsigned y0 = line * 200, y1 = (line + 1) * 200;
unsigned red = 0, green = 0, blue = 0;
unsigned width = (sx1 < x1 ? sx1 : x1) - (sx0 > x0 ? sx0 : x0);
unsigned weight = width * height;
- uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
- const uint8_t *rgb = cpu->vga_dac_palette[index];
+ uint8_t index;
+ const uint8_t *rgb;
+
+ if (bios_video_mode == 0x13) {
+
+ index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
+ rgb = cpu->vga_dac_palette[index];
+
+ } else {
+
+ uint32_t address = 0xB8000 + ((y / 2) * 80 + (x / 4)) * 2;
+
+ uint8_t ch = cpu->mem[address];
+ uint8_t attr = cpu->mem[address + 1];
+ uint8_t foreground = attr & 0x0F;
+ uint8_t background = (attr >> 4) & (bios_video_blink_enabled ? 0x07 : 0x0F);
+
+ index = ch == 0xDE ? ((x & 2) ? foreground : background) :
+ ch == 0xDD ? ((x & 2) ? background : foreground) :
+ ch == 0xDB ? foreground : background;
+
+ rgb = vga16[index];
+
+ }
red += weight * rgb[0];
green += weight * rgb[1];
struct timeval now;
#endif
- if (video_native_present (cpu)) {
+ if (video_native_present (cpu, bios_video_mode != 0x13, bios_video_blink_enabled)) {
return;
}
return;
}
- full_redraw = !bios_graphics_visible || columns != bios_graphics_columns || rows != bios_graphics_rows;
+ full_redraw = !bios_graphics_visible || columns != bios_graphics_columns || rows != bios_graphics_rows || bios_graphics_text_mode != (bios_video_mode != 0x13);
- if (memcmp (bios_graphics_palette, cpu->vga_dac_palette, sizeof (bios_graphics_palette)) != 0 || bios_graphics_dac_mask != cpu->vga_dac_mask) {
+ if (bios_video_mode == 0x13 && (memcmp (bios_graphics_palette, cpu->vga_dac_palette, sizeof (bios_graphics_palette)) != 0 || bios_graphics_dac_mask != cpu->vga_dac_mask)) {
full_redraw = 1;
}
- if (!(mem_video_dirty & 4) && !full_redraw) {
+ if (!(mem_video_dirty & (bios_video_mode == 0x13 ? 4u : 2u)) && !full_redraw && !bios_video_force_redraw) {
return;
}
bios_graphics_columns = columns;
bios_graphics_rows = rows;
+ bios_graphics_text_mode = bios_video_mode != 0x13;
memcpy (bios_graphics_palette, cpu->vga_dac_palette, sizeof (bios_graphics_palette));
bios_graphics_dac_mask = cpu->vga_dac_mask;
- mem_video_dirty &= ~4u;
+ mem_video_dirty &= ~(bios_video_mode == 0x13 ? 4u : 2u);
+ bios_video_force_redraw = 0;
#if defined (_WIN32)
if (!vt_console) {
int full_redraw = bios_video_force_redraw;
uint32_t base;
- if (bios_video_mode == 0x13) {
+ if (bios_video_mode == 0x13 || (bios_video_mode == 0x03 && bios_video_columns == 80 && (cpu->crtc_registers[9] & 0x1F) == 3)) {
bios_graphics_refresh (cpu);
return;
#include "cpu.h"
-int video_native_present (CPU8086 *cpu);
+int video_native_present (CPU8086 *cpu, int text_mode, int blink_enabled);
+void video_native_text_render (CPU8086 *cpu, uint32_t *pixels, int blink_enabled);
+
int video_native_active (void);
int video_native_poll (CPU8086 *cpu);
static int attempted;
static int closed;
+static int video_last_text_mode = -1;
+static int video_last_blink_enabled = -1;
static uint64_t last_refresh;
static uint8_t previous_palette[256][3];
}
-int video_native_present (CPU8086 *cpu) {
+int video_native_present (CPU8086 *cpu, int text_mode, int blink_enabled) {
int palette_changed;
palette_changed = memcmp (previous_palette, cpu->vga_dac_palette, sizeof (previous_palette)) || previous_mask != cpu->vga_dac_mask;
- if (!(mem_video_dirty & 4) && !palette_changed && (backend != 1 || !x11.redraw)) {
+ if (!(mem_video_dirty & (text_mode ? 2u : 4u)) && (text_mode || !palette_changed) && video_last_text_mode == text_mode && (!text_mode || video_last_blink_enabled == blink_enabled) && (backend != 1 || !x11.redraw)) {
return 1;
}
last_refresh = now;
- for (y = 0; y < 200; y++) {
+ if (text_mode) {
+ video_native_text_render (cpu, video_framebuffer, blink_enabled);
+ } else {
- for (x = 0; x < 320; x++) {
+ for (y = 0; y < 200; y++) {
- uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
- const uint8_t *rgb = cpu->vga_dac_palette[index];
+ for (x = 0; x < 320; x++) {
- uint32_t color = ((uint32_t) (rgb[0] * 255 + 31) / 63 << 16) | ((uint32_t) (rgb[1] * 255 + 31) / 63 << 8) | (uint32_t) (rgb[2] * 255 + 31) / 63;
+ uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
+ const uint8_t *rgb = cpu->vga_dac_palette[index];
+
+ uint32_t color = ((uint32_t) (rgb[0] * 255 + 31) / 63 << 16) | ((uint32_t) (rgb[1] * 255 + 31) / 63 << 8) | (uint32_t) (rgb[2] * 255 + 31) / 63;
+
+ video_framebuffer[y * 2 * VIDEO_WIDTH + x * 2] = color;
+ video_framebuffer[y * 2 * VIDEO_WIDTH + x * 2 + 1] = color;
+ video_framebuffer[(y * 2 + 1) * VIDEO_WIDTH + x * 2] = color;
+ video_framebuffer[(y * 2 + 1) * VIDEO_WIDTH + x * 2 + 1] = color;
- video_framebuffer[y * 2 * VIDEO_WIDTH + x * 2] = color;
- video_framebuffer[y * 2 * VIDEO_WIDTH + x * 2 + 1] = color;
- video_framebuffer[(y * 2 + 1) * VIDEO_WIDTH + x * 2] = color;
- video_framebuffer[(y * 2 + 1) * VIDEO_WIDTH + x * 2 + 1] = color;
+ }
}
memcpy (previous_palette, cpu->vga_dac_palette, sizeof (previous_palette));
previous_mask = cpu->vga_dac_mask;
- mem_video_dirty &= ~4u;
+ mem_video_dirty &= ~(text_mode ? 2u : 4u);
+
+ video_last_text_mode = text_mode;
+ video_last_blink_enabled = blink_enabled;
return 1;
memset (previous_palette, 0, sizeof (previous_palette));
previous_mask = 0;
+
+ video_last_text_mode = -1;
+ video_last_blink_enabled = -1;
}
static NSWindow *video_window;
static NSView *video_view;
+static int video_last_text_mode = -1;
+static int video_last_blink_enabled = -1;
+
static uint32_t video_pixels[640 * 400];
static uint8_t video_palette[256][3];
}
-int video_native_present (CPU8086 *cpu) {
+int video_native_present (CPU8086 *cpu, int text_mode, int blink_enabled) {
unsigned x, y;
NSTimeInterval now;
video_native_poll (cpu);
palette_changed = memcmp (video_palette, cpu->vga_dac_palette, sizeof (video_palette)) || video_mask != cpu->vga_dac_mask;
- if (!(mem_video_dirty & 4) && !palette_changed) {
+ if (!(mem_video_dirty & (text_mode ? 2u : 4u)) && (text_mode || !palette_changed) && video_last_text_mode == text_mode && (!text_mode || video_last_blink_enabled == blink_enabled)) {
return 1;
}
video_last_refresh = now;
- for (y = 0; y < 200; y++) {
+ if (text_mode) {
+ video_native_text_render (cpu, video_pixels, blink_enabled);
+ } else {
- for (x = 0; x < 320; x++) {
+ for (y = 0; y < 200; y++) {
- uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
- const uint8_t *rgb = cpu->vga_dac_palette[index];
+ for (x = 0; x < 320; x++) {
- uint32_t color = ((uint32_t) (rgb[0] * 255 + 31) / 63 << 16) |
- ((uint32_t) (rgb[1] * 255 + 31) / 63 << 8) | (uint32_t) (rgb[2] * 255 + 31) / 63;
+ uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
+ const uint8_t *rgb = cpu->vga_dac_palette[index];
+
+ uint32_t color = ((uint32_t) (rgb[0] * 255 + 31) / 63 << 16) |
+ ((uint32_t) (rgb[1] * 255 + 31) / 63 << 8) | (uint32_t) (rgb[2] * 255 + 31) / 63;
+
+ video_pixels[y * 2 * 640 + x * 2] = color;
+ video_pixels[y * 2 * 640 + x * 2 + 1] = color;
+ video_pixels[(y * 2 + 1) * 640 + x * 2] = color;
+ video_pixels[(y * 2 + 1) * 640 + x * 2 + 1] = color;
- video_pixels[y * 2 * 640 + x * 2] = color;
- video_pixels[y * 2 * 640 + x * 2 + 1] = color;
- video_pixels[(y * 2 + 1) * 640 + x * 2] = color;
- video_pixels[(y * 2 + 1) * 640 + x * 2 + 1] = color;
+ }
}
memcpy (video_palette, cpu->vga_dac_palette, sizeof (video_palette));
video_mask = cpu->vga_dac_mask;
- mem_video_dirty &= ~4u;
+ mem_video_dirty &= ~(text_mode ? 2u : 4u);
+
+ video_last_text_mode = text_mode;
+ video_last_blink_enabled = blink_enabled;
[video_view setNeedsDisplay: YES];
[video_view displayIfNeeded];
memset (video_palette, 0, sizeof (video_palette));
video_mask = 0;
+
+ video_last_text_mode = -1;
+ video_last_blink_enabled = -1;
}
#if !defined (__linux__) && !defined (_WIN32) && !defined (__APPLE__) || defined (__ANDROID__)
#include "video_native.h"
-int video_native_present (CPU8086 *cpu) {
+int video_native_present (CPU8086 *cpu, int text_mode, int blink_enabled) {
+ (void) blink_enabled;
+ (void) text_mode;
(void) cpu;
+
return 0;
}
--- /dev/null
+/******************************************************************************
+ * @file video_native_text.c
+ *****************************************************************************/
+#include <stdint.h>
+
+#include "video_native.h"
+
+void video_native_text_render (CPU8086 *cpu, uint32_t *pixels, int blink_enabled) {
+
+ static const uint8_t vga16[16][3] = {
+
+ { 0, 0, 0 }, { 0, 0, 42 }, { 0, 42, 0 }, { 0, 42, 42 },
+ { 42, 0, 0 }, { 42, 0, 42 }, { 42, 21, 0 }, { 42, 42, 42 },
+ { 21, 21, 21 }, { 21, 21, 63 }, { 21, 63, 21 }, { 21, 63, 63 },
+ { 63, 21, 21 }, { 63, 21, 63 }, { 63, 63, 21 }, { 63, 63, 63 }
+
+ };
+
+ uint32_t colors[16];
+ unsigned row, col, x, y, i;
+
+ for (i = 0; i < 16; i++) {
+
+ colors[i] = ((uint32_t) (vga16[i][0] * 255 + 31) / 63 << 16) |
+ ((uint32_t) (vga16[i][1] * 255 + 31) / 63 << 8) | (uint32_t) (vga16[i][2] * 255 + 31) / 63;
+
+ }
+
+ for (row = 0; row < 100; row++) {
+
+ for (col = 0; col < 80; col++) {
+
+ unsigned address = 0xB8000 + (row * 80 + col) * 2;
+
+ uint8_t ch = cpu->mem[address];
+ uint8_t attr = cpu->mem[address + 1];
+ uint8_t foreground = attr & 0x0F;
+ uint8_t background = (attr >> 4) & (blink_enabled ? 0x07 : 0x0F);
+
+ uint32_t left = colors[background];
+ uint32_t right = colors[background];
+
+ if (ch == 0xDE) {
+ right = colors[foreground];
+ } else if (ch == 0xDD) {
+ left = colors[foreground];
+ } else if (ch == 0xDB) {
+ left = right = colors[foreground];
+ }
+
+ for (y = 0; y < 4; y++) {
+
+ uint32_t *line = pixels + (row * 4 + y) * 640 + col * 8;
+
+ for (x = 0; x < 4; x++) {
+
+ line[x] = left;
+ line[x + 4] = right;
+
+ }
+
+ }
+
+ }
+
+ }
+
+}
static uint8_t video_mask;
static uint8_t video_key_queue[128];
+static int video_last_text_mode = -1;
+static int video_last_blink_enabled = -1;
+
static unsigned video_key_head, video_key_tail;
static void video_key (UINT key, int pressed) {
}
-int video_native_present (CPU8086 *cpu) {
+int video_native_present (CPU8086 *cpu, int text_mode, int blink_enabled) {
unsigned x, y;
DWORD now;
video_native_poll (cpu);
palette_changed = memcmp (video_palette, cpu->vga_dac_palette, sizeof (video_palette)) || video_mask != cpu->vga_dac_mask;
- if (!(mem_video_dirty & 4) && !palette_changed) {
+ if (!(mem_video_dirty & (text_mode ? 2u : 4u)) && (text_mode || !palette_changed) && video_last_text_mode == text_mode && (!text_mode || video_last_blink_enabled == blink_enabled)) {
return 1;
}
video_last_refresh = now;
- for (y = 0; y < 200; y++) {
+ if (text_mode) {
+ video_native_text_render (cpu, video_pixels, blink_enabled);
+ } else {
- for (x = 0; x < 320; x++) {
+ for (y = 0; y < 200; y++) {
- uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
- const uint8_t *rgb = cpu->vga_dac_palette[index];
+ for (x = 0; x < 320; x++) {
- uint32_t color = ((uint32_t) (rgb[0] * 255 + 31) / 63 << 16) |
- ((uint32_t) (rgb[1] * 255 + 31) / 63 << 8) | (uint32_t) (rgb[2] * 255 + 31) / 63;
+ uint8_t index = mem_vga_pixel (cpu, x, y) & cpu->vga_dac_mask;
+ const uint8_t *rgb = cpu->vga_dac_palette[index];
+
+ uint32_t color = ((uint32_t) (rgb[0] * 255 + 31) / 63 << 16) |
+ ((uint32_t) (rgb[1] * 255 + 31) / 63 << 8) | (uint32_t) (rgb[2] * 255 + 31) / 63;
+
+ video_pixels[y * 2 * 640 + x * 2] = color;
+ video_pixels[y * 2 * 640 + x * 2 + 1] = color;
+ video_pixels[(y * 2 + 1) * 640 + x * 2] = color;
+ video_pixels[(y * 2 + 1) * 640 + x * 2 + 1] = color;
- video_pixels[y * 2 * 640 + x * 2] = color;
- video_pixels[y * 2 * 640 + x * 2 + 1] = color;
- video_pixels[(y * 2 + 1) * 640 + x * 2] = color;
- video_pixels[(y * 2 + 1) * 640 + x * 2 + 1] = color;
+ }
}
memcpy (video_palette, cpu->vga_dac_palette, sizeof (video_palette));
video_mask = cpu->vga_dac_mask;
- mem_video_dirty &= ~4u;
+ mem_video_dirty &= ~(text_mode ? 2u : 4u);
+
+ video_last_text_mode = text_mode;
+ video_last_blink_enabled = blink_enabled;
InvalidateRect (video_window, NULL, FALSE);
UpdateWindow (video_window);
memset (video_palette, 0, sizeof (video_palette));
video_mask = 0;
+
+ video_last_text_mode = -1;
+ video_last_blink_enabled = -1;
}