From 9d2dd22d6d68c8347408bb8f1f3650457e644520 Mon Sep 17 00:00:00 2001 From: TomW Date: Mon, 12 Oct 2015 13:42:09 +0100 Subject: [PATCH] Initialise A20 gate correctly at startup. Keyboard controller self-test command enables A20. HIMEM.SYS included with Windows/286 now works. --- src/keyboard_at.c | 11 ++++++++++- src/mem.c | 8 +++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/keyboard_at.c b/src/keyboard_at.c index c02f506..4c89a56 100644 --- a/src/keyboard_at.c +++ b/src/keyboard_at.c @@ -340,6 +340,15 @@ void keyboard_at_write(uint16_t port, uint8_t val, void *priv) keyboard_at.status |= STAT_SYSFLAG; keyboard_at.mem[0] |= 0x04; keyboard_at_adddata(0x55); + /*Self-test also resets the output port, enabling A20*/ + if (!(keyboard_at.output_port & 0x02)) + { + mem_a20_key = 2; + mem_a20_recalc(); +// pclog("Rammask change to %08X %02X\n", rammask, val & 0x02); + flushmmucache(); + } + keyboard_at.output_port = 0xcf; break; case 0xab: /*Interface test*/ @@ -445,7 +454,7 @@ void keyboard_at_reset() keyboard_at.status = STAT_LOCK | STAT_CD; keyboard_at.mem[0] = 0x11; keyboard_at.wantirq = 0; - keyboard_at.output_port = 0; + keyboard_at.output_port = 0xcf; keyboard_at.input_port = 0xb0; keyboard_at.out_new = -1; keyboard_at.last_irq = 0; diff --git a/src/mem.c b/src/mem.c index 16548d6..57c5fd3 100644 --- a/src/mem.c +++ b/src/mem.c @@ -1736,6 +1736,9 @@ void mem_add_bios() mem_mapping_add(&bios_high_mapping[7], 0xffffc000, 0x04000, mem_read_bios, mem_read_biosw, mem_read_biosl, mem_write_null, mem_write_nullw, mem_write_nulll, rom + (0x1c000 & biosmask), 0, 0); } +int mem_a20_key = 0, mem_a20_alt = 0; +static int mem_a20_state = 1; + void mem_init() { int c; @@ -1847,6 +1850,8 @@ void mem_resize() mem_mapping_add(&romext_mapping, 0xc8000, 0x08000, mem_read_romext, mem_read_romextw, mem_read_romextl, NULL, NULL, NULL, romext, 0, NULL); // pclog("Mem resize %i %i\n",mem_size,c); + mem_a20_key = 2; + mem_a20_recalc(); } void mem_reset_page_blocks() @@ -1863,9 +1868,6 @@ void mem_reset_page_blocks() } } -int mem_a20_key = 0, mem_a20_alt = 0; -static int mem_a20_state = 0; - void mem_a20_recalc() { int state = mem_a20_key | mem_a20_alt;