summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-11-18 08:56:53 -0500
committer Nathan Woods <npwoods@mess.org>2016-11-18 08:56:53 -0500
commitd8b4f2171453158390e410b6be6cd25876f7e3e1 (patch)
treea57887469a0c26a5468e9676adf44ad32965feef /src/devices/cpu
parentbb99eba11dadfa37acb2a796f4f8e2b0a7330e44 (diff)
Changed the upd7810 disassembler to use 'std::ostream &' internally
Diffstat (limited to 'src/devices/cpu')
-rw-r--r--src/devices/cpu/upd7810/upd7810_dasm.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/devices/cpu/upd7810/upd7810_dasm.cpp b/src/devices/cpu/upd7810/upd7810_dasm.cpp
index 0beed6a01d3..2988a8d63f0 100644
--- a/src/devices/cpu/upd7810/upd7810_dasm.cpp
+++ b/src/devices/cpu/upd7810/upd7810_dasm.cpp
@@ -5416,7 +5416,7 @@ const char *const regname[32] =
"illegal", "TMM", "PT", "illegal"
};
-offs_t Dasm( char *buffer, offs_t pc, const dasm_s (&dasmXX)[256], const uint8_t *oprom, const uint8_t *opram, int is_7810 )
+offs_t Dasm( std::ostream &stream, offs_t pc, const dasm_s (&dasmXX)[256], const uint8_t *oprom, const uint8_t *opram, bool is_7810 )
{
unsigned idx = 0;
const uint8_t op = oprom[idx++];
@@ -5424,7 +5424,7 @@ offs_t Dasm( char *buffer, offs_t pc, const dasm_s (&dasmXX)[256], const uint8_t
if (desc->is_prefix())
desc = &desc->prefix_get(oprom[idx++]);
- buffer += sprintf(buffer, "%-8.8s", desc->name());
+ util::stream_format(stream, "%-8.8s", desc->name());
uint32_t flags = desc->is_call() ? DASMFLAG_STEP_OVER : desc->is_return() ? DASMFLAG_STEP_OUT : 0;
uint8_t op2;
@@ -5440,68 +5440,76 @@ offs_t Dasm( char *buffer, offs_t pc, const dasm_s (&dasmXX)[256], const uint8_t
{
case 'a': /* address V * 256 + offset */
op2 = opram[idx++];
- buffer += sprintf(buffer, "VV:%02X", op2);
+ util::stream_format(stream, "VV:%02X", op2);
break;
case 'b': /* immediate byte */
- buffer += sprintf(buffer, "$%02X", opram[idx++]);
+ util::stream_format(stream, "$%02X", opram[idx++]);
break;
case 'w': /* immediate word */
ea = opram[idx++];
ea += opram[idx++] << 8;
- buffer += sprintf(buffer, "$%04X", ea);
+ util::stream_format(stream, "$%04X", ea);
break;
case 'd': /* JRE address */
op2 = oprom[idx++];
offset = (op & 1) ? -(256 - op2): + op2;
- buffer += sprintf(buffer, "$%04X", ( pc + idx + offset ) & 0xFFFF );
+ util::stream_format(stream, "$%04X", ( pc + idx + offset ) & 0xFFFF );
break;
case 't': /* CALT address */
ea = 0x80 + 2 * (op & (is_7810 ? 0x1f : 0x3f));
- buffer += sprintf(buffer, "($%04X)", ea);
+ util::stream_format(stream, "($%04X)", ea);
break;
case 'f': /* CALF address */
op2 = oprom[idx++];
ea = 0x800 + 0x100 * (op & 0x07) + op2;
- buffer += sprintf(buffer, "$%04X", ea);
+ util::stream_format(stream, "$%04X", ea);
break;
case 'o': /* JR offset */
offset = ( ( op & 0x20 ) ? -0x20 : 0 ) + ( op & 0x1F );
- buffer += sprintf(buffer, "$%04X", ( pc + idx + offset ) & 0xFFFF );
+ util::stream_format(stream, "$%04X", ( pc + idx + offset ) & 0xFFFF );
break;
case 'i': /* bit manipulation */
op2 = oprom[idx++];
- buffer += sprintf(buffer, "%s,%d", regname[op2 & 0x1f], op2 >> 5);
+ util::stream_format(stream, "%s,%d", regname[op2 & 0x1f], op2 >> 5);
break;
default:
- *buffer++ = *a;
+ stream << *a;
}
}
else
- *buffer++ = *a;
+ stream << *a;
}
- *buffer = '\0';
return idx | flags | DASMFLAG_SUPPORTED;
}
+offs_t Dasm(char *buffer, offs_t pc, const dasm_s(&dasmXX)[256], const uint8_t *oprom, const uint8_t *opram, bool is_7810)
+{
+ std::ostringstream stream;
+ offs_t result = Dasm(stream, pc, dasmXX, oprom, opram, is_7810);
+ std::string stream_str = stream.str();
+ strcpy(buffer, stream_str.c_str());
+ return result;
+}
+
} // anonymous namespace
CPU_DISASSEMBLE( upd7810 )
{
- return Dasm( buffer, pc, dasm_s::XX_7810, oprom, opram, 1 );
+ return Dasm( buffer, pc, dasm_s::XX_7810, oprom, opram, true );
}
CPU_DISASSEMBLE( upd7807 )
{
- return Dasm( buffer, pc, dasm_s::XX_7807, oprom, opram, 1 );
+ return Dasm( buffer, pc, dasm_s::XX_7807, oprom, opram, true );
}
CPU_DISASSEMBLE( upd7801 )
{
- return Dasm( buffer, pc, dasm_s::XX_7801, oprom, opram, 0 );
+ return Dasm( buffer, pc, dasm_s::XX_7801, oprom, opram, false );
}
CPU_DISASSEMBLE( upd78c05 )
{
- return Dasm( buffer, pc, dasm_s::XX_78c05, oprom, opram, 0 );
+ return Dasm( buffer, pc, dasm_s::XX_78c05, oprom, opram, false );
}