Merge pull request #1720 from npwoods/dasmstream_pdp8

Changed the pdp8 disassembler to use 'std::ostream &' internally
This commit is contained in:
Vas Crabb 2016-11-17 11:30:46 +11:00 committed by GitHub
commit 2432bf4212
2 changed files with 40 additions and 33 deletions

View File

@ -8,9 +8,7 @@
#include "emu.h" #include "emu.h"
static char *output; static offs_t pdp8_dasm_one(std::ostream &stream, offs_t pc, uint16_t op)
offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
{ {
uint8_t opcode = (op >> 011) & 07; uint8_t opcode = (op >> 011) & 07;
uint16_t current_page = pc & 07600; uint16_t current_page = pc & 07600;
@ -19,30 +17,28 @@ offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
bool indirect = (op & 0400) ? true : false; bool indirect = (op & 0400) ? true : false;
bool zero_page = (op & 0200) ? false : true; bool zero_page = (op & 0200) ? false : true;
output = buffer;
switch (opcode) switch (opcode)
{ {
case 0: case 0:
output += sprintf(buffer, "AND %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr); util::stream_format(stream, "AND %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr);
break; break;
case 1: case 1:
output += sprintf(buffer, "TAD %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr); util::stream_format(stream, "TAD %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr);
break; break;
case 2: case 2:
output += sprintf(buffer, "ISZ %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr); util::stream_format(stream, "ISZ %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr);
break; break;
case 3: case 3:
output += sprintf(buffer, "DCA %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr); util::stream_format(stream, "DCA %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr);
break; break;
case 4: case 4:
output += sprintf(buffer, "JMS %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr); util::stream_format(stream, "JMS %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr);
break; break;
case 5: case 5:
output += sprintf(buffer, "JMP %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr); util::stream_format(stream, "JMP %c %05o", indirect ? 'I' : ' ', zero_page ? zero_addr : current_addr);
break; break;
case 6: case 6:
output += sprintf(buffer, "IOT %03o %01o", (op >> 03) & 077, op & 07); util::stream_format(stream, "IOT %03o %01o", (op >> 03) & 077, op & 07);
break; break;
case 7: case 7:
{ {
@ -51,50 +47,50 @@ offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
{ {
if (!(op & 0377)) if (!(op & 0377))
{ {
output += sprintf(buffer, "NOP "); util::stream_format(stream, "NOP ");
} }
else else
{ {
if (op & 0200) if (op & 0200)
{ {
output += sprintf(buffer, "CLA "); util::stream_format(stream, "CLA ");
} }
if (op & 0100) if (op & 0100)
{ {
output += sprintf(buffer, "CLL "); util::stream_format(stream, "CLL ");
} }
if (op & 040) if (op & 040)
{ {
output += sprintf(buffer, "CMA "); util::stream_format(stream, "CMA ");
} }
if (op & 020) if (op & 020)
{ {
output += sprintf(buffer, "CML "); util::stream_format(stream, "CML ");
} }
if (op & 01) if (op & 01)
{ {
output += sprintf(buffer, "IAC "); util::stream_format(stream, "IAC ");
} }
if (op & 010) if (op & 010)
{ {
if (op & 02) if (op & 02)
{ {
output += sprintf(buffer, "RTR "); util::stream_format(stream, "RTR ");
} }
else else
{ {
output += sprintf(buffer, "RAR "); util::stream_format(stream, "RAR ");
} }
} }
if (op & 04) if (op & 04)
{ {
if (op & 02) if (op & 02)
{ {
output += sprintf(buffer, "RTL "); util::stream_format(stream, "RTL ");
} }
else else
{ {
output += sprintf(buffer, "RAL "); util::stream_format(stream, "RAL ");
} }
} }
} }
@ -103,7 +99,7 @@ offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
{ {
if (!(op & 0377)) if (!(op & 0377))
{ {
output += sprintf(buffer, "NOP "); util::stream_format(stream, "NOP ");
} }
else else
{ {
@ -111,21 +107,21 @@ offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
{ {
if (!(op & 0160)) if (!(op & 0160))
{ {
output += sprintf(buffer, "SKP "); util::stream_format(stream, "SKP ");
} }
else else
{ {
if (op & 0100) if (op & 0100)
{ {
output += sprintf(buffer, "SPA "); util::stream_format(stream, "SPA ");
} }
if (op & 040) if (op & 040)
{ {
output += sprintf(buffer, "SNA "); util::stream_format(stream, "SNA ");
} }
if (op & 020) if (op & 020)
{ {
output += sprintf(buffer, "SZL "); util::stream_format(stream, "SZL ");
} }
} }
} }
@ -133,28 +129,28 @@ offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
{ {
if (op & 0100) if (op & 0100)
{ {
output += sprintf(buffer, "SMA "); util::stream_format(stream, "SMA ");
} }
if (op & 040) if (op & 040)
{ {
output += sprintf(buffer, "SZA "); util::stream_format(stream, "SZA ");
} }
if (op & 020) if (op & 020)
{ {
output += sprintf(buffer, "SNL "); util::stream_format(stream, "SNL ");
} }
} }
if (op & 0200) if (op & 0200)
{ {
output += sprintf(buffer, "CLA "); util::stream_format(stream, "CLA ");
} }
if (op & 04) if (op & 04)
{ {
output += sprintf(buffer, "OSR "); util::stream_format(stream, "OSR ");
} }
if (op & 02) if (op & 02)
{ {
output += sprintf(buffer, "HLT "); util::stream_format(stream, "HLT ");
} }
} }
} }
@ -164,6 +160,15 @@ offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
return 2 | DASMFLAG_SUPPORTED; return 2 | DASMFLAG_SUPPORTED;
} }
static offs_t pdp8_dasm_one(char *buffer, offs_t pc, uint16_t op)
{
std::ostringstream stream;
offs_t result = pdp8_dasm_one(stream, pc, op);
std::string stream_str = stream.str();
strcpy(buffer, stream_str.c_str());
return result;
}
/*****************************************************************************/ /*****************************************************************************/
CPU_DISASSEMBLE( pdp8 ) CPU_DISASSEMBLE( pdp8 )

View File

@ -151,6 +151,7 @@ CPU_DISASSEMBLE( n8x300 );
CPU_DISASSEMBLE( nec ); CPU_DISASSEMBLE( nec );
CPU_DISASSEMBLE( nsc8105 ); CPU_DISASSEMBLE( nsc8105 );
CPU_DISASSEMBLE( pdp1 ); CPU_DISASSEMBLE( pdp1 );
CPU_DISASSEMBLE( pdp8 );
CPU_DISASSEMBLE( pic16c5x ); CPU_DISASSEMBLE( pic16c5x );
CPU_DISASSEMBLE( pic16c62x ); CPU_DISASSEMBLE( pic16c62x );
CPU_DISASSEMBLE( powerpc ); CPU_DISASSEMBLE( powerpc );
@ -320,6 +321,7 @@ static const dasm_table_entry dasm_table[] =
{ "nec", _8bit, 0, CPU_DISASSEMBLE_NAME(nec) }, { "nec", _8bit, 0, CPU_DISASSEMBLE_NAME(nec) },
{ "nsc8105", _8bit, 0, CPU_DISASSEMBLE_NAME(nsc8105) }, { "nsc8105", _8bit, 0, CPU_DISASSEMBLE_NAME(nsc8105) },
{ "pdp1", _32be, 0, CPU_DISASSEMBLE_NAME(pdp1) }, { "pdp1", _32be, 0, CPU_DISASSEMBLE_NAME(pdp1) },
{ "pdp8", _16be, 0, CPU_DISASSEMBLE_NAME(pdp8) },
{ "pic16c5x", _16le, -1, CPU_DISASSEMBLE_NAME(pic16c5x) }, { "pic16c5x", _16le, -1, CPU_DISASSEMBLE_NAME(pic16c5x) },
{ "pic16c62x", _16le, -1, CPU_DISASSEMBLE_NAME(pic16c62x) }, { "pic16c62x", _16le, -1, CPU_DISASSEMBLE_NAME(pic16c62x) },
{ "powerpc", _32be, 0, CPU_DISASSEMBLE_NAME(powerpc) }, { "powerpc", _32be, 0, CPU_DISASSEMBLE_NAME(powerpc) },