From f93d2f80aa0e5273f36000feb4951222840024e2 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sun, 2 Nov 2025 13:56:47 +0900 Subject: [PATCH] */vrender0.cpp and related drivers/devices: Cleanup - Fix naming (Use snake_case as default naming convention for consistency) - Use shortened typename value for consistency - Fix spacings - Use lowercase hexadecimal values - Make some variables constant - Suppress side effects for debugger reads - Fix variable and function order in header files - Reduce defines cpu/se3208/se3208.cpp: - Make interrupt pin define as enum - Use logmacro.h for logging feature cpu/se3208/se3208dis.cpp: - Fix naming for reduce confusion sound/vrender0.cpp: - Update per-channel cache when texture memory pointer is changed - Use refefence instead pointer as possible video/vrender0.cpp: - Use template and function arrays for textured draw function - Use device_memory_interface for external memory space - Split shade and alpha function - Minor fixes in single color fill function - Use refefence instead pointer as possible lib/util/coretmpl.h: - Add allow/disallow side effects in fifo dequeue function misc/crospuzl.cpp: - Fix filename in comment (is_busy() is now moved into machine/nandflash.h) misc/crystal.cpp: - Add notes for flash memory emulations - Remove unused finder - Reduce literal tag usages misc/ddz.cpp: - Reduce literal tag usages misc/menghong.cpp: - Add notes for flash memory emulations misc/psattack.cpp: - Fix logging - Reduce literal tag usages misc/trivrus.cpp: - Add notes for flash memory emulations --- src/devices/cpu/se3208/se3208.cpp | 1331 +++++++++++++------------- src/devices/cpu/se3208/se3208.h | 239 ++--- src/devices/cpu/se3208/se3208dis.cpp | 954 +++++++++--------- src/devices/cpu/se3208/se3208dis.h | 158 +-- src/devices/machine/vr0uart.cpp | 53 +- src/devices/machine/vrender0.cpp | 226 +++-- src/devices/machine/vrender0.h | 154 +-- src/devices/sound/vrender0.cpp | 324 ++++--- src/devices/sound/vrender0.h | 60 +- src/devices/video/vrender0.cpp | 774 +++++++-------- src/devices/video/vrender0.h | 169 ++-- src/lib/util/coretmpl.h | 13 +- src/mame/misc/crospuzl.cpp | 146 +-- src/mame/misc/crystal.cpp | 107 +-- src/mame/misc/ddz.cpp | 18 +- src/mame/misc/menghong.cpp | 110 +-- src/mame/misc/psattack.cpp | 39 +- src/mame/misc/trivrus.cpp | 77 +- src/mame/misc/v0bowl.cpp | 4 +- 19 files changed, 2476 insertions(+), 2480 deletions(-) diff --git a/src/devices/cpu/se3208/se3208.cpp b/src/devices/cpu/se3208/se3208.cpp index 32d9dc533a436..40449bb667af3 100644 --- a/src/devices/cpu/se3208/se3208.cpp +++ b/src/devices/cpu/se3208/se3208.cpp @@ -4,6 +4,12 @@ #include "se3208.h" #include "se3208dis.h" +#define LOG_ALIGN (1 << 1) + +#define VERBOSE (0) + +#include "logmacro.h" + /* SE3208 CPU Emulator by ElSemi @@ -14,7 +20,7 @@ */ -enum : uint32_t +enum : u32 { FLAG_C = 0x0080, FLAG_V = 0x0010, @@ -29,12 +35,12 @@ enum : uint32_t }; //Precompute the instruction decoding in a big table -#define INST(a) void se3208_device::a(uint16_t Opcode) +#define INST(a) void se3208_device::a(u16 opcode) DEFINE_DEVICE_TYPE(SE3208, se3208_device, "se3208", "ADChips SE3208") -se3208_device::se3208_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +se3208_device::se3208_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : cpu_device(mconfig, SE3208, tag, owner, clock) , m_program_config("program", ENDIANNESS_LITTLE, 32, 32, 0) , m_machinex_cb(*this) @@ -51,41 +57,42 @@ device_memory_interface::space_config_vector se3208_device::memory_space_config( } -uint8_t se3208_device::SE3208_Read8(uint32_t address) +u8 se3208_device::read8(u32 address) { return m_program.read_byte(address); } -uint16_t se3208_device::SE3208_Read16(uint32_t address) +u16 se3208_device::read16(u32 address) { if (!WORD_ALIGNED(address)) - return m_program.read_byte(address) | m_program.read_byte(address+1)<<8; + return m_program.read_byte(address) | m_program.read_byte(address + 1) << 8; else return m_program.read_word(address); } -uint32_t se3208_device::SE3208_Read32(uint32_t address) +u32 se3208_device::read32(u32 address) { if (DWORD_ALIGNED(address)) return m_program.read_dword(address); else { - osd_printf_debug("%08x: dword READ unaligned %08x\n", m_PC, address); + if (!machine().side_effects_disabled()) + LOGMASKED(LOG_ALIGN, "%s: dword READ unaligned %08x\n", machine().describe_context(), address); return m_program.read_byte(address) | m_program.read_byte(address + 1) << 8 | m_program.read_byte(address + 2) << 16 | m_program.read_byte(address + 3) << 24; } } -void se3208_device::SE3208_Write8(uint32_t address,uint8_t data) +void se3208_device::write8(u32 address, u8 data) { m_program.write_byte(address,data); } -void se3208_device::SE3208_Write16(uint32_t address,uint16_t data) +void se3208_device::write16(u32 address, u16 data) { if (!WORD_ALIGNED(address)) { m_program.write_byte(address, data & 0xff); - m_program.write_byte(address+1, (data>>8)&0xff); + m_program.write_byte(address + 1, (data >> 8) & 0xff); } else { @@ -93,7 +100,7 @@ void se3208_device::SE3208_Write16(uint32_t address,uint16_t data) } } -void se3208_device::SE3208_Write32(uint32_t address, uint32_t data) +void se3208_device::write32(u32 address, u32 data) { if (DWORD_ALIGNED(address)) m_program.write_dword(address, data); @@ -103,131 +110,143 @@ void se3208_device::SE3208_Write32(uint32_t address, uint32_t data) m_program.write_byte(address + 1, (data >> 8) & 0xff); m_program.write_byte(address + 2, (data >> 16) & 0xff); m_program.write_byte(address + 3, (data >> 24) & 0xff); - osd_printf_debug("%08x: dword WRITE unaligned %08x\n", m_PC, address); + LOGMASKED(LOG_ALIGN, "%s: dword WRITE unaligned %08x\n", machine().describe_context(), address); } } -uint32_t se3208_device::AddWithFlags(uint32_t a,uint32_t b) +u32 se3208_device::add_with_lfags(u32 a, u32 b) { - uint32_t r=a+b; + const u32 r = a + b; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!r) + if (!r) SETFLAG(FLAG_Z); - if(r&0x80000000) + if (r & 0x80000000) SETFLAG(FLAG_S); - if(((((a&b)|(~r&(a|b)))>>31))&1) + if (((((a & b) | (~r & (a | b))) >> 31)) & 1) SETFLAG(FLAG_C); - if(((((a^r)&(b^r))>>31))&1) + if (((((a ^ r) & (b ^ r)) >> 31)) & 1) SETFLAG(FLAG_V); return r; } -uint32_t se3208_device::SubWithFlags(uint32_t a,uint32_t b) //a-b +u32 se3208_device::sub_with_lfags(u32 a, u32 b) //a-b { - uint32_t r=a-b; + const u32 r = a - b; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!r) + if (!r) SETFLAG(FLAG_Z); - if(r&0x80000000) + if (r & 0x80000000) SETFLAG(FLAG_S); - if((((b&r)|(~a&(b|r)))>>31)&1) + if ((((b & r) | (~a & (b | r))) >> 31) & 1) SETFLAG(FLAG_C); - if((((b^a)&(r^a))>>31)&1) + if ((((b ^ a) & (r ^ a)) >> 31) & 1) SETFLAG(FLAG_V); return r; } -uint32_t se3208_device::AdcWithFlags(uint32_t a,uint32_t b) +u32 se3208_device::adc_with_lfags(u32 a, u32 b) { - uint32_t C=(m_SR&FLAG_C)?1:0; - uint32_t r=a+b+C; + const u32 carry = (m_SR & FLAG_C) ? 1 : 0; + const u32 r = a + b + carry; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!r) + if (!r) SETFLAG(FLAG_Z); - if(r&0x80000000) + if (r & 0x80000000) SETFLAG(FLAG_S); - if(((((a&b)|(~r&(a|b)))>>31))&1) + if (((((a & b) | (~r & (a | b))) >> 31)) & 1) SETFLAG(FLAG_C); - if(((((a^r)&(b^r))>>31))&1) + if (((((a ^ r) & (b ^ r)) >> 31)) & 1) SETFLAG(FLAG_V); return r; } -uint32_t se3208_device::SbcWithFlags(uint32_t a,uint32_t b) +u32 se3208_device::sbc_with_lfags(u32 a, u32 b) { - uint32_t C=(m_SR&FLAG_C)?1:0; - uint32_t r=a-b-C; + const u32 carry = (m_SR & FLAG_C) ? 1 : 0; + const u32 r = a - b - carry; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!r) + if (!r) SETFLAG(FLAG_Z); - if(r&0x80000000) + if (r & 0x80000000) SETFLAG(FLAG_S); - if((((b&r)|(~a&(b|r)))>>31)&1) + if ((((b & r) | (~a & (b | r))) >> 31) & 1) SETFLAG(FLAG_C); - if((((b^a)&(r^a))>>31)&1) + if ((((b ^ a) & (r ^ a)) >> 31) & 1) SETFLAG(FLAG_V); return r; } -uint32_t se3208_device::MulWithFlags(uint32_t a,uint32_t b) +u32 se3208_device::mul_with_lfags(u32 a, u32 b) { - int64_t r=(int64_t) a*(int64_t) b; + const int64_t r = int64_t(a) * int64_t(b); CLRFLAG(FLAG_V); - if(r>>32) + if (r >> 32) SETFLAG(FLAG_V); - return (uint32_t) (r&0xffffffff); + return u32(r & 0xffffffff); } -uint32_t se3208_device::NegWithFlags(uint32_t a) +u32 se3208_device::neg_with_lfags(u32 a) { - return SubWithFlags(0,a); + return sub_with_lfags(0, a); } -uint32_t se3208_device::AsrWithFlags(uint32_t Val, uint8_t By) +u32 se3208_device::asr_with_lfags(u32 val, u8 by) { - signed int v=(signed int) Val; - v>>=By; + s32 v = s32(val); + v >>= by; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!v) + if (!v) SETFLAG(FLAG_Z); - if(v&0x80000000) + if (v & 0x80000000) SETFLAG(FLAG_S); - if(BIT(Val,By-1)) + if (BIT(val, by - 1)) SETFLAG(FLAG_C); - return (uint32_t) v; + return u32(v); } -uint32_t se3208_device::LsrWithFlags(uint32_t Val, uint8_t By) +u32 se3208_device::lsr_with_lfags(u32 val, u8 by) { - uint32_t v=Val; - v>>=By; + u32 v = val; + v >>= by; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!v) + if (!v) SETFLAG(FLAG_Z); - if(v&0x80000000) + if (v & 0x80000000) SETFLAG(FLAG_S); - if(BIT(Val,By-1)) + if (BIT(val, by - 1)) SETFLAG(FLAG_C); return v; } -uint32_t se3208_device::AslWithFlags(uint32_t Val, uint8_t By) +u32 se3208_device::asl_with_lfags(u32 val, u8 by) { - uint32_t v=Val; - v<<=By; + u32 v = val; + v <<= by; CLRFLAG(FLAG_Z|FLAG_C|FLAG_V|FLAG_S); - if(!v) + if (!v) SETFLAG(FLAG_Z); - if(v&0x80000000) + if (v & 0x80000000) SETFLAG(FLAG_S); - if(BIT(Val,32-By)) + if (BIT(val, 32 - by)) SETFLAG(FLAG_C); return v; } +u32 se3208_device::get_index(u32 index) +{ + if (index) + return m_R[index]; + else + return 0; +} + +u32 se3208_device::get_extended_operand(u32 imm, u8 shift) +{ + return (m_ER << shift) | (imm & ((1 << shift) - 1)); +} INST(INVALIDOP) { @@ -236,170 +255,142 @@ INST(INVALIDOP) INST(LDB) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read8(Index+Offset); - m_R[SrcDst]=int8_t(Val); + const u32 val = read8(index + offset); + m_R[src_dst] = s8(val); CLRFLAG(FLAG_E); } INST(STB) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - SE3208_Write8(Index+Offset,m_R[SrcDst]&0xFF); + write8(index + offset, m_R[src_dst] & 0xff); CLRFLAG(FLAG_E); } INST(LDS) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=1; + offset <<= 1; - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read16(Index+Offset); - m_R[SrcDst]=int16_t(Val); + const u32 val = read16(index + offset); + m_R[src_dst] = s16(val); CLRFLAG(FLAG_E); } INST(STS) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=1; + offset <<= 1; - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - SE3208_Write16(Index+Offset,m_R[SrcDst]&0xFFFF); + write16(index + offset, m_R[src_dst] & 0xffff); CLRFLAG(FLAG_E); } INST(LD) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=2; + offset <<= 2; - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - m_R[SrcDst]=SE3208_Read32(Index+Offset); + m_R[src_dst] = read32(index + offset); CLRFLAG(FLAG_E); } INST(ST) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=2; + offset <<= 2; - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - SE3208_Write32(Index+Offset,m_R[SrcDst]); + write32(index + offset, m_R[src_dst]); CLRFLAG(FLAG_E); } INST(LDBU) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read8(Index+Offset); - m_R[SrcDst]=Val; + const u32 val = read8(index + offset); + m_R[src_dst] = val; CLRFLAG(FLAG_E); } INST(LDSU) { - uint32_t Offset=BIT(Opcode,0,5); - uint32_t Index=BIT(Opcode,5,3); - uint32_t SrcDst=BIT(Opcode,8,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 5); + u32 index = BIT(opcode, 5, 3); + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=1; + offset <<= 1; - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read16(Index+Offset); - m_R[SrcDst]=Val&0xFFFF; + const u32 val = read16(index + offset); + m_R[src_dst] = val & 0xffff; CLRFLAG(FLAG_E); } @@ -407,601 +398,591 @@ INST(LDSU) INST(LERI) { - uint32_t Imm=BIT(Opcode,0,14); - if(TESTFLAG(FLAG_E)) - m_ER=(m_ER<<14)|Imm; + const u32 imm = BIT(opcode, 0, 14); + if (TESTFLAG(FLAG_E)) + m_ER = (m_ER << 14) | imm; else - m_ER=util::sext(Imm,14); - + m_ER = util::sext(imm, 14); SETFLAG(FLAG_E); } INST(LDSP) { - uint32_t Offset=BIT(Opcode,0,8); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,8,3); + u32 offset = BIT(opcode, 0, 8); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - m_R[SrcDst]=SE3208_Read32(Index+Offset); + m_R[src_dst] = read32(index + offset); CLRFLAG(FLAG_E); } INST(STSP) { - uint32_t Offset=BIT(Opcode,0,8); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,8,3); + u32 offset = BIT(opcode, 0, 8); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 8, 3); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - SE3208_Write32(Index+Offset,m_R[SrcDst]); + write32(index + offset, m_R[src_dst]); CLRFLAG(FLAG_E); } -void se3208_device::PushVal(uint32_t Val) +void se3208_device::push_val(u32 val) { - m_SP-=4; - SE3208_Write32(m_SP,Val); + m_SP -= 4; + write32(m_SP, val); } -uint32_t se3208_device::PopVal() +u32 se3208_device::pop_val() { - uint32_t Val=SE3208_Read32(m_SP); - m_SP+=4; - return Val; + const u32 val = read32(m_SP); + m_SP += 4; + return val; } INST(PUSH) { - uint32_t Set=BIT(Opcode,0,11); - if(BIT(Set,10)) - PushVal(m_PC); - if(BIT(Set,9)) - PushVal(m_SR); - if(BIT(Set,8)) - PushVal(m_ER); - if(BIT(Set,7)) - PushVal(m_R[7]); - if(BIT(Set,6)) - PushVal(m_R[6]); - if(BIT(Set,5)) - PushVal(m_R[5]); - if(BIT(Set,4)) - PushVal(m_R[4]); - if(BIT(Set,3)) - PushVal(m_R[3]); - if(BIT(Set,2)) - PushVal(m_R[2]); - if(BIT(Set,1)) - PushVal(m_R[1]); - if(BIT(Set,0)) - PushVal(m_R[0]); + const u32 set = BIT(opcode, 0, 11); + if (BIT(set, 10)) + push_val(m_PC); + if (BIT(set, 9)) + push_val(m_SR); + if (BIT(set, 8)) + push_val(m_ER); + if (BIT(set, 7)) + push_val(m_R[7]); + if (BIT(set, 6)) + push_val(m_R[6]); + if (BIT(set, 5)) + push_val(m_R[5]); + if (BIT(set, 4)) + push_val(m_R[4]); + if (BIT(set, 3)) + push_val(m_R[3]); + if (BIT(set, 2)) + push_val(m_R[2]); + if (BIT(set, 1)) + push_val(m_R[1]); + if (BIT(set, 0)) + push_val(m_R[0]); } INST(POP) { - uint32_t Set=BIT(Opcode,0,11); - if(BIT(Set,0)) - m_R[0]=PopVal(); - if(BIT(Set,1)) - m_R[1]=PopVal(); - if(BIT(Set,2)) - m_R[2]=PopVal(); - if(BIT(Set,3)) - m_R[3]=PopVal(); - if(BIT(Set,4)) - m_R[4]=PopVal(); - if(BIT(Set,5)) - m_R[5]=PopVal(); - if(BIT(Set,6)) - m_R[6]=PopVal(); - if(BIT(Set,7)) - m_R[7]=PopVal(); - if(BIT(Set,8)) - m_ER=PopVal(); - if(BIT(Set,9)) - m_SR=PopVal(); - if(BIT(Set,10)) + const u32 set = BIT(opcode, 0, 11); + if (BIT(set, 0)) + m_R[0] = pop_val(); + if (BIT(set, 1)) + m_R[1] = pop_val(); + if (BIT(set, 2)) + m_R[2] = pop_val(); + if (BIT(set, 3)) + m_R[3] = pop_val(); + if (BIT(set, 4)) + m_R[4] = pop_val(); + if (BIT(set, 5)) + m_R[5] = pop_val(); + if (BIT(set, 6)) + m_R[6] = pop_val(); + if (BIT(set, 7)) + m_R[7] = pop_val(); + if (BIT(set, 8)) + m_ER = pop_val(); + if (BIT(set, 9)) + m_SR = pop_val(); + if (BIT(set, 10)) { - m_PC=PopVal()-2; //PC automatically incresases by 2 + m_PC = pop_val() - 2; //PC automatically incresases by 2 } } INST(LEATOSP) { - uint32_t Offset=BIT(Opcode,9,4); - uint32_t Index=BIT(Opcode,3,3); + u32 offset = BIT(opcode, 9, 4); + u32 index = BIT(opcode, 3, 3); - if(Index) - Index=m_R[Index]; - else - Index=0; + index = get_index(index); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); else - Offset=util::sext(Offset,4); + offset = util::sext(offset, 4); - m_SP=(Index+Offset) & (~3); + m_SP = (index + offset) & ~3; CLRFLAG(FLAG_E); } INST(LEAFROMSP) { - uint32_t Offset=BIT(Opcode,9,4); - uint32_t Index=BIT(Opcode,3,3); + u32 offset = BIT(opcode, 9, 4); + const u32 index = BIT(opcode, 3, 3); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); else - Offset=util::sext(Offset,4); + offset = util::sext(offset, 4); - m_R[Index]=m_SP+Offset; + m_R[index] = m_SP + offset; CLRFLAG(FLAG_E); } INST(LEASPTOSP) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|(Offset&0xff); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=util::sext(Offset,10); + offset = util::sext(offset, 10); - m_SP=(m_SP+Offset) & (~3); + m_SP = (m_SP + offset) & ~3; CLRFLAG(FLAG_E); } INST(MOV) { - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,9,3); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 9, 3); - m_R[Dst]=m_R[Src]; + m_R[dst] = m_R[src]; } INST(LDI) { - uint32_t Dst=BIT(Opcode,8,3); - uint32_t Imm=BIT(Opcode,0,8); + const u32 dst = BIT(opcode, 8, 3); + u32 imm = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|(Imm&0xf); + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=int8_t(Imm); + imm = s8(imm); - m_R[Dst]=Imm; + m_R[dst] = imm; CLRFLAG(FLAG_E); } INST(LDBSP) { - uint32_t Offset=BIT(Opcode,0,4); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,4,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 4); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 4, 3); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read8(Index+Offset); - m_R[SrcDst]=int8_t(Val); + const u32 val = read8(index + offset); + m_R[src_dst] = s8(val); CLRFLAG(FLAG_E); } INST(STBSP) { - uint32_t Offset=BIT(Opcode,0,4); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,4,3); + u32 offset = BIT(opcode, 0, 4); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 4, 3); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - SE3208_Write8(Index+Offset,m_R[SrcDst]&0xFF); + write8(index + offset, m_R[src_dst] & 0xff); CLRFLAG(FLAG_E); } INST(LDSSP) { - uint32_t Offset=BIT(Opcode,0,4); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,4,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 4); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 4, 3); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read16(Index+Offset); - m_R[SrcDst]=int16_t(Val); + const u32 val = read16(index + offset); + m_R[src_dst] = s16(val); CLRFLAG(FLAG_E); } INST(STSSP) { - uint32_t Offset=BIT(Opcode,0,4); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,4,3); + u32 offset = BIT(opcode, 0, 4); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 4, 3); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - SE3208_Write16(Index+Offset,m_R[SrcDst]&0xFFFF); + write16(index + offset, m_R[src_dst] & 0xffff); CLRFLAG(FLAG_E); } INST(LDBUSP) { - uint32_t Offset=BIT(Opcode,0,4); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,4,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 4); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 4, 3); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read8(Index+Offset); - m_R[SrcDst]=Val; + const u32 val = read8(index + offset); + m_R[src_dst] = val; CLRFLAG(FLAG_E); } INST(LDSUSP) { - uint32_t Offset=BIT(Opcode,0,4); - uint32_t Index=m_SP; - uint32_t SrcDst=BIT(Opcode,4,3); - uint32_t Val; + u32 offset = BIT(opcode, 0, 4); + const u32 index = m_SP; + const u32 src_dst = BIT(opcode, 4, 3); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 4); - Val=SE3208_Read16(Index+Offset); - m_R[SrcDst]=Val; + const u32 val = read16(index + offset); + m_R[src_dst] = val; CLRFLAG(FLAG_E); } INST(ADDI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=AddWithFlags(m_R[Src],Imm); + m_R[dst] = add_with_lfags(m_R[src], imm); CLRFLAG(FLAG_E); } INST(SUBI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=SubWithFlags(m_R[Src],Imm); + m_R[dst] = sub_with_lfags(m_R[src], imm); CLRFLAG(FLAG_E); } INST(ADCI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=AdcWithFlags(m_R[Src],Imm); + m_R[dst] = adc_with_lfags(m_R[src], imm); CLRFLAG(FLAG_E); } INST(SBCI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=SbcWithFlags(m_R[Src],Imm); + m_R[dst] = sbc_with_lfags(m_R[src], imm); CLRFLAG(FLAG_E); } INST(ANDI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=m_R[Src]&Imm; + m_R[dst] = m_R[src] & imm; CLRFLAG(FLAG_S|FLAG_Z|FLAG_E); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(ORI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=m_R[Src]|Imm; + m_R[dst] = m_R[src] | imm; CLRFLAG(FLAG_S|FLAG_Z|FLAG_E); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(XORI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - m_R[Dst]=m_R[Src]^Imm; + m_R[dst] = m_R[src] ^ imm; CLRFLAG(FLAG_S|FLAG_Z|FLAG_E); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(CMPI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - SubWithFlags(m_R[Src],Imm); + sub_with_lfags(m_R[src], imm); CLRFLAG(FLAG_E); } INST(TSTI) { - uint32_t Imm=BIT(Opcode,9,4); - uint32_t Src=BIT(Opcode,3,3); - uint32_t Dst; + u32 imm = BIT(opcode, 9, 4); + const u32 src = BIT(opcode, 3, 3); - if(TESTFLAG(FLAG_E)) - Imm=(m_ER<<4)|Imm; + if (TESTFLAG(FLAG_E)) + imm = get_extended_operand(imm, 4); else - Imm=util::sext(Imm,4); + imm = util::sext(imm, 4); - Dst=m_R[Src]&Imm; + const u32 dst = m_R[src] & imm; CLRFLAG(FLAG_S|FLAG_Z|FLAG_E); - if(!Dst) + if (!dst) SETFLAG(FLAG_Z); - if(Dst&0x80000000) + if (dst & 0x80000000) SETFLAG(FLAG_S); } INST(ADD) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=AddWithFlags(m_R[Src1],m_R[Src2]); + m_R[dst] = add_with_lfags(m_R[src1], m_R[src2]); } INST(SUB) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=SubWithFlags(m_R[Src1],m_R[Src2]); + m_R[dst] = sub_with_lfags(m_R[src1], m_R[src2]); } INST(ADC) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=AdcWithFlags(m_R[Src1],m_R[Src2]); + m_R[dst] = adc_with_lfags(m_R[src1], m_R[src2]); } INST(SBC) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=SbcWithFlags(m_R[Src1],m_R[Src2]); + m_R[dst] = sbc_with_lfags(m_R[src1], m_R[src2]); } INST(AND) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=m_R[Src1]&m_R[Src2]; + m_R[dst] = m_R[src1] & m_R[src2]; CLRFLAG(FLAG_S|FLAG_Z); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(OR) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=m_R[Src1]|m_R[Src2]; + m_R[dst] = m_R[src1] | m_R[src2]; CLRFLAG(FLAG_S|FLAG_Z); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(XOR) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=m_R[Src1]^m_R[Src2]; + m_R[dst] = m_R[src1] ^ m_R[src2]; CLRFLAG(FLAG_S|FLAG_Z); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(CMP) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); - SubWithFlags(m_R[Src1],m_R[Src2]); + sub_with_lfags(m_R[src1], m_R[src2]); } INST(TST) { - uint32_t Src2=BIT(Opcode,9,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst; + const u32 src2 = BIT(opcode, 9, 3); + const u32 src1 = BIT(opcode, 3, 3); - Dst=m_R[Src1]&m_R[Src2]; + const u32 dst = m_R[src1] & m_R[src2]; CLRFLAG(FLAG_S|FLAG_Z); - if(!Dst) + if (!dst) SETFLAG(FLAG_Z); - if(Dst&0x80000000) + if (dst & 0x80000000) SETFLAG(FLAG_S); } INST(MULS) { - uint32_t Src2=BIT(Opcode,6,3); - uint32_t Src1=BIT(Opcode,3,3); - uint32_t Dst=BIT(Opcode,0,3); + const u32 src2 = BIT(opcode, 6, 3); + const u32 src1 = BIT(opcode, 3, 3); + const u32 dst = BIT(opcode, 0, 3); - m_R[Dst]=MulWithFlags(m_R[Src1],m_R[Src2]); + m_R[dst] = mul_with_lfags(m_R[src1], m_R[src2]); CLRFLAG(FLAG_E); } INST(NEG) { - uint32_t Dst=BIT(Opcode,9,3); - uint32_t Src=BIT(Opcode,3,3); + const u32 dst = BIT(opcode, 9, 3); + const u32 src = BIT(opcode, 3, 3); - m_R[Dst]=NegWithFlags(m_R[Src]); + m_R[dst] = neg_with_lfags(m_R[src]); } INST(CALL) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; - PushVal(m_PC+2); - m_PC=m_PC+Offset; + offset = s8(offset); + offset <<= 1; + push_val(m_PC + 2); + m_PC = m_PC + offset; CLRFLAG(FLAG_E); } INST(JV) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(TESTFLAG(FLAG_V)) + if (TESTFLAG(FLAG_V)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1010,17 +991,17 @@ INST(JV) INST(JNV) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!TESTFLAG(FLAG_V)) + if (!TESTFLAG(FLAG_V)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1028,17 +1009,17 @@ INST(JNV) INST(JC) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(TESTFLAG(FLAG_C)) + if (TESTFLAG(FLAG_C)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1046,17 +1027,17 @@ INST(JC) INST(JNC) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!TESTFLAG(FLAG_C)) + if (!TESTFLAG(FLAG_C)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1064,17 +1045,17 @@ INST(JNC) INST(JP) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!TESTFLAG(FLAG_S)) + if (!TESTFLAG(FLAG_S)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1082,17 +1063,17 @@ INST(JP) INST(JM) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(TESTFLAG(FLAG_S)) + if (TESTFLAG(FLAG_S)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1100,17 +1081,17 @@ INST(JM) INST(JNZ) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!TESTFLAG(FLAG_Z)) + if (!TESTFLAG(FLAG_Z)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1118,17 +1099,17 @@ INST(JNZ) INST(JZ) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(TESTFLAG(FLAG_Z)) + if (TESTFLAG(FLAG_Z)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1136,19 +1117,19 @@ INST(JZ) INST(JGE) { - uint32_t Offset=BIT(Opcode,0,8); - uint32_t S=TESTFLAG(FLAG_S)?1:0; - uint32_t V=TESTFLAG(FLAG_V)?1:0; + u32 offset = BIT(opcode, 0, 8); + const u32 s = TESTFLAG(FLAG_S) ? 1 : 0; + const u32 v = TESTFLAG(FLAG_V) ? 1 : 0; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!(S^V)) + if (!(s ^ v)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1156,36 +1137,36 @@ INST(JGE) INST(JLE) { - uint32_t Offset=BIT(Opcode,0,8); - uint32_t S=TESTFLAG(FLAG_S)?1:0; - uint32_t V=TESTFLAG(FLAG_V)?1:0; + u32 offset = BIT(opcode, 0, 8); + const u32 s = TESTFLAG(FLAG_S) ? 1 : 0; + const u32 v = TESTFLAG(FLAG_V) ? 1 : 0; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(TESTFLAG(FLAG_Z) || (S^V)) + if (TESTFLAG(FLAG_Z) || (s ^ v)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); } INST(JHI) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!(TESTFLAG(FLAG_Z) || TESTFLAG(FLAG_C))) + if (!(TESTFLAG(FLAG_Z) || TESTFLAG(FLAG_C))) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1193,17 +1174,17 @@ INST(JHI) INST(JLS) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(TESTFLAG(FLAG_Z) || TESTFLAG(FLAG_C)) + if (TESTFLAG(FLAG_Z) || TESTFLAG(FLAG_C)) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1211,19 +1192,19 @@ INST(JLS) INST(JGT) { - uint32_t Offset=BIT(Opcode,0,8); - uint32_t S=TESTFLAG(FLAG_S)?1:0; - uint32_t V=TESTFLAG(FLAG_V)?1:0; + u32 offset = BIT(opcode, 0, 8); + const u32 s = TESTFLAG(FLAG_S) ? 1 : 0; + const u32 v = TESTFLAG(FLAG_V) ? 1 : 0; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(!(TESTFLAG(FLAG_Z) || (S^V))) + if (!(TESTFLAG(FLAG_Z) || (s ^ v))) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); @@ -1231,73 +1212,71 @@ INST(JGT) INST(JLT) { - uint32_t Offset=BIT(Opcode,0,8); - uint32_t S=TESTFLAG(FLAG_S)?1:0; - uint32_t V=TESTFLAG(FLAG_V)?1:0; + u32 offset = BIT(opcode, 0, 8); + const u32 s = TESTFLAG(FLAG_S) ? 1 : 0; + const u32 v = TESTFLAG(FLAG_V) ? 1 : 0; - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); - Offset<<=1; + offset = s8(offset); + offset <<= 1; - if(S^V) + if (s ^ v) { - m_PC=m_PC+Offset; + m_PC = m_PC + offset; } CLRFLAG(FLAG_E); } - - INST(JMP) { - uint32_t Offset=BIT(Opcode,0,8); + u32 offset = BIT(opcode, 0, 8); - if(TESTFLAG(FLAG_E)) - Offset=(m_ER<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset = get_extended_operand(offset, 8); else - Offset=int8_t(Offset); + offset = s8(offset); - Offset<<=1; + offset <<= 1; - m_PC=m_PC+Offset; + m_PC = m_PC + offset; CLRFLAG(FLAG_E); } INST(JR) { - uint32_t Src=BIT(Opcode,0,4); + const u32 src = BIT(opcode, 0, 4); - m_PC=m_R[Src]-2; + m_PC = m_R[src] - 2; CLRFLAG(FLAG_E); } INST(CALLR) { - uint32_t Src=BIT(Opcode,0,4); - PushVal(m_PC+2); - m_PC=m_R[Src]-2; + const u32 src = BIT(opcode, 0, 4); + push_val(m_PC + 2); + m_PC = m_R[src] - 2; CLRFLAG(FLAG_E); } INST(ASR) { - uint32_t Dst=BIT(Opcode,0,3); + const u32 dst = BIT(opcode, 0, 3); - if(BIT(Opcode,10)) + if (BIT(opcode, 10)) { - uint32_t Cnt=BIT(Opcode,5,3); - m_R[Dst]=AsrWithFlags(m_R[Dst],m_R[Cnt]&0x1f); + const u32 cnt = BIT(opcode, 5, 3); + m_R[dst] = asr_with_lfags(m_R[dst], m_R[cnt] & 0x1f); } else { - uint32_t Imm=BIT(Opcode,5,5); - m_R[Dst]=AsrWithFlags(m_R[Dst],Imm); + const u32 imm = BIT(opcode, 5, 5); + m_R[dst] = asr_with_lfags(m_R[dst], imm); } CLRFLAG(FLAG_E); @@ -1305,17 +1284,17 @@ INST(ASR) INST(LSR) { - uint32_t Dst=BIT(Opcode,0,3); + const u32 dst = BIT(opcode, 0, 3); - if(BIT(Opcode,10)) + if (BIT(opcode, 10)) { - uint32_t Cnt=BIT(Opcode,5,3); - m_R[Dst]=LsrWithFlags(m_R[Dst],m_R[Cnt]&0x1f); + const u32 cnt = BIT(opcode, 5, 3); + m_R[dst] = lsr_with_lfags(m_R[dst], m_R[cnt] & 0x1f); } else { - uint32_t Imm=BIT(Opcode,5,5); - m_R[Dst]=LsrWithFlags(m_R[Dst],Imm); + const u32 imm = BIT(opcode, 5, 5); + m_R[dst] = lsr_with_lfags(m_R[dst], imm); } CLRFLAG(FLAG_E); @@ -1323,17 +1302,17 @@ INST(LSR) INST(ASL) { - uint32_t Dst=BIT(Opcode,0,3); + const u32 dst = BIT(opcode, 0, 3); - if(BIT(Opcode,10)) + if (BIT(opcode, 10)) { - uint32_t Cnt=BIT(Opcode,5,3); - m_R[Dst]=AslWithFlags(m_R[Dst],m_R[Cnt]&0x1f); + const u32 cnt = BIT(opcode, 5, 3); + m_R[dst] = asl_with_lfags(m_R[dst], m_R[cnt] & 0x1f); } else { - uint32_t Imm=BIT(Opcode,5,5); - m_R[Dst]=AslWithFlags(m_R[Dst],Imm); + const u32 imm = BIT(opcode, 5, 5); + m_R[dst] = asl_with_lfags(m_R[dst], imm); } CLRFLAG(FLAG_E); @@ -1341,100 +1320,99 @@ INST(ASL) INST(EXTB) { - uint32_t Dst=BIT(Opcode,0,4); - uint32_t Val=m_R[Dst]; + const u32 dst = BIT(opcode,0,4); + const u32 val = m_R[dst]; - m_R[Dst]=int8_t(Val&0xFF); + m_R[dst] = s8(val & 0xff); CLRFLAG(FLAG_S|FLAG_Z|FLAG_E); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); - } INST(EXTS) { - uint32_t Dst=BIT(Opcode,0,4); - uint32_t Val=m_R[Dst]; + const u32 dst = BIT(opcode,0,4); + const u32 val = m_R[dst]; - m_R[Dst]=int16_t(Val&0xFFFF); + m_R[dst] = s16(val & 0xffff); CLRFLAG(FLAG_S|FLAG_Z|FLAG_E); - if(!m_R[Dst]) + if (!m_R[dst]) SETFLAG(FLAG_Z); - if(m_R[Dst]&0x80000000) + if (m_R[dst] & 0x80000000) SETFLAG(FLAG_S); } INST(SET) { - uint32_t Imm=BIT(Opcode,0,4); + const u32 imm = BIT(opcode, 0, 4); - m_SR|=(1<*OpTable[Opcode])(Opcode); - m_PC+=2; + (this->*m_optable[opcode])(opcode); + m_PC += 2; //Check interrupts - if(m_NMI==ASSERT_LINE) + if (m_NMI == ASSERT_LINE) { - SE3208_NMI(); - m_NMI=CLEAR_LINE; + nmi_execute(); + m_NMI = CLEAR_LINE; } - else if(m_IRQ==ASSERT_LINE && TESTFLAG(FLAG_ENI)) + else if (m_IRQ == ASSERT_LINE && TESTFLAG(FLAG_ENI)) { - SE3208_Interrupt(); + interrupt_execute(); } --(m_icount); - } while(m_icount>0); + } while(m_icount > 0); } void se3208_device::device_start() { - BuildTable(); + build_table(); space(AS_PROGRAM).cache(m_cache); space(AS_PROGRAM).specific(m_program); @@ -1780,19 +1757,19 @@ void se3208_device::device_start() save_item(NAME(m_IRQ)); save_item(NAME(m_NMI)); - state_add( SE3208_PC, "PC", m_PC).formatstr("%08X"); - state_add( SE3208_SR, "SR", m_SR).formatstr("%08X"); - state_add( SE3208_ER, "ER", m_ER).formatstr("%08X"); - state_add( SE3208_SP, "SP", m_SP).formatstr("%08X"); - state_add( SE3208_R0, "R0", m_R[ 0]).formatstr("%08X"); - state_add( SE3208_R1, "R1", m_R[ 1]).formatstr("%08X"); - state_add( SE3208_R2, "R2", m_R[ 2]).formatstr("%08X"); - state_add( SE3208_R3, "R3", m_R[ 3]).formatstr("%08X"); - state_add( SE3208_R4, "R4", m_R[ 4]).formatstr("%08X"); - state_add( SE3208_R5, "R5", m_R[ 5]).formatstr("%08X"); - state_add( SE3208_R6, "R6", m_R[ 6]).formatstr("%08X"); - state_add( SE3208_R7, "R7", m_R[ 7]).formatstr("%08X"); - state_add( SE3208_PPC, "PPC", m_PPC).formatstr("%08X"); + state_add(SE3208_PC, "PC", m_PC).formatstr("%08X"); + state_add(SE3208_SR, "SR", m_SR).formatstr("%08X"); + state_add(SE3208_ER, "ER", m_ER).formatstr("%08X"); + state_add(SE3208_SP, "SP", m_SP).formatstr("%08X"); + state_add(SE3208_R0, "R0", m_R[0]).formatstr("%08X"); + state_add(SE3208_R1, "R1", m_R[1]).formatstr("%08X"); + state_add(SE3208_R2, "R2", m_R[2]).formatstr("%08X"); + state_add(SE3208_R3, "R3", m_R[3]).formatstr("%08X"); + state_add(SE3208_R4, "R4", m_R[4]).formatstr("%08X"); + state_add(SE3208_R5, "R5", m_R[5]).formatstr("%08X"); + state_add(SE3208_R6, "R6", m_R[6]).formatstr("%08X"); + state_add(SE3208_R7, "R7", m_R[7]).formatstr("%08X"); + state_add(SE3208_PPC, "PPC", m_PPC).formatstr("%08X"); state_add(STATE_GENPC, "GENPC", m_PC).noshow(); state_add(STATE_GENPCBASE, "CURPC", m_PPC).noshow(); @@ -1808,27 +1785,27 @@ void se3208_device::state_string_export(const device_state_entry &entry, std::st { case STATE_GENFLAGS: str = string_format("%c%c%c%c %c%c%c%c%c", - m_SR&FLAG_C?'C':'.', - m_SR&FLAG_V?'V':'.', - m_SR&FLAG_S?'S':'.', - m_SR&FLAG_Z?'Z':'.', - - m_SR&FLAG_M?'M':'.', - m_SR&FLAG_E?'E':'.', - m_SR&FLAG_AUT?'A':'.', - m_SR&FLAG_ENI?'I':'.', - m_SR&FLAG_NMI?'N':'.' + m_SR & FLAG_C ? 'C' : '.', + m_SR & FLAG_V ? 'V' : '.', + m_SR & FLAG_S ? 'S' : '.', + m_SR & FLAG_Z ? 'Z' : '.', + + m_SR & FLAG_M ? 'M' : '.', + m_SR & FLAG_E ? 'E' : '.', + m_SR & FLAG_AUT ? 'A' : '.', + m_SR & FLAG_ENI ? 'I' : '.', + m_SR & FLAG_NMI ? 'N' : '.' ); break; } } -void se3208_device::execute_set_input( int line, int state ) +void se3208_device::execute_set_input(int line, int state) { - if(line==INPUT_LINE_NMI) //NMI - m_NMI=state; + if (line == INPUT_LINE_NMI) //NMI + m_NMI = state; else - m_IRQ=state; + m_IRQ = state; } std::unique_ptr se3208_device::create_disassembler() diff --git a/src/devices/cpu/se3208/se3208.h b/src/devices/cpu/se3208/se3208.h index 8f6b2a1ccbbc0..795ea0e928482 100644 --- a/src/devices/cpu/se3208/se3208.h +++ b/src/devices/cpu/se3208/se3208.h @@ -11,14 +11,17 @@ enum SE3208_R0, SE3208_R1, SE3208_R2, SE3208_R3, SE3208_R4, SE3208_R5, SE3208_R6, SE3208_R7 }; -#define SE3208_INT 0 class se3208_device : public cpu_device { public: + enum + { + SE3208_INT = 0 + }; // construction/destruction - se3208_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + se3208_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); // callback configuration auto machinex_cb() { return m_machinex_cb.bind(); } @@ -30,8 +33,8 @@ class se3208_device : public cpu_device virtual void device_reset() override ATTR_COLD; // device_execute_interface implementation - virtual uint32_t execute_min_cycles() const noexcept override { return 1; } - virtual uint32_t execute_max_cycles() const noexcept override { return 1; } + virtual u32 execute_min_cycles() const noexcept override { return 1; } + virtual u32 execute_max_cycles() const noexcept override { return 1; } virtual bool execute_input_edge_triggered(int inputnum) const noexcept override { return inputnum == INPUT_LINE_NMI; } virtual void execute_run() override; virtual void execute_set_input(int inputnum, int state) override; @@ -52,126 +55,128 @@ class se3208_device : public cpu_device devcb_read8 m_iackx_cb; //GPR - uint32_t m_R[8]; + u32 m_R[8]{}; //SPR - uint32_t m_PC; - uint32_t m_SR; - uint32_t m_SP; - uint32_t m_ER; - uint32_t m_PPC; + u32 m_PC; + u32 m_SR; + u32 m_SP; + u32 m_ER; + u32 m_PPC; memory_access<32, 2, 0, ENDIANNESS_LITTLE>::cache m_cache; memory_access<32, 2, 0, ENDIANNESS_LITTLE>::specific m_program; - uint8_t m_IRQ; - uint8_t m_NMI; + u8 m_IRQ; + u8 m_NMI; int m_icount; - inline void CLRFLAG(uint32_t f) { m_SR&=~f; } - inline void SETFLAG(uint32_t f) { m_SR|=f; } - inline bool TESTFLAG(uint32_t f) const { return m_SR&f; } - - inline uint8_t SE3208_Read8(uint32_t addr); - inline uint16_t SE3208_Read16(uint32_t addr); - inline uint32_t SE3208_Read32(uint32_t addr); - inline void SE3208_Write8(uint32_t addr,uint8_t val); - inline void SE3208_Write16(uint32_t addr,uint16_t val); - inline void SE3208_Write32(uint32_t addr,uint32_t val); - inline uint32_t AddWithFlags(uint32_t a,uint32_t b); - inline uint32_t SubWithFlags(uint32_t a,uint32_t b); - inline uint32_t AdcWithFlags(uint32_t a,uint32_t b); - inline uint32_t SbcWithFlags(uint32_t a,uint32_t b); - inline uint32_t MulWithFlags(uint32_t a,uint32_t b); - inline uint32_t NegWithFlags(uint32_t a); - inline uint32_t AsrWithFlags(uint32_t Val, uint8_t By); - inline uint32_t LsrWithFlags(uint32_t Val, uint8_t By); - inline uint32_t AslWithFlags(uint32_t Val, uint8_t By); - inline void PushVal(uint32_t Val); - inline uint32_t PopVal(); - inline void TakeExceptionVector(uint8_t vector); - - typedef void (se3208_device::*OP)(uint16_t Opcode); - OP OpTable[0x10000]; - - void INVALIDOP(uint16_t Opcode); - void LDB(uint16_t Opcode); - void STB(uint16_t Opcode); - void LDS(uint16_t Opcode); - void STS(uint16_t Opcode); - void LD(uint16_t Opcode); - void ST(uint16_t Opcode); - void LDBU(uint16_t Opcode); - void LDSU(uint16_t Opcode); - void LERI(uint16_t Opcode); - void LDSP(uint16_t Opcode); - void STSP(uint16_t Opcode); - void PUSH(uint16_t Opcode); - void POP(uint16_t Opcode); - void LEATOSP(uint16_t Opcode); - void LEAFROMSP(uint16_t Opcode); - void LEASPTOSP(uint16_t Opcode); - void MOV(uint16_t Opcode); - void LDI(uint16_t Opcode); - void LDBSP(uint16_t Opcode); - void STBSP(uint16_t Opcode); - void LDSSP(uint16_t Opcode); - void STSSP(uint16_t Opcode); - void LDBUSP(uint16_t Opcode); - void LDSUSP(uint16_t Opcode); - void ADDI(uint16_t Opcode); - void SUBI(uint16_t Opcode); - void ADCI(uint16_t Opcode); - void SBCI(uint16_t Opcode); - void ANDI(uint16_t Opcode); - void ORI(uint16_t Opcode); - void XORI(uint16_t Opcode); - void CMPI(uint16_t Opcode); - void TSTI(uint16_t Opcode); - void ADD(uint16_t Opcode); - void SUB(uint16_t Opcode); - void ADC(uint16_t Opcode); - void SBC(uint16_t Opcode); - void AND(uint16_t Opcode); - void OR(uint16_t Opcode); - void XOR(uint16_t Opcode); - void CMP(uint16_t Opcode); - void TST(uint16_t Opcode); - void MULS(uint16_t Opcode); - void NEG(uint16_t Opcode); - void CALL(uint16_t Opcode); - void JV(uint16_t Opcode); - void JNV(uint16_t Opcode); - void JC(uint16_t Opcode); - void JNC(uint16_t Opcode); - void JP(uint16_t Opcode); - void JM(uint16_t Opcode); - void JNZ(uint16_t Opcode); - void JZ(uint16_t Opcode); - void JGE(uint16_t Opcode); - void JLE(uint16_t Opcode); - void JHI(uint16_t Opcode); - void JLS(uint16_t Opcode); - void JGT(uint16_t Opcode); - void JLT(uint16_t Opcode); - void JMP(uint16_t Opcode); - void JR(uint16_t Opcode); - void CALLR(uint16_t Opcode); - void ASR(uint16_t Opcode); - void LSR(uint16_t Opcode); - void ASL(uint16_t Opcode); - void EXTB(uint16_t Opcode); - void EXTS(uint16_t Opcode); - void SET(uint16_t Opcode); - void CLR(uint16_t Opcode); - void SWI(uint16_t Opcode); - void HALT(uint16_t Opcode); - void MVTC(uint16_t Opcode); - void MVFC(uint16_t Opcode); - - void BuildTable(void); - OP DecodeOp(uint16_t Opcode); - void SE3208_NMI(); - void SE3208_Interrupt(); + typedef void (se3208_device::*OP)(u16 opcode); + OP m_optable[0x10000]; + + inline void CLRFLAG(u32 f) { m_SR &= ~f; } + inline void SETFLAG(u32 f) { m_SR |= f; } + inline bool TESTFLAG(u32 f) const { return m_SR & f; } + + inline u8 read8(u32 addr); + inline u16 read16(u32 addr); + inline u32 read32(u32 addr); + inline void write8(u32 addr, u8 val); + inline void write16(u32 addr, u16 val); + inline void write32(u32 addr, u32 val); + inline u32 add_with_lfags(u32 a, u32 b); + inline u32 sub_with_lfags(u32 a, u32 b); + inline u32 adc_with_lfags(u32 a, u32 b); + inline u32 sbc_with_lfags(u32 a, u32 b); + inline u32 mul_with_lfags(u32 a, u32 b); + inline u32 neg_with_lfags(u32 a); + inline u32 asr_with_lfags(u32 Val, u8 By); + inline u32 lsr_with_lfags(u32 Val, u8 By); + inline u32 asl_with_lfags(u32 Val, u8 By); + inline u32 get_index(u32 index); + inline u32 get_extended_operand(u32 imm, u8 shift); + inline void push_val(u32 Val); + inline u32 pop_val(); + inline void take_exception_vector(u8 vector); + + void INVALIDOP(u16 opcode); + void LDB(u16 opcode); + void STB(u16 opcode); + void LDS(u16 opcode); + void STS(u16 opcode); + void LD(u16 opcode); + void ST(u16 opcode); + void LDBU(u16 opcode); + void LDSU(u16 opcode); + void LERI(u16 opcode); + void LDSP(u16 opcode); + void STSP(u16 opcode); + void PUSH(u16 opcode); + void POP(u16 opcode); + void LEATOSP(u16 opcode); + void LEAFROMSP(u16 opcode); + void LEASPTOSP(u16 opcode); + void MOV(u16 opcode); + void LDI(u16 opcode); + void LDBSP(u16 opcode); + void STBSP(u16 opcode); + void LDSSP(u16 opcode); + void STSSP(u16 opcode); + void LDBUSP(u16 opcode); + void LDSUSP(u16 opcode); + void ADDI(u16 opcode); + void SUBI(u16 opcode); + void ADCI(u16 opcode); + void SBCI(u16 opcode); + void ANDI(u16 opcode); + void ORI(u16 opcode); + void XORI(u16 opcode); + void CMPI(u16 opcode); + void TSTI(u16 opcode); + void ADD(u16 opcode); + void SUB(u16 opcode); + void ADC(u16 opcode); + void SBC(u16 opcode); + void AND(u16 opcode); + void OR(u16 opcode); + void XOR(u16 opcode); + void CMP(u16 opcode); + void TST(u16 opcode); + void MULS(u16 opcode); + void NEG(u16 opcode); + void CALL(u16 opcode); + void JV(u16 opcode); + void JNV(u16 opcode); + void JC(u16 opcode); + void JNC(u16 opcode); + void JP(u16 opcode); + void JM(u16 opcode); + void JNZ(u16 opcode); + void JZ(u16 opcode); + void JGE(u16 opcode); + void JLE(u16 opcode); + void JHI(u16 opcode); + void JLS(u16 opcode); + void JGT(u16 opcode); + void JLT(u16 opcode); + void JMP(u16 opcode); + void JR(u16 opcode); + void CALLR(u16 opcode); + void ASR(u16 opcode); + void LSR(u16 opcode); + void ASL(u16 opcode); + void EXTB(u16 opcode); + void EXTS(u16 opcode); + void SET(u16 opcode); + void CLR(u16 opcode); + void SWI(u16 opcode); + void HALT(u16 opcode); + void MVTC(u16 opcode); + void MVFC(u16 opcode); + + void build_table(); + OP decode_op(u16 opcode); + void nmi_execute(); + void interrupt_execute(); }; diff --git a/src/devices/cpu/se3208/se3208dis.cpp b/src/devices/cpu/se3208/se3208dis.cpp index cde334c5d3c5d..cb7b07eb2dac0 100644 --- a/src/devices/cpu/se3208/se3208dis.cpp +++ b/src/devices/cpu/se3208/se3208dis.cpp @@ -5,18 +5,18 @@ #define FLAG_E 0x0800 -#define CLRFLAG(f) SR&=~(f); -#define SETFLAG(f) SR|=(f); -#define TESTFLAG(f) (SR&(f)) +#define CLRFLAG(f) SR &= ~(f); +#define SETFLAG(f) SR |= (f); +#define TESTFLAG(f) (SR & (f)) -#define EXTRACT(val,sbit,ebit) (((val)>>sbit)&((1<<((ebit-sbit)+1))-1)) -#define SEX8(val) ((val&0x80)?(val|0xFFFFFF00):(val&0xFF)) -#define SEX16(val) ((val&0x8000)?(val|0xFFFF0000):(val&0xFFFF)) -#define ZEX8(val) ((val)&0xFF) -#define ZEX16(val) ((val)&0xFFFF) -#define SEX(bits,val) ((val)&(1<<(bits-1))?((val)|(~((1<> sbit) & ((1 << (((ebit) - (sbit)) + 1)) - 1)) +#define SEXT8(val) (((val) & 0x80) ? ((val) | 0xffffff00) : ((val) & 0xff)) +#define SEXT16(val) (((val) & 0x8000) ? ((val) | 0xffff0000) : ((val) & 0xffff)) +#define ZEXT8(val) ((val) & 0xff) +#define ZEX1T6(val) ((val) & 0xffff) +#define SEXT(bits,val) ((val) & (1 << ((bits) - 1)) ? ((val) | (~((1 << (bits)) - 1))) : (val & ((1 << (bits)) - 1))) -#define INST(a) uint32_t se3208_disassembler::a(uint16_t Opcode, std::ostream &stream) +#define INST(a) u32 se3208_disassembler::a(u16 opcode, std::ostream &stream) @@ -28,17 +28,17 @@ INST(INVALIDOP) INST(LDB) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "LDB (%%R%d,0x%x),%%R%d",Index,Offset,SrcDst); + if (index) + util::stream_format(stream, "LDB (%%R%d,0x%x),%%R%d", index, offset, src_dst); else - util::stream_format(stream, "LDB (0x%x),%%R%d",Index+Offset,SrcDst); + util::stream_format(stream, "LDB (0x%x),%%R%d", index + offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -46,17 +46,17 @@ INST(LDB) INST(STB) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "STB %%R%d,(%%R%d,0x%x)",SrcDst,Index,Offset); + if (index) + util::stream_format(stream, "STB %%R%d,(%%R%d,0x%x)", src_dst, index, offset); else - util::stream_format(stream, "STB %%R%d,(0x%x)",SrcDst,Index+Offset); + util::stream_format(stream, "STB %%R%d,(0x%x)", src_dst, index + offset); CLRFLAG(FLAG_E); return 0; @@ -64,19 +64,19 @@ INST(STB) INST(LDS) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "LDS (%%R%d,0x%x),%%R%d",Index,Offset,SrcDst); + if (index) + util::stream_format(stream, "LDS (%%R%d,0x%x),%%R%d", index, offset, src_dst); else - util::stream_format(stream, "LDS (0x%x),%%R%d",Index+Offset,SrcDst); + util::stream_format(stream, "LDS (0x%x),%%R%d", index + offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -84,19 +84,19 @@ INST(LDS) INST(STS) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "STS %%R%d,(%%R%d,0x%x)",SrcDst,Index,Offset); + if (index) + util::stream_format(stream, "STS %%R%d,(%%R%d,0x%x)", src_dst, index, offset); else - util::stream_format(stream, "STS %%R%d,(0x%x)",SrcDst,Index+Offset); + util::stream_format(stream, "STS %%R%d,(0x%x)", src_dst, index + offset); CLRFLAG(FLAG_E); return 0; @@ -104,19 +104,19 @@ INST(STS) INST(LD) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "LD (%%R%d,0x%x),%%R%d",Index,Offset,SrcDst); + if (index) + util::stream_format(stream, "LD (%%R%d,0x%x),%%R%d", index, offset, src_dst); else - util::stream_format(stream, "LD (0x%x),%%R%d",Index+Offset,SrcDst); + util::stream_format(stream, "LD (0x%x),%%R%d", index + offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -124,19 +124,19 @@ INST(LD) INST(ST) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "ST %%R%d,(%%R%d,0x%x)",SrcDst,Index,Offset); + if (index) + util::stream_format(stream, "ST %%R%d,(%%R%d,0x%x)", src_dst, index, offset); else - util::stream_format(stream, "ST %%R%d,(0x%x)",SrcDst,Index+Offset); + util::stream_format(stream, "ST %%R%d,(0x%x)", src_dst, index + offset); CLRFLAG(FLAG_E); return 0; @@ -144,17 +144,17 @@ INST(ST) INST(LDBU) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "LDBU (%%R%d,0x%x),%%R%d",Index,Offset,SrcDst); + if (index) + util::stream_format(stream, "LDBU (%%R%d,0x%x),%%R%d", index, offset, src_dst); else - util::stream_format(stream, "LDBU (0x%x),%%R%d",Index+Offset,SrcDst); + util::stream_format(stream, "LDBU (0x%x),%%R%d", index + offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -162,19 +162,19 @@ INST(LDBU) INST(LDSU) { - uint32_t Offset=EXTRACT(Opcode,0,4); - uint32_t Index=EXTRACT(Opcode,5,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 4); + const u32 index = EXTRACT(opcode, 5, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - if(Index) - util::stream_format(stream, "LDSU (%%R%d,0x%x),%%R%d",Index,Offset,SrcDst); + if (index) + util::stream_format(stream, "LDSU (%%R%d,0x%x),%%R%d", index, offset, src_dst); else - util::stream_format(stream, "LDSU (0x%x),%%R%d",Index+Offset,SrcDst); + util::stream_format(stream, "LDSU (0x%x),%%R%d", index + offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -183,15 +183,15 @@ INST(LDSU) INST(LERI) { - uint32_t Imm=EXTRACT(Opcode,0,13); + const u32 imm = EXTRACT(opcode, 0, 13); - if(TESTFLAG(FLAG_E)) - ER=(EXTRACT(ER,0,17)<<14)|Imm; + if (TESTFLAG(FLAG_E)) + ER = (EXTRACT(ER, 0, 17) << 14) | imm; else - ER=SEX(14,Imm); + ER = SEXT(14, imm); - //util::stream_format(stream, "LERI 0x%x\t\tER=%08X",Imm,ER); - util::stream_format(stream, "LERI 0x%x",Imm/*,ER*/); + //util::stream_format(stream, "LERI 0x%x\t\tER=%08X", imm,ER); + util::stream_format(stream, "LERI 0x%x", imm/*, ER*/); SETFLAG(FLAG_E); return 0; @@ -199,15 +199,15 @@ INST(LERI) INST(LDSP) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "LD (%%SP,0x%x),%%R%d",Offset,SrcDst); + util::stream_format(stream, "LD (%%SP,0x%x),%%R%d", offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -215,15 +215,15 @@ INST(LDSP) INST(STSP) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t SrcDst=EXTRACT(Opcode,8,10); + u32 offset = EXTRACT(opcode, 0, 7); + const u32 src_dst = EXTRACT(opcode, 8, 10); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "ST %%R%d,(%%SP,0x%x)",SrcDst,Offset); + util::stream_format(stream, "ST %%R%d,(%%SP,0x%x)", src_dst, offset); CLRFLAG(FLAG_E); return 0; @@ -231,81 +231,81 @@ INST(STSP) INST(PUSH) { - uint32_t Set=EXTRACT(Opcode,0,10); + u32 set = EXTRACT(opcode, 0, 10); stream << "PUSH "; - if(Set&(1<<10)) + if (set & (1 << 10)) stream << "%PC-"; - if(Set&(1<<9)) + if (set & (1 << 9)) stream << "%SR-"; - if(Set&(1<<8)) + if (set & (1 << 8)) stream << "%ER-"; - if(Set&(1<<7)) + if (set & (1 << 7)) stream << "%R7-"; - if(Set&(1<<6)) + if (set & (1 << 6)) stream << "%R6-"; - if(Set&(1<<5)) + if (set & (1 << 5)) stream << "%R5-"; - if(Set&(1<<4)) + if (set & (1 << 4)) stream << "%R4-"; - if(Set&(1<<3)) + if (set & (1 << 3)) stream << "%R3-"; - if(Set&(1<<2)) + if (set & (1 << 2)) stream << "%R2-"; - if(Set&(1<<1)) + if (set & (1 << 1)) stream << "%R1-"; - if(Set&(1<<0)) + if (set & (1 << 0)) stream << "%R0-"; return 0; } INST(POP) { - uint32_t Set=EXTRACT(Opcode,0,10); - int Ret=0; + u32 set = EXTRACT(opcode, 0, 10); + int ret = 0; stream << "POP "; - if(Set&(1<<0)) + if (set & (1 << 0)) stream << "%R0-"; - if(Set&(1<<1)) + if (set & (1 << 1)) stream << "%R1-"; - if(Set&(1<<2)) + if (set & (1 << 2)) stream << "%R2-"; - if(Set&(1<<3)) + if (set & (1 << 3)) stream << "%R3-"; - if(Set&(1<<4)) + if (set & (1 << 4)) stream << "%R4-"; - if(Set&(1<<5)) + if (set & (1 << 5)) stream << "%R5-"; - if(Set&(1<<6)) + if (set & (1 << 6)) stream << "%R6-"; - if(Set&(1<<7)) + if (set & (1 << 7)) stream << "%R7-"; - if(Set&(1<<8)) + if (set & (1 << 8)) stream << "%ER-"; - if(Set&(1<<9)) + if (set & (1 << 9)) stream << "%SR-"; - if(Set&(1<<10)) + if (set & (1 << 10)) { stream << "%PC-"; CLRFLAG(FLAG_E); //Clear the flag, this is a ret so disassemble will start a new E block - Ret=1; + ret = 1; } - return Ret ? STEP_OUT : 0; + return ret ? STEP_OUT : 0; } INST(LEATOSP) { - uint32_t Offset=EXTRACT(Opcode,9,12); - uint32_t Index=EXTRACT(Opcode,3,5); + u32 offset = EXTRACT(opcode, 9, 12); + const u32 index = EXTRACT(opcode, 3, 5); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); else - Offset=SEX(4,Offset); + offset = SEXT(4, offset); - if(Index) - util::stream_format(stream, "LEA (%%R%d,0x%x),%%SP",Index,Offset); + if (index) + util::stream_format(stream, "LEA (%%R%d,0x%x),%%SP", index, offset); else - util::stream_format(stream, "LEA (0x%x),%%SP",Index+Offset); + util::stream_format(stream, "LEA (0x%x),%%SP", index + offset); CLRFLAG(FLAG_E); return 0; @@ -313,15 +313,15 @@ INST(LEATOSP) INST(LEAFROMSP) { - uint32_t Offset=EXTRACT(Opcode,9,12); - uint32_t Index=EXTRACT(Opcode,3,5); + u32 offset = EXTRACT(opcode, 9, 12); + const u32 index = EXTRACT(opcode, 3, 5); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); else - Offset=SEX(4,Offset); + offset = SEXT(4, offset); - util::stream_format(stream, "LEA (%%SP,0x%x),%%R%d",Offset,Index); + util::stream_format(stream, "LEA (%%SP,0x%x),%%R%d", offset, index); CLRFLAG(FLAG_E); return 0; @@ -329,17 +329,17 @@ INST(LEAFROMSP) INST(LEASPTOSP) { - uint32_t Offset=EXTRACT(Opcode,0,7); + u32 offset = EXTRACT(opcode, 0, 7); - Offset<<=2; + offset <<= 2; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,23)<<8)|(Offset&0xff); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0,23) << 8) | (offset&0xff); else - Offset=SEX(10,Offset); + offset = SEXT(10, offset); - util::stream_format(stream, "LEA (%%SP,0x%x),%%SP",Offset); + util::stream_format(stream, "LEA (%%SP,0x%x),%%SP", offset); CLRFLAG(FLAG_E); return 0; @@ -347,27 +347,27 @@ INST(LEASPTOSP) INST(MOV) { - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,9,11); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 9, 11); - if(Src==0 && Dst==0) + if (src == 0 && dst == 0) util::stream_format(stream, "NOP"); else - util::stream_format(stream, "MOV %%SR%d,%%DR%d",Src,Dst); + util::stream_format(stream, "MOV %%SR%d,%%DR%d", src, dst); return 0; } INST(LDI) { - uint32_t Dst=EXTRACT(Opcode,8,10); - uint32_t Imm=EXTRACT(Opcode,0,7); + const u32 dst = EXTRACT(opcode, 8, 10); + u32 imm = EXTRACT(opcode, 0, 7); - if(TESTFLAG(FLAG_E)) - Imm=(EXTRACT(ER,0,27)<<4)|(Imm&0xf); + if (TESTFLAG(FLAG_E)) + imm = (EXTRACT(ER, 0, 27) << 4) | (imm & 0xf); else - Imm=SEX8(Imm); + imm = SEXT8(imm); - util::stream_format(stream, "LDI 0x%x,%%R%d",Imm,Dst); + util::stream_format(stream, "LDI 0x%x,%%R%d", imm, dst); CLRFLAG(FLAG_E); return 0; @@ -375,13 +375,13 @@ INST(LDI) INST(LDBSP) { - uint32_t Offset=EXTRACT(Opcode,0,3); - uint32_t SrcDst=EXTRACT(Opcode,4,6); + u32 offset = EXTRACT(opcode, 0, 3); + const u32 src_dst = EXTRACT(opcode, 4, 6); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "LDB (%%SP,0x%x),%%R%d",Offset,SrcDst); + util::stream_format(stream, "LDB (%%SP,0x%x),%%R%d", offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -389,13 +389,13 @@ INST(LDBSP) INST(STBSP) { - uint32_t Offset=EXTRACT(Opcode,0,3); - uint32_t SrcDst=EXTRACT(Opcode,4,6); + u32 offset = EXTRACT(opcode, 0, 3); + const u32 src_dst = EXTRACT(opcode, 4, 6); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "STB %%R%d,(%%SP,0x%x)",SrcDst,Offset); + util::stream_format(stream, "STB %%R%d,(%%SP,0x%x)", src_dst, offset); CLRFLAG(FLAG_E); return 0; @@ -403,15 +403,15 @@ INST(STBSP) INST(LDSSP) { - uint32_t Offset=EXTRACT(Opcode,0,3); - uint32_t SrcDst=EXTRACT(Opcode,4,6); + u32 offset = EXTRACT(opcode, 0, 3); + const u32 src_dst = EXTRACT(opcode, 4, 6); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "LDS (%%SP,0x%x),%%R%d",Offset,SrcDst); + util::stream_format(stream, "LDS (%%SP,0x%x),%%R%d", offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -419,15 +419,15 @@ INST(LDSSP) INST(STSSP) { - uint32_t Offset=EXTRACT(Opcode,0,3); - uint32_t SrcDst=EXTRACT(Opcode,4,6); + u32 offset = EXTRACT(opcode, 0, 3); + const u32 src_dst = EXTRACT(opcode, 4, 6); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "STS %%R%d,(%%SP,0x%x)",SrcDst,Offset); + util::stream_format(stream, "STS %%R%d,(%%SP,0x%x)", src_dst, offset); CLRFLAG(FLAG_E); return 0; @@ -435,13 +435,13 @@ INST(STSSP) INST(LDBUSP) { - uint32_t Offset=EXTRACT(Opcode,0,3); - uint32_t SrcDst=EXTRACT(Opcode,4,6); + u32 offset = EXTRACT(opcode, 0, 3); + const u32 src_dst = EXTRACT(opcode, 4, 6); - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "LDBU (%%SP,0x%x),%%R%d",Offset,SrcDst); + util::stream_format(stream, "LDBU (%%SP,0x%x),%%R%d", offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -449,15 +449,15 @@ INST(LDBUSP) INST(LDSUSP) { - uint32_t Offset=EXTRACT(Opcode,0,3); - uint32_t SrcDst=EXTRACT(Opcode,4,6); + u32 offset = EXTRACT(opcode, 0, 3); + const u32 src_dst = EXTRACT(opcode, 4, 6); - Offset<<=1; + offset <<= 1; - if(TESTFLAG(FLAG_E)) - Offset=(EXTRACT(ER,0,27)<<4)|(Offset&0xf); + if (TESTFLAG(FLAG_E)) + offset = (EXTRACT(ER, 0, 27) << 4) | (offset & 0xf); - util::stream_format(stream, "LDSU (%%SP,0x%x),%%R%d",Offset,SrcDst); + util::stream_format(stream, "LDSU (%%SP,0x%x),%%R%d", offset, src_dst); CLRFLAG(FLAG_E); return 0; @@ -465,17 +465,17 @@ INST(LDSUSP) INST(ADDI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "ADD %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "ADD %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -483,17 +483,17 @@ INST(ADDI) INST(SUBI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "SUB %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "SUB %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); @@ -502,17 +502,17 @@ INST(SUBI) INST(ADCI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "ADC %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "ADC %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -520,17 +520,17 @@ INST(ADCI) INST(SBCI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "SBC %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "SBC %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -538,17 +538,17 @@ INST(SBCI) INST(ANDI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "AND %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "AND %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -556,17 +556,17 @@ INST(ANDI) INST(ORI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "OR %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "OR %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -574,17 +574,17 @@ INST(ORI) INST(XORI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "XOR %%SR%d,0x%x,%%DR%d",Src,Imm2,Dst/*,Imm2*/); + util::stream_format(stream, "XOR %%SR%d,0x%x,%%DR%d", src, imm2, dst/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -592,16 +592,16 @@ INST(XORI) INST(CMPI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "CMP %%SR%d,0x%x",Src,Imm2/*,Imm2*/); + util::stream_format(stream, "CMP %%SR%d,0x%x", src, imm2/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -609,16 +609,16 @@ INST(CMPI) INST(TSTI) { - uint32_t Imm=EXTRACT(Opcode,9,12); - uint32_t Src=EXTRACT(Opcode,3,5); - uint32_t Imm2=Imm; + const u32 imm = EXTRACT(opcode, 9, 12); + const u32 src = EXTRACT(opcode, 3, 5); + u32 imm2 = imm; - if(TESTFLAG(FLAG_E)) - Imm2=(EXTRACT(ER,0,27)<<4)|(Imm2&0xf); + if (TESTFLAG(FLAG_E)) + imm2 = (EXTRACT(ER, 0, 27) << 4) | (imm2 & 0xf); else - Imm2=SEX(4,Imm2); + imm2 = SEXT(4, imm2); - util::stream_format(stream, "TST %%SR%d,0x%x",Src,Imm2/*,Imm2*/); + util::stream_format(stream, "TST %%SR%d,0x%x", src, imm2/*, imm2*/); CLRFLAG(FLAG_E); return 0; @@ -626,99 +626,99 @@ INST(TSTI) INST(ADD) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "ADD %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "ADD %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(SUB) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "SUB %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "SUB %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(ADC) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "ADC %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "ADC %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(SBC) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "SBC %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "SBC %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(AND) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "AND %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "AND %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(OR) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "OR %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "OR %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(XOR) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "XOR %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "XOR %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); return 0; } INST(CMP) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); - util::stream_format(stream, "CMP %%SR%d,%%SR%d",Src1,Src2); + util::stream_format(stream, "CMP %%SR%d,%%SR%d", src1, src2); return 0; } INST(TST) { - uint32_t Src2=EXTRACT(Opcode,9,11); - uint32_t Src1=EXTRACT(Opcode,3,5); + const u32 src2 = EXTRACT(opcode, 9, 11); + const u32 src1 = EXTRACT(opcode, 3, 5); - util::stream_format(stream, "TST %%SR%d,%%SR%d",Src1,Src2); + util::stream_format(stream, "TST %%SR%d,%%SR%d", src1, src2); return 0; } INST(MULS) { - uint32_t Src2=EXTRACT(Opcode,6,8); - uint32_t Src1=EXTRACT(Opcode,3,5); - uint32_t Dst=EXTRACT(Opcode,0,2); + const u32 src2 = EXTRACT(opcode, 6, 8); + const u32 src1 = EXTRACT(opcode, 3, 5); + const u32 dst = EXTRACT(opcode, 0, 2); - util::stream_format(stream, "MUL %%SR%d,%%SR%d,%%DR%d",Src1,Src2,Dst); + util::stream_format(stream, "MUL %%SR%d,%%SR%d,%%DR%d", src1, src2, dst); CLRFLAG(FLAG_E); return 0; @@ -726,24 +726,24 @@ INST(MULS) INST(NEG) { - uint32_t Dst=EXTRACT(Opcode,9,11); - uint32_t Src=EXTRACT(Opcode,3,5); + const u32 dst = EXTRACT(opcode, 9, 11); + const u32 src = EXTRACT(opcode, 3, 5); - util::stream_format(stream, "NEG %%SR%d,%%DR%d",Src,Dst); + util::stream_format(stream, "NEG %%SR%d,%%DR%d", src, dst); return 0; } INST(CALL) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "CALL 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "CALL 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_OVER; @@ -751,15 +751,15 @@ INST(CALL) INST(JV) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JV 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JV 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -767,15 +767,15 @@ INST(JV) INST(JNV) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JNV 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JNV 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -783,15 +783,15 @@ INST(JNV) INST(JC) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JC 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JC 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -799,15 +799,15 @@ INST(JC) INST(JNC) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JNC 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JNC 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -815,15 +815,15 @@ INST(JNC) INST(JP) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JP 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JP 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -831,15 +831,15 @@ INST(JP) INST(JM) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JM 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JM 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -847,15 +847,15 @@ INST(JM) INST(JNZ) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JNZ 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JNZ 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -863,15 +863,15 @@ INST(JNZ) INST(JZ) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JZ 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JZ 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -879,15 +879,15 @@ INST(JZ) INST(JGE) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JGE 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JGE 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -895,15 +895,15 @@ INST(JGE) INST(JLE) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JLE 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JLE 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -911,15 +911,15 @@ INST(JLE) INST(JHI) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JHI 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JHI 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -927,15 +927,15 @@ INST(JHI) INST(JLS) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JLS 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JLS 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -943,15 +943,15 @@ INST(JLS) INST(JGT) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JGT 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JGT 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; @@ -959,33 +959,31 @@ INST(JGT) INST(JLT) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JLT 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JLT 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return STEP_COND; } - - INST(JMP) { - uint32_t Offset=EXTRACT(Opcode,0,7); - uint32_t Offset2; + const u32 offset = EXTRACT(opcode, 0, 7); + u32 offset2; - if(TESTFLAG(FLAG_E)) - Offset2=(EXTRACT(ER,0,22)<<8)|Offset; + if (TESTFLAG(FLAG_E)) + offset2 = (EXTRACT(ER, 0, 22) << 8) | offset; else - Offset2=SEX(8,Offset); - Offset2<<=1; - util::stream_format(stream, "JMP 0x%x",PC+2+Offset2); + offset2 = SEXT(8, offset); + offset2 <<= 1; + util::stream_format(stream, "JMP 0x%x", PC + 2 + offset2); CLRFLAG(FLAG_E); return 0; @@ -993,9 +991,9 @@ INST(JMP) INST(JR) { - uint32_t Src=EXTRACT(Opcode,0,3); + const u32 src = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "JR %%R%d",Src); + util::stream_format(stream, "JR %%R%d", src); CLRFLAG(FLAG_E); return 0; @@ -1003,9 +1001,9 @@ INST(JR) INST(CALLR) { - uint32_t Src=EXTRACT(Opcode,0,3); + const u32 src = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "CALLR %%R%d",Src); + util::stream_format(stream, "CALLR %%R%d", src); CLRFLAG(FLAG_E); return STEP_OVER; @@ -1013,15 +1011,15 @@ INST(CALLR) INST(ASR) { - uint32_t CS=Opcode&(1<<10); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm=EXTRACT(Opcode,5,9); - uint32_t Cnt=EXTRACT(Opcode,5,7); + const u32 cs = opcode & (1 << 10); + const u32 dst = EXTRACT(opcode, 0, 2); + const u32 imm = EXTRACT(opcode, 5, 9); + const u32 cnt = EXTRACT(opcode, 5, 7); - if(CS) - util::stream_format(stream, "ASR %%R%d,%%R%d",Cnt,Dst); + if (cs) + util::stream_format(stream, "ASR %%R%d,%%R%d", cnt, dst); else - util::stream_format(stream, "ASR %x,%%R%d",Imm,Dst); + util::stream_format(stream, "ASR %x,%%R%d", imm, dst); CLRFLAG(FLAG_E); return 0; @@ -1029,15 +1027,15 @@ INST(ASR) INST(LSR) { - uint32_t CS=Opcode&(1<<10); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm=EXTRACT(Opcode,5,9); - uint32_t Cnt=EXTRACT(Opcode,5,7); + const u32 cs = opcode & (1 << 10); + const u32 dst = EXTRACT(opcode, 0, 2); + const u32 imm = EXTRACT(opcode, 5, 9); + const u32 cnt = EXTRACT(opcode, 5, 7); - if(CS) - util::stream_format(stream, "LSR %%R%d,%%R%d",Cnt,Dst); + if (cs) + util::stream_format(stream, "LSR %%R%d,%%R%d", cnt, dst); else - util::stream_format(stream, "LSR %x,%%R%d",Imm,Dst); + util::stream_format(stream, "LSR %x,%%R%d", imm, dst); CLRFLAG(FLAG_E); return 0; @@ -1045,15 +1043,15 @@ INST(LSR) INST(ASL) { - uint32_t CS=Opcode&(1<<10); - uint32_t Dst=EXTRACT(Opcode,0,2); - uint32_t Imm=EXTRACT(Opcode,5,9); - uint32_t Cnt=EXTRACT(Opcode,5,7); + const u32 cs = opcode & (1 << 10); + const u32 dst = EXTRACT(opcode, 0, 2); + const u32 imm = EXTRACT(opcode, 5, 9); + const u32 cnt = EXTRACT(opcode, 5, 7); - if(CS) - util::stream_format(stream, "ASL %%R%d,%%R%d",Cnt,Dst); + if (cs) + util::stream_format(stream, "ASL %%R%d,%%R%d", cnt, dst); else - util::stream_format(stream, "ASL %x,%%R%d",Imm,Dst); + util::stream_format(stream, "ASL %x,%%R%d", imm, dst); CLRFLAG(FLAG_E); return 0; @@ -1061,9 +1059,9 @@ INST(ASL) INST(EXTB) { - uint32_t Dst=EXTRACT(Opcode,0,3); + const u32 dst = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "EXTB %%R%d",Dst); + util::stream_format(stream, "EXTB %%R%d", dst); CLRFLAG(FLAG_E); return 0; @@ -1071,9 +1069,9 @@ INST(EXTB) INST(EXTS) { - uint32_t Dst=EXTRACT(Opcode,0,3); + const u32 dst = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "EXTS %%R%d",Dst); + util::stream_format(stream, "EXTS %%R%d", dst); CLRFLAG(FLAG_E); return 0; @@ -1081,60 +1079,60 @@ INST(EXTS) INST(SET) { - uint32_t Imm=EXTRACT(Opcode,0,3); + const u32 imm = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "SET 0x%x",Imm); + util::stream_format(stream, "SET 0x%x", imm); return 0; } INST(CLR) { - uint32_t Imm=EXTRACT(Opcode,0,3); + const u32 imm = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "CLR 0x%x",Imm); + util::stream_format(stream, "CLR 0x%x", imm); return 0; } INST(SWI) { - uint32_t Imm=EXTRACT(Opcode,0,3); + const u32 imm = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "SWI 0x%x",Imm); + util::stream_format(stream, "SWI 0x%x", imm); return 0; } INST(HALT) { - uint32_t Imm=EXTRACT(Opcode,0,3); + const u32 imm = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "HALT 0x%x",Imm); + util::stream_format(stream, "HALT 0x%x", imm); return 0; } INST(MVTC) { - uint32_t Imm=EXTRACT(Opcode,0,3); + const u32 imm = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "MVTC %%R0,%%CR%d",Imm); + util::stream_format(stream, "MVTC %%R0,%%CR%d", imm); return 0; } INST(MVFC) { - uint32_t Imm=EXTRACT(Opcode,0,3); + const u32 imm = EXTRACT(opcode, 0, 3); - util::stream_format(stream, "MVFC %%CR0%d,%%R0",Imm); + util::stream_format(stream, "MVFC %%CR0%d,%%R0", imm); return 0; } -se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) +se3208_disassembler::_OP se3208_disassembler::decode_op(u16 opcode) { - switch(EXTRACT(Opcode,14,15)) + switch (EXTRACT(opcode, 14, 15)) { case 0x0: { - uint8_t Op=EXTRACT(Opcode,11,13); - switch(Op) + const u8 op = EXTRACT(opcode, 11, 13); + switch (op) { case 0x0: return &se3208_disassembler::LDB; @@ -1159,7 +1157,7 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) return &se3208_disassembler::LERI; case 0x2: { - switch(EXTRACT(Opcode,11,13)) + switch (EXTRACT(opcode, 11, 13)) { case 0: return &se3208_disassembler::LDSP; @@ -1181,7 +1179,7 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) case 13: case 14: case 15: - switch(EXTRACT(Opcode,6,8)) + switch (EXTRACT(opcode, 6, 8)) { case 0: return &se3208_disassembler::ADDI; @@ -1198,7 +1196,7 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) case 6: return &se3208_disassembler::XORI; case 7: - switch(EXTRACT(Opcode,0,2)) + switch (EXTRACT(opcode, 0, 2)) { case 0: return &se3208_disassembler::CMPI; @@ -1216,10 +1214,10 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) } break; case 3: - switch(EXTRACT(Opcode,12,13)) + switch (EXTRACT(opcode, 12, 13)) { case 0: - switch(EXTRACT(Opcode,6,8)) + switch (EXTRACT(opcode, 6, 8)) { case 0: return &se3208_disassembler::ADD; @@ -1236,7 +1234,7 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) case 6: return &se3208_disassembler::XOR; case 7: - switch(EXTRACT(Opcode,0,2)) + switch (EXTRACT(opcode, 0, 2)) { case 0: return &se3208_disassembler::CMP; @@ -1251,7 +1249,7 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) } break; case 1: //Jumps - switch(EXTRACT(Opcode,8,11)) + switch (EXTRACT(opcode, 8, 11)) { case 0x0: return &se3208_disassembler::JNV; @@ -1288,13 +1286,13 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) } break; case 2: - if(Opcode&(1<<11)) + if (opcode & (1 << 11)) return &se3208_disassembler::LDI; else //SP Ops { - if(Opcode&(1<<10)) + if (opcode & (1 << 10)) { - switch(EXTRACT(Opcode,7,9)) + switch (EXTRACT(opcode, 7, 9)) { case 0: return &se3208_disassembler::LDBSP; @@ -1312,18 +1310,18 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) } else { - if(Opcode&(1<<9)) + if (opcode & (1 << 9)) { return &se3208_disassembler::LEASPTOSP; } else { - if(Opcode&(1<<8)) + if (opcode & (1 << 8)) { } else { - switch(EXTRACT(Opcode,4,7)) + switch (EXTRACT(opcode, 4, 7)) { case 0: return &se3208_disassembler::EXTB; @@ -1348,13 +1346,13 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) } break; case 3: - switch(EXTRACT(Opcode,9,11)) + switch (EXTRACT(opcode, 9, 11)) { case 0: case 1: case 2: case 3: - switch(EXTRACT(Opcode,3,4)) + switch (EXTRACT(opcode, 3, 4)) { case 0: return &se3208_disassembler::ASR; @@ -1369,7 +1367,7 @@ se3208_disassembler::_OP se3208_disassembler::DecodeOp(uint16_t Opcode) case 4: return &se3208_disassembler::MULS; case 6: - if(Opcode&(1<<3)) + if (opcode & (1 << 3)) return &se3208_disassembler::MVFC; else return &se3208_disassembler::MVTC; @@ -1390,12 +1388,10 @@ u32 se3208_disassembler::opcode_alignment() const offs_t se3208_disassembler::disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer ¶ms) { - uint16_t Opcode; - CLRFLAG(FLAG_E); - ER=0; + ER = 0; - PC=pc; - Opcode=opcodes.r16(pc); - return 2 | ((this->*DecodeOp(Opcode))(Opcode, stream)) | SUPPORTED; + PC = pc; + const u16 opcode = opcodes.r16(pc); + return 2 | ((this->*decode_op(opcode))(opcode, stream)) | SUPPORTED; } diff --git a/src/devices/cpu/se3208/se3208dis.h b/src/devices/cpu/se3208/se3208dis.h index ffe66c602c75a..7a5ddf142e8e4 100644 --- a/src/devices/cpu/se3208/se3208dis.h +++ b/src/devices/cpu/se3208/se3208dis.h @@ -16,88 +16,88 @@ class se3208_disassembler : public util::disasm_interface virtual offs_t disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer ¶ms) override; private: - typedef uint32_t (se3208_disassembler::*_OP)(uint16_t Opcode, std::ostream &stream); + typedef u32 (se3208_disassembler::*_OP)(u16 opcode, std::ostream &stream); - uint32_t INVALIDOP(uint16_t Opcode, std::ostream &stream); - uint32_t LDB(uint16_t Opcode, std::ostream &stream); - uint32_t STB(uint16_t Opcode, std::ostream &stream); - uint32_t LDS(uint16_t Opcode, std::ostream &stream); - uint32_t STS(uint16_t Opcode, std::ostream &stream); - uint32_t LD(uint16_t Opcode, std::ostream &stream); - uint32_t ST(uint16_t Opcode, std::ostream &stream); - uint32_t LDBU(uint16_t Opcode, std::ostream &stream); - uint32_t LDSU(uint16_t Opcode, std::ostream &stream); - uint32_t LERI(uint16_t Opcode, std::ostream &stream); - uint32_t LDSP(uint16_t Opcode, std::ostream &stream); - uint32_t STSP(uint16_t Opcode, std::ostream &stream); - uint32_t PUSH(uint16_t Opcode, std::ostream &stream); - uint32_t POP(uint16_t Opcode, std::ostream &stream); - uint32_t LEATOSP(uint16_t Opcode, std::ostream &stream); - uint32_t LEAFROMSP(uint16_t Opcode, std::ostream &stream); - uint32_t LEASPTOSP(uint16_t Opcode, std::ostream &stream); - uint32_t MOV(uint16_t Opcode, std::ostream &stream); - uint32_t LDI(uint16_t Opcode, std::ostream &stream); - uint32_t LDBSP(uint16_t Opcode, std::ostream &stream); - uint32_t STBSP(uint16_t Opcode, std::ostream &stream); - uint32_t LDSSP(uint16_t Opcode, std::ostream &stream); - uint32_t STSSP(uint16_t Opcode, std::ostream &stream); - uint32_t LDBUSP(uint16_t Opcode, std::ostream &stream); - uint32_t LDSUSP(uint16_t Opcode, std::ostream &stream); - uint32_t ADDI(uint16_t Opcode, std::ostream &stream); - uint32_t SUBI(uint16_t Opcode, std::ostream &stream); - uint32_t ADCI(uint16_t Opcode, std::ostream &stream); - uint32_t SBCI(uint16_t Opcode, std::ostream &stream); - uint32_t ANDI(uint16_t Opcode, std::ostream &stream); - uint32_t ORI(uint16_t Opcode, std::ostream &stream); - uint32_t XORI(uint16_t Opcode, std::ostream &stream); - uint32_t CMPI(uint16_t Opcode, std::ostream &stream); - uint32_t TSTI(uint16_t Opcode, std::ostream &stream); - uint32_t ADD(uint16_t Opcode, std::ostream &stream); - uint32_t SUB(uint16_t Opcode, std::ostream &stream); - uint32_t ADC(uint16_t Opcode, std::ostream &stream); - uint32_t SBC(uint16_t Opcode, std::ostream &stream); - uint32_t AND(uint16_t Opcode, std::ostream &stream); - uint32_t OR(uint16_t Opcode, std::ostream &stream); - uint32_t XOR(uint16_t Opcode, std::ostream &stream); - uint32_t CMP(uint16_t Opcode, std::ostream &stream); - uint32_t TST(uint16_t Opcode, std::ostream &stream); - uint32_t MULS(uint16_t Opcode, std::ostream &stream); - uint32_t NEG(uint16_t Opcode, std::ostream &stream); - uint32_t CALL(uint16_t Opcode, std::ostream &stream); - uint32_t JV(uint16_t Opcode, std::ostream &stream); - uint32_t JNV(uint16_t Opcode, std::ostream &stream); - uint32_t JC(uint16_t Opcode, std::ostream &stream); - uint32_t JNC(uint16_t Opcode, std::ostream &stream); - uint32_t JP(uint16_t Opcode, std::ostream &stream); - uint32_t JM(uint16_t Opcode, std::ostream &stream); - uint32_t JNZ(uint16_t Opcode, std::ostream &stream); - uint32_t JZ(uint16_t Opcode, std::ostream &stream); - uint32_t JGE(uint16_t Opcode, std::ostream &stream); - uint32_t JLE(uint16_t Opcode, std::ostream &stream); - uint32_t JHI(uint16_t Opcode, std::ostream &stream); - uint32_t JLS(uint16_t Opcode, std::ostream &stream); - uint32_t JGT(uint16_t Opcode, std::ostream &stream); - uint32_t JLT(uint16_t Opcode, std::ostream &stream); - uint32_t JMP(uint16_t Opcode, std::ostream &stream); - uint32_t JR(uint16_t Opcode, std::ostream &stream); - uint32_t CALLR(uint16_t Opcode, std::ostream &stream); - uint32_t ASR(uint16_t Opcode, std::ostream &stream); - uint32_t LSR(uint16_t Opcode, std::ostream &stream); - uint32_t ASL(uint16_t Opcode, std::ostream &stream); - uint32_t EXTB(uint16_t Opcode, std::ostream &stream); - uint32_t EXTS(uint16_t Opcode, std::ostream &stream); - uint32_t SET(uint16_t Opcode, std::ostream &stream); - uint32_t CLR(uint16_t Opcode, std::ostream &stream); - uint32_t SWI(uint16_t Opcode, std::ostream &stream); - uint32_t HALT(uint16_t Opcode, std::ostream &stream); - uint32_t MVTC(uint16_t Opcode, std::ostream &stream); - uint32_t MVFC(uint16_t Opcode, std::ostream &stream); + u32 INVALIDOP(u16 opcode, std::ostream &stream); + u32 LDB(u16 opcode, std::ostream &stream); + u32 STB(u16 opcode, std::ostream &stream); + u32 LDS(u16 opcode, std::ostream &stream); + u32 STS(u16 opcode, std::ostream &stream); + u32 LD(u16 opcode, std::ostream &stream); + u32 ST(u16 opcode, std::ostream &stream); + u32 LDBU(u16 opcode, std::ostream &stream); + u32 LDSU(u16 opcode, std::ostream &stream); + u32 LERI(u16 opcode, std::ostream &stream); + u32 LDSP(u16 opcode, std::ostream &stream); + u32 STSP(u16 opcode, std::ostream &stream); + u32 PUSH(u16 opcode, std::ostream &stream); + u32 POP(u16 opcode, std::ostream &stream); + u32 LEATOSP(u16 opcode, std::ostream &stream); + u32 LEAFROMSP(u16 opcode, std::ostream &stream); + u32 LEASPTOSP(u16 opcode, std::ostream &stream); + u32 MOV(u16 opcode, std::ostream &stream); + u32 LDI(u16 opcode, std::ostream &stream); + u32 LDBSP(u16 opcode, std::ostream &stream); + u32 STBSP(u16 opcode, std::ostream &stream); + u32 LDSSP(u16 opcode, std::ostream &stream); + u32 STSSP(u16 opcode, std::ostream &stream); + u32 LDBUSP(u16 opcode, std::ostream &stream); + u32 LDSUSP(u16 opcode, std::ostream &stream); + u32 ADDI(u16 opcode, std::ostream &stream); + u32 SUBI(u16 opcode, std::ostream &stream); + u32 ADCI(u16 opcode, std::ostream &stream); + u32 SBCI(u16 opcode, std::ostream &stream); + u32 ANDI(u16 opcode, std::ostream &stream); + u32 ORI(u16 opcode, std::ostream &stream); + u32 XORI(u16 opcode, std::ostream &stream); + u32 CMPI(u16 opcode, std::ostream &stream); + u32 TSTI(u16 opcode, std::ostream &stream); + u32 ADD(u16 opcode, std::ostream &stream); + u32 SUB(u16 opcode, std::ostream &stream); + u32 ADC(u16 opcode, std::ostream &stream); + u32 SBC(u16 opcode, std::ostream &stream); + u32 AND(u16 opcode, std::ostream &stream); + u32 OR(u16 opcode, std::ostream &stream); + u32 XOR(u16 opcode, std::ostream &stream); + u32 CMP(u16 opcode, std::ostream &stream); + u32 TST(u16 opcode, std::ostream &stream); + u32 MULS(u16 opcode, std::ostream &stream); + u32 NEG(u16 opcode, std::ostream &stream); + u32 CALL(u16 opcode, std::ostream &stream); + u32 JV(u16 opcode, std::ostream &stream); + u32 JNV(u16 opcode, std::ostream &stream); + u32 JC(u16 opcode, std::ostream &stream); + u32 JNC(u16 opcode, std::ostream &stream); + u32 JP(u16 opcode, std::ostream &stream); + u32 JM(u16 opcode, std::ostream &stream); + u32 JNZ(u16 opcode, std::ostream &stream); + u32 JZ(u16 opcode, std::ostream &stream); + u32 JGE(u16 opcode, std::ostream &stream); + u32 JLE(u16 opcode, std::ostream &stream); + u32 JHI(u16 opcode, std::ostream &stream); + u32 JLS(u16 opcode, std::ostream &stream); + u32 JGT(u16 opcode, std::ostream &stream); + u32 JLT(u16 opcode, std::ostream &stream); + u32 JMP(u16 opcode, std::ostream &stream); + u32 JR(u16 opcode, std::ostream &stream); + u32 CALLR(u16 opcode, std::ostream &stream); + u32 ASR(u16 opcode, std::ostream &stream); + u32 LSR(u16 opcode, std::ostream &stream); + u32 ASL(u16 opcode, std::ostream &stream); + u32 EXTB(u16 opcode, std::ostream &stream); + u32 EXTS(u16 opcode, std::ostream &stream); + u32 SET(u16 opcode, std::ostream &stream); + u32 CLR(u16 opcode, std::ostream &stream); + u32 SWI(u16 opcode, std::ostream &stream); + u32 HALT(u16 opcode, std::ostream &stream); + u32 MVTC(u16 opcode, std::ostream &stream); + u32 MVFC(u16 opcode, std::ostream &stream); - _OP DecodeOp(uint16_t Opcode); + _OP decode_op(u16 opcode); - uint32_t PC; - uint32_t SR; - uint32_t ER; + u32 PC; + u32 SR; + u32 ER; }; #endif diff --git a/src/devices/machine/vr0uart.cpp b/src/devices/machine/vr0uart.cpp index 1bfbf0ebf3daf..b5c9190eb7d75 100644 --- a/src/devices/machine/vr0uart.cpp +++ b/src/devices/machine/vr0uart.cpp @@ -32,7 +32,7 @@ DEFINE_DEVICE_TYPE(VRENDER0_UART, vr0uart_device, "vr0uart", "MagicEyes VRender0 // vr0uart_device - constructor //------------------------------------------------- -vr0uart_device::vr0uart_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +vr0uart_device::vr0uart_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, VRENDER0_UART, tag, owner, clock), device_serial_interface(mconfig, *this) { @@ -71,32 +71,32 @@ void vr0uart_device::device_reset() update_serial_config(); } -inline void vr0uart_device::tx_send_byte(uint8_t val) +inline void vr0uart_device::tx_send_byte(u8 val) { transmit_register_setup(val); m_ustat |= 0x20; } -inline uint32_t vr0uart_device::calculate_baud_rate() +inline u32 vr0uart_device::calculate_baud_rate() { - uint32_t div_rate = ((m_ubdr & 0xffff) + 1) * 16; + const u32 div_rate = ((m_ubdr & 0xffff) + 1) * 16; // TODO: external / internal serial clock config return (this->clock() / 2) / div_rate; } void vr0uart_device::update_serial_config() { - const parity_t parity_modes[4] = { PARITY_NONE, PARITY_NONE, PARITY_EVEN, PARITY_ODD }; + static const parity_t parity_modes[4] = { PARITY_NONE, PARITY_NONE, PARITY_EVEN, PARITY_ODD }; - uint8_t word_length = m_ucon & 1 ? 8 : 7; - parity_t parity_mode = parity_modes[(m_ucon & 0xc) >> 2]; - stop_bits_t stop_bits = m_ucon & 2 ? STOP_BITS_2 : STOP_BITS_1; + const u8 word_length = BIT(m_ucon, 0) ? 8 : 7; + const parity_t parity_mode = parity_modes[(m_ucon & 0xc) >> 2]; + const stop_bits_t stop_bits = BIT(m_ucon, 1) ? STOP_BITS_2 : STOP_BITS_1; set_data_frame(1, word_length, parity_mode, stop_bits); - if (m_ucon & 0x100) // UART Enable + if (BIT(m_ucon, 8)) // UART Enable { - uint32_t clock_rate = calculate_baud_rate(); + const u32 clock_rate = calculate_baud_rate(); set_rcv_rate(clock_rate); set_tra_rate(clock_rate); } @@ -109,7 +109,7 @@ void vr0uart_device::update_serial_config() void vr0uart_device::tra_callback() { - int bit = transmit_register_get_data_bit(); + const int bit = transmit_register_get_data_bit(); m_ustat |= 0x40; m_parent->write_line_tx(m_channel_num, bit); } @@ -117,7 +117,7 @@ void vr0uart_device::tra_callback() void vr0uart_device::tra_complete() { m_ustat &= ~0x60; - m_parent->IntReq(m_channel_num ? 18 : 15); + m_parent->int_req(m_channel_num ? 18 : 15); } void vr0uart_device::rcv_complete() @@ -136,10 +136,10 @@ void vr0uart_device::rcv_complete() else m_ustat |= 1; // overrun - if (m_ucon & 0x20 && m_ustat & 0xf) - m_parent->IntReq(m_channel_num ? 16 : 13); + if (BIT(m_ucon, 5) && m_ustat & 0xf) + m_parent->int_req(m_channel_num ? 16 : 13); else - m_parent->IntReq(m_channel_num ? 17 : 14); + m_parent->int_req(m_channel_num ? 17 : 14); } @@ -157,12 +157,12 @@ void vr0uart_device::rcv_complete() * ---- ---- --x- Stop Bits (1=2 bits, 0=1 Bit) * ---- ---- ---x Word Length (1=8 bits, 0=7 bits) */ -uint32_t vr0uart_device::control_r() +u32 vr0uart_device::control_r() { return m_ucon; } -void vr0uart_device::control_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vr0uart_device::control_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_ucon); update_serial_config(); @@ -178,42 +178,43 @@ void vr0uart_device::control_w(offs_t offset, uint32_t data, uint32_t mem_mask) * ---- ---- --x- Parity error * ---- ---- ---x Overrun Error */ -uint32_t vr0uart_device::status_r() +u32 vr0uart_device::status_r() { - uint32_t res = m_ustat; + u32 res = m_ustat; if (!m_urxb_fifo.empty()) { res |= 0x10; res |= (m_urxb_fifo.queue_length() << 8); } // Break detect and errors are cleared by reading this - m_ustat &= ~0xf; + if (!machine().side_effects_disabled()) + m_ustat &= ~0xf; return res; } -void vr0uart_device::transmit_buffer_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vr0uart_device::transmit_buffer_w(offs_t offset, u32 data, u32 mem_mask) { if (ACCESSING_BITS_0_7) tx_send_byte(data & 0xff); } -uint32_t vr0uart_device::receive_buffer_r(offs_t offset, uint32_t mem_mask) +u32 vr0uart_device::receive_buffer_r(offs_t offset, u32 mem_mask) { // TODO: unknown value & behaviour attempting to read this on empty FIFO (stall?) - uint8_t res = 0; + u8 res = 0; if (ACCESSING_BITS_0_7 && !m_urxb_fifo.empty()) - res = m_urxb_fifo.dequeue(); + res = m_urxb_fifo.dequeue(!machine().side_effects_disabled()); return res; } -uint32_t vr0uart_device::baud_rate_div_r() +u32 vr0uart_device::baud_rate_div_r() { return m_ubdr; } -void vr0uart_device::baud_rate_div_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vr0uart_device::baud_rate_div_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_ubdr); update_serial_config(); diff --git a/src/devices/machine/vrender0.cpp b/src/devices/machine/vrender0.cpp index c01fed77823b8..b13611a608b03 100644 --- a/src/devices/machine/vrender0.cpp +++ b/src/devices/machine/vrender0.cpp @@ -36,7 +36,7 @@ DEFINE_DEVICE_TYPE(VRENDER0_SOC, vrender0soc_device, "vrender0", "MagicEyes VRen // vrender0soc_device - constructor //------------------------------------------------- -vrender0soc_device::vrender0soc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : +vrender0soc_device::vrender0soc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, VRENDER0_SOC, tag, owner, clock), device_mixer_interface(mconfig, *this), m_screen(*this, "screen"), @@ -46,6 +46,8 @@ vrender0soc_device::vrender0soc_device(const machine_config &mconfig, const char m_uart(*this, "uart%u", 0), m_crtcregs(*this, "crtcregs"), m_host_space(*this, finder_base::DUMMY_TAG, -1, 32), + m_textureram(*this, "textureram", 0x800000, ENDIANNESS_LITTLE), + m_frameram(*this, "frameram", 0x800000, ENDIANNESS_LITTLE), m_int_cb(*this), m_write_tx(*this) { @@ -135,6 +137,8 @@ void vrender0soc_device::device_add_mconfig(machine_config &config) // runs at double speed WRT the bus clock VIDEO_VRENDER0(config, m_vr0vid, DERIVED_CLOCK(1, 1)); + m_vr0vid->set_addrmap(vr0video_device::AS_TEXTURE, &vrender0soc_device::texture_map); + m_vr0vid->set_addrmap(vr0video_device::AS_FRAME, &vrender0soc_device::frame_map); PALETTE(config, m_palette, palette_device::RGB_565); @@ -153,18 +157,13 @@ void vrender0soc_device::device_add_mconfig(machine_config &config) void vrender0soc_device::device_start() { - m_textureram = make_unique_clear(0x00800000/2); - m_frameram = make_unique_clear(0x00800000/2); - - m_vr0vid->set_areas(m_textureram.get(), m_frameram.get()); - if (this->clock() == 0) - fatalerror("%s: bus clock not setup properly",this->tag()); + fatalerror("%s: bus clock not setup properly", machine().describe_context()); - m_Timer[0] = timer_alloc(FUNC(vrender0soc_device::Timercb<0>), this); - m_Timer[1] = timer_alloc(FUNC(vrender0soc_device::Timercb<1>), this); - m_Timer[2] = timer_alloc(FUNC(vrender0soc_device::Timercb<2>), this); - m_Timer[3] = timer_alloc(FUNC(vrender0soc_device::Timercb<3>), this); + m_timer[0] = timer_alloc(FUNC(vrender0soc_device::timer_cb<0>), this); + m_timer[1] = timer_alloc(FUNC(vrender0soc_device::timer_cb<1>), this); + m_timer[2] = timer_alloc(FUNC(vrender0soc_device::timer_cb<2>), this); + m_timer[3] = timer_alloc(FUNC(vrender0soc_device::timer_cb<3>), this); for (int i = 0; i < 2; i++) { @@ -173,23 +172,18 @@ void vrender0soc_device::device_start() } save_item(NAME(m_inten)); + save_item(NAME(m_int_high)); save_item(NAME(m_intst)); - save_item(NAME(m_IntHigh)); - save_pointer(NAME(m_timer_control), 4); - save_pointer(NAME(m_timer_count), 4); - save_item(NAME(m_dma[0].src)); - save_item(NAME(m_dma[0].dst)); - save_item(NAME(m_dma[0].size)); - save_item(NAME(m_dma[0].ctrl)); - - save_item(NAME(m_dma[1].ctrl)); - save_item(NAME(m_dma[1].src)); - save_item(NAME(m_dma[1].dst)); - save_item(NAME(m_dma[1].size)); + save_item(NAME(m_timer_control)); + save_item(NAME(m_timer_count)); + save_item(STRUCT_MEMBER(m_dma, src)); + save_item(STRUCT_MEMBER(m_dma, dst)); + save_item(STRUCT_MEMBER(m_dma, size)); + save_item(STRUCT_MEMBER(m_dma, ctrl)); } -void vrender0soc_device::write_line_tx(int port, uint8_t value) +void vrender0soc_device::write_line_tx(int port, u8 value) { //printf("callback %d %02x\n",port,value); m_write_tx[port & 1](value); @@ -207,7 +201,7 @@ void vrender0soc_device::device_reset() m_crtcregs[1] = 0x0000002a; //m_FlipCount = 0; - m_IntHigh = 0; + m_int_high = 0; m_dma[0].ctrl = 0; m_dma[1].ctrl = 0; @@ -215,7 +209,7 @@ void vrender0soc_device::device_reset() for (int i = 0; i < 4; i++) { m_timer_control[i] = 0xff << 8; - m_Timer[i]->adjust(attotime::never); + m_timer[i]->adjust(attotime::never); } } @@ -230,22 +224,22 @@ void vrender0soc_device::device_reset() * */ -uint16_t vrender0soc_device::textureram_r(offs_t offset) +u16 vrender0soc_device::textureram_r(offs_t offset) { return m_textureram[offset]; } -void vrender0soc_device::textureram_w(offs_t offset, uint16_t data, uint16_t mem_mask) +void vrender0soc_device::textureram_w(offs_t offset, u16 data, u16 mem_mask) { COMBINE_DATA(&m_textureram[offset]); } -uint16_t vrender0soc_device::frameram_r(offs_t offset) +u16 vrender0soc_device::frameram_r(offs_t offset) { return m_frameram[offset]; } -void vrender0soc_device::frameram_w(offs_t offset, uint16_t data, uint16_t mem_mask) +void vrender0soc_device::frameram_w(offs_t offset, u16 data, u16 mem_mask) { COMBINE_DATA(&m_frameram[offset]); } @@ -256,12 +250,12 @@ void vrender0soc_device::frameram_w(offs_t offset, uint16_t data, uint16_t mem_m * */ -uint32_t vrender0soc_device::intvec_r() +u32 vrender0soc_device::intvec_r() { - return (m_IntHigh & 7) << 8; + return (m_int_high & 7) << 8; } -void vrender0soc_device::intvec_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vrender0soc_device::intvec_w(offs_t offset, u32 data, u32 mem_mask) { if (ACCESSING_BITS_0_7) { @@ -270,15 +264,15 @@ void vrender0soc_device::intvec_w(offs_t offset, uint32_t data, uint32_t mem_mas m_int_cb(CLEAR_LINE); } if (ACCESSING_BITS_8_15) - m_IntHigh = (data >> 8) & 7; + m_int_high = (data >> 8) & 7; } -uint32_t vrender0soc_device::inten_r() +u32 vrender0soc_device::inten_r() { return m_inten; } -void vrender0soc_device::inten_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vrender0soc_device::inten_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_inten); // P'S Attack has a timer 0 irq service with no call to intvec_w but just this @@ -287,18 +281,18 @@ void vrender0soc_device::inten_w(offs_t offset, uint32_t data, uint32_t mem_mask m_int_cb(CLEAR_LINE); } -uint32_t vrender0soc_device::intst_r() +u32 vrender0soc_device::intst_r() { return m_intst; } -void vrender0soc_device::intst_w(uint32_t data) +void vrender0soc_device::intst_w(u32 data) { // TODO: contradicts with documentation, games writes to this? // ... } -void vrender0soc_device::IntReq( int num ) +void vrender0soc_device::int_req(int num) { if (m_inten & (1 << num)) { @@ -308,13 +302,13 @@ void vrender0soc_device::IntReq( int num ) } -uint8_t vrender0soc_device::irq_callback() +u8 vrender0soc_device::irq_callback() { for (int i = 0; i < 32; ++i) { if (BIT(m_intst, i)) { - return (m_IntHigh << 5) | i; + return (m_int_high << 5) | i; } } return 0; //This should never happen @@ -325,7 +319,7 @@ void vrender0soc_device::soundirq_cb(int state) { if (state) { - IntReq(2); + int_req(2); } } @@ -336,65 +330,65 @@ void vrender0soc_device::soundirq_cb(int state) */ -void vrender0soc_device::TimerStart(int which) +void vrender0soc_device::timer_start(int which) { - int PD = (m_timer_control[which] >> 8) & 0xff; - int TCV = m_timer_count[which] & 0xffff; + int const pd = (m_timer_control[which] >> 8) & 0xff; + int const tcv = m_timer_count[which] & 0xffff; // TODO: documentation claims this is bus clock, half the internal PLL frequency. - attotime period = attotime::from_hz(this->clock()) * 2 * ((PD + 1) * (TCV + 1)); - m_Timer[which]->adjust(period); + attotime const period = attotime::from_hz(this->clock()) * 2 * ((pd + 1) * (tcv + 1)); + m_timer[which]->adjust(period); -// printf("timer %d start, PD = %x TCV = %x period = %s\n", which, PD, TCV, period.as_string()); +// printf("timer %d start, pd = %x tcv = %x period = %s\n", which, pd, tcv, period.as_string()); } template -TIMER_CALLBACK_MEMBER(vrender0soc_device::Timercb) +TIMER_CALLBACK_MEMBER(vrender0soc_device::timer_cb) { static const int num[] = { 0, 1, 9, 10 }; if (m_timer_control[Which] & 2) - TimerStart(Which); + timer_start(Which); else m_timer_control[Which] &= ~1; - IntReq(num[Which]); + int_req(num[Which]); } template -uint32_t vrender0soc_device::tmcon_r() +u32 vrender0soc_device::tmcon_r() { return m_timer_control[Which]; } template -void vrender0soc_device::tmcon_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vrender0soc_device::tmcon_w(offs_t offset, u32 data, u32 mem_mask) { - uint32_t old = m_timer_control[Which]; + u32 const old = m_timer_control[Which]; data = COMBINE_DATA(&m_timer_control[Which]); if ((data ^ old) & 1) { if (data & 1) { - TimerStart(Which); + timer_start(Which); } else { // Timer stop - m_Timer[Which]->adjust(attotime::never); + m_timer[Which]->adjust(attotime::never); // printf("timer %d stop\n", Which); } } } template -uint16_t vrender0soc_device::tmcnt_r() +u16 vrender0soc_device::tmcnt_r() { return m_timer_count[Which] & 0xffff; } template -void vrender0soc_device::tmcnt_w(offs_t offset, uint16_t data, uint16_t mem_mask) +void vrender0soc_device::tmcnt_w(offs_t offset, u16 data, u16 mem_mask) { COMBINE_DATA(&m_timer_count[Which]); } @@ -409,61 +403,62 @@ void vrender0soc_device::tmcnt_w(offs_t offset, uint16_t data, uint16_t mem_mask // bit 5 and bit 3 of the DMA control don't increment source/destination addresses if enabled. // At the time of writing P's Attack is the only SW that uses this feature, // in a work RAM to area $4500000 transfer, probably to extend something ... -inline int vrender0soc_device::dma_setup_hold(uint8_t setting, uint8_t bitmask) +inline int vrender0soc_device::dma_setup_hold(u8 setting, u8 bitmask) { + // TODO: supports negative value return setting & bitmask ? 0 : (setting & 2) ? 4 : (1 << (setting & 1)); } -template uint32_t vrender0soc_device::dmasa_r() { return m_dma[Which].src; } -template void vrender0soc_device::dmasa_w(offs_t offset, uint32_t data, uint32_t mem_mask) { COMBINE_DATA(&m_dma[Which].src); } -template uint32_t vrender0soc_device::dmada_r() { return m_dma[Which].dst; } -template void vrender0soc_device::dmada_w(offs_t offset, uint32_t data, uint32_t mem_mask) { COMBINE_DATA(&m_dma[Which].dst); } -template uint32_t vrender0soc_device::dmatc_r() { return m_dma[Which].size; } -template void vrender0soc_device::dmatc_w(offs_t offset, uint32_t data, uint32_t mem_mask) { COMBINE_DATA(&m_dma[Which].size); } -template uint32_t vrender0soc_device::dmac_r() { return m_dma[Which].ctrl; } +template u32 vrender0soc_device::dmasa_r() { return m_dma[Which].src; } +template void vrender0soc_device::dmasa_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_dma[Which].src); } +template u32 vrender0soc_device::dmada_r() { return m_dma[Which].dst; } +template void vrender0soc_device::dmada_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_dma[Which].dst); } +template u32 vrender0soc_device::dmatc_r() { return m_dma[Which].size; } +template void vrender0soc_device::dmatc_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_dma[Which].size); } +template u32 vrender0soc_device::dmac_r() { return m_dma[Which].ctrl; } template -void vrender0soc_device::dmac_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vrender0soc_device::dmac_w(offs_t offset, u32 data, u32 mem_mask) { if (((data ^ m_dma[Which].ctrl) & (1 << 10)) && (data & (1 << 10))) //DMAOn { - uint32_t const CTR = data; - uint32_t const SRC = m_dma[Which].src; - uint32_t const DST = m_dma[Which].dst; - uint32_t const CNT = m_dma[Which].size; - const int src_inc = dma_setup_hold(CTR, 0x20); - const int dst_inc = dma_setup_hold(CTR, 0x08); + u32 const ctr = data; + u32 const src = m_dma[Which].src; + u32 const dst = m_dma[Which].dst; + u32 const cnt = m_dma[Which].size; + int const src_inc = dma_setup_hold(ctr, 0x20); + int const dst_inc = dma_setup_hold(ctr, 0x08); - if ((CTR & 0xd4) != 0) - popmessage("DMA%d with unhandled mode %02x, contact MAMEdev",Which,CTR); + if ((ctr & 0xd4) != 0) + popmessage("DMA%d with unhandled mode %02x, contact MAMEdev",Which,ctr); - if (CTR & 0x2) //32 bits + if (ctr & 0x2) //32 bits { - for (int i = 0; i < CNT; ++i) + for (int i = 0; i < cnt; ++i) { - uint32_t v = m_host_space->read_dword(SRC + i * src_inc); - m_host_space->write_dword(DST + i * dst_inc, v); + u32 const v = m_host_space->read_dword(src + i * src_inc); + m_host_space->write_dword(dst + i * dst_inc, v); } } - else if (CTR & 0x1) //16 bits + else if (ctr & 0x1) //16 bits { - for (int i = 0; i < CNT; ++i) + for (int i = 0; i < cnt; ++i) { - uint16_t v = m_host_space->read_word(SRC + i * src_inc); - m_host_space->write_word(DST + i * dst_inc, v); + u16 const v = m_host_space->read_word(src + i * src_inc); + m_host_space->write_word(dst + i * dst_inc, v); } } else //8 bits { - for (int i = 0; i < CNT; ++i) + for (int i = 0; i < cnt; ++i) { - uint8_t v = m_host_space->read_byte(SRC + i * src_inc); - m_host_space->write_byte(DST + i * dst_inc, v); + u8 const v = m_host_space->read_byte(src + i * src_inc); + m_host_space->write_byte(dst + i * dst_inc, v); } } data &= ~(1 << 10); // TODO: insta-DMA m_dma[Which].size = 0; - IntReq(7 + Which); + int_req(7 + Which); } COMBINE_DATA(&m_dma[Which].ctrl); } @@ -474,11 +469,11 @@ void vrender0soc_device::dmac_w(offs_t offset, uint32_t data, uint32_t mem_mask) * */ -uint32_t vrender0soc_device::crtc_r(offs_t offset) +u32 vrender0soc_device::crtc_r(offs_t offset) { - uint32_t res = m_crtcregs[offset]; - uint32_t hdisp = (m_crtcregs[0x0c / 4] + 1); - uint32_t vdisp = (m_crtcregs[0x1c / 4] + 1); + u32 res = m_crtcregs[offset]; + u32 const hdisp = (m_crtcregs[0x0c / 4] + 1); + u32 vdisp = (m_crtcregs[0x1c / 4] + 1); switch (offset) { case 0: // CRTC Status / Mode @@ -500,12 +495,12 @@ uint32_t vrender0soc_device::crtc_r(offs_t offset) return res; } -void vrender0soc_device::crtc_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void vrender0soc_device::crtc_w(offs_t offset, u32 data, u32 mem_mask) { if (((m_crtcregs[0] & 0x0100) == 0x0100) && (offset > 0) && (offset < 0x28/4)) // Write protect return; - uint32_t old = m_crtcregs[offset]; + u32 const old = m_crtcregs[offset]; switch (offset * 4) { case 0: // CRTC Status / Mode Register (CRTMOD) @@ -577,12 +572,12 @@ void vrender0soc_device::crtc_w(offs_t offset, uint32_t data, uint32_t mem_mask) inline bool vrender0soc_device::crt_is_interlaced() { - return (m_crtcregs[0x30 / 4] & 1) == 0; + return BIT(~m_crtcregs[0x30 / 4], 0); } bool vrender0soc_device::crt_active_vblank_irq() { - if (crt_is_interlaced() == false) + if (!crt_is_interlaced()) return true; // bit 3 of CRTC reg -> select display start even/odd fields @@ -591,18 +586,18 @@ bool vrender0soc_device::crt_active_vblank_irq() void vrender0soc_device::crtc_update() { - uint32_t hdisp = m_crtcregs[0x0c / 4] + 1; - uint32_t vdisp = m_crtcregs[0x1c / 4]; + u32 const hdisp = m_crtcregs[0x0c / 4] + 1; + u32 vdisp = m_crtcregs[0x1c / 4]; if (hdisp == 0 || vdisp == 0) return; - bool interlace_mode = crt_is_interlaced(); + bool const interlace_mode = crt_is_interlaced(); if (interlace_mode) vdisp <<= 1; - uint32_t htot = (m_crtcregs[0x20 / 4] & 0x3ff) + 1; - uint32_t vtot = (m_crtcregs[0x24 / 4] & 0x7ff); + u32 htot = (m_crtcregs[0x20 / 4] & 0x3ff) + 1; + u32 vtot = (m_crtcregs[0x24 / 4] & 0x7ff); // adjust htotal in case it's not setup by the game // (datasheet mentions that it can be done automatically shrug): @@ -612,20 +607,20 @@ void vrender0soc_device::crtc_update() // TODO: we may as well just ditch reading from HTOTAL and VTOTAL and use these instead if (htot <= 1 || htot <= hdisp) { - uint32_t hbp = (m_crtcregs[0x08 / 4] & 0xff00) >> 8; - uint32_t hsw = (m_crtcregs[0x08 / 4] & 0xff); - uint32_t hsfp = m_crtcregs[0x10 / 4] & 0xff; + u32 const hbp = (m_crtcregs[0x08 / 4] & 0xff00) >> 8; + u32 const hsw = (m_crtcregs[0x08 / 4] & 0xff); + u32 const hsfp = m_crtcregs[0x10 / 4] & 0xff; if (hbp == 0 && hsw == 0 && hsfp == 0) return; - htot = hdisp + (hbp+1) + (hsw+1) + (hsfp+1); + htot = hdisp + (hbp + 1) + (hsw + 1) + (hsfp + 1); m_crtcregs[0x20 / 4] = ((htot & 0x3ff) - 1); } // urachamu if (vtot == 0) { - uint32_t vbp = (m_crtcregs[0x08 / 4] & 0xff); + u32 const vbp = (m_crtcregs[0x08 / 4] & 0xff); if (vbp == 0) return; @@ -634,9 +629,9 @@ void vrender0soc_device::crtc_update() } // ext vclk set up by Sealy games in menghong.cpp - uint32_t pixel_clock = (BIT(m_crtcregs[0x04 / 4], 3)) ? 14318180 : m_ext_vclk; + u32 pixel_clock = (BIT(m_crtcregs[0x04 / 4], 3)) ? 14318180/* TODO: Input clock? */ : m_ext_vclk; if (pixel_clock == 0) - fatalerror("%s: Accessing external vclk in CRTC parameters, please set it up via setter in config\n",this->tag()); + fatalerror("%s: Accessing external vclk in CRTC parameters, please set it up via setter in config\n", machine().describe_context()); if (BIT(m_crtcregs[0x04 / 4], 7)) pixel_clock *= 2; @@ -648,7 +643,7 @@ void vrender0soc_device::crtc_update() //printf("CBCLK divider %d\n",((m_crtcregs[0x04 / 4] & 0x70) >> 4) + 1); //printf("ivclk speed %d\n",(m_crtcregs[0x04 / 4] & 0x80)); - if (interlace_mode == false) + if (!interlace_mode) { vtot >>= 1; vtot += 1; @@ -656,7 +651,6 @@ void vrender0soc_device::crtc_update() //else // pixel_clock >>= 1; - vtot += 9; //printf("%dX%d %dX%d %d\n",htot, vtot, hdisp, vdisp, pixel_clock); @@ -666,15 +660,16 @@ void vrender0soc_device::crtc_update() } // accessed by cross puzzle -uint32_t vrender0soc_device::sysid_r() +u32 vrender0soc_device::sysid_r() { // Device ID: VRender0+ -> 0x0a // Revision Number -> 0x00 - logerror("%s: read SYSID\n",this->tag()); + if (!machine().side_effects_disabled()) + logerror("%s: read SYSID\n", machine().describe_context()); return 0x00000a00; } -uint32_t vrender0soc_device::cfgr_r() +u32 vrender0soc_device::cfgr_r() { // TODO: this truly needs real HW verification, // only Cross Puzzle reads this so far so leaving a logerror @@ -682,7 +677,8 @@ uint32_t vrender0soc_device::cfgr_r() // --xx x--- Reserved for Chip Test Mode // ---- -xx- Local ROM Data Bus Width (01 -> 16 bit) // ---- ---x Local Memory Bus Width (0 -> 16 bit) - logerror("%s: read CFGR\n",this->tag()); + if (!machine().side_effects_disabled()) + logerror("%s: read CFGR\n", machine().describe_context()); return 0x00000041; } @@ -692,7 +688,7 @@ uint32_t vrender0soc_device::cfgr_r() * */ -uint32_t vrender0soc_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +u32 vrender0soc_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { if (crt_is_blanked()) // Blank Screen { @@ -712,7 +708,7 @@ void vrender0soc_device::screen_vblank(int state) { if (crt_active_vblank_irq() == true) { - IntReq(24); //VRender0 VBlank + int_req(24); //VRender0 VBlank m_vr0vid->execute_flipping(); } } diff --git a/src/devices/machine/vrender0.h b/src/devices/machine/vrender0.h index 80957e1aaeaf1..ef7739bd19611 100644 --- a/src/devices/machine/vrender0.h +++ b/src/devices/machine/vrender0.h @@ -31,10 +31,10 @@ class vr0uart_device : public device_t, { public: // construction/destruction - vr0uart_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + vr0uart_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); void regs_map(address_map &map) ATTR_COLD; - void set_channel_num(int ch) { m_channel_num = ch; } + void set_channel_num(s32 ch) { m_channel_num = ch; } void set_parent(vrender0soc_device *parent) { m_parent = parent; } protected: @@ -42,31 +42,32 @@ class vr0uart_device : public device_t, virtual void device_start() override ATTR_COLD; virtual void device_reset() override ATTR_COLD; -private: - uint32_t control_r(); - void control_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t baud_rate_div_r(); - void baud_rate_div_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t status_r(); - void transmit_buffer_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t receive_buffer_r(offs_t offset, uint32_t mem_mask = ~0); - TIMER_CALLBACK_MEMBER( break_timer_cb ); - - uint32_t m_ucon = 0; // control - uint32_t m_ubdr = 0; // baud rate - uint32_t m_ustat = 0; // status - util::fifo m_urxb_fifo; // receive FIFO - - void update_serial_config(); - inline uint32_t calculate_baud_rate(); - virtual void tra_callback() override; virtual void tra_complete() override; virtual void rcv_complete() override; - inline void tx_send_byte(uint8_t val); - int m_channel_num; - vrender0soc_device *m_parent; +private: + u32 m_ucon = 0; // control + u32 m_ubdr = 0; // baud rate + u32 m_ustat = 0; // status + util::fifo m_urxb_fifo; // receive FIFO + + s32 m_channel_num = 0; + vrender0soc_device *m_parent = nullptr; + + u32 control_r(); + void control_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 baud_rate_div_r(); + void baud_rate_div_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 status_r(); + void transmit_buffer_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 receive_buffer_r(offs_t offset, u32 mem_mask = ~0); + TIMER_CALLBACK_MEMBER(break_timer_cb); + + void update_serial_config(); + inline u32 calculate_baud_rate(); + + inline void tx_send_byte(u8 val); }; @@ -78,23 +79,23 @@ class vrender0soc_device : public device_t, public device_mixer_interface { public: // construction/destruction - vrender0soc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + vrender0soc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); // configurations template void set_host_space_tag(T &&tag, int spacenum) { m_host_space.set_tag(std::forward(tag), spacenum); } - void set_external_vclk(const uint32_t vclk) { m_ext_vclk = vclk; } + void set_external_vclk(const u32 vclk) { m_ext_vclk = vclk; } void set_external_vclk(const XTAL vclk) { m_ext_vclk = vclk.value(); } auto int_callback() { return m_int_cb.bind(); } template auto tx_callback() { return m_write_tx[Port].bind(); } - template void rx_w(int state) { m_uart[Port]->rx_w((uint8_t)state); } + template void rx_w(int state) { m_uart[Port]->rx_w((u8)state); } // handlers bool crt_is_blanked() { return ((m_crtcregs[0] & 0x0200) == 0x0200); } bool crt_active_vblank_irq(); - void IntReq(int num); - uint8_t irq_callback(); + void int_req(int num); + u8 irq_callback(); bool irq_pending() { return m_intst; } - void write_line_tx(int port, uint8_t value); + void write_line_tx(int port, u8 value); // address map void regs_map(address_map &map) ATTR_COLD; @@ -115,77 +116,80 @@ class vrender0soc_device : public device_t, public device_mixer_interface required_device m_vr0vid; required_device m_vr0snd; required_device_array m_uart; - required_shared_ptr m_crtcregs; + required_shared_ptr m_crtcregs; required_address_space m_host_space; - std::unique_ptr m_textureram; - std::unique_ptr m_frameram; + memory_share_creator m_textureram; + memory_share_creator m_frameram; + + u32 m_ext_vclk = 0; + + u32 m_inten = 0; + u8 m_int_high = 0; + u32 m_intst = 0; - uint32_t m_ext_vclk = 0; + u32 m_timer_control[4]{0}; + u16 m_timer_count[4]{0}; + emu_timer *m_timer[4]{nullptr}; + + struct { + u32 src = 0; + u32 dst = 0; + u32 size = 0; + u32 ctrl = 0; + } m_dma[2]; devcb_write_line m_int_cb; devcb_write_line::array<2> m_write_tx; // INTC - uint32_t m_inten = 0; - uint32_t inten_r(); - void inten_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); + u32 inten_r(); + void inten_w(offs_t offset, u32 data, u32 mem_mask = ~0); - uint32_t intvec_r(); - void intvec_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); + u32 intvec_r(); + void intvec_w(offs_t offset, u32 data, u32 mem_mask = ~0); - uint8_t m_IntHigh = 0; - uint32_t m_intst = 0; - uint32_t intst_r(); - void intst_w(uint32_t data); + u32 intst_r(); + void intst_w(u32 data); void soundirq_cb(int state); // Timer - template void tmcon_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - template uint32_t tmcon_r(); - template void tmcnt_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); - template uint16_t tmcnt_r(); - template TIMER_CALLBACK_MEMBER(Timercb); + template void tmcon_w(offs_t offset, u32 data, u32 mem_mask = ~0); + template u32 tmcon_r(); + template void tmcnt_w(offs_t offset, u16 data, u16 mem_mask = ~0); + template u16 tmcnt_r(); + template TIMER_CALLBACK_MEMBER(timer_cb); - uint32_t m_timer_control[4] = { 0, 0, 0, 0 }; - uint16_t m_timer_count[4] = { 0, 0, 0, 0 }; - emu_timer *m_Timer[4] = { nullptr, nullptr, nullptr, nullptr }; - void TimerStart(int which); + void timer_start(int which); // DMAC - template uint32_t dmac_r(); - template void dmac_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - template uint32_t dmatc_r(); - template void dmatc_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - template uint32_t dmasa_r(); - template void dmasa_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - template uint32_t dmada_r(); - template void dmada_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - inline int dma_setup_hold(uint8_t setting, uint8_t bitmask); - struct { - uint32_t src = 0; - uint32_t dst = 0; - uint32_t size = 0; - uint32_t ctrl = 0; - }m_dma[2]; + template u32 dmac_r(); + template void dmac_w(offs_t offset, u32 data, u32 mem_mask = ~0); + template u32 dmatc_r(); + template void dmatc_w(offs_t offset, u32 data, u32 mem_mask = ~0); + template u32 dmasa_r(); + template void dmasa_w(offs_t offset, u32 data, u32 mem_mask = ~0); + template u32 dmada_r(); + template void dmada_w(offs_t offset, u32 data, u32 mem_mask = ~0); + inline int dma_setup_hold(u8 setting, u8 bitmask); // CRTC - uint32_t crtc_r(offs_t offset); - void crtc_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); + u32 crtc_r(offs_t offset); + void crtc_w(offs_t offset, u32 data, u32 mem_mask = ~0); void crtc_update(); inline bool crt_is_interlaced(); // Misc - uint32_t sysid_r(); - uint32_t cfgr_r(); + u32 sysid_r(); + u32 cfgr_r(); - uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); void screen_vblank(int state); - uint16_t textureram_r(offs_t offset); - void textureram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); - uint16_t frameram_r(offs_t offset); - void frameram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); + u16 textureram_r(offs_t offset); + void textureram_w(offs_t offset, u16 data, u16 mem_mask = ~0); + u16 frameram_r(offs_t offset); + void frameram_w(offs_t offset, u16 data, u16 mem_mask = ~0); }; diff --git a/src/devices/sound/vrender0.cpp b/src/devices/sound/vrender0.cpp index e91fea403b0f4..68070ad29342b 100644 --- a/src/devices/sound/vrender0.cpp +++ b/src/devices/sound/vrender0.cpp @@ -17,40 +17,40 @@ //Correct table thanks to Evoga //they left a ulaw<->linear conversion tool inside the roms -static const u16 ULawTo16[]= +static const u16 ulaw_to_16[]= { - 0x8000,0x8400,0x8800,0x8C00,0x9000,0x9400,0x9800,0x9C00, - 0xA000,0xA400,0xA800,0xAC00,0xB000,0xB400,0xB800,0xBC00, - 0x4000,0x4400,0x4800,0x4C00,0x5000,0x5400,0x5800,0x5C00, - 0x6000,0x6400,0x6800,0x6C00,0x7000,0x7400,0x7800,0x7C00, - 0xC000,0xC200,0xC400,0xC600,0xC800,0xCA00,0xCC00,0xCE00, - 0xD000,0xD200,0xD400,0xD600,0xD800,0xDA00,0xDC00,0xDE00, - 0x2000,0x2200,0x2400,0x2600,0x2800,0x2A00,0x2C00,0x2E00, - 0x3000,0x3200,0x3400,0x3600,0x3800,0x3A00,0x3C00,0x3E00, - 0xE000,0xE100,0xE200,0xE300,0xE400,0xE500,0xE600,0xE700, - 0xE800,0xE900,0xEA00,0xEB00,0xEC00,0xED00,0xEE00,0xEF00, + 0x8000,0x8400,0x8800,0x8c00,0x9000,0x9400,0x9800,0x9c00, + 0xa000,0xa400,0xa800,0xac00,0xb000,0xb400,0xb800,0xbc00, + 0x4000,0x4400,0x4800,0x4c00,0x5000,0x5400,0x5800,0x5c00, + 0x6000,0x6400,0x6800,0x6c00,0x7000,0x7400,0x7800,0x7c00, + 0xc000,0xc200,0xc400,0xc600,0xc800,0xca00,0xcc00,0xce00, + 0xd000,0xd200,0xd400,0xd600,0xd800,0xda00,0xdc00,0xde00, + 0x2000,0x2200,0x2400,0x2600,0x2800,0x2a00,0x2c00,0x2e00, + 0x3000,0x3200,0x3400,0x3600,0x3800,0x3a00,0x3c00,0x3e00, + 0xe000,0xe100,0xe200,0xe300,0xe400,0xe500,0xe600,0xe700, + 0xe800,0xe900,0xea00,0xeb00,0xec00,0xed00,0xee00,0xef00, 0x1000,0x1100,0x1200,0x1300,0x1400,0x1500,0x1600,0x1700, - 0x1800,0x1900,0x1A00,0x1B00,0x1C00,0x1D00,0x1E00,0x1F00, - 0xF000,0xF080,0xF100,0xF180,0xF200,0xF280,0xF300,0xF380, - 0xF400,0xF480,0xF500,0xF580,0xF600,0xF680,0xF700,0xF780, - 0x0800,0x0880,0x0900,0x0980,0x0A00,0x0A80,0x0B00,0x0B80, - 0x0C00,0x0C80,0x0D00,0x0D80,0x0E00,0x0E80,0x0F00,0x0F80, - 0xF800,0xF840,0xF880,0xF8C0,0xF900,0xF940,0xF980,0xF9C0, - 0xFA00,0xFA40,0xFA80,0xFAC0,0xFB00,0xFB40,0xFB80,0xFBC0, - 0x0400,0x0440,0x0480,0x04C0,0x0500,0x0540,0x0580,0x05C0, - 0x0600,0x0640,0x0680,0x06C0,0x0700,0x0740,0x0780,0x07C0, - 0xFC00,0xFC20,0xFC40,0xFC60,0xFC80,0xFCA0,0xFCC0,0xFCE0, - 0xFD00,0xFD20,0xFD40,0xFD60,0xFD80,0xFDA0,0xFDC0,0xFDE0, - 0x0200,0x0220,0x0240,0x0260,0x0280,0x02A0,0x02C0,0x02E0, - 0x0300,0x0320,0x0340,0x0360,0x0380,0x03A0,0x03C0,0x03E0, - 0xFE00,0xFE10,0xFE20,0xFE30,0xFE40,0xFE50,0xFE60,0xFE70, - 0xFE80,0xFE90,0xFEA0,0xFEB0,0xFEC0,0xFED0,0xFEE0,0xFEF0, + 0x1800,0x1900,0x1a00,0x1b00,0x1c00,0x1d00,0x1e00,0x1f00, + 0xf000,0xf080,0xf100,0xf180,0xf200,0xf280,0xf300,0xf380, + 0xf400,0xf480,0xf500,0xf580,0xf600,0xf680,0xf700,0xf780, + 0x0800,0x0880,0x0900,0x0980,0x0a00,0x0a80,0x0b00,0x0b80, + 0x0c00,0x0c80,0x0d00,0x0d80,0x0e00,0x0e80,0x0f00,0x0f80, + 0xf800,0xf840,0xf880,0xf8c0,0xf900,0xf940,0xf980,0xf9c0, + 0xfa00,0xfa40,0xfa80,0xfac0,0xfb00,0xfb40,0xfb80,0xfbc0, + 0x0400,0x0440,0x0480,0x04c0,0x0500,0x0540,0x0580,0x05c0, + 0x0600,0x0640,0x0680,0x06c0,0x0700,0x0740,0x0780,0x07c0, + 0xfc00,0xfc20,0xfc40,0xfc60,0xfc80,0xfca0,0xfcc0,0xfce0, + 0xfd00,0xfd20,0xfd40,0xfd60,0xfd80,0xfda0,0xfdc0,0xfde0, + 0x0200,0x0220,0x0240,0x0260,0x0280,0x02a0,0x02c0,0x02e0, + 0x0300,0x0320,0x0340,0x0360,0x0380,0x03a0,0x03c0,0x03e0, + 0xfe00,0xfe10,0xfe20,0xfe30,0xfe40,0xfe50,0xfe60,0xfe70, + 0xfe80,0xfe90,0xfea0,0xfeb0,0xfec0,0xfed0,0xfee0,0xfef0, 0x0100,0x0110,0x0120,0x0130,0x0140,0x0150,0x0160,0x0170, - 0x0180,0x0190,0x01A0,0x01B0,0x01C0,0x01D0,0x01E0,0x01F0, + 0x0180,0x0190,0x01a0,0x01b0,0x01c0,0x01d0,0x01e0,0x01f0, 0x0000,0x0008,0x0010,0x0018,0x0020,0x0028,0x0030,0x0038, 0x0040,0x0048,0x0050,0x0058,0x0060,0x0068,0x0070,0x0078, - 0xFF80,0xFF88,0xFF90,0xFF98,0xFFA0,0xFFA8,0xFFB0,0xFFB8, - 0xFFC0,0xFFC8,0xFFD0,0xFFD8,0xFFE0,0xFFE8,0xFFF0,0xFFF8, + 0xff80,0xff88,0xff90,0xff98,0xffa0,0xffa8,0xffb0,0xffb8, + 0xffc0,0xffc8,0xffd0,0xffd8,0xffe0,0xffe8,0xfff0,0xfff8, }; // 16 bit access only @@ -139,32 +139,32 @@ void vr0sound_device::device_start() space(AS_FRAME).cache(m_fbcache); m_texcache_ctrl = &m_fbcache; for (auto &elem : m_channel) - elem.Cache = &m_fbcache; + elem.cache = &m_fbcache; m_stream = stream_alloc(0, 2, clock() / 972); // TODO : Correct source / divider? - save_item(STRUCT_MEMBER(m_channel, CurSAddr)); - save_item(STRUCT_MEMBER(m_channel, EnvVol)); - save_item(STRUCT_MEMBER(m_channel, EnvStage)); - save_item(STRUCT_MEMBER(m_channel, dSAddr)); - save_item(STRUCT_MEMBER(m_channel, Modes)); - save_item(STRUCT_MEMBER(m_channel, LD)); - save_item(STRUCT_MEMBER(m_channel, LoopBegin)); - save_item(STRUCT_MEMBER(m_channel, LoopEnd)); - save_item(STRUCT_MEMBER(m_channel, LChnVol)); - save_item(STRUCT_MEMBER(m_channel, RChnVol)); - save_item(STRUCT_MEMBER(m_channel, EnvRate)); - save_item(STRUCT_MEMBER(m_channel, EnvTarget)); - save_item(NAME(m_Status)); - save_item(NAME(m_NoteOn)); - save_item(NAME(m_RevFactor)); - save_item(NAME(m_BufferAddr)); - save_item(NAME(m_BufferSize)); - save_item(NAME(m_IntMask)); - save_item(NAME(m_IntPend)); - save_item(NAME(m_MaxChn)); - save_item(NAME(m_ChnClkNum)); - save_item(NAME(m_Ctrl)); + save_item(STRUCT_MEMBER(m_channel, cur_saddr)); + save_item(STRUCT_MEMBER(m_channel, env_vol)); + save_item(STRUCT_MEMBER(m_channel, env_stage)); + save_item(STRUCT_MEMBER(m_channel, ds_addr)); + save_item(STRUCT_MEMBER(m_channel, modes)); + save_item(STRUCT_MEMBER(m_channel, ld)); + save_item(STRUCT_MEMBER(m_channel, loop_begin)); + save_item(STRUCT_MEMBER(m_channel, loop_end)); + save_item(STRUCT_MEMBER(m_channel, l_chn_vol)); + save_item(STRUCT_MEMBER(m_channel, r_chn_vol)); + save_item(STRUCT_MEMBER(m_channel, env_rate)); + save_item(STRUCT_MEMBER(m_channel, env_target)); + save_item(NAME(m_status)); + save_item(NAME(m_note_on)); + save_item(NAME(m_rev_factor)); + save_item(NAME(m_buffer_addr)); + save_item(NAME(m_buffer_size)); + save_item(NAME(m_int_mask)); + save_item(NAME(m_int_pend)); + save_item(NAME(m_max_chan)); + save_item(NAME(m_chan_clk_num)); + save_item(NAME(m_ctrl)); } //------------------------------------------------- @@ -207,7 +207,7 @@ device_memory_interface::space_config_vector vr0sound_device::memory_space_confi void vr0sound_device::sound_stream_update(sound_stream &stream) { - VR0_RenderAudio(stream); + render_audio(stream); } u16 vr0sound_device::channel_r(offs_t offset) @@ -217,60 +217,60 @@ u16 vr0sound_device::channel_r(offs_t offset) void vr0sound_device::channel_w(offs_t offset, u16 data, u16 mem_mask) { - channel_t *channel = &m_channel[(offset >> 4) & 0x1f]; - u16 old_mode = channel->Modes; + channel_t &channel = m_channel[(offset >> 4) & 0x1f]; + const u16 old_mode = channel.modes; m_channel[(offset >> 4) & 0x1f].write(offset & 0xf, data, mem_mask); - if ((old_mode ^ channel->Modes) & MODE_TEXTURE) + if ((old_mode ^ channel.modes) & MODE_TEXTURE) { - channel->Cache = (channel->Modes & MODE_TEXTURE) ? m_texcache_ctrl : &m_fbcache; + channel.cache = (channel.modes & MODE_TEXTURE) ? m_texcache_ctrl : &m_fbcache; } } u16 vr0sound_device::status_r(offs_t offset) { - return m_Status >> ((offset & 1) << 2); + return m_status >> ((offset & 1) << 2); } void vr0sound_device::status_w(offs_t offset, u16 data) { const u32 c = data & 0x1f; - if (data & 0x8000) + if (BIT(data, 15)) { - m_Status |= 1 << c; + m_status |= 1 << c; } else { - m_Status &= ~(1 << c); + m_status &= ~(1 << c); } } u16 vr0sound_device::noteon_r(offs_t offset) { - return m_NoteOn >> ((offset & 1) << 2); + return m_note_on >> ((offset & 1) << 2); } void vr0sound_device::noteon_w(offs_t offset, u16 data) { const u32 c = data & 0x1f; - if (data & 0x8000) + if (BIT(data, 15)) { - m_NoteOn |= 1 << c; + m_note_on |= 1 << c; } else { - m_NoteOn &= ~(1 << c); + m_note_on &= ~(1 << c); } } u16 vr0sound_device::revfactor_r(offs_t offset) { - return m_RevFactor & 0xff; + return m_rev_factor & 0xff; } void vr0sound_device::revfactor_w(offs_t offset, u16 data, u16 mem_mask) { if (ACCESSING_BITS_0_7) - m_RevFactor = data & 0xff; + m_rev_factor = data & 0xff; } /* @@ -284,72 +284,80 @@ void vr0sound_device::revfactor_w(offs_t offset, u16 data, u16 mem_mask) u16 vr0sound_device::buffersaddr_r(offs_t offset) { - return (m_BufferAddr >> 14) & 0x7f; + return (m_buffer_addr >> 14) & 0x7f; } void vr0sound_device::buffersaddr_w(offs_t offset, u16 data, u16 mem_mask) { if (ACCESSING_BITS_0_7) - m_BufferAddr = (m_BufferAddr & ~(0x7f << 14)) | ((data & 0x7f) << 14); + m_buffer_addr = (m_buffer_addr & ~(0x7f << 14)) | ((data & 0x7f) << 14); } -u16 vr0sound_device::buffersize0_r(offs_t offset) { return m_BufferSize[0] & 0xfff; } -u16 vr0sound_device::buffersize1_r(offs_t offset) { return m_BufferSize[1] & 0xfff; } -u16 vr0sound_device::buffersize2_r(offs_t offset) { return m_BufferSize[2] & 0xfff; } -u16 vr0sound_device::buffersize3_r(offs_t offset) { return m_BufferSize[3] & 0xfff; } +u16 vr0sound_device::buffersize0_r(offs_t offset) { return m_buffer_size[0] & 0xfff; } +u16 vr0sound_device::buffersize1_r(offs_t offset) { return m_buffer_size[1] & 0xfff; } +u16 vr0sound_device::buffersize2_r(offs_t offset) { return m_buffer_size[2] & 0xfff; } +u16 vr0sound_device::buffersize3_r(offs_t offset) { return m_buffer_size[3] & 0xfff; } -void vr0sound_device::buffersize0_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_BufferSize[0]); } -void vr0sound_device::buffersize1_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_BufferSize[1]); } -void vr0sound_device::buffersize2_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_BufferSize[2]); } -void vr0sound_device::buffersize3_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_BufferSize[3]); } +void vr0sound_device::buffersize0_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_buffer_size[0]); } +void vr0sound_device::buffersize1_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_buffer_size[1]); } +void vr0sound_device::buffersize2_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_buffer_size[2]); } +void vr0sound_device::buffersize3_w(offs_t offset, u16 data, u16 mem_mask) { data &= 0xfff; COMBINE_DATA(&m_buffer_size[3]); } u16 vr0sound_device::intmask_r(offs_t offset) { - return m_IntMask >> ((offset & 1) << 2); + return m_int_mask >> ((offset & 1) << 2); } void vr0sound_device::intmask_w(offs_t offset, u16 data, u16 mem_mask) { const int shift = ((offset & 1) << 2); - m_IntMask = (m_IntMask & ~(mem_mask << shift)) | ((data & mem_mask) << shift); + m_int_mask = (m_int_mask & ~(mem_mask << shift)) | ((data & mem_mask) << shift); } u16 vr0sound_device::intpend_r(offs_t offset) { - return m_IntPend >> ((offset & 1) << 2); + return m_int_pend >> ((offset & 1) << 2); } void vr0sound_device::intpend_w(offs_t offset, u16 data, u16 mem_mask) { - m_IntPend &= ~((data & mem_mask) << ((offset & 1) << 2)); - if (!m_IntPend) + m_int_pend &= ~((data & mem_mask) << ((offset & 1) << 2)); + if (!m_int_pend) m_irq_cb(false); } u16 vr0sound_device::chnnum_r(offs_t offset) { - return ((m_MaxChn & 0x1f) << 8) | (m_ChnClkNum & 0xff); + return ((m_max_chan & 0x1f) << 8) | (m_chan_clk_num & 0xff); } void vr0sound_device::chnnum_w(offs_t offset, u16 data, u16 mem_mask) { if (ACCESSING_BITS_0_7) - m_ChnClkNum = data & 0xff; + m_chan_clk_num = data & 0xff; if (ACCESSING_BITS_8_15) - m_MaxChn = (data >> 8) & 0x1f; + m_max_chan = (data >> 8) & 0x1f; } u16 vr0sound_device::ctrl_r(offs_t offset) { - return m_Ctrl; + return m_ctrl; } void vr0sound_device::ctrl_w(offs_t offset, u16 data, u16 mem_mask) { - const u16 old_ctrl = m_Ctrl; - COMBINE_DATA(&m_Ctrl); - if ((old_ctrl ^ m_Ctrl) & CTRL_TM) - m_texcache_ctrl = (m_Ctrl & CTRL_TM) ? &m_texcache : &m_fbcache; + const u16 old_ctrl = m_ctrl; + COMBINE_DATA(&m_ctrl); + if ((old_ctrl ^ m_ctrl) & CTRL_TM) + { + m_texcache_ctrl = (m_ctrl & CTRL_TM) ? &m_texcache : &m_fbcache; + // refresh channel cache + for (auto & elem : m_channel) + { + if (elem.modes & MODE_TEXTURE) + elem.cache = m_texcache_ctrl; + } + } } /* @@ -391,45 +399,45 @@ u16 vr0sound_device::channel_t::read(offs_t offset) switch (offset) { case 0x00/2: - ret = CurSAddr & 0x0000ffff; + ret = cur_saddr & 0x0000ffff; break; case 0x02/2: - ret = (CurSAddr & 0xffff0000) >> 16; + ret = (cur_saddr & 0xffff0000) >> 16; break; case 0x04/2: - ret = EnvVol & 0xffff; + ret = env_vol & 0xffff; break; case 0x06/2: - ret = 0x6000 | (LD ? 0x1000 : 0) | ((EnvStage << 8) & 0x0f00) | ((EnvVol & 0xff0000) >> 16); + ret = 0x6000 | (ld ? 0x1000 : 0) | ((env_stage << 8) & 0x0f00) | ((env_vol & 0xff0000) >> 16); break; case 0x08/2: - ret = dSAddr; + ret = ds_addr; break; case 0x0a/2: - ret = (Modes << 8) & 0x7f00; + ret = (modes << 8) & 0x7f00; break; case 0x0c/2: - ret = LoopBegin & 0x00ffff; + ret = loop_begin & 0x00ffff; break; case 0x0e/2: - ret = ((LChnVol << 8) & 0x7f00) | ((LoopBegin & 0x3f0000) >> 16); + ret = ((l_chn_vol << 8) & 0x7f00) | ((loop_begin & 0x3f0000) >> 16); break; case 0x10/2: - ret = LoopEnd & 0x00ffff; + ret = loop_end & 0x00ffff; break; case 0x12/2: - ret = ((RChnVol << 8) & 0x7f00) | ((LoopEnd & 0x3f0000) >> 16); + ret = ((r_chn_vol << 8) & 0x7f00) | ((loop_end & 0x3f0000) >> 16); break; case 0x14/2: case 0x16/2: case 0x18/2: case 0x1a/2: - ret = EnvRate[offset - (0x14/2)] & 0x0ffff; + ret = env_rate[offset - (0x14/2)] & 0x0ffff; break; case 0x1c/2: case 0x1e/2: - ret = (EnvTarget[((offset - (0x1c/2)) * 2) + 0] & 0x007f) | ((EnvTarget[((offset - (0x1c/2)) * 2) + 1] << 8) & 0x7f00); - ret |= ((EnvRate[((offset - (0x1c/2)) * 2) + 0] & 0x10000) >> 9) | ((EnvRate[((offset - (0x1c/2)) * 2) + 1] & 0x10000) >> 1); + ret = (env_target[((offset - (0x1c/2)) * 2) + 0] & 0x007f) | ((env_target[((offset - (0x1c/2)) * 2) + 1] << 8) & 0x7f00); + ret |= ((env_rate[((offset - (0x1c/2)) * 2) + 0] & 0x10000) >> 9) | ((env_rate[((offset - (0x1c/2)) * 2) + 1] & 0x10000) >> 1); break; } return ret; @@ -444,144 +452,144 @@ void vr0sound_device::channel_t::write(offs_t offset, u16 data, u16 mem_mask) switch (offset) { case 0x00/2: - CurSAddr = (CurSAddr & 0xffff0000) | (data & 0x0000ffff); + cur_saddr = (cur_saddr & 0xffff0000) | (data & 0x0000ffff); break; case 0x02/2: - CurSAddr = (CurSAddr & 0x0000ffff) | ((data << 16) & 0xffff0000); + cur_saddr = (cur_saddr & 0x0000ffff) | ((data << 16) & 0xffff0000); break; case 0x04/2: - EnvVol = (EnvVol & ~0xffff) | (data & 0xffff); + env_vol = (env_vol & ~0xffff) | (data & 0xffff); break; case 0x06/2: - LD = data & 0x1000; - EnvStage = (data & 0x0f00) >> 8; - EnvVol = util::sext((EnvVol & 0x00ffff) | ((data << 16) & 0xff0000), 24); + ld = BIT(data, 12); + env_stage = (data & 0x0f00) >> 8; + env_vol = util::sext((env_vol & 0x00ffff) | ((data << 16) & 0xff0000), 24); break; case 0x08/2: - dSAddr = data & 0xffff; + ds_addr = data & 0xffff; break; case 0x0a/2: - Modes = (data & 0x7f00) >> 8; + modes = (data & 0x7f00) >> 8; break; case 0x0c/2: - LoopBegin = (LoopBegin & 0x3f0000) | (data & 0x00ffff); + loop_begin = (loop_begin & 0x3f0000) | (data & 0x00ffff); break; case 0x0e/2: - LChnVol = (data & 0x7f00) >> 8; - LoopBegin = (LoopBegin & 0x00ffff) | ((data << 16) & 0x3f0000); + l_chn_vol = (data & 0x7f00) >> 8; + loop_begin = (loop_begin & 0x00ffff) | ((data << 16) & 0x3f0000); break; case 0x10/2: - LoopEnd = (LoopEnd & 0x3f0000) | (data & 0x00ffff); + loop_end = (loop_end & 0x3f0000) | (data & 0x00ffff); break; case 0x12/2: - RChnVol = (data & 0x7f00) >> 8; - LoopEnd = (LoopEnd & 0x00ffff) | ((data << 16) & 0x3f0000); + r_chn_vol = (data & 0x7f00) >> 8; + loop_end = (loop_end & 0x00ffff) | ((data << 16) & 0x3f0000); break; case 0x14/2: case 0x16/2: case 0x18/2: case 0x1a/2: - EnvRate[offset - (0x14/2)] = (EnvRate[offset - (0x14/2)] & ~0xffff) | (data & 0xffff); + env_rate[offset - (0x14/2)] = (env_rate[offset - (0x14/2)] & ~0xffff) | (data & 0xffff); break; case 0x1c/2: case 0x1e/2: - EnvTarget[((offset - (0x1c/2)) * 2) + 0] = (data & 0x007f); - EnvTarget[((offset - (0x1c/2)) * 2) + 1] = ((data & 0x7f00) >> 8); - EnvRate[((offset - (0x1c/2)) * 2) + 0] = util::sext((EnvRate[((offset - (0x1c/2)) * 2) + 0] & 0xffff) | ((data & 0x0080) << 9), 17); - EnvRate[((offset - (0x1c/2)) * 2) + 1] = util::sext((EnvRate[((offset - (0x1c/2)) * 2) + 1] & 0xffff) | ((data & 0x8000) << 1), 17); + env_target[((offset - (0x1c/2)) * 2) + 0] = (data & 0x007f); + env_target[((offset - (0x1c/2)) * 2) + 1] = ((data & 0x7f00) >> 8); + env_rate[((offset - (0x1c/2)) * 2) + 0] = util::sext((env_rate[((offset - (0x1c/2)) * 2) + 0] & 0xffff) | ((data & 0x0080) << 9), 17); + env_rate[((offset - (0x1c/2)) * 2) + 1] = util::sext((env_rate[((offset - (0x1c/2)) * 2) + 1] & 0xffff) | ((data & 0x8000) << 1), 17); break; } } -void vr0sound_device::VR0_RenderAudio(sound_stream &stream) +void vr0sound_device::render_audio(sound_stream &stream) { int div; - if (m_ChnClkNum) - div = ((30 << 16) | 0x8000) / (m_ChnClkNum + 1); // TODO : Verify algorithm + if (m_chan_clk_num) + div = ((30 << 16) | 0x8000) / (m_chan_clk_num + 1); // TODO : Verify algorithm else div = 1 << 16; for (int s = 0; s < stream.samples(); s++) { s32 lsample = 0, rsample = 0; - for (int i = 0; i <= m_MaxChn; i++) + for (int i = 0; i <= m_max_chan; i++) { - channel_t *channel = &m_channel[i]; + channel_t &channel = m_channel[i]; s32 sample = 0; - const u32 loopbegin_scaled = channel->LoopBegin << 10; - const u32 loopend_scaled = channel->LoopEnd << 10; + const u32 loopbegin_scaled = channel.loop_begin << 10; + const u32 loopend_scaled = channel.loop_end << 10; - if (!(m_Status & (1 << i)) || !(m_Ctrl & CTRL_RS)) + if (!(m_status & (1 << i)) || !(m_ctrl & CTRL_RS)) continue; - if (channel->Modes & MODE_ULAW) //u-law + if (channel.modes & MODE_ULAW) //u-law { - sample = channel->Cache->read_byte(channel->CurSAddr >> 9); - sample = (s16)ULawTo16[sample & 0xff]; + sample = channel.cache->read_byte(channel.cur_saddr >> 9); + sample = (s16)ulaw_to_16[sample & 0xff]; } else { - if (channel->Modes & MODE_8BIT) //8bit + if (channel.modes & MODE_8BIT) //8bit { - sample = channel->Cache->read_byte(channel->CurSAddr >> 9); + sample = channel.cache->read_byte(channel.cur_saddr >> 9); sample = (s16)(((s8)(sample & 0xff)) << 8); } else //16bit { - sample = (s16)(channel->Cache->read_word((channel->CurSAddr >> 9) & ~1)); + sample = (s16)(channel.cache->read_word((channel.cur_saddr >> 9) & ~1)); } } - channel->CurSAddr += (channel->dSAddr * div) >> 16; - if (channel->CurSAddr >= loopend_scaled) + channel.cur_saddr += (channel.ds_addr * div) >> 16; + if (channel.cur_saddr >= loopend_scaled) { - if (channel->Modes & MODE_LOOP) //Loop - channel->CurSAddr = (channel->CurSAddr - loopend_scaled) + loopbegin_scaled; + if (channel.modes & MODE_LOOP) //Loop + channel.cur_saddr = (channel.cur_saddr - loopend_scaled) + loopbegin_scaled; else { - m_Status &= ~(1 << (i & 0x1f)); - if (m_IntMask != 0xffffffff) // Interrupt, TODO : Partially implemented, Verify behavior from real hardware + m_status &= ~(1 << (i & 0x1f)); + if (m_int_mask != 0xffffffff) // Interrupt, TODO : Partially implemented, Verify behavior from real hardware { - const u32 old_pend = m_IntPend; - m_IntPend |= (~m_IntMask & (1 << (i & 0x1f))); // it's can be with loop? - if ((m_IntPend != 0) && (old_pend != m_IntPend)) + const u32 old_pend = m_int_pend; + m_int_pend |= (~m_int_mask & (1 << (i & 0x1f))); // it's can be with loop? + if ((m_int_pend != 0) && (old_pend != m_int_pend)) m_irq_cb(true); } break; } } - const s32 v = channel->EnvVol >> 16; + const s32 v = channel.env_vol >> 16; sample = (sample * v) >> 8; - if (channel->Modes & MODE_ENVELOPE) // Envelope, TODO : Partially implemented, Verify behavior from real hardware + if (channel.modes & MODE_ENVELOPE) // Envelope, TODO : Partially implemented, Verify behavior from real hardware { for (int level = 0; level < 4; level++) { - if (BIT(channel->EnvStage, level)) + if (BIT(channel.env_stage, level)) { - s32 RATE = (channel->EnvRate[level] * div) >> 16; + const s32 rate = (channel.env_rate[level] * div) >> 16; - channel->EnvVol += RATE; - if (RATE > 0) + channel.env_vol += rate; + if (rate > 0) { - if (((channel->EnvVol >> 16) & 0x7f) >= channel->EnvTarget[level]) + if (((channel.env_vol >> 16) & 0x7f) >= channel.env_target[level]) { - channel->EnvStage <<= 1; + channel.env_stage <<= 1; } } - else if (RATE < 0) + else if (rate < 0) { - if (((channel->EnvVol >> 16) & 0x7f) <= channel->EnvTarget[level]) + if (((channel.env_vol >> 16) & 0x7f) <= channel.env_target[level]) { - channel->EnvStage <<= 1; + channel.env_stage <<= 1; } } } } } - lsample += (sample * channel->LChnVol) >> 8; - rsample += (sample * channel->RChnVol) >> 8; + lsample += (sample * channel.l_chn_vol) >> 8; + rsample += (sample * channel.r_chn_vol) >> 8; } stream.put_int_clamp(0, s, lsample, 32768); stream.put_int_clamp(1, s, rsample, 32768); diff --git a/src/devices/sound/vrender0.h b/src/devices/sound/vrender0.h index 5a2d64183f07c..0ff12cc2ca9db 100644 --- a/src/devices/sound/vrender0.h +++ b/src/devices/sound/vrender0.h @@ -71,6 +71,7 @@ class vr0sound_device : public device_t, void ctrl_w(offs_t offset, u16 data, u16 mem_mask); void sound_map(address_map &map) ATTR_COLD; + protected: // device-level overrides virtual void device_start() override ATTR_COLD; @@ -83,8 +84,6 @@ class vr0sound_device : public device_t, // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; - address_space_config m_texture_config; - address_space_config m_frame_config; private: enum { @@ -109,29 +108,26 @@ class vr0sound_device : public device_t, struct channel_t { - channel_t() - { - std::fill(std::begin(EnvRate), std::end(EnvRate), 0); - std::fill(std::begin(EnvTarget), std::end(EnvTarget), 0); - } - - memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache *Cache; - u32 CurSAddr = 0; // Current Address Pointer, 22.10 Fixed Point - s32 EnvVol = 0; // Envelope Volume (Overall Volume), S.7.16 Fixed Point - u8 EnvStage = 1; // Envelope Stage - u16 dSAddr = 0; // Frequency, 6.10 Fixed Point - u8 Modes = 0; // Modes - bool LD = true; // Loop Direction (Not Implemented) - u32 LoopBegin = 0; // Loop Start Pointer, High 22 Bits - u32 LoopEnd = 0; // Loop End Pointer, High 22 Bits - u8 LChnVol = 0; // Left Volume, 7 bit unsigned - u8 RChnVol = 0; // Right Volume, 7 bit unsigned - s32 EnvRate[4]; // Envenloe Rate per Each stages, S.16 Fixed Point - u8 EnvTarget[4]; // Envelope Target Volume per Each stages, High 7 Bits + memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache *cache; + u32 cur_saddr = 0; // Current Address Pointer, 22.10 Fixed Point + s32 env_vol = 0; // Envelope Volume (Overall Volume), S.7.16 Fixed Point + u8 env_stage = 1; // Envelope Stage + u16 ds_addr = 0; // Frequency, 6.10 Fixed Point + u8 modes = 0; // modes + bool ld = true; // Loop Direction (Not Implemented) + u32 loop_begin = 0; // Loop Start Pointer, High 22 Bits + u32 loop_end = 0; // Loop End Pointer, High 22 Bits + u8 l_chn_vol = 0; // Left Volume, 7 bit unsigned + u8 r_chn_vol = 0; // Right Volume, 7 bit unsigned + s32 env_rate[4]{0}; // Envenloe Rate per Each stages, S.16 Fixed Point + u8 env_target[4]{0}; // Envelope Target Volume per Each stages, High 7 Bits u16 read(offs_t offset); void write(offs_t offset, u16 data, u16 mem_mask); }; + address_space_config m_texture_config; + address_space_config m_frame_config; + memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache m_texcache; memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache m_fbcache; memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache *m_texcache_ctrl; @@ -141,17 +137,17 @@ class vr0sound_device : public device_t, devcb_write_line m_irq_cb; // Registers - u32 m_Status = 0; // Status (0 Idle, 1 Busy) - u32 m_NoteOn = 0; // Note On (0 Off, 1 On) (Not Implemented) - u8 m_RevFactor = 0; // Reverb Factor (Not Implemented) - u32 m_BufferAddr = 0; // 21bit Reverb Buffer Start Address (Not Implemented) - u16 m_BufferSize[4] = {0, 0, 0, 0}; // Reverb Buffer Size (Not Implemented) - u32 m_IntMask = 0; // Interrupt Mask (0 Enable, 1 Disable) - u32 m_IntPend = 0; // Interrupt Pending - u8 m_MaxChn = 0x1f; // Max Channels - 1 - u8 m_ChnClkNum = 0; // Clock Number per Channel - u16 m_Ctrl = 0; // 0x602 Control Functions - void VR0_RenderAudio(sound_stream &stream); + u32 m_status = 0; // Status (0 Idle, 1 Busy) + u32 m_note_on = 0; // Note On (0 Off, 1 On) (Not Implemented) + u8 m_rev_factor = 0; // Reverb Factor (Not Implemented) + u32 m_buffer_addr = 0; // 21bit Reverb Buffer Start Address (Not Implemented) + u16 m_buffer_size[4]{0}; // Reverb Buffer Size (Not Implemented) + u32 m_int_mask = 0; // Interrupt Mask (0 Enable, 1 Disable) + u32 m_int_pend = 0; // Interrupt Pending + u8 m_max_chan = 0x1f; // Max Channels - 1 + u8 m_chan_clk_num = 0; // Clock Number per Channel + u16 m_ctrl = 0; // 0x602 Control Functions + void render_audio(sound_stream &stream); }; DECLARE_DEVICE_TYPE(SOUND_VRENDER0, vr0sound_device) diff --git a/src/devices/video/vrender0.cpp b/src/devices/video/vrender0.cpp index d2085339bef8d..55aa83a4bee44 100644 --- a/src/devices/video/vrender0.cpp +++ b/src/devices/video/vrender0.cpp @@ -30,11 +30,67 @@ DEFINE_DEVICE_TYPE(VIDEO_VRENDER0, vr0video_device, "vr0video", "MagicEyes VRender0 Video Engine") -vr0video_device::vr0video_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +vr0video_device::vr0video_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, VIDEO_VRENDER0, tag, owner, clock) , device_video_interface(mconfig, *this) + , device_memory_interface(mconfig, *this) + , m_draw_image{ + { + &vr0video_device::draw_quad<4, false, 0>, + &vr0video_device::draw_quad<8, false, 0>, + &vr0video_device::draw_quad<16, false, 0>, + &vr0video_device::draw_quad<16, false, 0>, + &vr0video_device::draw_quad<4, false, 1>, + &vr0video_device::draw_quad<8, false, 1>, + &vr0video_device::draw_quad<16, false, 1>, + &vr0video_device::draw_quad<16, false, 1>, + &vr0video_device::draw_quad<4, false, 2>, + &vr0video_device::draw_quad<8, false, 2>, + &vr0video_device::draw_quad<16, false, 2>, + &vr0video_device::draw_quad<16, false, 2>, + &vr0video_device::draw_quad<4, false, 3>, + &vr0video_device::draw_quad<8, false, 3>, + &vr0video_device::draw_quad<16, false, 3>, + &vr0video_device::draw_quad<16, false, 3> + }, + { + &vr0video_device::draw_quad<4, true, 0>, + &vr0video_device::draw_quad<8, true, 0>, + &vr0video_device::draw_quad<16, true, 0>, + &vr0video_device::draw_quad<16, true, 0>, + &vr0video_device::draw_quad<4, true, 1>, + &vr0video_device::draw_quad<8, true, 1>, + &vr0video_device::draw_quad<16, true, 1>, + &vr0video_device::draw_quad<16, true, 1>, + &vr0video_device::draw_quad<4, true, 2>, + &vr0video_device::draw_quad<8, true, 2>, + &vr0video_device::draw_quad<16, true, 2>, + &vr0video_device::draw_quad<16, true, 2>, + &vr0video_device::draw_quad<4, true, 3>, + &vr0video_device::draw_quad<8, true, 3>, + &vr0video_device::draw_quad<16, true, 3>, + &vr0video_device::draw_quad<16, true, 3> + } + } + , m_texture_config("texture", ENDIANNESS_LITTLE, 16, 23) // 64 MBit (8 MB) Texture Memory Support + , m_frame_config("frame", ENDIANNESS_LITTLE, 16, 23) // 64 MBit (8 MB) Framebuffer Memory Support , m_idleskip_cb(*this) - + , m_internal_palette{0} + , m_last_pal_update(0xffffffff) + , m_render_state(render_state_info()) + , m_queue_rear(0) + , m_queue_front(0) + , m_bank1_select(false) + , m_display_bank(0) + , m_draw_select(false) + , m_render_reset(false) + , m_render_start(false) + , m_dither_mode(0) + , m_flip_count(0) + , m_draw_dest(0) + , m_display_dest(0) + , m_flip_sync(false) + , m_pipeline_timer(nullptr) { } @@ -50,27 +106,27 @@ void vr0video_device::regs_map(address_map &map) map(0x00a6, 0x00a7).rw(FUNC(vr0video_device::flip_count_r), FUNC(vr0video_device::flip_count_w)); } -uint16_t vr0video_device::cmd_queue_front_r() +u16 vr0video_device::cmd_queue_front_r() { return m_queue_front & 0x7ff; } -void vr0video_device::cmd_queue_front_w(offs_t offset, uint16_t data, uint16_t mem_mask) +void vr0video_device::cmd_queue_front_w(offs_t offset, u16 data, u16 mem_mask) { COMBINE_DATA(&m_queue_front); } -uint16_t vr0video_device::cmd_queue_rear_r() +u16 vr0video_device::cmd_queue_rear_r() { return m_queue_rear & 0x7ff; } -uint16_t vr0video_device::render_control_r() +u16 vr0video_device::render_control_r() { - return (m_draw_select<<7) | (m_render_reset<<3) | (m_render_start<<2) | (m_dither_mode); + return (m_draw_select ? 0x80 : 0) | (m_render_reset ? 0x8 : 0) | (m_render_start ? 0x4 : 0) | m_dither_mode; } -void vr0video_device::render_control_w(offs_t offset, uint16_t data, uint16_t mem_mask) +void vr0video_device::render_control_w(offs_t offset, u16 data, u16 mem_mask) { if (ACCESSING_BITS_0_7) { @@ -81,37 +137,37 @@ void vr0video_device::render_control_w(offs_t offset, uint16_t data, uint16_t me // initialize pipeline // TODO: what happens if reset and start are both 1? Datasheet advises against it. - if (m_render_reset == true) + if (m_render_reset) m_queue_front = m_queue_rear = 0; } } -uint16_t vr0video_device::display_bank_r() +u16 vr0video_device::display_bank_r() { return m_display_bank; } -uint16_t vr0video_device::bank1_select_r() +u16 vr0video_device::bank1_select_r() { - return (m_bank1_select)<<15; + return m_bank1_select ? 0x8000 : 0; } -void vr0video_device::bank1_select_w(uint16_t data) +void vr0video_device::bank1_select_w(u16 data) { - m_bank1_select = BIT(data,15); + m_bank1_select = BIT(data, 15); } -uint16_t vr0video_device::flip_count_r() +u16 vr0video_device::flip_count_r() { m_idleskip_cb(m_flip_count != 0); return m_flip_count; } -void vr0video_device::flip_count_w(offs_t offset, uint16_t data, uint16_t mem_mask) +void vr0video_device::flip_count_w(offs_t offset, u16 data, u16 mem_mask) { if (ACCESSING_BITS_0_7) { - int fc = (data) & 0xff; + int const fc = data & 0xff; if (fc == 1) m_flip_count++; else if (fc == 0) @@ -125,29 +181,34 @@ void vr0video_device::flip_count_w(offs_t offset, uint16_t data, uint16_t mem_ma void vr0video_device::device_start() { - save_item(NAME(m_InternalPalette)); - save_item(NAME(m_LastPalUpdate)); - - save_item(NAME(m_RenderState.Tx)); - save_item(NAME(m_RenderState.Ty)); - save_item(NAME(m_RenderState.Txdx)); - save_item(NAME(m_RenderState.Tydx)); - save_item(NAME(m_RenderState.Txdy)); - save_item(NAME(m_RenderState.Tydy)); - save_item(NAME(m_RenderState.SrcAlphaColor)); - save_item(NAME(m_RenderState.SrcBlend)); - save_item(NAME(m_RenderState.DstAlphaColor)); - save_item(NAME(m_RenderState.DstBlend)); - save_item(NAME(m_RenderState.ShadeColor)); - save_item(NAME(m_RenderState.TransColor)); - save_item(NAME(m_RenderState.TileOffset)); - save_item(NAME(m_RenderState.FontOffset)); - save_item(NAME(m_RenderState.PalOffset)); - save_item(NAME(m_RenderState.PaletteBank)); - save_item(NAME(m_RenderState.TextureMode)); - save_item(NAME(m_RenderState.PixelFormat)); - save_item(NAME(m_RenderState.Width)); - save_item(NAME(m_RenderState.Height)); + // Find our direct access + space(AS_TEXTURE).cache(m_texcache); + space(AS_FRAME).cache(m_fbcache); + space(AS_FRAME).specific(m_fbmem); + + save_item(NAME(m_internal_palette)); + save_item(NAME(m_last_pal_update)); + + save_item(NAME(m_render_state.tx)); + save_item(NAME(m_render_state.ty)); + save_item(NAME(m_render_state.txdx)); + save_item(NAME(m_render_state.tydx)); + save_item(NAME(m_render_state.txdy)); + save_item(NAME(m_render_state.tydy)); + save_item(NAME(m_render_state.src_alpha_color)); + save_item(NAME(m_render_state.src_blend)); + save_item(NAME(m_render_state.dst_alpha_color)); + save_item(NAME(m_render_state.dst_blend)); + save_item(NAME(m_render_state.shade_color)); + save_item(NAME(m_render_state.trans_color)); + save_item(NAME(m_render_state.tile_offset)); + save_item(NAME(m_render_state.font_offset)); + save_item(NAME(m_render_state.pal_offset)); + save_item(NAME(m_render_state.palette_bank)); + save_item(NAME(m_render_state.texture_mode)); + save_item(NAME(m_render_state.pixel_format)); + save_item(NAME(m_render_state.Width)); + save_item(NAME(m_render_state.Height)); save_item(NAME(m_flip_count)); save_item(NAME(m_queue_rear)); @@ -163,109 +224,78 @@ void vr0video_device::device_start() m_pipeline_timer = timer_alloc(FUNC(vr0video_device::pipeline_cb), this); } -void vr0video_device::set_areas(uint16_t *textureram, uint16_t *frameram) -{ - m_textureram = (uint8_t *)textureram; - m_packetram = textureram; - m_frameram = frameram; -} - //------------------------------------------------- // device_reset - device-specific reset //------------------------------------------------- void vr0video_device::device_reset() { - memset(m_InternalPalette, 0, sizeof(m_InternalPalette)); - m_LastPalUpdate = 0xffffffff; + std::fill(std::begin(m_internal_palette), std::end(m_internal_palette), 0); + m_last_pal_update = 0xffffffff; - m_DisplayDest = m_DrawDest = m_frameram; + m_display_dest = m_draw_dest = 0; // 1100 objects per second at ~80 MHz - m_pipeline_timer->adjust(attotime::from_hz(this->clock() /1100), 0, attotime::from_hz(this->clock() / 1100)); + m_pipeline_timer->adjust(attotime::from_hz(this->clock() / 1100), 0, attotime::from_hz(this->clock() / 1100)); +} + +//------------------------------------------------- +// memory_space_config - return a description of +// any address spaces owned by this device +//------------------------------------------------- + +device_memory_interface::space_config_vector vr0video_device::memory_space_config() const +{ + return space_config_vector { + std::make_pair(AS_TEXTURE, &m_texture_config), + std::make_pair(AS_FRAME, &m_frame_config) + }; } /***************************************************************************** IMPLEMENTATION *****************************************************************************/ -struct QuadInfo -{ - uint16_t *Dest; - uint32_t Pitch; //in UINT16s - uint32_t w,h; - uint32_t Tx; - uint32_t Ty; - uint32_t Txdx; - uint32_t Tydx; - uint32_t Txdy; - uint32_t Tydy; - uint16_t TWidth; - uint16_t THeight; - union _u - { - uint8_t *Imageb; - uint16_t *Imagew; - } u; - uint16_t *Tile; - uint16_t *Pal; - uint32_t TransColor; - uint32_t Shade; - uint8_t Clamp; - uint8_t Trans; - uint8_t SrcAlpha; - uint32_t SrcColor; - uint8_t DstAlpha; - uint32_t DstColor; -}; - -/* -Pick a rare enough color to disable transparency (that way I save a cmp per loop to check -if I must draw transparent or not. The palette build will take this color in account so -no color in the palette will have this value -*/ -#define NOTRANSCOLOR 0xecda - -#define RGB32(r,g,b) ((r << 16) | (g << 8) | (b << 0)) -#define RGB16(r,g,b) ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3) - -static inline uint16_t RGB32TO16(uint32_t rgb) +static inline u32 RGB32(u8 r, u8 g, u8 b) { return (r << 16) | (g << 8) | (b << 0); } +static inline u16 RGB16(u8 r, u8 g, u8 b) { return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); } + +static inline u16 RGB32TO16(u32 rgb) { return (((rgb >> (16 + 3)) & 0x1f) << 11) | (((rgb >> (8 + 2)) & 0x3f) << 5) | (((rgb >> (3)) & 0x1f) << 0); } -#define EXTRACTR8(Src) (((Src >> 11) << 3) & 0xff) -#define EXTRACTG8(Src) (((Src >> 5) << 2) & 0xff) -#define EXTRACTB8(Src) (((Src >> 0) << 3) & 0xff) +static inline u8 EXTRACTR8(u16 src) { return ((src >> 11) << 3) & 0xff; } +static inline u8 EXTRACTG8(u16 src) { return ((src >> 5) << 2) & 0xff; } +static inline u8 EXTRACTB8(u16 src) { return ((src >> 0) << 3) & 0xff; } -static inline uint16_t Shade(uint16_t Src, uint32_t Shade) +static inline u16 do_shade(u16 src, u32 shade) { - uint32_t scr = (EXTRACTR8(Src) * ((Shade >> 16) & 0xff)) >> 8; - uint32_t scg = (EXTRACTG8(Src) * ((Shade >> 8) & 0xff)) >> 8; - uint32_t scb = (EXTRACTB8(Src) * ((Shade >> 0) & 0xff)) >> 8; + u32 const scr = (EXTRACTR8(src) * ((shade >> 16) & 0xff)) >> 8; + u32 const scg = (EXTRACTG8(src) * ((shade >> 8) & 0xff)) >> 8; + u32 const scb = (EXTRACTB8(src) * ((shade >> 0) & 0xff)) >> 8; return RGB16(scr, scg, scb); } -static uint16_t Alpha(QuadInfo *Quad, uint16_t Src, uint16_t Dst) +u16 vr0video_device::do_alpha(quad_info &quad, u16 src, u16 dst) { - uint32_t scr = (EXTRACTR8(Src) * ((Quad->Shade >> 16) & 0xff)) >> 8; - uint32_t scg = (EXTRACTG8(Src) * ((Quad->Shade >> 8) & 0xff)) >> 8; - uint32_t scb = (EXTRACTB8(Src) * ((Quad->Shade >> 0) & 0xff)) >> 8; - uint32_t dcr = EXTRACTR8(Dst); - uint32_t dcg = EXTRACTG8(Dst); - uint32_t dcb = EXTRACTB8(Dst); + u32 const scr = EXTRACTR8(src); + u32 const scg = EXTRACTG8(src); + u32 const scb = EXTRACTB8(src); + u32 dcr = EXTRACTR8(dst); + u32 dcg = EXTRACTG8(dst); + u32 dcb = EXTRACTB8(dst); - uint32_t smulr, smulg, smulb; - uint32_t dmulr, dmulg, dmulb; + u32 smulr, smulg, smulb; + u32 dmulr, dmulg, dmulb; - switch (Quad->SrcAlpha & 0x1f) + switch (quad.src_alpha & 0x1f) { case 0x01: smulr = smulg = smulb = 0; break; case 0x02: - smulr = (Quad->SrcColor >> 16) & 0xff; - smulg = (Quad->SrcColor >> 8) & 0xff; - smulb = (Quad->SrcColor >> 0) & 0xff; + smulr = (quad.src_color >> 16) & 0xff; + smulg = (quad.src_color >> 8) & 0xff; + smulb = (quad.src_color >> 0) & 0xff; break; case 0x04: smulr = scr; @@ -273,9 +303,9 @@ static uint16_t Alpha(QuadInfo *Quad, uint16_t Src, uint16_t Dst) smulb = scb; break; case 0x08: - smulr = (Quad->DstColor >> 16) & 0xff; - smulg = (Quad->DstColor >> 8) & 0xff; - smulb = (Quad->DstColor >> 0) & 0xff; + smulr = (quad.dst_color >> 16) & 0xff; + smulg = (quad.dst_color >> 8) & 0xff; + smulb = (quad.dst_color >> 0) & 0xff; break; case 0x10: smulr = dcr; @@ -287,22 +317,22 @@ static uint16_t Alpha(QuadInfo *Quad, uint16_t Src, uint16_t Dst) break; } - if (Quad->SrcAlpha & 0x20) + if (BIT(quad.src_alpha, 5)) { smulr = 0x100 - smulr; smulg = 0x100 - smulg; smulb = 0x100 - smulb; } - switch (Quad->DstAlpha & 0x1f) + switch (quad.dst_alpha & 0x1f) { case 0x01: dmulr = dmulg = dmulb = 0; break; case 0x02: - dmulr = (Quad->SrcColor >> 16) & 0xff; - dmulg = (Quad->SrcColor >> 8) & 0xff; - dmulb = (Quad->SrcColor >> 0) & 0xff; + dmulr = (quad.src_color >> 16) & 0xff; + dmulg = (quad.src_color >> 8) & 0xff; + dmulb = (quad.src_color >> 0) & 0xff; break; case 0x04: dmulr = scr; @@ -310,9 +340,9 @@ static uint16_t Alpha(QuadInfo *Quad, uint16_t Src, uint16_t Dst) dmulb = scb; break; case 0x08: - dmulr = (Quad->DstColor >> 16) & 0xff; - dmulg = (Quad->DstColor >> 8) & 0xff; - dmulb = (Quad->DstColor >> 0) & 0xff; + dmulr = (quad.dst_color >> 16) & 0xff; + dmulg = (quad.dst_color >> 8) & 0xff; + dmulb = (quad.dst_color >> 0) & 0xff; break; case 0x10: dmulr = dcr; @@ -324,14 +354,13 @@ static uint16_t Alpha(QuadInfo *Quad, uint16_t Src, uint16_t Dst) break; } - if (Quad->DstAlpha&0x20) + if (BIT(quad.dst_alpha, 5)) { dmulr = 0x100 - dmulr; dmulg = 0x100 - dmulg; dmulb = 0x100 - dmulb; } - dcr = (scr * smulr + dcr * dmulr) >> 8; if (dcr > 0xff) dcr = 0xff; @@ -347,392 +376,308 @@ static uint16_t Alpha(QuadInfo *Quad, uint16_t Src, uint16_t Dst) return RGB16(dcr, dcg, dcb); } -#define TILENAME(bpp, t, a) \ -static void DrawQuad##bpp##t##a(QuadInfo *Quad) - -//TRUST ON THE COMPILER OPTIMIZATIONS -#define TILETEMPL(bpp, t, a) \ -TILENAME(bpp, t, a)\ -{\ - uint32_t TransColor = Quad->Trans ? RGB32TO16(Quad->TransColor) : NOTRANSCOLOR;\ - uint32_t x, y;\ - uint16_t *line = Quad->Dest;\ - uint32_t y_tx = Quad->Tx, y_ty = Quad->Ty;\ - uint32_t x_tx, x_ty;\ - uint32_t Maskw = Quad->TWidth - 1;\ - uint32_t Maskh = Quad->THeight - 1;\ - uint32_t W = Quad->TWidth >> 3;\ -\ - for (y = 0; y < Quad->h; ++y)\ - {\ - uint16_t *pixel = line;\ - x_tx = y_tx;\ - x_ty = y_ty;\ - for (x = 0; x < Quad->w; ++x)\ - {\ - uint32_t Offset;\ - uint32_t tx = x_tx >> 9;\ - uint32_t ty = x_ty >> 9;\ - uint16_t Color;\ - if (Quad->Clamp)\ - {\ - if (tx > Maskw)\ - goto Clamped;\ - if (ty > Maskh)\ - goto Clamped;\ - }\ - else\ - {\ - tx &= Maskw;\ - ty &= Maskh;\ - }\ -\ - if(t)\ - {\ - uint32_t Index=Quad->Tile[(ty>>3)*(W)+(tx>>3)];\ - Offset=(Index<<6)+((ty&7)<<3)+(tx&7);\ - if(Index==0) goto Clamped;\ - }\ - else\ - Offset = ty * (Quad->TWidth) + tx;\ -\ - if (bpp == 4)\ - {\ - uint8_t Texel = Quad->u.Imageb[Offset / 2];\ - if (Offset & 1)\ - Texel &= 0xf;\ - else\ - Texel = (Texel >> 4) & 0xf;\ - Color = Quad->Pal[Texel];\ - }\ - else if (bpp == 8)\ - {\ - uint8_t Texel = Quad->u.Imageb[Offset];\ - Color = Quad->Pal[Texel];\ - }\ - else if (bpp == 16)\ - {\ - Color = Quad->u.Imagew[Offset];\ - }\ - if (Color != TransColor)\ - {\ - if (a == 1)\ - *pixel = Alpha(Quad, Color, *pixel);\ - else if (a == 2)\ - *pixel = Shade(Color, Quad->Shade);\ - else\ - *pixel = Color;\ - }\ - Clamped:\ - ++pixel;\ - x_tx += Quad->Txdx;\ - x_ty += Quad->Tydx;\ - }\ - line += Quad->Pitch;\ - y_tx += Quad->Txdy;\ - y_ty += Quad->Tydy;\ - }\ -} -TILETEMPL(16,0,0) TILETEMPL(16,0,1) TILETEMPL(16,0,2) -TILETEMPL(16,1,0) TILETEMPL(16,1,1) TILETEMPL(16,1,2) - -TILETEMPL(8,0,0) TILETEMPL(8,0,1) TILETEMPL(8,0,2) -TILETEMPL(8,1,0) TILETEMPL(8,1,1) TILETEMPL(8,1,2) - -TILETEMPL(4,0,0) TILETEMPL(4,0,1) TILETEMPL(4,0,2) -TILETEMPL(4,1,0) TILETEMPL(4,1,1) TILETEMPL(4,1,2) +template +void vr0video_device::draw_quad(quad_info &quad) +{ + u32 const trans_color = quad.trans ? RGB32TO16(quad.trans_color) : NOTRANSCOLOR; + u32 const maskw = quad.twidth - 1; + u32 const maskh = quad.theight - 1; + u32 const w = quad.twidth >> 3; + for (int y = quad.dy, y_tx = quad.tx, y_ty = quad.ty; y <= quad.endy; y++, y_tx += quad.txdy, y_ty += quad.tydy) + { + for (int x = quad.dx, x_tx = y_tx, x_ty = y_ty; x <= quad.endx; x++, x_tx += quad.txdx, x_ty += quad.tydx) + { + u32 const fb_addr = quad.dest + get_fb_addr(x, y); + u32 tx = x_tx >> 9; + u32 ty = x_ty >> 9; + if (quad.clamp) + { + if ((tx > maskw) || (ty > maskh)) + continue; + } + else + { + tx &= maskw; + ty &= maskh; + } -#undef TILENAME -#define TILENAME(bpp, t, a) \ -DrawQuad##bpp##t##a + u32 offset = 0; + if (Tiled) + { + u32 const index = m_texcache.read_word(quad.tile + (((ty >> 3) * w + (tx >> 3)) << 1)); + if (index == 0) + continue; + offset = (index << 6) + ((ty & 7) << 3) + (tx & 7); + } + else + offset = (ty * quad.twidth) + tx; + u16 color = 0; + if (Bpp == 4) + { + const u8 texel = m_texcache.read_byte(quad.texaddr + (offset >> 1)); + color = quad.pal[(texel >> (BIT(~offset, 0) << 2)) & 0xf]; + } + else if (Bpp == 8) + { + const u8 texel = m_texcache.read_byte(quad.texaddr + offset); + color = quad.pal[texel]; + } + else if (Bpp == 16) + { + color = m_texcache.read_word(quad.texaddr + (offset << 1)); + } + if (color != trans_color) + { + u16 pixel = m_fbcache.read_word(fb_addr), prev_pixel = pixel; + if (BIT(Blend, 1)) + color = do_shade(color, quad.shade); + if (BIT(Blend, 0)) + pixel = do_alpha(quad, color, pixel); + else + pixel = color; + if (prev_pixel != pixel) + m_fbmem.write_word(fb_addr, pixel); + } + } + } +} -static void DrawQuadFill(QuadInfo *Quad) +void vr0video_device::draw_quad_fill(quad_info &quad) { - uint32_t x, y; - uint16_t *line = Quad->Dest; - uint16_t ShadeColor = RGB32TO16(Quad->Shade); - for (y = 0; y < Quad->h; ++y) + u16 const shade_color = RGB32TO16(quad.shade); + for (u32 y = quad.dy; y <= quad.endy; y++) { - uint16_t *pixel = line; - for (x = 0; x < Quad->w; ++x) + for (u32 x = quad.dx; x <= quad.endx; x++) { - if (Quad->SrcAlpha) - *pixel = Alpha(Quad, Quad->Shade, *pixel); + u32 const fb_addr = quad.dest + get_fb_addr(x, y); + u16 pixel = m_fbcache.read_word(fb_addr), prev_pixel = pixel; + if (quad.src_alpha) + pixel = do_alpha(quad, shade_color, pixel); else - *pixel = ShadeColor; - ++pixel; + pixel = shade_color; + if (prev_pixel != pixel) + m_fbmem.write_word(fb_addr, pixel); } - line += Quad->Pitch; } } -typedef void (*_DrawTemplate)(QuadInfo *); - -static const _DrawTemplate DrawImage[]= -{ - TILENAME(4,0,0), - TILENAME(8,0,0), - TILENAME(16,0,0), - TILENAME(16,0,0), - - TILENAME(4,0,1), - TILENAME(8,0,1), - TILENAME(16,0,1), - TILENAME(16,0,1), - - TILENAME(4,0,2), - TILENAME(8,0,2), - TILENAME(16,0,2), - TILENAME(16,0,2), -}; - -static const _DrawTemplate DrawTile[]= -{ - TILENAME(4,1,0), - TILENAME(8,1,0), - TILENAME(16,1,0), - TILENAME(16,1,0), - - TILENAME(4,1,1), - TILENAME(8,1,1), - TILENAME(16,1,1), - TILENAME(16,1,1), - - TILENAME(4,1,2), - TILENAME(8,1,2), - TILENAME(16,1,2), - TILENAME(16,1,2), -}; - -//Returns true if the operation was a flip (sync or async) +// Returns true if the operation was a flip (sync or async) // TODO: async loading actually doesn't stop rendering but just flips the render bank -int vr0video_device::vrender0_ProcessPacket(uint32_t PacketPtr) +int vr0video_device::process_packet(u32 packet_ptr) { - uint16_t *Packet = m_packetram; - uint8_t *TEXTURE = m_textureram; - - Packet += PacketPtr; - - uint32_t Dx = Packet[1] & 0x3ff; - uint32_t Dy = Packet[2] & 0x1ff; - uint32_t Endx = Packet[3] & 0x3ff; - uint32_t Endy = Packet[4] & 0x1ff; - uint32_t Mode = 0; - uint16_t Packet0 = Packet[0]; - - if (Packet0 & 0x81) //Sync or ASync flip + u32 const dx = get_packet(packet_ptr + 1) & 0x3ff; + u32 const dy = get_packet(packet_ptr + 2) & 0x1ff; + u32 const endx = get_packet(packet_ptr + 3) & 0x3ff; + u32 const endy = get_packet(packet_ptr + 4) & 0x1ff; + u8 blend_mode = 0; + u16 const packet_0 = get_packet(packet_ptr + 0); + + if (packet_0 & 0x81) //Sync or ASync flip { - m_LastPalUpdate = 0xffffffff; //Force update palette next frame - return Packet0 & 0x81; + m_last_pal_update = 0xffffffff; //Force update palette next frame + return packet_0 & 0x81; } - if (Packet0 & 0x200) + if (BIT(packet_0, 9)) { - m_RenderState.Tx = Packet[5] | ((Packet[6] & 0x1f) << 16); - m_RenderState.Ty = Packet[7] | ((Packet[8] & 0x1f) << 16); + m_render_state.tx = get_packet(packet_ptr + 5) | ((get_packet(packet_ptr + 6) & 0x1f) << 16); + m_render_state.ty = get_packet(packet_ptr + 7) | ((get_packet(packet_ptr + 8) & 0x1f) << 16); } else { - m_RenderState.Tx = 0; - m_RenderState.Ty = 0; + m_render_state.tx = 0; + m_render_state.ty = 0; } - if (Packet0 & 0x400) + if (BIT(packet_0, 10)) { - m_RenderState.Txdx = Packet[9] | ((Packet[10] & 0x1f) << 16); - m_RenderState.Tydx = Packet[11] | ((Packet[12] & 0x1f) << 16); - m_RenderState.Txdy = Packet[13] | ((Packet[14] & 0x1f) << 16); - m_RenderState.Tydy = Packet[15] | ((Packet[16] & 0x1f) << 16); + m_render_state.txdx = get_packet(packet_ptr + 9) | ((get_packet(packet_ptr + 10) & 0x1f) << 16); + m_render_state.tydx = get_packet(packet_ptr + 11) | ((get_packet(packet_ptr + 12) & 0x1f) << 16); + m_render_state.txdy = get_packet(packet_ptr + 13) | ((get_packet(packet_ptr + 14) & 0x1f) << 16); + m_render_state.tydy = get_packet(packet_ptr + 15) | ((get_packet(packet_ptr + 16) & 0x1f) << 16); } else { - m_RenderState.Txdx = 1 << 9; - m_RenderState.Tydx = 0; - m_RenderState.Txdy = 0; - m_RenderState.Tydy = 1 << 9; + m_render_state.txdx = 1 << 9; + m_render_state.tydx = 0; + m_render_state.txdy = 0; + m_render_state.tydy = 1 << 9; } - if (Packet0 & 0x800) + if (BIT(packet_0, 11)) { - m_RenderState.SrcAlphaColor = Packet[17] | ((Packet[18] & 0xff) << 16); - m_RenderState.SrcBlend = (Packet[18] >> 8) & 0x3f; - m_RenderState.DstAlphaColor = Packet[19] | ((Packet[20] & 0xff) << 16); - m_RenderState.DstBlend = (Packet[20] >> 8) & 0x3f; + m_render_state.src_alpha_color = get_packet(packet_ptr + 17) | ((get_packet(packet_ptr + 18) & 0xff) << 16); + m_render_state.src_blend = (get_packet(packet_ptr + 18) >> 8) & 0x3f; + m_render_state.dst_alpha_color = get_packet(packet_ptr + 19) | ((get_packet(packet_ptr + 20) & 0xff) << 16); + m_render_state.dst_blend = (get_packet(packet_ptr + 20) >> 8) & 0x3f; } - if (Packet0 & 0x1000) - m_RenderState.ShadeColor = Packet[21] | ((Packet[22] & 0xff) << 16); - if (Packet0 & 0x2000) - m_RenderState.TransColor = Packet[23] | ((Packet[24] & 0xff) << 16); - if (Packet0 & 0x4000) + if (BIT(packet_0, 12)) + m_render_state.shade_color = get_packet(packet_ptr + 21) | ((get_packet(packet_ptr + 22) & 0xff) << 16); + if (BIT(packet_0, 13)) + m_render_state.trans_color = get_packet(packet_ptr + 23) | ((get_packet(packet_ptr + 24) & 0xff) << 16); + if (BIT(packet_0, 14)) { - m_RenderState.TileOffset = Packet[25]; - m_RenderState.FontOffset = Packet[26]; - m_RenderState.PalOffset = Packet[27] >> 3; - m_RenderState.PaletteBank = (Packet[28] >> 8) & 0xf; - m_RenderState.TextureMode = Packet[28] & 0x1000; - m_RenderState.PixelFormat = (Packet[28] >> 6) & 3; - m_RenderState.Width = 8 << ((Packet[28] >> 0) & 0x7); - m_RenderState.Height = 8 << ((Packet[28] >> 3) & 0x7); + m_render_state.tile_offset = get_packet(packet_ptr + 25); + m_render_state.font_offset = get_packet(packet_ptr + 26); + m_render_state.pal_offset = get_packet(packet_ptr + 27) >> 3; + m_render_state.palette_bank = (get_packet(packet_ptr + 28) >> 8) & 0xf; + m_render_state.texture_mode = BIT(get_packet(packet_ptr + 28), 12); + m_render_state.pixel_format = (get_packet(packet_ptr + 28) >> 6) & 3; + m_render_state.Width = 8 << ((get_packet(packet_ptr + 28) >> 0) & 0x7); + m_render_state.Height = 8 << ((get_packet(packet_ptr + 28) >> 3) & 0x7); } - if (Packet0 & 0x40 && m_RenderState.PalOffset != m_LastPalUpdate) + if (BIT(packet_0, 6) && m_render_state.pal_offset != m_last_pal_update) { - uint32_t *Pal = (uint32_t*) (TEXTURE + 1024 * m_RenderState.PalOffset); - uint16_t Trans = RGB32TO16(m_RenderState.TransColor); - int i; - for (i = 0; i < 256; ++i) + u32 const pal = 1024 * m_render_state.pal_offset; + u16 const trans = RGB32TO16(m_render_state.trans_color); + for (int i = 0; i < 256; ++i) { - uint32_t p = Pal[i]; - uint16_t v = RGB32TO16(p); + u32 const p = m_texcache.read_dword(pal + (i << 2)); + u16 v = RGB32TO16(p); // TODO: this is most likely an artifact of not emulating the dither modes, // and it's wrong anyway: topbladv gameplay fighters sports a slighty visible square shadow block. - if ((v == Trans && p != m_RenderState.TransColor) || v == NOTRANSCOLOR) //Error due to conversion. caused transparent + if ((v == trans && p != m_render_state.trans_color) || v == NOTRANSCOLOR) //Error due to conversion. caused transparent { if ((v & 0x1f) != 0x1f) v++; //Make the color a bit different (blueish) so it's not else v--; } - m_InternalPalette[i] = v; //made transparent by mistake + m_internal_palette[i] = v; //made transparent by mistake } - m_LastPalUpdate = m_RenderState.PalOffset; + m_last_pal_update = m_render_state.pal_offset; } - if (Packet0 & 0x100) + if (BIT(packet_0, 8)) { - QuadInfo Quad; - - Quad.Pitch = 1024; + quad_info quad; -// assert(Endx >= Dx && Endy >= Dy); +// assert(endx >= dx && endy >= dy); - if (Packet0 & 2) + if (BIT(packet_0, 1)) { - Quad.SrcAlpha = m_RenderState.SrcBlend; - Quad.DstAlpha = m_RenderState.DstBlend; - Quad.SrcColor = m_RenderState.SrcAlphaColor; - Quad.DstColor = m_RenderState.DstAlphaColor; - Mode = 1; + quad.src_alpha = m_render_state.src_blend; + quad.dst_alpha = m_render_state.dst_blend; + quad.src_color = m_render_state.src_alpha_color; + quad.dst_color = m_render_state.dst_alpha_color; + blend_mode |= 1; } else - Quad.SrcAlpha = 0; - - Quad.w = 1 + Endx - Dx; - Quad.h = 1 + Endy - Dy; - - Quad.Dest = m_DrawDest; - Quad.Dest = Quad.Dest + Dx + (Dy * Quad.Pitch); - - Quad.Tx = m_RenderState.Tx; - Quad.Ty = m_RenderState.Ty; - Quad.Txdx = m_RenderState.Txdx; - Quad.Tydx = m_RenderState.Tydx; - Quad.Txdy = m_RenderState.Txdy; - Quad.Tydy = m_RenderState.Tydy; - if (Packet0 & 0x10) + quad.src_alpha = 0; + + quad.dx = dx; + quad.dy = dy; + quad.endx = endx; + quad.endy = endy; + + quad.dest = m_draw_dest; + + quad.tx = m_render_state.tx; + quad.ty = m_render_state.ty; + quad.txdx = m_render_state.txdx; + quad.tydx = m_render_state.tydx; + quad.txdy = m_render_state.txdy; + quad.tydy = m_render_state.tydy; + if (BIT(packet_0, 4)) { - Quad.Shade = m_RenderState.ShadeColor; - if (!Mode) //Alpha includes Shade - Mode = 2; + quad.shade = m_render_state.shade_color; + blend_mode |= 2; /* //simulate shade with alphablend (SLOW!!!) - if (!Quad.SrcAlpha && (Packet0 & 0x8)) + if (!quad.src_alpha && BIT(packet_0, 3)) { - Quad.SrcAlpha = 0x21; //1 - Quad.DstAlpha = 0x01; //0 + quad.src_alpha = 0x21; //1 + quad.dst_alpha = 0x01; //0 }*/ } else - Quad.Shade = RGB32(255,255,255); - Quad.TransColor = m_RenderState.TransColor; - Quad.TWidth = m_RenderState.Width; - Quad.THeight = m_RenderState.Height; - Quad.Trans = Packet0 & 4; - //Quad.Trans = 0; - Quad.Clamp = Packet0 & 0x20; - - if (Packet0 & 0x8) //Texture Enable + quad.shade = RGB32(255,255,255); + quad.trans_color = m_render_state.trans_color; + quad.twidth = m_render_state.Width; + quad.theight = m_render_state.Height; + quad.trans = BIT(packet_0, 2); + //quad.trans = false; + quad.clamp = BIT(packet_0, 5); + + if (BIT(packet_0, 3)) //Texture Enable { - Quad.u.Imageb = TEXTURE + 128 * m_RenderState.FontOffset; - Quad.Tile = (uint16_t*) (TEXTURE + 128 * m_RenderState.TileOffset); - if (!m_RenderState.PixelFormat) - Quad.Pal = m_InternalPalette + (m_RenderState.PaletteBank * 16); + quad.texaddr = 128 * m_render_state.font_offset; + quad.tile = 128 * m_render_state.tile_offset; + if (!m_render_state.pixel_format) + quad.pal = m_internal_palette + (m_render_state.palette_bank * 16); else - Quad.Pal = m_InternalPalette; + quad.pal = m_internal_palette; - if (m_RenderState.TextureMode) //Tiled - DrawTile[m_RenderState.PixelFormat + 4 * Mode](&Quad); - else - DrawImage[m_RenderState.PixelFormat + 4 * Mode](&Quad); + ((this)->*(m_draw_image[m_render_state.texture_mode ? 1 : 0][m_render_state.pixel_format + 4 * blend_mode]))(quad); } else - DrawQuadFill(&Quad); + draw_quad_fill(quad); } return 0; } TIMER_CALLBACK_MEMBER(vr0video_device::pipeline_cb) { - if (m_render_start == false) + if (!m_render_start) return; // bail out if we encountered a flip sync command // pipeline waits until it receives a vblank signal - if (m_flip_sync == true) + if (m_flip_sync) return; if ((m_queue_rear & 0x7ff) == (m_queue_front & 0x7ff)) return; - int DoFlip = vrender0_ProcessPacket(m_queue_rear * 32); - m_queue_rear ++; + int const do_flip = process_packet(m_queue_rear * 32); + m_queue_rear++; m_queue_rear &= 0x7ff; - if (DoFlip & 0x01) + if (BIT(do_flip, 0)) m_flip_sync = true; - if (DoFlip & 0x80) + if (BIT(do_flip, 7)) { - uint32_t B0 = 0x000000; - uint32_t B1 = (m_bank1_select == true ? 0x400000 : 0x100000)/2; - uint16_t *Front, *Back; + u32 const B0 = 0x000000; + u32 const B1 = m_bank1_select ? 0x400000 : 0x100000; + u32 front, back; - if (m_display_bank & 1) + if (BIT(m_display_bank, 0)) { - Front = (m_frameram + B1); - Back = (m_frameram + B0); + front = B1; + back = B0; } else { - Front = (m_frameram + B0); - Back = (m_frameram + B1); + front = B0; + back = B1; } - m_DrawDest = ((m_draw_select == true) ? Back : Front); + m_draw_dest = m_draw_select ? back : front; } - } void vr0video_device::execute_flipping() { - if (m_render_start == false) + if (!m_render_start) return; - uint32_t B0 = 0x000000; - uint32_t B1 = (m_bank1_select == true ? 0x400000 : 0x100000)/2; - uint16_t *Front, *Back; + u32 const B0 = 0x000000; + u32 const B1 = m_bank1_select ? 0x400000 : 0x100000; + u32 front, back; - if (m_display_bank & 1) + if (BIT(m_display_bank, 0)) { - Front = (m_frameram + B1); - Back = (m_frameram + B0); + front = B1; + back = B0; } else { - Front = (m_frameram + B0); - Back = (m_frameram + B1); + front = B0; + back = B1; } - m_DrawDest = ((m_draw_select == true) ? Front : Back); - m_DisplayDest = Front; + m_draw_dest = m_draw_select ? front : back; + m_display_dest = front; m_flip_sync = false; if (m_flip_count) @@ -742,13 +687,14 @@ void vr0video_device::execute_flipping() } } -uint32_t vr0video_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +u32 vr0video_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { - const uint32_t width = cliprect.width(); - - uint32_t const dx = cliprect.left(); for (int y = cliprect.top(); y <= cliprect.bottom(); y++) - std::copy_n(&m_DisplayDest[(y * 1024) + dx], width, &bitmap.pix(y, dx)); + { + u16 *const dest = &bitmap.pix(y); + for (int x = cliprect.left(); x <= cliprect.right(); x++) + dest[x] = m_fbcache.read_word(m_display_dest + get_fb_addr(x, y)); + } return 0; } diff --git a/src/devices/video/vrender0.h b/src/devices/video/vrender0.h index bdccd2755158f..79d3ec011816b 100644 --- a/src/devices/video/vrender0.h +++ b/src/devices/video/vrender0.h @@ -11,91 +11,148 @@ ***************************************************************************/ class vr0video_device : public device_t, - public device_video_interface + public device_video_interface, + public device_memory_interface { public: - vr0video_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + enum + { + AS_TEXTURE = 0, + AS_FRAME + }; + + vr0video_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - void set_areas(uint16_t *textureram, uint16_t *frameram); - void regs_map(address_map &map) ATTR_COLD; void execute_flipping(); - uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); auto idleskip_cb() { return m_idleskip_cb.bind(); } - uint16_t flip_count_r(); - void flip_count_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); + u16 flip_count_r(); + void flip_count_w(offs_t offset, u16 data, u16 mem_mask = ~0); + + void regs_map(address_map &map) ATTR_COLD; protected: // device-level overrides virtual void device_start() override ATTR_COLD; virtual void device_reset() override ATTR_COLD; -private: - int vrender0_ProcessPacket(uint32_t PacketPtr); + // device_memory_interface configuration + virtual space_config_vector memory_space_config() const override; - devcb_write_line m_idleskip_cb; +private: + /* + Pick a rare enough color to disable transparency (that way I save a cmp per loop to check + if I must draw transparent or not. The palette build will take this color in account so + no color in the palette will have this value + */ + static constexpr u16 NOTRANSCOLOR = 0xecda; + + struct quad_info + { + u32 dest = 0; + u32 dx = 0, dy = 0; + u32 endx = 0, endy = 0; + u32 tx = 0; + u32 ty = 0; + u32 txdx = 0; + u32 tydx = 0; + u32 txdy = 0; + u32 tydy = 0; + u16 twidth = 0; + u16 theight = 0; + u32 texaddr = 0; + u32 tile = 0; + u16 *pal = nullptr; + u32 trans_color = 0; + u32 shade = 0; + bool clamp = false; + bool trans = false; + u8 src_alpha = 0; + u32 src_color = 0; + u8 dst_alpha = 0; + u32 dst_color = 0; + }; - struct RenderStateInfo + struct render_state_info { - uint32_t Tx; - uint32_t Ty; - uint32_t Txdx; - uint32_t Tydx; - uint32_t Txdy; - uint32_t Tydy; - uint32_t SrcAlphaColor; - uint32_t SrcBlend; - uint32_t DstAlphaColor; - uint32_t DstBlend; - uint32_t ShadeColor; - uint32_t TransColor; - uint32_t TileOffset; - uint32_t FontOffset; - uint32_t PalOffset; - uint32_t PaletteBank; - uint32_t TextureMode; - uint32_t PixelFormat; - uint32_t Width; - uint32_t Height; + u32 tx = 0; + u32 ty = 0; + u32 txdx = 0; + u32 tydx = 0; + u32 txdy = 0; + u32 tydy = 0; + u32 src_alpha_color = 0; + u32 src_blend = 0; + u32 dst_alpha_color = 0; + u32 dst_blend = 0; + u32 shade_color = 0; + u32 trans_color = 0; + u32 tile_offset = 0; + u32 font_offset = 0; + u32 pal_offset = 0; + u8 palette_bank = 0; + bool texture_mode = false; + u8 pixel_format = 0; + u16 Width = 0; + u16 Height = 0; }; + typedef void (vr0video_device::*_draw_template)(quad_info &); + _draw_template m_draw_image[2][16]; - uint16_t m_InternalPalette[256]; - uint32_t m_LastPalUpdate; + address_space_config m_texture_config; + address_space_config m_frame_config; - RenderStateInfo m_RenderState; + memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache m_texcache; + memory_access<23, 1, 0, ENDIANNESS_LITTLE>::cache m_fbcache; + memory_access<23, 1, 0, ENDIANNESS_LITTLE>::specific m_fbmem; - uint8_t *m_textureram; - uint16_t *m_packetram; - uint16_t *m_frameram; + devcb_write_line m_idleskip_cb; - uint16_t cmd_queue_front_r(); - void cmd_queue_front_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); + u16 m_internal_palette[256]; + u32 m_last_pal_update; - uint16_t cmd_queue_rear_r(); - uint16_t m_queue_rear, m_queue_front; + render_state_info m_render_state; - uint16_t bank1_select_r(); - void bank1_select_w(uint16_t data); - bool m_bank1_select; //!< Select framebuffer bank1 address + u16 m_queue_rear, m_queue_front; - uint16_t display_bank_r(); - uint8_t m_display_bank; //!< Current display bank + bool m_bank1_select; // Select framebuffer bank1 address + u8 m_display_bank; // Current display bank - uint16_t render_control_r(); - void render_control_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); - bool m_draw_select; //!< If true, device draws to Front buffer instead of Back - bool m_render_reset; //!< Reset pipeline FIFO - bool m_render_start; //!< Enable pipeline processing - uint8_t m_dither_mode; //!< applied on RGB888 to RGB565 conversions (00: 2x2, 01:4x4, 1x disable) - uint8_t m_flip_count; //!< number of framebuffer "syncs" loaded in the parameter RAM, - //!< a.k.a. how many full (vblank) buffers are ready for the device to parse. + bool m_draw_select; // If true, device draws to Front buffer instead of Back + bool m_render_reset; // Reset pipeline FIFO + bool m_render_start; // Enable pipeline processing + u8 m_dither_mode; // applied on RGB888 to RGB565 conversions (00: 2x2, 01:4x4, 1x disable) + u8 m_flip_count; // number of framebuffer "syncs" loaded in the parameter RAM, + // a.k.a. how many full (vblank) buffers are ready for the device to parse. - uint16_t *m_DrawDest; //!< frameram pointer to draw buffer area - uint16_t *m_DisplayDest; //!< frameram pointer to display buffer area + u32 m_draw_dest; // frameram pointer to draw buffer area + u32 m_display_dest; // frameram pointer to display buffer area bool m_flip_sync = false; emu_timer *m_pipeline_timer; + + // 2 bytes per framebuffer data + inline u32 get_fb_addr(u16 x, u16 y) { return ((x & 0x3ff) | ((u32(y) & 0x1ff) << 10)) << 1; } + inline u16 get_packet(u32 ptr) { return m_texcache.read_word(ptr << 1); } + u16 do_alpha(quad_info &quad, u16 src, u16 dst); + template void draw_quad(quad_info &quad); + void draw_quad_fill(quad_info &quad); + int process_packet(u32 packet_ptr); + + u16 cmd_queue_front_r(); + void cmd_queue_front_w(offs_t offset, u16 data, u16 mem_mask = ~0); + + u16 cmd_queue_rear_r(); + + u16 bank1_select_r(); + void bank1_select_w(u16 data); + + u16 display_bank_r(); + + u16 render_control_r(); + void render_control_w(offs_t offset, u16 data, u16 mem_mask = ~0); TIMER_CALLBACK_MEMBER(pipeline_cb); }; diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 87f8cfbf09e3f..58f6a5a1d03b9 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -487,14 +487,17 @@ class fifo : protected std::array } } - T const &dequeue() + T const &dequeue(bool allow_side_effects = true) { T const &result(*m_head); - if (ReadWrap || !m_empty) + if (allow_side_effects) { - if (this->end() == ++m_head) - m_head = this->begin(); - m_empty = (m_head == m_tail); + if (ReadWrap || !m_empty) + { + if (this->end() == ++m_head) + m_head = this->begin(); + m_empty = (m_head == m_tail); + } } return result; } diff --git a/src/mame/misc/crospuzl.cpp b/src/mame/misc/crospuzl.cpp index e13e89fc485f4..ac70b35299909 100644 --- a/src/mame/misc/crospuzl.cpp +++ b/src/mame/misc/crospuzl.cpp @@ -56,140 +56,142 @@ class crospuzl_state : public driver_device { } - void crospuzl(machine_config &config); + void crospuzl(machine_config &config) ATTR_COLD; -private: +protected: + virtual void machine_start() override ATTR_COLD; + virtual void machine_reset() override ATTR_COLD; +private: /* memory pointers */ - required_shared_ptr m_workram; - required_region_ptr m_flash; + required_shared_ptr m_workram; + required_region_ptr m_flash; /* devices */ required_device m_maincpu; required_device m_vr0soc; required_device m_rtc; - uint8_t m_FlashCmd = 0; - uint8_t m_FlashPrevCommand = 0; - uint32_t m_FlashAddr = 0; - uint8_t m_FlashShift = 0; + u8 m_flash_cmd = 0; + u8 m_flash_prev_command = 0; + u32 m_flash_addr = 0; + u8 m_flash_shift = 0; -// void Banksw_w(uint32_t data); - uint8_t FlashCmd_r(); - void FlashCmd_w(uint8_t data); - void FlashAddr_w(uint8_t data); + u32 m_pio = 0; + u32 m_ddr = 0; - virtual void machine_start() override ATTR_COLD; - virtual void machine_reset() override ATTR_COLD; - void crospuzl_mem(address_map &map) ATTR_COLD; +// void banksw_w(u32 data); + u8 flash_cmd_r(); + void flash_cmd_w(u8 data); + void flash_addr_w(u8 data); // PIO - uint32_t m_PIO = 0; - uint32_t m_ddr = 0; - uint32_t PIOlddr_r(); - void PIOlddr_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t PIOldat_r(); - void PIOldat_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t PIOedat_r(); + u32 pio_lddr_r(); + void pio_lddr_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 pio_ldat_r(); + void pio_ldat_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 pio_edat_r(); + + void main_map(address_map &map) ATTR_COLD; }; -uint32_t crospuzl_state::PIOedat_r() +u32 crospuzl_state::pio_edat_r() { - // TODO: this needs fixing in serflash_device + // TODO: this needs fixing in nand_device // (has a laconic constant for the ready line) return (m_rtc->sda_r() << 19) | (machine().rand() & 0x04000000); // serial ready line } -uint8_t crospuzl_state::FlashCmd_r() +u8 crospuzl_state::flash_cmd_r() { - if ((m_FlashCmd & 0xff) == 0xff) + if ((m_flash_cmd & 0xff) == 0xff) { return 0xff; } - if ((m_FlashCmd & 0xff) == 0x90) + if ((m_flash_cmd & 0xff) == 0x90) { // Service Mode has the first two bytes of the ID printed, // in format ****/ee81 // ee81 has no correspondence in the JEDEC flash vendor ID list, // and the standard claims that the ID is 7 + 1 parity bit. // TODO: Retrieve ID from actual HW service mode screen. -// const uint8_t id[5] = { 0xee, 0x81, 0x00, 0x15, 0x00 }; - const uint8_t id[5] = { 0xec, 0xf1, 0x00, 0x95, 0x40 }; - uint8_t res = id[m_FlashAddr]; +// const u8 id[5] = { 0xee, 0x81, 0x00, 0x15, 0x00 }; + const u8 id[5] = { 0xec, 0xf1, 0x00, 0x95, 0x40 }; + const u8 res = id[m_flash_addr]; if (!machine().side_effects_disabled()) { - m_FlashAddr++; - m_FlashAddr %= 5; + m_flash_addr++; + m_flash_addr %= 5; } return res; } - if ((m_FlashCmd & 0xff) == 0x30) + if ((m_flash_cmd & 0xff) == 0x30) { - uint8_t res = m_flash[m_FlashAddr]; + const u8 res = m_flash[m_flash_addr]; if (!machine().side_effects_disabled()) - m_FlashAddr++; + m_flash_addr++; return res; } return 0; } -void crospuzl_state::FlashCmd_w(uint8_t data) +void crospuzl_state::flash_cmd_w(u8 data) { - m_FlashPrevCommand = m_FlashCmd; - m_FlashCmd = data; - m_FlashShift = 0; - m_FlashAddr = 0; - logerror("%08x %08x CMD\n",m_FlashPrevCommand, m_FlashCmd); + m_flash_prev_command = m_flash_cmd; + m_flash_cmd = data; + m_flash_shift = 0; + m_flash_addr = 0; + logerror("%s: %08x %08x CMD\n", machine().describe_context(), m_flash_prev_command, m_flash_cmd); } -void crospuzl_state::FlashAddr_w(uint8_t data) +void crospuzl_state::flash_addr_w(u8 data) { - m_FlashAddr |= data << (m_FlashShift*8); - m_FlashShift++; - if (m_FlashShift == 4) - logerror("%08x %02x ADDR\n",m_FlashAddr,m_FlashShift); + m_flash_addr |= data << (m_flash_shift * 8); + m_flash_shift++; + if (m_flash_shift == 4) + logerror("%s: %08x %02x ADDR\n", machine().describe_context(), m_flash_addr, m_flash_shift); } -uint32_t crospuzl_state::PIOlddr_r() +u32 crospuzl_state::pio_lddr_r() { return m_ddr; } -void crospuzl_state::PIOlddr_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void crospuzl_state::pio_lddr_w(offs_t offset, u32 data, u32 mem_mask) { if (BIT(m_ddr, 19) != BIT(data, 19)) - m_rtc->sda_w(BIT(data, 19) ? 1 : BIT(m_PIO, 19)); + m_rtc->sda_w(BIT(data, 19) ? 1 : BIT(m_pio, 19)); if (BIT(m_ddr, 20) != BIT(data, 20)) - m_rtc->scl_w(BIT(data, 20) ? 1 : BIT(m_PIO, 20)); + m_rtc->scl_w(BIT(data, 20) ? 1 : BIT(m_pio, 20)); COMBINE_DATA(&m_ddr); } -uint32_t crospuzl_state::PIOldat_r() +u32 crospuzl_state::pio_ldat_r() { - return m_PIO; + return m_pio; } // PIO Latched output DATa Register // TODO: change me -void crospuzl_state::PIOldat_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void crospuzl_state::pio_ldat_w(offs_t offset, u32 data, u32 mem_mask) { if (!BIT(m_ddr, 19)) m_rtc->sda_w(BIT(data, 19)); if (!BIT(m_ddr, 20)) m_rtc->scl_w(BIT(data, 20)); - COMBINE_DATA(&m_PIO); + COMBINE_DATA(&m_pio); } -void crospuzl_state::crospuzl_mem(address_map &map) +void crospuzl_state::main_map(address_map &map) { map(0x00000000, 0x0007ffff).rom().nopw(); - map(0x01500000, 0x01500000).r(FUNC(crospuzl_state::FlashCmd_r)); - map(0x01500100, 0x01500100).w(FUNC(crospuzl_state::FlashCmd_w)); - map(0x01500200, 0x01500200).w(FUNC(crospuzl_state::FlashAddr_w)); + map(0x01500000, 0x01500000).r(FUNC(crospuzl_state::flash_cmd_r)); + map(0x01500100, 0x01500100).w(FUNC(crospuzl_state::flash_cmd_w)); + map(0x01500200, 0x01500200).w(FUNC(crospuzl_state::flash_addr_w)); map(0x01510000, 0x01510003).portr("IN0"); map(0x01511000, 0x01511003).portr("IN1"); map(0x01512000, 0x01512003).portr("IN2"); @@ -199,32 +201,32 @@ void crospuzl_state::crospuzl_mem(address_map &map) map(0x01800000, 0x01ffffff).m(m_vr0soc, FUNC(vrender0soc_device::regs_map)); map(0x0180001c, 0x0180001f).noprw(); - map(0x01802000, 0x01802003).rw(FUNC(crospuzl_state::PIOlddr_r), FUNC(crospuzl_state::PIOlddr_w)); - map(0x01802004, 0x01802007).rw(FUNC(crospuzl_state::PIOldat_r), FUNC(crospuzl_state::PIOldat_w)); - map(0x01802008, 0x0180200b).r(FUNC(crospuzl_state::PIOedat_r)); + map(0x01802000, 0x01802003).rw(FUNC(crospuzl_state::pio_lddr_r), FUNC(crospuzl_state::pio_lddr_w)); + map(0x01802004, 0x01802007).rw(FUNC(crospuzl_state::pio_ldat_r), FUNC(crospuzl_state::pio_ldat_w)); + map(0x01802008, 0x0180200b).r(FUNC(crospuzl_state::pio_edat_r)); - map(0x02000000, 0x027fffff).ram().share("workram"); + map(0x02000000, 0x027fffff).ram().share(m_workram); map(0x03000000, 0x04ffffff).m(m_vr0soc, FUNC(vrender0soc_device::audiovideo_map)); // map(0x05000000, 0x05ffffff).bankr("mainbank"); -// map(0x05000000, 0x05000003).rw(FUNC(crospuzl_state::FlashCmd_r), FUNC(crospuzl_state::FlashCmd_w)); +// map(0x05000000, 0x05000003).rw(FUNC(crospuzl_state::flash_cmd_r), FUNC(crospuzl_state::flash_cmd_w)); } void crospuzl_state::machine_start() { // save_item(NAME(m_Bank)); - save_item(NAME(m_FlashCmd)); - save_item(NAME(m_PIO)); + save_item(NAME(m_flash_cmd)); + save_item(NAME(m_pio)); save_item(NAME(m_ddr)); } void crospuzl_state::machine_reset() { - m_FlashCmd = 0xff; - m_FlashAddr = 0; - m_FlashShift = 0; - m_FlashPrevCommand = 0xff; + m_flash_cmd = 0xff; + m_flash_addr = 0; + m_flash_shift = 0; + m_flash_prev_command = 0xff; m_ddr = 0xffffffff; } @@ -363,18 +365,18 @@ INPUT_PORTS_END void crospuzl_state::crospuzl(machine_config &config) { SE3208(config, m_maincpu, 14318180 * 3); // FIXME: 72 MHz-ish - m_maincpu->set_addrmap(AS_PROGRAM, &crospuzl_state::crospuzl_mem); + m_maincpu->set_addrmap(AS_PROGRAM, &crospuzl_state::main_map); m_maincpu->iackx_cb().set(m_vr0soc, FUNC(vrender0soc_device::irq_callback)); NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0); VRENDER0_SOC(config, m_vr0soc, 14318180 * 6); // FIXME: 72 MHz-ish m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); m_vr0soc->set_external_vclk(14318180 * 2); // Unknown clock, should output ~70 Hz? // ROM strings have references to a K9FXX08 device -// TODO: use this device, in machine/smartmed.h (has issues with is_busy() emulation) +// TODO: use this device, in machine/nandflash.h (has issues with is_busy() emulation) // SAMSUNG_K9F1G08U0B(config, m_nand, 0); // TODO: exact flavor PCF8583(config, m_rtc, 32.768_kHz_XTAL); diff --git a/src/mame/misc/crystal.cpp b/src/mame/misc/crystal.cpp index fca3b647cebe3..50b188c24dd92 100644 --- a/src/mame/misc/crystal.cpp +++ b/src/mame/misc/crystal.cpp @@ -24,6 +24,7 @@ Additional work and refactoring by Angelo Salese TODO: + - Move flash memory implementation into machine/intelfsh.cpp - provide NVRAM defaults where applicable; - add an actual reset button (helps with inp record/playback); - donghaer: needs "raster effect" for 2 players mode split screen, but no @@ -162,7 +163,6 @@ class crystal_state : public driver_device m_maincpu(*this, "maincpu"), m_vr0soc(*this, "vr0soc"), m_ds1302(*this, "rtc"), - m_eeprom(*this, "eeprom"), m_dsw(*this, "DSW"), m_system(*this, "SYSTEM"), m_lamps(*this, "lamp%u", 1U) @@ -185,96 +185,95 @@ class crystal_state : public driver_device private: // memory pointers - required_shared_ptr m_workram; - optional_shared_ptr m_reset_patch; - optional_region_ptr m_flash; + required_shared_ptr m_workram; + required_shared_ptr m_reset_patch; + required_region_ptr m_flash; - optional_memory_bank m_mainbank; + required_memory_bank m_mainbank; // devices required_device m_maincpu; required_device m_vr0soc; required_device m_ds1302; - optional_device m_eeprom; required_ioport m_dsw; required_ioport m_system; output_finder<16> m_lamps; - std::unique_ptr m_dummy_region; + std::unique_ptr m_dummy_region; - uint32_t m_bank; - uint32_t m_maxbank; - uint32_t m_flashcmd; - uint32_t m_pio; + u32 m_bank = 0; + u32 m_maxbank = 0; + u32 m_flashcmd = 0xff; + u32 m_pio = 0; - uint32_t system_input_r(); - void banksw_w(uint32_t data); + u32 system_input_r(); + void banksw_w(u32 data); void lamps_w(offs_t offset, u8 data); - uint32_t flashcmd_r(); - void flashcmd_w(uint32_t data); - void coin_counters_w(uint8_t data); + u32 flashcmd_r(); + void flashcmd_w(u32 data); + void coin_counters_w(u8 data); void patchreset(); - void crystal_mem(address_map &map) ATTR_COLD; + void main_map(address_map &map) ATTR_COLD; // PIO - uint32_t pioldat_r(); - void pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t pioedat_r(); + u32 pioldat_r(); + void pioldat_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 pioedat_r(); }; -uint32_t crystal_state::system_input_r() +u32 crystal_state::system_input_r() { return (m_system->read() << 16) | (m_dsw->read()) | 0xff00ff00; } -void crystal_state::banksw_w(uint32_t data) +void crystal_state::banksw_w(u32 data) { m_bank = (data >> 1) & 7; m_mainbank->set_entry(m_bank); } -void crystal_state::lamps_w(offs_t offset, uint8_t data) +void crystal_state::lamps_w(offs_t offset, u8 data) { for (unsigned i = 0; 8 > i; ++i) m_lamps[(offset << 3) | i] = BIT(data, i); } -uint32_t crystal_state::pioldat_r() +u32 crystal_state::pioldat_r() { return m_pio; } // PIO Latched output DATa Register -void crystal_state::pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void crystal_state::pioldat_w(offs_t offset, u32 data, u32 mem_mask) { - const uint32_t RST = BIT(data, 24); - const uint32_t CLK = BIT(data, 25); - const uint32_t DAT = BIT(data, 28); + const u32 rst = BIT(data, 24); + const u32 clk = BIT(data, 25); + const u32 dat = BIT(data, 28); - m_ds1302->ce_w(RST); - m_ds1302->io_w(DAT); - m_ds1302->sclk_w(CLK); + m_ds1302->ce_w(rst); + m_ds1302->io_w(dat); + m_ds1302->sclk_w(clk); COMBINE_DATA(&m_pio); } // PIO External DATa Register -uint32_t crystal_state::pioedat_r() +u32 crystal_state::pioedat_r() { return m_ds1302->io_r() << 28; } -uint32_t crystal_state::flashcmd_r() +u32 crystal_state::flashcmd_r() { if ((m_flashcmd & 0xff) == 0xff) { if (m_bank < m_maxbank) { - uint32_t *ptr = (uint32_t*)(m_mainbank->base()); + u32 *ptr = (u32*)(m_mainbank->base()); return ptr[0]; } else @@ -290,12 +289,12 @@ uint32_t crystal_state::flashcmd_r() return 0; } -void crystal_state::flashcmd_w(uint32_t data) +void crystal_state::flashcmd_w(u32 data) { m_flashcmd = data; } -void crystal_state::coin_counters_w(uint8_t data) +void crystal_state::coin_counters_w(u8 data) { // Both signals are sent when setting is "1 shooter" // Only evosocc and crysking allow the user to change this setting. @@ -303,7 +302,7 @@ void crystal_state::coin_counters_w(uint8_t data) machine().bookkeeping().coin_counter_w(1, BIT(data, 1)); } -void crystal_state::crystal_mem(address_map &map) +void crystal_state::main_map(address_map &map) { map(0x00000000, 0x0001ffff).rom().nopw(); @@ -321,14 +320,14 @@ void crystal_state::crystal_mem(address_map &map) map(0x01802008, 0x0180200b).r(FUNC(crystal_state::pioedat_r)); // mirror is accessed by donghaer on later levels - map(0x02000000, 0x027fffff).mirror(0x00800000).ram().share("workram"); + map(0x02000000, 0x027fffff).mirror(0x00800000).ram().share(m_workram); map(0x03000000, 0x04ffffff).m(m_vr0soc, FUNC(vrender0soc_device::audiovideo_map)); - map(0x05000000, 0x05ffffff).bankr("mainbank"); + map(0x05000000, 0x05ffffff).bankr(m_mainbank); map(0x05000000, 0x05000003).rw(FUNC(crystal_state::flashcmd_r), FUNC(crystal_state::flashcmd_w)); - map(0x44414f4c, 0x44414f7f).ram().share("reset_patch"); + map(0x44414f4c, 0x44414f7f).ram().share(m_reset_patch); } void crystal_state::patchreset() @@ -360,7 +359,7 @@ void crystal_state::patchreset() #if 1 - static const uint32_t patch[] = + static const u32 patch[] = { 0x40c0ea01, 0xe906400a, @@ -372,7 +371,7 @@ void crystal_state::patchreset() memcpy(m_reset_patch, patch, sizeof(patch)); #else - static const uint8_t patch[] = + static const u8 patch[] = { 0x01,0xea,0xc0,0x40,0x0a,0x40,0x06,0xe9, 0x20,0x2a,0xc0,0x40,0x0a,0x40,0x06,0xe9, @@ -392,9 +391,9 @@ void crystal_state::machine_start() if (m_mainbank) { m_maxbank = m_flash ? (m_flash.bytes() / 0x1000000) : 0; - m_dummy_region = std::make_unique(0x1000000); + m_dummy_region = std::make_unique(0x1000000); std::fill_n(&m_dummy_region[0], 0x1000000, 0xff); // 0xff filled at unmapped area - uint8_t *rom = (m_flash) ? (uint8_t *)&m_flash[0] : &m_dummy_region[0]; + u8 *rom = (m_flash) ? (u8 *)&m_flash[0] : &m_dummy_region[0]; for (int i = 0; i < 8; i++) { if ((i < m_maxbank)) @@ -422,8 +421,8 @@ INPUT_CHANGED_MEMBER(crystal_state::coin_inserted) { if (oldval) { - uint8_t coin_chute = (uint8_t)(uintptr_t)param & 1; - m_vr0soc->IntReq(coin_chute ? 19 : 12); + const u8 coin_chute = (u8)(uintptr_t)param & 1; + m_vr0soc->int_req(coin_chute ? 19 : 12); } } @@ -593,14 +592,14 @@ INPUT_PORTS_END void crystal_state::crystal(machine_config &config) { SE3208(config, m_maincpu, 14'318'180 * 3); // TODO : dynamic via PLL - m_maincpu->set_addrmap(AS_PROGRAM, &crystal_state::crystal_mem); + m_maincpu->set_addrmap(AS_PROGRAM, &crystal_state::main_map); m_maincpu->iackx_cb().set(m_vr0soc, FUNC(vrender0soc_device::irq_callback)); NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0); VRENDER0_SOC(config, m_vr0soc, 14'318'180 * 6); // TODO : dynamic via PLL m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); DS1302(config, m_ds1302, 32.768_kHz_XTAL); @@ -727,7 +726,7 @@ loop. Also it seems that bit 0x40000000 is the PIC reset. void crystal_state::init_crysking() { - uint16_t *rom = (uint16_t*) memregion("flash")->base(); + u16 *rom = (u16*) memregion("flash")->base(); //patch the data feed by the protection @@ -746,7 +745,7 @@ void crystal_state::init_crysking() void crystal_state::init_evosocc() { - uint16_t *rom = (uint16_t*) memregion("flash")->base(); + u16 *rom = (u16*) memregion("flash")->base(); rom += 0x1000000 * 2 / 2; rom[WORD_XOR_LE(0x97388e / 2)] = 0x90fc; //PUSH R2..R7 @@ -765,7 +764,7 @@ void crystal_state::init_evosocc() void crystal_state::init_topbladv() { // patches based on analysis of PIC dump - uint16_t *rom = (uint16_t*) memregion("flash")->base(); + u16 *rom = (u16*) memregion("flash")->base(); /* PIC Protection data: - RAM ADDR - --PATCH-- @@ -792,7 +791,7 @@ void crystal_state::init_topbladv() void crystal_state::init_officeye() { // patches based on analysis of PIC dump - uint16_t *rom = (uint16_t*) memregion("flash")->base(); + u16 *rom = (u16*) memregion("flash")->base(); /* PIC Protection data: @@ -818,7 +817,7 @@ void crystal_state::init_officeye() void crystal_state::init_donghaer() { - uint16_t *rom = (uint16_t*)memregion("flash")->base(); + u16 *rom = (u16*)memregion("flash")->base(); rom[WORD_XOR_LE(0x037a2 / 2)] = 0x9004; // PUSH %R2 rom[WORD_XOR_LE(0x037a4 / 2)] = 0x8202; // LD (%SP,0x8),%R2 @@ -835,7 +834,7 @@ void crystal_state::init_donghaer() void crystal_state::init_maldaiza() { - uint16_t *rom = (uint16_t*)memregion("flash")->base(); + u16 *rom = (u16*)memregion("flash")->base(); rom[WORD_XOR_LE(0x09b12 / 2)] = 0x9004; // PUSH %R2 rom[WORD_XOR_LE(0x09b14 / 2)] = 0x8202; // LD (%SP,0x8),%R2 // ... diff --git a/src/mame/misc/ddz.cpp b/src/mame/misc/ddz.cpp index cd36926d2fc93..1dfe6e7736ff4 100644 --- a/src/mame/misc/ddz.cpp +++ b/src/mame/misc/ddz.cpp @@ -79,17 +79,17 @@ class ddz_state : public driver_device virtual void machine_reset() override ATTR_COLD; private: - required_shared_ptr m_workram; - required_region_ptr m_encdata; + required_shared_ptr m_workram; + required_region_ptr m_encdata; required_device m_maincpu; required_device m_vr0soc; - void ddz_mem(address_map &map) ATTR_COLD; + void main_map(address_map &map) ATTR_COLD; }; -void ddz_state::ddz_mem(address_map &map) +void ddz_state::main_map(address_map &map) { map(0x00000000, 0x00ffffff).rom().nopw().region("ipl", 0); @@ -99,7 +99,7 @@ void ddz_state::ddz_mem(address_map &map) map(0x01800000, 0x01ffffff).m(m_vr0soc, FUNC(vrender0soc_device::regs_map)); - map(0x02000000, 0x027fffff).ram().share("workram"); + map(0x02000000, 0x027fffff).ram().share(m_workram); map(0x03000000, 0x04ffffff).m(m_vr0soc, FUNC(vrender0soc_device::audiovideo_map)); } @@ -128,12 +128,12 @@ void ddz_state::machine_reset() void ddz_state::ddz(machine_config &config) { SE3208(config, m_maincpu, 14'318'180 * 3); // TODO : dynamic via PLL - m_maincpu->set_addrmap(AS_PROGRAM, &ddz_state::ddz_mem); + m_maincpu->set_addrmap(AS_PROGRAM, &ddz_state::main_map); m_maincpu->iackx_cb().set(m_vr0soc, FUNC(vrender0soc_device::irq_callback)); VRENDER0_SOC(config, m_vr0soc, 14'318'180 * 6); // TODO : dynamic via PLL m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); SPEAKER(config, "speaker", 2).front(); m_vr0soc->add_route(0, "speaker", 1.0, 0); @@ -219,8 +219,8 @@ ROM_END void ddz_state::init_ddz() { - uint8_t *ipl = reinterpret_cast(memregion("ipl")->base()); - for (uint32_t x = 0; x < m_encdata.bytes(); x += 16) + u8 *ipl = reinterpret_cast(memregion("ipl")->base()); + for (u32 x = 0; x < m_encdata.bytes(); x += 16) { // TODO for (int y = 0; y < 16; y++) diff --git a/src/mame/misc/menghong.cpp b/src/mame/misc/menghong.cpp index 63e6ac36e9c18..3f96f1e727079 100644 --- a/src/mame/misc/menghong.cpp +++ b/src/mame/misc/menghong.cpp @@ -7,6 +7,7 @@ driver by Angelo Salese, based off original crystal.cpp by ElSemi TODO: + - Move flash memory implementation into machine/intelfsh.cpp - HY04 protection (controls tile RNG, 8bpp colors, a few program flow bits) - 8bpp colors are washed, data from flash ROMs is XORed with contents of NVRAM area 0x1400070b-80f in menghong, might be shared with @@ -127,8 +128,8 @@ class menghong_state : public driver_device private: // memory pointers - required_shared_ptr m_workram; - required_region_ptr m_flash; + required_shared_ptr m_workram; + required_region_ptr m_flash; required_memory_bank m_mainbank; // devices @@ -137,53 +138,54 @@ class menghong_state : public driver_device // required_device m_nvram; required_device m_ds1302; required_device m_eeprom; - required_region_ptr m_prot_data; + required_region_ptr m_prot_data; // inputs required_ioport_array<5> m_keys; - uint32_t m_bank; - uint32_t m_maxbank; - uint32_t m_flashcmd; + u32 m_bank = 0; + u32 m_maxbank = 0; + u32 m_flashcmd = 0xff; + u32 m_pio = 0; + u8 m_prot = 0; - void banksw_w(uint32_t data); - uint32_t flashcmd_r(); - void flashcmd_w(uint32_t data); + std::unique_ptr m_sharedram; - uint32_t key_r(); + void banksw_w(u32 data); + u32 flashcmd_r(); + void flashcmd_w(u32 data); - void menghong_mem(address_map &map) ATTR_COLD; - void crzyddz2_mem(address_map &map) ATTR_COLD; + u32 key_r(); // pio - uint32_t pioldat_r(); - uint32_t m_pio; - void pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t pioedat_r(); - uint8_t m_prot; - - uint8_t menghong_shared_r(offs_t offset); - void menghong_shared_w(offs_t offset, uint8_t data); - uint8_t crzyddz2_shared_r(offs_t offset); - void crzyddz2_shared_w(offs_t offset, uint8_t data); - std::unique_ptr m_sharedram; + u32 pioldat_r(); + void pioldat_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 pioedat_r(); + + u8 menghong_shared_r(offs_t offset); + void menghong_shared_w(offs_t offset, u8 data); + u8 crzyddz2_shared_r(offs_t offset); + void crzyddz2_shared_w(offs_t offset, u8 data); + + void menghong_mem(address_map &map) ATTR_COLD; + void crzyddz2_mem(address_map &map) ATTR_COLD; }; -void menghong_state::banksw_w(uint32_t data) +void menghong_state::banksw_w(u32 data) { m_bank = (data >> 1) & 7; m_mainbank->set_entry(m_bank); } -uint32_t menghong_state::flashcmd_r() +u32 menghong_state::flashcmd_r() { if ((m_flashcmd & 0xff) == 0xff) { if (m_bank < m_maxbank) { - uint32_t *ptr = (uint32_t*)(m_mainbank->base()); + u32 *ptr = (u32*)(m_mainbank->base()); return ptr[0]; } else @@ -199,7 +201,7 @@ uint32_t menghong_state::flashcmd_r() return 0; } -void menghong_state::flashcmd_w(uint32_t data) +void menghong_state::flashcmd_w(u32 data) { m_flashcmd = data; } @@ -209,12 +211,12 @@ void menghong_state::flashcmd_w(uint32_t data) // Crazy Dou Di Zhu II // To do: HY04 (pic?) protection, 93C46 hookup -uint8_t menghong_state::menghong_shared_r(offs_t offset) +u8 menghong_state::menghong_shared_r(offs_t offset) { return m_sharedram[offset]; } -void menghong_state::menghong_shared_w(offs_t offset, uint8_t data) +void menghong_state::menghong_shared_w(offs_t offset, u8 data) { m_sharedram[offset] = data; @@ -229,8 +231,8 @@ void menghong_state::menghong_shared_w(offs_t offset, uint8_t data) // we conveniently use an handcrafted ROM here, created by guessing colors from // transparencies and shading. // This will be useful for comparison when the actual PIC data will be extracted. - for (int i=0;i<0x100;i++) - m_sharedram[i+0x70c] = m_prot_data[i]; + for (int i = 0; i < 0x100; i++) + m_sharedram[i + 0x70c] = m_prot_data[i]; // MCU also has a part in providing RNG // hold service1 while selecting makes the user select "a set" (location in NVRAM tbd) @@ -243,19 +245,19 @@ void menghong_state::menghong_shared_w(offs_t offset, uint8_t data) } } -uint8_t menghong_state::crzyddz2_shared_r(offs_t offset) +u8 menghong_state::crzyddz2_shared_r(offs_t offset) { return m_sharedram[offset]; } -void menghong_state::crzyddz2_shared_w(offs_t offset, uint8_t data) +void menghong_state::crzyddz2_shared_w(offs_t offset, u8 data) { m_sharedram[offset] = data; // State machine is unconfirmed if (offset == 0x7e3) { - switch(data) + switch (data) { case 0x00: m_sharedram[0x650] = 0x00; // prints 93c46 error otherwise @@ -266,8 +268,8 @@ void menghong_state::crzyddz2_shared_w(offs_t offset, uint8_t data) // at PC=0x2011f9a, expecting a value of 0x7ebe otherwise locks up // after Sealy logo. Every single value is added to the routine and left // shifted by 1 (including the two values above) - for(int i=0;i<0x3f;i++) - m_sharedram[i+0x652] = 0xff; + for(int i = 0; i < 0x3f; i++) + m_sharedram[i + 0x652] = 0xff; m_sharedram[0x691] = 0x9b; break; // additional locking protection is also applied with RNG feature @@ -276,25 +278,25 @@ void menghong_state::crzyddz2_shared_w(offs_t offset, uint8_t data) } } -uint32_t menghong_state::pioldat_r() +u32 menghong_state::pioldat_r() { return m_pio; } -void menghong_state::pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void menghong_state::pioldat_w(offs_t offset, u32 data, u32 mem_mask) { COMBINE_DATA(&m_pio); - //uint32_t RST = data & 0x01000000; - //uint32_t CLK = data & 0x02000000; - //uint32_t DAT = data & 0x10000000; + //const u32 rst = BIT(data, 24); + //const u32 clk = BIT(data, 25); + //const u32 dat = BIT(data, 28); -// m_eeprom->cs_write(RST ? 1 : 0); -// m_eeprom->di_write(DAT ? 1 : 0); -// m_eeprom->clk_write(CLK ? 1 : 0); +// m_eeprom->cs_write(rst); +// m_eeprom->di_write(dat); +// m_eeprom->clk_write(clk); if (ACCESSING_BITS_8_15) { - int mux = (m_pio >> 8) & 0x1f; + const int mux = (m_pio >> 8) & 0x1f; if (mux == 0x1f) { m_prot = ((m_pio >> 8) & 0xc0) ^ 0x40; @@ -303,18 +305,18 @@ void menghong_state::pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask) } } -uint32_t menghong_state::pioedat_r() +u32 menghong_state::pioedat_r() { return 0;//m_eeprom->do_read(); } -uint32_t menghong_state::key_r() +u32 menghong_state::key_r() { - int mux = (m_pio >> 8) & 0x1f; + const int mux = (m_pio >> 8) & 0x1f; - uint8_t data = 0x3f; + u8 data = 0x3f; for (int i = 0; i < m_keys.size(); ++i) - if (!BIT(mux,i)) + if (!BIT(mux, i)) data = m_keys[i]->read(); /* @@ -362,12 +364,12 @@ void menghong_state::crzyddz2_mem(address_map &map) void menghong_state::machine_start() { - m_sharedram = make_unique_clear(0x10000); + m_sharedram = make_unique_clear(0x10000); m_maxbank = (m_flash) ? m_flash.bytes() / 0x1000000 : 0; - std::unique_ptr dummy_region = std::make_unique(0x1000000); + std::unique_ptr dummy_region = std::make_unique(0x1000000); std::fill_n(&dummy_region[0], 0x1000000, 0xff); // 0xff Filled at Unmapped area - uint8_t *rom = (m_flash) ? (uint8_t *)&m_flash[0] : dummy_region.get(); + u8 *rom = (m_flash) ? (u8 *)&m_flash[0] : dummy_region.get(); for (int i = 0; i < 8; i++) { if (i < m_maxbank) @@ -495,7 +497,7 @@ void menghong_state::menghong(machine_config &config) VRENDER0_SOC(config, m_vr0soc, 14318180 * 6); // TODO : dynamic via PLL m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); m_vr0soc->set_external_vclk(28636360); // Assumed from the only available XTal on PCB DS1302(config, m_ds1302, 32.768_kHz_XTAL); diff --git a/src/mame/misc/psattack.cpp b/src/mame/misc/psattack.cpp index 2d6aba3ac3b7d..b55d03e022a55 100644 --- a/src/mame/misc/psattack.cpp +++ b/src/mame/misc/psattack.cpp @@ -150,53 +150,54 @@ class psattack_state : public driver_device void init_psattack(); - void psattack(machine_config &config); + void psattack(machine_config &config) ATTR_COLD; -private: +protected: + virtual void machine_start() override ATTR_COLD; + virtual void machine_reset() override ATTR_COLD; +private: /* memory pointers */ - required_shared_ptr m_workram; + required_shared_ptr m_workram; /* devices */ required_device m_maincpu; required_device m_vr0soc; required_device m_ata; - virtual void machine_start() override ATTR_COLD; - virtual void machine_reset() override ATTR_COLD; - void psattack_mem(address_map &map) ATTR_COLD; + void main_map(address_map &map) ATTR_COLD; - uint16_t cfcard_data_r(); - uint8_t cfcard_regs_r(offs_t offset); - void cfcard_regs_w(offs_t offset, uint8_t data); - void output_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); + u16 cfcard_data_r(); + u8 cfcard_regs_r(offs_t offset); + void cfcard_regs_w(offs_t offset, u8 data); + void output_w(offs_t offset, u32 data, u32 mem_mask = ~0); }; // TODO: wrong, likely PIC protected too -uint8_t psattack_state::cfcard_regs_r(offs_t offset) +u8 psattack_state::cfcard_regs_r(offs_t offset) { return m_ata->cs0_r(offset & 7, 0x000000ff); } -void psattack_state::cfcard_regs_w(offs_t offset, uint8_t data) +void psattack_state::cfcard_regs_w(offs_t offset, u8 data) { m_ata->cs0_w(offset & 7, 0x000000ff); } -uint16_t psattack_state::cfcard_data_r() +u16 psattack_state::cfcard_data_r() { // TODO: may not be it (pushes data into stack then never read it other than a comparison check from +0xfc) return m_ata->cs0_r(0, 0x0000ffff); } -void psattack_state::output_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void psattack_state::output_w(offs_t offset, u32 data, u32 mem_mask) { // suppress logging for now if (data) - logerror("output_w: %08x & %08x\n",data,mem_mask); + logerror("%s: output_w: %08x & %08x\n", machine().describe_context(), data, mem_mask); } -void psattack_state::psattack_mem(address_map &map) +void psattack_state::main_map(address_map &map) { map(0x00000000, 0x001fffff).rom().nopw(); @@ -214,7 +215,7 @@ void psattack_state::psattack_mem(address_map &map) map(0x01800000, 0x01ffffff).m(m_vr0soc, FUNC(vrender0soc_device::regs_map)); // map(0x01802410, 0x01802413) peripheral chip select for cf? - map(0x02000000, 0x027fffff).ram().share("workram"); + map(0x02000000, 0x027fffff).ram().share(m_workram); map(0x03000000, 0x04ffffff).m(m_vr0soc, FUNC(vrender0soc_device::audiovideo_map)); } @@ -243,14 +244,14 @@ void psattack_state::machine_reset() void psattack_state::psattack(machine_config &config) { SE3208(config, m_maincpu, 14318180 * 3); // TODO : dynamic via PLL - m_maincpu->set_addrmap(AS_PROGRAM, &psattack_state::psattack_mem); + m_maincpu->set_addrmap(AS_PROGRAM, &psattack_state::main_map); m_maincpu->iackx_cb().set(m_vr0soc, FUNC(vrender0soc_device::irq_callback)); // PIC16C711 VRENDER0_SOC(config, m_vr0soc, 14318180 * 6); // TODO : dynamic via PLL m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); m_vr0soc->set_external_vclk(XTAL(25'175'000)); // assumed from the only available XTal on PCB ATA_INTERFACE(config, m_ata).options(ata_devices, "hdd", nullptr, true); diff --git a/src/mame/misc/trivrus.cpp b/src/mame/misc/trivrus.cpp index 861adf8314369..f40177d2cd2e0 100644 --- a/src/mame/misc/trivrus.cpp +++ b/src/mame/misc/trivrus.cpp @@ -8,6 +8,7 @@ original mods on this driver by Luca Elia TODO: + - Move flash memory implementation into machine/intelfsh.cpp - touch panel, according to service mode can be generic, atouch or 3M (microtouch?). It interfaces thru UART0 port; - RTC (unknown type); @@ -47,7 +48,7 @@ class trivrus_state : public driver_device { } - void trivrus(machine_config &config); + void trivrus(machine_config &config) ATTR_COLD; protected: virtual void machine_start() override ATTR_COLD; @@ -55,8 +56,8 @@ class trivrus_state : public driver_device private: // memory pointers - required_shared_ptr m_workram; - required_region_ptr m_flash; + required_shared_ptr m_workram; + required_region_ptr m_flash; // devices required_device m_maincpu; @@ -68,54 +69,55 @@ class trivrus_state : public driver_device required_ioport_array<5> m_inputs; required_ioport m_dsw; - uint32_t m_flashcmd; - uint32_t m_bank; - uint32_t m_maxbank; + u32 m_flashcmd = 0; + u32 m_bank = 0; + u32 m_maxbank = 0; - uint32_t flashcmd_r(); - void flashcmd_w(uint32_t data); - void banksw_w(uint32_t data); + u32 m_pio = 0; + u8 m_input_sel = 0; - void trivrus_mem(address_map &map) ATTR_COLD; + u32 flashcmd_r(); + void flashcmd_w(u32 data); + void banksw_w(u32 data); + + void main_map(address_map &map) ATTR_COLD; // pio - uint32_t pioldat_r(); - uint32_t m_pio; - void pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t pioedat_r(); - - uint8_t trivrus_input_r(); - void trivrus_input_w(uint8_t data); - uint8_t m_trivrus_input; + u32 pioldat_r(); + void pioldat_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 pioedat_r(); + + u8 input_sel_r(); + void input_sel_w(u8 data); }; -void trivrus_state::flashcmd_w(uint32_t data) +void trivrus_state::flashcmd_w(u32 data) { m_flashcmd = data; } -uint32_t trivrus_state::pioedat_r() +u32 trivrus_state::pioedat_r() { return 0; } -uint32_t trivrus_state::pioldat_r() +u32 trivrus_state::pioldat_r() { // ... return m_pio; } // pio Latched output DATa Register -void trivrus_state::pioldat_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void trivrus_state::pioldat_w(offs_t offset, u32 data, u32 mem_mask) { // ... COMBINE_DATA(&m_pio); } -uint8_t trivrus_state::trivrus_input_r() +u8 trivrus_state::input_sel_r() { - switch (m_trivrus_input) + switch (m_input_sel) { case 1: return m_inputs[0]->read(); case 2: return m_inputs[1]->read(); @@ -124,22 +126,23 @@ uint8_t trivrus_state::trivrus_input_r() case 5: return m_inputs[4]->read(); case 6: return m_dsw->read(); } - logerror("%s: unknown input %02x read\n", machine().describe_context(), m_trivrus_input); + if (!machine().side_effects_disabled()) + logerror("%s: unknown input %02x read\n", machine().describe_context(), m_input_sel); return 0xff; } -void trivrus_state::trivrus_input_w(uint8_t data) +void trivrus_state::input_sel_w(u8 data) { - m_trivrus_input = data; + m_input_sel = data; } -uint32_t trivrus_state::flashcmd_r() +u32 trivrus_state::flashcmd_r() { if ((m_flashcmd & 0xff) == 0xff) { if (m_bank < m_maxbank) { - uint32_t *ptr = (uint32_t*)(m_mainbank->base()); + u32 *ptr = (u32*)(m_mainbank->base()); return ptr[0]; } else @@ -156,19 +159,19 @@ uint32_t trivrus_state::flashcmd_r() } -void trivrus_state::banksw_w(uint32_t data) +void trivrus_state::banksw_w(u32 data) { m_bank = (data >> 1) & 7; m_mainbank->set_entry(m_bank); } -void trivrus_state::trivrus_mem(address_map &map) +void trivrus_state::main_map(address_map &map) { map(0x00000000, 0x0007ffff).rom().nopw(); map(0x01280000, 0x01280003).w(FUNC(trivrus_state::banksw_w)); - map(0x01500000, 0x01500000).rw(FUNC(trivrus_state::trivrus_input_r), FUNC(trivrus_state::trivrus_input_w)); + map(0x01500000, 0x01500000).rw(FUNC(trivrus_state::input_sel_r), FUNC(trivrus_state::input_sel_w)); // reads occurs by SELECTING the given register on successive ODD addresses then reading at 0x01500011 // bit 0 of 1500010 looks some kind of busy flag (game tight loops if on) // on write: @@ -197,9 +200,9 @@ void trivrus_state::trivrus_mem(address_map &map) void trivrus_state::machine_start() { m_maxbank = (m_flash) ? m_flash.bytes() / 0x1000000 : 0; - std::unique_ptr dummy_region = std::make_unique(0x1000000); + std::unique_ptr dummy_region = std::make_unique(0x1000000); std::fill_n(&dummy_region[0], 0x1000000, 0xff); // 0xff Filled at Unmapped area - uint8_t *rom = (m_flash) ? (uint8_t *)&m_flash[0] : dummy_region.get(); + u8 *rom = (m_flash) ? (u8 *)&m_flash[0] : dummy_region.get(); for (int i = 0; i < 8; i++) { if (i < m_maxbank) @@ -211,7 +214,7 @@ void trivrus_state::machine_start() save_item(NAME(m_bank)); save_item(NAME(m_flashcmd)); save_item(NAME(m_pio)); - save_item(NAME(m_trivrus_input)); + save_item(NAME(m_input_sel)); } void trivrus_state::machine_reset() @@ -295,14 +298,14 @@ INPUT_PORTS_END void trivrus_state::trivrus(machine_config &config) { SE3208(config, m_maincpu, 14318180 * 3); // unknown clock - m_maincpu->set_addrmap(AS_PROGRAM, &trivrus_state::trivrus_mem); + m_maincpu->set_addrmap(AS_PROGRAM, &trivrus_state::main_map); m_maincpu->iackx_cb().set(m_vr0soc, FUNC(vrender0soc_device::irq_callback)); NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0); VRENDER0_SOC(config, m_vr0soc, 14318180 * 6); // unknown clock m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); m_vr0soc->set_external_vclk(28636360); m_vr0soc->tx_callback<0>().set(m_microtouch, FUNC(microtouch_device::rx)); diff --git a/src/mame/misc/v0bowl.cpp b/src/mame/misc/v0bowl.cpp index 0cda7c23efa35..2e70412e3580e 100644 --- a/src/mame/misc/v0bowl.cpp +++ b/src/mame/misc/v0bowl.cpp @@ -30,7 +30,7 @@ class v0bowl_state : public driver_device , m_vr0soc(*this, "vr0soc") {} - void v0bowl(machine_config &config); + void v0bowl(machine_config &config) ATTR_COLD; protected: // driver_device overrides @@ -138,7 +138,7 @@ void v0bowl_state::v0bowl(machine_config &config) VRENDER0_SOC(config, m_vr0soc, 14318180 * 6); m_vr0soc->set_host_space_tag(m_maincpu, AS_PROGRAM); - m_vr0soc->int_callback().set_inputline(m_maincpu, SE3208_INT); + m_vr0soc->int_callback().set_inputline(m_maincpu, se3208_device::SE3208_INT); SPEAKER(config, "speaker", 2).front(); m_vr0soc->add_route(0, "speaker", 1.0, 0);