machine/decocass_tape.cpp: Don't use static buffers for building messages.

This commit is contained in:
Vas Crabb 2022-02-24 17:38:37 +11:00
parent 0a1c686c8e
commit eb886fe53e
2 changed files with 56 additions and 46 deletions

View File

@ -12,6 +12,8 @@
#include "cpu/m6502/m6502.h" #include "cpu/m6502/m6502.h"
#include "cpu/mcs48/mcs48.h" #include "cpu/mcs48/mcs48.h"
#include <sstream>
#define LOG_CASSETTE_STATE 0 #define LOG_CASSETTE_STATE 0
/*************************************************************************** /***************************************************************************
@ -154,68 +156,76 @@ static uint16_t tape_crc16_byte(uint16_t crc, uint8_t data)
describes the state of the tape describes the state of the tape
-------------------------------------------------*/ -------------------------------------------------*/
const char *decocass_tape_device::describe_state() std::string decocass_tape_device::describe_state()
{ {
static char buffer[40]; std::ostringstream buffer;
char temprname[40]; util::stream_format(buffer, "{%9d=", m_clockpos);
const char *rname = temprname;
if (m_region == REGION_LEADER) switch (m_region)
rname = "LEAD";
else if (m_region == REGION_LEADER_GAP)
rname = "LGAP";
else if (m_region == REGION_BOT)
rname = "BOT ";
else if (m_region == REGION_BOT_GAP)
rname = "BGAP";
else if (m_region == REGION_TRAILER)
rname = "TRLR";
else if (m_region == REGION_TRAILER_GAP)
rname = "TGAP";
else if (m_region == REGION_EOT)
rname = "EOT ";
else if (m_region == REGION_EOT_GAP)
rname = "EGAP";
else
{ {
char tempbname[40]; case REGION_LEADER:
const char *bname = tempbname; buffer << "LEAD}";
int clk; break;
case REGION_LEADER_GAP:
buffer << "LGAP}";
break;
case REGION_BOT:
buffer << "BOT }";
break;
case REGION_BOT_GAP:
buffer << "BGAP}";
break;
case REGION_TRAILER:
buffer << "TRLR}";
break;
case REGION_TRAILER_GAP:
buffer << "TGAP}";
break;
case REGION_EOT:
buffer << "EOT }";
break;
case REGION_EOT_GAP:
buffer << "EGAP}";
break;
default:
util::stream_format(buffer, "BL%02X.", m_region - REGION_DATA_BLOCK_0);
if (m_bytenum <= BYTE_PRE_GAP_33) if (m_bytenum <= BYTE_PRE_GAP_33)
sprintf(tempbname, "PR%02d", m_bytenum - BYTE_PRE_GAP_0); util::stream_format(buffer, "PR%02d", m_bytenum - BYTE_PRE_GAP_0);
else if (m_bytenum == BYTE_LEADIN) else if (m_bytenum == BYTE_LEADIN)
bname = "LDIN"; buffer << "LDIN";
else if (m_bytenum == BYTE_HEADER) else if (m_bytenum == BYTE_HEADER)
bname = "HEAD"; buffer << "HEAD";
else if (m_bytenum <= BYTE_DATA_255) else if (m_bytenum <= BYTE_DATA_255)
sprintf(tempbname, "BY%02X", m_bytenum - BYTE_DATA_0); util::stream_format(buffer, "BY%02X", m_bytenum - BYTE_DATA_0);
else if (m_bytenum == BYTE_CRC16_MSB) else if (m_bytenum == BYTE_CRC16_MSB)
bname = "CRCM"; buffer << "CRCM";
else if (m_bytenum == BYTE_CRC16_LSB) else if (m_bytenum == BYTE_CRC16_LSB)
bname = "CRCL"; buffer << "CRCL";
else if (m_bytenum == BYTE_TRAILER) else if (m_bytenum == BYTE_TRAILER)
bname = "TRLR"; buffer << "TRLR";
else if (m_bytenum == BYTE_LEADOUT) else if (m_bytenum == BYTE_LEADOUT)
bname = "LOUT"; buffer << "LOUT";
else if (m_bytenum == BYTE_LONGCLOCK) else if (m_bytenum == BYTE_LONGCLOCK)
bname = "LONG"; buffer << "LONG";
else else
sprintf(tempbname, "PO%02d", m_bytenum - BYTE_POSTGAP_0); util::stream_format(buffer, "PO%02d", m_bytenum - BYTE_POSTGAP_0);
/* in the main data area, the clock alternates at the clock rate */ {
if (m_bytenum >= BYTE_LEADIN && m_bytenum <= BYTE_LEADOUT) // in the main data area, the clock alternates at the clock rate
clk = ((uint32_t)(m_clockpos - REGION_BOT_GAP_END_CLOCK) & 1) ? 0 : 1; int clk;
else if (m_bytenum == BYTE_LONGCLOCK) if (m_bytenum >= BYTE_LEADIN && m_bytenum <= BYTE_LEADOUT)
clk = 1; clk = BIT(~uint32_t(m_clockpos - REGION_BOT_GAP_END_CLOCK), 0);
else else if (m_bytenum == BYTE_LONGCLOCK)
clk = 0; clk = 1;
else
clk = 0;
sprintf(temprname, "BL%02X.%4s.%d.%d", m_region - REGION_DATA_BLOCK_0, bname, m_bitnum, clk); util::stream_format(buffer, ".%d.%d}", m_bitnum, clk);
}
} }
sprintf(buffer, "{%9d=%s}", m_clockpos, rname); return std::move(buffer).str();
return buffer;
} }
@ -271,7 +281,7 @@ TIMER_CALLBACK_MEMBER( decocass_tape_device::tape_clock_callback )
/* log */ /* log */
if (LOG_CASSETTE_STATE) if (LOG_CASSETTE_STATE)
describe_state(); describe_state(); // FIXME: is this supposed to actually do something with the result?
} }

View File

@ -67,7 +67,7 @@ private:
uint16_t m_crc16[256]; /* CRC16 for each block */ uint16_t m_crc16[256]; /* CRC16 for each block */
optional_region_ptr<uint8_t> m_tape_data; optional_region_ptr<uint8_t> m_tape_data;
const char *describe_state(); std::string describe_state();
TIMER_CALLBACK_MEMBER( tape_clock_callback ); TIMER_CALLBACK_MEMBER( tape_clock_callback );
}; };