Skip to content

Commit c8c9640

Browse files
committed
Updated "CPU Tester" sample code so it will mostly build and work again.
Only remaining issue is that m_icountptr is now private, so it can't set remaining cycles.
1 parent 84b7bc9 commit c8c9640

File tree

1 file changed

+56
-40
lines changed

1 file changed

+56
-40
lines changed

src/emu/drivers/testcpu.cpp

+56-40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "emu.h"
1313
#include "cpu/powerpc/ppc.h"
1414

15+
#include <sstream>
16+
17+
18+
namespace {
1519

1620
//**************************************************************************
1721
// CONSTANTS
@@ -29,18 +33,37 @@ class testcpu_state : public driver_device
2933
{
3034
public:
3135
// constructor
32-
testcpu_state(const machine_config &mconfig, device_type type, const char *tag)
33-
: driver_device(mconfig, type, tag),
34-
m_cpu(*this, "maincpu"),
35-
m_ram(*this, "ram"),
36-
m_space(nullptr)
36+
testcpu_state(const machine_config &mconfig, device_type type, const char *tag) :
37+
driver_device(mconfig, type, tag),
38+
m_cpu(*this, "maincpu"),
39+
m_ram(*this, "ram"),
40+
m_space(nullptr)
3741
{
3842
}
3943

44+
void testcpu(machine_config &config);
45+
46+
private:
47+
class disasm_data_buffer : public util::disasm_interface::data_buffer
48+
{
49+
public:
50+
disasm_data_buffer(address_space &space) : m_space(space)
51+
{
52+
}
53+
54+
virtual u8 r8(offs_t pc) const override { return m_space.read_byte(pc); }
55+
virtual u16 r16(offs_t pc) const override { return m_space.read_word(pc); }
56+
virtual u32 r32(offs_t pc) const override { return m_space.read_dword(pc); }
57+
virtual u64 r64(offs_t pc) const override { return m_space.read_qword(pc); }
58+
59+
private:
60+
address_space &m_space;
61+
};
62+
4063
// timer callback; used to wrest control of the system
4164
TIMER_CALLBACK_MEMBER(timer_tick)
4265
{
43-
static const u32 sample_instructions[] =
66+
static constexpr u32 sample_instructions[] =
4467
{
4568
0x3d40f900, // li r10,0xf9000000
4669
0x394af000, // addi r10,r10,-0x1000
@@ -52,7 +75,7 @@ class testcpu_state : public driver_device
5275
};
5376

5477
// iterate over instructions
55-
for (auto & sample_instruction : sample_instructions)
78+
for (auto &sample_instruction : sample_instructions)
5679
{
5780
// write the instruction to execute, followed by a BLR which will terminate the
5881
// basic block in the DRC
@@ -74,16 +97,16 @@ class testcpu_state : public driver_device
7497
}
7598

7699
// output initial state
77-
printf("==================================================\n");
78-
printf("Initial state:\n");
100+
osd_printf_info("==================================================\n");
101+
osd_printf_info("Initial state:\n");
79102
dump_state(true);
80103

81104
// execute one instruction
82105
*m_cpu->m_icountptr = 0;
83106
m_cpu->run();
84107

85108
// dump the final register state
86-
printf("Final state:\n");
109+
osd_printf_info("Final state:\n");
87110
dump_state(false);
88111
}
89112

@@ -101,49 +124,43 @@ class testcpu_state : public driver_device
101124
m_cpu->ppcdrc_set_options(PPCDRC_COMPATIBLE_OPTIONS);
102125

103126
// set a timer to go off right away
104-
timer_alloc(FUNC(timer_tick), this)->adjust(attotime::zero);
127+
timer_alloc(FUNC(testcpu_state::timer_tick), this)->adjust(attotime::zero);
105128
}
106129

107130
// dump the current CPU state
108131
void dump_state(bool disassemble)
109132
{
110-
char buffer[256];
111-
u8 instruction[32];
112-
buffer[0] = 0;
133+
std::ostringstream buffer;
113134
int bytes = 0;
114135
if (disassemble)
115136
{
116-
// fill in an array of bytes in the CPU's natural order
117-
int maxbytes = m_cpu->max_opcode_bytes();
118-
for (int bytenum = 0; bytenum < maxbytes; bytenum++)
119-
instruction[bytenum] = m_space->read_byte(RAM_BASE + bytenum);
120-
121137
// disassemble the current instruction
122-
bytes = m_cpu->disassemble(buffer, RAM_BASE, instruction, instruction) & DASMFLAG_LENGTHMASK;
138+
disasm_data_buffer databuf(*m_space);
139+
bytes = m_cpu->get_disassembler().disassemble(buffer, RAM_BASE, databuf, databuf) & util::disasm_interface::LENGTHMASK;
123140
}
124141

125142
// output the registers
126-
printf("PC : %08X", u32(m_cpu->state_int(PPC_PC)));
127-
if (disassemble && bytes > 0)
143+
osd_printf_info("PC : %08X", u32(m_cpu->state_int(PPC_PC)));
144+
if (bytes > 0)
128145
{
129-
printf(" => ");
146+
osd_printf_info(" => ");
130147
for (int bytenum = 0; bytenum < bytes; bytenum++)
131-
printf("%02X", instruction[bytenum]);
132-
printf(" %s", buffer);
148+
osd_printf_info("%02X", m_space->read_byte(RAM_BASE + bytenum));
149+
osd_printf_info(" %s", buffer.str());
133150
}
134-
printf("\n");
151+
osd_printf_info("\n");
135152
for (int regnum = 0; regnum < 32; regnum++)
136153
{
137-
printf("R%-2d: %08X ", regnum, u32(m_cpu->state_int(PPC_R0 + regnum)));
138-
if (regnum % 4 == 3) printf("\n");
154+
osd_printf_info("R%-2d: %08X ", regnum, u32(m_cpu->state_int(PPC_R0 + regnum)));
155+
if (regnum % 4 == 3) osd_printf_info("\n");
139156
}
140-
printf("CR : %08X LR : %08X CTR: %08X XER: %08X\n",
157+
osd_printf_info("CR : %08X LR : %08X CTR: %08X XER: %08X\n",
141158
u32(m_cpu->state_int(PPC_CR)), u32(m_cpu->state_int(PPC_LR)),
142159
u32(m_cpu->state_int(PPC_CTR)), u32(m_cpu->state_int(PPC_XER)));
143160
for (int regnum = 0; regnum < 32; regnum++)
144161
{
145-
printf("F%-2d: %10g ", regnum, u2d(m_cpu->state_int(PPC_F0 + regnum)));
146-
if (regnum % 4 == 3) printf("\n");
162+
osd_printf_info("F%-2d: %10g ", regnum, u2d(m_cpu->state_int(PPC_F0 + regnum)));
163+
if (regnum % 4 == 3) osd_printf_info("\n");
147164
}
148165
}
149166

@@ -152,20 +169,18 @@ class testcpu_state : public driver_device
152169
{
153170
u64 fulloffs = offset;
154171
u64 result = fulloffs + (fulloffs << 8) + (fulloffs << 16) + (fulloffs << 24) + (fulloffs << 32);
155-
printf("Read from %08X & %08X%08X = %08X%08X\n", offset * 8, (int)((mem_mask&0xffffffff00000000LL) >> 32) , (int)(mem_mask&0xffffffff), (int)((result&0xffffffff00000000LL) >> 32), (int)(result&0xffffffff));
172+
osd_printf_info("Read from %08X & %016X = %016X\n", offset * 8, mem_mask, result);
156173
return result;
157174
}
158175

159176
// report writes to anywhere
160177
void general_w(offs_t offset, u64 data, u64 mem_mask = ~0)
161178
{
162-
printf("Write to %08X & %08X%08X = %08X%08X\n", offset * 8, (int)((mem_mask&0xffffffff00000000LL) >> 32) , (int)(mem_mask&0xffffffff), (int)((data&0xffffffff00000000LL) >> 32), (int)(data&0xffffffff));
179+
osd_printf_info("Write to %08X & %016X = %016X\n", offset * 8, mem_mask, data);
163180
}
164181

165-
void testcpu(machine_config &config);
166-
167182
void ppc_mem(address_map &map);
168-
private:
183+
169184
// internal state
170185
required_device<ppc603e_device> m_cpu;
171186
required_shared_ptr<u64> m_ram;
@@ -180,8 +195,8 @@ class testcpu_state : public driver_device
180195

181196
void testcpu_state::ppc_mem(address_map &map)
182197
{
198+
map(0x00000000, 0xffffffff).rw(FUNC(testcpu_state::general_r), FUNC(testcpu_state::general_w));
183199
map(RAM_BASE, RAM_BASE+7).ram().share("ram");
184-
map(0x00000000, 0xffffffff).rw(this, FUNC(testcpu_state::general_r), FUNC(testcpu_state::general_w));
185200
}
186201

187202

@@ -193,8 +208,8 @@ void testcpu_state::ppc_mem(address_map &map)
193208
void testcpu_state::testcpu(machine_config &config)
194209
{
195210
// CPUs
196-
PPC603E(config, m_cpu, 66000000);
197-
m_cpu->set_bus_frequency(66000000); // Multiplier 1, Bus = 66MHz, Core = 66MHz
211+
PPC603E(config, m_cpu, 66'000'000);
212+
m_cpu->set_bus_frequency(66'000'000); // Multiplier 1, Bus = 66MHz, Core = 66MHz
198213
m_cpu->set_addrmap(AS_PROGRAM, &testcpu_state::ppc_mem);
199214
}
200215

@@ -208,10 +223,11 @@ ROM_START( testcpu )
208223
ROM_REGION( 0x10, "user1", ROMREGION_ERASEFF )
209224
ROM_END
210225

226+
} // anonymous namespace
211227

212228

213229
//**************************************************************************
214230
// GAME DRIVERS
215231
//**************************************************************************
216232

217-
GAME( 2012, testcpu, 0, testcpu, 0, driver_device, 0, ROT0, "MAME", "CPU Tester", MACHINE_NO_SOUND )
233+
GAME( 2012, testcpu, 0, testcpu, 0, testcpu_state, empty_init, ROT0, "MAME", "CPU Tester", MACHINE_NO_SOUND_HW )

0 commit comments

Comments
 (0)