From 678036dcd45187d6adde3087280fc2937e43c4ea Mon Sep 17 00:00:00 2001 From: AJR Date: Tue, 1 Nov 2022 19:33:42 -0400 Subject: cpu/cr16b, cpu/es5510, cpu/ks0164, cpu/mb86235, cpu/sharc, upd7220: Use util::sext and other bit utility functions * cpu/sharc: Be a bit more paranoid about extreme values of bit6 and len6 (non-DRC) --- src/devices/cpu/cr16b/cr16bdasm.cpp | 26 +++----- src/devices/cpu/cr16b/cr16bdasm.h | 3 +- src/devices/cpu/es5510/es5510.cpp | 46 ++++++++------ src/devices/cpu/ks0164/ks0164.cpp | 12 +--- src/devices/cpu/ks0164/ks0164d.cpp | 37 +++++------ src/devices/cpu/ks0164/ks0164d.h | 1 - src/devices/cpu/mb86235/mb86235d.cpp | 2 +- src/devices/cpu/mb86235/mb86235drc.cpp | 5 +- src/devices/cpu/mb86235/mb86235fe.cpp | 2 +- src/devices/cpu/sharc/sharc.h | 4 -- src/devices/cpu/sharc/sharcdrc.cpp | 16 ++--- src/devices/cpu/sharc/sharcdsm.cpp | 15 ++--- src/devices/cpu/sharc/sharcfe.cpp | 12 ++-- src/devices/cpu/sharc/sharcops.hxx | 113 ++++++++++++++------------------- src/devices/video/upd7220.cpp | 6 +- 15 files changed, 129 insertions(+), 171 deletions(-) diff --git a/src/devices/cpu/cr16b/cr16bdasm.cpp b/src/devices/cpu/cr16b/cr16bdasm.cpp index c9cb483e02e..afbd24e0add 100644 --- a/src/devices/cpu/cr16b/cr16bdasm.cpp +++ b/src/devices/cpu/cr16b/cr16bdasm.cpp @@ -160,9 +160,9 @@ void cr16b_disassembler::format_short_imm_unsigned(std::ostream &stream, u8 imm, if (imm == 0) stream << "$0"; else if (i) - util::stream_format(stream, "$0x%04X", (imm >= 0x10) ? 0xfff0 | (imm & 0x0f) : imm); + util::stream_format(stream, "$0x%04X", u16(util::sext(imm, 5))); else - util::stream_format(stream, "$0x%02X", (imm >= 0x10) ? 0xf0 | (imm & 0x0f) : imm); + util::stream_format(stream, "$0x%02X", u8(util::sext(imm, 5))); } void cr16b_disassembler::format_short_imm_decimal(std::ostream &stream, u8 imm) @@ -231,25 +231,17 @@ void cr16b_disassembler::format_abs18(std::ostream &stream, u32 addr) util::stream_format(stream, "0x%05X", addr); } -void cr16b_disassembler::format_pc_disp5(std::ostream &stream, offs_t pc, u8 disp) +void cr16b_disassembler::format_pc(std::ostream &stream, offs_t pc) { if (m_arch == cr16_arch::CR16A) - util::stream_format(stream, "0x%05X", (pc + disp - (disp >= 0x10 ? 0x20 : 0)) & 0x1ffff); // SMM + util::stream_format(stream, "0x%05X", pc & 0x1ffff); // SMM else - util::stream_format(stream, "0x%06X", (pc + disp - (disp >= 0x10 ? 0x20 : 0)) & 0x1fffff); // LMM -} - -void cr16b_disassembler::format_pc_disp9(std::ostream &stream, offs_t pc, u16 disp) -{ - if (m_arch == cr16_arch::CR16A) - util::stream_format(stream, "0x%05X", (pc + disp - (disp >= 0x100 ? 0x200 : 0)) & 0x1ffff); // SMM - else - util::stream_format(stream, "0x%06X", (pc + disp - (disp >= 0x100 ? 0x200 : 0)) & 0x1fffff); // LMM + util::stream_format(stream, "0x%06X", pc & 0x1fffff); // LMM } void cr16b_disassembler::format_pc_disp17(std::ostream &stream, offs_t pc, u32 disp) { - util::stream_format(stream, "0x%05X", (pc + disp - (disp >= 0x10000 ? 0x20000 : 0)) & 0x1ffff); + util::stream_format(stream, "0x%05X", (pc + disp) & 0x1ffff); } void cr16b_disassembler::format_pc_disp21(std::ostream &stream, offs_t pc, u32 disp) @@ -594,7 +586,7 @@ offs_t cr16b_disassembler::disassemble(std::ostream &stream, offs_t pc, const cr util::stream_format(stream, "b%s%c%c ", BIT(opcode, 7) ? "ne" : "eq", BIT(opcode, 6) ? '1' : '0', BIT(opcode, 13) ? 'w' : 'b'); format_reg(stream, (opcode & 0x0120) >> 5); stream << ", "; - format_pc_disp5(stream, pc, opcode & 0x001e); + format_pc(stream, pc + util::sext(opcode & 0x001e, 5)); return 2 | STEP_COND | SUPPORTED; } @@ -739,13 +731,13 @@ offs_t cr16b_disassembler::disassemble(std::ostream &stream, offs_t pc, const cr if ((opcode & 0x01e0) == 0x01c0) { stream << "br "; - format_pc_disp9(stream, pc, (opcode & 0x1e00) >> 4 | (opcode & 0x001e)); + format_pc(stream, pc + util::sext((opcode & 0x1e00) >> 4 | (opcode & 0x001e), 9)); return 2 | SUPPORTED; } else { util::stream_format(stream, "b%s ", s_cc[(opcode & 0x01e0) >> 5]); - format_pc_disp9(stream, pc, (opcode & 0x1e00) >> 4 | (opcode & 0x001e)); + format_pc(stream, pc + util::sext((opcode & 0x1e00) >> 4 | (opcode & 0x001e), 9)); return 2 | STEP_COND | SUPPORTED; } } diff --git a/src/devices/cpu/cr16b/cr16bdasm.h b/src/devices/cpu/cr16b/cr16bdasm.h index fa0218796ee..bfbb03b9d52 100644 --- a/src/devices/cpu/cr16b/cr16bdasm.h +++ b/src/devices/cpu/cr16b/cr16bdasm.h @@ -40,8 +40,7 @@ protected: void format_disp16(std::ostream &stream, u16 disp); void format_disp18(std::ostream &stream, u32 disp); void format_abs18(std::ostream &stream, u32 addr); - void format_pc_disp5(std::ostream &stream, offs_t pc, u8 disp); - void format_pc_disp9(std::ostream &stream, offs_t pc, u16 disp); + void format_pc(std::ostream &stream, offs_t pc); void format_pc_disp17(std::ostream &stream, offs_t pc, u32 disp); void format_pc_disp21(std::ostream &stream, offs_t pc, u32 disp); void format_excp_vector(std::ostream &stream, u8 vec); diff --git a/src/devices/cpu/es5510/es5510.cpp b/src/devices/cpu/es5510/es5510.cpp index 6614c03ab52..e5b377db12c 100644 --- a/src/devices/cpu/es5510/es5510.cpp +++ b/src/devices/cpu/es5510/es5510.cpp @@ -36,11 +36,6 @@ static constexpr int64_t MAX_48 = (s64(1) << 47) - 1; #define CARRY_OUT_24 (0x01000000) -constexpr int32_t SX(int32_t x) { return IS_NEGATIVE(x) ? x | 0xff000000 : x & 0x00ffffff; } -constexpr int32_t SC(int32_t x) { return x & 0x00ffffff; } -constexpr int64_t SX64(int64_t x) { return (x & s64(0x0000800000000000U)) ? x | s64(0xffff000000000000U) : x & s64(0x0000ffffffffffffU); } -//constexpr int64_t SC64(int64_t x) { return x & s64(0x0000ffffffffffffU); } - #define VERBOSE 0 #define VERBOSE_EXEC 0 @@ -108,7 +103,7 @@ inline static int32_t add(int32_t a, int32_t b, uint8_t &flags) { flags = setFlagTo(flags, FLAG_Z, result == 0); flags = setFlagTo(flags, FLAG_V, overflow); flags = setFlagTo(flags, FLAG_LT, lessThan); - return SC(result); + return result & 0x00ffffff; } inline static int32_t saturate(int32_t value, uint8_t &flags, bool negative) { @@ -292,7 +287,7 @@ const es5510_device::ram_control_t es5510_device::RAM_CONTROL[8] = { }; static inline char * DESCRIBE_RAM(char *s, uint8_t ramControl, uint32_t gprContents) { - return s + sprintf(s, es5510_device::RAM_CONTROL[ramControl].description, SC(gprContents)); + return s + sprintf(s, es5510_device::RAM_CONTROL[ramControl].description, gprContents & 0x00ffffff); } static inline char * DESCRIBE_ALU(char *s, uint8_t opcode, uint8_t aReg, const char *aName, uint8_t bReg, const char *bName, const op_select_t &opSelect) { @@ -414,15 +409,15 @@ void es5510_device::host_w(offs_t offset, uint8_t data) switch (offset) { case 0x00: gpr_latch = (gpr_latch&0x00ffff) | ((data&0xff)<<16); - LOG("ES5510: Host Write GPR latch[2] = %02x -> %06x (%d)\n", data, gpr_latch, SX(gpr_latch)); + LOG("ES5510: Host Write GPR latch[2] = %02x -> %06x (%d)\n", data, gpr_latch, util::sext(gpr_latch, 24)); break; case 0x01: gpr_latch = (gpr_latch&0xff00ff) | ((data&0xff)<< 8); - LOG("ES5510: Host Write GPR latch[1] = %02x -> %06x (%d)\n", data, gpr_latch, SX(gpr_latch)); + LOG("ES5510: Host Write GPR latch[1] = %02x -> %06x (%d)\n", data, gpr_latch, util::sext(gpr_latch, 24)); break; case 0x02: gpr_latch = (gpr_latch&0xffff00) | ((data&0xff)<< 0); - LOG("ES5510: Host Write GPR latch[0] = %02x -> %06x (%d)\n", data, gpr_latch, SX(gpr_latch)); + LOG("ES5510: Host Write GPR latch[0] = %02x -> %06x (%d)\n", data, gpr_latch, util::sext(gpr_latch, 24)); break; /* 0x03 to 0x08 INSTR Register */ @@ -435,9 +430,18 @@ void es5510_device::host_w(offs_t offset, uint8_t data) /* 0x09 to 0x0b DIL Register (r/o) */ - case 0x0c: dol_latch = (dol_latch&0x00ffff) | ((data&0xff)<<16); LOG("ES5510: Host Write DOL latch[2] = %02x -> %06x (%d)\n", data, dol_latch, SX(dol_latch)); break; - case 0x0d: dol_latch = (dol_latch&0xff00ff) | ((data&0xff)<< 8); LOG("ES5510: Host Write DOL latch[1] = %02x -> %06x (%d)\n", data, dol_latch, SX(dol_latch)); break; - case 0x0e: dol_latch = (dol_latch&0xffff00) | ((data&0xff)<< 0); LOG("ES5510: Host Write DOL latch[0] = %02x -> %06x (%d)\n", data, dol_latch, SX(dol_latch)); break; //TODO: docs says that this always returns 0xff + case 0x0c: + dol_latch = (dol_latch&0x00ffff) | ((data&0xff)<<16); + LOG("ES5510: Host Write DOL latch[2] = %02x -> %06x (%d)\n", data, dol_latch, util::sext(dol_latch, 24)); + break; + case 0x0d: + dol_latch = (dol_latch&0xff00ff) | ((data&0xff)<< 8); + LOG("ES5510: Host Write DOL latch[1] = %02x -> %06x (%d)\n", data, dol_latch, util::sext(dol_latch, 24)); + break; + case 0x0e: + dol_latch = (dol_latch&0xffff00) | ((data&0xff)<< 0); + LOG("ES5510: Host Write DOL latch[0] = %02x -> %06x (%d)\n", data, dol_latch, util::sext(dol_latch, 24)); + break; //TODO: docs says that this always returns 0xff case 0x0f: dadr_latch = (dadr_latch&0x00ffff) | ((data&0xff)<<16); @@ -509,7 +513,7 @@ void es5510_device::host_w(offs_t offset, uint8_t data) break; case 0xa0: /* Write select - GPR */ - LOG("ES5510: Host Write GPR %02x (%s): %06x (%d)\n", data, REGNAME(data&0xff), gpr_latch, SX(gpr_latch)); + LOG("ES5510: Host Write GPR %02x (%s): %06x (%d)\n", data, REGNAME(data&0xff), gpr_latch, util::sext(gpr_latch, 24)); write_reg(data, gpr_latch); break; @@ -526,7 +530,7 @@ void es5510_device::host_w(offs_t offset, uint8_t data) case 0xe0: /* Write select - GPR + INSTR */ #if VERBOSE DESCRIBE_INSTR(buf, instr_latch, gpr_latch, nullptr, nullptr, nullptr, nullptr); - LOG("%s",string_format("ES5510: Host Write INSTR+GPR %02x (%s): %012x %06x (%d): %s\n", data, REGNAME(data&0xff), instr_latch, gpr_latch, SX(gpr_latch), buf).c_str()); + LOG("%s",string_format("ES5510: Host Write INSTR+GPR %02x (%s): %012x %06x (%d): %s\n", data, REGNAME(data&0xff), instr_latch, gpr_latch, util::sext(gpr_latch, 24), buf).c_str()); #endif if (data < 0xa0) { instr[data] = instr_latch; @@ -769,10 +773,10 @@ void es5510_device::list_program(void(p)(const char *, ...)) { uint8_t cReg = (uint8_t)((instr[addr] >> 32) & 0xff); uint8_t dReg = (uint8_t)((instr[addr] >> 40) & 0xff); DESCRIBE_INSTR(buf, instr[addr], gpr[addr], name[aReg], name[bReg], name[cReg], name[dReg]); - p("%s",string_format("%02x: %012x %06x (%8d) %s\n", addr, instr[addr], gpr[addr]&0xffffff, SX(gpr[addr]&0xffffff), buf).c_str()); + p("%s",string_format("%02x: %012x %06x (%8d) %s\n", addr, instr[addr], gpr[addr]&0xffffff, util::sext(gpr[addr], 24), buf).c_str()); } for (; addr < 0xc0; addr++) { - p("%02x: %06x (%d)\n", addr, gpr[addr]&0xffffff, SX(gpr[addr]&0xffffff)); + p("%02x: %06x (%d)\n", addr, gpr[addr]&0xffffff, util::sext(gpr[addr], 24)); } } @@ -870,7 +874,7 @@ void es5510_device::execute_run() { // --- Write Multiplier result N-1 LOG_EXEC((". write mulacc:\n")); if (mulacc.write_result) { - mulacc.product = ((int64_t)SX(mulacc.cValue) * (int64_t)SX(mulacc.dValue)) << mulshift; + mulacc.product = mul_32x32(util::sext(mulacc.cValue, 24), util::sext(mulacc.dValue, 24)) << mulshift; if (mulacc.accumulate) { mulacc.result = mulacc.product + machl; } else { @@ -884,7 +888,7 @@ void es5510_device::execute_run() { } #if VERBOSE_EXEC if (mulacc.cValue || mulacc.dValue || (mulacc.accumulate && machl)) { - LOG_EXEC((". mulacc: %x (%d) * %x (%d) << %d", SX(mulacc.cValue), SX(mulacc.cValue), SX(mulacc.dValue), SX(mulacc.dValue), mulshift)); + LOG_EXEC((". mulacc: %x (%d) * %x (%d) << %d", (mulacc.cValue & 0x00ffffff), util::sext(mulacc.cValue, 24), (mulacc.dValue & 0x00ffffff), util::sext(mulacc.dValue, 24), mulshift)); if (mulacc.accumulate) LOG_EXEC((" + %llx (%lld) ", machl, machl)); LOG_EXEC((" = %llx (%lld)", mulacc.result, mulacc.result)); if (mac_overflow) { @@ -1137,7 +1141,7 @@ void es5510_device::write_reg(uint8_t reg, int32_t value) #endif int64_t masked = machl & (s64(0x00ffffffU) << 24); int64_t shifted = (int64_t)(value & 0x00ffffff) << 0; - machl = SX64(masked | shifted); + machl = util::sext(masked | shifted, 48); #if VERBOSE_EXEC LOG_EXEC((" . writing machl: l -> %06x => %llx -> %llx\n", value, old, machl)); #endif @@ -1149,7 +1153,7 @@ void es5510_device::write_reg(uint8_t reg, int32_t value) #endif int64_t masked = machl & (s64(0x00ffffffU) << 0); int64_t shifted = (int64_t)(value & 0x00ffffff) << 24; - machl = SX64(masked | shifted); + machl = util::sext(masked | shifted, 48); mac_overflow = false; #if VERBOSE_EXEC LOG_EXEC((" . writing machl: h -> %06x => %llx -> %llx\n", value, old, machl)); diff --git a/src/devices/cpu/ks0164/ks0164.cpp b/src/devices/cpu/ks0164/ks0164.cpp index 5b8f57fb776..7b59a4ef69a 100644 --- a/src/devices/cpu/ks0164/ks0164.cpp +++ b/src/devices/cpu/ks0164/ks0164.cpp @@ -9,11 +9,6 @@ DEFINE_DEVICE_TYPE(KS0164CPU, ks0164_cpu_device, "ks0164cpu", "Samsung KS0164 audio processor") -const u16 ks0164_cpu_device::imask[16] = { - 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, - 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff -}; - ks0164_cpu_device::ks0164_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : cpu_device(mconfig, KS0164CPU, tag, owner, clock) , m_program_config("program", ENDIANNESS_BIG, 16, 16) @@ -105,7 +100,7 @@ void ks0164_cpu_device::state_string_export(const device_state_entry &entry, std void ks0164_cpu_device::handle_irq() { - u16 mask = m_irq & imask[m_r[R_PSW] & 15]; + u16 mask = m_irq & util::make_bitmask(m_r[R_PSW] & 15); if(mask) { int index; for(index = 0; !(mask & (1 << index)); index ++); @@ -265,10 +260,7 @@ void ks0164_cpu_device::execute_run() case 0xf: default: cond = true; break; } if(cond) { - if(opcode & 0x200) - m_r[R_PC] += opcode | 0xfc00; - else - m_r[R_PC] += opcode & 0x3ff; + m_r[R_PC] += util::sext(opcode, 10); } break; } diff --git a/src/devices/cpu/ks0164/ks0164d.cpp b/src/devices/cpu/ks0164/ks0164d.cpp index a62e4e293a3..21e60bd97f7 100644 --- a/src/devices/cpu/ks0164/ks0164d.cpp +++ b/src/devices/cpu/ks0164/ks0164d.cpp @@ -15,11 +15,6 @@ const char *const ks0164_disassembler::regs[8] = { "r0", "r1", "r2", "r3", "sp", "psw", "pc", "zero" }; -s32 ks0164_disassembler::off10(u32 opcode) -{ - return opcode & 0x200 ? opcode | 0xfffffc00 : opcode & 0x3ff; -} - std::string ks0164_disassembler::imm8(s8 dt) { return dt < 0 ? util::string_format("-%x", -dt) : util::string_format("%x", dt); @@ -32,22 +27,22 @@ std::string ks0164_disassembler::off16(s16 dt) #define P std::ostream &stream, u32 opcode, const data_buffer &opcodes, u32 pc const ks0164_disassembler::instruction ks0164_disassembler::instructions[] { - { 0x0000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bne %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x0400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "beq %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x0800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bgeu %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x0c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bltu %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x1000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bpl %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x1400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bmi %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x1800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bvc %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x1c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bvs %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x2000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bnv %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x2400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bgtu %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x2800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bleu %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x2c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bgts %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x3000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bles %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x3400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bges %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x3800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "blts %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2 | STEP_COND; } }, - { 0x3c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bra %04x", (pc + 2 + off10(opcode)) & 0xffff); return 2; } }, + { 0x0000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bne %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x0400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "beq %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x0800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bgeu %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x0c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bltu %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x1000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bpl %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x1400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bmi %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x1800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bvc %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x1c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bvs %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x2000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bnv %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x2400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bgtu %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x2800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bleu %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x2c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bgts %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x3000, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bles %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x3400, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bges %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x3800, 0xfc00, [](P) -> u32 { util::stream_format(stream, "blts %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2 | STEP_COND; } }, + { 0x3c00, 0xfc00, [](P) -> u32 { util::stream_format(stream, "bra %04x", (pc + 2 + util::sext(opcode, 10)) & 0xffff); return 2; } }, { 0x4000, 0xf800, [](P) -> u32 { util::stream_format(stream, "%s += %s", regs[(opcode >> 8) & 7], imm8(opcode)); return 2; } }, { 0x4800, 0xf800, [](P) -> u32 { util::stream_format(stream, "%s -= %s", regs[(opcode >> 8) & 7], imm8(opcode)); return 2; } }, diff --git a/src/devices/cpu/ks0164/ks0164d.h b/src/devices/cpu/ks0164/ks0164d.h index 7f817ab8ba3..1062e2090be 100644 --- a/src/devices/cpu/ks0164/ks0164d.h +++ b/src/devices/cpu/ks0164/ks0164d.h @@ -28,7 +28,6 @@ private: static const instruction instructions[]; static const char *const regs[8]; - static s32 off10(u32 opcode); static std::string imm8(s8 dt); static std::string off16(s16 dt); }; diff --git a/src/devices/cpu/mb86235/mb86235d.cpp b/src/devices/cpu/mb86235/mb86235d.cpp index 6c6d176575d..4b47ec2038d 100644 --- a/src/devices/cpu/mb86235/mb86235d.cpp +++ b/src/devices/cpu/mb86235/mb86235d.cpp @@ -226,7 +226,7 @@ offs_t mb86235_disassembler::dasm_control(std::ostream &stream, uint32_t pc, uin int cop = (opcode >> 22) & 0x1f; - int rel12 = (opcode & 0x800) ? (0xfffff000 | (opcode & 0xfff)) : (opcode & 0xfff); + int rel12 = util::sext(opcode, 12); offs_t flags = 0; diff --git a/src/devices/cpu/mb86235/mb86235drc.cpp b/src/devices/cpu/mb86235/mb86235drc.cpp index 77953a640d8..e5903a3224b 100644 --- a/src/devices/cpu/mb86235/mb86235drc.cpp +++ b/src/devices/cpu/mb86235/mb86235drc.cpp @@ -1529,7 +1529,7 @@ void mb86235_device::generate_control(drcuml_block &block, compiler_state &compi int ef1 = (op >> 16) & 0x3f; int ef2 = op & 0xffff; int cop = (op >> 22) & 0x1f; -// int rel12 = (op & 0x800) ? (0xfffff000 | (op & 0xfff)) : (op & 0xfff); +// int rel12 = util::sext(op, 12); switch (cop) { @@ -1811,8 +1811,7 @@ void mb86235_device::generate_xfer3(drcuml_block &block, compiler_state &compile int ary = (opcode >> 4) & 7; int md = opcode & 0xf; - int disp = (opcode >> 7) & 0xfff; - if (disp & 0x800) disp |= 0xfffff800; + int disp = util::sext((opcode >> 7) & 0xfff, 12); switch (dr >> 5) { diff --git a/src/devices/cpu/mb86235/mb86235fe.cpp b/src/devices/cpu/mb86235/mb86235fe.cpp index 94a8d986869..26aa0e3adf4 100644 --- a/src/devices/cpu/mb86235/mb86235fe.cpp +++ b/src/devices/cpu/mb86235/mb86235fe.cpp @@ -804,7 +804,7 @@ void mb86235_frontend::describe_control(opcode_desc &desc) int ef1 = (desc.opptr.q[0] >> 16) & 0x3f; int ef2 = desc.opptr.q[0] & 0xffff; int cop = (desc.opptr.q[0] >> 22) & 0x1f; - int rel12 = (desc.opptr.q[0] & 0x800) ? (0xfffff000 | (desc.opptr.q[0] & 0xfff)) : (desc.opptr.q[0] & 0xfff); + int rel12 = util::sext(desc.opptr.q[0], 12); switch (cop) { diff --git a/src/devices/cpu/sharc/sharc.h b/src/devices/cpu/sharc/sharc.h index f7d2d8701cd..2189a1e6010 100644 --- a/src/devices/cpu/sharc/sharc.h +++ b/src/devices/cpu/sharc/sharc.h @@ -52,10 +52,6 @@ #define MODE2_CAFRZ 0x80000 /* Cache freeze */ -#define SIGN_EXTEND6(x) (((x) & 0x20) ? (0xffffffc0 | (x)) : (x)) -#define SIGN_EXTEND24(x) (((x) & 0x800000) ? (0xff000000 | (x)) : (x)) -#define MAKE_EXTRACT_MASK(start_bit, length) ((0xffffffff << start_bit) & (((uint32_t)0xffffffff) >> (32 - (start_bit + length)))) - #define OP_USERFLAG_COUNTER_LOOP 0x00000001 #define OP_USERFLAG_COND_LOOP 0x00000002 #define OP_USERFLAG_COND_FIELD 0x000003fc diff --git a/src/devices/cpu/sharc/sharcdrc.cpp b/src/devices/cpu/sharc/sharcdrc.cpp index 94f017df4b5..a2671db7a76 100644 --- a/src/devices/cpu/sharc/sharcdrc.cpp +++ b/src/devices/cpu/sharc/sharcdrc.cpp @@ -2349,7 +2349,7 @@ bool adsp21062_device::generate_opcode(drcuml_block &block, compiler_state &comp case 0x0c: // do until counter expired |000|01100| { uint16_t data = (uint16_t)(opcode >> 24); - int offset = SIGN_EXTEND24(opcode & 0xffffff); + int offset = util::sext(opcode & 0xffffff, 24); uint32_t address = desc->pc + offset; UML_MOV(block, LCNTR, data); @@ -2370,7 +2370,7 @@ bool adsp21062_device::generate_opcode(drcuml_block &block, compiler_state &comp case 0x0d: // do until counter expired |000|01101| { int ureg = (opcode >> 32) & 0xff; - int offset = SIGN_EXTEND24(opcode & 0xffffff); + int offset = util::sext(opcode & 0xffffff, 24); uint32_t address = desc->pc + offset; generate_read_ureg(block, compiler, desc, ureg, false); @@ -2391,7 +2391,7 @@ bool adsp21062_device::generate_opcode(drcuml_block &block, compiler_state &comp case 0x0e: // do until |000|01110| { - int offset = SIGN_EXTEND24(opcode & 0xffffff); + int offset = util::sext(opcode & 0xffffff, 24); uint32_t address = desc->pc + offset; // push pc @@ -3030,7 +3030,7 @@ bool adsp21062_device::generate_opcode(drcuml_block &block, compiler_state &comp int g = (opcode >> 40) & 0x1; int dreg = (opcode >> 23) & 0xf; int i = (opcode >> 41) & 0x7; - int mod = SIGN_EXTEND6((opcode >> 27) & 0x3f); + int mod = util::sext((opcode >> 27) & 0x3f, 6); int compute = opcode & 0x7fffff; bool has_condition = !if_condition_always_true(cond); @@ -5233,11 +5233,11 @@ void adsp21062_device::generate_shift_imm(drcuml_block &block, compiler_state &c case 0x10: // FEXT Rx BY : if (bit == 0) { - UML_AND(block, REG(rn), REG(rx), MAKE_EXTRACT_MASK(bit, len)); + UML_AND(block, REG(rn), REG(rx), util::make_bitmask(len)); } else { - UML_AND(block, I0, REG(rx), MAKE_EXTRACT_MASK(bit, len)); + UML_AND(block, I0, REG(rx), util::make_bitmask(len) << bit); UML_SHR(block, REG(rn), I0, bit); } if (SZ_CALC_REQUIRED) UML_SETc(block, COND_Z, ASTAT_SZ); @@ -5247,7 +5247,7 @@ void adsp21062_device::generate_shift_imm(drcuml_block &block, compiler_state &c return; case 0x12: // FEXT Rx BY : (SE) - UML_AND(block, I0, REG(rx), MAKE_EXTRACT_MASK(bit, len)); + UML_AND(block, I0, REG(rx), util::make_bitmask(len) << bit); UML_SHL(block, I0, I0, 32 - (bit + len)); UML_SAR(block, REG(rn), I0, 32 - (bit + len) + bit); if (SZ_CALC_REQUIRED) UML_SETc(block, COND_Z, ASTAT_SZ); @@ -5257,7 +5257,7 @@ void adsp21062_device::generate_shift_imm(drcuml_block &block, compiler_state &c return; case 0x19: // Rn = Rn OR FDEP Rx BY : - UML_AND(block, I0, REG(rx), MAKE_EXTRACT_MASK(0, len)); + UML_AND(block, I0, REG(rx), util::make_bitmask(len)); if (bit > 0) UML_SHL(block, I0, I0, bit); UML_OR(block, REG(rn), REG(rn), I0); diff --git a/src/devices/cpu/sharc/sharcdsm.cpp b/src/devices/cpu/sharc/sharcdsm.cpp index 7f2a6756bf1..f215e8816b9 100644 --- a/src/devices/cpu/sharc/sharcdsm.cpp +++ b/src/devices/cpu/sharc/sharcdsm.cpp @@ -95,9 +95,6 @@ const char sharc_disassembler::mr_regnames[16][8] = #define GET_DAG2_L(x) (GET_UREG(0x30 | (8 + (x & 0x7)))) #define GET_DAG2_B(x) (GET_UREG(0x40 | (8 + (x & 0x7)))) -#define SIGN_EXTEND6(x) ((x & 0x20) ? (0xffffffc0 | x) : x) -#define SIGN_EXTEND24(x) ((x & 0x800000) ? (0xff000000 | x) : x) - void sharc_disassembler::compute(std::ostream &stream, uint32_t opcode) { @@ -715,7 +712,7 @@ uint32_t sharc_disassembler::dasm_direct_jump(std::ostream &stream, uint32_t pc, if (opcode & 0x10000000000U) /* PC-relative branch */ { - util::stream_format(stream, " (0x%08X)", pc + SIGN_EXTEND24(addr)); + util::stream_format(stream, " (0x%08X)", pc + util::sext(addr, 24)); } else /* Indirect branch */ { @@ -761,7 +758,7 @@ uint32_t sharc_disassembler::dasm_indirect_jump_compute(std::ostream &stream, ui if (opcode & 0x10000000000U) /* PC-relative branch */ { - util::stream_format(stream, " (0x%08X)", pc + SIGN_EXTEND6(reladdr)); + util::stream_format(stream, " (0x%08X)", pc + util::sext(reladdr, 6)); } else /* Indirect branch */ { @@ -808,7 +805,7 @@ uint32_t sharc_disassembler::dasm_indirect_jump_compute_dregdm(std::ostream &str if (opcode & 0x200000000000U) /* PC-relative branch */ { - util::stream_format(stream, " (0x%08X)", pc + SIGN_EXTEND6(reladdr)); + util::stream_format(stream, " (0x%08X)", pc + util::sext(reladdr, 6)); } else /* Indirect branch */ { @@ -886,12 +883,12 @@ uint32_t sharc_disassembler::dasm_do_until_counter(std::ostream &stream, uint32_ if (opcode & 0x10000000000U) /* Loop counter from universal register */ { util::stream_format(stream, "LCNTR = %s, ", GET_UREG(ureg)); - util::stream_format(stream, "DO (0x%08X)", pc + SIGN_EXTEND24(addr)); + util::stream_format(stream, "DO (0x%08X)", pc + util::sext(addr, 24)); } else /* Loop counter from immediate */ { util::stream_format(stream, "LCNTR = 0x%04X, ", data); - util::stream_format(stream, "DO (0x%08X) UNTIL LCE", pc + SIGN_EXTEND24(addr)); + util::stream_format(stream, "DO (0x%08X) UNTIL LCE", pc + util::sext(addr, 24)); } return 0; } @@ -901,7 +898,7 @@ uint32_t sharc_disassembler::dasm_do_until(std::ostream &stream, uint32_t pc, ui int term = (opcode >> 33) & 0x1f; uint32_t addr = opcode & 0xffffff; - util::stream_format(stream, "DO (0x%08X) UNTIL %s", pc + SIGN_EXTEND24(addr), condition_codes_do[term]); + util::stream_format(stream, "DO (0x%08X) UNTIL %s", pc + util::sext(addr, 24), condition_codes_do[term]); return 0; } diff --git a/src/devices/cpu/sharc/sharcfe.cpp b/src/devices/cpu/sharc/sharcfe.cpp index dc060ac733d..e3405799124 100644 --- a/src/devices/cpu/sharc/sharcfe.cpp +++ b/src/devices/cpu/sharc/sharcfe.cpp @@ -326,7 +326,7 @@ bool sharc_frontend::describe(opcode_desc &desc, const opcode_desc *prev) describe_if_condition(desc, cond); - desc.targetpc = desc.pc + SIGN_EXTEND24(address); + desc.targetpc = desc.pc + util::sext(address, 24); desc.delayslots = (j) ? 2 : 0; desc.userflags |= (b) ? OP_USERFLAG_CALL : 0; @@ -377,7 +377,7 @@ bool sharc_frontend::describe(opcode_desc &desc, const opcode_desc *prev) describe_if_condition(desc, cond); - desc.targetpc = desc.pc + SIGN_EXTEND6((opcode >> 27) & 0x3f); + desc.targetpc = desc.pc + util::sext((opcode >> 27) & 0x3f, 6); desc.delayslots = (j) ? 2 : 0; desc.userflags |= (b) ? OP_USERFLAG_CALL : 0; @@ -426,7 +426,7 @@ bool sharc_frontend::describe(opcode_desc &desc, const opcode_desc *prev) case 0x0c: // do until counter expired |000|01100| { - int offset = SIGN_EXTEND24(opcode & 0xffffff); + int offset = util::sext(opcode & 0xffffff, 24); LOOP_DESCRIPTOR loop; loop.start_pc = desc.pc + 1; @@ -445,7 +445,7 @@ bool sharc_frontend::describe(opcode_desc &desc, const opcode_desc *prev) if (!describe_ureg_access(desc, ureg, UREG_READ)) return false; - int offset = SIGN_EXTEND24(opcode & 0xffffff); + int offset = util::sext(opcode & 0xffffff, 24); LOOP_DESCRIPTOR loop; loop.start_pc = desc.pc + 1; @@ -460,7 +460,7 @@ bool sharc_frontend::describe(opcode_desc &desc, const opcode_desc *prev) case 0x0e: // do until |000|01110| { - int offset = SIGN_EXTEND24(opcode & 0xffffff); + int offset = util::sext(opcode & 0xffffff, 24); int cond = (opcode >> 33) & 0x1f; LOOP_DESCRIPTOR loop; @@ -969,7 +969,7 @@ bool sharc_frontend::describe(opcode_desc &desc, const opcode_desc *prev) desc.flags |= OPFLAG_READS_MEMORY; } - desc.targetpc = desc.pc + SIGN_EXTEND6((opcode >> 27) & 0x3f); + desc.targetpc = desc.pc + util::sext((opcode >> 27) & 0x3f, 6); desc.delayslots = 0; break; } diff --git a/src/devices/cpu/sharc/sharcops.hxx b/src/devices/cpu/sharc/sharcops.hxx index ae2248b309f..a0144878174 100644 --- a/src/devices/cpu/sharc/sharcops.hxx +++ b/src/devices/cpu/sharc/sharcops.hxx @@ -1,8 +1,5 @@ // license:BSD-3-Clause // copyright-holders:Ville Linde -#define SIGN_EXTEND6(x) (((x) & 0x20) ? (0xffffffc0 | (x)) : (x)) -#define SIGN_EXTEND24(x) (((x) & 0x800000) ? (0xff000000 | (x)) : (x)) - #define PM_REG_I(x) (m_core->dag2.i[x]) #define PM_REG_M(x) (m_core->dag2.m[x]) #define PM_REG_B(x) (m_core->dag2.b[x]) @@ -457,8 +454,6 @@ void adsp21062_device::SET_UREG(int ureg, uint32_t data) #define SET_FLAG_SZ(x) if((x) == 0) m_core->astat |= SZ -#define MAKE_EXTRACT_MASK(start_bit, length) ((0xffffffff << start_bit) & (((uint32_t)0xffffffff) >> (32 - (start_bit + length)))) - void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx) { int8_t shift = data & 0xff; @@ -504,18 +499,7 @@ void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx case 0x02: /* ROT Rx BY */ { - if (shift < 0) - { - int s = (-shift) & 0x1f; - REG(rn) = (((uint32_t)REG(rx) >> s) & ((uint32_t)(0xffffffff) >> s)) | - (((uint32_t)REG(rx) << (32-s)) & ((uint32_t)(0xffffffff) << (32-s))); - } - else - { - int s = shift & 0x1f; - REG(rn) = (((uint32_t)REG(rx) << s) & ((uint32_t)(0xffffffff) << s)) | - (((uint32_t)REG(rx) >> (32-s)) & ((uint32_t)(0xffffffff) >> (32-s))); - } + REG(rn) = rotl_32(REG(rx), shift); SET_FLAG_SZ(REG(rn)); break; } @@ -541,8 +525,10 @@ void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx case 0x10: /* FEXT Rx BY : */ { - uint32_t ext = REG(rx) & MAKE_EXTRACT_MASK(bit, len); - REG(rn) = ext >> bit; + if (len == 0 || bit >= 32) + REG(rn) = 0; + else + REG(rn) = BIT(REG(rx), bit, std::min(len, 32)); SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -554,9 +540,10 @@ void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx case 0x11: /* Rn = Rn FDEP Rx BY : */ { - uint32_t ext = REG(rx) & MAKE_EXTRACT_MASK(0, len); - - REG(rn) = ext << bit; + if (len == 0 || bit >= 32) + REG(rn) = 0; + else + REG(rn) = (REG(rx) & util::make_bitmask(std::min(len, 32))) << bit; SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -568,11 +555,10 @@ void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx case 0x12: /* FEXT Rx BY : (Sign Extended) */ { - uint32_t ext = (REG(rx) & MAKE_EXTRACT_MASK(bit, len)) >> bit; - if (ext & (1 << (len-1))) { - ext |= (uint32_t)0xffffffff << (len-1); - } - REG(rn) = ext; + if (len == 0 || bit >= 32) + REG(rn) = 0; + else + REG(rn) = util::sext(REG(rx) >> bit, std::min(len, 32)); SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -584,11 +570,10 @@ void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx case 0x13: /* FDEP Rx BY Ry : (Sign Extended) */ { - uint32_t ext = REG(rx) & MAKE_EXTRACT_MASK(0, len); - if (ext & (1 << (len-1))) { - ext |= (uint32_t)0xffffffff << (len-1); - } - REG(rn) = ext << bit; + if (len == 0 || bit >= 32) + REG(rn) = 0; + else + REG(rn) = util::sext(REG(rx), std::min(len, 32)) << bit; SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -600,9 +585,8 @@ void adsp21062_device::SHIFT_OPERATION_IMM(int shiftop, int data, int rn, int rx case 0x19: /* Rn = Rn OR FDEP Rx BY : */ { - uint32_t ext = REG(rx) & MAKE_EXTRACT_MASK(0, len); - - REG(rn) |= ext << bit; + if (len != 0 && bit < 32) + REG(rn) |= (REG(rx) & util::make_bitmask(std::min(len, 32))) << bit; SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -946,8 +930,10 @@ void adsp21062_device::COMPUTE(uint32_t opcode) { int bit = REG(ry) & 0x3f; int len = (REG(ry) >> 6) & 0x3f; - uint32_t ext = REG(rx) & MAKE_EXTRACT_MASK(bit, len); - REG(rn) = ext >> bit; + if (len == 0 || bit >= 32) + REG(rn) = 0; + else + REG(rn) = BIT(REG(rx), bit, std::min(len, 32)); SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -961,11 +947,10 @@ void adsp21062_device::COMPUTE(uint32_t opcode) { int bit = REG(ry) & 0x3f; int len = (REG(ry) >> 6) & 0x3f; - uint32_t ext = (REG(rx) & MAKE_EXTRACT_MASK(bit, len)) >> bit; - if (ext & (1 << (len-1))) { - ext |= (uint32_t)0xffffffff << (len-1); - } - REG(rn) = ext; + if (len == 0 || bit >= 32) + REG(rn) = 0; + else + REG(rn) = util::sext(REG(rx) >> bit, std::min(len, 32)); SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -979,9 +964,9 @@ void adsp21062_device::COMPUTE(uint32_t opcode) { int bit = REG(ry) & 0x3f; int len = (REG(ry) >> 6) & 0x3f; - uint32_t ext = REG(rx) & MAKE_EXTRACT_MASK(0, len); - REG(rn) |= ext << bit; + if (len != 0 && bit < 32) + REG(rn) |= (REG(rx) & util::make_bitmask(std::min(len, 32))) << bit; SET_FLAG_SZ(REG(rn)); if (bit+len > 32) @@ -1484,7 +1469,7 @@ void adsp21062_device::sharcop_compute_dm_to_dreg_immmod() int u = (m_core->opcode >> 38) & 0x1; int dreg = (m_core->opcode >> 23) & 0xf; int i = (m_core->opcode >> 41) & 0x7; - int mod = SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f); + int mod = util::sext((m_core->opcode >> 27) & 0x3f, 6); int compute = m_core->opcode & 0x7fffff; if (IF_CONDITION_CODE(cond)) @@ -1514,7 +1499,7 @@ void adsp21062_device::sharcop_compute_dreg_to_dm_immmod() int u = (m_core->opcode >> 38) & 0x1; int dreg = (m_core->opcode >> 23) & 0xf; int i = (m_core->opcode >> 41) & 0x7; - int mod = SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f); + int mod = util::sext((m_core->opcode >> 27) & 0x3f, 6); int compute = m_core->opcode & 0x7fffff; /* due to parallelity issues, source REG must be saved */ @@ -1548,7 +1533,7 @@ void adsp21062_device::sharcop_compute_pm_to_dreg_immmod() int u = (m_core->opcode >> 38) & 0x1; int dreg = (m_core->opcode >> 23) & 0xf; int i = (m_core->opcode >> 41) & 0x7; - int mod = SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f); + int mod = util::sext((m_core->opcode >> 27) & 0x3f, 6); int compute = m_core->opcode & 0x7fffff; if (IF_CONDITION_CODE(cond)) @@ -1578,7 +1563,7 @@ void adsp21062_device::sharcop_compute_dreg_to_pm_immmod() int u = (m_core->opcode >> 38) & 0x1; int dreg = (m_core->opcode >> 23) & 0xf; int i = (m_core->opcode >> 41) & 0x7; - int mod = SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f); + int mod = util::sext((m_core->opcode >> 27) & 0x3f, 6); int compute = m_core->opcode & 0x7fffff; /* due to parallelity issues, source REG must be saved */ @@ -1822,12 +1807,12 @@ void adsp21062_device::sharcop_relative_call() if (j) { PUSH_PC(m_core->pc+3); /* 1 instruction + 2 delayed instructions */ - CHANGE_PC_DELAYED(m_core->pc + SIGN_EXTEND24(address)); + CHANGE_PC_DELAYED(m_core->pc + util::sext(address, 24)); } else { PUSH_PC(m_core->pc+1); - CHANGE_PC(m_core->pc + SIGN_EXTEND24(address)); + CHANGE_PC(m_core->pc + util::sext(address, 24)); } } } @@ -1864,11 +1849,11 @@ void adsp21062_device::sharcop_relative_jump() if (j) { - CHANGE_PC_DELAYED(m_core->pc + SIGN_EXTEND24(address)); + CHANGE_PC_DELAYED(m_core->pc + util::sext(address, 24)); } else { - CHANGE_PC(m_core->pc + SIGN_EXTEND24(address)); + CHANGE_PC(m_core->pc + util::sext(address, 24)); } } } @@ -2053,11 +2038,11 @@ void adsp21062_device::sharcop_relative_jump_compute() if (j) { - CHANGE_PC_DELAYED(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC_DELAYED(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } else { - CHANGE_PC(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } } else @@ -2085,11 +2070,11 @@ void adsp21062_device::sharcop_relative_jump_compute() if (j) { - CHANGE_PC_DELAYED(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC_DELAYED(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } else { - CHANGE_PC(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } } } @@ -2111,13 +2096,13 @@ void adsp21062_device::sharcop_relative_call_compute() { //PUSH_PC(m_core->pc+3); /* 1 instruction + 2 delayed instructions */ PUSH_PC(m_core->nfaddr); /* 1 instruction + 2 delayed instructions */ - CHANGE_PC_DELAYED(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC_DELAYED(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } else { //PUSH_PC(m_core->pc+1); PUSH_PC(m_core->daddr); - CHANGE_PC(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } } else @@ -2141,13 +2126,13 @@ void adsp21062_device::sharcop_relative_call_compute() { //PUSH_PC(m_core->pc+3); /* 1 instruction + 2 delayed instructions */ PUSH_PC(m_core->nfaddr); /* 1 instruction + 2 delayed instructions */ - CHANGE_PC_DELAYED(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC_DELAYED(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } else { //PUSH_PC(m_core->pc+1); PUSH_PC(m_core->daddr); - CHANGE_PC(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } } } @@ -2212,7 +2197,7 @@ void adsp21062_device::sharcop_relative_jump_compute_dreg_dm() if (IF_CONDITION_CODE(cond)) { - CHANGE_PC(m_core->pc + SIGN_EXTEND6((m_core->opcode >> 27) & 0x3f)); + CHANGE_PC(m_core->pc + util::sext((m_core->opcode >> 27) & 0x3f, 6)); } else { @@ -2368,7 +2353,7 @@ void adsp21062_device::sharcop_rti() void adsp21062_device::sharcop_do_until_counter_imm() { uint16_t data = (uint16_t)(m_core->opcode >> 24); - int offset = SIGN_EXTEND24(m_core->opcode & 0xffffff); + int offset = util::sext(m_core->opcode & 0xffffff, 24); uint32_t address = m_core->pc + offset; int type; int cond = 0xf; /* until LCE (loop counter expired */ @@ -2402,7 +2387,7 @@ void adsp21062_device::sharcop_do_until_counter_imm() void adsp21062_device::sharcop_do_until_counter_ureg() { int ureg = (m_core->opcode >> 32) & 0xff; - int offset = SIGN_EXTEND24(m_core->opcode & 0xffffff); + int offset = util::sext(m_core->opcode & 0xffffff, 24); uint32_t address = m_core->pc + offset; int type; int cond = 0xf; /* until LCE (loop counter expired */ @@ -2436,7 +2421,7 @@ void adsp21062_device::sharcop_do_until_counter_ureg() void adsp21062_device::sharcop_do_until() { int cond = (m_core->opcode >> 33) & 0x1f; - int offset = SIGN_EXTEND24(m_core->opcode & 0xffffff); + int offset = util::sext(m_core->opcode & 0xffffff, 24); uint32_t address = (m_core->pc + offset); PUSH_PC(m_core->pc+1); diff --git a/src/devices/video/upd7220.cpp b/src/devices/video/upd7220.cpp index 91a78531ea5..0dcecca025b 100644 --- a/src/devices/video/upd7220.cpp +++ b/src/devices/video/upd7220.cpp @@ -811,9 +811,9 @@ void upd7220_device::draw_pixel() void upd7220_device::draw_line() { - int d = (m_figs.m_d & 0x2000) ? (int16_t)(m_figs.m_d | 0xe000) : m_figs.m_d; - int d1 = (m_figs.m_d1 & 0x2000) ? (int16_t)(m_figs.m_d1 | 0xe000) : m_figs.m_d1; - int d2 = (m_figs.m_d2 & 0x2000) ? (int16_t)(m_figs.m_d2 | 0xe000) : m_figs.m_d2; + int d = util::sext(m_figs.m_d, 14); + int d1 = util::sext(m_figs.m_d1, 14); + int d2 = util::sext(m_figs.m_d2, 14); const uint8_t octant = m_figs.m_dir; LOG("uPD7220 line check: %08x %04x %02x %02x %d %d %d %d\n", m_ead, m_mask, m_bitmap_mod, m_figs.m_dir, m_figs.m_dc, d, d1, d2); -- cgit v1.2.3