HANDLE handle = GetStdHandle (STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
- CHAR_INFO cells[80 * 25];
+ CHAR_INFO *cells;
COORD size, origin = { 0, 0 };
SMALL_RECT region;
width = right - left + 1;
+ if (!(cells = malloc (width * (bottom - top + 1) * sizeof (*cells)))) {
+ return;
+ }
+
for (row = top; row <= bottom; row++) {
for (col = left; col <= right; col++) {
region.Bottom = (SHORT) (info.srWindow.Top + bottom);
WriteConsoleOutputW (handle, cells, size, origin, ®ion);
+ free (cells);
}
#endif
+static uint32_t bios_video_memory_base (void) {
+ return bios_video_mode == 0x07 ? 0xB0000 : 0xB8000;
+}
+
+static void bios_video_copy_to_memory (CPU8086 *cpu, unsigned top, unsigned left, unsigned bottom, unsigned right) {
+
+ uint32_t base = bios_video_memory_base ();
+ unsigned row, col;
+
+ for (row = top; row <= bottom; row++) {
+
+ for (col = left; col <= right; col++) {
+
+ uint32_t address = base + (row * bios_video_columns + col) * 2;
+
+ cpu->mem[address] = bios_video_chars[row][col];
+ cpu->mem[address + 1] = bios_video_attrs[row][col];
+
+ }
+
+ }
+
+}
+
+static void bios_video_copy_from_memory (CPU8086 *cpu) {
+
+ uint32_t base = bios_video_memory_base ();
+ unsigned row, col;
+
+ for (row = 0; row < bios_video_rows; row++) {
+
+ for (col = 0; col < bios_video_columns; col++) {
+
+ uint32_t address = base + (row * bios_video_columns + col) * 2;
+
+ bios_video_chars[row][col] = cpu->mem[address];
+ bios_video_attrs[row][col] = cpu->mem[address + 1];
+
+ }
+
+ }
+
+}
+
static void bios_video_initialize (void) {
unsigned row;
}
}
+
+ bios_video_copy_to_memory (cpu, 0, 0, 24, bios_video_columns - 1);
+
+ } else {
+ bios_video_copy_from_memory (cpu);
}
}
+ bios_video_copy_to_memory (cpu, top, left, bottom, right);
+
#if defined (_WIN32)
if (bios_windows_legacy_console ()) {
}
+ if (bios_cursor_row[0] < bios_video_rows && bios_cursor_col[0] < bios_video_columns) {
+
+ unsigned right = (unsigned) bios_cursor_col[0] + (count ? count - 1 : 0);
+
+ if (right >= bios_video_columns) {
+ right = bios_video_columns - 1;
+ }
+
+ if (count != 0) {
+ bios_video_copy_to_memory (cpu, bios_cursor_row[0], bios_cursor_col[0], bios_cursor_row[0], right);
+ }
+
+ }
+
#if defined (_WIN32)
if (bios_windows_legacy_console ()) {
}
+void bios_video_refresh (CPU8086 *cpu) {
+
+ unsigned dirty = mem_video_dirty;
+ unsigned row, col, first, last;
+
+ unsigned viewport_width, viewport_height;
+ uint32_t base;
+
+ mem_video_dirty = 0;
+
+ if (!(dirty & (bios_video_mode == 0x07 ? 1 : 2))) {
+ return;
+ }
+
+ bios_video_initialize ();
+ bios_video_viewport (&viewport_width, &viewport_height);
+
+ base = bios_video_memory_base ();
+
+#if !defined (_WIN32)
+ fputs ("\0337\033[?7l", stdout);
+#else
+ if (!bios_windows_legacy_console ()) {
+ fputs ("\0337\033[?7l", stdout);
+ }
+#endif
+
+ for (row = 0; row < bios_video_rows; row++) {
+
+ first = bios_video_columns;
+ last = 0;
+
+ for (col = 0; col < bios_video_columns; col++) {
+
+ uint32_t address = base + (row * bios_video_columns + col) * 2;
+
+ uint8_t ch = cpu->mem[address];
+ uint8_t attr = cpu->mem[address + 1];
+
+ if (ch != bios_video_chars[row][col] || attr != bios_video_attrs[row][col]) {
+
+ bios_video_chars[row][col] = ch;
+ bios_video_attrs[row][col] = attr;
+
+ if (first == bios_video_columns) {
+ first = col;
+ }
+
+ last = col;
+
+ }
+
+ }
+
+ if (first == bios_video_columns || row >= viewport_height || first >= viewport_width) {
+ continue;
+ }
+
+#if defined (_WIN32)
+ if (bios_windows_legacy_console ()) {
+ bios_windows_render (row, first, row, last);
+ } else
+#endif
+ {
+
+ unsigned end = last < viewport_width ? last : viewport_width - 1;
+ fprintf (stdout, "\033[%u;%uH", row + 1, first + 1);
+
+ for (col = first; col <= end; col++) {
+
+ bios_video_set_attribute (bios_video_attrs[row][col]);
+ bios_write_video_char (bios_video_chars[row][col]);
+
+ }
+
+ }
+
+ }
+
+#if !defined (_WIN32)
+ fputs ("\033[0m\033[?7h\0338", stdout);
+#else
+ if (!bios_windows_legacy_console ()) {
+ fputs ("\033[0m\033[?7h\0338", stdout);
+ }
+#endif
+
+ fflush (stdout);
+
+}
+
static void int_13 (CPU8086 *cpu) {
uint8_t ah = get_reg8 (cpu, 4);
file_handle_references[2] = 1;
bios_video_initialize ();
+
+ bios_video_copy_to_memory (cpu, 0, 0, 24, 79);
+ bios_video_mode = 0x07;
+
+ bios_video_copy_to_memory (cpu, 0, 0, 24, 79);
+ bios_video_mode = 0x03;
+
bios_video_update_bda (cpu);
}
#include "memory.h"
#include "psp.h"
-#define MEM_SIZE (640UL << 10)
+#define CONVENTIONAL_MEM_SIZE (640UL << 10)
#define EXE_LOAD_SEG 0x0060
+#define MEM_SIZE (1UL << 20)
#if defined (_WIN32)
static HANDLE terminal_output_handle;
cpu_reset (&cpu, mem, MEM_SIZE);
dos_path = dos_register_initial_program (path);
- if (load_mz_file (path, &cpu, EXE_LOAD_SEG << 4, (uint16_t) ((MEM_SIZE - ((uint32_t) (EXE_LOAD_SEG << 4) << 4)) / 16))) {
+ if (load_mz_file (path, &cpu, EXE_LOAD_SEG << 4, (uint16_t) ((CONVENTIONAL_MEM_SIZE - ((uint32_t) (EXE_LOAD_SEG << 4) << 4)) / 16))) {
init_psp (dos_path, &cpu, cmd_tail, EXE_LOAD_SEG);
- } else if (load_com_file (path, &cpu, mem, MEM_SIZE, EXE_LOAD_SEG, &loaded)) {
+ } else if (load_com_file (path, &cpu, mem, CONVENTIONAL_MEM_SIZE, EXE_LOAD_SEG, &loaded)) {
init_psp (dos_path, &cpu, cmd_tail, EXE_LOAD_SEG);
} else {
}
rc = cpu_step (&cpu);
+ bios_video_refresh (&cpu);
if (rc <= 0) {