Skip to content

Commit 440ccee

Browse files
[tmp94c241] dasm: SFR symbol names (#14181)
1 parent 610ca72 commit 440ccee

File tree

3 files changed

+165
-35
lines changed

3 files changed

+165
-35
lines changed

src/devices/cpu/tlcs900/dasm900.cpp

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// license:BSD-3-Clause
2-
// copyright-holders:Wilbert Pol
2+
// copyright-holders:Wilbert Pol, Felipe Sanches
33
/*******************************************************************
44
55
Toshiba TLCS-900/H disassembly
@@ -9,6 +9,21 @@ Toshiba TLCS-900/H disassembly
99
#include "emu.h"
1010
#include "dasm900.h"
1111

12+
template <typename T> std::string tlcs900_disassembler::address(T offset, int size) const
13+
{
14+
auto const symbol = std::lower_bound(
15+
m_symbols,
16+
m_symbols + m_symbol_count,
17+
offset,
18+
[] (auto const &sym, u16 addr) { return sym.first < addr; }
19+
);
20+
21+
if ((m_symbol_count != (symbol - m_symbols)) && (symbol->first == offset))
22+
return symbol->second;
23+
else
24+
return util::string_format("0x%0*x", size/4, offset);
25+
}
26+
1227
const char *const tlcs900_disassembler::s_mnemonic[] =
1328
{
1429
"adc", "add", "and", "andcf", "bit", "bs1b",
@@ -1395,7 +1410,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
13951410
break;
13961411

13971412
case M_80:
1398-
buf = string_format("%s", s_reg32[op & 0x07]);
1413+
buf = s_reg32[op & 0x07];
13991414
op = opcodes.r8( pos++ );
14001415
dasm = &mnemonic_80[ op ];
14011416
break;
@@ -1408,7 +1423,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
14081423
break;
14091424

14101425
case M_90:
1411-
buf = string_format("%s", s_reg32[op & 0x07]);
1426+
buf = s_reg32[op & 0x07];
14121427
op = opcodes.r8( pos++ );
14131428
dasm = &mnemonic_90[ op ];
14141429
break;
@@ -1421,7 +1436,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
14211436
break;
14221437

14231438
case M_A0:
1424-
buf = string_format("%s", s_reg32[op & 0x07]);
1439+
buf = s_reg32[op & 0x07];
14251440
op = opcodes.r8( pos++ );
14261441
dasm = &mnemonic_a0[ op ];
14271442
break;
@@ -1434,7 +1449,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
14341449
break;
14351450

14361451
case M_B0:
1437-
buf = string_format("%s", s_reg32[op & 0x07]);
1452+
buf = s_reg32[op & 0x07];
14381453
op = opcodes.r8( pos++ );
14391454
dasm = &mnemonic_b0[ op ];
14401455
break;
@@ -1451,13 +1466,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
14511466
{
14521467
case 0x00: /* 0xC0 */
14531468
imm = opcodes.r8( pos++ );
1454-
buf = string_format("0x%02x", imm);
1469+
buf = address(imm, 8);
14551470
break;
14561471

14571472
case 0x01: /* 0xC1 */
14581473
imm = opcodes.r8( pos++ );
14591474
imm = imm | (opcodes.r8( pos++ ) << 8);
1460-
buf = string_format("0x%04x", imm);
1475+
buf = address(imm, 16);
14611476
break;
14621477

14631478
case 0x02: /* 0xC2 */
@@ -1472,7 +1487,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
14721487
switch( imm & 0x03 )
14731488
{
14741489
case 0x00:
1475-
buf = string_format("%s", s_allreg32[imm]);
1490+
buf = s_allreg32[imm];
14761491
break;
14771492

14781493
case 0x01:
@@ -1528,12 +1543,12 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
15281543
case oC8:
15291544
if ( op & 0x08 )
15301545
{
1531-
buf = string_format("%s", s_reg8[ op & 0x07 ]);
1546+
buf = s_reg8[ op & 0x07 ];
15321547
}
15331548
else
15341549
{
15351550
imm = opcodes.r8( pos++ );
1536-
buf = string_format("%s", s_allreg8[imm]);
1551+
buf = s_allreg8[imm];
15371552
}
15381553
op = opcodes.r8( pos++ );
15391554
dasm = &mnemonic_c8[ op ];
@@ -1544,13 +1559,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
15441559
{
15451560
case 0x00: /* 0xD0 */
15461561
imm = opcodes.r8( pos++ );
1547-
buf = string_format("0x%02x", imm);
1562+
buf = address(imm, 8);
15481563
break;
15491564

15501565
case 0x01: /* 0xD1 */
15511566
imm = opcodes.r8( pos++ );
15521567
imm = imm | (opcodes.r8( pos++ ) << 8);
1553-
buf = string_format("0x%04x", imm);
1568+
buf = address(imm, 16);
15541569
break;
15551570

15561571
case 0x02: /* 0xD2 */
@@ -1565,7 +1580,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
15651580
switch( imm & 0x03 )
15661581
{
15671582
case 0x00:
1568-
buf = string_format("%s", s_allreg32[imm]);
1583+
buf = s_allreg32[imm];
15691584
break;
15701585

15711586
case 0x01:
@@ -1621,12 +1636,12 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
16211636
case oD8:
16221637
if ( op & 0x08 )
16231638
{
1624-
buf = string_format("%s", s_reg16[ op & 0x07 ]);
1639+
buf = s_reg16[ op & 0x07 ];
16251640
}
16261641
else
16271642
{
16281643
imm = opcodes.r8( pos++ );
1629-
buf = string_format("%s", s_allreg16[imm]);
1644+
buf = s_allreg16[imm];
16301645
}
16311646

16321647
op = opcodes.r8( pos++ );
@@ -1638,13 +1653,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
16381653
{
16391654
case 0x00: /* 0xE0 */
16401655
imm = opcodes.r8( pos++ );
1641-
buf = string_format("0x%02x", imm);
1656+
buf = address(imm, 8);
16421657
break;
16431658

16441659
case 0x01: /* 0xE1 */
16451660
imm = opcodes.r8( pos++ );
16461661
imm = imm | (opcodes.r8( pos++ ) << 8);
1647-
buf = string_format("0x%04x", imm);
1662+
buf = address(imm, 16);
16481663
break;
16491664

16501665
case 0x02: /* 0xE2 */
@@ -1659,7 +1674,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
16591674
switch( imm & 0x03 )
16601675
{
16611676
case 0x00:
1662-
buf = string_format("%s", s_allreg32[imm]);
1677+
buf = s_allreg32[imm];
16631678
break;
16641679

16651680
case 0x01:
@@ -1715,12 +1730,12 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
17151730
case M_E8:
17161731
if ( op & 0x08 )
17171732
{
1718-
buf = string_format("%s", s_reg32[ op & 0x07 ]);
1733+
buf = s_reg32[ op & 0x07 ];
17191734
}
17201735
else
17211736
{
17221737
imm = opcodes.r8( pos++ );
1723-
buf = string_format("%s", s_allreg32[imm]);
1738+
buf = s_allreg32[imm];
17241739
}
17251740
op = opcodes.r8( pos++ );
17261741
dasm = &mnemonic_e8[ op ];
@@ -1731,13 +1746,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
17311746
{
17321747
case 0x00: /* 0xF0 */
17331748
imm = opcodes.r8( pos++ );
1734-
buf = string_format("0x%02x", imm);
1749+
buf = address(imm, 8);
17351750
break;
17361751

17371752
case 0x01: /* 0xF1 */
17381753
imm = opcodes.r8( pos++ );
17391754
imm = imm | (opcodes.r8( pos++ ) << 8);
1740-
buf = string_format("0x%04x", imm);
1755+
buf = address(imm, 16);
17411756
break;
17421757

17431758
case 0x02: /* 0xF2 */
@@ -1752,7 +1767,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
17521767
switch( imm & 0x03 )
17531768
{
17541769
case 0x00:
1755-
buf = string_format("%s", s_allreg32[imm]);
1770+
buf = s_allreg32[imm];
17561771
break;
17571772

17581773
case 0x01:
@@ -1763,7 +1778,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
17631778
break;
17641779

17651780
case 0x02:
1766-
buf = string_format("unknown");
1781+
buf = "unknown";
17671782
break;
17681783

17691784
case 0x03:
@@ -1806,7 +1821,7 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
18061821
break;
18071822
}
18081823

1809-
util::stream_format(stream, "%s", s_mnemonic[ dasm->mnemonic ]);
1824+
stream << s_mnemonic[ dasm->mnemonic ];
18101825

18111826
switch( dasm->mnemonic )
18121827
{
@@ -1957,13 +1972,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
19571972

19581973
case O_I8:
19591974
imm = opcodes.r8( pos++ );
1960-
util::stream_format(stream, " 0x%02x", imm);
1975+
util::stream_format(stream, " %s", address(imm, 8));
19611976
break;
19621977

19631978
case O_I16:
19641979
imm = opcodes.r8( pos++ );
19651980
imm = imm | (opcodes.r8( pos++ ) << 8);
1966-
util::stream_format(stream, " 0x%04x", imm);
1981+
util::stream_format(stream, " %s", address(imm, 16));
19671982
break;
19681983

19691984
case O_I24:
@@ -1997,13 +2012,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
19972012

19982013
case O_M8:
19992014
imm = opcodes.r8( pos++ );
2000-
util::stream_format(stream, " (0x%02x)", imm);
2015+
util::stream_format(stream, " (%s)", address(imm, 8));
20012016
break;
20022017

20032018
case O_M16:
20042019
imm = opcodes.r8( pos++ );
20052020
imm = imm | (opcodes.r8( pos++ ) << 8);
2006-
util::stream_format(stream, " (0x%04x)", imm);
2021+
util::stream_format(stream, " (%s)", address(imm, 16));
20072022
break;
20082023

20092024
case O_R:
@@ -2145,13 +2160,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
21452160

21462161
case O_I8:
21472162
imm = opcodes.r8( pos++ );
2148-
util::stream_format(stream, ",0x%02x", imm);
2163+
util::stream_format(stream, ",%s", address(imm, 8));
21492164
break;
21502165

21512166
case O_I16:
21522167
imm = opcodes.r8( pos++ );
21532168
imm = imm | (opcodes.r8( pos++ ) << 8);
2154-
util::stream_format(stream, ",0x%04x", imm);
2169+
util::stream_format(stream, ",%s", address(imm, 16));
21552170
break;
21562171

21572172
case O_I24:
@@ -2185,13 +2200,13 @@ offs_t tlcs900_disassembler::disassemble(std::ostream &stream, offs_t pc, const
21852200

21862201
case O_M8:
21872202
imm = opcodes.r8( pos++ );
2188-
util::stream_format(stream, ",(0x%02x)", imm);
2203+
util::stream_format(stream, ",(%s)", address(imm, 8));
21892204
break;
21902205

21912206
case O_M16:
21922207
imm = opcodes.r8( pos++ );
21932208
imm = imm | (opcodes.r8( pos++ ) << 8);
2194-
util::stream_format(stream, ",(0x%04x)", imm);
2209+
util::stream_format(stream, ",(%s)", address(imm, 16));
21952210
break;
21962211

21972212
case O_R:

src/devices/cpu/tlcs900/dasm900.h

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// license:BSD-3-Clause
2-
// copyright-holders:Wilbert Pol
2+
// copyright-holders:Wilbert Pol, Felipe Sanches
33
/*******************************************************************
44
55
Toshiba TLCS-900/H disassembly
@@ -17,6 +17,11 @@ class tlcs900_disassembler : public util::disasm_interface
1717
tlcs900_disassembler() = default;
1818
virtual ~tlcs900_disassembler() = default;
1919

20+
tlcs900_disassembler(std::pair<u16, char const *> const symbols[], std::size_t symbol_count)
21+
: m_symbols(symbols), m_symbol_count(symbol_count)
22+
{
23+
}
24+
2025
virtual u32 opcode_alignment() const override;
2126
virtual offs_t disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer &params) override;
2227

@@ -106,6 +111,42 @@ class tlcs900_disassembler : public util::disasm_interface
106111
static const char *const s_allreg32[256];
107112
static const char *const s_cond[16];
108113

114+
std::pair<u16, char const *> const *m_symbols;
115+
std::size_t m_symbol_count;
116+
117+
template <typename T> std::string address(T offset, int size) const;
118+
};
119+
120+
121+
class tmp94c241_disassembler : public tlcs900_disassembler
122+
{
123+
public:
124+
tmp94c241_disassembler(std::pair<u16, char const *> const symbols[], std::size_t symbol_count);
125+
template<size_t N> tmp94c241_disassembler(std::pair<u16, char const *> const (&symbols)[N]) : tlcs900_disassembler(symbols, N) {}
126+
127+
private:
128+
static const char *const s_sfr_names[];
129+
};
130+
131+
132+
class tmp95c061_disassembler : public tlcs900_disassembler
133+
{
134+
public:
135+
tmp95c061_disassembler() : tlcs900_disassembler() {};
136+
};
137+
138+
139+
class tmp95c063_disassembler : public tlcs900_disassembler
140+
{
141+
public:
142+
tmp95c063_disassembler() : tlcs900_disassembler() {};
143+
};
144+
145+
146+
class tmp96c141_disassembler : public tlcs900_disassembler
147+
{
148+
public:
149+
tmp96c141_disassembler() : tlcs900_disassembler() {};
109150
};
110151

111152
#endif

0 commit comments

Comments
 (0)