Previous 15994 Revisions Next

r15701 Sunday 29th July, 2012 at 19:15:10 UTC by Wilbert Pol
v30mz.c: Getting rid of some typedefs and cleaning up a few things. (nw)
[src/emu/cpu/v30mz]necmodrm.h v30mz.c v30mz.h

src/emu/cpu/v30mz/v30mz.c
r15700r15701
4545
4646#define PC(n)      (((n)->sregs[CS]<<4)+(n)->ip)
4747
48typedef UINT8 BOOLEAN;
49typedef UINT8 BYTE;
50typedef UINT16 WORD;
51typedef UINT32 DWORD;
5248
5349#include "v30mz.h"
5450#include "nec.h"
r15700r15701
6056    UINT8  b[16];   /* or as 8 bit registers */
6157} necbasicregs;
6258
63/* default configuration */
64static const nec_config default_config =
65{
66   NULL       // no internal decryption table
67};
68
6959typedef struct _v30mz_state v30mz_state;
7060struct _v30mz_state
7161{
r15700r15701
9686   UINT32 ea;
9787   UINT16 eo;
9888   UINT16 e16;
99
100   const nec_config *config;
10189};
10290
10391extern int necv_dasm_one(char *buffer, UINT32 eip, const UINT8 *oprom, const nec_config *config);
r15700r15701
173161
174162}
175163
176static void nec_interrupt(v30mz_state *cpustate,unsigned int_num,BOOLEAN md_flag)
164static void nec_interrupt(v30mz_state *cpustate,unsigned int_num)
177165{
178166    UINT32 dest_seg, dest_off;
179167
180168    i_pushf(cpustate);
181169   cpustate->TF = cpustate->IF = 0;
182   if (md_flag) SetMD(0);   /* clear Mode-flag = start 8080 emulation mode */
183170
184171   if (int_num == -1)
185172   {
r15700r15701
194181
195182   PUSH(cpustate->sregs[CS]);
196183   PUSH(cpustate->ip);
197   cpustate->ip = (WORD)dest_off;
198   cpustate->sregs[CS] = (WORD)dest_seg;
184   cpustate->ip = (UINT16)dest_off;
185   cpustate->sregs[CS] = (UINT16)dest_seg;
199186}
200187
201188static void nec_trap(v30mz_state *cpustate)
202189{
203190   nec_instruction[FETCHOP](cpustate);
204   nec_interrupt(cpustate,1,0);
191   nec_interrupt(cpustate,1);
205192}
206193
207194static void external_int(v30mz_state *cpustate)
208195{
209196   if( cpustate->pending_irq & NMI_IRQ )
210197   {
211      nec_interrupt(cpustate,NEC_NMI_INT_VECTOR,0);
198      nec_interrupt(cpustate,NEC_NMI_INT_VECTOR);
212199      cpustate->pending_irq &= ~NMI_IRQ;
213200   }
214201   else if( cpustate->pending_irq )
215202   {
216203      /* the actual vector is retrieved after pushing flags */
217204      /* and clearing the IF */
218      nec_interrupt(cpustate,(UINT32)-1,0);
205      nec_interrupt(cpustate,(UINT32)-1);
219206   }
220207}
221208
r15700r15701
397384   high= GetnextRMWord;
398385   tmp= RegWord(ModRM);
399386   if (tmp<low || tmp>high) {
400      nec_interrupt(cpustate,5,0);
387      nec_interrupt(cpustate,5);
401388      CLK(20);
402389   } else {
403390      CLK(13);
r15700r15701
461448}
462449
463450OP( 0x68, i_push_d16 ) { UINT32 tmp;   FETCHWORD(tmp); PUSH(tmp);   CLK(1);   }
464OP( 0x69, i_imul_d16 ) { UINT32 tmp;   DEF_r16w;   FETCHWORD(tmp); dst = (INT32)((INT16)src)*(INT32)((INT16)tmp); cpustate->CarryVal = cpustate->OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1);     RegWord(ModRM)=(WORD)dst;     if (ModRM >= 0xc0) CLK(3) else CLK(4) }
465OP( 0x6a, i_push_d8  ) { UINT32 tmp = (WORD)((INT16)((INT8)FETCH));    PUSH(tmp);   CLK(1);   }
466OP( 0x6b, i_imul_d8  ) { UINT32 src2; DEF_r16w; src2= (WORD)((INT16)((INT8)FETCH)); dst = (INT32)((INT16)src)*(INT32)((INT16)src2); cpustate->CarryVal = cpustate->OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); RegWord(ModRM)=(WORD)dst; if (ModRM >= 0xc0) CLK(3) else CLK(4) }
451OP( 0x69, i_imul_d16 ) { UINT32 tmp;   DEF_r16w;   FETCHWORD(tmp); dst = (INT32)((INT16)src)*(INT32)((INT16)tmp); cpustate->CarryVal = cpustate->OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1);     RegWord(ModRM)=(UINT16)dst;     if (ModRM >= 0xc0) CLK(3) else CLK(4) }
452OP( 0x6a, i_push_d8  ) { UINT32 tmp = (UINT16)((INT16)((INT8)FETCH));    PUSH(tmp);   CLK(1);   }
453OP( 0x6b, i_imul_d8  ) { UINT32 src2; DEF_r16w; src2= (UINT16)((INT16)((INT8)FETCH)); dst = (INT32)((INT16)src)*(INT32)((INT16)src2); cpustate->CarryVal = cpustate->OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); RegWord(ModRM)=(UINT16)dst; if (ModRM >= 0xc0) CLK(3) else CLK(4) }
467454OP( 0x6c, i_insb     ) { PutMemB(ES,cpustate->regs.w[IY],read_port(cpustate->regs.w[DW])); cpustate->regs.w[IY]+= -2 * cpustate->DF + 1; CLK(6); }
468455OP( 0x6d, i_insw     ) { PutMemB(ES,cpustate->regs.w[IY],read_port(cpustate->regs.w[DW])); PutMemB(ES,(cpustate->regs.w[IY]+1)&0xffff,read_port((cpustate->regs.w[DW]+1)&0xffff)); cpustate->regs.w[IY]+= -4 * cpustate->DF + 2; CLK(6); }
469456OP( 0x6e, i_outsb    ) { write_port(cpustate->regs.w[DW],GetMemB(DS,cpustate->regs.w[IX])); cpustate->regs.w[IX]+= -2 * cpustate->DF + 1; CLK(7); }
r15700r15701
514501    }
515502}
516503
517OP( 0x82, i_82pre   ) { UINT32 dst, src; GetModRM; dst = GetRMByte(ModRM); src = (BYTE)((INT8)FETCH);
504OP( 0x82, i_82pre   ) { UINT32 dst, src; GetModRM; dst = GetRMByte(ModRM); src = (UINT8)((INT8)FETCH);
518505   if (ModRM >=0xc0 ) CLK(1) else if ((ModRM & 0x38)==0x38) CLK(2) else CLK(3)
519506   switch (ModRM & 0x38) {
520507       case 0x00: ADDB;         PutbackRMByte(ModRM,dst);   break;
r15700r15701
528515    }
529516}
530517
531OP( 0x83, i_83pre   ) { UINT32 dst, src; GetModRM; dst = GetRMWord(ModRM); src = (WORD)((INT16)((INT8)FETCH));
518OP( 0x83, i_83pre   ) { UINT32 dst, src; GetModRM; dst = GetRMWord(ModRM); src = (UINT16)((INT16)((INT8)FETCH));
532519   if (ModRM >=0xc0 ) CLK(1) else if ((ModRM & 0x38)==0x38) CLK(2) else CLK(3)
533520    switch (ModRM & 0x38) {
534521       case 0x00: ADDW;         PutbackRMWord(ModRM,dst);   break;
r15700r15701
579566
580567OP( 0x98, i_cbw       ) { cpustate->regs.b[AH] = (cpustate->regs.b[AL] & 0x80) ? 0xff : 0;      CLK(1);   }
581568OP( 0x99, i_cwd       ) { cpustate->regs.w[DW] = (cpustate->regs.b[AH] & 0x80) ? 0xffff : 0;   CLK(1);   }
582OP( 0x9a, i_call_far  ) { UINT32 tmp, tmp2;   FETCHWORD(tmp); FETCHWORD(tmp2); PUSH(cpustate->sregs[CS]); PUSH(cpustate->ip); cpustate->ip = (WORD)tmp; cpustate->sregs[CS] = (WORD)tmp2; CLK(10); }
569OP( 0x9a, i_call_far  ) { UINT32 tmp, tmp2;   FETCHWORD(tmp); FETCHWORD(tmp2); PUSH(cpustate->sregs[CS]); PUSH(cpustate->ip); cpustate->ip = (UINT16)tmp; cpustate->sregs[CS] = (UINT16)tmp2; CLK(10); }
583570OP( 0x9b, i_wait      ) { logerror("%06x: Hardware POLL\n",PC(cpustate)); }
584571OP( 0x9c, i_pushf     ) { PUSH( CompressFlags() ); CLK(2); }
585572OP( 0x9d, i_popf      ) { UINT32 tmp; POP(tmp); ExpandFlags(tmp); CLK(3); if (cpustate->TF) nec_trap(cpustate); }
r15700r15701
628615   c=FETCH;
629616   CLKM(3,5);
630617   if (c) switch (ModRM & 0x38) {
631      case 0x00: do { ROL_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
632      case 0x08: do { ROR_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
633      case 0x10: do { ROLC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
634      case 0x18: do { RORC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
618      case 0x00: do { ROL_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
619      case 0x08: do { ROR_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
620      case 0x10: do { ROLC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
621      case 0x18: do { RORC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
635622      case 0x20: SHL_BYTE(c); break;
636623      case 0x28: SHR_BYTE(c); break;
637624      case 0x30: logerror("%06x: Undefined opcode 0xc0 0x30 (SHLA)\n",PC(cpustate)); break;
r15700r15701
645632   c=FETCH;
646633   CLKM(3,5);
647634    if (c) switch (ModRM & 0x38) {
648      case 0x00: do { ROL_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
649      case 0x08: do { ROR_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
650      case 0x10: do { ROLC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
651      case 0x18: do { RORC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
635      case 0x00: do { ROL_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
636      case 0x08: do { ROR_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
637      case 0x10: do { ROLC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
638      case 0x18: do { RORC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
652639      case 0x20: SHL_WORD(c); break;
653640      case 0x28: SHR_WORD(c); break;
654641      case 0x30: logerror("%06x: Undefined opcode 0xc1 0x30 (SHLA)\n",PC(cpustate)); break;
r15700r15701
658645
659646OP( 0xc2, i_ret_d16  ) { UINT32 count = FETCH; count += FETCH << 8; POP(cpustate->ip); cpustate->regs.w[SP]+=count; CLK(6); }
660647OP( 0xc3, i_ret      ) { POP(cpustate->ip); CLK(6); }
661OP( 0xc4, i_les_dw   ) { GetModRM; WORD tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; cpustate->sregs[ES] = GetnextRMWord; CLK(6); }
662OP( 0xc5, i_lds_dw   ) { GetModRM; WORD tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; cpustate->sregs[DS] = GetnextRMWord; CLK(6); }
648OP( 0xc4, i_les_dw   ) { GetModRM; UINT16 tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; cpustate->sregs[ES] = GetnextRMWord; CLK(6); }
649OP( 0xc5, i_lds_dw   ) { GetModRM; UINT16 tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; cpustate->sregs[DS] = GetnextRMWord; CLK(6); }
663650OP( 0xc6, i_mov_bd8  ) { GetModRM; PutImmRMByte(ModRM); CLK(1); }
664651OP( 0xc7, i_mov_wd16 ) { GetModRM; PutImmRMWord(ModRM); CLK(1); }
665652
r15700r15701
686673}
687674OP( 0xca, i_retf_d16  ) { UINT32 count = FETCH; count += FETCH << 8; POP(cpustate->ip); POP(cpustate->sregs[CS]); cpustate->regs.w[SP]+=count; CLK(9); }
688675OP( 0xcb, i_retf      ) { POP(cpustate->ip); POP(cpustate->sregs[CS]); CLK(8); }
689OP( 0xcc, i_int3      ) { nec_interrupt(cpustate,3,0); CLK(9); }
690OP( 0xcd, i_int       ) { nec_interrupt(cpustate,FETCH,0); CLK(10); }
691OP( 0xce, i_into      ) { if (OF) { nec_interrupt(cpustate,4,0); CLK(13); } else CLK(6); }
676OP( 0xcc, i_int3      ) { nec_interrupt(cpustate,3); CLK(9); }
677OP( 0xcd, i_int       ) { nec_interrupt(cpustate,FETCH); CLK(10); }
678OP( 0xce, i_into      ) { if (OF) { nec_interrupt(cpustate,4); CLK(13); } else CLK(6); }
692679OP( 0xcf, i_iret      ) { POP(cpustate->ip); POP(cpustate->sregs[CS]); i_popf(cpustate); CLK(10); }
693680
694681OP( 0xd0, i_rotshft_b ) {
695682   UINT32 src, dst; GetModRM; src = (UINT32)GetRMByte(ModRM); dst=src;
696683   CLKM(1,3);
697684    switch (ModRM & 0x38) {
698      case 0x00: ROL_BYTE;  PutbackRMByte(ModRM,(BYTE)dst); cpustate->OverVal = (src^dst)&0x80; break;
699      case 0x08: ROR_BYTE;  PutbackRMByte(ModRM,(BYTE)dst); cpustate->OverVal = (src^dst)&0x80; break;
700      case 0x10: ROLC_BYTE; PutbackRMByte(ModRM,(BYTE)dst); cpustate->OverVal = (src^dst)&0x80; break;
701      case 0x18: RORC_BYTE; PutbackRMByte(ModRM,(BYTE)dst); cpustate->OverVal = (src^dst)&0x80; break;
685      case 0x00: ROL_BYTE;  PutbackRMByte(ModRM,(UINT8)dst); cpustate->OverVal = (src^dst)&0x80; break;
686      case 0x08: ROR_BYTE;  PutbackRMByte(ModRM,(UINT8)dst); cpustate->OverVal = (src^dst)&0x80; break;
687      case 0x10: ROLC_BYTE; PutbackRMByte(ModRM,(UINT8)dst); cpustate->OverVal = (src^dst)&0x80; break;
688      case 0x18: RORC_BYTE; PutbackRMByte(ModRM,(UINT8)dst); cpustate->OverVal = (src^dst)&0x80; break;
702689      case 0x20: SHL_BYTE(1); cpustate->OverVal = (src^dst)&0x80; break;
703690      case 0x28: SHR_BYTE(1); cpustate->OverVal = (src^dst)&0x80; break;
704691      case 0x30: logerror("%06x: Undefined opcode 0xd0 0x30 (SHLA)\n",PC(cpustate)); break;
r15700r15701
710697   UINT32 src, dst; GetModRM; src = (UINT32)GetRMWord(ModRM); dst=src;
711698   CLKM(1,3);
712699   switch (ModRM & 0x38) {
713      case 0x00: ROL_WORD;  PutbackRMWord(ModRM,(WORD)dst); cpustate->OverVal = (src^dst)&0x8000; break;
714      case 0x08: ROR_WORD;  PutbackRMWord(ModRM,(WORD)dst); cpustate->OverVal = (src^dst)&0x8000; break;
715      case 0x10: ROLC_WORD; PutbackRMWord(ModRM,(WORD)dst); cpustate->OverVal = (src^dst)&0x8000; break;
716      case 0x18: RORC_WORD; PutbackRMWord(ModRM,(WORD)dst); cpustate->OverVal = (src^dst)&0x8000; break;
700      case 0x00: ROL_WORD;  PutbackRMWord(ModRM,(UINT16)dst); cpustate->OverVal = (src^dst)&0x8000; break;
701      case 0x08: ROR_WORD;  PutbackRMWord(ModRM,(UINT16)dst); cpustate->OverVal = (src^dst)&0x8000; break;
702      case 0x10: ROLC_WORD; PutbackRMWord(ModRM,(UINT16)dst); cpustate->OverVal = (src^dst)&0x8000; break;
703      case 0x18: RORC_WORD; PutbackRMWord(ModRM,(UINT16)dst); cpustate->OverVal = (src^dst)&0x8000; break;
717704      case 0x20: SHL_WORD(1); cpustate->OverVal = (src^dst)&0x8000;  break;
718705      case 0x28: SHR_WORD(1); cpustate->OverVal = (src^dst)&0x8000;  break;
719706      case 0x30: logerror("%06x: Undefined opcode 0xd1 0x30 (SHLA)\n",PC(cpustate)); break;
r15700r15701
726713   c=cpustate->regs.b[CL];
727714   CLKM(3,5);
728715   if (c) switch (ModRM & 0x38) {
729      case 0x00: do { ROL_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
730      case 0x08: do { ROR_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
731      case 0x10: do { ROLC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
732      case 0x18: do { RORC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
716      case 0x00: do { ROL_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
717      case 0x08: do { ROR_BYTE;  c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
718      case 0x10: do { ROLC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
719      case 0x18: do { RORC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(UINT8)dst); break;
733720      case 0x20: SHL_BYTE(c); break;
734721      case 0x28: SHR_BYTE(c); break;
735722      case 0x30: logerror("%06x: Undefined opcode 0xd2 0x30 (SHLA)\n",PC(cpustate)); break;
r15700r15701
742729   c=cpustate->regs.b[CL];
743730   CLKM(3,5);
744731    if (c) switch (ModRM & 0x38) {
745      case 0x00: do { ROL_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
746      case 0x08: do { ROR_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
747      case 0x10: do { ROLC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
748      case 0x18: do { RORC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
732      case 0x00: do { ROL_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
733      case 0x08: do { ROR_WORD;  c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
734      case 0x10: do { ROLC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
735      case 0x18: do { RORC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(UINT16)dst); break;
749736      case 0x20: SHL_WORD(c); break;
750737      case 0x28: SHR_WORD(c); break;
751738      case 0x30: logerror("%06x: Undefined opcode 0xd3 0x30 (SHLA)\n",PC(cpustate)); break;
r15700r15701
759746OP( 0xd7, i_trans  ) { UINT32 dest = (cpustate->regs.w[BW]+cpustate->regs.b[AL])&0xffff; cpustate->regs.b[AL] = GetMemB(DS, dest); CLK(5); }
760747OP( 0xd8, i_fpo    ) { GetModRM; CLK(1);   logerror("%06x: Unimplemented floating point control %04x\n",PC(cpustate),ModRM); }
761748
762OP( 0xe0, i_loopne ) { INT8 disp = (INT8)FETCH; cpustate->regs.w[CW]--; if (!ZF && cpustate->regs.w[CW]) { cpustate->ip = (WORD)(cpustate->ip+disp); CLK(6); } else CLK(3); }
763OP( 0xe1, i_loope  ) { INT8 disp = (INT8)FETCH; cpustate->regs.w[CW]--; if ( ZF && cpustate->regs.w[CW]) { cpustate->ip = (WORD)(cpustate->ip+disp); CLK(6); } else CLK(3); }
764OP( 0xe2, i_loop   ) { INT8 disp = (INT8)FETCH; cpustate->regs.w[CW]--; if (cpustate->regs.w[CW]) { cpustate->ip = (WORD)(cpustate->ip+disp); CLK(5); } else CLK(2); }
765OP( 0xe3, i_jcxz   ) { INT8 disp = (INT8)FETCH; if (cpustate->regs.w[CW] == 0) { cpustate->ip = (WORD)(cpustate->ip+disp); CLK(4); } else CLK(1); }
749OP( 0xe0, i_loopne ) { INT8 disp = (INT8)FETCH; cpustate->regs.w[CW]--; if (!ZF && cpustate->regs.w[CW]) { cpustate->ip = (UINT16)(cpustate->ip+disp); CLK(6); } else CLK(3); }
750OP( 0xe1, i_loope  ) { INT8 disp = (INT8)FETCH; cpustate->regs.w[CW]--; if ( ZF && cpustate->regs.w[CW]) { cpustate->ip = (UINT16)(cpustate->ip+disp); CLK(6); } else CLK(3); }
751OP( 0xe2, i_loop   ) { INT8 disp = (INT8)FETCH; cpustate->regs.w[CW]--; if (cpustate->regs.w[CW]) { cpustate->ip = (UINT16)(cpustate->ip+disp); CLK(5); } else CLK(2); }
752OP( 0xe3, i_jcxz   ) { INT8 disp = (INT8)FETCH; if (cpustate->regs.w[CW] == 0) { cpustate->ip = (UINT16)(cpustate->ip+disp); CLK(4); } else CLK(1); }
766753OP( 0xe4, i_inal   ) { UINT8 port = FETCH; cpustate->regs.b[AL] = read_port(port); CLK(6);   }
767754OP( 0xe5, i_inax   ) { UINT8 port = FETCH; cpustate->regs.b[AL] = read_port(port); cpustate->regs.b[AH] = read_port(port+1); CLK(6); }
768755OP( 0xe6, i_outal  ) { UINT8 port = FETCH; write_port(port, cpustate->regs.b[AL]); CLK(6);   }
769756OP( 0xe7, i_outax  ) { UINT8 port = FETCH; write_port(port, cpustate->regs.b[AL]); write_port(port+1, cpustate->regs.b[AH]); CLK(6);   }
770757
771OP( 0xe8, i_call_d16 ) { UINT32 tmp; FETCHWORD(tmp); PUSH(cpustate->ip); cpustate->ip = (WORD)(cpustate->ip+(INT16)tmp); CLK(5); }
772OP( 0xe9, i_jmp_d16  ) { UINT32 tmp; FETCHWORD(tmp); cpustate->ip = (WORD)(cpustate->ip+(INT16)tmp); CLK(4); }
773OP( 0xea, i_jmp_far  ) { UINT32 tmp,tmp1; FETCHWORD(tmp); FETCHWORD(tmp1); cpustate->sregs[CS] = (WORD)tmp1;   cpustate->ip = (WORD)tmp; CLK(7);  }
758OP( 0xe8, i_call_d16 ) { UINT32 tmp; FETCHWORD(tmp); PUSH(cpustate->ip); cpustate->ip = (UINT16)(cpustate->ip+(INT16)tmp); CLK(5); }
759OP( 0xe9, i_jmp_d16  ) { UINT32 tmp; FETCHWORD(tmp); cpustate->ip = (UINT16)(cpustate->ip+(INT16)tmp); CLK(4); }
760OP( 0xea, i_jmp_far  ) { UINT32 tmp,tmp1; FETCHWORD(tmp); FETCHWORD(tmp1); cpustate->sregs[CS] = (UINT16)tmp1;   cpustate->ip = (UINT16)tmp; CLK(7);  }
774761OP( 0xeb, i_jmp_d8   ) { int tmp = (int)((INT8)FETCH); CLK(4);
775762   if (tmp==-2 && cpustate->no_interrupt==0 && (cpustate->pending_irq==0) && cpustate->icount>0) cpustate->icount%=12; /* cycle skip */
776   cpustate->ip = (WORD)(cpustate->ip+tmp);
763   cpustate->ip = (UINT16)(cpustate->ip+tmp);
777764}
778765OP( 0xec, i_inaldx   ) { cpustate->regs.b[AL] = read_port(cpustate->regs.w[DW]); CLK(6);}
779766OP( 0xed, i_inaxdx   ) { UINT32 port = cpustate->regs.w[DW];   cpustate->regs.b[AL] = read_port(port);   cpustate->regs.b[AH] = read_port(port+1); CLK(6); }
r15700r15701
844831      case 0x08: logerror("%06x: Undefined opcode 0xf6 0x08\n",PC(cpustate)); break;
845832      case 0x10: PutbackRMByte(ModRM,~tmp); CLKM(1,3); break; /* NOT */
846833      case 0x18: cpustate->CarryVal=(tmp!=0); tmp=(~tmp)+1; SetSZPF_Byte(tmp); PutbackRMByte(ModRM,tmp&0xff); CLKM(1,3); break; /* NEG */
847      case 0x20: uresult = cpustate->regs.b[AL]*tmp; cpustate->regs.w[AW]=(WORD)uresult; cpustate->CarryVal=cpustate->OverVal=(cpustate->regs.b[AH]!=0); CLKM(3,4); break; /* MULU */
848      case 0x28: result = (INT16)((INT8)cpustate->regs.b[AL])*(INT16)((INT8)tmp); cpustate->regs.w[AW]=(WORD)result; cpustate->CarryVal=cpustate->OverVal=(cpustate->regs.b[AH]!=0); CLKM(3,4); break; /* MUL */
849      case 0x30: if (tmp) { DIVUB; } else nec_interrupt(cpustate,0,0); CLKM(15,16); break;
850      case 0x38: if (tmp) { DIVB;  } else nec_interrupt(cpustate,0,0); CLKM(17,18); break;
834      case 0x20: uresult = cpustate->regs.b[AL]*tmp; cpustate->regs.w[AW]=(UINT16)uresult; cpustate->CarryVal=cpustate->OverVal=(cpustate->regs.b[AH]!=0); CLKM(3,4); break; /* MULU */
835      case 0x28: result = (INT16)((INT8)cpustate->regs.b[AL])*(INT16)((INT8)tmp); cpustate->regs.w[AW]=(UINT16)result; cpustate->CarryVal=cpustate->OverVal=(cpustate->regs.b[AH]!=0); CLKM(3,4); break; /* MUL */
836      case 0x30: if (tmp) { DIVUB; } else nec_interrupt(cpustate,0); CLKM(15,16); break;
837      case 0x38: if (tmp) { DIVB;  } else nec_interrupt(cpustate,0); CLKM(17,18); break;
851838   }
852839}
853840
r15700r15701
860847      case 0x18: cpustate->CarryVal=(tmp!=0); tmp=(~tmp)+1; SetSZPF_Word(tmp); PutbackRMWord(ModRM,tmp&0xffff); CLKM(1,3); break; /* NEG */
861848      case 0x20: uresult = cpustate->regs.w[AW]*tmp; cpustate->regs.w[AW]=uresult&0xffff; cpustate->regs.w[DW]=((UINT32)uresult)>>16; cpustate->CarryVal=cpustate->OverVal=(cpustate->regs.w[DW]!=0); CLKM(3,4); break; /* MULU */
862849      case 0x28: result = (INT32)((INT16)cpustate->regs.w[AW])*(INT32)((INT16)tmp); cpustate->regs.w[AW]=result&0xffff; cpustate->regs.w[DW]=result>>16; cpustate->CarryVal=cpustate->OverVal=(cpustate->regs.w[DW]!=0); CLKM(3,4); break; /* MUL */
863      case 0x30: if (tmp) { DIVUW; } else nec_interrupt(cpustate,0,0); CLKM(23,24); break;
864      case 0x38: if (tmp) { DIVW;  } else nec_interrupt(cpustate,0,0); CLKM(24,25); break;
850      case 0x30: if (tmp) { DIVUW; } else nec_interrupt(cpustate,0); CLKM(23,24); break;
851      case 0x38: if (tmp) { DIVW;  } else nec_interrupt(cpustate,0); CLKM(24,25); break;
865852   }
866853}
867854
r15700r15701
873860OP( 0xfd, i_std   ) { SetDF(1);         CLK(4);   }
874861OP( 0xfe, i_fepre ) { UINT32 tmp, tmp1; GetModRM; tmp=GetRMByte(ModRM);
875862    switch(ModRM & 0x38) {
876       case 0x00: tmp1 = tmp+1; cpustate->OverVal = (tmp==0x7f); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(BYTE)tmp1); CLKM(1,3); break; /* INC */
877      case 0x08: tmp1 = tmp-1; cpustate->OverVal = (tmp==0x80); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(BYTE)tmp1); CLKM(1,3); break; /* DEC */
863       case 0x00: tmp1 = tmp+1; cpustate->OverVal = (tmp==0x7f); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(UINT8)tmp1); CLKM(1,3); break; /* INC */
864      case 0x08: tmp1 = tmp-1; cpustate->OverVal = (tmp==0x80); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(UINT8)tmp1); CLKM(1,3); break; /* DEC */
878865      default:   logerror("%06x: FE Pre with unimplemented mod\n",PC(cpustate));
879866   }
880867}
881868OP( 0xff, i_ffpre ) { UINT32 tmp, tmp1; GetModRM; tmp=GetRMWord(ModRM);
882869    switch(ModRM & 0x38) {
883       case 0x00: tmp1 = tmp+1; cpustate->OverVal = (tmp==0x7fff); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(WORD)tmp1); CLKM(1,3); break; /* INC */
884      case 0x08: tmp1 = tmp-1; cpustate->OverVal = (tmp==0x8000); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(WORD)tmp1); CLKM(1,3); break; /* DEC */
885      case 0x10: PUSH(cpustate->ip);   cpustate->ip = (WORD)tmp; CLKM(5,6); break; /* CALL */
870       case 0x00: tmp1 = tmp+1; cpustate->OverVal = (tmp==0x7fff); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(UINT16)tmp1); CLKM(1,3); break; /* INC */
871      case 0x08: tmp1 = tmp-1; cpustate->OverVal = (tmp==0x8000); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(UINT16)tmp1); CLKM(1,3); break; /* DEC */
872      case 0x10: PUSH(cpustate->ip);   cpustate->ip = (UINT16)tmp; CLKM(5,6); break; /* CALL */
886873      case 0x18: tmp1 = cpustate->sregs[CS]; cpustate->sregs[CS] = GetnextRMWord; PUSH(tmp1); PUSH(cpustate->ip); cpustate->ip = tmp; CLKM(5,12); break; /* CALL FAR */
887874      case 0x20: cpustate->ip = tmp; CLKM(4,5); break; /* JMP */
888875      case 0x28: cpustate->ip = tmp; cpustate->sregs[CS] = GetnextRMWord; CLK(10); break; /* JMP FAR */
r15700r15701
928915
929916static CPU_DISASSEMBLE( nec )
930917{
931   v30mz_state *cpustate = get_safe_token(device);
932
933   return necv_dasm_one(buffer, pc, oprom, cpustate->config);
918   return necv_dasm_one(buffer, pc, oprom, NULL);
934919}
935920
936921static void nec_init(legacy_cpu_device *device, device_irq_acknowledge_callback irqcallback, int type)
937922{
938923   v30mz_state *cpustate = get_safe_token(device);
939924
940   const nec_config *config = &default_config;
941
942925   device->save_item(NAME(cpustate->regs.w));
943926   device->save_item(NAME(cpustate->sregs));
944927
r15700r15701
958941   device->save_item(NAME(cpustate->CarryVal));
959942   device->save_item(NAME(cpustate->ParityVal));
960943
961   cpustate->config = config;
962944   cpustate->irq_callback = irqcallback;
963945   cpustate->device = device;
964946   cpustate->program = device->space(AS_PROGRAM);
src/emu/cpu/v30mz/v30mz.h
r15700r15701
4545#define SetOFW_Sub(x,y,z)   (cpustate->OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x8000)
4646#define SetOFB_Sub(x,y,z)   (cpustate->OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x80)
4747
48#define ADDB { UINT32 res=dst+src; SetCFB(res); SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(BYTE)res; }
49#define ADDW { UINT32 res=dst+src; SetCFW(res); SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(WORD)res; }
48#define ADDB { UINT32 res=dst+src; SetCFB(res); SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(UINT8)res; }
49#define ADDW { UINT32 res=dst+src; SetCFW(res); SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(UINT16)res; }
5050
51#define SUBB { UINT32 res=dst-src; SetCFB(res); SetOFB_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(BYTE)res; }
52#define SUBW { UINT32 res=dst-src; SetCFW(res); SetOFW_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(WORD)res; }
51#define SUBB { UINT32 res=dst-src; SetCFB(res); SetOFB_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(UINT8)res; }
52#define SUBW { UINT32 res=dst-src; SetCFW(res); SetOFW_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(UINT16)res; }
5353
5454#define ORB dst|=src; cpustate->CarryVal=cpustate->OverVal=cpustate->AuxVal=0; SetSZPF_Byte(dst)
5555#define ORW dst|=src; cpustate->CarryVal=cpustate->OverVal=cpustate->AuxVal=0; SetSZPF_Word(dst)
r15700r15701
6363#define CF      (cpustate->CarryVal!=0)
6464#define SF      (cpustate->SignVal<0)
6565#define ZF      (cpustate->ZeroVal==0)
66#define PF      parity_table[(BYTE)cpustate->ParityVal]
66#define PF      parity_table[(UINT8)cpustate->ParityVal]
6767#define AF      (cpustate->AuxVal!=0)
6868#define OF      (cpustate->OverVal!=0)
6969#define MD      (cpustate->MF!=0)
r15700r15701
7878#define GetMemW(Seg,Off) ((UINT16) cpustate->program->read_byte((DefaultBase(Seg)+(Off))) + (cpustate->program->read_byte((DefaultBase(Seg)+((Off)+1)))<<8) )
7979
8080#define PutMemB(Seg,Off,x) { cpustate->program->write_byte((DefaultBase(Seg)+(Off)),(x)); }
81#define PutMemW(Seg,Off,x) { PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(BYTE)((x)>>8)); }
81#define PutMemW(Seg,Off,x) { PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(UINT8)((x)>>8)); }
8282
8383/* Todo:  Remove these later - plus readword could overflow */
84#define ReadByte(ea) ((BYTE)cpustate->program->read_byte((ea)))
84#define ReadByte(ea) ((UINT8)cpustate->program->read_byte((ea)))
8585#define ReadWord(ea) (cpustate->program->read_byte((ea))+(cpustate->program->read_byte(((ea)+1))<<8))
8686#define WriteByte(ea,val) { cpustate->program->write_byte((ea),val); }
87#define WriteWord(ea,val) { cpustate->program->write_byte((ea),(BYTE)(val)); cpustate->program->write_byte(((ea)+1),(val)>>8); }
87#define WriteWord(ea,val) { cpustate->program->write_byte((ea),(UINT8)(val)); cpustate->program->write_byte(((ea)+1),(val)>>8); }
8888
8989#define read_port(port) cpustate->io->read_byte(port)
9090#define write_port(port,val) cpustate->io->write_byte(port,val)
r15700r15701
9494#define FETCHWORD(var) { var=cpustate->direct->read_raw_byte((((cpustate->sregs[CS]<<4)+cpustate->ip)))+(cpustate->direct->read_raw_byte((((cpustate->sregs[CS]<<4)+cpustate->ip+1)))<<8); cpustate->ip+=2; }
9595#define PUSH(val) { cpustate->regs.w[SP]-=2; WriteWord((((cpustate->sregs[SS]<<4)+cpustate->regs.w[SP])),val); }
9696#define POP(var) { var = ReadWord((((cpustate->sregs[SS]<<4)+cpustate->regs.w[SP]))); cpustate->regs.w[SP]+=2; }
97#define PEEK(addr) ((BYTE)cpustate->direct->read_raw_byte(addr))
98#define PEEKOP(addr) ((BYTE)cpustate->direct->read_decrypted_byte(addr))
97#define PEEK(addr) ((UINT8)cpustate->direct->read_raw_byte(addr))
98#define PEEKOP(addr) ((UINT8)cpustate->direct->read_decrypted_byte(addr))
9999
100100#define GetModRM UINT32 ModRM=cpustate->direct->read_raw_byte((cpustate->sregs[CS]<<4)+cpustate->ip++)
101101
r15700r15701
115115#define CLKM(v30mz,v30mzm) { cpustate->icount-=( ModRM >=0xc0 )?v30mz:v30mzm; }
116116
117117/************************************************************************/
118#define CompressFlags() (WORD)(CF | (PF << 2) | (AF << 4) | (ZF << 6) \
118#define CompressFlags() (UINT16)(CF | (PF << 2) | (AF << 4) | (ZF << 6) \
119119            | (SF << 7) | (cpustate->TF << 8) | (cpustate->IF << 9) \
120120            | (cpustate->DF << 10) | (OF << 11)| (MD << 15))
121121
r15700r15701
153153   int tmp = (int)((INT8)FETCH);         \
154154   if (flag)                        \
155155   {                              \
156      cpustate->ip = (WORD)(cpustate->ip+tmp);         \
156      cpustate->ip = (UINT16)(cpustate->ip+tmp);         \
157157      cpustate->icount-=10;      \
158158      return;                        \
159159   }
r15700r15701
216216      tmp |= (1<<tmp2)
217217
218218#define XchgAWReg(Reg)                  \
219    WORD tmp;                        \
219    UINT16 tmp;                        \
220220   tmp = cpustate->regs.w[Reg];               \
221221   cpustate->regs.w[Reg] = cpustate->regs.w[AW];         \
222222   cpustate->regs.w[AW] = tmp
r15700r15701
229229#define ROLC_WORD dst = (dst << 1) + CF; SetCFW(dst)
230230#define RORC_BYTE dst = (CF<<8)+dst; cpustate->CarryVal = dst & 0x01; dst >>= 1
231231#define RORC_WORD dst = (CF<<16)+dst; cpustate->CarryVal = dst & 0x01; dst >>= 1
232#define SHL_BYTE(c) cpustate->icount-=c; dst <<= c;   SetCFB(dst); SetSZPF_Byte(dst);   PutbackRMByte(ModRM,(BYTE)dst)
233#define SHL_WORD(c) cpustate->icount-=c; dst <<= c;   SetCFW(dst); SetSZPF_Word(dst);   PutbackRMWord(ModRM,(WORD)dst)
234#define SHR_BYTE(c) cpustate->icount-=c; dst >>= c-1; cpustate->CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(BYTE)dst)
235#define SHR_WORD(c) cpustate->icount-=c; dst >>= c-1; cpustate->CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(WORD)dst)
236#define SHRA_BYTE(c) cpustate->icount-=c; dst = ((INT8)dst) >> (c-1);   cpustate->CarryVal = dst & 0x1;   dst = ((INT8)((BYTE)dst)) >> 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(BYTE)dst)
237#define SHRA_WORD(c) cpustate->icount-=c; dst = ((INT16)dst) >> (c-1);   cpustate->CarryVal = dst & 0x1;   dst = ((INT16)((WORD)dst)) >> 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(WORD)dst)
232#define SHL_BYTE(c) cpustate->icount-=c; dst <<= c;   SetCFB(dst); SetSZPF_Byte(dst);   PutbackRMByte(ModRM,(UINT8)dst)
233#define SHL_WORD(c) cpustate->icount-=c; dst <<= c;   SetCFW(dst); SetSZPF_Word(dst);   PutbackRMWord(ModRM,(UINT16)dst)
234#define SHR_BYTE(c) cpustate->icount-=c; dst >>= c-1; cpustate->CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(UINT8)dst)
235#define SHR_WORD(c) cpustate->icount-=c; dst >>= c-1; cpustate->CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(UINT16)dst)
236#define SHRA_BYTE(c) cpustate->icount-=c; dst = ((INT8)dst) >> (c-1);   cpustate->CarryVal = dst & 0x1;   dst = ((INT8)((UINT8)dst)) >> 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(UINT8)dst)
237#define SHRA_WORD(c) cpustate->icount-=c; dst = ((INT16)dst) >> (c-1);   cpustate->CarryVal = dst & 0x1;   dst = ((INT16)((UINT16)dst)) >> 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(UINT16)dst)
238238
239239#define DIVUB                                    \
240240   uresult = cpustate->regs.w[AW];                           \
241241   uresult2 = uresult % tmp;                        \
242242   if ((uresult /= tmp) > 0xff) {                     \
243      nec_interrupt(cpustate,0,0); break;                     \
243      nec_interrupt(cpustate,0); break;                     \
244244   } else {                                    \
245245      cpustate->regs.b[AL] = uresult;                        \
246246      cpustate->regs.b[AH] = uresult2;                     \
r15700r15701
250250   result = (INT16)cpustate->regs.w[AW];                     \
251251   result2 = result % (INT16)((INT8)tmp);               \
252252   if ((result /= (INT16)((INT8)tmp)) > 0xff) {         \
253      nec_interrupt(cpustate,0,0); break;                     \
253      nec_interrupt(cpustate,0); break;                     \
254254   } else {                                    \
255255      cpustate->regs.b[AL] = result;                        \
256256      cpustate->regs.b[AH] = result2;                        \
r15700r15701
260260   uresult = (((UINT32)cpustate->regs.w[DW]) << 16) | cpustate->regs.w[AW];\
261261   uresult2 = uresult % tmp;                        \
262262   if ((uresult /= tmp) > 0xffff) {                  \
263      nec_interrupt(cpustate,0,0); break;                     \
263      nec_interrupt(cpustate,0); break;                     \
264264   } else {                                    \
265265      cpustate->regs.w[AW]=uresult;                        \
266266      cpustate->regs.w[DW]=uresult2;                        \
r15700r15701
270270   result = ((UINT32)cpustate->regs.w[DW] << 16) + cpustate->regs.w[AW];   \
271271   result2 = result % (INT32)((INT16)tmp);               \
272272   if ((result /= (INT32)((INT16)tmp)) > 0xffff) {         \
273      nec_interrupt(cpustate,0,0); break;                     \
273      nec_interrupt(cpustate,0); break;                     \
274274   } else {                                    \
275275      cpustate->regs.w[AW]=result;                        \
276276      cpustate->regs.w[DW]=result2;                        \
src/emu/cpu/v30mz/necmodrm.h
r15700r15701
3535
3636#define PutImmRMWord(ModRM)             \
3737{                     \
38   WORD val;               \
38   UINT16 val;               \
3939   if (ModRM >= 0xc0)            \
4040      FETCHWORD(cpustate->regs.w[Mod_RM.RM.w[ModRM]]) \
4141   else {                  \

Previous 15994 Revisions Next


© 1998-2018 The MESS Team