Previous 15994 Revisions Next

r11964 Thursday 16th June, 2011 at 05:39:45 UTC by Miodrag Milanović
i286 - Fix bunch of fault restarts
pcjr - Fixed floppy issues [Carl]
[src/emu/cpu/i86]i86priv.h instr186.c instr286.c instr286.h instr86.c
[src/mess/drivers]pc.c
[src/mess/machine]pc_fdc.c pc_fdc.h

src/emu/cpu/i86/instr186.c
r11963r11964
1616{
1717   unsigned tmp=cpustate->regs.w[SP];
1818
19#ifdef I80286
20   if(PM) i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]-16, 16, I80286_WRITE);
21#endif
1922   ICOUNT -= timing.pusha;
2023   PUSH(cpustate->regs.w[AX]);
2124   PUSH(cpustate->regs.w[CX]);
r11963r11964
3134static void PREFIX186(_popa)(i8086_state *cpustate)    /* Opcode 0x61 */
3235{
3336
37#ifdef I80286
38   if(PM) i80286_check_permission(cpustate, SS, cpustate->regs.w[SP], 16, I80286_READ);
39#endif
3440   ICOUNT -= timing.popa;
3541   POP(cpustate->regs.w[DI]);
3642   POP(cpustate->regs.w[SI]);
r11963r11964
100106
101107static void PREFIX186(_insb)(i8086_state *cpustate)    /* Opcode 0x6c */
102108{
109#ifdef I80286
110   if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0);
111#endif
103112   ICOUNT -= timing.ins8;
104113   PutMemB(ES,cpustate->regs.w[DI],read_port_byte(cpustate->regs.w[DX]));
105114   cpustate->regs.w[DI] += cpustate->DirVal;
r11963r11964
107116
108117static void PREFIX186(_insw)(i8086_state *cpustate)    /* Opcode 0x6d */
109118{
119#ifdef I80286
120   if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0);
121#endif
110122   ICOUNT -= timing.ins16;
111123   PutMemW(ES,cpustate->regs.w[DI],read_port_word(cpustate->regs.w[DX]));
112124   cpustate->regs.w[DI] += 2 * cpustate->DirVal;
r11963r11964
114126
115127static void PREFIX186(_outsb)(i8086_state *cpustate)    /* Opcode 0x6e */
116128{
129#ifdef I80286
130   if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0);
131#endif
117132   ICOUNT -= timing.outs8;
118133   write_port_byte(cpustate->regs.w[DX],GetMemB(DS,cpustate->regs.w[SI]));
119134   cpustate->regs.w[SI] += cpustate->DirVal; /* GOL 11/27/01 */
r11963r11964
121136
122137static void PREFIX186(_outsw)(i8086_state *cpustate)    /* Opcode 0x6f */
123138{
139#ifdef I80286
140   if (PM && (CPL>IOPL)) throw TRAP(GENERAL_PROTECTION_FAULT, 0);
141#endif
124142   ICOUNT -= timing.outs16;
125143   write_port_word(cpustate->regs.w[DX],GetMemW(DS,cpustate->regs.w[SI]));
126144   cpustate->regs.w[SI] += 2 * cpustate->DirVal; /* GOL 11/27/01 */
r11963r11964
146164
147165static void PREFIX186(_enter)(i8086_state *cpustate)    /* Opcode 0xc8 */
148166{
149   unsigned nb = FETCH;    unsigned i,level;
167   unsigned nb = FETCH;
168   unsigned i,level;
169   UINT16 fp;
150170
151171   nb += FETCH << 8;
172#ifdef I80286
173   level = FETCH & 0x1f;
174   if(PM) i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]-2-(level*2), 2+(level*2), I80286_WRITE);
175#else
152176   level = FETCH;
177#endif
153178   ICOUNT -= (level == 0) ? timing.enter0 : (level == 1) ? timing.enter1 : timing.enter_base + level * timing.enter_count;
154179   PUSH(cpustate->regs.w[BP]);
155   cpustate->regs.w[BP]=cpustate->regs.w[SP];
156   cpustate->regs.w[SP] -= nb;
180   fp = cpustate->regs.w[SP];
157181   for (i=1;i<level;i++)
158182      PUSH(GetMemW(SS,cpustate->regs.w[BP]-i*2));
159   if (level) PUSH(cpustate->regs.w[BP]);
183   if (level) PUSH(fp);
184   cpustate->regs.w[BP] = fp;
185   cpustate->regs.w[SP] -= nb;
160186}
161187
162188static void PREFIX186(_leave)(i8086_state *cpustate)    /* Opcode 0xc9 */
src/emu/cpu/i86/instr286.c
r11963r11964
152152   cpustate->regs.w[SP] += 2;
153153}
154154
155static void i80286_data_descriptor_full(i80286_state *cpustate,int reg, UINT16 selector, int cpl, UINT32 trap)
155static void i80286_data_descriptor_full(i80286_state *cpustate, int reg, UINT16 selector, int cpl, UINT32 trap, UINT16 offset, int size)
156156{
157157   if (PM) {
158158      UINT16 desc[3];
r11963r11964
189189         if (CODE(r) && !READ(r)) throw trap;
190190         if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(IDXTBL(selector)+(trap&1)));
191191      }
192      if (offset+size) {
193         if ((CODE(r) || !EXPDOWN(r)) && ((offset+size-1) > LIMIT(desc))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap;
194         if (!CODE(r) && EXPDOWN(r) && ((offset <= LIMIT(desc)) || ((offset+size) > 0xffff))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap;
195      }
192196
193197      SET_ACC(desc);
194198      WriteWord(addr+4, desc[2]);
r11963r11964
204208
205209static void i80286_data_descriptor(i80286_state *cpustate, int reg, UINT16 selector)
206210{
207   i80286_data_descriptor_full(cpustate, reg, selector, CPL, TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector)));
211   i80286_data_descriptor_full(cpustate, reg, selector, CPL, TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector)), 0, 0);
208212}
209213
210214static void i80286_switch_task(i80286_state *cpustate, UINT16 ntask, int type)
r11963r11964
296300
297301   if (type == CALL) cpustate->flags |= 0x4000;
298302   cpustate->msw |= 8;
299   i80286_data_descriptor_full(cpustate, SS, ntss[TSS_SS], RPL(ntss[TSS_CS]), TRAP(INVALID_TSS,IDXTBL(ntss[TSS_SS])));
303   i80286_data_descriptor_full(cpustate, SS, ntss[TSS_SS], RPL(ntss[TSS_CS]), TRAP(INVALID_TSS,IDXTBL(ntss[TSS_SS])), 0, 0);
300304
301305   cpustate->sregs[CS] = IDXTBL(cpustate->sregs[CS]) | RPL(ntss[TSS_CS]);  // fixme
302306   try {
r11963r11964
307311      throw e;
308312   }
309313
310   i80286_data_descriptor_full(cpustate, ES, ntss[TSS_ES], RPL(ntss[TSS_CS]), TRAP(INVALID_TSS,IDXTBL(ntss[TSS_ES])));
311   i80286_data_descriptor_full(cpustate, DS, ntss[TSS_DS], RPL(ntss[TSS_CS]), TRAP(INVALID_TSS,IDXTBL(ntss[TSS_DS])));
314   i80286_data_descriptor_full(cpustate, ES, ntss[TSS_ES], RPL(ntss[TSS_CS]), TRAP(INVALID_TSS,IDXTBL(ntss[TSS_ES])), 0, 0);
315   i80286_data_descriptor_full(cpustate, DS, ntss[TSS_DS], RPL(ntss[TSS_CS]), TRAP(INVALID_TSS,IDXTBL(ntss[TSS_DS])), 0, 0);
312316}
313317
314318static void i80286_code_descriptor(i80286_state *cpustate, UINT16 selector, UINT16 offset, int gate)
r11963r11964
360364            if (!CODE(r) || !SEGDESC(r)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel));
361365            if (DPL(r)>CPL) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel));
362366            if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(gatesel));
363            if (GATEOFF(desc) > LIMIT(gatedesc)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel));
367            if (GATEOFF(desc) > LIMIT(gatedesc)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
364368
365369            if (!CONF(r)&&(DPL(r)<CPL)) {  // inner call
366370               UINT16 tss_ss, tss_sp, oldss, oldsp;
r11963r11964
373377               oldss = cpustate->sregs[SS];
374378               oldsp = cpustate->regs.w[SP];
375379               oldstk = cpustate->base[SS] + oldsp;
376               i80286_data_descriptor_full(cpustate, SS, tss_ss, DPL(r), TRAP(INVALID_TSS,IDXTBL(tss_ss)));
380               i80286_data_descriptor_full(cpustate, SS, tss_ss, DPL(r), TRAP(INVALID_TSS,IDXTBL(tss_ss)), tss_sp-8-(GATECNT(desc)*2), 8+(GATECNT(desc)*2));
377381               cpustate->regs.w[SP] = tss_sp;
378382               PUSH(oldss);
379383               PUSH(oldsp);
380384               for (i = GATECNT(desc)-1; i >= 0; i--)
381385                  PUSH(ReadWord(oldstk+(i*2)));
382            }
386            } else i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]-4, 4, I80286_READ);
383387            SET_ACC(gatedesc);
384388            WriteWord(addr+4, gatedesc[2]);
385389            cpustate->sregs[CS]=IDXTBL(gatesel) | DPL(r);
r11963r11964
448452      if (!CODE(r) || !SEGDESC(r)) throw TRAP(GENERAL_PROTECTION_FAULT,(IDXTBL(gatesel)+(hwint&&1)));
449453      if (DPL(r)>CPL) throw TRAP(GENERAL_PROTECTION_FAULT,(IDXTBL(gatesel)+(hwint&&1)));
450454      if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(IDXTBL(gatesel)+(hwint&&1)));
451      if (GATEOFF(desc) > LIMIT(gatedesc)) throw TRAP(GENERAL_PROTECTION_FAULT,(IDXTBL(gatesel)+(hwint&&1)));
455      if (GATEOFF(desc) > LIMIT(gatedesc)) throw TRAP(GENERAL_PROTECTION_FAULT,(hwint&&1));
452456
453457      if (!CONF(r)&&(DPL(r)<CPL)) {  // inner call
454458         UINT16 tss_ss, tss_sp, oldss, oldsp;
r11963r11964
457461
458462         oldss = cpustate->sregs[SS];
459463         oldsp = cpustate->regs.w[SP];
460         i80286_data_descriptor_full(cpustate, SS, tss_ss, DPL(r), TRAP(INVALID_TSS,(IDXTBL(tss_ss)+(hwint&&1))));
464         i80286_data_descriptor_full(cpustate, SS, tss_ss, DPL(r), TRAP(INVALID_TSS,(IDXTBL(tss_ss)+(hwint&&1))), tss_sp-((error != -1)?12:10), (error != -1)?12:10);
461465         cpustate->regs.w[SP] = tss_sp;
462466         PUSH(oldss);
463467         PUSH(oldsp);
464      }
468      } else i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]-((error != -1)?8:6), (error != -1)?8:6, I80286_READ);
465469      SET_ACC(gatedesc);
466470      WriteWord(addr+4, gatedesc[2]);
467471      PREFIX(_pushf(cpustate));
r11963r11964
776780      if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(sel));
777781      if (off > LIMIT(desc)) throw TRAP(GENERAL_PROTECTION_FAULT, IDXTBL(sel));
778782      if (CPL<RPL(sel)) {
783         i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]+(iret?6:4)+bytes, 4, I80286_READ);
779784         newsp = ReadWord(spaddr+((iret?6:4)+bytes));
780785         newss = ReadWord(spaddr+((iret?8:6)+bytes));
781         i80286_data_descriptor_full(cpustate, SS, newss, RPL(sel), TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(newss)));
786         i80286_data_descriptor_full(cpustate, SS, newss, RPL(sel), TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(newss)), 0, 0);
782787         cpustate->regs.w[SP] = newsp + bytes;
783788      } else cpustate->regs.w[SP] += (iret?6:4) + bytes;
784789      SET_ACC(desc);
r11963r11964
855860      rights = cpustate->rights[check_seg];
856861      trap = i80286_verify(cpustate, cpustate->sregs[check_seg], operation, rights);
857862      if ((CODE(rights) || !EXPDOWN(rights)) && ((offset+size-1) > cpustate->limit[check_seg])) trap = GENERAL_PROTECTION_FAULT;
858      if (!CODE(rights) && EXPDOWN(rights) && (offset <= cpustate->limit[check_seg]) && ((offset+size) > 0xffff)) trap = GENERAL_PROTECTION_FAULT;
863      if (!CODE(rights) && EXPDOWN(rights) && ((offset <= cpustate->limit[check_seg]) || ((offset+size) > 0xffff))) trap = GENERAL_PROTECTION_FAULT;
859864
860865      if ((trap == GENERAL_PROTECTION_FAULT) && (check_seg == SS)) trap = STACK_FAULT;
861866      if (trap) throw TRAP(trap, 0);
src/emu/cpu/i86/instr286.h
r11963r11964
1313#define STACK_FAULT 12
1414#define GENERAL_PROTECTION_FAULT 13
1515
16#define CPL (cpustate->sregs[CS]&3)
1617#define PM (cpustate->msw&1)
17#define CPL (cpustate->sregs[CS]&3)
1818
1919static void i80286_trap2(i80286_state *cpustate,UINT32 error);
2020static void i80286_interrupt_descriptor(i80286_state *cpustate,UINT16 number, int trap, int error);
r11963r11964
4040};
4141
4242static void i80286_check_permission(i8086_state *cpustate, UINT8 check_seg, UINT32 offset, int size, i80286_operation operation);
43
44static inline UINT32 GetMemAddr(i80286_state *cpustate, UINT16 seg, UINT16 off, UINT8 size, i80286_operation op) {
45   seg = DefaultSeg(seg);
46   if(PM) i80286_check_permission(cpustate, seg, off, size, op);
47   return (cpustate->base[seg] + off) & AMASK;
48}
src/emu/cpu/i86/i86priv.h
r11963r11964
6565#define SUBB(dst,src) { unsigned res=dst-src; SetCFB(res); SetOFB_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(BYTE)res; }
6666#define SUBW(dst,src) { unsigned res=dst-src; SetCFW(res); SetOFW_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(WORD)res; }
6767
68// don't modify CF in case fault occurs
69#define ADCB(dst,src,tmpcf) { unsigned res=dst+src; tmpcf = res & 0x100; SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(BYTE)res; }
70#define ADCW(dst,src,tmpcf) { unsigned res=dst+src; tmpcf = res & 0x10000; SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(WORD)res; }
71
72#define SBBB(dst,src,tmpcf) { unsigned res=dst-src; tmpcf = res & 0x100; SetOFB_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(BYTE)res; }
73#define SBBW(dst,src,tmpcf) { unsigned res=dst-src; tmpcf = res & 0x10000; SetOFW_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(WORD)res; }
74
6875#define ORB(dst,src)      dst |= src; cpustate->CarryVal = cpustate->OverVal = cpustate->AuxVal = 0; SetSZPF_Byte(dst)
6976#define ORW(dst,src)      dst |= src; cpustate->CarryVal = cpustate->OverVal = cpustate->AuxVal = 0; SetSZPF_Word(dst)
7077
r11963r11964
101108#define DefaultSeg(Seg)         ((cpustate->seg_prefix && (Seg == DS || Seg == SS)) ? cpustate->prefix_seg : Seg)
102109#define DefaultBase(Seg)      ((cpustate->seg_prefix && (Seg == DS || Seg == SS)) ? cpustate->base[cpustate->prefix_seg] : cpustate->base[Seg])
103110
111#ifdef I80286
112#define GetMemB(Seg,Off)      (read_mem_byte(GetMemAddr(cpustate,Seg,Off,1,I80286_READ)))
113#define GetMemW(Seg,Off)      (read_mem_word(GetMemAddr(cpustate,Seg,Off,2,I80286_READ)))
114#define PutMemB(Seg,Off,x)      write_mem_byte(GetMemAddr(cpustate,Seg,Off,1,I80286_WRITE), (x))
115#define PutMemW(Seg,Off,x)      write_mem_word(GetMemAddr(cpustate,Seg,Off,2,I80286_WRITE), (x))
116#else
104117#define GetMemB(Seg,Off)      (read_mem_byte((DefaultBase(Seg) + (Off)) & AMASK))
105118#define GetMemW(Seg,Off)      (read_mem_word((DefaultBase(Seg) + (Off)) & AMASK))
106119#define PutMemB(Seg,Off,x)      write_mem_byte((DefaultBase(Seg) + (Off)) & AMASK, (x))
107120#define PutMemW(Seg,Off,x)      write_mem_word((DefaultBase(Seg) + (Off)) & AMASK, (x))
121#endif
108122
109123#define PEEKBYTE(ea)         (read_mem_byte((ea) & AMASK))
110124#define ReadByte(ea)         (read_mem_byte((ea) & AMASK))
src/emu/cpu/i86/instr86.c
r11963r11964
138138   }
139139   else
140140   {
141      int tmpcf = CF;
141142      ICOUNT -= (ModRM >= 0xc0) ? timing.rot_reg_base + timing.rot_reg_bit : timing.rot_m8_base + timing.rot_m8_bit;
142143
143144      switch (ModRM & 0x38)
r11963r11964
161162      case 0x10:   /* RCL eb,count */
162163         for (; count > 0; count--)
163164         {
164            dst = (dst << 1) + CF;
165            SetCFB(dst);
165            dst = (dst << 1) + tmpcf;
166            tmpcf = (int)((dst & 0x100) != 0);
166167         }
167168         PutbackRMByte(ModRM,(BYTE)dst);
169         cpustate->CarryVal = tmpcf;
168170         break;
169171      case 0x18:   /* RCR eb,count */
170172         for (; count > 0; count--)
171173         {
172            dst = (CF<<8)+dst;
173            cpustate->CarryVal = dst & 0x01;
174            dst = (tmpcf<<8)+dst;
175            tmpcf = dst & 0x01;
174176            dst >>= 1;
175177         }
176178         PutbackRMByte(ModRM,(BYTE)dst);
179         cpustate->CarryVal = tmpcf;
177180         break;
178181      case 0x20:
179182      case 0x30:   /* SHL eb,count */
r11963r11964
329332   }
330333   else
331334   {
335      int tmpcf = CF;
332336      ICOUNT -= (ModRM >= 0xc0) ? timing.rot_reg_base + timing.rot_reg_bit : timing.rot_m8_base + timing.rot_m16_bit;
333337
334338      switch (ModRM & 0x38)
r11963r11964
352356      case 0x10:  /* RCL ew,count */
353357         for (; count > 0; count--)
354358         {
355            dst = (dst << 1) + CF;
356            SetCFW(dst);
359            dst = (dst << 1) + tmpcf;
360            tmpcf = (int)((dst & 0x10000) != 0);
357361         }
358362         PutbackRMWord(ModRM,dst);
363         cpustate->CarryVal = tmpcf;
359364         break;
360365      case 0x18:   /* RCR ew,count */
361366         for (; count > 0; count--)
362367         {
363            dst = dst + (CF << 16);
364            cpustate->CarryVal = dst & 0x01;
368            dst = dst + (tmpcf << 16);
369            tmpcf = dst & 0x01;
365370            dst >>= 1;
366371         }
367372         PutbackRMWord(ModRM,dst);
373         cpustate->CarryVal = tmpcf;
368374         break;
369375      case 0x20:
370376      case 0x30:   /* SHL ew,count */
r11963r11964
401407         loop  to continue for CMPS and SCAS instructions. */
402408
403409   unsigned next = FETCHOP;
404   unsigned count = cpustate->regs.w[CX];
405410
406411    switch(next)
407412    {
r11963r11964
441446      if (!cpustate->rep_in_progress)
442447         ICOUNT -= timing.rep_ins8_base;
443448      cpustate->rep_in_progress = FALSE;
444      for (; count > 0; count--)
449      while(cpustate->regs.w[CX])
445450      {
446451         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
447452         PutMemB(ES,cpustate->regs.w[DI],read_port_byte(cpustate->regs.w[DX]));
453         cpustate->regs.w[CX]--;
448454         cpustate->regs.w[DI] += cpustate->DirVal;
449455         ICOUNT -= timing.rep_ins8_count;
450456      }
451      cpustate->regs.w[CX]=count;
452457      break;
453458   case 0x6d:  /* REP INSW */
454459#ifdef I80286
r11963r11964
457462      if (!cpustate->rep_in_progress)
458463         ICOUNT -= timing.rep_ins16_base;
459464      cpustate->rep_in_progress = FALSE;
460      for (; count > 0; count--)
465      while(cpustate->regs.w[CX])
461466      {
462467         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
463468         PutMemW(ES,cpustate->regs.w[DI],read_port_word(cpustate->regs.w[DX]));
469         cpustate->regs.w[CX]--;
464470         cpustate->regs.w[DI] += 2 * cpustate->DirVal;
465471         ICOUNT -= timing.rep_ins16_count;
466472      }
467      cpustate->regs.w[CX]=count;
468473      break;
469474   case 0x6e:  /* REP OUTSB */
470475#ifdef I80286
r11963r11964
473478      if (!cpustate->rep_in_progress)
474479         ICOUNT -= timing.rep_outs8_base;
475480      cpustate->rep_in_progress = FALSE;
476      for (; count > 0; count--)
481      while(cpustate->regs.w[CX])
477482      {
478483         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
479484         write_port_byte(cpustate->regs.w[DX],GetMemB(DS,cpustate->regs.w[SI]));
485         cpustate->regs.w[CX]--;
480486         cpustate->regs.w[SI] += cpustate->DirVal; /* GOL 11/27/01 */
481487         ICOUNT -= timing.rep_outs8_count;
482488      }
483      cpustate->regs.w[CX]=count;
484489      break;
485490   case 0x6f:  /* REP OUTSW */
486491#ifdef I80286
r11963r11964
489494      if (!cpustate->rep_in_progress)
490495         ICOUNT -= timing.rep_outs16_base;
491496      cpustate->rep_in_progress = FALSE;
492      for (; count > 0; count--)
497      while(cpustate->regs.w[CX])
493498      {
494499         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
495500         write_port_word(cpustate->regs.w[DX],GetMemW(DS,cpustate->regs.w[SI]));
501         cpustate->regs.w[CX]--;
496502         cpustate->regs.w[SI] += 2 * cpustate->DirVal; /* GOL 11/27/01 */
497503         ICOUNT -= timing.rep_outs16_count;
498504      }
499      cpustate->regs.w[CX]=count;
500505      break;
501506#endif
502507   case 0xa4:  /* REP MOVSB */
503508      if (!cpustate->rep_in_progress)
504509         ICOUNT -= timing.rep_movs8_base;
505510      cpustate->rep_in_progress = FALSE;
506      for (; count > 0; count--)
511      while(cpustate->regs.w[CX])
507512      {
508513         BYTE tmp;
509514
510515         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
511516         tmp = GetMemB(DS,cpustate->regs.w[SI]);
512517         PutMemB(ES,cpustate->regs.w[DI], tmp);
518         cpustate->regs.w[CX]--;
513519         cpustate->regs.w[DI] += cpustate->DirVal;
514520         cpustate->regs.w[SI] += cpustate->DirVal;
515521         ICOUNT -= timing.rep_movs8_count;
516522      }
517      cpustate->regs.w[CX]=count;
518523      break;
519524   case 0xa5:  /* REP MOVSW */
520525      if (!cpustate->rep_in_progress)
521526         ICOUNT -= timing.rep_movs16_base;
522527      cpustate->rep_in_progress = FALSE;
523      for (; count > 0; count--)
528      while(cpustate->regs.w[CX])
524529      {
525530         WORD tmp;
526531
527532         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
528533         tmp = GetMemW(DS,cpustate->regs.w[SI]);
529534         PutMemW(ES,cpustate->regs.w[DI], tmp);
535         cpustate->regs.w[CX]--;
530536         cpustate->regs.w[DI] += 2 * cpustate->DirVal;
531537         cpustate->regs.w[SI] += 2 * cpustate->DirVal;
532538         ICOUNT -= timing.rep_movs16_count;
533539      }
534      cpustate->regs.w[CX]=count;
535540      break;
536541   case 0xa6:  /* REP(N)E CMPSB */
537542      if (!cpustate->rep_in_progress)
538543         ICOUNT -= timing.rep_cmps8_base;
539544      cpustate->rep_in_progress = FALSE;
540      for (cpustate->ZeroVal = !flagval; (ZF == flagval) && (count > 0); count--)
545      cpustate->ZeroVal = !flagval;
546      while(cpustate->regs.w[CX] && (ZF == flagval))
541547      {
542548         unsigned dst, src;
543549
r11963r11964
545551         dst = GetMemB(ES, cpustate->regs.w[DI]);
546552         src = GetMemB(DS, cpustate->regs.w[SI]);
547553          SUBB(src,dst); /* opposite of the usual convention */
554         cpustate->regs.w[CX]--;
548555         cpustate->regs.w[DI] += cpustate->DirVal;
549556         cpustate->regs.w[SI] += cpustate->DirVal;
550557         ICOUNT -= timing.rep_cmps8_count;
551558      }
552      cpustate->regs.w[CX]=count;
553559      break;
554560   case 0xa7:  /* REP(N)E CMPSW */
555561      if (!cpustate->rep_in_progress)
556562         ICOUNT -= timing.rep_cmps16_base;
557563      cpustate->rep_in_progress = FALSE;
558      for (cpustate->ZeroVal = !flagval; (ZF == flagval) && (count > 0); count--)
564      cpustate->ZeroVal = !flagval;
565      while(cpustate->regs.w[CX] && (ZF == flagval))
559566      {
560567         unsigned dst, src;
561568
r11963r11964
563570         dst = GetMemW(ES, cpustate->regs.w[DI]);
564571         src = GetMemW(DS, cpustate->regs.w[SI]);
565572          SUBW(src,dst); /* opposite of the usual convention */
573         cpustate->regs.w[CX]--;
566574         cpustate->regs.w[DI] += 2 * cpustate->DirVal;
567575         cpustate->regs.w[SI] += 2 * cpustate->DirVal;
568576         ICOUNT -= timing.rep_cmps16_count;
569577      }
570      cpustate->regs.w[CX]=count;
571578      break;
572579   case 0xaa:  /* REP STOSB */
573580      if (!cpustate->rep_in_progress)
574581         ICOUNT -= timing.rep_stos8_base;
575582      cpustate->rep_in_progress = FALSE;
576      for (; count > 0; count--)
583      while(cpustate->regs.w[CX])
577584      {
578585         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
579586         PutMemB(ES,cpustate->regs.w[DI],cpustate->regs.b[AL]);
587         cpustate->regs.w[CX]--;
580588         cpustate->regs.w[DI] += cpustate->DirVal;
581589         ICOUNT -= timing.rep_stos8_count;
582590      }
583      cpustate->regs.w[CX]=count;
584591      break;
585592   case 0xab:  /* REP STOSW */
586593      if (!cpustate->rep_in_progress)
587594         ICOUNT -= timing.rep_stos16_base;
588595      cpustate->rep_in_progress = FALSE;
589      for (; count > 0; count--)
596      while(cpustate->regs.w[CX])
590597      {
591598         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
592599         PutMemW(ES,cpustate->regs.w[DI],cpustate->regs.w[AX]);
600         cpustate->regs.w[CX]--;
593601         cpustate->regs.w[DI] += 2 * cpustate->DirVal;
594602         ICOUNT -= timing.rep_stos16_count;
595603      }
596      cpustate->regs.w[CX]=count;
597604      break;
598605   case 0xac:  /* REP LODSB */
599606      if (!cpustate->rep_in_progress)
600607         ICOUNT -= timing.rep_lods8_base;
601608      cpustate->rep_in_progress = FALSE;
602      for (; count > 0; count--)
609      while(cpustate->regs.w[CX])
603610      {
604611         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
605612         cpustate->regs.b[AL] = GetMemB(DS,cpustate->regs.w[SI]);
613         cpustate->regs.w[CX]--;
606614         cpustate->regs.w[SI] += cpustate->DirVal;
607615         ICOUNT -= timing.rep_lods8_count;
608616      }
609      cpustate->regs.w[CX]=count;
610617      break;
611618   case 0xad:  /* REP LODSW */
612619      if (!cpustate->rep_in_progress)
613620         ICOUNT -= timing.rep_lods16_base;
614621      cpustate->rep_in_progress = FALSE;
615      for (; count > 0; count--)
622      while(cpustate->regs.w[CX])
616623      {
617624         if (ICOUNT <= 0) { cpustate->pc = cpustate->prevpc; cpustate->rep_in_progress = TRUE; break; }
618625         cpustate->regs.w[AX] = GetMemW(DS,cpustate->regs.w[SI]);
626         cpustate->regs.w[CX]--;
619627         cpustate->regs.w[SI] += 2 * cpustate->DirVal;
620628         ICOUNT -= timing.rep_lods16_count;
621629      }
622      cpustate->regs.w[CX]=count;
623630      break;
624631   case 0xae:  /* REP(N)E SCASB */
625632      if (!cpustate->rep_in_progress)
626633         ICOUNT -= timing.rep_scas8_base;
627634      cpustate->rep_in_progress = FALSE;
628      for (cpustate->ZeroVal = !flagval; (ZF == flagval) && (count > 0); count--)
635      cpustate->ZeroVal = !flagval;
636      while(cpustate->regs.w[CX] && (ZF == flagval))
629637      {
630638         unsigned src, dst;
631639
r11963r11964
633641         src = GetMemB(ES, cpustate->regs.w[DI]);
634642         dst = cpustate->regs.b[AL];
635643          SUBB(dst,src);
644         cpustate->regs.w[CX]--;
636645         cpustate->regs.w[DI] += cpustate->DirVal;
637646         ICOUNT -= timing.rep_scas8_count;
638647      }
639      cpustate->regs.w[CX]=count;
640648      break;
641649   case 0xaf:  /* REP(N)E SCASW */
642650      if (!cpustate->rep_in_progress)
643651         ICOUNT -= timing.rep_scas16_base;
644652      cpustate->rep_in_progress = FALSE;
645      for (cpustate->ZeroVal = !flagval; (ZF == flagval) && (count > 0); count--)
653      cpustate->ZeroVal = !flagval;
654      while(cpustate->regs.w[CX] && (ZF == flagval))
646655      {
647656         unsigned src, dst;
648657
r11963r11964
650659         src = GetMemW(ES, cpustate->regs.w[DI]);
651660         dst = cpustate->regs.w[AX];
652661          SUBW(dst,src);
662         cpustate->regs.w[CX]--;
653663         cpustate->regs.w[DI] += 2 * cpustate->DirVal;
654664         ICOUNT -= timing.rep_scas16_count;
655665      }
656      cpustate->regs.w[CX]=count;
657666      break;
658667   default:
659668      PREFIX(_instruction)[next](cpustate);
r11963r11964
798807
799808static void PREFIX86(_adc_br8)(i8086_state *cpustate)    /* Opcode 0x10 */
800809{
801    DEF_br8(dst,src);
810    int tmpcf;
811   DEF_br8(dst,src);
802812   ICOUNT -= (ModRM >= 0xc0) ? timing.alu_rr8 : timing.alu_mr8;
803813    src+=CF;
804    ADDB(dst,src);
814    ADCB(dst,src,tmpcf);
805815    PutbackRMByte(ModRM,dst);
816   cpustate->CarryVal = tmpcf;
806817}
807818
808819static void PREFIX86(_adc_wr16)(i8086_state *cpustate)    /* Opcode 0x11 */
809820{
810    DEF_wr16(dst,src);
821    int tmpcf;
822   DEF_wr16(dst,src);
811823   ICOUNT -= (ModRM >= 0xc0) ? timing.alu_rr16 : timing.alu_mr16;
812824    src+=CF;
813    ADDW(dst,src);
825    ADCW(dst,src,tmpcf);
814826   PutbackRMWord(ModRM,dst);
827   cpustate->CarryVal = tmpcf;
815828}
816829
817830static void PREFIX86(_adc_r8b)(i8086_state *cpustate)    /* Opcode 0x12 */
r11963r11964
858871
859872static void PREFIX86(_sbb_br8)(i8086_state *cpustate)    /* Opcode 0x18 */
860873{
861    DEF_br8(dst,src);
874    int tmpcf;
875   DEF_br8(dst,src);
862876   ICOUNT -= (ModRM >= 0xc0) ? timing.alu_rr8 : timing.alu_mr8;
863877    src+=CF;
864    SUBB(dst,src);
878    SBBB(dst,src,tmpcf);
865879    PutbackRMByte(ModRM,dst);
880   cpustate->CarryVal = tmpcf;
866881}
867882
868883static void PREFIX86(_sbb_wr16)(i8086_state *cpustate)    /* Opcode 0x19 */
869884{
885    int tmpcf;
870886    DEF_wr16(dst,src);
871887   ICOUNT -= (ModRM >= 0xc0) ? timing.alu_rr16 : timing.alu_mr16;
872888    src+=CF;
873   SUBW(dst,src);
889   SBBW(dst,src,tmpcf);
874890   PutbackRMWord(ModRM,dst);
891   cpustate->CarryVal = tmpcf;
875892}
876893
877894static void PREFIX86(_sbb_r8b)(i8086_state *cpustate)    /* Opcode 0x1a */
r11963r11964
15811598   unsigned ModRM = FETCHOP;
15821599   unsigned dst = GetRMByte(ModRM);
15831600    unsigned src = FETCH;
1601   int tmpcf;
15841602
15851603    switch (ModRM & 0x38)
15861604   {
r11963r11964
15961614      break;
15971615    case 0x10:  /* ADC eb,d8 */
15981616        src+=CF;
1599        ADDB(dst,src);
1617        ADCB(dst,src,tmpcf);
16001618      PutbackRMByte(ModRM,dst);
1619      cpustate->CarryVal = tmpcf;
16011620        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_ri8 : timing.alu_mi8;
16021621      break;
16031622    case 0x18:  /* SBB eb,b8 */
16041623      src+=CF;
1605      SUBB(dst,src);
1624      SBBB(dst,src,tmpcf);
16061625        PutbackRMByte(ModRM,dst);
1626      cpustate->CarryVal = tmpcf;
16071627        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_ri8 : timing.alu_mi8;
16081628      break;
16091629    case 0x20:  /* AND eb,d8 */
r11963r11964
16341654   unsigned ModRM = FETCH;
16351655   unsigned dst = GetRMWord(ModRM);
16361656    unsigned src = FETCH;
1657   int tmpcf;
16371658    src+= (FETCH << 8);
16381659
16391660   switch (ModRM & 0x38)
r11963r11964
16501671      break;
16511672   case 0x10:   /* ADC ew,d16 */
16521673      src+=CF;
1653      ADDW(dst,src);
1674      ADCW(dst,src,tmpcf);
16541675        PutbackRMWord(ModRM,dst);
1676      cpustate->CarryVal = tmpcf;
16551677        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_ri16 : timing.alu_mi16;
16561678      break;
16571679    case 0x18:  /* SBB ew,d16 */
16581680        src+=CF;
1659      SUBW(dst,src);
1681      SBBW(dst,src,tmpcf);
16601682        PutbackRMWord(ModRM,dst);
1683      cpustate->CarryVal = tmpcf;
16611684        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_ri16 : timing.alu_mi16;
16621685      break;
16631686    case 0x20:  /* AND ew,d16 */
r11963r11964
16871710   unsigned ModRM = FETCH;
16881711   unsigned dst = GetRMByte(ModRM);
16891712   unsigned src = FETCH;
1713   int tmpcf;
16901714
16911715   switch (ModRM & 0x38)
16921716   {
r11963r11964
17021726      break;
17031727   case 0x10:   /* ADC eb,d8 */
17041728      src+=CF;
1705      ADDB(dst,src);
1729      ADCB(dst,src,tmpcf);
17061730      PutbackRMByte(ModRM,dst);
1731      cpustate->CarryVal = tmpcf;
17071732        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_ri8 : timing.alu_mi8;
17081733      break;
17091734   case 0x18:   /* SBB eb,d8 */
17101735        src+=CF;
1711      SUBB(dst,src);
1736      SBBB(dst,src,tmpcf);
17121737      PutbackRMByte(ModRM,dst);
1738      cpustate->CarryVal = tmpcf;
17131739        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_ri8 : timing.alu_mi8;
17141740      break;
17151741   case 0x20:   /* AND eb,d8 */
r11963r11964
17391765   unsigned ModRM = FETCH;
17401766    unsigned dst = GetRMWord(ModRM);
17411767    unsigned src = (WORD)((INT16)((INT8)FETCH));
1768   int tmpcf;
17421769
17431770   switch (ModRM & 0x38)
17441771    {
r11963r11964
17541781      break;
17551782    case 0x10:  /* ADC ew,d16 */
17561783        src+=CF;
1757      ADDW(dst,src);
1784      ADCW(dst,src,tmpcf);
17581785        PutbackRMWord(ModRM,dst);
1786      cpustate->CarryVal = tmpcf;
17591787        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_r16i8 : timing.alu_m16i8;
17601788      break;
17611789   case 0x18:   /* SBB ew,d16 */
17621790      src+=CF;
1763        SUBW(dst,src);
1791        SBBW(dst,src,tmpcf);
17641792        PutbackRMWord(ModRM,dst);
1793      cpustate->CarryVal = tmpcf;
17651794        ICOUNT -= (ModRM >= 0xc0) ? timing.alu_r16i8 : timing.alu_m16i8;
17661795      break;
17671796   case 0x20:   /* AND ew,d16 */
r11963r11964
18041833{
18051834    DEF_br8(dst,src);
18061835   ICOUNT -= (ModRM >= 0xc0) ? timing.xchg_rr8 : timing.xchg_rm8;
1836    PutbackRMByte(ModRM,src);
18071837    RegByte(ModRM)=dst;
1808    PutbackRMByte(ModRM,src);
18091838}
18101839
18111840static void PREFIX86(_xchg_wr16)(i8086_state *cpustate)    /* Opcode 0x87 */
18121841{
18131842    DEF_wr16(dst,src);
18141843   ICOUNT -= (ModRM >= 0xc0) ? timing.xchg_rr16 : timing.xchg_rm16;
1844    PutbackRMWord(ModRM,src);
18151845    RegWord(ModRM)=dst;
1816    PutbackRMWord(ModRM,src);
18171846}
18181847
18191848static void PREFIX86(_mov_br8)(i8086_state *cpustate)    /* Opcode 0x88 */
r11963r11964
27542783      PREFIX(_instruction)[FETCHOP](cpustate);
27552784      break;
27562785    case 0x08:  /* mov cs,ew */
2786      PREFIX(_invalid)(cpustate);
27572787      break;  /* doesn't do a jump far */
27582788    }
27592789#else
src/mess/machine/pc_fdc.c
r11963r11964
5858static WRITE_LINE_DEVICE_HANDLER(  pc_fdc_hw_interrupt );
5959static WRITE_LINE_DEVICE_HANDLER( pc_fdc_hw_dma_drq );
6060static UPD765_GET_IMAGE ( pc_fdc_get_image );
61static UPD765_GET_IMAGE ( pcjr_fdc_get_image );
6162
6263const upd765_interface pc_fdc_upd765_connected_interface =
6364{
r11963r11964
8788   {FLOPPY_0, FLOPPY_1, NULL, NULL}
8889};
8990
91const upd765_interface pcjr_fdc_upd765_interface =
92{
93   DEVCB_LINE(pc_fdc_hw_interrupt),
94   DEVCB_NULL,
95   pcjr_fdc_get_image,
96   UPD765_RDY_PIN_NOT_CONNECTED,
97   {FLOPPY_0, NULL, NULL, NULL}
98};
99
100
90101static device_t* pc_get_device(running_machine &machine)
91102{
92103   return (*fdc->fdc_interface.get_device)(machine);
r11963r11964
140151   return image;
141152}
142153
154static UPD765_GET_IMAGE ( pcjr_fdc_get_image )
155{
156   device_t *image = NULL;
143157
158   if (!fdc->fdc_interface.get_image)
159   {
160      image = floppy_get_device(device->machine(), 0);
161   }
162   else
163   {
164      image = fdc->fdc_interface.get_image(device->machine(), 0);
165   }
166   return image;
167}
144168
145169void pc_fdc_set_tc_state(running_machine &machine, int state)
146170{
r11963r11964
546570      case 2:
547571         pcjr_fdc_dor_w( space->machine(), data );
548572         break;
573      case 4:
574      case 7:
575         break;
549576      default:
550577         pc_fdc_w( space, offset, data );
551578         break;
src/mess/machine/pc_fdc.h
r11963r11964
3535extern const upd765_interface pc_fdc_upd765_connected_interface;
3636extern const upd765_interface pc_fdc_upd765_not_connected_interface;
3737extern const upd765_interface pc_fdc_upd765_connected_1_drive_interface;
38extern const upd765_interface pcjr_fdc_upd765_interface;
3839
3940void pc_fdc_init(running_machine &machine, const struct pc_fdc_interface *iface);
4041void pc_fdc_set_tc_state(running_machine &machine, int state);
src/mess/drivers/pc.c
r11963r11964
17281728   /* cassette */
17291729   MCFG_CASSETTE_ADD( CASSETTE_TAG, ibm5150_cassette_interface )
17301730
1731   MCFG_UPD765A_ADD("upd765", pc_fdc_upd765_not_connected_interface)
1731   MCFG_UPD765A_ADD("upd765", pcjr_fdc_upd765_interface)
17321732
1733   MCFG_FLOPPY_2_DRIVES_ADD(ibmpc_floppy_config)
1733   MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, ibmpc_floppy_config)
17341734
17351735   /* cartridge */
17361736   MCFG_CARTSLOT_ADD("cart1")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team