| version 1.1, 2003/10/16 17:57:36 | version 1.6, 2003/12/03 07:59:57 | 
| Line 1 | Line 1 | 
 | //---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | 
 | // | // | 
| //  i286y : 80286 Engine for Pentium  ver0.02 | //  i286x : 80286 Engine for Pentium  ver0.02 | 
 | // | // | 
 | //                               Copyright by Yui/Studio Milmake 1999-2000 | //                               Copyright by Yui/Studio Milmake 1999-2000 | 
 | // | // | 
 | //---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | 
 |  |  | 
 |  | #if !defined(CPUDEBUG) | 
 | enum { | enum { | 
 | I286_MEMREADMAX         = 0xa4000, | I286_MEMREADMAX         = 0xa4000, | 
 | I286_MEMWRITEMAX        = 0xa0000 | I286_MEMWRITEMAX        = 0xa0000 | 
 | }; | }; | 
 |  | #else                                                                   // ダイレクトアクセス範囲を狭める | 
 |  | enum { | 
 |  | I286_MEMREADMAX         = 0x00400, | 
 |  | I286_MEMWRITEMAX        = 0x00400 | 
 |  | }; | 
 |  | #endif | 
 |  |  | 
 | #ifndef CPUCALL | #ifndef CPUCALL | 
 | #define CPUCALL | #define CPUCALL | 
| Line 18  enum { | Line 25  enum { | 
 | #if defined(BYTESEX_LITTLE) | #if defined(BYTESEX_LITTLE) | 
 |  |  | 
 | typedef struct { | typedef struct { | 
| BYTE    al; | UINT8   al; | 
| BYTE    ah; | UINT8   ah; | 
| BYTE    cl; | UINT8   cl; | 
| BYTE    ch; | UINT8   ch; | 
| BYTE    dl; | UINT8   dl; | 
| BYTE    dh; | UINT8   dh; | 
| BYTE    bl; | UINT8   bl; | 
| BYTE    bh; | UINT8   bh; | 
| BYTE    sp_l; | UINT8   sp_l; | 
| BYTE    sp_h; | UINT8   sp_h; | 
| BYTE    bp_l; | UINT8   bp_l; | 
| BYTE    bp_h; | UINT8   bp_h; | 
| BYTE    si_l; | UINT8   si_l; | 
| BYTE    si_h; | UINT8   si_h; | 
| BYTE    di_l; | UINT8   di_l; | 
| BYTE    di_h; | UINT8   di_h; | 
| BYTE    es_l; | UINT8   es_l; | 
| BYTE    es_h; | UINT8   es_h; | 
| BYTE    cs_l; | UINT8   cs_l; | 
| BYTE    cs_h; | UINT8   cs_h; | 
| BYTE    ss_l; | UINT8   ss_l; | 
| BYTE    ss_h; | UINT8   ss_h; | 
| BYTE    ds_l; | UINT8   ds_l; | 
| BYTE    ds_h; | UINT8   ds_h; | 
|  | UINT8   flag_l; | 
| BYTE    flag_l; | UINT8   flag_h; | 
| BYTE    flag_h; | UINT8   ip_l; | 
| BYTE    ip_l; | UINT8   ip_h; | 
| BYTE    ip_h; | } I286REG8; | 
| } I286REG_BYTE; |  | 
 |  |  | 
 | #else | #else | 
 |  |  | 
 | typedef struct { | typedef struct { | 
| BYTE    ah; | UINT8   ah; | 
| BYTE    al; | UINT8   al; | 
| BYTE    ch; | UINT8   ch; | 
| BYTE    cl; | UINT8   cl; | 
| BYTE    dh; | UINT8   dh; | 
| BYTE    dl; | UINT8   dl; | 
| BYTE    bh; | UINT8   bh; | 
| BYTE    bl; | UINT8   bl; | 
| BYTE    sp_h; | UINT8   sp_h; | 
| BYTE    sp_l; | UINT8   sp_l; | 
| BYTE    bp_h; | UINT8   bp_h; | 
| BYTE    bp_l; | UINT8   bp_l; | 
| BYTE    si_h; | UINT8   si_h; | 
| BYTE    si_l; | UINT8   si_l; | 
| BYTE    di_h; | UINT8   di_h; | 
| BYTE    di_l; | UINT8   di_l; | 
| BYTE    es_h; | UINT8   es_h; | 
| BYTE    es_l; | UINT8   es_l; | 
| BYTE    cs_h; | UINT8   cs_h; | 
| BYTE    cs_l; | UINT8   cs_l; | 
| BYTE    ss_h; | UINT8   ss_h; | 
| BYTE    ss_l; | UINT8   ss_l; | 
| BYTE    ds_h; | UINT8   ds_h; | 
| BYTE    ds_l; | UINT8   ds_l; | 
| BYTE    flag_h; | UINT8   flag_h; | 
| BYTE    flag_l; | UINT8   flag_l; | 
| BYTE    ip_h; | UINT8   ip_h; | 
| BYTE    ip_l; | UINT8   ip_l; | 
| } I286REG_BYTE; | } I286REG8; | 
 |  |  | 
 | #endif | #endif | 
 |  |  | 
| Line 99  typedef struct { | Line 105  typedef struct { | 
 | UINT16  ds; | UINT16  ds; | 
 | UINT16  flag; | UINT16  flag; | 
 | UINT16  ip; | UINT16  ip; | 
| } I286REG_WORD; | } I286REG16; | 
 |  |  | 
| typedef union { | typedef struct { | 
| I286REG_BYTE    b; | UINT16  limit; | 
| I286REG_WORD    w; | UINT16  base; | 
| } I286REGS; | UINT8   base24; | 
|  | UINT8   reserved; | 
|  | } I286DTR; | 
 |  |  | 
 | typedef struct { | typedef struct { | 
 |  | union { | 
 |  | I286REG8        b; | 
 |  | I286REG16       w; | 
 |  | }               r; | 
 |  | SINT32  remainclock; | 
 |  | SINT32  baseclock; | 
 |  | UINT32  clock; | 
 |  | UINT32  adrsmask;                                               // ver0.72 | 
 | UINT32  es_base; | UINT32  es_base; | 
 | UINT32  cs_base; | UINT32  cs_base; | 
 | UINT32  ss_base; | UINT32  ss_base; | 
| Line 114  typedef struct { | Line 130  typedef struct { | 
 | UINT32  ss_fix; | UINT32  ss_fix; | 
 | UINT32  ds_fix; | UINT32  ds_fix; | 
 | UINT16  prefix; | UINT16  prefix; | 
| BYTE    trap; | UINT8   trap; | 
| BYTE    reserved; | UINT8   cpu_type; | 
 | UINT32  pf_semaphore; | UINT32  pf_semaphore; | 
 | UINT32  repbak; | UINT32  repbak; | 
 | UINT32  inport; | UINT32  inport; | 
 | UINT32  ovflag; | UINT32  ovflag; | 
| BYTE    cpu_type; | I286DTR GDTR; | 
|  | I286DTR IDTR; | 
|  | UINT16  MSW; | 
|  | UINT8   resetreq;                                               // ver0.72 | 
|  | UINT8   itfbank;                                                // ver0.72 | 
 | } I286STAT; | } I286STAT; | 
 |  |  | 
 |  | typedef struct {                                                        // for ver0.73 | 
 |  | UINT    dummy; | 
 |  | } I286EXT; | 
 |  |  | 
 | typedef struct { | typedef struct { | 
| UINT16  limit; | I286STAT        s;                                                      // STATsaveされる奴 | 
| UINT16  base; | I286EXT         e; | 
| BYTE    base24; | } I286CORE; | 
| BYTE    reserved; |  | 
| } I286DTR; |  | 
 |  |  | 
 |  |  | 
 | #ifdef __cplusplus | #ifdef __cplusplus | 
 | extern "C" { | extern "C" { | 
 | #endif | #endif | 
 |  |  | 
| extern  I286REGS        i286r; | extern  I286CORE        i286core; | 
| extern  I286STAT        i286s; |  | 
| extern  I286DTR         GDTR; |  | 
| extern  I286DTR         IDTR; |  | 
| extern  UINT16          MSW; |  | 
 | extern  const BYTE      iflags[]; | extern  const BYTE      iflags[]; | 
 |  |  | 
 |  |  | 
 | #define         I286_MEM                mem | #define         I286_MEM                mem | 
 |  |  | 
| #define         I286_REG                i286r | #define         I286_REG                i286core.s.r | 
| #define         I286_SEGREG             i286r.w.es | #define         I286_SEGREG             i286core.s.r.w.es | 
|  |  | 
|  | #define         I286_AX                 i286core.s.r.w.ax | 
|  | #define         I286_BX                 i286core.s.r.w.bx | 
|  | #define         I286_CX                 i286core.s.r.w.cx | 
|  | #define         I286_DX                 i286core.s.r.w.dx | 
|  | #define         I286_SI                 i286core.s.r.w.si | 
|  | #define         I286_DI                 i286core.s.r.w.di | 
|  | #define         I286_BP                 i286core.s.r.w.bp | 
|  | #define         I286_SP                 i286core.s.r.w.sp | 
|  | #define         I286_CS                 i286core.s.r.w.cs | 
|  | #define         I286_DS                 i286core.s.r.w.ds | 
|  | #define         I286_ES                 i286core.s.r.w.es | 
|  | #define         I286_SS                 i286core.s.r.w.ss | 
|  | #define         I286_IP                 i286core.s.r.w.ip | 
|  |  | 
|  | #define         SEG_BASE                i286core.s.es_base | 
|  | #define         ES_BASE                 i286core.s.es_base | 
|  | #define         CS_BASE                 i286core.s.cs_base | 
|  | #define         SS_BASE                 i286core.s.ss_base | 
|  | #define         DS_BASE                 i286core.s.ds_base | 
|  | #define         SS_FIX                  i286core.s.ss_fix | 
|  | #define         DS_FIX                  i286core.s.ds_fix | 
|  |  | 
|  | #define         I286_AL                 i286core.s.r.b.al | 
|  | #define         I286_BL                 i286core.s.r.b.bl | 
|  | #define         I286_CL                 i286core.s.r.b.cl | 
|  | #define         I286_DL                 i286core.s.r.b.dl | 
|  | #define         I286_AH                 i286core.s.r.b.ah | 
|  | #define         I286_BH                 i286core.s.r.b.bh | 
|  | #define         I286_CH                 i286core.s.r.b.ch | 
|  | #define         I286_DH                 i286core.s.r.b.dh | 
|  |  | 
|  | #define         I286_FLAG               i286core.s.r.w.flag | 
|  | #define         I286_FLAGL              i286core.s.r.b.flag_l | 
|  | #define         I286_FLAGH              i286core.s.r.b.flag_h | 
|  | #define         I286_TRAP               i286core.s.trap | 
|  | #define         I286_OV                 i286core.s.ovflag | 
|  |  | 
|  | #define         I286_REMCLOCK   i286core.s.remainclock | 
|  | #define         I286_BASECLOCK  i286core.s.baseclock | 
|  | #define         I286_CLOCK              i286core.s.clock | 
 |  |  | 
 | #define         I286_AX                 i286r.w.ax |  | 
 | #define         I286_BX                 i286r.w.bx |  | 
 | #define         I286_CX                 i286r.w.cx |  | 
 | #define         I286_DX                 i286r.w.dx |  | 
 | #define         I286_SI                 i286r.w.si |  | 
 | #define         I286_DI                 i286r.w.di |  | 
 | #define         I286_BP                 i286r.w.bp |  | 
 | #define         I286_SP                 i286r.w.sp |  | 
 | #define         I286_CS                 i286r.w.cs |  | 
 | #define         I286_DS                 i286r.w.ds |  | 
 | #define         I286_ES                 i286r.w.es |  | 
 | #define         I286_SS                 i286r.w.ss |  | 
 | #define         I286_IP                 i286r.w.ip |  | 
 |  |  | 
 | #define         SEG_BASE                i286s.es_base |  | 
 | #define         ES_BASE                 i286s.es_base |  | 
 | #define         CS_BASE                 i286s.cs_base |  | 
 | #define         SS_BASE                 i286s.ss_base |  | 
 | #define         DS_BASE                 i286s.ds_base |  | 
 | #define         SS_FIX                  i286s.ss_fix |  | 
 | #define         DS_FIX                  i286s.ds_fix |  | 
 |  |  | 
 | #define         I286_AL                 i286r.b.al |  | 
 | #define         I286_BL                 i286r.b.bl |  | 
 | #define         I286_CL                 i286r.b.cl |  | 
 | #define         I286_DL                 i286r.b.dl |  | 
 | #define         I286_AH                 i286r.b.ah |  | 
 | #define         I286_BH                 i286r.b.bh |  | 
 | #define         I286_CH                 i286r.b.ch |  | 
 | #define         I286_DH                 i286r.b.dh |  | 
 |  |  | 
 | #define         I286_FLAG               i286r.w.flag |  | 
 | #define         I286_FLAGL              i286r.b.flag_l |  | 
 | #define         I286_FLAGH              i286r.b.flag_h |  | 
 | #define         I286_TRAP               i286s.trap |  | 
 | #define         I286_OV                 i286s.ovflag |  | 
 |  |  | 
 | #define         C_FLAG                  0x0001 |  | 
 | #define         P_FLAG                  0x0004 |  | 
 | #define         A_FLAG                  0x0010 |  | 
 | #define         Z_FLAG                  0x0040 |  | 
 | #define         S_FLAG                  0x0080 |  | 
 | #define         T_FLAG                  0x0100 |  | 
 | #define         I_FLAG                  0x0200 |  | 
 | #define         D_FLAG                  0x0400 |  | 
 | #define         O_FLAG                  0x0800 |  | 
 |  |  | 
| #define         CPUTYPE                 i286s.cpu_type | enum { | 
|  | C_FLAG                  = 0x0001, | 
|  | P_FLAG                  = 0x0004, | 
|  | A_FLAG                  = 0x0010, | 
|  | Z_FLAG                  = 0x0040, | 
|  | S_FLAG                  = 0x0080, | 
|  | T_FLAG                  = 0x0100, | 
|  | I_FLAG                  = 0x0200, | 
|  | D_FLAG                  = 0x0400, | 
|  | O_FLAG                  = 0x0800 | 
|  | }; | 
|  |  | 
|  | #define         CPUTYPE                 i286core.s.cpu_type | 
 | #define         CPUTYPE_V30             0x01 | #define         CPUTYPE_V30             0x01 | 
 |  |  | 
 | // ver0.28 | // ver0.28 | 
| #define         REPPOSBAK               i286s.repbak | #define         REPPOSBAK               i286core.s.repbak | 
| #define         PREFIX_SMP              i286s.pf_semaphore | #define         PREFIX_SMP              i286core.s.pf_semaphore | 
 |  |  | 
 | #define         isI286DI                (!(I286_FLAG & I_FLAG)) | #define         isI286DI                (!(I286_FLAG & I_FLAG)) | 
 | #define         isI286EI                (I286_FLAG & I_FLAG) | #define         isI286EI                (I286_FLAG & I_FLAG) | 
| Line 219  void CPUCALL i286_interrupt(BYTE vect); | Line 244  void CPUCALL i286_interrupt(BYTE vect); | 
 | void i286(void); | void i286(void); | 
 | void i286_step(void); | void i286_step(void); | 
 |  |  | 
| #define v30                             i286 | void v30(void); | 
| #define v30_step                i286_step | void v30_step(void); | 
 |  |  | 
 | #ifdef __cplusplus | #ifdef __cplusplus | 
 | } | } |