--- np2/i286c/i286c.c 2003/12/08 00:55:31 1.13 +++ np2/i286c/i286c.c 2004/01/25 07:53:08 1.24 @@ -2,7 +2,6 @@ #include "cpucore.h" #include "i286c.h" #include "v30patch.h" -#include "memory.h" #include "pccore.h" #include "iocore.h" #include "dmap.h" @@ -11,7 +10,7 @@ I286CORE i286core; -const UINT8 iflags[256] = { // Z_FLAG, S_FLAG, P_FLAG +const UINT8 iflags[512] = { // Z_FLAG, S_FLAG, P_FLAG 0x44, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, @@ -43,13 +42,43 @@ const UINT8 iflags[256] = { // Z_FLA 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84, 0x84, 0x80, 0x80, 0x84, 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84, 0x80, 0x84, 0x84, 0x80, - 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84}; + 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84, + 0x45, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x01, 0x05, 0x05, 0x01, 0x05, 0x01, 0x01, 0x05, + 0x05, 0x01, 0x01, 0x05, 0x01, 0x05, 0x05, 0x01, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x85, 0x81, 0x81, 0x85, 0x81, 0x85, 0x85, 0x81, + 0x81, 0x85, 0x85, 0x81, 0x85, 0x81, 0x81, 0x85}; // ---- - UINT8 _szpcflag8[0x200]; - #if !defined(MEMOPTIMIZE) UINT8 _szpflag16[0x10000]; #endif @@ -65,26 +94,9 @@ const UINT8 iflags[256] = { // Z_FLA void i286c_initialize(void) { +#if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) UINT i; - UINT bit; - REG8 f; - - for (i=0; i<0x100; i++) { - f = P_FLAG; - for (bit=0x80; bit; bit>>=1) { - if (i & bit) { - f ^= P_FLAG; - } - } - if (!(i & 0xff)) { - f |= Z_FLAG; - } - if (i & 0x80) { - f |= S_FLAG; - } - _szpcflag8[i+0x000] = f; - _szpcflag8[i+0x100] = f | C_FLAG; - } +#endif #if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) for (i=0; i<0x100; i++) { @@ -112,6 +124,8 @@ void i286c_initialize(void) { #if !defined(MEMOPTIMIZE) for (i=0; i<0x10000; i++) { + REG8 f; + UINT bit; f = P_FLAG; for (bit=0x80; bit; bit>>=1) { if (i & bit) { @@ -131,16 +145,77 @@ void i286c_initialize(void) { i286cea_initialize(); #endif v30cinit(); + ZeroMemory(&i286core, sizeof(i286core)); } -void i286c_reset(void) { +void i286c_deinitialize(void) { - ZeroMemory(&I286_STAT, sizeof(I286_STAT)); - I286_CS = 0x1fc0; - CS_BASE = 0x1fc00; + if (CPU_EXTMEM) { + _MFREE(CPU_EXTMEM); + CPU_EXTMEM = NULL; + CPU_EXTMEMSIZE = 0; + } +} + +static void i286c_initreg(void) { + + I286_CS = 0xf000; + CS_BASE = 0xf0000; + I286_IP = 0xfff0; I286_ADRSMASK = 0xfffff; } +void i286c_reset(void) { + + ZeroMemory(&i286core.s, sizeof(i286core.s)); + i286c_initreg(); +} + +void i286c_shut(void) { + + ZeroMemory(&i286core.s, offsetof(I286STAT, cpu_type)); + i286c_initreg(); +} + +void i286c_setextsize(UINT32 size) { + + if (CPU_EXTMEMSIZE != size) { + if (CPU_EXTMEM) { + _MFREE(CPU_EXTMEM); + CPU_EXTMEM = NULL; + } + if (size) { + CPU_EXTMEM = (BYTE *)_MALLOC(size + 16, "EXTMEM"); + if (CPU_EXTMEM == NULL) { + size = 0; + } + } + CPU_EXTMEMSIZE = size; + } + i286core.e.ems[0] = mem + 0xc0000; + i286core.e.ems[1] = mem + 0xc4000; + i286core.e.ems[2] = mem + 0xc8000; + i286core.e.ems[3] = mem + 0xcc000; +} + +void i286c_setemm(UINT frame, UINT32 addr) { + + BYTE *ptr; + + frame &= 3; + if (addr < USE_HIMEM) { + ptr = mem + addr; + } + else if ((addr - 0x100000 + 0x4000) <= CPU_EXTMEMSIZE) { + ptr = CPU_EXTMEM + (addr - 0x100000); + } + else { + ptr = mem + 0xc0000 + (frame << 14); + } + i286core.e.ems[frame] = ptr; +} + + void CPUCALL i286c_intnum(UINT vect, REG16 IP) { const BYTE *ptr; @@ -152,7 +227,7 @@ const BYTE *ptr; I286_FLAG &= ~(T_FLAG | I_FLAG); I286_TRAP = 0; - ptr = I286_MEM + (vect * 4); + ptr = mem + (vect * 4); I286_IP = LOADINTELWORD(ptr+0); // real mode! I286_CS = LOADINTELWORD(ptr+2); // real mode! CS_BASE = I286_CS << 4; @@ -175,7 +250,7 @@ const BYTE *ptr; I286_FLAG &= ~(T_FLAG | I_FLAG); I286_TRAP = 0; - ptr = I286_MEM + (vect * 4); + ptr = mem + (vect * 4); I286_IP = LOADINTELWORD(ptr + 0); // real mode! I286_CS = LOADINTELWORD(ptr + 2); // real mode! CS_BASE = I286_CS << 4; @@ -237,7 +312,7 @@ BYTE BYTESZPF(UINT r) { if (r & (~0xff)) { TRACEOUT(("BYTESZPF bound error: %x", r)); } - return(_szpcflag8[r & 0xff]); + return(iflags[r & 0xff]); } BYTE BYTESZPCF(UINT r) { @@ -245,7 +320,7 @@ BYTE BYTESZPCF(UINT r) { if (r & (~0x1ff)) { TRACEOUT(("BYTESZPCF bound error: %x", r)); } - return(_szpcflag8[r & 0x1ff]); + return(iflags[r & 0x1ff]); } BYTE WORDSZPF(UINT32 r) { @@ -257,7 +332,7 @@ BYTE WORDSZPF(UINT32 r) { TRACEOUT(("WORDSZPF bound error: %x", r)); } f1 = _szpflag16[r & 0xffff]; - f2 = _szpcflag8[r & 0xff] & P_FLAG; + f2 = iflags[r & 0xff] & P_FLAG; f2 += (r)?0:Z_FLAG; f2 += (r >> 8) & S_FLAG; if (f1 != f2) { @@ -277,7 +352,7 @@ BYTE WORDSZPCF(UINT32 r) { f1 = (r >> 16) & 1; f1 += _szpflag16[LOW16(r)]; - f2 = _szpcflag8[r & 0xff] & P_FLAG; + f2 = iflags[r & 0xff] & P_FLAG; f2 += (LOW16(r))?0:Z_FLAG; f2 += (r >> 8) & S_FLAG; f2 += (r >> 16) & 1;