3#include <gmock/gmock-nice-strict.h>
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
27 void SetupMemory(uint16_t address,
const std::vector<uint8_t>& values) {
32 for (
const auto& each : values) {
41 ON_CALL(*
this,
read(_)).WillByDefault([
this](uint16_t address) {
45 .WillByDefault([
this](uint16_t address) -> uint8_t& {
48 ON_CALL(*
this,
write(_, _))
49 .WillByDefault([
this](uint16_t address, uint8_t value) {
52 ON_CALL(*
this,
reset()).WillByDefault([
this]() {
84 uint8_t opcode = 0xE8;
85 uint8_t immediate_value = 0x5A;
86 audioRAM.SetupMemory(0x0100, {opcode, immediate_value});
88 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
92 EXPECT_EQ(spc700.A, immediate_value);
93 EXPECT_EQ(spc700.PSW.Z, 0);
94 EXPECT_EQ(spc700.PSW.N, 0);
99 uint8_t opcode = 0x7D;
102 spc700.ExecuteInstructions(opcode);
104 EXPECT_EQ(spc700.A, spc700.X);
105 EXPECT_EQ(spc700.PSW.Z, 0);
106 EXPECT_EQ(spc700.PSW.N, 0);
111 uint8_t opcode = 0xDD;
114 spc700.ExecuteInstructions(opcode);
116 EXPECT_EQ(spc700.A, spc700.Y);
117 EXPECT_EQ(spc700.PSW.Z, 0);
118 EXPECT_EQ(spc700.PSW.N, 0);
123 uint8_t opcode = 0xE4;
124 uint8_t dp_value = 0x5A;
125 audioRAM.SetupMemory(0x005A, {0x42});
126 audioRAM.SetupMemory(0x0100, {opcode, dp_value});
128 EXPECT_CALL(audioRAM, read(_))
129 .WillOnce(Return(dp_value))
130 .WillOnce(Return(0x42));
132 spc700.ExecuteInstructions(opcode);
134 EXPECT_EQ(spc700.A, 0x42);
135 EXPECT_EQ(spc700.PSW.Z, 0);
136 EXPECT_EQ(spc700.PSW.N, 0);
141 uint8_t opcode = 0xF4;
142 uint8_t dp_value = 0x5A;
144 audioRAM.SetupMemory(0x005B, {0x42});
145 audioRAM.SetupMemory(0x0100, {opcode, dp_value});
147 EXPECT_CALL(audioRAM, read(_))
148 .WillOnce(Return(dp_value + spc700.X))
149 .WillOnce(Return(0x42));
151 spc700.ExecuteInstructions(opcode);
153 EXPECT_EQ(spc700.A, 0x42);
154 EXPECT_EQ(spc700.PSW.Z, 0);
155 EXPECT_EQ(spc700.PSW.N, 0);
160 uint8_t opcode = 0xF7;
161 uint8_t dp_value = 0x5A;
163 audioRAM.SetupMemory(0x005A, {0x00, 0x42});
164 audioRAM.SetupMemory(0x0100, {opcode, dp_value});
165 audioRAM.SetupMemory(0x4201, {0x69});
167 EXPECT_CALL(audioRAM, read(_))
168 .WillOnce(Return(dp_value))
169 .WillOnce(Return(0x4200))
170 .WillOnce(Return(0x69));
172 spc700.ExecuteInstructions(opcode);
174 EXPECT_EQ(spc700.A, 0x69);
175 EXPECT_EQ(spc700.PSW.Z, 0);
176 EXPECT_EQ(spc700.PSW.N, 0);
181 uint8_t opcode = 0xE7;
182 uint8_t dp_value = 0x5A;
184 audioRAM.SetupMemory(0x005B, {0x00, 0x42});
185 audioRAM.SetupMemory(0x0100, {opcode, dp_value});
186 audioRAM.SetupMemory(0x4200, {0x69});
188 EXPECT_CALL(audioRAM, read(_))
189 .WillOnce(Return(dp_value + 1))
190 .WillOnce(Return(0x4200))
191 .WillOnce(Return(0x69));
193 spc700.ExecuteInstructions(opcode);
195 EXPECT_EQ(spc700.A, 0x69);
196 EXPECT_EQ(spc700.PSW.Z, 0);
197 EXPECT_EQ(spc700.PSW.N, 0);
202 uint8_t opcode = 0xE5;
203 uint16_t abs_addr = 0x1234;
204 uint8_t abs_value = 0x5A;
206 EXPECT_CALL(audioRAM, read(_))
207 .WillOnce(Return(abs_addr & 0xFF))
208 .WillOnce(Return(abs_addr >> 8));
210 EXPECT_CALL(audioRAM, read(abs_addr)).WillOnce(Return(abs_value));
212 spc700.ExecuteInstructions(opcode);
214 EXPECT_EQ(spc700.A, abs_value);
215 EXPECT_EQ(spc700.PSW.Z, 0);
216 EXPECT_EQ(spc700.PSW.N, 0);
224 uint8_t opcode = 0xE8;
225 uint8_t immediate_value = 0x5A;
227 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
229 spc700.ExecuteInstructions(opcode);
231 EXPECT_EQ(spc700.A, immediate_value);
232 EXPECT_EQ(spc700.PSW.Z, 0);
233 EXPECT_EQ(spc700.PSW.N, 0);
240 uint8_t opcode = 0x00;
242 uint16_t initialPC = spc700.PC;
243 spc700.ExecuteInstructions(opcode);
246 EXPECT_EQ(spc700.PC, initialPC + 1);
252 uint8_t opcode = 0x88;
253 uint8_t immediate_value = 0x10;
257 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
259 spc700.ExecuteInstructions(opcode);
262 EXPECT_EQ(spc700.A, 0x12);
268 uint8_t opcode = 0xF0;
269 int8_t offset = 0x05;
272 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
274 uint16_t initialPC = spc700.PC + 1;
275 spc700.ExecuteInstructions(opcode);
277 EXPECT_EQ(spc700.PC, initialPC + offset);
282 uint8_t opcode = 0x85;
283 uint16_t abs_addr = 0x1234;
287 EXPECT_CALL(audioRAM, read(_))
288 .WillOnce(Return(abs_addr & 0xFF))
289 .WillOnce(Return(abs_addr >> 8));
291 spc700.ExecuteInstructions(opcode);
296 uint8_t opcode = 0x88;
297 uint8_t immediate_value = 0x10;
300 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
302 spc700.ExecuteInstructions(opcode);
304 EXPECT_EQ(spc700.A, 0x25);
305 EXPECT_EQ(spc700.PSW.Z, 0);
306 EXPECT_EQ(spc700.PSW.N, 0);
307 EXPECT_EQ(spc700.PSW.C, 0);
312 uint8_t opcode = 0x2F;
313 int8_t offset = 0x05;
315 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
318 uint16_t initialPC = spc700.PC + 1;
319 spc700.ExecuteInstructions(opcode);
321 EXPECT_EQ(spc700.PC, initialPC + offset);
325 uint16_t address = 0x1234;
326 uint8_t expected_value = 0x5A;
328 EXPECT_CALL(audioRAM, read(address)).WillOnce(Return(expected_value));
330 uint8_t value = spc700.read(address);
331 EXPECT_EQ(value, expected_value);
335 uint16_t address = 0x1234;
336 uint8_t value = 0x5A;
338 EXPECT_CALL(audioRAM, write(address, value));
340 spc700.write(address, value);
345 uint8_t opcode = 0x28;
346 uint8_t immediate_value = 0x0F;
349 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
351 spc700.ExecuteInstructions(opcode);
353 EXPECT_EQ(spc700.A, 0x0A);
354 EXPECT_EQ(spc700.PSW.Z, 0);
355 EXPECT_EQ(spc700.PSW.N, 0);
360 uint8_t opcode = 0x08;
361 uint8_t immediate_value = 0x0F;
364 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
366 spc700.ExecuteInstructions(opcode);
368 EXPECT_EQ(spc700.A, 0xAF);
369 EXPECT_EQ(spc700.PSW.Z, 0);
375 uint8_t opcode = 0x48;
376 uint8_t immediate_value = 0x5A;
379 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
381 spc700.ExecuteInstructions(opcode);
383 EXPECT_EQ(spc700.A, 0x00);
384 EXPECT_EQ(spc700.PSW.Z, 1);
385 EXPECT_EQ(spc700.PSW.N, 0);
390 uint8_t opcode = 0xBC;
393 spc700.ExecuteInstructions(opcode);
395 EXPECT_EQ(spc700.A, 0x00);
396 EXPECT_EQ(spc700.PSW.Z, 1);
397 EXPECT_EQ(spc700.PSW.N, 0);
402 uint8_t opcode = 0x9C;
405 spc700.ExecuteInstructions(opcode);
407 EXPECT_EQ(spc700.A, 0x00);
408 EXPECT_EQ(spc700.PSW.Z, 1);
409 EXPECT_EQ(spc700.PSW.N, 0);
414 uint8_t opcode = 0xD0;
415 int8_t offset = 0x05;
418 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
420 uint16_t initialPC = spc700.PC + 1;
421 spc700.ExecuteInstructions(opcode);
423 EXPECT_EQ(spc700.PC, initialPC + offset);
428 uint8_t opcode = 0xD0;
429 int8_t offset = 0x05;
432 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
434 uint16_t initialPC = spc700.PC;
435 spc700.ExecuteInstructions(opcode);
437 EXPECT_EQ(spc700.PC, initialPC + 1);
442 uint8_t opcode = 0xF0;
443 int8_t offset = 0x05;
446 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
448 uint16_t initialPC = spc700.PC + 1;
449 spc700.ExecuteInstructions(opcode);
451 EXPECT_EQ(spc700.PC, initialPC + offset);
456 uint8_t opcode = 0xF0;
457 int8_t offset = 0x05;
460 EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
462 uint16_t initialPC = spc700.PC;
463 spc700.ExecuteInstructions(opcode);
465 EXPECT_EQ(spc700.PC, initialPC + 1);
AudioRam is an interface for the Audio RAM used by the SPC700.
virtual uint8_t & mutable_read(uint16_t address)=0
virtual void write(uint16_t address, uint8_t value)=0
virtual uint8_t read(uint16_t address) const =0
The Spc700 class represents the SPC700 processor.
void ExecuteInstructions(uint8_t opcode)
MockAudioRam is a mock class for the AudioRam class.
std::vector< uint8_t > internal_audio_ram_
MOCK_METHOD(void, reset,(),(override))
void SetupMemory(uint16_t address, const std::vector< uint8_t > &values)
MOCK_METHOD(uint8_t &, mutable_read,(uint16_t address),(override))
MOCK_METHOD(uint8_t, read,(uint16_t address),(const, override))
MOCK_METHOD(void, write,(uint16_t address, uint8_t value),(override))
testing::StrictMock< MockAudioRam > audioRAM
TEST_F(CpuTest, AsmParserTokenizerOk)