12
12
#include " emu.h"
13
13
#include " cpu/powerpc/ppc.h"
14
14
15
+ #include < sstream>
16
+
17
+
18
+ namespace {
15
19
16
20
// **************************************************************************
17
21
// CONSTANTS
@@ -29,18 +33,37 @@ class testcpu_state : public driver_device
29
33
{
30
34
public:
31
35
// 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 )
37
41
{
38
42
}
39
43
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
+
40
63
// timer callback; used to wrest control of the system
41
64
TIMER_CALLBACK_MEMBER (timer_tick)
42
65
{
43
- static const u32 sample_instructions[] =
66
+ static constexpr u32 sample_instructions[] =
44
67
{
45
68
0x3d40f900 , // li r10,0xf9000000
46
69
0x394af000 , // addi r10,r10,-0x1000
@@ -52,7 +75,7 @@ class testcpu_state : public driver_device
52
75
};
53
76
54
77
// iterate over instructions
55
- for (auto & sample_instruction : sample_instructions)
78
+ for (auto &sample_instruction : sample_instructions)
56
79
{
57
80
// write the instruction to execute, followed by a BLR which will terminate the
58
81
// basic block in the DRC
@@ -74,16 +97,16 @@ class testcpu_state : public driver_device
74
97
}
75
98
76
99
// output initial state
77
- printf (" ==================================================\n " );
78
- printf (" Initial state:\n " );
100
+ osd_printf_info (" ==================================================\n " );
101
+ osd_printf_info (" Initial state:\n " );
79
102
dump_state (true );
80
103
81
104
// execute one instruction
82
105
*m_cpu->m_icountptr = 0 ;
83
106
m_cpu->run ();
84
107
85
108
// dump the final register state
86
- printf (" Final state:\n " );
109
+ osd_printf_info (" Final state:\n " );
87
110
dump_state (false );
88
111
}
89
112
@@ -101,49 +124,43 @@ class testcpu_state : public driver_device
101
124
m_cpu->ppcdrc_set_options (PPCDRC_COMPATIBLE_OPTIONS);
102
125
103
126
// 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);
105
128
}
106
129
107
130
// dump the current CPU state
108
131
void dump_state (bool disassemble)
109
132
{
110
- char buffer[256 ];
111
- u8 instruction[32 ];
112
- buffer[0 ] = 0 ;
133
+ std::ostringstream buffer;
113
134
int bytes = 0 ;
114
135
if (disassemble)
115
136
{
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
-
121
137
// 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;
123
140
}
124
141
125
142
// 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 )
128
145
{
129
- printf (" => " );
146
+ osd_printf_info (" => " );
130
147
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 () );
133
150
}
134
- printf (" \n " );
151
+ osd_printf_info (" \n " );
135
152
for (int regnum = 0 ; regnum < 32 ; regnum++)
136
153
{
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 " );
139
156
}
140
- printf (" CR : %08X LR : %08X CTR: %08X XER: %08X\n " ,
157
+ osd_printf_info (" CR : %08X LR : %08X CTR: %08X XER: %08X\n " ,
141
158
u32 (m_cpu->state_int (PPC_CR)), u32 (m_cpu->state_int (PPC_LR)),
142
159
u32 (m_cpu->state_int (PPC_CTR)), u32 (m_cpu->state_int (PPC_XER)));
143
160
for (int regnum = 0 ; regnum < 32 ; regnum++)
144
161
{
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 " );
147
164
}
148
165
}
149
166
@@ -152,20 +169,18 @@ class testcpu_state : public driver_device
152
169
{
153
170
u64 fulloffs = offset;
154
171
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);
156
173
return result;
157
174
}
158
175
159
176
// report writes to anywhere
160
177
void general_w (offs_t offset, u64 data, u64 mem_mask = ~0 )
161
178
{
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);
163
180
}
164
181
165
- void testcpu (machine_config &config);
166
-
167
182
void ppc_mem (address_map &map);
168
- private:
183
+
169
184
// internal state
170
185
required_device<ppc603e_device> m_cpu;
171
186
required_shared_ptr<u64> m_ram;
@@ -180,8 +195,8 @@ class testcpu_state : public driver_device
180
195
181
196
void testcpu_state::ppc_mem (address_map &map)
182
197
{
198
+ map (0x00000000 , 0xffffffff ).rw (FUNC (testcpu_state::general_r), FUNC (testcpu_state::general_w));
183
199
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));
185
200
}
186
201
187
202
@@ -193,8 +208,8 @@ void testcpu_state::ppc_mem(address_map &map)
193
208
void testcpu_state::testcpu (machine_config &config)
194
209
{
195
210
// 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
198
213
m_cpu->set_addrmap (AS_PROGRAM, &testcpu_state::ppc_mem);
199
214
}
200
215
@@ -208,10 +223,11 @@ ROM_START( testcpu )
208
223
ROM_REGION ( 0x10 , " user1" , ROMREGION_ERASEFF )
209
224
ROM_END
210
225
226
+ } // anonymous namespace
211
227
212
228
213
229
// **************************************************************************
214
230
// GAME DRIVERS
215
231
// **************************************************************************
216
232
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