Changed the upd7810 disassembler to use 'std::ostream &' internally

This commit is contained in:
Nathan Woods 2016-11-18 08:56:53 -05:00
parent bb99eba11d
commit d8b4f21714

View File

@ -5416,7 +5416,7 @@ const char *const regname[32] =
"illegal", "TMM", "PT", "illegal" "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; unsigned idx = 0;
const uint8_t op = oprom[idx++]; 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()) if (desc->is_prefix())
desc = &desc->prefix_get(oprom[idx++]); 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; uint32_t flags = desc->is_call() ? DASMFLAG_STEP_OVER : desc->is_return() ? DASMFLAG_STEP_OUT : 0;
uint8_t op2; 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 */ case 'a': /* address V * 256 + offset */
op2 = opram[idx++]; op2 = opram[idx++];
buffer += sprintf(buffer, "VV:%02X", op2); util::stream_format(stream, "VV:%02X", op2);
break; break;
case 'b': /* immediate byte */ case 'b': /* immediate byte */
buffer += sprintf(buffer, "$%02X", opram[idx++]); util::stream_format(stream, "$%02X", opram[idx++]);
break; break;
case 'w': /* immediate word */ case 'w': /* immediate word */
ea = opram[idx++]; ea = opram[idx++];
ea += opram[idx++] << 8; ea += opram[idx++] << 8;
buffer += sprintf(buffer, "$%04X", ea); util::stream_format(stream, "$%04X", ea);
break; break;
case 'd': /* JRE address */ case 'd': /* JRE address */
op2 = oprom[idx++]; op2 = oprom[idx++];
offset = (op & 1) ? -(256 - op2): + op2; offset = (op & 1) ? -(256 - op2): + op2;
buffer += sprintf(buffer, "$%04X", ( pc + idx + offset ) & 0xFFFF ); util::stream_format(stream, "$%04X", ( pc + idx + offset ) & 0xFFFF );
break; break;
case 't': /* CALT address */ case 't': /* CALT address */
ea = 0x80 + 2 * (op & (is_7810 ? 0x1f : 0x3f)); ea = 0x80 + 2 * (op & (is_7810 ? 0x1f : 0x3f));
buffer += sprintf(buffer, "($%04X)", ea); util::stream_format(stream, "($%04X)", ea);
break; break;
case 'f': /* CALF address */ case 'f': /* CALF address */
op2 = oprom[idx++]; op2 = oprom[idx++];
ea = 0x800 + 0x100 * (op & 0x07) + op2; ea = 0x800 + 0x100 * (op & 0x07) + op2;
buffer += sprintf(buffer, "$%04X", ea); util::stream_format(stream, "$%04X", ea);
break; break;
case 'o': /* JR offset */ case 'o': /* JR offset */
offset = ( ( op & 0x20 ) ? -0x20 : 0 ) + ( op & 0x1F ); 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; break;
case 'i': /* bit manipulation */ case 'i': /* bit manipulation */
op2 = oprom[idx++]; 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; break;
default: default:
*buffer++ = *a; stream << *a;
} }
} }
else else
*buffer++ = *a; stream << *a;
} }
*buffer = '\0';
return idx | flags | DASMFLAG_SUPPORTED; 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 } // anonymous namespace
CPU_DISASSEMBLE( upd7810 ) 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 ) 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 ) 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 ) 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 );
} }