static CPU_RESET( nec ) { nec_state_t *nec_state = get_safe_token(device); memset( &nec_state->regs.w, 0, sizeof(nec_state->regs.w)); nec_state->ip = 0; nec_state->TF = 0; nec_state->IF = 0; nec_state->DF = 0; nec_state->MF = 1; // brkem should set to 0 when implemented nec_state->SignVal = 0; nec_state->AuxVal = 0; nec_state->OverVal = 0; nec_state->ZeroVal = 1; nec_state->CarryVal = 0; nec_state->ParityVal = 1; nec_state->pending_irq = 0; nec_state->nmi_state = 0; nec_state->irq_state = 0; nec_state->poll_state = 1; nec_state->halted = 0; Sreg(PS) = 0xffff; Sreg(SS) = 0; Sreg(DS0) = 0; Sreg(DS1) = 0; CHANGE_PC; }
static CPU_EXECUTE( necv ) { nec_state_t *nec_state = get_safe_token(device); int prev_ICount; if (nec_state->halted) { nec_state->icount = 0; debugger_instruction_hook(device, (Sreg(PS)<<4) + nec_state->ip); return; } while(nec_state->icount>0) { /* Dispatch IRQ */ if (nec_state->pending_irq && nec_state->no_interrupt==0) { if (nec_state->pending_irq & NMI_IRQ) external_int(nec_state); else if (nec_state->IF) external_int(nec_state); } /* No interrupt allowed between last instruction and this one */ if (nec_state->no_interrupt) nec_state->no_interrupt--; debugger_instruction_hook(device, (Sreg(PS)<<4) + nec_state->ip); prev_ICount = nec_state->icount; nec_instruction[fetchop(nec_state)](nec_state); do_prefetch(nec_state, prev_ICount); } }
void nec_common_device::device_reset() { memset( &m_regs.w, 0, sizeof(m_regs.w)); m_ip = 0; m_TF = 0; m_IF = 0; m_DF = 0; m_MF = 1; // brkem should set to 0 when implemented m_SignVal = 0; m_AuxVal = 0; m_OverVal = 0; m_ZeroVal = 1; m_CarryVal = 0; m_ParityVal = 1; m_pending_irq = 0; m_nmi_state = 0; m_irq_state = 0; m_poll_state = 1; m_halted = 0; Sreg(PS) = 0xffff; Sreg(SS) = 0; Sreg(DS0) = 0; Sreg(DS1) = 0; CHANGE_PC; }
int nec_reset() { nec_state_t *nec_state = sChipsPtr; memset( &nec_state->regs.w, 0, sizeof(nec_state->regs.w)); nec_state->ip = 0; nec_state->TF = 0; nec_state->IF = 0; nec_state->DF = 0; nec_state->MF = 1; // brkem should set to 0 when implemented nec_state->SignVal = 0; nec_state->AuxVal = 0; nec_state->OverVal = 0; nec_state->ZeroVal = 1; nec_state->CarryVal = 0; nec_state->ParityVal = 1; nec_state->pending_irq = 0; nec_state->nmi_state = 0; nec_state->irq_state = 0; nec_state->poll_state = 1; nec_state->halted = 0; nec_state->cycles_total = 0; nec_state->cycles_remaining = 0; nec_state->vector = 0xff; //default vector Sreg(PS) = 0xffff; Sreg(SS) = 0; Sreg(DS0) = 0; Sreg(DS1) = 0; CHANGE_PC; return 0; }
void nec_common_device::execute_run() { int prev_ICount; if (m_halted) { m_icount = 0; debugger_instruction_hook(this, (Sreg(PS)<<4) + m_ip); return; } while(m_icount>0) { /* Dispatch IRQ */ if (m_pending_irq && m_no_interrupt==0) { if (m_pending_irq & NMI_IRQ) external_int(); else if (m_IF) external_int(); } /* No interrupt allowed between last instruction and this one */ if (m_no_interrupt) m_no_interrupt--; debugger_instruction_hook(this, (Sreg(PS)<<4) + m_ip); prev_ICount = m_icount; (this->*s_nec_instruction[fetchop()])(); do_prefetch(prev_ICount); } }
void nec_common_device::state_export(const device_state_entry &entry) { switch (entry.index()) { case STATE_GENPC: case NEC_PC: m_debugger_temp = (Sreg(PS)<<4) + m_ip; break; case STATE_GENSP: m_debugger_temp = (Sreg(SS)<<4) + Wreg(SP); break; case NEC_FLAGS: m_debugger_temp = CompressFlags(); break; } }
static void nec_interrupt(nec_state_t *nec_state, unsigned int_num, INTSOURCES source) { UINT32 dest_seg, dest_off; i_pushf(nec_state); nec_state->TF = nec_state->IF = 0; if (source == INT_IRQ) /* get vector */ int_num = (*nec_state->irq_callback)(nec_state->device, 0); dest_off = read_mem_word(int_num*4); dest_seg = read_mem_word(int_num*4+2); PUSH(Sreg(PS)); PUSH(nec_state->ip); nec_state->ip = (WORD)dest_off; Sreg(PS) = (WORD)dest_seg; CHANGE_PC; }
void nec_common_device::nec_interrupt(unsigned int_num, int/*INTSOURCES*/ source) { UINT32 dest_seg, dest_off; i_pushf(); m_TF = m_IF = 0; if (source == INT_IRQ) /* get vector */ int_num = (standard_irq_callback)(0); dest_off = read_mem_word(int_num*4); dest_seg = read_mem_word(int_num*4+2); PUSH(Sreg(PS)); PUSH(m_ip); m_ip = (WORD)dest_off; Sreg(PS) = (WORD)dest_seg; CHANGE_PC; }
void nec_common_device::state_import(const device_state_entry &entry) { switch (entry.index()) { case NEC_PC: if( m_debugger_temp - (Sreg(PS)<<4) < 0x10000 ) { m_ip = m_debugger_temp - (Sreg(PS)<<4); } else { Sreg(PS) = m_debugger_temp >> 4; m_ip = m_debugger_temp & 0x0000f; } break; case NEC_FLAGS: ExpandFlags(m_debugger_temp); break; } }
static CPU_SET_INFO( nec ) { nec_state_t *nec_state = get_safe_token(device); switch (state) { /* --- the following bits of info are set as 64-bit signed integers --- */ case CPUINFO_INT_INPUT_STATE + 0: set_irq_line(nec_state, 0, info->i); break; case CPUINFO_INT_INPUT_STATE + INPUT_LINE_NMI: set_irq_line(nec_state, INPUT_LINE_NMI, info->i); break; case CPUINFO_INT_INPUT_STATE + NEC_INPUT_LINE_POLL: set_irq_line(nec_state, NEC_INPUT_LINE_POLL, info->i); break; case CPUINFO_INT_PC: case CPUINFO_INT_REGISTER + NEC_PC: if( info->i - (Sreg(PS)<<4) < 0x10000 ) { nec_state->ip = info->i - (Sreg(PS)<<4); } else { Sreg(PS) = info->i >> 4; nec_state->ip = info->i & 0x0000f; } break; case CPUINFO_INT_REGISTER + NEC_IP: nec_state->ip = info->i; break; case CPUINFO_INT_SP: if( info->i - (Sreg(SS)<<4) < 0x10000 ) { Wreg(SP) = info->i - (Sreg(SS)<<4); } else { Sreg(SS) = info->i >> 4; Wreg(SP) = info->i & 0x0000f; } break; case CPUINFO_INT_REGISTER + NEC_SP: Wreg(SP) = info->i; break; case CPUINFO_INT_REGISTER + NEC_FLAGS: ExpandFlags(info->i); break; case CPUINFO_INT_REGISTER + NEC_AW: Wreg(AW) = info->i; break; case CPUINFO_INT_REGISTER + NEC_CW: Wreg(CW) = info->i; break; case CPUINFO_INT_REGISTER + NEC_DW: Wreg(DW) = info->i; break; case CPUINFO_INT_REGISTER + NEC_BW: Wreg(BW) = info->i; break; case CPUINFO_INT_REGISTER + NEC_BP: Wreg(BP) = info->i; break; case CPUINFO_INT_REGISTER + NEC_IX: Wreg(IX) = info->i; break; case CPUINFO_INT_REGISTER + NEC_IY: Wreg(IY) = info->i; break; case CPUINFO_INT_REGISTER + NEC_ES: Sreg(DS1) = info->i; break; case CPUINFO_INT_REGISTER + NEC_CS: Sreg(PS) = info->i; break; case CPUINFO_INT_REGISTER + NEC_SS: Sreg(SS) = info->i; break; case CPUINFO_INT_REGISTER + NEC_DS: Sreg(DS0) = info->i; break; } }
arma::mat BaderGrid::regional_overlap(size_t ireg) { if(ireg>=maxima.size()) { ERROR_INFO(); throw std::runtime_error("Invalid region!\n"); } // Function values in grid points arma::mat bf(basp->get_Nbf(),reggrid[ireg].size()); arma::rowvec w(reggrid[ireg].size()); for(size_t ip=0;ip<reggrid[ireg].size();ip++) { // Weight is w(ip)=reggrid[ireg][ip].w; // Basis function values are bf.col(ip)=basp->eval_func(reggrid[ireg][ip].r.x,reggrid[ireg][ip].r.y,reggrid[ireg][ip].r.z); } // Overlap matrix is arma::mat Sreg(basp->get_Nbf(),basp->get_Nbf()); Sreg.zeros(); increment_lda<double>(Sreg,w,bf); return Sreg; }
static UINT8 fetchop(nec_state_t *nec_state) { prefetch(nec_state); return cpu_readop(((Sreg(PS)<<4)+nec_state->ip++) ^ nec_state->fetch_xor); }
static CPU_GET_INFO( nec ) { nec_state_t *nec_state = (device != NULL && device->token() != NULL) ? get_safe_token(device) : NULL; int flags; switch (state) { /* --- the following bits of info are returned as 64-bit signed integers --- */ case CPUINFO_INT_CONTEXT_SIZE: info->i = sizeof(nec_state_t); break; case CPUINFO_INT_INPUT_LINES: info->i = 1; break; case CPUINFO_INT_DEFAULT_IRQ_VECTOR: info->i = 0xff; break; case CPUINFO_INT_ENDIANNESS: info->i = ENDIANNESS_LITTLE; break; case CPUINFO_INT_CLOCK_MULTIPLIER: info->i = 1; break; case CPUINFO_INT_CLOCK_DIVIDER: info->i = 1; break; case CPUINFO_INT_MIN_INSTRUCTION_BYTES: info->i = 1; break; case CPUINFO_INT_MAX_INSTRUCTION_BYTES: info->i = 8; break; case CPUINFO_INT_MIN_CYCLES: info->i = 1; break; case CPUINFO_INT_MAX_CYCLES: info->i = 80; break; case CPUINFO_INT_DATABUS_WIDTH + AS_PROGRAM: info->i = 16; break; case CPUINFO_INT_ADDRBUS_WIDTH + AS_PROGRAM: info->i = 20; break; case CPUINFO_INT_ADDRBUS_SHIFT + AS_PROGRAM: info->i = 0; break; case CPUINFO_INT_DATABUS_WIDTH + AS_DATA: info->i = 0; break; case CPUINFO_INT_ADDRBUS_WIDTH + AS_DATA: info->i = 0; break; case CPUINFO_INT_ADDRBUS_SHIFT + AS_DATA: info->i = 0; break; case CPUINFO_INT_DATABUS_WIDTH + AS_IO: info->i = 16; break; case CPUINFO_INT_ADDRBUS_WIDTH + AS_IO: info->i = 16; break; case CPUINFO_INT_ADDRBUS_SHIFT + AS_IO: info->i = 0; break; case CPUINFO_INT_INPUT_STATE + 0: info->i = (nec_state->pending_irq & INT_IRQ) ? ASSERT_LINE : CLEAR_LINE; break; case CPUINFO_INT_INPUT_STATE + INPUT_LINE_NMI: info->i = nec_state->nmi_state; break; case CPUINFO_INT_INPUT_STATE + NEC_INPUT_LINE_POLL: info->i = nec_state->poll_state; break; case CPUINFO_INT_PREVIOUSPC: /* not supported */ break; case CPUINFO_INT_PC: case CPUINFO_INT_REGISTER + NEC_PC: info->i = ((Sreg(PS)<<4) + nec_state->ip); break; case CPUINFO_INT_REGISTER + NEC_IP: info->i = nec_state->ip; break; case CPUINFO_INT_SP: info->i = (Sreg(SS)<<4) + Wreg(SP); break; case CPUINFO_INT_REGISTER + NEC_SP: info->i = Wreg(SP); break; case CPUINFO_INT_REGISTER + NEC_FLAGS: info->i = CompressFlags(); break; case CPUINFO_INT_REGISTER + NEC_AW: info->i = Wreg(AW); break; case CPUINFO_INT_REGISTER + NEC_CW: info->i = Wreg(CW); break; case CPUINFO_INT_REGISTER + NEC_DW: info->i = Wreg(DW); break; case CPUINFO_INT_REGISTER + NEC_BW: info->i = Wreg(BW); break; case CPUINFO_INT_REGISTER + NEC_BP: info->i = Wreg(BP); break; case CPUINFO_INT_REGISTER + NEC_IX: info->i = Wreg(IX); break; case CPUINFO_INT_REGISTER + NEC_IY: info->i = Wreg(IY); break; case CPUINFO_INT_REGISTER + NEC_ES: info->i = Sreg(DS1); break; case CPUINFO_INT_REGISTER + NEC_CS: info->i = Sreg(PS); break; case CPUINFO_INT_REGISTER + NEC_SS: info->i = Sreg(SS); break; case CPUINFO_INT_REGISTER + NEC_DS: info->i = Sreg(DS0); break; case CPUINFO_INT_REGISTER + NEC_PENDING: info->i = nec_state->pending_irq; break; /* --- the following bits of info are returned as pointers to data or functions --- */ case CPUINFO_FCT_SET_INFO: info->setinfo = CPU_SET_INFO_NAME(nec); break; case CPUINFO_FCT_INIT: /* set per-CPU */ break; case CPUINFO_FCT_RESET: info->reset = CPU_RESET_NAME(nec); break; case CPUINFO_FCT_EXIT: info->exit = CPU_EXIT_NAME(nec); break; case CPUINFO_FCT_EXECUTE: info->execute = CPU_EXECUTE_NAME(necv); break; case CPUINFO_FCT_BURN: info->burn = NULL; break; case CPUINFO_FCT_DISASSEMBLE: info->disassemble = CPU_DISASSEMBLE_NAME(nec); break; case CPUINFO_PTR_INSTRUCTION_COUNTER: info->icount = &nec_state->icount; break; /* --- the following bits of info are returned as NULL-terminated strings --- */ case CPUINFO_STR_NAME: strcpy(info->s, "NEC"); break; case CPUINFO_STR_FAMILY: strcpy(info->s, "NEC V-Series"); break; case CPUINFO_STR_VERSION: strcpy(info->s, "2.0"); break; case CPUINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; case CPUINFO_STR_CREDITS: strcpy(info->s, "Bryan McPhail (V25/V35 support added by Alex W. Jackson)"); break; case CPUINFO_STR_FLAGS: flags = CompressFlags(); sprintf(info->s, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", flags & 0x8000 ? 'N':'E', flags & 0x4000 ? '?':'.', flags & 0x2000 ? '?':'.', flags & 0x1000 ? '?':'.', flags & 0x0800 ? 'O':'.', flags & 0x0400 ? 'D':'.', flags & 0x0200 ? 'I':'.', flags & 0x0100 ? 'T':'.', flags & 0x0080 ? 'S':'.', flags & 0x0040 ? 'Z':'.', flags & 0x0020 ? '?':'.', flags & 0x0010 ? 'A':'.', flags & 0x0008 ? '?':'.', flags & 0x0004 ? 'P':'.', flags & 0x0002 ? '.':'?', flags & 0x0001 ? 'C':'.'); break; case CPUINFO_STR_REGISTER + NEC_PC: sprintf(info->s, "PC:%05X", (Sreg(PS)<<4) + nec_state->ip); break; case CPUINFO_STR_REGISTER + NEC_IP: sprintf(info->s, "IP:%04X", nec_state->ip); break; case CPUINFO_STR_REGISTER + NEC_SP: sprintf(info->s, "SP:%04X", Wreg(SP)); break; case CPUINFO_STR_REGISTER + NEC_FLAGS: sprintf(info->s, "F:%04X", CompressFlags()); break; case CPUINFO_STR_REGISTER + NEC_AW: sprintf(info->s, "AW:%04X", Wreg(AW)); break; case CPUINFO_STR_REGISTER + NEC_CW: sprintf(info->s, "CW:%04X", Wreg(CW)); break; case CPUINFO_STR_REGISTER + NEC_DW: sprintf(info->s, "DW:%04X", Wreg(DW)); break; case CPUINFO_STR_REGISTER + NEC_BW: sprintf(info->s, "BW:%04X", Wreg(BW)); break; case CPUINFO_STR_REGISTER + NEC_BP: sprintf(info->s, "BP:%04X", Wreg(BP)); break; case CPUINFO_STR_REGISTER + NEC_IX: sprintf(info->s, "IX:%04X", Wreg(IX)); break; case CPUINFO_STR_REGISTER + NEC_IY: sprintf(info->s, "IY:%04X", Wreg(IY)); break; case CPUINFO_STR_REGISTER + NEC_ES: sprintf(info->s, "DS1:%04X", Sreg(DS1)); break; case CPUINFO_STR_REGISTER + NEC_CS: sprintf(info->s, "PS:%04X", Sreg(PS)); break; case CPUINFO_STR_REGISTER + NEC_SS: sprintf(info->s, "SS:%04X", Sreg(SS)); break; case CPUINFO_STR_REGISTER + NEC_DS: sprintf(info->s, "DS0:%04X", Sreg(DS0)); break; } }
UINT8 nec_common_device::fetchop() { prefetch(); return m_direct->read_byte(( Sreg(PS)<<4)+m_ip++, m_fetch_xor); }
void nec_common_device::device_start() { unsigned int i, j, c; static const WREGS wreg_name[8]={ AW, CW, DW, BW, SP, BP, IX, IY }; static const BREGS breg_name[8]={ AL, CL, DL, BL, AH, CH, DH, BH }; for (i = 0; i < 256; i++) { for (j = i, c = 0; j > 0; j >>= 1) if (j & 1) c++; parity_table[i] = !(c & 1); } for (i = 0; i < 256; i++) { Mod_RM.reg.b[i] = breg_name[(i & 0x38) >> 3]; Mod_RM.reg.w[i] = wreg_name[(i & 0x38) >> 3]; } for (i = 0xc0; i < 0x100; i++) { Mod_RM.RM.w[i] = wreg_name[i & 7]; Mod_RM.RM.b[i] = breg_name[i & 7]; } m_no_interrupt = 0; m_prefetch_count = 0; m_prefetch_reset = 0; m_prefix_base = 0; m_seg_prefix = 0; m_EA = 0; m_EO = 0; m_E16 = 0; m_debugger_temp = 0; m_ip = 0; memset(m_regs.w, 0x00, sizeof(m_regs.w)); memset(m_sregs, 0x00, sizeof(m_sregs)); save_item(NAME(m_regs.w)); save_item(NAME(m_sregs)); save_item(NAME(m_ip)); save_item(NAME(m_TF)); save_item(NAME(m_IF)); save_item(NAME(m_DF)); save_item(NAME(m_MF)); save_item(NAME(m_SignVal)); save_item(NAME(m_AuxVal)); save_item(NAME(m_OverVal)); save_item(NAME(m_ZeroVal)); save_item(NAME(m_CarryVal)); save_item(NAME(m_ParityVal)); save_item(NAME(m_pending_irq)); save_item(NAME(m_nmi_state)); save_item(NAME(m_irq_state)); save_item(NAME(m_poll_state)); save_item(NAME(m_no_interrupt)); save_item(NAME(m_halted)); save_item(NAME(m_prefetch_count)); save_item(NAME(m_prefetch_reset)); m_program = &space(AS_PROGRAM); m_direct = &m_program->direct(); m_io = &space(AS_IO); state_add( NEC_PC, "PC", m_debugger_temp).callimport().callexport().formatstr("%05X"); state_add( NEC_IP, "IP", m_ip).formatstr("%04X"); state_add( NEC_SP, "SP", Wreg(SP)).formatstr("%04X"); state_add( NEC_FLAGS, "F", m_debugger_temp).callimport().callexport().formatstr("%04X"); state_add( NEC_AW, "AW", Wreg(AW)).formatstr("%04X"); state_add( NEC_CW, "CW", Wreg(CW)).formatstr("%04X"); state_add( NEC_DW, "DW", Wreg(DW)).formatstr("%04X"); state_add( NEC_BW, "BW", Wreg(BW)).formatstr("%04X"); state_add( NEC_BP, "BP", Wreg(BP)).formatstr("%04X"); state_add( NEC_IX, "IX", Wreg(IX)).formatstr("%04X"); state_add( NEC_IY, "IY", Wreg(IY)).formatstr("%04X"); state_add( NEC_ES, "DS1", Sreg(DS1)).formatstr("%04X"); state_add( NEC_CS, "PS", Sreg(PS)).formatstr("%04X"); state_add( NEC_SS, "SS", Sreg(SS)).formatstr("%04X"); state_add( NEC_DS, "DS0", Sreg(DS0)).formatstr("%04X"); state_add( STATE_GENPC, "GENPC", m_debugger_temp).callexport().noshow(); state_add( STATE_GENPCBASE, "CURPC", m_debugger_temp).callexport().noshow(); state_add( STATE_GENSP, "GENSP", m_debugger_temp).callimport().callexport().noshow(); state_add( STATE_GENFLAGS, "GENFLAGS", m_debugger_temp).formatstr("%16s").noshow(); m_icountptr = &m_icount; }
NEC_INLINE UINT8 fetch(nec_state_t *nec_state) { prefetch(nec_state); return cpu_readop_arg(((Sreg(PS)<<4)+nec_state->ip++) ^ nec_state->fetch_xor); // ^ fetch_xor? }
static UINT8 fetchop(nec_state_t *nec_state) { prefetch(nec_state); return nec_state->direct->read_decrypted_byte(( Sreg(PS)<<4)+nec_state->ip++, nec_state->fetch_xor); }
INLINE UINT8 fetch(nec_state_t *nec_state) { prefetch(nec_state); return nec_state->direct->read_raw_byte((Sreg(PS)<<4)+nec_state->ip++, nec_state->fetch_xor); }