From 2126f6cdf308233f88ffb2db2d85fac3f4e306c5 Mon Sep 17 00:00:00 2001 From: hap Date: Sat, 7 Feb 2015 16:50:19 +0100 Subject: ucom4 disassembler --- src/emu/cpu/amis2000/amis2000d.c | 21 +++--- src/emu/cpu/ucom4/ucom4.c | 12 +++- src/emu/cpu/ucom4/ucom4.h | 1 + src/emu/cpu/ucom4/ucom4d.c | 139 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 155 insertions(+), 18 deletions(-) diff --git a/src/emu/cpu/amis2000/amis2000d.c b/src/emu/cpu/amis2000/amis2000d.c index efb2f74b5f6..971a1a61571 100644 --- a/src/emu/cpu/amis2000/amis2000d.c +++ b/src/emu/cpu/amis2000/amis2000d.c @@ -31,6 +31,16 @@ static const char *const s_mnemonics[] = "INP", "OUT", "DISB", "DISN", "MVS", "PSH", "PSL", "EUR" }; +// number of bits per opcode parameter, negative indicates complement +static const INT8 s_bits[] = +{ + 0, 0, 4, 2, 2, 2, 2, 0, 0, 0, + -2, -2, -2, -2, 2, 2, + 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 2, 0, 0, 0, 0, 0, 0, 0, + -4, 6, 6, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; #define _OVER DASMFLAG_STEP_OVER #define _OUT DASMFLAG_STEP_OUT @@ -46,17 +56,6 @@ static const UINT32 s_flags[] = }; -static const int s_bits[] = -{ - 0, 0, 4, 2, 2, 2, 2, 0, 0, 0, - -2, -2, -2, -2, 2, 2, - 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 0, 0, 0, 0, 0, 0, - -4, 6, 6, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - - static const UINT8 s2000_mnemonic[0x100] = { /* 0x00 */ diff --git a/src/emu/cpu/ucom4/ucom4.c b/src/emu/cpu/ucom4/ucom4.c index 0734cac425f..00a4167fa92 100644 --- a/src/emu/cpu/ucom4/ucom4.c +++ b/src/emu/cpu/ucom4/ucom4.c @@ -3,6 +3,9 @@ /* NEC uCOM-4 MCU family cores + + reference: 1981 NEC Microcomputers Catalog (later editions may have errors!) + also looked at asterick's JavaScript D553 emulator for verification, with permission */ @@ -58,11 +61,13 @@ void ucom4_cpu_device::state_string_export(const device_state_entry &entry, astr { switch (entry.index()) { + // obviously not from a single flags register case STATE_GENFLAGS: - string.printf("%c%c%c%c", + string.printf("%c%c%c%c%c", m_inte_f ? 'E':'e', m_int_f ? 'I':'i', m_timer_f ? 'T':'t', + m_carry_s ? 'S':'s', m_carry_f ? 'C':'c' ); break; @@ -118,6 +123,7 @@ void ucom4_cpu_device::device_start() m_dpl = 0; m_dph = 0; m_carry_f = 0; + m_carry_s = 0; m_timer_f = 0; m_int_f = 0; m_inte_f = 0; @@ -131,6 +137,7 @@ void ucom4_cpu_device::device_start() save_item(NAME(m_dpl)); save_item(NAME(m_dph)); save_item(NAME(m_carry_f)); + save_item(NAME(m_carry_s)); save_item(NAME(m_timer_f)); save_item(NAME(m_int_f)); save_item(NAME(m_inte_f)); @@ -142,7 +149,7 @@ void ucom4_cpu_device::device_start() state_add(UCOM4_ACC, "ACC", m_acc).formatstr("%01X"); state_add(STATE_GENPC, "curpc", m_pc).formatstr("%04X").noshow(); - state_add(STATE_GENFLAGS, "GENFLAGS", m_carry_f).formatstr("%4s").noshow(); // dummy + state_add(STATE_GENFLAGS, "GENFLAGS", m_carry_f).formatstr("%5s").noshow(); // dummy m_icountptr = &m_icount; } @@ -155,6 +162,7 @@ void ucom4_cpu_device::device_start() void ucom4_cpu_device::device_reset() { + m_inte_f = 1; m_pc = 0; m_op = 0; } diff --git a/src/emu/cpu/ucom4/ucom4.h b/src/emu/cpu/ucom4/ucom4.h index 033d4dd6956..db0c3764a70 100644 --- a/src/emu/cpu/ucom4/ucom4.h +++ b/src/emu/cpu/ucom4/ucom4.h @@ -125,6 +125,7 @@ protected: UINT8 m_dpl; // 4-bit data pointer low (RAM x) UINT8 m_dph; // 1/2/3-bit data pointer high (RAM y) UINT8 m_carry_f; // carry flag + UINT8 m_carry_s; // carry save UINT8 m_timer_f; // timer out flag UINT8 m_int_f; // interrupt flag UINT8 m_inte_f; // interrupt enable flag diff --git a/src/emu/cpu/ucom4/ucom4d.c b/src/emu/cpu/ucom4/ucom4d.c index bfbdd7da43a..531be0ed58c 100644 --- a/src/emu/cpu/ucom4/ucom4d.c +++ b/src/emu/cpu/ucom4/ucom4d.c @@ -11,14 +11,143 @@ #include "ucom4.h" +enum e_mnemonics +{ + mLI, mL, mLM, mLDI, mLDZ, mS, mTAL, mTLA, + mX, mXI, mXD, mXM, mXMI, mXMD, mAD, mADC, mADS, mDAA, mDAS, + mEXL, mCLA, mCMA, mCIA, mCLC, mSTC, mTC, mINC, mDEC, mIND, mDED, + mRMB, mSMB, mREB, mSEB, mRPB, mSPB, mJMP, mJCP, mJPA, mCAL, mCZP, mRT, mRTS, + mCI, mCM, mCMB, mTAB, mCLI, mTMB, mTPA, mTPB, + mTIT, mIA, mIP, mOE, mOP, mOCD, mNOP, + mILL, + mTAW, mTAZ, mTHX, mTLY, mXAW, mXAZ, mXHR, mXHX, mXLS, mXLY, mXC, + mSFB, mRFB, mFBT, mFBF, mRAR, mINM, mDEM, mSTM, mTTM, mEI, mDI +}; + +static const char *const s_mnemonics[] = +{ + "LI", "L", "LM", "LDI", "LDZ", "S", "TAL", "TLA", + "X", "XI", "XD", "XM", "XMI", "XMD", "AD", "ADC", "ADS", "DAA", "DAS", + "EXL", "CLA", "CMA", "CIA", "CLC", "STC", "TC", "INC", "DEC", "IND", "DED", + "RMB", "SMB", "REB", "SEB", "RPB", "SPB", "JMP", "JCP", "JPA", "CAL", "CZP", "RT", "RTS", + "CI", "CM", "CMB", "TAB", "CLI", "TMB", "TPA", "TPB", + "TIT", "IA", "IP", "OE", "OP", "OCD", "NOP", + "?", + "TAW", "TAZ", "THX", "TLY", "XAW", "XAZ", "XHR", "XHX", "XLS", "XLY", "XC", + "SFB", "RFB", "FBT", "FBF", "RAR", "INM", "DEM", "STM", "TTM", "EI", "DI" +}; + +// number of bits per opcode parameter, 2 digits means opcode is 2 bytes +static const UINT8 s_bits[] = +{ + 4, 0, 2, 80, 4, 0, 0, 0, + 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 2, 2, 2, 2, 2, 83, 6, 0, 83, 4, 0, 0, + 40, 0, 2, 2, 40, 2, 2, 2, + 0, 0, 0, 0, 0, 80, 0, + 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 2, 2, 2, 0, 0, 0, 80, 0, 0, 0 +}; + +#define _OVER DASMFLAG_STEP_OVER +#define _OUT DASMFLAG_STEP_OUT + +static const UINT32 s_flags[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, _OVER, _OVER, _OUT, _OUT, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + + +static const UINT8 ucom4_mnemonic[0x100] = +{ + /* 0x00 */ + mNOP, mDI, mS, mTIT, mTC, mTTM, mDAA, mTAL, + mAD, mADS, mDAS, mCLC, mCM, mINC, mOP, mDEC, + mCMA, mCIA, mTLA, mDED, mSTM, mLDI, mCLI, mCI, + mEXL, mADC, mXC, mSTC, mILL, mINM, mOCD, mDEM, + /* 0x20 */ + mFBF, mFBF, mFBF, mFBF, mTAB, mTAB, mTAB, mTAB, + mX, mXM, mXM, mXM, mXD, mXMD, mXMD, mXMD, + mRAR, mEI, mIP, mIND, mCMB, mCMB, mCMB, mCMB, + mL, mLM, mLM, mLM, mXI, mXMI, mXMI, mXMI, + /* 0x40 */ + mIA, mJPA, mTAZ, mTAW, mOE, mILL, mTLY, mTHX, + mRT, mRTS, mXAZ, mXAW, mXLS, mXHR, mXLY, mXHX, + mTPB, mTPB, mTPB, mTPB, mTPA, mTPA, mTPA, mTPA, + mTMB, mTMB, mTMB, mTMB, mFBT, mFBT, mFBT, mFBT, + /* 0x60 */ + mRPB, mRPB, mRPB, mRPB, mREB, mREB, mREB, mREB, + mRMB, mRMB, mRMB, mRMB, mRFB, mRFB, mRFB, mRFB, + mSPB, mSPB, mSPB, mSPB, mSEB, mSEB, mSEB, mSEB, + mSMB, mSMB, mSMB, mSMB, mSFB, mSFB, mSFB, mSFB, + /* 0x80 */ + mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, + mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, mLDZ, + mCLA, mLI, mLI, mLI, mLI, mLI, mLI, mLI, + mLI, mLI, mLI, mLI, mLI, mLI, mLI, mLI, + /* 0xa0 */ + mJMP, mJMP, mJMP, mJMP, mJMP, mJMP, mJMP, mJMP, + mCAL, mCAL, mCAL, mCAL, mCAL, mCAL, mCAL, mCAL, + mCZP, mCZP, mCZP, mCZP, mCZP, mCZP, mCZP, mCZP, + mCZP, mCZP, mCZP, mCZP, mCZP, mCZP, mCZP, mCZP, + /* 0xc0 */ + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, + mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP, mJCP +}; + + + CPU_DISASSEMBLE(ucom4) { - int pos = 1;//0; -// UINT8 op = oprom[pos++]; -// UINT8 instr = ucom4_mnemonic[op]; + int pos = 0; + UINT8 op = oprom[pos++]; + UINT8 instr = ucom4_mnemonic[op]; char *dst = buffer; - dst += sprintf(dst, "ABC"); + dst += sprintf(dst, "%-4s ", s_mnemonics[instr]); + + // opcode parameter + int bits = s_bits[instr]; + if (bits) + { + UINT16 param = op & ((1 << (bits % 10)) - 1); + if (bits / 10) + { + UINT8 op2 = oprom[pos++]; + param = (param << (bits / 10)) | (op2 & ((1 << (bits / 10)) - 1)); + bits = (bits % 10) + (bits / 10); + } + + // special case for CZP + if (instr == mCZP) + { + param <<= 2; + bits += 2; + } + + if (bits <= 4) + dst += sprintf(dst, "%d", param); + else if (bits <= 8) + dst += sprintf(dst, "$%02X", param); + else + dst += sprintf(dst, "$%03X", param); + } - return pos | 0 | DASMFLAG_SUPPORTED; + return pos | s_flags[instr] | DASMFLAG_SUPPORTED; } -- cgit v1.2.3