diff options
author | 2016-11-19 08:40:36 +1100 | |
---|---|---|
committer | 2016-11-19 08:40:36 +1100 | |
commit | 53ef979d6342707434fe3845e71f3d7a01155d9c (patch) | |
tree | 6eace2582e1f3ad2522e110d4201441a5f1c2bc5 /src/devices/cpu | |
parent | 539196cd977a37ff43c93eaeda3acf91455018a7 (diff) | |
parent | 8566c9cfe9a83dcd45ccb625920209f5f933b897 (diff) |
Merge pull request #1737 from npwoods/dasmstream_tms57002
Changed the tms57002 disassembler to use 'std::ostream &' internally
Diffstat (limited to 'src/devices/cpu')
-rw-r--r-- | src/devices/cpu/tms57002/57002dsm.cpp | 54 | ||||
-rwxr-xr-x | src/devices/cpu/tms57002/tmsmake.py | 2 |
2 files changed, 28 insertions, 28 deletions
diff --git a/src/devices/cpu/tms57002/57002dsm.cpp b/src/devices/cpu/tms57002/57002dsm.cpp index 4b03fff991d..0bec39e16c7 100644 --- a/src/devices/cpu/tms57002/57002dsm.cpp +++ b/src/devices/cpu/tms57002/57002dsm.cpp @@ -12,35 +12,30 @@ #include "debugger.h" #include "tms57002.h" -static const char *get_memadr(uint32_t opcode, char type) +static std::string get_memadr(uint32_t opcode, char type) { - static char buff[2][10]; - static int index = 0; - char *buf; - - index = 1-index; - buf = buff[index]; + std::string buf; if(((opcode & 0x400) && (type == 'c')) || (!(opcode & 0x400) && (type == 'd'))) { if(opcode & 0x100) - sprintf(buf, "%c(%02x)", type, opcode & 0xff); + buf = util::string_format("%c(%02x)", type, opcode & 0xff); else if(opcode & 0x80) - sprintf(buf, "%c*+", type); + buf = util::string_format("%c*+", type); else - sprintf(buf, "%c*", type); + buf = util::string_format("%c*", type); } else if(opcode & 0x200) - sprintf(buf, "%c*+", type); + buf = util::string_format("%c*+", type); else - sprintf(buf, "%c*", type); + buf = util::string_format("%c*", type); return buf; } -CPU_DISASSEMBLE(tms57002) +static offs_t internal_disasm_tms57002(cpu_device *device, std::ostream &stream, offs_t pc, const uint8_t *oprom, const uint8_t *opram, int options) { + std::streampos original_pos = stream.tellp(); uint32_t opcode = opram[0] | (opram[1] << 8) | (opram[2] << 16); uint8_t fa = opcode >> 18; - char *buf = buffer; if(fa == 0x3f) { switch((opcode >> 11) & 0x7f) { // category 3 @@ -49,13 +44,12 @@ CPU_DISASSEMBLE(tms57002) #undef DASM3 default: - sprintf(buf, "unk c3 %02x", (opcode >> 11) & 0x7f); + util::stream_format(stream, "unk c3 %02x", (opcode >> 11) & 0x7f); break; } } else { switch(fa) { // category 1 case 0x00: - buf[0] = 0; break; #define DASM1 @@ -63,22 +57,18 @@ CPU_DISASSEMBLE(tms57002) #undef DASM1 default: - sprintf(buf, "unk c1 %02x", fa); + util::stream_format(stream, "unk c1 %02x", fa); break; } - buf += strlen(buf); - if(buf != buffer) { - strcpy(buf, " ; "); - buf += 3; - } + bool next_is_nop = ((opcode >> 11) & 0x7f) == 0x00; + if (!next_is_nop && stream.tellp() != original_pos) + stream << " ; "; switch((opcode >> 11) & 0x7f) { // category 2 case 0x00: - if(buf != buffer) - buf[-3] = 0; - else - sprintf(buf, "nop"); + if (stream.tellp() == original_pos) + util::stream_format(stream, "nop"); break; #define DASM2 @@ -86,10 +76,20 @@ CPU_DISASSEMBLE(tms57002) #undef DASM2 default: - sprintf(buf, "unk c2 %02x", (opcode >> 11) & 0x7f); + util::stream_format(stream, "unk c2 %02x", (opcode >> 11) & 0x7f); break; } } return 1; } + + +CPU_DISASSEMBLE(tms57002) +{ + std::ostringstream stream; + offs_t result = internal_disasm_tms57002(device, stream, pc, oprom, opram, options); + std::string stream_str = stream.str(); + strcpy(buffer, stream_str.c_str()); + return result; +} diff --git a/src/devices/cpu/tms57002/tmsmake.py b/src/devices/cpu/tms57002/tmsmake.py index 1aaa0fc59e4..19336061c11 100755 --- a/src/devices/cpu/tms57002/tmsmake.py +++ b/src/devices/cpu/tms57002/tmsmake.py @@ -206,7 +206,7 @@ class Instruction: opcode, args = self.GetDasmInfo() args = [", " + a for a in args] print("%scase 0x%02x:" % (prefix, self._id), file=f) - print("%s sprintf(buf, \"%s\"%s);" % (prefix, opcode, "".join(args)), file=f) + print("%s util::stream_format(stream, \"%s\"%s);" % (prefix, opcode, "".join(args)), file=f) print("%s break;" % prefix, file=f) |