|
|
| version 1.3, 2003/10/17 11:10:02 | version 1.14, 2003/12/12 01:04:40 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "i286.h" | #include "cpucore.h" |
| #include "i286c.h" | #include "i286c.h" |
| #include "memory.h" | #include "v30patch.h" |
| #include "pccore.h" | #include "pccore.h" |
| #include "iocore.h" | #include "iocore.h" |
| #include "dmap.h" | #include "dmap.h" |
| #include "i286c.mcr" | #include "i286c.mcr" |
| I286REG i286reg; | I286CORE i286core; |
| const BYTE iflags[256] = { // Z_FLAG, S_FLAG, P_FLAG | const UINT8 iflags[256] = { // Z_FLAG, S_FLAG, P_FLAG |
| 0x44, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, | 0x44, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, |
| 0x00, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, | 0x00, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, |
| 0x00, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, | 0x00, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, |
| Line 47 const BYTE iflags[256] = { // Z_FLAG | Line 47 const BYTE iflags[256] = { // Z_FLAG |
| // ---- | // ---- |
| UINT32 EA_FIX; | UINT8 _szpcflag8[0x200]; |
| BYTE *reg8_b53[256]; | |
| BYTE *reg8_b20[256]; | |
| UINT16 *reg16_b53[256]; | |
| UINT16 *reg16_b20[256]; | |
| BYTE szpcflag[0x200]; | |
| BYTE szpflag_w[0x10000]; | |
| CALCEA c_calc_ea_dst[256]; | |
| CALCLEA c_calc_lea[192]; | |
| GETLEA c_get_ea[192]; | |
| #if !defined(MEMOPTIMIZE) | |
| UINT8 _szpflag16[0x10000]; | |
| #endif | |
| static UINT32 ea_nop(void) { | #if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) |
| UINT8 *_reg8_b53[256]; | |
| return(0); | UINT8 *_reg8_b20[256]; |
| } | #endif |
| #if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) | |
| UINT16 *_reg16_b53[256]; | |
| UINT16 *_reg16_b20[256]; | |
| #endif | |
| void i286_initialize(void) { | void i286c_initialize(void) { |
| UINT i; | UINT i; |
| UINT bit; | UINT bit; |
| BYTE f; | REG8 f; |
| int pos; | |
| for (i=0; i<0x100; i++) { | for (i=0; i<0x100; i++) { |
| f = P_FLAG; | f = P_FLAG; |
| Line 84 void i286_initialize(void) { | Line 81 void i286_initialize(void) { |
| if (i & 0x80) { | if (i & 0x80) { |
| f |= S_FLAG; | f |= S_FLAG; |
| } | } |
| szpcflag[i+0x000] = f; | _szpcflag8[i+0x000] = f; |
| szpcflag[i+0x100] = f | C_FLAG; | _szpcflag8[i+0x100] = f | C_FLAG; |
| } | } |
| #if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) | |
| for (i=0; i<0x100; i++) { | for (i=0; i<0x100; i++) { |
| int pos; | |
| #if defined(BYTESEX_LITTLE) | #if defined(BYTESEX_LITTLE) |
| pos = ((i & 0x20)?1:0); | pos = ((i & 0x20)?1:0); |
| #else | #else |
| pos = ((i & 0x20)?0:1); | pos = ((i & 0x20)?0:1); |
| #endif | #endif |
| pos += ((i >> 3) & 3) * 2; | pos += ((i >> 3) & 3) * 2; |
| reg8_b53[i] = ((BYTE *)&I286_REG) + pos; | _reg8_b53[i] = ((UINT8 *)&I286_REG) + pos; |
| #if defined(BYTESEX_LITTLE) | #if defined(BYTESEX_LITTLE) |
| pos = ((i & 0x4)?1:0); | pos = ((i & 0x4)?1:0); |
| #else | #else |
| pos = ((i & 0x4)?0:1); | pos = ((i & 0x4)?0:1); |
| #endif | #endif |
| pos += (i & 3) * 2; | pos += (i & 3) * 2; |
| reg8_b20[i] = ((BYTE *)&I286_REG) + pos; | _reg8_b20[i] = ((UINT8 *)&I286_REG) + pos; |
| reg16_b53[i] = ((UINT16 *)&I286_REG) + ((i >> 3) & 7); | #if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) |
| reg16_b20[i] = ((UINT16 *)&I286_REG) + (i & 7); | _reg16_b53[i] = ((UINT16 *)&I286_REG) + ((i >> 3) & 7); |
| _reg16_b20[i] = ((UINT16 *)&I286_REG) + (i & 7); | |
| #endif | |
| } | } |
| #endif | |
| for (i=0; i<0xc0; i++) { | #if !defined(MEMOPTIMIZE) |
| pos = ((i >> 3) & 0x18) + (i & 0x07); | |
| c_calc_ea_dst[i] = i286c_ea_dst_tbl[pos]; | |
| c_calc_lea[i] = i286c_lea_tbl[pos]; | |
| c_get_ea[i] = i286c_ea_tbl[pos]; | |
| } | |
| for (; i<0x100; i++) { | |
| c_calc_ea_dst[i] = ea_nop; | |
| } | |
| for (i=0; i<0x10000; i++) { | for (i=0; i<0x10000; i++) { |
| f = P_FLAG; | f = P_FLAG; |
| for (bit=0x80; bit; bit>>=1) { | for (bit=0x80; bit; bit>>=1) { |
| Line 129 void i286_initialize(void) { | Line 123 void i286_initialize(void) { |
| if (i & 0x8000) { | if (i & 0x8000) { |
| f |= S_FLAG; | f |= S_FLAG; |
| } | } |
| szpflag_w[i] = f; | _szpflag16[i] = f; |
| } | } |
| #endif | |
| #if !defined(MEMOPTIMIZE) || (MEMOPTIMIZE < 2) | |
| i286cea_initialize(); | |
| #endif | |
| v30cinit(); | |
| } | } |
| void i286_reset(void) { | void i286c_reset(void) { |
| i286_initialize(); | ZeroMemory(&I286_STAT, sizeof(I286_STAT)); |
| ZeroMemory(&i286reg, sizeof(i286reg)); | |
| I286_CS = 0x1fc0; | I286_CS = 0x1fc0; |
| CS_BASE = 0x1fc00; | CS_BASE = 0x1fc00; |
| I286_ADRSMASK = 0xfffff; | |
| } | } |
| void i286_resetprefetch(void) { | void CPUCALL i286c_intnum(UINT vect, REG16 IP) { |
| } | |
| void CPUCALL i286_intnum(UINT vect, UINT16 IP) { | |
| const BYTE *ptr; | const BYTE *ptr; |
| Line 155 const BYTE *ptr; | Line 151 const BYTE *ptr; |
| I286_FLAG &= ~(T_FLAG | I_FLAG); | I286_FLAG &= ~(T_FLAG | I_FLAG); |
| I286_TRAP = 0; | I286_TRAP = 0; |
| ptr = I286_MEM + (vect * 4); | ptr = mem + (vect * 4); |
| I286_IP = LOADINTELWORD(ptr+0); // real mode! | I286_IP = LOADINTELWORD(ptr+0); // real mode! |
| I286_CS = LOADINTELWORD(ptr+2); // real mode! | I286_CS = LOADINTELWORD(ptr+2); // real mode! |
| CS_BASE = I286_CS << 4; | CS_BASE = I286_CS << 4; |
| I286_CLOCK(20) | I286_WORKCLOCK(20); |
| } | } |
| void CPUCALL i286_interrupt(BYTE vect) { | void CPUCALL i286c_interrupt(REG8 vect) { |
| UINT op; | UINT op; |
| const BYTE *ptr; | const BYTE *ptr; |
| Line 171 const BYTE *ptr; | Line 167 const BYTE *ptr; |
| if (op == 0xf4) { // hlt | if (op == 0xf4) { // hlt |
| I286_IP++; | I286_IP++; |
| } | } |
| REGPUSH0(REAL_FLAGREG) | REGPUSH0(REAL_FLAGREG) // ここV30で辻褄が合わない |
| REGPUSH0(I286_CS) | REGPUSH0(I286_CS) |
| REGPUSH0(I286_IP) | REGPUSH0(I286_IP) |
| I286_FLAG &= ~(T_FLAG | I_FLAG); | I286_FLAG &= ~(T_FLAG | I_FLAG); |
| I286_TRAP = 0; | I286_TRAP = 0; |
| ptr = I286_MEM + (vect * 4); | ptr = mem + (vect * 4); |
| I286_IP = LOADINTELWORD(ptr+0); // real mode! | I286_IP = LOADINTELWORD(ptr + 0); // real mode! |
| I286_CS = LOADINTELWORD(ptr+2); // real mode! | I286_CS = LOADINTELWORD(ptr + 2); // real mode! |
| CS_BASE = I286_CS << 4; | CS_BASE = I286_CS << 4; |
| I286_CLOCK(20) | I286_WORKCLOCK(20); |
| } | } |
| void i286(void) { | void i286c(void) { |
| UINT opcode; | UINT opcode; |
| Line 194 void i286(void) { | Line 190 void i286(void) { |
| GET_PCBYTE(opcode); | GET_PCBYTE(opcode); |
| i286op[opcode](); | i286op[opcode](); |
| if (I286_TRAP) { | if (I286_TRAP) { |
| i286_interrupt(1); | i286c_interrupt(1); |
| } | } |
| dmap_i286(); | dmap_i286(); |
| } while(nevent.remainclock > 0); | } while(I286_REMCLOCK > 0); |
| } | } |
| else if (dmac.working) { | else if (dmac.working) { |
| do { | do { |
| GET_PCBYTE(opcode); | GET_PCBYTE(opcode); |
| i286op[opcode](); | i286op[opcode](); |
| dmap_i286(); | dmap_i286(); |
| } while(nevent.remainclock > 0); | } while(I286_REMCLOCK > 0); |
| } | } |
| else { | else { |
| do { | do { |
| GET_PCBYTE(opcode); | GET_PCBYTE(opcode); |
| i286op[opcode](); | i286op[opcode](); |
| } while(nevent.remainclock > 0); | } while(I286_REMCLOCK > 0); |
| } | } |
| } | } |
| void i286_step(void) { | void i286c_step(void) { |
| UINT opcode; | UINT opcode; |
| Line 231 void i286_step(void) { | Line 227 void i286_step(void) { |
| dmap_i286(); | dmap_i286(); |
| } | } |
| // ---- test | |
| #if defined(I286C_TEST) | |
| BYTE BYTESZPF(UINT r) { | |
| if (r & (~0xff)) { | |
| TRACEOUT(("BYTESZPF bound error: %x", r)); | |
| } | |
| return(_szpcflag8[r & 0xff]); | |
| } | |
| BYTE BYTESZPCF(UINT r) { | |
| if (r & (~0x1ff)) { | |
| TRACEOUT(("BYTESZPCF bound error: %x", r)); | |
| } | |
| return(_szpcflag8[r & 0x1ff]); | |
| } | |
| BYTE WORDSZPF(UINT32 r) { | |
| BYTE f1; | |
| BYTE f2; | |
| if (r & (~0xffff)) { | |
| TRACEOUT(("WORDSZPF bound error: %x", r)); | |
| } | |
| f1 = _szpflag16[r & 0xffff]; | |
| f2 = _szpcflag8[r & 0xff] & P_FLAG; | |
| f2 += (r)?0:Z_FLAG; | |
| f2 += (r >> 8) & S_FLAG; | |
| if (f1 != f2) { | |
| TRACEOUT(("word flag error: %.2x %.2x", f1, f2)); | |
| } | |
| return(f1); | |
| } | |
| BYTE WORDSZPCF(UINT32 r) { | |
| BYTE f1; | |
| BYTE f2; | |
| if ((r & 0xffff0000) && (!(r & 0x00010000))) { | |
| TRACEOUT(("WORDSZPCF bound error: %x", r)); | |
| } | |
| f1 = (r >> 16) & 1; | |
| f1 += _szpflag16[LOW16(r)]; | |
| f2 = _szpcflag8[r & 0xff] & P_FLAG; | |
| f2 += (LOW16(r))?0:Z_FLAG; | |
| f2 += (r >> 8) & S_FLAG; | |
| f2 += (r >> 16) & 1; | |
| if (f1 != f2) { | |
| TRACEOUT(("word flag error: %.2x %.2x", f1, f2)); | |
| } | |
| return(f1); | |
| } | |
| #endif | |