| 1 | /**************************************************************************** |
| 2 | |
| 3 | NEC V30MZ emulator |
| 4 | |
| 5 | Stripped out non-V30MZ clock counts and code. |
| 6 | |
| 7 | Small changes made by [email protected] (Corrected bug in NEG instruction , different AUX flag handling in some opcodes) |
| 8 | |
| 9 | (Re)Written June-September 2000 by Bryan McPhail ([email protected]) based |
| 10 | on code by Oliver Bergmann ([email protected]) who based code |
| 11 | on the i286 emulator by Fabrice Frances which had initial work based on |
| 12 | David Hedley's pcemu(!). |
| 13 | |
| 14 | ****************************************************************************/ |
| 15 | |
| 16 | /* This NEC V30MZ emulator may be used for purposes both commercial and noncommercial if you give the author, Bryan McPhail, |
| 17 | a small credit somewhere(such as in the documentation for an executable package). |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | TODO: |
| 22 | Implement bus lock fully(prevent interrupts from occuring during a REP sequence, I think...), taking into account |
| 23 | HLT emulation to prevent deadlocks! |
| 24 | |
| 25 | Implement better prefix emulation. It's extremely kludgey right now. |
| 26 | |
| 27 | Implement prefetch/pipeline emulation. |
| 28 | */ |
| 29 | |
| 30 | #include <string.h> |
| 31 | |
| 32 | #include "interrupt.h" |
| 33 | #include "wswan.h" |
| 34 | #include "wswan-memory.h" |
| 35 | |
| 36 | #include "v30mz.h" |
| 37 | |
| 38 | #include "../state_inline.h" |
| 39 | |
| 40 | typedef enum { DS1, PS, SS, DS0 } SREGS; |
| 41 | typedef enum { AW, CW, DW, BW, SP, BP, IX, IY } WREGS; |
| 42 | |
| 43 | #define NEC_NMI_INT_VECTOR 2 |
| 44 | |
| 45 | typedef enum |
| 46 | { |
| 47 | #ifdef MSB_FIRST |
| 48 | AH,AL, |
| 49 | CH,CL, |
| 50 | DH,DL, |
| 51 | BH,BL, |
| 52 | SPH,SPL, |
| 53 | BPH,BPL, |
| 54 | IXH,IXL, |
| 55 | IYH,IYL |
| 56 | #else |
| 57 | AL,AH, |
| 58 | CL,CH, |
| 59 | DL,DH, |
| 60 | BL,BH, |
| 61 | SPL,SPH, |
| 62 | BPL,BPH, |
| 63 | IXL,IXH, |
| 64 | IYL,IYH |
| 65 | #endif |
| 66 | } BREGS; |
| 67 | |
| 68 | /* parameter x = result, y = source 1, z = source 2 */ |
| 69 | |
| 70 | #define SetTF(x) (I.TF = (x)) |
| 71 | #define SetIF(x) (I.IF = (x)) |
| 72 | #define SetDF(x) (I.DF = (x)) |
| 73 | |
| 74 | #define SetCFB(x) (I.CarryVal = (x) & 0x100) |
| 75 | #define SetCFW(x) (I.CarryVal = (x) & 0x10000) |
| 76 | |
| 77 | #define SetAF(x,y,z) (I.AuxVal = ((x) ^ ((y) ^ (z))) & 0x10) |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | #define SetSF(x) (I.SignVal = (x)) |
| 83 | #define SetZF(x) (I.ZeroVal = (x)) |
| 84 | #define SetPF(x) (I.ParityVal = (x)) |
| 85 | |
| 86 | #define SetSZPF_Byte(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int8)(x)) |
| 87 | #define SetSZPF_Word(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int16)(x)) |
| 88 | |
| 89 | #define SetOFW_Add(x,y,z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x8000) |
| 90 | #define SetOFB_Add(x,y,z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x80) |
| 91 | #define SetOFW_Sub(x,y,z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x8000) |
| 92 | #define SetOFB_Sub(x,y,z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x80) |
| 93 | |
| 94 | #define ADDB { uint32 res=dst+src; SetCFB(res); SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(uint8)res; } |
| 95 | #define ADDW { uint32 res=dst+src; SetCFW(res); SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(uint16)res; } |
| 96 | |
| 97 | #define SUBB { uint32 res=dst-src; SetCFB(res); SetOFB_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(uint8)res; } |
| 98 | #define SUBW { uint32 res=dst-src; SetCFW(res); SetOFW_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(uint16)res; } |
| 99 | |
| 100 | #define ORB dst|=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Byte(dst) |
| 101 | #define ORW dst|=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Word(dst) |
| 102 | |
| 103 | #define ANDB dst&=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Byte(dst) |
| 104 | #define ANDW dst&=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Word(dst) |
| 105 | |
| 106 | #define XORB dst^=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Byte(dst) |
| 107 | #define XORW dst^=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Word(dst) |
| 108 | |
| 109 | #define CF (I.CarryVal!=0) |
| 110 | #define SF (I.SignVal<0) |
| 111 | #define ZF (I.ZeroVal==0) |
| 112 | #define PF parity_table[(uint8)I.ParityVal] |
| 113 | #define AF (I.AuxVal!=0) |
| 114 | #define FLAG_O (I.OverVal!=0) |
| 115 | |
| 116 | /************************************************************************/ |
| 117 | |
| 118 | #define SegBase(Seg) (I.sregs[Seg] << 4) |
| 119 | |
| 120 | #define DefaultBase(Seg) ((seg_prefix && (Seg==DS0 || Seg==SS)) ? prefix_base : I.sregs[Seg] << 4) |
| 121 | |
| 122 | #define GetMemB(Seg,Off) ((uint8)PhysRead8((DefaultBase(Seg)+(Off)))) |
| 123 | #define GetMemW(Seg,Off) ((uint16)PhysRead16((DefaultBase(Seg)+(Off)))) |
| 124 | |
| 125 | #define PutMemB(Seg,Off,x) { cpu_writemem20((DefaultBase(Seg)+(Off)),(x)); } |
| 126 | #define PutMemW(Seg,Off,x) { PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(uint8)((x)>>8)); } |
| 127 | |
| 128 | /* Todo: Remove these later - plus readword could overflow */ |
| 129 | #define ReadByte(ea) ((uint8)PhysRead8((ea))) |
| 130 | #define ReadWord(ea) (PhysRead16((ea))) |
| 131 | #define WriteByte(ea,val) { cpu_writemem20((ea),val); } |
| 132 | #define WriteWord(ea,val) { cpu_writemem20((ea),(uint8)(val)); cpu_writemem20(((ea)+1),(val)>>8); } |
| 133 | |
| 134 | #define read_port(port) cpu_readport(port) |
| 135 | #define write_port(port,val) cpu_writeport(port,val) |
| 136 | |
| 137 | /* Cycle count macros: |
| 138 | CLK - cycle count is the same on all processors |
| 139 | CLKM - cycle count for reg/mem instructions |
| 140 | |
| 141 | |
| 142 | Prefetch & buswait time is not emulated. |
| 143 | Extra cycles for PUSH'ing or POP'ing registers to odd addresses is not emulated. |
| 144 | */ |
| 145 | |
| 146 | #define _REAL_CLK(cycles) { v30mz_ICount -= cycles; v30mz_timestamp += cycles; } |
| 147 | #define CLK _REAL_CLK |
| 148 | |
| 149 | #define CLKM(mcount, ccount) { if(ModRM >=0xc0 ) { CLK(ccount);} else {CLK(mcount);} } |
| 150 | |
| 151 | |
| 152 | #define PUSH(val) \ |
| 153 | { \ |
| 154 | I.regs.w[SP] -= 2; \ |
| 155 | WriteWord((((I.sregs[SS]<<4)+I.regs.w[SP])),val); \ |
| 156 | } |
| 157 | |
| 158 | #define POP(var) \ |
| 159 | { \ |
| 160 | var = ReadWord((((I.sregs[SS]<<4)+I.regs.w[SP]))); \ |
| 161 | I.regs.w[SP]+=2; \ |
| 162 | } |
| 163 | |
| 164 | #define POPNOVAR() \ |
| 165 | { \ |
| 166 | ReadWord((((I.sregs[SS]<<4)+I.regs.w[SP]))); \ |
| 167 | I.regs.w[SP]+=2; \ |
| 168 | } |
| 169 | |
| 170 | #define FETCH (PhysRead8((I.sregs[PS]<<4)+I.pc++)) |
| 171 | #define FETCHOP (PhysRead8((I.sregs[PS]<<4)+I.pc++)) |
| 172 | #define FETCHuint16(var) { var=PhysRead16((((I.sregs[PS]<<4)+I.pc))); I.pc+=2; } |
| 173 | #define PEEK(addr) ((uint8)Physread8(addr)) |
| 174 | #define PEEKOP(addr) ((uint8)PhysRead8(addr)) |
| 175 | |
| 176 | #define GetModRM uint32 ModRM=PhysRead8((I.sregs[PS]<<4)+I.pc++) |
| 177 | |
| 178 | #define CompressFlags() (uint16)(CF | (PF << 2) | (AF << 4) | (ZF << 6) \ |
| 179 | | (SF << 7) | (I.TF << 8) | (I.IF << 9) \ |
| 180 | | (I.DF << 10) | (FLAG_O << 11) | (0xF002)) |
| 181 | |
| 182 | #define ExpandFlags(f) \ |
| 183 | { \ |
| 184 | I.CarryVal = (f) & 1; \ |
| 185 | I.ParityVal = !((f) & 4); \ |
| 186 | I.AuxVal = (f) & 16; \ |
| 187 | I.ZeroVal = !((f) & 64); \ |
| 188 | I.SignVal = (f) & 128 ? -1 : 0; \ |
| 189 | I.TF = ((f) & 256) == 256; \ |
| 190 | I.IF = ((f) & 512) == 512; \ |
| 191 | I.DF = ((f) & 1024) == 1024; \ |
| 192 | I.OverVal = (f) & 2048; \ |
| 193 | } |
| 194 | |
| 195 | |
| 196 | |
| 197 | #define IncWordReg(Reg) \ |
| 198 | unsigned tmp = (unsigned)I.regs.w[Reg]; \ |
| 199 | unsigned tmp1 = tmp+1; \ |
| 200 | I.OverVal = (tmp == 0x7fff); \ |
| 201 | SetAF(tmp1,tmp,1); \ |
| 202 | SetSZPF_Word(tmp1); \ |
| 203 | I.regs.w[Reg]=tmp1 |
| 204 | |
| 205 | |
| 206 | |
| 207 | #define DecWordReg(Reg) \ |
| 208 | unsigned tmp = (unsigned)I.regs.w[Reg]; \ |
| 209 | unsigned tmp1 = tmp-1; \ |
| 210 | I.OverVal = (tmp == 0x8000); \ |
| 211 | SetAF(tmp1,tmp,1); \ |
| 212 | SetSZPF_Word(tmp1); \ |
| 213 | I.regs.w[Reg]=tmp1 |
| 214 | |
| 215 | #define JMP(flag) \ |
| 216 | int tmp = (int)((int8)FETCH); \ |
| 217 | if (flag) \ |
| 218 | { \ |
| 219 | I.pc = (uint16)(I.pc+tmp); \ |
| 220 | CLK(3); \ |
| 221 | return; \ |
| 222 | } |
| 223 | |
| 224 | #define ADJ4(param1,param2) \ |
| 225 | if (AF || ((I.regs.b[AL] & 0xf) > 9)) \ |
| 226 | { \ |
| 227 | uint16 tmp; \ |
| 228 | tmp = I.regs.b[AL] + param1; \ |
| 229 | I.regs.b[AL] = tmp; \ |
| 230 | I.AuxVal = 1; \ |
| 231 | I.CarryVal |= tmp & 0x100; /*if(tmp&0x100){puts("Meow"); }*//* Correct? */ \ |
| 232 | } \ |
| 233 | if (CF || (I.regs.b[AL] > 0x9f)) \ |
| 234 | { \ |
| 235 | I.regs.b[AL] += param2; \ |
| 236 | I.CarryVal = 1; \ |
| 237 | } \ |
| 238 | SetSZPF_Byte(I.regs.b[AL]) |
| 239 | |
| 240 | #define ADJB(param1,param2) \ |
| 241 | if (AF || ((I.regs.b[AL] & 0xf) > 9)) \ |
| 242 | { \ |
| 243 | I.regs.b[AL] += param1; \ |
| 244 | I.regs.b[AH] += param2; \ |
| 245 | I.AuxVal = 1; \ |
| 246 | I.CarryVal = 1; \ |
| 247 | } \ |
| 248 | else \ |
| 249 | { \ |
| 250 | I.AuxVal = 0; \ |
| 251 | I.CarryVal = 0; \ |
| 252 | } \ |
| 253 | I.regs.b[AL] &= 0x0F |
| 254 | |
| 255 | #define BIT_NOT \ |
| 256 | if (tmp & (1<<tmp2)) \ |
| 257 | tmp &= ~(1<<tmp2); \ |
| 258 | else \ |
| 259 | tmp |= (1<<tmp2) |
| 260 | |
| 261 | #define XchgAWReg(Reg) \ |
| 262 | uint16 tmp; \ |
| 263 | tmp = I.regs.w[Reg]; \ |
| 264 | I.regs.w[Reg] = I.regs.w[AW]; \ |
| 265 | I.regs.w[AW] = tmp |
| 266 | |
| 267 | #define ROL_uint8 I.CarryVal = dst & 0x80; dst = (dst << 1)+CF |
| 268 | #define ROL_uint16 I.CarryVal = dst & 0x8000; dst = (dst << 1)+CF |
| 269 | #define ROR_uint8 I.CarryVal = dst & 0x1; dst = (dst >> 1)+(CF<<7) |
| 270 | #define ROR_uint16 I.CarryVal = dst & 0x1; dst = (dst >> 1)+(CF<<15) |
| 271 | #define ROLC_uint8 dst = (dst << 1) + CF; SetCFB(dst) |
| 272 | #define ROLC_uint16 dst = (dst << 1) + CF; SetCFW(dst) |
| 273 | #define RORC_uint8 dst = (CF<<8)+dst; I.CarryVal = dst & 0x01; dst >>= 1 |
| 274 | #define RORC_uint16 dst = (CF<<16)+dst; I.CarryVal = dst & 0x01; dst >>= 1 |
| 275 | #define SHL_uint8(c) dst <<= c; SetCFB(dst); SetSZPF_Byte(dst); PutbackRMByte(ModRM,(uint8)dst) |
| 276 | #define SHL_uint16(c) dst <<= c; SetCFW(dst); SetSZPF_Word(dst); PutbackRMWord(ModRM,(uint16)dst) |
| 277 | #define SHR_uint8(c) dst >>= c-1; I.CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(uint8)dst) |
| 278 | #define SHR_uint16(c) dst >>= c-1; I.CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(uint16)dst) |
| 279 | #define SHRA_uint8(c) dst = ((int8)dst) >> (c-1); I.CarryVal = dst & 0x1; dst = ((int8)((uint8)dst)) >> 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(uint8)dst) |
| 280 | #define SHRA_uint16(c) dst = ((int16)dst) >> (c-1); I.CarryVal = dst & 0x1; dst = ((int16)((uint16)dst)) >> 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(uint16)dst) |
| 281 | |
| 282 | #define DIVUB \ |
| 283 | uresult = I.regs.w[AW]; \ |
| 284 | uresult2 = uresult % tmp; \ |
| 285 | if ((uresult /= tmp) > 0xff) { \ |
| 286 | nec_interrupt(0); break; \ |
| 287 | } else { \ |
| 288 | I.regs.b[AL] = uresult; \ |
| 289 | I.regs.b[AH] = uresult2; \ |
| 290 | } |
| 291 | |
| 292 | #define DIVB \ |
| 293 | result = (int16)I.regs.w[AW]; \ |
| 294 | result2 = result % (int16)((int8)tmp); \ |
| 295 | if ((result /= (int16)((int8)tmp)) > 0xff) { \ |
| 296 | nec_interrupt(0); break; \ |
| 297 | } else { \ |
| 298 | I.regs.b[AL] = result; \ |
| 299 | I.regs.b[AH] = result2; \ |
| 300 | } |
| 301 | |
| 302 | #define DIVUW \ |
| 303 | uresult = (((uint32)I.regs.w[DW]) << 16) | I.regs.w[AW];\ |
| 304 | uresult2 = uresult % tmp; \ |
| 305 | if ((uresult /= tmp) > 0xffff) { \ |
| 306 | nec_interrupt(0); break; \ |
| 307 | } else { \ |
| 308 | I.regs.w[AW]=uresult; \ |
| 309 | I.regs.w[DW]=uresult2; \ |
| 310 | } |
| 311 | |
| 312 | #define DIVW \ |
| 313 | result = ((uint32)I.regs.w[DW] << 16) + I.regs.w[AW]; \ |
| 314 | result2 = result % (int32)((int16)tmp); \ |
| 315 | if ((result /= (int32)((int16)tmp)) > 0xffff) { \ |
| 316 | nec_interrupt(0); break; \ |
| 317 | } else { \ |
| 318 | I.regs.w[AW]=result; \ |
| 319 | I.regs.w[DW]=result2; \ |
| 320 | } |
| 321 | |
| 322 | |
| 323 | typedef union |
| 324 | { /* eight general registers */ |
| 325 | uint16 w[8]; /* viewed as 16 bits registers */ |
| 326 | uint8 b[16]; /* or as 8 bit registers */ |
| 327 | } v30mz_basicregs_t; |
| 328 | |
| 329 | typedef struct |
| 330 | { |
| 331 | v30mz_basicregs_t regs; |
| 332 | uint16 sregs[4]; |
| 333 | |
| 334 | uint16 pc; |
| 335 | |
| 336 | int32 SignVal; |
| 337 | uint32 AuxVal, OverVal, ZeroVal, CarryVal, ParityVal; /* 0 or non-0 valued flags */ |
| 338 | uint8 TF, IF, DF; |
| 339 | } v30mz_regs_t; |
| 340 | |
| 341 | static void (*cpu_writemem20)(uint32,uint8) = NULL; |
| 342 | static uint8 (*cpu_readport)(uint32) = NULL; |
| 343 | static void (*cpu_writeport)(uint32, uint8) = NULL; |
| 344 | static uint8 (*cpu_readmem20)(uint32) = NULL; |
| 345 | |
| 346 | #define PhysRead8(addr) cpu_readmem20(addr) |
| 347 | |
| 348 | static INLINE uint16 PhysRead16(uint32 addr) |
| 349 | { |
| 350 | uint16 ret = cpu_readmem20(addr); |
| 351 | ret |= cpu_readmem20(addr + 1) << 8; |
| 352 | return ret; |
| 353 | } |
| 354 | |
| 355 | /***************************************************************************/ |
| 356 | /* cpu state */ |
| 357 | /***************************************************************************/ |
| 358 | |
| 359 | uint32 v30mz_timestamp; |
| 360 | int32 v30mz_ICount; |
| 361 | |
| 362 | static v30mz_regs_t I; |
| 363 | static bool InHLT; |
| 364 | |
| 365 | static uint32 prefix_base; /* base address of the latest prefix segment */ |
| 366 | static int8 seg_prefix; /* prefix segment indicator */ |
| 367 | |
| 368 | static uint32 EA; |
| 369 | static uint16 EO; |
| 370 | static uint16 E16; |
| 371 | |
| 372 | static unsigned EA_000(void) { EO=I.regs.w[BW]+I.regs.w[IX]; EA=DefaultBase(DS0)+EO; return EA; } |
| 373 | static unsigned EA_001(void) { EO=I.regs.w[BW]+I.regs.w[IY]; EA=DefaultBase(DS0)+EO; return EA; } |
| 374 | static unsigned EA_002(void) { EO=I.regs.w[BP]+I.regs.w[IX]; EA=DefaultBase(SS)+EO; return EA; } |
| 375 | static unsigned EA_003(void) { EO=I.regs.w[BP]+I.regs.w[IY]; EA=DefaultBase(SS)+EO; return EA; } |
| 376 | static unsigned EA_004(void) { EO=I.regs.w[IX]; EA=DefaultBase(DS0)+EO; return EA; } |
| 377 | static unsigned EA_005(void) { EO=I.regs.w[IY]; EA=DefaultBase(DS0)+EO; return EA; } |
| 378 | static unsigned EA_006(void) { EO=FETCH; EO+=FETCH<<8; EA=DefaultBase(DS0)+EO; return EA; } |
| 379 | static unsigned EA_007(void) { EO=I.regs.w[BW]; EA=DefaultBase(DS0)+EO; return EA; } |
| 380 | |
| 381 | static unsigned EA_100(void) { EO=(I.regs.w[BW]+I.regs.w[IX]+(int8)FETCH); EA=DefaultBase(DS0)+EO; return EA; } |
| 382 | static unsigned EA_101(void) { EO=(I.regs.w[BW]+I.regs.w[IY]+(int8)FETCH); EA=DefaultBase(DS0)+EO; return EA; } |
| 383 | static unsigned EA_102(void) { EO=(I.regs.w[BP]+I.regs.w[IX]+(int8)FETCH); EA=DefaultBase(SS)+EO; return EA; } |
| 384 | static unsigned EA_103(void) { EO=(I.regs.w[BP]+I.regs.w[IY]+(int8)FETCH); EA=DefaultBase(SS)+EO; return EA; } |
| 385 | static unsigned EA_104(void) { EO=(I.regs.w[IX]+(int8)FETCH); EA=DefaultBase(DS0)+EO; return EA; } |
| 386 | static unsigned EA_105(void) { EO=(I.regs.w[IY]+(int8)FETCH); EA=DefaultBase(DS0)+EO; return EA; } |
| 387 | static unsigned EA_106(void) { EO=(I.regs.w[BP]+(int8)FETCH); EA=DefaultBase(SS)+EO; return EA; } |
| 388 | static unsigned EA_107(void) { EO=(I.regs.w[BW]+(int8)FETCH); EA=DefaultBase(DS0)+EO; return EA; } |
| 389 | |
| 390 | static unsigned EA_200(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BW]+I.regs.w[IX]+(int16)E16; EA=DefaultBase(DS0)+EO; return EA; } |
| 391 | static unsigned EA_201(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BW]+I.regs.w[IY]+(int16)E16; EA=DefaultBase(DS0)+EO; return EA; } |
| 392 | static unsigned EA_202(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BP]+I.regs.w[IX]+(int16)E16; EA=DefaultBase(SS)+EO; return EA; } |
| 393 | static unsigned EA_203(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BP]+I.regs.w[IY]+(int16)E16; EA=DefaultBase(SS)+EO; return EA; } |
| 394 | static unsigned EA_204(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[IX]+(int16)E16; EA=DefaultBase(DS0)+EO; return EA; } |
| 395 | static unsigned EA_205(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[IY]+(int16)E16; EA=DefaultBase(DS0)+EO; return EA; } |
| 396 | static unsigned EA_206(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BP]+(int16)E16; EA=DefaultBase(SS)+EO; return EA; } |
| 397 | static unsigned EA_207(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BW]+(int16)E16; EA=DefaultBase(DS0)+EO; return EA; } |
| 398 | |
| 399 | static unsigned (*GetEA[192])(void)={ |
| 400 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 401 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 402 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 403 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 404 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 405 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 406 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 407 | EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, |
| 408 | |
| 409 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 410 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 411 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 412 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 413 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 414 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 415 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 416 | EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, |
| 417 | |
| 418 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 419 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 420 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 421 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 422 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 423 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 424 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, |
| 425 | EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207 |
| 426 | }; |
| 427 | |
| 428 | static struct { |
| 429 | struct { |
| 430 | WREGS w[256]; |
| 431 | BREGS b[256]; |
| 432 | } reg; |
| 433 | struct { |
| 434 | WREGS w[256]; |
| 435 | BREGS b[256]; |
| 436 | } RM; |
| 437 | } Mod_RM; |
| 438 | |
| 439 | #define RegWord(ModRM) I.regs.w[Mod_RM.reg.w[ModRM]] |
| 440 | #define RegByte(ModRM) I.regs.b[Mod_RM.reg.b[ModRM]] |
| 441 | |
| 442 | #define GetRMWord(ModRM) \ |
| 443 | ((ModRM) >= 0xc0 ? I.regs.w[Mod_RM.RM.w[ModRM]] : ( (*GetEA[ModRM])(), ReadWord( EA ) )) |
| 444 | |
| 445 | #define PutbackRMWord(ModRM,val) \ |
| 446 | { \ |
| 447 | if (ModRM >= 0xc0) I.regs.w[Mod_RM.RM.w[ModRM]]=val; \ |
| 448 | else WriteWord(EA,val); \ |
| 449 | } |
| 450 | |
| 451 | #define GetnextRMWord ReadWord((EA&0xf0000)|((EA+2)&0xffff)) |
| 452 | |
| 453 | #define PutRMWord(ModRM,val) \ |
| 454 | { \ |
| 455 | if (ModRM >= 0xc0) \ |
| 456 | I.regs.w[Mod_RM.RM.w[ModRM]]=val; \ |
| 457 | else \ |
| 458 | { \ |
| 459 | (*GetEA[ModRM])(); \ |
| 460 | WriteWord( EA ,val); \ |
| 461 | } \ |
| 462 | } |
| 463 | |
| 464 | #define PutImmRMWord(ModRM) \ |
| 465 | { \ |
| 466 | uint16 val; \ |
| 467 | if (ModRM >= 0xc0) \ |
| 468 | FETCHuint16(I.regs.w[Mod_RM.RM.w[ModRM]]) \ |
| 469 | else { \ |
| 470 | (*GetEA[ModRM])(); \ |
| 471 | FETCHuint16(val) \ |
| 472 | WriteWord( EA , val); \ |
| 473 | } \ |
| 474 | } |
| 475 | |
| 476 | #define GetRMByte(ModRM) \ |
| 477 | ((ModRM) >= 0xc0 ? I.regs.b[Mod_RM.RM.b[ModRM]] : ReadByte( (*GetEA[ModRM])() )) |
| 478 | |
| 479 | #define PutRMByte(ModRM,val) \ |
| 480 | { \ |
| 481 | if (ModRM >= 0xc0) \ |
| 482 | I.regs.b[Mod_RM.RM.b[ModRM]]=val; \ |
| 483 | else \ |
| 484 | WriteByte( (*GetEA[ModRM])() ,val); \ |
| 485 | } |
| 486 | |
| 487 | #define PutImmRMByte(ModRM) \ |
| 488 | { \ |
| 489 | if (ModRM >= 0xc0) \ |
| 490 | I.regs.b[Mod_RM.RM.b[ModRM]]=FETCH; \ |
| 491 | else { \ |
| 492 | (*GetEA[ModRM])(); \ |
| 493 | WriteByte( EA , FETCH ); \ |
| 494 | } \ |
| 495 | } |
| 496 | |
| 497 | #define PutbackRMByte(ModRM,val) \ |
| 498 | { \ |
| 499 | if (ModRM >= 0xc0) \ |
| 500 | I.regs.b[Mod_RM.RM.b[ModRM]]=val; \ |
| 501 | else \ |
| 502 | WriteByte(EA,val); \ |
| 503 | } |
| 504 | |
| 505 | #define DEF_br8 \ |
| 506 | uint32 ModRM = FETCH,src,dst; \ |
| 507 | src = RegByte(ModRM); \ |
| 508 | dst = GetRMByte(ModRM) |
| 509 | |
| 510 | #define DEF_wr16 \ |
| 511 | uint32 ModRM = FETCH,src,dst; \ |
| 512 | src = RegWord(ModRM); \ |
| 513 | dst = GetRMWord(ModRM) |
| 514 | |
| 515 | #define DEF_r8b \ |
| 516 | uint32 ModRM = FETCH,src,dst; \ |
| 517 | dst = RegByte(ModRM); \ |
| 518 | src = GetRMByte(ModRM) |
| 519 | |
| 520 | #define DEF_r16w \ |
| 521 | uint32 ModRM = FETCH,src,dst; \ |
| 522 | dst = RegWord(ModRM); \ |
| 523 | src = GetRMWord(ModRM) |
| 524 | |
| 525 | #define DEF_ald8 \ |
| 526 | uint32 src = FETCH; \ |
| 527 | uint32 dst = I.regs.b[AL] |
| 528 | |
| 529 | #define DEF_axd16 \ |
| 530 | uint32 src = FETCH; \ |
| 531 | uint32 dst = I.regs.w[AW]; \ |
| 532 | src += (FETCH << 8) |
| 533 | |
| 534 | static uint8 parity_table[256]; |
| 535 | |
| 536 | static INLINE void i_real_pushf(void) |
| 537 | { |
| 538 | uint16 compr = CompressFlags(); |
| 539 | PUSH(compr); |
| 540 | CLK(2); |
| 541 | } |
| 542 | |
| 543 | static INLINE void i_real_popf(void) |
| 544 | { |
| 545 | uint32 tmp; |
| 546 | POP(tmp); |
| 547 | ExpandFlags(tmp); |
| 548 | CLK(3); |
| 549 | } |
| 550 | |
| 551 | /***************************************************************************/ |
| 552 | |
| 553 | void v30mz_init(uint8 (*readmem20)(uint32), void (*writemem20)(uint32,uint8), uint8 (*readport)(uint32), void (*writeport)(uint32, uint8)) |
| 554 | { |
| 555 | cpu_readmem20 = readmem20; |
| 556 | cpu_writemem20 = writemem20; |
| 557 | |
| 558 | cpu_readport = readport; |
| 559 | cpu_writeport = writeport; |
| 560 | } |
| 561 | |
| 562 | void v30mz_reset(void) |
| 563 | { |
| 564 | unsigned i; |
| 565 | const BREGS reg_name[8] = { AL, CL, DL, BL, AH, CH, DH, BH }; |
| 566 | |
| 567 | v30mz_ICount = 0; |
| 568 | v30mz_timestamp = 0; |
| 569 | |
| 570 | memset(&I, 0, sizeof(I)); |
| 571 | |
| 572 | I.sregs[PS] = 0xffff; |
| 573 | |
| 574 | for(i = 0; i < 256; i++) |
| 575 | { |
| 576 | unsigned j; |
| 577 | unsigned int c = 0; |
| 578 | |
| 579 | for (j = i; j > 0; j >>= 1) |
| 580 | if (j & 1) c++; |
| 581 | |
| 582 | parity_table[i] = !(c & 1); |
| 583 | } |
| 584 | |
| 585 | I.ZeroVal = I.ParityVal = 1; |
| 586 | |
| 587 | for(i = 0; i < 256; i++) |
| 588 | { |
| 589 | Mod_RM.reg.b[i] = reg_name[(i & 0x38) >> 3]; |
| 590 | Mod_RM.reg.w[i] = (WREGS) ( (i & 0x38) >> 3) ; |
| 591 | } |
| 592 | |
| 593 | for(i = 0xc0; i < 0x100; i++) |
| 594 | { |
| 595 | Mod_RM.RM.w[i] = (WREGS)( i & 7 ); |
| 596 | Mod_RM.RM.b[i] = (BREGS)reg_name[i & 7]; |
| 597 | } |
| 598 | |
| 599 | prefix_base = 0; |
| 600 | seg_prefix = 0; |
| 601 | InHLT = 0; |
| 602 | } |
| 603 | |
| 604 | void v30mz_int(uint32 vector, bool IgnoreIF) |
| 605 | { |
| 606 | InHLT = false; // This is correct! Standby mode is always exited when there is an INT signal, regardless of whether interrupt are disabled. |
| 607 | if(I.IF || IgnoreIF) |
| 608 | { |
| 609 | uint32 dest_seg, dest_off; |
| 610 | uint16 compr = CompressFlags(); |
| 611 | |
| 612 | PUSH( compr ); |
| 613 | I.TF = I.IF = 0; |
| 614 | dest_off = ReadWord(vector); |
| 615 | dest_seg = ReadWord(vector+2); |
| 616 | PUSH(I.sregs[PS]); |
| 617 | PUSH(I.pc); |
| 618 | I.pc = (uint16)dest_off; |
| 619 | I.sregs[PS] = (uint16)dest_seg; |
| 620 | CLK(32); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | static void nec_interrupt(unsigned int_num) |
| 625 | { |
| 626 | uint32 dest_seg, dest_off; |
| 627 | |
| 628 | if (int_num == -1) |
| 629 | return; |
| 630 | |
| 631 | i_real_pushf(); |
| 632 | I.TF = I.IF = 0; |
| 633 | |
| 634 | |
| 635 | dest_off = ReadWord((int_num)*4); |
| 636 | dest_seg = ReadWord((int_num)*4+2); |
| 637 | |
| 638 | PUSH(I.sregs[PS]); |
| 639 | PUSH(I.pc); |
| 640 | I.pc = (uint16)dest_off; |
| 641 | I.sregs[PS] = (uint16)dest_seg; |
| 642 | } |
| 643 | |
| 644 | static bool CheckInHLT(void) |
| 645 | { |
| 646 | if(InHLT) |
| 647 | { |
| 648 | WSwan_InterruptCheck(); |
| 649 | if(InHLT) |
| 650 | { |
| 651 | int32 tmp = v30mz_ICount; |
| 652 | |
| 653 | if(tmp > 0) |
| 654 | CLK(tmp); |
| 655 | return(1); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | return(0); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | /****************************************************************************/ |
| 664 | /* OPCODES */ |
| 665 | /****************************************************************************/ |
| 666 | |
| 667 | static INLINE void i_real_insb(void) |
| 668 | { |
| 669 | PutMemB(DS1,I.regs.w[IY], read_port(I.regs.w[DW])); |
| 670 | I.regs.w[IY]+= -2 * I.DF + 1; |
| 671 | CLK(6); |
| 672 | } |
| 673 | |
| 674 | static INLINE void i_real_insw(void) |
| 675 | { |
| 676 | PutMemB(DS1,I.regs.w[IY],read_port(I.regs.w[DW])); |
| 677 | PutMemB(DS1,(I.regs.w[IY]+1)&0xffff,read_port((I.regs.w[DW]+1)&0xffff)); |
| 678 | I.regs.w[IY]+= -4 * I.DF + 2; |
| 679 | CLK(6); |
| 680 | } |
| 681 | |
| 682 | static INLINE void i_real_outsb(void) |
| 683 | { |
| 684 | write_port(I.regs.w[DW],GetMemB(DS0,I.regs.w[IX])); |
| 685 | I.regs.w[IX]+= -2 * I.DF + 1; |
| 686 | CLK(7); |
| 687 | } |
| 688 | |
| 689 | static INLINE void i_real_outsw(void) |
| 690 | { |
| 691 | write_port(I.regs.w[DW],GetMemB(DS0,I.regs.w[IX])); |
| 692 | write_port((I.regs.w[DW]+1)&0xffff,GetMemB(DS0,(I.regs.w[IX]+1)&0xffff)); |
| 693 | I.regs.w[IX]+= -4 * I.DF + 2; |
| 694 | CLK(7); |
| 695 | } |
| 696 | |
| 697 | static INLINE void i_real_movsb(void) |
| 698 | { |
| 699 | uint32 tmp = GetMemB(DS0,I.regs.w[IX]); |
| 700 | PutMemB(DS1,I.regs.w[IY], tmp); |
| 701 | I.regs.w[IY] += -2 * I.DF + 1; |
| 702 | I.regs.w[IX] += -2 * I.DF + 1; |
| 703 | CLK(5); |
| 704 | } |
| 705 | |
| 706 | static INLINE void i_real_movsw(void) |
| 707 | { |
| 708 | uint32 tmp = GetMemW(DS0,I.regs.w[IX]); PutMemW(DS1,I.regs.w[IY], tmp); I.regs.w[IY] += -4 * I.DF + 2; |
| 709 | I.regs.w[IX] += -4 * I.DF + 2; CLK(5); |
| 710 | } |
| 711 | |
| 712 | static INLINE void i_real_cmpsb(void) |
| 713 | { |
| 714 | uint32 src = GetMemB(DS1, I.regs.w[IY]); uint32 dst = GetMemB(DS0, I.regs.w[IX]); SUBB; I.regs.w[IY] += -2 * I.DF + 1; |
| 715 | I.regs.w[IX] += -2 * I.DF + 1; CLK(6); |
| 716 | } |
| 717 | |
| 718 | static INLINE void i_real_cmpsw(void) |
| 719 | { |
| 720 | uint32 src = GetMemW(DS1, I.regs.w[IY]); |
| 721 | uint32 dst = GetMemW(DS0, I.regs.w[IX]); |
| 722 | SUBW; |
| 723 | I.regs.w[IY] += -4 * I.DF + 2; |
| 724 | I.regs.w[IX] += -4 * I.DF + 2; |
| 725 | CLK(6); |
| 726 | } |
| 727 | |
| 728 | static INLINE void i_real_stosb(void) |
| 729 | { |
| 730 | PutMemB(DS1,I.regs.w[IY],I.regs.b[AL]); |
| 731 | I.regs.w[IY] += -2 * I.DF + 1; |
| 732 | CLK(3); |
| 733 | } |
| 734 | |
| 735 | static INLINE void i_real_stosw(void) |
| 736 | { |
| 737 | PutMemW(DS1,I.regs.w[IY],I.regs.w[AW]); |
| 738 | I.regs.w[IY] += -4 * I.DF + 2; |
| 739 | CLK(3); |
| 740 | } |
| 741 | |
| 742 | static INLINE void i_real_lodsb(void) |
| 743 | { |
| 744 | I.regs.b[AL] = GetMemB(DS0,I.regs.w[IX]); |
| 745 | I.regs.w[IX] += -2 * I.DF + 1; |
| 746 | CLK(3); |
| 747 | } |
| 748 | |
| 749 | static INLINE void i_real_lodsw(void) |
| 750 | { |
| 751 | I.regs.w[AW] = GetMemW(DS0,I.regs.w[IX]); |
| 752 | I.regs.w[IX] += -4 * I.DF + 2; |
| 753 | CLK(3); |
| 754 | } |
| 755 | |
| 756 | static INLINE void i_real_scasb(void) |
| 757 | { |
| 758 | uint32 src = GetMemB(DS1, I.regs.w[IY]); |
| 759 | uint32 dst = I.regs.b[AL]; SUBB; |
| 760 | I.regs.w[IY] += -2 * I.DF + 1; |
| 761 | CLK(4); |
| 762 | } |
| 763 | |
| 764 | static INLINE void i_real_scasw(void) |
| 765 | { |
| 766 | uint32 src = GetMemW(DS1, I.regs.w[IY]); |
| 767 | uint32 dst = I.regs.w[AW]; |
| 768 | SUBW; |
| 769 | I.regs.w[IY] += -4 * I.DF + 2; |
| 770 | CLK(4); |
| 771 | } |
| 772 | |
| 773 | static void DoOP(uint8 opcode) |
| 774 | { |
| 775 | #define OP(num, func_name) case num: |
| 776 | #define OP_EPILOGUE break |
| 777 | |
| 778 | switch(opcode) |
| 779 | { |
| 780 | default: |
| 781 | CLK(10); |
| 782 | break; |
| 783 | |
| 784 | OP( 0x00, i_add_br8 ) { DEF_br8; ADDB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 785 | OP( 0x01, i_add_wr16 ) { DEF_wr16; ADDW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 786 | OP( 0x02, i_add_r8b ) { DEF_r8b; ADDB; RegByte(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 787 | OP( 0x03, i_add_r16w ) { DEF_r16w; ADDW; RegWord(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 788 | OP( 0x04, i_add_ald8 ) { DEF_ald8; ADDB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 789 | OP( 0x05, i_add_axd16) { DEF_axd16; ADDW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 790 | OP( 0x06, i_push_ds1 ) { PUSH(I.sregs[DS1]); CLK(2); } OP_EPILOGUE; |
| 791 | OP( 0x07, i_pop_ds1 ) { POP(I.sregs[DS1]); CLK(3); } OP_EPILOGUE; |
| 792 | |
| 793 | OP( 0x08, i_or_br8 ) { DEF_br8; ORB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 794 | OP( 0x09, i_or_wr16 ) { DEF_wr16; ORW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 795 | OP( 0x0a, i_or_r8b ) { DEF_r8b; ORB; RegByte(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 796 | OP( 0x0b, i_or_r16w ) { DEF_r16w; ORW; RegWord(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 797 | OP( 0x0c, i_or_ald8 ) { DEF_ald8; ORB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 798 | OP( 0x0d, i_or_axd16 ) { DEF_axd16; ORW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 799 | OP( 0x0e, i_push_cs ) { PUSH(I.sregs[PS]); CLK(2); } OP_EPILOGUE; |
| 800 | |
| 801 | OP( 0x10, i_adc_br8 ) { DEF_br8; src+=CF; ADDB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 802 | OP( 0x11, i_adc_wr16 ) { DEF_wr16; src+=CF; ADDW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 803 | OP( 0x12, i_adc_r8b ) { DEF_r8b; src+=CF; ADDB; RegByte(ModRM)=dst; CLKM(2, 1); } OP_EPILOGUE; |
| 804 | OP( 0x13, i_adc_r16w ) { DEF_r16w; src+=CF; ADDW; RegWord(ModRM)=dst; CLKM(2, 1); } OP_EPILOGUE; |
| 805 | OP( 0x14, i_adc_ald8 ) { DEF_ald8; src+=CF; ADDB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 806 | OP( 0x15, i_adc_axd16) { DEF_axd16; src+=CF; ADDW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 807 | OP( 0x16, i_push_ss ) { PUSH(I.sregs[SS]); CLK(2); } OP_EPILOGUE; |
| 808 | OP( 0x17, i_pop_ss ) { POP(I.sregs[SS]); CLK(3); } OP_EPILOGUE; |
| 809 | |
| 810 | OP( 0x18, i_sbb_br8 ) { DEF_br8; src+=CF; SUBB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 811 | OP( 0x19, i_sbb_wr16 ) { DEF_wr16; src+=CF; SUBW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 812 | OP( 0x1a, i_sbb_r8b ) { DEF_r8b; src+=CF; SUBB; RegByte(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 813 | OP( 0x1b, i_sbb_r16w ) { DEF_r16w; src+=CF; SUBW; RegWord(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 814 | OP( 0x1c, i_sbb_ald8 ) { DEF_ald8; src+=CF; SUBB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 815 | OP( 0x1d, i_sbb_axd16) { DEF_axd16; src+=CF; SUBW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 816 | OP( 0x1e, i_push_ds ) { PUSH(I.sregs[DS0]); CLK(2); } OP_EPILOGUE; |
| 817 | OP( 0x1f, i_pop_ds ) { POP(I.sregs[DS0]); CLK(3); } OP_EPILOGUE; |
| 818 | |
| 819 | OP( 0x20, i_and_br8 ) { DEF_br8; ANDB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 820 | OP( 0x21, i_and_wr16 ) { DEF_wr16; ANDW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 821 | OP( 0x22, i_and_r8b ) { DEF_r8b; ANDB; RegByte(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 822 | OP( 0x23, i_and_r16w ) { DEF_r16w; ANDW; RegWord(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 823 | OP( 0x24, i_and_ald8 ) { DEF_ald8; ANDB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 824 | OP( 0x25, i_and_axd16) { DEF_axd16; ANDW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 825 | OP( 0x26, i_ds1 ) { seg_prefix=true; prefix_base=I.sregs[DS1]<<4; CLK(1); DoOP(FETCHOP); seg_prefix=false; } OP_EPILOGUE; |
| 826 | OP( 0x27, i_daa ) { ADJ4(6,0x60); CLK(10); } OP_EPILOGUE; |
| 827 | |
| 828 | OP( 0x28, i_sub_br8 ) { DEF_br8; SUBB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 829 | OP( 0x29, i_sub_wr16 ) { DEF_wr16; SUBW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 830 | OP( 0x2a, i_sub_r8b ) { DEF_r8b; SUBB; RegByte(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 831 | OP( 0x2b, i_sub_r16w ) { DEF_r16w; SUBW; RegWord(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 832 | OP( 0x2c, i_sub_ald8 ) { DEF_ald8; SUBB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 833 | OP( 0x2d, i_sub_axd16) { DEF_axd16; SUBW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 834 | OP( 0x2e, i_ps ) { seg_prefix=true; prefix_base=I.sregs[PS]<<4; CLK(1); DoOP(FETCHOP); seg_prefix=false; } OP_EPILOGUE; |
| 835 | OP( 0x2f, i_das ) { ADJ4(-6,-0x60); CLK(10); } OP_EPILOGUE; |
| 836 | |
| 837 | OP( 0x30, i_xor_br8 ) { DEF_br8; XORB; PutbackRMByte(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 838 | OP( 0x31, i_xor_wr16 ) { DEF_wr16; XORW; PutbackRMWord(ModRM,dst); CLKM(3,1); } OP_EPILOGUE; |
| 839 | OP( 0x32, i_xor_r8b ) { DEF_r8b; XORB; RegByte(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 840 | OP( 0x33, i_xor_r16w ) { DEF_r16w; XORW; RegWord(ModRM)=dst; CLKM(2,1); } OP_EPILOGUE; |
| 841 | OP( 0x34, i_xor_ald8 ) { DEF_ald8; XORB; I.regs.b[AL]=dst; CLK(1); } OP_EPILOGUE; |
| 842 | OP( 0x35, i_xor_axd16) { DEF_axd16; XORW; I.regs.w[AW]=dst; CLK(1); } OP_EPILOGUE; |
| 843 | OP( 0x36, i_ss ) { seg_prefix=true; prefix_base=I.sregs[SS]<<4; CLK(1); DoOP(FETCHOP); seg_prefix=false; } OP_EPILOGUE; |
| 844 | OP( 0x37, i_aaa ) { ADJB(6,1); CLK(9); } OP_EPILOGUE; |
| 845 | |
| 846 | OP( 0x38, i_cmp_br8 ) { DEF_br8; SUBB; CLKM(2,1); } OP_EPILOGUE; |
| 847 | OP( 0x39, i_cmp_wr16 ) { DEF_wr16; SUBW; CLKM(2,1); } OP_EPILOGUE; |
| 848 | OP( 0x3a, i_cmp_r8b ) { DEF_r8b; SUBB; CLKM(2,1); } OP_EPILOGUE; |
| 849 | OP( 0x3b, i_cmp_r16w ) { DEF_r16w; SUBW; CLKM(2,1); } OP_EPILOGUE; |
| 850 | OP( 0x3c, i_cmp_ald8 ) { DEF_ald8; SUBB; CLK(1); } OP_EPILOGUE; |
| 851 | OP( 0x3d, i_cmp_axd16) { DEF_axd16; SUBW; CLK(1); } OP_EPILOGUE; |
| 852 | OP( 0x3e, i_ds0 ) { seg_prefix=true; prefix_base=I.sregs[DS0]<<4; CLK(1); DoOP(FETCHOP); seg_prefix=false; } OP_EPILOGUE; |
| 853 | OP( 0x3f, i_aas ) { ADJB(-6,-1); CLK(9); } OP_EPILOGUE; |
| 854 | |
| 855 | OP( 0x40, i_inc_ax ) { IncWordReg(AW); CLK(1); } OP_EPILOGUE; |
| 856 | OP( 0x41, i_inc_cx ) { IncWordReg(CW); CLK(1); } OP_EPILOGUE; |
| 857 | OP( 0x42, i_inc_dx ) { IncWordReg(DW); CLK(1); } OP_EPILOGUE; |
| 858 | OP( 0x43, i_inc_bx ) { IncWordReg(BW); CLK(1); } OP_EPILOGUE; |
| 859 | OP( 0x44, i_inc_sp ) { IncWordReg(SP); CLK(1); } OP_EPILOGUE; |
| 860 | OP( 0x45, i_inc_bp ) { IncWordReg(BP); CLK(1); } OP_EPILOGUE; |
| 861 | OP( 0x46, i_inc_si ) { IncWordReg(IX); CLK(1); } OP_EPILOGUE; |
| 862 | OP( 0x47, i_inc_di ) { IncWordReg(IY); CLK(1); } OP_EPILOGUE; |
| 863 | |
| 864 | OP( 0x48, i_dec_ax ) { DecWordReg(AW); CLK(1); } OP_EPILOGUE; |
| 865 | OP( 0x49, i_dec_cx ) { DecWordReg(CW); CLK(1); } OP_EPILOGUE; |
| 866 | OP( 0x4a, i_dec_dx ) { DecWordReg(DW); CLK(1); } OP_EPILOGUE; |
| 867 | OP( 0x4b, i_dec_bx ) { DecWordReg(BW); CLK(1); } OP_EPILOGUE; |
| 868 | OP( 0x4c, i_dec_sp ) { DecWordReg(SP); CLK(1); } OP_EPILOGUE; |
| 869 | OP( 0x4d, i_dec_bp ) { DecWordReg(BP); CLK(1); } OP_EPILOGUE; |
| 870 | OP( 0x4e, i_dec_si ) { DecWordReg(IX); CLK(1); } OP_EPILOGUE; |
| 871 | OP( 0x4f, i_dec_di ) { DecWordReg(IY); CLK(1); } OP_EPILOGUE; |
| 872 | |
| 873 | OP( 0x50, i_push_ax ) { PUSH(I.regs.w[AW]); CLK(1); } OP_EPILOGUE; |
| 874 | OP( 0x51, i_push_cx ) { PUSH(I.regs.w[CW]); CLK(1); } OP_EPILOGUE; |
| 875 | OP( 0x52, i_push_dx ) { PUSH(I.regs.w[DW]); CLK(1); } OP_EPILOGUE; |
| 876 | OP( 0x53, i_push_bx ) { PUSH(I.regs.w[BW]); CLK(1); } OP_EPILOGUE; |
| 877 | OP( 0x54, i_push_sp ) { PUSH(I.regs.w[SP]); CLK(1); } OP_EPILOGUE; |
| 878 | OP( 0x55, i_push_bp ) { PUSH(I.regs.w[BP]); CLK(1); } OP_EPILOGUE; |
| 879 | OP( 0x56, i_push_si ) { PUSH(I.regs.w[IX]); CLK(1); } OP_EPILOGUE; |
| 880 | OP( 0x57, i_push_di ) { PUSH(I.regs.w[IY]); CLK(1); } OP_EPILOGUE; |
| 881 | |
| 882 | OP( 0x58, i_pop_ax ) { POP(I.regs.w[AW]); CLK(1); } OP_EPILOGUE; |
| 883 | OP( 0x59, i_pop_cx ) { POP(I.regs.w[CW]); CLK(1); } OP_EPILOGUE; |
| 884 | OP( 0x5a, i_pop_dx ) { POP(I.regs.w[DW]); CLK(1); } OP_EPILOGUE; |
| 885 | OP( 0x5b, i_pop_bx ) { POP(I.regs.w[BW]); CLK(1); } OP_EPILOGUE; |
| 886 | OP( 0x5c, i_pop_sp ) { POP(I.regs.w[SP]); CLK(1); } OP_EPILOGUE; |
| 887 | OP( 0x5d, i_pop_bp ) { POP(I.regs.w[BP]); CLK(1); } OP_EPILOGUE; |
| 888 | OP( 0x5e, i_pop_si ) { POP(I.regs.w[IX]); CLK(1); } OP_EPILOGUE; |
| 889 | OP( 0x5f, i_pop_di ) { POP(I.regs.w[IY]); CLK(1); } OP_EPILOGUE; |
| 890 | |
| 891 | OP( 0x60, i_pusha ) { |
| 892 | unsigned tmp=I.regs.w[SP]; |
| 893 | PUSH(I.regs.w[AW]); |
| 894 | PUSH(I.regs.w[CW]); |
| 895 | PUSH(I.regs.w[DW]); |
| 896 | PUSH(I.regs.w[BW]); |
| 897 | PUSH(tmp); |
| 898 | PUSH(I.regs.w[BP]); |
| 899 | PUSH(I.regs.w[IX]); |
| 900 | PUSH(I.regs.w[IY]); |
| 901 | CLK(9); |
| 902 | } OP_EPILOGUE; |
| 903 | |
| 904 | OP( 0x61, i_popa ) { |
| 905 | POP(I.regs.w[IY]); |
| 906 | POP(I.regs.w[IX]); |
| 907 | POP(I.regs.w[BP]); |
| 908 | POPNOVAR(); |
| 909 | POP(I.regs.w[BW]); |
| 910 | POP(I.regs.w[DW]); |
| 911 | POP(I.regs.w[CW]); |
| 912 | POP(I.regs.w[AW]); |
| 913 | CLK(8); |
| 914 | } OP_EPILOGUE; |
| 915 | |
| 916 | OP( 0x62, i_chkind ) |
| 917 | { |
| 918 | GetModRM; |
| 919 | uint32 low = GetRMWord(ModRM); |
| 920 | uint32 high = GetnextRMWord; |
| 921 | uint32 tmp = RegWord(ModRM); |
| 922 | |
| 923 | CLK(13); |
| 924 | if (tmp<low || tmp>high) |
| 925 | nec_interrupt(5); |
| 926 | } OP_EPILOGUE; |
| 927 | |
| 928 | OP( 0x68, i_push_d16 ) { uint32 tmp; FETCHuint16(tmp); PUSH(tmp); CLK(1); } OP_EPILOGUE; |
| 929 | OP( 0x69, i_imul_d16 ) { uint32 tmp; DEF_r16w; FETCHuint16(tmp); dst = (int32)((int16)src)*(int32)((int16)tmp); I.CarryVal = I.OverVal = (((int32)dst) >> 15 != 0) && (((int32)dst) >> 15 != -1); RegWord(ModRM)=(uint16)dst; CLKM(4,3);} OP_EPILOGUE; |
| 930 | OP( 0x6a, i_push_d8 ) { uint32 tmp = (uint16)((int16)((int8)FETCH)); PUSH(tmp); CLK(1); } OP_EPILOGUE; |
| 931 | OP( 0x6b, i_imul_d8 ) { uint32 src2; DEF_r16w; src2= (uint16)((int16)((int8)FETCH)); dst = (int32)((int16)src)*(int32)((int16)src2); I.CarryVal = I.OverVal = (((int32)dst) >> 15 != 0) && (((int32)dst) >> 15 != -1); RegWord(ModRM)=(uint16)dst; CLKM(4,3); } OP_EPILOGUE; |
| 932 | OP( 0x6c, i_insb ) { i_real_insb(); } OP_EPILOGUE; |
| 933 | OP( 0x6d, i_insw ) { i_real_insw(); } OP_EPILOGUE; |
| 934 | OP( 0x6e, i_outsb ) { i_real_outsb(); } OP_EPILOGUE; |
| 935 | OP( 0x6f, i_outsw ) { i_real_outsw(); } OP_EPILOGUE; |
| 936 | |
| 937 | OP( 0x70, i_jo ) { JMP( FLAG_O); CLK(1); } OP_EPILOGUE; |
| 938 | OP( 0x71, i_jno ) { JMP(!FLAG_O); CLK(1); } OP_EPILOGUE; |
| 939 | OP( 0x72, i_jc ) { JMP( CF); CLK(1); } OP_EPILOGUE; |
| 940 | OP( 0x73, i_jnc ) { JMP(!CF); CLK(1); } OP_EPILOGUE; |
| 941 | OP( 0x74, i_jz ) { JMP( ZF); CLK(1); } OP_EPILOGUE; |
| 942 | OP( 0x75, i_jnz ) { JMP(!ZF); CLK(1); } OP_EPILOGUE; |
| 943 | OP( 0x76, i_jce ) { JMP(CF || ZF); CLK(1); } OP_EPILOGUE; |
| 944 | OP( 0x77, i_jnce ) { JMP(!(CF || ZF)); CLK(1); } OP_EPILOGUE; |
| 945 | OP( 0x78, i_js ) { JMP( SF); CLK(1); } OP_EPILOGUE; |
| 946 | OP( 0x79, i_jns ) { JMP(!SF); CLK(1); } OP_EPILOGUE; |
| 947 | OP( 0x7a, i_jp ) { JMP( PF); CLK(1); } OP_EPILOGUE; |
| 948 | OP( 0x7b, i_jnp ) { JMP(!PF); CLK(1); } OP_EPILOGUE; |
| 949 | OP( 0x7c, i_jl ) { JMP((SF!=FLAG_O)&&(!ZF)); CLK(1); } OP_EPILOGUE; |
| 950 | OP( 0x7d, i_jnl ) { JMP((ZF)||(SF==FLAG_O)); CLK(1); } OP_EPILOGUE; |
| 951 | OP( 0x7e, i_jle ) { JMP((ZF)||(SF!=FLAG_O)); CLK(1); } OP_EPILOGUE; |
| 952 | OP( 0x7f, i_jnle ) { JMP((SF==FLAG_O)&&(!ZF)); CLK(1); } OP_EPILOGUE; |
| 953 | |
| 954 | OP( 0x80, i_80pre ) { GetModRM; uint32 dst = GetRMByte(ModRM); uint32 src = FETCH; |
| 955 | CLKM(3, 1); |
| 956 | switch (ModRM & 0x38) { |
| 957 | case 0x00: ADDB; PutbackRMByte(ModRM,dst); break; |
| 958 | case 0x08: ORB; PutbackRMByte(ModRM,dst); break; |
| 959 | case 0x10: src+=CF; ADDB; PutbackRMByte(ModRM,dst); break; |
| 960 | case 0x18: src+=CF; SUBB; PutbackRMByte(ModRM,dst); break; |
| 961 | case 0x20: ANDB; PutbackRMByte(ModRM,dst); break; |
| 962 | case 0x28: SUBB; PutbackRMByte(ModRM,dst); break; |
| 963 | case 0x30: XORB; PutbackRMByte(ModRM,dst); break; |
| 964 | case 0x38: SUBB; break; /* CMP */ |
| 965 | } |
| 966 | } OP_EPILOGUE; |
| 967 | |
| 968 | OP( 0x81, i_81pre ) { GetModRM; uint32 dst = GetRMWord(ModRM); uint32 src = FETCH; src+= (FETCH << 8); |
| 969 | CLKM(3, 1); |
| 970 | switch (ModRM & 0x38) { |
| 971 | case 0x00: ADDW; PutbackRMWord(ModRM,dst); break; |
| 972 | case 0x08: ORW; PutbackRMWord(ModRM,dst); break; |
| 973 | case 0x10: src+=CF; ADDW; PutbackRMWord(ModRM,dst); break; |
| 974 | case 0x18: src+=CF; SUBW; PutbackRMWord(ModRM,dst); break; |
| 975 | case 0x20: ANDW; PutbackRMWord(ModRM,dst); break; |
| 976 | case 0x28: SUBW; PutbackRMWord(ModRM,dst); break; |
| 977 | case 0x30: XORW; PutbackRMWord(ModRM,dst); break; |
| 978 | case 0x38: SUBW; break; /* CMP */ |
| 979 | } |
| 980 | } OP_EPILOGUE; |
| 981 | |
| 982 | OP( 0x82, i_82pre ) { GetModRM; uint32 dst = GetRMByte(ModRM); uint32 src = (uint8)((int8)FETCH); |
| 983 | CLKM(3,1); |
| 984 | switch (ModRM & 0x38) { |
| 985 | case 0x00: ADDB; PutbackRMByte(ModRM,dst); break; |
| 986 | case 0x08: ORB; PutbackRMByte(ModRM,dst); break; |
| 987 | case 0x10: src+=CF; ADDB; PutbackRMByte(ModRM,dst); break; |
| 988 | case 0x18: src+=CF; SUBB; PutbackRMByte(ModRM,dst); break; |
| 989 | case 0x20: ANDB; PutbackRMByte(ModRM,dst); break; |
| 990 | case 0x28: SUBB; PutbackRMByte(ModRM,dst); break; |
| 991 | case 0x30: XORB; PutbackRMByte(ModRM,dst); break; |
| 992 | case 0x38: SUBB; break; /* CMP */ |
| 993 | } |
| 994 | } OP_EPILOGUE; |
| 995 | |
| 996 | OP( 0x83, i_83pre ) { GetModRM; uint32 dst = GetRMWord(ModRM); uint32 src = (uint16)((int16)((int8)FETCH)); |
| 997 | CLKM(3,1); |
| 998 | switch (ModRM & 0x38) { |
| 999 | case 0x00: ADDW; PutbackRMWord(ModRM,dst); break; |
| 1000 | case 0x08: ORW; PutbackRMWord(ModRM,dst); break; |
| 1001 | case 0x10: src+=CF; ADDW; PutbackRMWord(ModRM,dst); break; |
| 1002 | case 0x18: src+=CF; SUBW; PutbackRMWord(ModRM,dst); break; |
| 1003 | case 0x20: ANDW; PutbackRMWord(ModRM,dst); break; |
| 1004 | case 0x28: SUBW; PutbackRMWord(ModRM,dst); break; |
| 1005 | case 0x30: XORW; PutbackRMWord(ModRM,dst); break; |
| 1006 | case 0x38: SUBW; break; /* CMP */ |
| 1007 | } |
| 1008 | } OP_EPILOGUE; |
| 1009 | |
| 1010 | OP( 0x84, i_test_br8 ) { DEF_br8; ANDB; CLKM(2,1); } OP_EPILOGUE; |
| 1011 | OP( 0x85, i_test_wr16 ) { DEF_wr16; ANDW; CLKM(2,1); } OP_EPILOGUE; |
| 1012 | OP( 0x86, i_xchg_br8 ) { DEF_br8; RegByte(ModRM)=dst; PutbackRMByte(ModRM,src); CLKM(5,3); } OP_EPILOGUE; |
| 1013 | OP( 0x87, i_xchg_wr16 ) { DEF_wr16; RegWord(ModRM)=dst; PutbackRMWord(ModRM,src); CLKM(5,3); } OP_EPILOGUE; |
| 1014 | |
| 1015 | OP( 0x88, i_mov_br8 ) { GetModRM; uint8 src = RegByte(ModRM); PutRMByte(ModRM,src); CLK(1); } OP_EPILOGUE; |
| 1016 | OP( 0x89, i_mov_wr16 ) { GetModRM; uint16 src = RegWord(ModRM); PutRMWord(ModRM,src); CLK(1); } OP_EPILOGUE; |
| 1017 | OP( 0x8a, i_mov_r8b ) { GetModRM; uint8 src = GetRMByte(ModRM); RegByte(ModRM)=src; CLK(1); } OP_EPILOGUE; |
| 1018 | OP( 0x8b, i_mov_r16w ) { GetModRM; uint16 src = GetRMWord(ModRM); RegWord(ModRM)=src; CLK(1); } OP_EPILOGUE; |
| 1019 | OP( 0x8c, i_mov_wsreg ) { GetModRM; PutRMWord(ModRM,I.sregs[(ModRM & 0x38) >> 3]); CLK(1); } OP_EPILOGUE; |
| 1020 | OP( 0x8d, i_lea ) { uint16 ModRM = FETCH; if(ModRM < 192) { (void)(*GetEA[ModRM])(); } RegWord(ModRM)=EO; CLK(1); } OP_EPILOGUE; |
| 1021 | OP( 0x8e, i_mov_sregw ) { GetModRM; uint16 src = GetRMWord(ModRM); CLKM(3,2); |
| 1022 | switch (ModRM & 0x38) { |
| 1023 | case 0x00: I.sregs[DS1] = src; break; /* mov ds1,ew */ |
| 1024 | case 0x08: I.sregs[PS] = src; break; /* mov cs,ew */ |
| 1025 | case 0x10: I.sregs[SS] = src; break; /* mov ss,ew */ |
| 1026 | case 0x18: I.sregs[DS0] = src; break; /* mov ds0,ew */ |
| 1027 | } |
| 1028 | } OP_EPILOGUE; |
| 1029 | |
| 1030 | OP( 0x8f, i_popw ) { uint16 tmp; GetModRM; POP(tmp); PutRMWord(ModRM,tmp); CLKM(3,1); } OP_EPILOGUE; |
| 1031 | OP( 0x90, i_nop ) { CLK(3); } OP_EPILOGUE; |
| 1032 | |
| 1033 | OP( 0x91, i_xchg_axcx ) { XchgAWReg(CW); CLK(3); } OP_EPILOGUE; |
| 1034 | OP( 0x92, i_xchg_axdx ) { XchgAWReg(DW); CLK(3); } OP_EPILOGUE; |
| 1035 | OP( 0x93, i_xchg_axbx ) { XchgAWReg(BW); CLK(3); } OP_EPILOGUE; |
| 1036 | OP( 0x94, i_xchg_axsp ) { XchgAWReg(SP); CLK(3); } OP_EPILOGUE; |
| 1037 | OP( 0x95, i_xchg_axbp ) { XchgAWReg(BP); CLK(3); } OP_EPILOGUE; |
| 1038 | OP( 0x96, i_xchg_axsi ) { XchgAWReg(IX); CLK(3); } OP_EPILOGUE; |
| 1039 | OP( 0x97, i_xchg_axdi ) { XchgAWReg(IY); CLK(3); } OP_EPILOGUE; |
| 1040 | |
| 1041 | // AKA CVTBW |
| 1042 | OP( 0x98, i_cbw ) { I.regs.b[AH] = (I.regs.b[AL] & 0x80) ? 0xff : 0; CLK(1); } OP_EPILOGUE; |
| 1043 | |
| 1044 | // AKA CVTWL |
| 1045 | OP( 0x99, i_cwd ) { I.regs.w[DW] = (I.regs.b[AH] & 0x80) ? 0xffff : 0; CLK(1); } OP_EPILOGUE; |
| 1046 | |
| 1047 | OP( 0x9a, i_call_far ) { uint32 tmp, tmp2; FETCHuint16(tmp); FETCHuint16(tmp2); PUSH(I.sregs[PS]); PUSH(I.pc); I.pc = (uint16)tmp; I.sregs[PS] = (uint16)tmp2; CLK(10); } OP_EPILOGUE; |
| 1048 | OP( 0x9b, i_poll ) { } OP_EPILOGUE; |
| 1049 | OP( 0x9c, i_pushf ) { i_real_pushf(); } OP_EPILOGUE; |
| 1050 | OP( 0x9d, i_popf ) { i_real_popf(); } OP_EPILOGUE; |
| 1051 | OP( 0x9e, i_sahf ) { uint32 tmp = (CompressFlags() & 0xff00) | (I.regs.b[AH] & 0xd5); ExpandFlags(tmp); CLK(4); } OP_EPILOGUE; |
| 1052 | OP( 0x9f, i_lahf ) { I.regs.b[AH] = CompressFlags() & 0xff; CLK(2); } OP_EPILOGUE; |
| 1053 | |
| 1054 | OP( 0xa0, i_mov_aldisp ) { uint32 addr; FETCHuint16(addr); I.regs.b[AL] = GetMemB(DS0, addr); CLK(1); } OP_EPILOGUE; |
| 1055 | OP( 0xa1, i_mov_axdisp ) { uint32 addr; FETCHuint16(addr); I.regs.b[AL] = GetMemB(DS0, addr); I.regs.b[AH] = GetMemB(DS0, (addr+1)&0xffff); CLK(1); } OP_EPILOGUE; |
| 1056 | OP( 0xa2, i_mov_dispal ) { uint32 addr; FETCHuint16(addr); PutMemB(DS0, addr, I.regs.b[AL]); CLK(1); } OP_EPILOGUE; |
| 1057 | OP( 0xa3, i_mov_dispax ) { uint32 addr; FETCHuint16(addr); PutMemB(DS0, addr, I.regs.b[AL]); PutMemB(DS0, (addr+1)&0xffff, I.regs.b[AH]); CLK(1); } OP_EPILOGUE; |
| 1058 | |
| 1059 | OP( 0xa4, i_movsb ) { i_real_movsb(); } OP_EPILOGUE; |
| 1060 | OP( 0xa5, i_movsw ) { i_real_movsw(); } OP_EPILOGUE; |
| 1061 | OP( 0xa6, i_cmpsb ) { i_real_cmpsb(); } OP_EPILOGUE; |
| 1062 | OP( 0xa7, i_cmpsw ) { i_real_cmpsw(); } OP_EPILOGUE; |
| 1063 | |
| 1064 | OP( 0xa8, i_test_ald8 ) { DEF_ald8; ANDB; CLK(1); } OP_EPILOGUE; |
| 1065 | OP( 0xa9, i_test_axd16 ) { DEF_axd16; ANDW; CLK(1); } OP_EPILOGUE; |
| 1066 | |
| 1067 | OP( 0xaa, i_stosb ) { i_real_stosb(); } OP_EPILOGUE; |
| 1068 | OP( 0xab, i_stosw ) { i_real_stosw(); } OP_EPILOGUE; |
| 1069 | OP( 0xac, i_lodsb ) { i_real_lodsb(); } OP_EPILOGUE; |
| 1070 | OP( 0xad, i_lodsw ) { i_real_lodsw(); } OP_EPILOGUE; |
| 1071 | OP( 0xae, i_scasb ) { i_real_scasb(); } OP_EPILOGUE; |
| 1072 | OP( 0xaf, i_scasw ) { i_real_scasw(); } OP_EPILOGUE; |
| 1073 | |
| 1074 | OP( 0xb0, i_mov_ald8 ) { I.regs.b[AL] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1075 | OP( 0xb1, i_mov_cld8 ) { I.regs.b[CL] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1076 | OP( 0xb2, i_mov_dld8 ) { I.regs.b[DL] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1077 | OP( 0xb3, i_mov_bld8 ) { I.regs.b[BL] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1078 | OP( 0xb4, i_mov_ahd8 ) { I.regs.b[AH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1079 | OP( 0xb5, i_mov_chd8 ) { I.regs.b[CH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1080 | OP( 0xb6, i_mov_dhd8 ) { I.regs.b[DH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1081 | OP( 0xb7, i_mov_bhd8 ) { I.regs.b[BH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1082 | |
| 1083 | OP( 0xb8, i_mov_axd16 ) { I.regs.b[AL] = FETCH; I.regs.b[AH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1084 | OP( 0xb9, i_mov_cxd16 ) { I.regs.b[CL] = FETCH; I.regs.b[CH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1085 | OP( 0xba, i_mov_dxd16 ) { I.regs.b[DL] = FETCH; I.regs.b[DH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1086 | OP( 0xbb, i_mov_bxd16 ) { I.regs.b[BL] = FETCH; I.regs.b[BH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1087 | OP( 0xbc, i_mov_spd16 ) { I.regs.b[SPL] = FETCH; I.regs.b[SPH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1088 | OP( 0xbd, i_mov_bpd16 ) { I.regs.b[BPL] = FETCH; I.regs.b[BPH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1089 | OP( 0xbe, i_mov_sid16 ) { I.regs.b[IXL] = FETCH; I.regs.b[IXH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1090 | OP( 0xbf, i_mov_did16 ) { I.regs.b[IYL] = FETCH; I.regs.b[IYH] = FETCH; CLK(1); } OP_EPILOGUE; |
| 1091 | |
| 1092 | OP( 0xc0, i_rotshft_bd8 ) { |
| 1093 | uint32 src, dst; uint8 c; |
| 1094 | GetModRM; src = (unsigned)GetRMByte(ModRM); dst=src; |
| 1095 | c=FETCH; |
| 1096 | c&=0x1f; |
| 1097 | CLKM(5,3); |
| 1098 | if (c) switch (ModRM & 0x38) { |
| 1099 | case 0x00: do { ROL_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1100 | case 0x08: do { ROR_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1101 | case 0x10: do { ROLC_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1102 | case 0x18: do { RORC_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1103 | case 0x20: SHL_uint8(c); I.AuxVal = 1; break;// |
| 1104 | case 0x28: SHR_uint8(c); I.AuxVal = 1; break;// |
| 1105 | case 0x30: break; |
| 1106 | case 0x38: SHRA_uint8(c); break; |
| 1107 | } |
| 1108 | } OP_EPILOGUE; |
| 1109 | |
| 1110 | OP( 0xc1, i_rotshft_wd8 ) { |
| 1111 | GetModRM; |
| 1112 | uint32 src = (unsigned)GetRMWord(ModRM); |
| 1113 | uint32 dst = src; |
| 1114 | uint8 c = FETCH; |
| 1115 | c&=0x1f; |
| 1116 | CLKM(5,3); |
| 1117 | if (c) switch (ModRM & 0x38) { |
| 1118 | case 0x00: do { ROL_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1119 | case 0x08: do { ROR_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1120 | case 0x10: do { ROLC_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1121 | case 0x18: do { RORC_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1122 | case 0x20: SHL_uint16(c); I.AuxVal = 1; break; |
| 1123 | case 0x28: SHR_uint16(c); I.AuxVal = 1; break; |
| 1124 | case 0x30: break; |
| 1125 | case 0x38: SHRA_uint16(c); break; |
| 1126 | } |
| 1127 | } OP_EPILOGUE; |
| 1128 | |
| 1129 | OP( 0xc2, i_ret_d16 ) { uint32 count = FETCH; count += FETCH << 8; POP(I.pc); I.regs.w[SP]+=count; CLK(6); } OP_EPILOGUE; |
| 1130 | OP( 0xc3, i_ret ) { POP(I.pc); CLK(6); } OP_EPILOGUE; |
| 1131 | OP( 0xc4, i_les_dw ) { GetModRM; uint16 tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; I.sregs[DS1] = GetnextRMWord; CLK(6); } OP_EPILOGUE; |
| 1132 | OP( 0xc5, i_lds_dw ) { GetModRM; uint16 tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; I.sregs[DS0] = GetnextRMWord; CLK(6); } OP_EPILOGUE; |
| 1133 | OP( 0xc6, i_mov_bd8 ) { GetModRM; PutImmRMByte(ModRM); CLK(1); } OP_EPILOGUE; |
| 1134 | OP( 0xc7, i_mov_wd16 ) { GetModRM; PutImmRMWord(ModRM); CLK(1); } OP_EPILOGUE; |
| 1135 | |
| 1136 | // NEC calls it "PREPARE" |
| 1137 | OP( 0xc8, i_enter ) { |
| 1138 | uint32 nb = FETCH; |
| 1139 | uint32 i,level; |
| 1140 | |
| 1141 | CLK(19); |
| 1142 | nb += FETCH << 8; |
| 1143 | |
| 1144 | level = FETCH; |
| 1145 | level &= 0x1F; // Only lower 5 bits are valid on V30MZ |
| 1146 | |
| 1147 | PUSH(I.regs.w[BP]); |
| 1148 | I.regs.w[BP]=I.regs.w[SP]; |
| 1149 | I.regs.w[SP] -= nb; |
| 1150 | for (i=1;i<level;i++) { |
| 1151 | PUSH(GetMemW(SS,I.regs.w[BP]-i*2)); |
| 1152 | CLK(4); |
| 1153 | } |
| 1154 | if (level) PUSH(I.regs.w[BP]); |
| 1155 | } OP_EPILOGUE; |
| 1156 | |
| 1157 | OP( 0xc9, i_leave ) { |
| 1158 | I.regs.w[SP]=I.regs.w[BP]; |
| 1159 | POP(I.regs.w[BP]); |
| 1160 | CLK(2); |
| 1161 | } OP_EPILOGUE; |
| 1162 | |
| 1163 | OP( 0xca, i_retf_d16 ) { uint32 count = FETCH; count += FETCH << 8; POP(I.pc); POP(I.sregs[PS]); I.regs.w[SP]+=count; CLK(9); } OP_EPILOGUE; |
| 1164 | OP( 0xcb, i_retf ) { POP(I.pc); POP(I.sregs[PS]); CLK(8); } OP_EPILOGUE; |
| 1165 | OP( 0xcc, i_int3 ) { nec_interrupt(3); CLK(9); } OP_EPILOGUE; |
| 1166 | OP( 0xcd, i_int ) { nec_interrupt(FETCH); CLK(10); } OP_EPILOGUE; |
| 1167 | OP( 0xce, i_into ) { if (FLAG_O) { nec_interrupt(4); CLK(13); } else CLK(6); } OP_EPILOGUE; |
| 1168 | OP( 0xcf, i_iret ) { POP(I.pc); POP(I.sregs[PS]); i_real_popf(); CLK(10); } OP_EPILOGUE; |
| 1169 | |
| 1170 | OP( 0xd0, i_rotshft_b ) { |
| 1171 | uint32 src, dst; GetModRM; src = (uint32)GetRMByte(ModRM); dst=src; |
| 1172 | CLKM(3,1); |
| 1173 | switch (ModRM & 0x38) { |
| 1174 | case 0x00: ROL_uint8; PutbackRMByte(ModRM,(uint8)dst); I.OverVal = (src^dst)&0x80; break; |
| 1175 | case 0x08: ROR_uint8; PutbackRMByte(ModRM,(uint8)dst); I.OverVal = (src^dst)&0x80; break; |
| 1176 | case 0x10: ROLC_uint8; PutbackRMByte(ModRM,(uint8)dst); I.OverVal = (src^dst)&0x80; break; |
| 1177 | case 0x18: RORC_uint8; PutbackRMByte(ModRM,(uint8)dst); I.OverVal = (src^dst)&0x80; break; |
| 1178 | case 0x20: SHL_uint8(1); I.OverVal = (src^dst)&0x80;I.AuxVal = 1; break; |
| 1179 | case 0x28: SHR_uint8(1); I.OverVal = (src^dst)&0x80;I.AuxVal = 1; break; |
| 1180 | case 0x30: break; |
| 1181 | case 0x38: SHRA_uint8(1); I.OverVal = 0; break; |
| 1182 | } |
| 1183 | } OP_EPILOGUE; |
| 1184 | |
| 1185 | OP( 0xd1, i_rotshft_w ) { |
| 1186 | uint32 src, dst; GetModRM; src = (uint32)GetRMWord(ModRM); dst=src; |
| 1187 | CLKM(3,1); |
| 1188 | switch (ModRM & 0x38) { |
| 1189 | case 0x00: ROL_uint16; PutbackRMWord(ModRM,(uint16)dst); I.OverVal = (src^dst)&0x8000; break; |
| 1190 | case 0x08: ROR_uint16; PutbackRMWord(ModRM,(uint16)dst); I.OverVal = (src^dst)&0x8000; break; |
| 1191 | case 0x10: ROLC_uint16; PutbackRMWord(ModRM,(uint16)dst); I.OverVal = (src^dst)&0x8000; break; |
| 1192 | case 0x18: RORC_uint16; PutbackRMWord(ModRM,(uint16)dst); I.OverVal = (src^dst)&0x8000; break; |
| 1193 | case 0x20: SHL_uint16(1); I.AuxVal = 1;I.OverVal = (src^dst)&0x8000; break; |
| 1194 | case 0x28: SHR_uint16(1); I.AuxVal = 1;I.OverVal = (src^dst)&0x8000; break; |
| 1195 | case 0x30: break; |
| 1196 | case 0x38: SHRA_uint16(1); I.AuxVal = 1;I.OverVal = 0; break; |
| 1197 | } |
| 1198 | } OP_EPILOGUE; |
| 1199 | |
| 1200 | OP( 0xd2, i_rotshft_bcl ) { |
| 1201 | uint32 src, dst; uint8 c; GetModRM; src = (uint32)GetRMByte(ModRM); dst=src; |
| 1202 | c=I.regs.b[CL]; |
| 1203 | CLKM(5,3); |
| 1204 | c&=0x1f; |
| 1205 | if (c) switch (ModRM & 0x38) { |
| 1206 | case 0x00: do { ROL_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1207 | case 0x08: do { ROR_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1208 | case 0x10: do { ROLC_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1209 | case 0x18: do { RORC_uint8; c--; } while (c>0); PutbackRMByte(ModRM,(uint8)dst); break; |
| 1210 | case 0x20: SHL_uint8(c); I.AuxVal = 1; break; |
| 1211 | case 0x28: SHR_uint8(c); I.AuxVal = 1;break; |
| 1212 | case 0x30: break; |
| 1213 | case 0x38: SHRA_uint8(c); break; |
| 1214 | } |
| 1215 | } OP_EPILOGUE; |
| 1216 | |
| 1217 | OP( 0xd3, i_rotshft_wcl ) { |
| 1218 | uint32 src, dst; uint8 c; GetModRM; src = (uint32)GetRMWord(ModRM); dst=src; |
| 1219 | c=I.regs.b[CL]; |
| 1220 | c&=0x1f; |
| 1221 | CLKM(5,3); |
| 1222 | if (c) switch (ModRM & 0x38) { |
| 1223 | case 0x00: do { ROL_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1224 | case 0x08: do { ROR_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1225 | case 0x10: do { ROLC_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1226 | case 0x18: do { RORC_uint16; c--; } while (c>0); PutbackRMWord(ModRM,(uint16)dst); break; |
| 1227 | case 0x20: SHL_uint16(c); I.AuxVal = 1; break; |
| 1228 | case 0x28: SHR_uint16(c); I.AuxVal = 1; break; |
| 1229 | case 0x30: break; |
| 1230 | case 0x38: SHRA_uint16(c); break; |
| 1231 | } |
| 1232 | } OP_EPILOGUE; |
| 1233 | |
| 1234 | /* Warning: Do not modify this code, or everything |
| 1235 | * will break |
| 1236 | * (ignore any "variable 'mult' set but not used" |
| 1237 | * compiler warnings; 'FETCH' is a non-trivial |
| 1238 | * macro, and is absolutely required) */ |
| 1239 | OP( 0xd4, i_aam ) { uint32 mult=FETCH; mult=0; I.regs.b[AH] = I.regs.b[AL] / 10; I.regs.b[AL] %= 10; SetSZPF_Word(I.regs.w[AW]); CLK(17); } OP_EPILOGUE; |
| 1240 | OP( 0xd5, i_aad ) { uint32 mult=FETCH; mult=0; I.regs.b[AL] = I.regs.b[AH] * 10 + I.regs.b[AL]; I.regs.b[AH] = 0; SetSZPF_Byte(I.regs.b[AL]); CLK(6); } OP_EPILOGUE; |
| 1241 | OP( 0xd6, i_setalc ) { I.regs.b[AL] = (CF)?0xff:0x00; CLK(3); } OP_EPILOGUE; |
| 1242 | OP( 0xd7, i_trans ) { uint32 dest = (I.regs.w[BW]+I.regs.b[AL])&0xffff; I.regs.b[AL] = GetMemB(DS0, dest); CLK(5); } OP_EPILOGUE; |
| 1243 | |
| 1244 | case 0xd8: |
| 1245 | case 0xd9: |
| 1246 | case 0xda: |
| 1247 | case 0xdb: |
| 1248 | case 0xdc: |
| 1249 | case 0xdd: |
| 1250 | case 0xde: |
| 1251 | case 0xdf: |
| 1252 | { GetModRM; CLK(1); } OP_EPILOGUE; |
| 1253 | |
| 1254 | OP( 0xe0, i_loopne ) { int8 disp = (int8)FETCH; I.regs.w[CW]--; if (!ZF && I.regs.w[CW]) { I.pc = (uint16)(I.pc+disp); CLK(6); } else CLK(3); } OP_EPILOGUE; |
| 1255 | OP( 0xe1, i_loope ) { int8 disp = (int8)FETCH; I.regs.w[CW]--; if ( ZF && I.regs.w[CW]) { I.pc = (uint16)(I.pc+disp); CLK(6); } else CLK(3); } OP_EPILOGUE; |
| 1256 | OP( 0xe2, i_loop ) { int8 disp = (int8)FETCH; I.regs.w[CW]--; if (I.regs.w[CW]) { I.pc = (uint16)(I.pc+disp); CLK(5); } else CLK(2); } OP_EPILOGUE; |
| 1257 | OP( 0xe3, i_jcxz ) { int8 disp = (int8)FETCH; if (I.regs.w[CW] == 0) { I.pc = (uint16)(I.pc+disp); CLK(4); } else CLK(1); } OP_EPILOGUE; |
| 1258 | OP( 0xe4, i_inal ) { uint8 port = FETCH; I.regs.b[AL] = read_port(port); CLK(6); } OP_EPILOGUE; |
| 1259 | OP( 0xe5, i_inax ) { uint8 port = FETCH; I.regs.b[AL] = read_port(port); I.regs.b[AH] = read_port(port+1); CLK(6); } OP_EPILOGUE; |
| 1260 | OP( 0xe6, i_outal ) { uint8 port = FETCH; write_port(port, I.regs.b[AL]); CLK(6); } OP_EPILOGUE; |
| 1261 | OP( 0xe7, i_outax ) { uint8 port = FETCH; write_port(port, I.regs.b[AL]); write_port(port+1, I.regs.b[AH]); CLK(6); } OP_EPILOGUE; |
| 1262 | |
| 1263 | OP( 0xe8, i_call_d16 ) { uint32 tmp; FETCHuint16(tmp); PUSH(I.pc); I.pc = (uint16)(I.pc+(int16)tmp); CLK(5); } OP_EPILOGUE; |
| 1264 | OP( 0xe9, i_jmp_d16 ) { uint32 tmp; FETCHuint16(tmp); I.pc = (uint16)(I.pc+(int16)tmp); CLK(4); } OP_EPILOGUE; |
| 1265 | OP( 0xea, i_jmp_far ) { uint32 tmp,tmp1; FETCHuint16(tmp); FETCHuint16(tmp1); I.sregs[PS] = (uint16)tmp1; I.pc = (uint16)tmp; CLK(7); } OP_EPILOGUE; |
| 1266 | OP( 0xeb, i_jmp_d8 ) { int tmp = (int)((int8)FETCH); CLK(4);I.pc = (uint16)(I.pc+tmp); } OP_EPILOGUE; |
| 1267 | |
| 1268 | OP( 0xec, i_inaldx ) { I.regs.b[AL] = read_port(I.regs.w[DW]); CLK(6);} OP_EPILOGUE; |
| 1269 | OP( 0xed, i_inaxdx ) { uint32 port = I.regs.w[DW]; I.regs.b[AL] = read_port(port); I.regs.b[AH] = read_port(port+1); CLK(6); } OP_EPILOGUE; |
| 1270 | |
| 1271 | OP( 0xee, i_outdxal ) { write_port(I.regs.w[DW], I.regs.b[AL]); CLK(6); } OP_EPILOGUE; |
| 1272 | OP( 0xef, i_outdxax ) { uint32 port = I.regs.w[DW]; write_port(port, I.regs.b[AL]); write_port(port+1, I.regs.b[AH]); CLK(6); } OP_EPILOGUE; |
| 1273 | |
| 1274 | // NEC calls it "BUSLOCK" |
| 1275 | OP( 0xf0, i_lock ) { CLK(1); DoOP(FETCHOP); } OP_EPILOGUE; |
| 1276 | |
| 1277 | // We put CHK_ICOUNT *after* the first iteration has completed, to match real behavior. |
| 1278 | #define CHK_ICOUNT(cond) if(v30mz_ICount < 0 && (cond)) { I.pc -= seg_prefix ? 3 : 2; break; } |
| 1279 | |
| 1280 | OP( 0xf2, i_repne ) |
| 1281 | { |
| 1282 | uint32 next = FETCHOP; |
| 1283 | |
| 1284 | switch(next) { /* Segments */ |
| 1285 | case 0x26: seg_prefix=true; prefix_base=I.sregs[DS1]<<4; next = FETCHOP; CLK(2); break; |
| 1286 | case 0x2e: seg_prefix=true; prefix_base=I.sregs[PS]<<4; next = FETCHOP; CLK(2); break; |
| 1287 | case 0x36: seg_prefix=true; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break; |
| 1288 | case 0x3e: seg_prefix=true; prefix_base=I.sregs[DS0]<<4; next = FETCHOP; CLK(2); break; |
| 1289 | } |
| 1290 | |
| 1291 | switch(next) { |
| 1292 | case 0x6c: CLK(5); if (I.regs.w[CW]) do { i_real_insb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1293 | case 0x6d: CLK(5); if (I.regs.w[CW]) do { i_real_insw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1294 | case 0x6e: CLK(5); if (I.regs.w[CW]) do { i_real_outsb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1295 | case 0x6f: CLK(5); if (I.regs.w[CW]) do { i_real_outsw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1296 | case 0xa4: CLK(5); if (I.regs.w[CW]) do { i_real_movsb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1297 | case 0xa5: CLK(5); if (I.regs.w[CW]) do { i_real_movsw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1298 | case 0xa6: CLK(5); if (I.regs.w[CW]) do { i_real_cmpsb(); I.regs.w[CW]--; CLK(3); CHK_ICOUNT(I.regs.w[CW] && ZF == 0); /* 6 + 3 = 9 */ } while (I.regs.w[CW]>0 && ZF==0); break; |
| 1299 | case 0xa7: CLK(5); if (I.regs.w[CW]) do { i_real_cmpsw(); I.regs.w[CW]--; CLK(3); CHK_ICOUNT(I.regs.w[CW] && ZF == 0); /* 6 + 3 = 9 */ } while (I.regs.w[CW]>0 && ZF==0); break; |
| 1300 | case 0xaa: CLK(5); if (I.regs.w[CW]) do { i_real_stosb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1301 | case 0xab: CLK(5); if (I.regs.w[CW]) do { i_real_stosw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1302 | case 0xac: CLK(5); if (I.regs.w[CW]) do { i_real_lodsb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1303 | case 0xad: CLK(5); if (I.regs.w[CW]) do { i_real_lodsw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1304 | case 0xae: CLK(5); if (I.regs.w[CW]) do { i_real_scasb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW] && ZF == 0); } while (I.regs.w[CW]>0 && ZF==0); break; |
| 1305 | case 0xaf: CLK(5); if (I.regs.w[CW]) do { i_real_scasw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW] && ZF == 0); } while (I.regs.w[CW]>0 && ZF==0); break; |
| 1306 | default: DoOP(next); break; |
| 1307 | } |
| 1308 | seg_prefix=false; |
| 1309 | } OP_EPILOGUE; |
| 1310 | |
| 1311 | OP( 0xf3, i_repe) |
| 1312 | { |
| 1313 | uint32 next = FETCHOP; |
| 1314 | |
| 1315 | switch(next) { /* Segments */ |
| 1316 | case 0x26: seg_prefix=true; prefix_base=I.sregs[DS1]<<4; next = FETCHOP; CLK(2); break; |
| 1317 | case 0x2e: seg_prefix=true; prefix_base=I.sregs[PS]<<4; next = FETCHOP; CLK(2); break; |
| 1318 | case 0x36: seg_prefix=true; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break; |
| 1319 | case 0x3e: seg_prefix=true; prefix_base=I.sregs[DS0]<<4; next = FETCHOP; CLK(2); break; |
| 1320 | } |
| 1321 | switch(next) { |
| 1322 | case 0x6c: CLK(5); if (I.regs.w[CW]) do { i_real_insb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1323 | case 0x6d: CLK(5); if (I.regs.w[CW]) do { i_real_insw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1324 | case 0x6e: CLK(5); if (I.regs.w[CW]) do { i_real_outsb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1325 | case 0x6f: CLK(5); if (I.regs.w[CW]) do { i_real_outsw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1326 | case 0xa4: CLK(5); if (I.regs.w[CW]) do { i_real_movsb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1327 | case 0xa5: CLK(5); if (I.regs.w[CW]) do { i_real_movsw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1328 | case 0xa6: CLK(5); if (I.regs.w[CW]) do { i_real_cmpsb(); I.regs.w[CW]--; CLK(3); CHK_ICOUNT(I.regs.w[CW] && ZF == 1); /* 6 + 3 = 9 */ } while (I.regs.w[CW]>0 && ZF==1); break; |
| 1329 | case 0xa7: CLK(5); if (I.regs.w[CW]) do { i_real_cmpsw(); I.regs.w[CW]--; CLK(3); CHK_ICOUNT(I.regs.w[CW] && ZF == 1);/* 6 + 3 = 9 */ } while (I.regs.w[CW]>0 && ZF==1); break; |
| 1330 | case 0xaa: CLK(5); if (I.regs.w[CW]) do { i_real_stosb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1331 | case 0xab: CLK(5); if (I.regs.w[CW]) do { i_real_stosw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1332 | case 0xac: CLK(5); if (I.regs.w[CW]) do { i_real_lodsb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1333 | case 0xad: CLK(5); if (I.regs.w[CW]) do { i_real_lodsw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW]); } while (I.regs.w[CW]>0); break; |
| 1334 | case 0xae: CLK(5); if (I.regs.w[CW]) do { i_real_scasb(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW] && ZF == 1); } while (I.regs.w[CW]>0 && ZF==1); break; |
| 1335 | case 0xaf: CLK(5); if (I.regs.w[CW]) do { i_real_scasw(); I.regs.w[CW]--; CHK_ICOUNT(I.regs.w[CW] && ZF == 1); } while (I.regs.w[CW]>0 && ZF==1); break; |
| 1336 | default: DoOP(next); break; |
| 1337 | } |
| 1338 | seg_prefix=false; |
| 1339 | } OP_EPILOGUE; |
| 1340 | |
| 1341 | OP( 0xf4, i_hlt ) { InHLT = true; CheckInHLT(); } OP_EPILOGUE; |
| 1342 | |
| 1343 | OP( 0xf5, i_cmc ) { I.CarryVal = !CF; CLK(4); } OP_EPILOGUE; |
| 1344 | OP( 0xf6, i_f6pre ) { uint32 tmp; uint32 uresult,uresult2; int32 result,result2; |
| 1345 | GetModRM; tmp = GetRMByte(ModRM); |
| 1346 | switch (ModRM & 0x38) { |
| 1347 | case 0x00: tmp &= FETCH; I.CarryVal = I.OverVal = I.AuxVal=0; SetSZPF_Byte(tmp); CLKM(2,1); break; /* TEST */ |
| 1348 | case 0x08: break; |
| 1349 | case 0x10: PutbackRMByte(ModRM,~tmp); CLKM(3,1); break; /* NOT */ |
| 1350 | |
| 1351 | case 0x18: I.CarryVal=(tmp!=0);tmp=(~tmp)+1; SetSZPF_Byte(tmp); PutbackRMByte(ModRM,tmp&0xff); CLKM(3,1); break; /* NEG */ |
| 1352 | case 0x20: uresult = I.regs.b[AL]*tmp; I.regs.w[AW]=(uint16)uresult; I.CarryVal=I.OverVal=(I.regs.b[AH]!=0); CLKM(4,3); break; /* MULU */ |
| 1353 | case 0x28: result = (int16)((int8)I.regs.b[AL])*(int16)((int8)tmp); I.regs.w[AW]=(uint16)result; I.CarryVal=I.OverVal=(I.regs.b[AH]!=0); CLKM(4,3); break; /* MUL */ |
| 1354 | case 0x30: if (tmp) { DIVUB; } else nec_interrupt(0); CLKM(16,15); break; |
| 1355 | case 0x38: if (tmp) { DIVB; } else nec_interrupt(0); CLKM(18,17); break; |
| 1356 | } |
| 1357 | } OP_EPILOGUE; |
| 1358 | |
| 1359 | OP( 0xf7, i_f7pre ) { uint32 tmp,tmp2; uint32 uresult,uresult2; int32 result,result2; |
| 1360 | GetModRM; tmp = GetRMWord(ModRM); |
| 1361 | switch (ModRM & 0x38) { |
| 1362 | case 0x00: FETCHuint16(tmp2); tmp &= tmp2; I.CarryVal = I.OverVal = I.AuxVal=0; SetSZPF_Word(tmp); CLKM(2,1); break; /* TEST */ |
| 1363 | case 0x08: break; |
| 1364 | case 0x10: PutbackRMWord(ModRM,~tmp); CLKM(3,1); break; /* NOT */ |
| 1365 | case 0x18: I.CarryVal=(tmp!=0); tmp=(~tmp)+1; SetSZPF_Word(tmp); PutbackRMWord(ModRM,tmp&0xffff); CLKM(3,1); break; /* NEG */ |
| 1366 | case 0x20: uresult = I.regs.w[AW]*tmp; I.regs.w[AW]=uresult&0xffff; I.regs.w[DW]=((uint32)uresult)>>16; I.CarryVal=I.OverVal=(I.regs.w[DW]!=0); CLKM(4,3); break; /* MULU */ |
| 1367 | case 0x28: result = (int32)((int16)I.regs.w[AW])*(int32)((int16)tmp); I.regs.w[AW]=result&0xffff; I.regs.w[DW]=result>>16; I.CarryVal=I.OverVal=(I.regs.w[DW]!=0); CLKM(4,3); break; /* MUL */ |
| 1368 | case 0x30: if (tmp) { DIVUW; } else nec_interrupt(0); CLKM(24,23); break; |
| 1369 | case 0x38: if (tmp) { DIVW; } else nec_interrupt(0); CLKM(25,24); break; |
| 1370 | } |
| 1371 | } OP_EPILOGUE; |
| 1372 | |
| 1373 | OP( 0xf8, i_clc ) { I.CarryVal = 0; CLK(4); } OP_EPILOGUE; |
| 1374 | OP( 0xf9, i_stc ) { I.CarryVal = 1; CLK(4); } OP_EPILOGUE; |
| 1375 | OP( 0xfa, i_di ) { SetIF(0); CLK(4); } OP_EPILOGUE; |
| 1376 | OP( 0xfb, i_ei ) { SetIF(1); CLK(4); } OP_EPILOGUE; |
| 1377 | OP( 0xfc, i_cld ) { SetDF(0); CLK(4); } OP_EPILOGUE; |
| 1378 | OP( 0xfd, i_std ) { SetDF(1); CLK(4); } OP_EPILOGUE; |
| 1379 | OP( 0xfe, i_fepre ) { uint32 tmp, tmp1; GetModRM; tmp=GetRMByte(ModRM); |
| 1380 | switch(ModRM & 0x38) { |
| 1381 | case 0x00: tmp1 = tmp+1; I.OverVal = (tmp==0x7f); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(uint8)tmp1); CLKM(3,1); break; /* INC */ |
| 1382 | case 0x08: tmp1 = tmp-1; I.OverVal = (tmp==0x80); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(uint8)tmp1); CLKM(3,1); break; /* DEC */ |
| 1383 | } |
| 1384 | } OP_EPILOGUE; |
| 1385 | |
| 1386 | OP( 0xff, i_ffpre ) { uint32 tmp, tmp1; GetModRM; tmp=GetRMWord(ModRM); |
| 1387 | switch(ModRM & 0x38) { |
| 1388 | case 0x00: tmp1 = tmp+1; I.OverVal = (tmp==0x7fff); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(uint16)tmp1); CLKM(3,1); break; /* INC */ |
| 1389 | case 0x08: tmp1 = tmp-1; I.OverVal = (tmp==0x8000); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(uint16)tmp1); CLKM(3,1); break; /* DEC */ |
| 1390 | case 0x10: PUSH(I.pc); I.pc = (uint16)tmp; CLKM(6,5); break; /* CALL */ |
| 1391 | case 0x18: tmp1 = I.sregs[PS]; I.sregs[PS] = GetnextRMWord; PUSH(tmp1); PUSH(I.pc); I.pc = tmp; CLKM(12,1); break; /* CALL FAR */ |
| 1392 | case 0x20: I.pc = tmp; CLKM(5,4); break; /* JMP */ |
| 1393 | case 0x28: I.pc = tmp; I.sregs[PS] = GetnextRMWord; CLKM(10,1); break; /* JMP FAR */ |
| 1394 | case 0x30: PUSH(tmp); CLKM(2,1); break; |
| 1395 | } |
| 1396 | } OP_EPILOGUE; |
| 1397 | } // End switch statement |
| 1398 | |
| 1399 | |
| 1400 | } // End func |
| 1401 | |
| 1402 | |
| 1403 | /*****************************************************************************/ |
| 1404 | |
| 1405 | unsigned v30mz_get_reg(int regnum) |
| 1406 | { |
| 1407 | switch( regnum ) |
| 1408 | { |
| 1409 | case NEC_PC: |
| 1410 | return I.pc; |
| 1411 | case NEC_SP: |
| 1412 | return I.regs.w[SP]; |
| 1413 | case NEC_FLAGS: |
| 1414 | return CompressFlags(); |
| 1415 | case NEC_AW: |
| 1416 | return I.regs.w[AW]; |
| 1417 | case NEC_CW: |
| 1418 | return I.regs.w[CW]; |
| 1419 | case NEC_DW: |
| 1420 | return I.regs.w[DW]; |
| 1421 | case NEC_BW: |
| 1422 | return I.regs.w[BW]; |
| 1423 | case NEC_BP: |
| 1424 | return I.regs.w[BP]; |
| 1425 | case NEC_IX: |
| 1426 | return I.regs.w[IX]; |
| 1427 | case NEC_IY: |
| 1428 | return I.regs.w[IY]; |
| 1429 | case NEC_DS1: |
| 1430 | return I.sregs[DS1]; |
| 1431 | case NEC_PS: |
| 1432 | return I.sregs[PS]; |
| 1433 | case NEC_SS: |
| 1434 | return I.sregs[SS]; |
| 1435 | case NEC_DS0: |
| 1436 | return I.sregs[DS0]; |
| 1437 | } |
| 1438 | return 0; |
| 1439 | } |
| 1440 | |
| 1441 | void v30mz_set_reg(int regnum, unsigned val) |
| 1442 | { |
| 1443 | switch( regnum ) |
| 1444 | { |
| 1445 | case NEC_PC: I.pc = val; break; |
| 1446 | case NEC_SP: I.regs.w[SP] = val; break; |
| 1447 | case NEC_FLAGS: ExpandFlags(val); break; |
| 1448 | case NEC_AW: I.regs.w[AW] = val; break; |
| 1449 | case NEC_CW: I.regs.w[CW] = val; break; |
| 1450 | case NEC_DW: I.regs.w[DW] = val; break; |
| 1451 | case NEC_BW: I.regs.w[BW] = val; break; |
| 1452 | case NEC_BP: I.regs.w[BP] = val; break; |
| 1453 | case NEC_IX: I.regs.w[IX] = val; break; |
| 1454 | case NEC_IY: I.regs.w[IY] = val; break; |
| 1455 | case NEC_DS1: I.sregs[DS1] = val; break; |
| 1456 | case NEC_PS: I.sregs[PS] = val; break; |
| 1457 | case NEC_SS: I.sregs[SS] = val; break; |
| 1458 | case NEC_DS0: I.sregs[DS0] = val; break; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | void v30mz_execute(int cycles) |
| 1463 | { |
| 1464 | v30mz_ICount += cycles; |
| 1465 | |
| 1466 | if(InHLT) |
| 1467 | { |
| 1468 | WSwan_InterruptCheck(); |
| 1469 | if(InHLT) |
| 1470 | { |
| 1471 | int32 tmp = v30mz_ICount; |
| 1472 | |
| 1473 | if(tmp > 0) |
| 1474 | CLK(tmp); |
| 1475 | |
| 1476 | return; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | while(v30mz_ICount > 0) |
| 1481 | { |
| 1482 | |
| 1483 | WSwan_InterruptCheck(); |
| 1484 | |
| 1485 | DoOP(FETCHOP); |
| 1486 | } |
| 1487 | |
| 1488 | } |
| 1489 | |
| 1490 | int v30mz_StateAction(StateMem *sm, int load, int data_only) |
| 1491 | { |
| 1492 | uint16 PSW; |
| 1493 | |
| 1494 | SFORMAT StateRegs[] = |
| 1495 | { |
| 1496 | SFVARN(I.pc, "IP"), |
| 1497 | SFARRAY16N(I.regs.w, 8, "regs"), |
| 1498 | SFARRAY16N(I.sregs, 4, "sregs"), |
| 1499 | |
| 1500 | SFVARN(v30mz_ICount, "ICount"), |
| 1501 | SFVARN_BOOL(InHLT, "InHLT"), |
| 1502 | SFVARN(prefix_base, "prefix_base"), |
| 1503 | SFVARN(seg_prefix, "seg_prefix"), |
| 1504 | SFVARN(PSW, "PSW"), |
| 1505 | SFEND |
| 1506 | }; |
| 1507 | |
| 1508 | PSW = CompressFlags(); |
| 1509 | |
| 1510 | if(!MDFNSS_StateAction(sm, load, data_only, StateRegs, "V30", false)) |
| 1511 | return 0; |
| 1512 | |
| 1513 | if(load) |
| 1514 | { |
| 1515 | ExpandFlags(PSW); |
| 1516 | } |
| 1517 | |
| 1518 | return 1; |
| 1519 | } |