backend-infra-engineer: Pre-0.2.2 snapshot (2023)
This commit is contained in:
4177
test/emu/cpu_test.cc
Normal file
4177
test/emu/cpu_test.cc
Normal file
File diff suppressed because it is too large
Load Diff
146
test/emu/ppu_test.cc
Normal file
146
test/emu/ppu_test.cc
Normal file
@@ -0,0 +1,146 @@
|
||||
#include "app/emu/video/ppu.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "app/emu/cpu/clock.h"
|
||||
#include "app/emu/memory/memory.h"
|
||||
#include "app/emu/memory/mock_memory.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
|
||||
class MockPpu : public PpuInterface {
|
||||
public:
|
||||
MOCK_METHOD(void, Write, (uint16_t address, uint8_t data), (override));
|
||||
MOCK_METHOD(uint8_t, Read, (uint16_t address), (const, override));
|
||||
|
||||
MOCK_METHOD(void, RenderFrame, (), (override));
|
||||
MOCK_METHOD(void, RenderScanline, (), (override));
|
||||
MOCK_METHOD(void, RenderBackground, (int layer), (override));
|
||||
MOCK_METHOD(void, RenderSprites, (), (override));
|
||||
|
||||
MOCK_METHOD(void, Init, (), (override));
|
||||
MOCK_METHOD(void, Reset, (), (override));
|
||||
MOCK_METHOD(void, Update, (double deltaTime), (override));
|
||||
MOCK_METHOD(void, UpdateClock, (double deltaTime), (override));
|
||||
MOCK_METHOD(void, UpdateInternalState, (int cycles), (override));
|
||||
|
||||
MOCK_METHOD(const std::vector<uint8_t>&, GetFrameBuffer, (),
|
||||
(const, override));
|
||||
MOCK_METHOD(std::shared_ptr<gfx::Bitmap>, GetScreen, (), (const, override));
|
||||
|
||||
MOCK_METHOD(void, UpdateModeSettings, (), (override));
|
||||
MOCK_METHOD(void, UpdateTileData, (), (override));
|
||||
MOCK_METHOD(void, UpdateTileMapData, (), (override));
|
||||
MOCK_METHOD(void, UpdatePaletteData, (), (override));
|
||||
|
||||
MOCK_METHOD(void, ApplyEffects, (), (override));
|
||||
MOCK_METHOD(void, ComposeLayers, (), (override));
|
||||
|
||||
MOCK_METHOD(void, DisplayFrameBuffer, (), (override));
|
||||
MOCK_METHOD(void, Notify, (uint32_t address, uint8_t data), (override));
|
||||
|
||||
std::vector<uint8_t> internalFrameBuffer;
|
||||
std::vector<uint8_t> vram;
|
||||
std::vector<SpriteAttributes> sprites;
|
||||
std::vector<Tilemap> tilemaps;
|
||||
BackgroundMode bgMode;
|
||||
};
|
||||
|
||||
class PpuTest : public ::testing::Test {
|
||||
protected:
|
||||
MockMemory mock_memory;
|
||||
MockClock mock_clock;
|
||||
MockPpu mock_ppu;
|
||||
|
||||
PpuTest() {}
|
||||
|
||||
void SetUp() override {
|
||||
ON_CALL(mock_ppu, Init()).WillByDefault([this]() {
|
||||
mock_ppu.internalFrameBuffer.resize(256 * 240);
|
||||
mock_ppu.vram.resize(0x10000);
|
||||
});
|
||||
|
||||
ON_CALL(mock_ppu, Write(::testing::_, ::testing::_))
|
||||
.WillByDefault([this](uint16_t address, uint8_t data) {
|
||||
mock_ppu.vram[address] = data;
|
||||
});
|
||||
|
||||
ON_CALL(mock_ppu, Read(::testing::_))
|
||||
.WillByDefault(
|
||||
[this](uint16_t address) { return mock_ppu.vram[address]; });
|
||||
|
||||
ON_CALL(mock_ppu, RenderScanline()).WillByDefault([this]() {
|
||||
// Simulate scanline rendering logic...
|
||||
});
|
||||
|
||||
ON_CALL(mock_ppu, GetFrameBuffer()).WillByDefault([this]() {
|
||||
return mock_ppu.internalFrameBuffer;
|
||||
});
|
||||
|
||||
// Additional ON_CALL setups as needed...
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
// Common cleanup (if necessary)
|
||||
}
|
||||
|
||||
const uint8_t testVRAMValue = 0xAB;
|
||||
const uint16_t testVRAMAddress = 0x2000;
|
||||
const std::vector<uint8_t> spriteData = {/* ... */};
|
||||
const std::vector<uint8_t> bgData = {/* ... */};
|
||||
const uint8_t testPaletteIndex = 3;
|
||||
const uint16_t testTileIndex = 42;
|
||||
};
|
||||
|
||||
// Test Initialization
|
||||
TEST_F(PpuTest, InitializationSetsCorrectFrameBufferSize) {
|
||||
// EXPECT_CALL(mock_ppu, Init()).Times(1);
|
||||
// mock_ppu.Init();
|
||||
// EXPECT_EQ(mock_ppu.GetFrameBuffer().size(), 256 * 240);
|
||||
}
|
||||
|
||||
// Test State Reset
|
||||
TEST_F(PpuTest, ResetClearsFrameBuffer) {
|
||||
// EXPECT_CALL(mock_ppu, Reset()).Times(1);
|
||||
// mock_ppu.Reset();
|
||||
// auto frameBuffer = mock_ppu.GetFrameBuffer();
|
||||
// EXPECT_TRUE(std::all_of(frameBuffer.begin(), frameBuffer.end(),
|
||||
// [](uint8_t val) { return val == 0; }));
|
||||
}
|
||||
|
||||
// Test Memory Interaction
|
||||
TEST_F(PpuTest, ReadWriteVRAM) {
|
||||
// uint16_t address = testVRAMAddress;
|
||||
// uint8_t value = testVRAMValue;
|
||||
// EXPECT_CALL(mock_ppu, Write(address, value)).Times(1);
|
||||
// mock_ppu.Write(address, value);
|
||||
// EXPECT_EQ(mock_ppu.Read(address), value);
|
||||
}
|
||||
|
||||
// Test Rendering Mechanics
|
||||
TEST_F(PpuTest, RenderScanlineUpdatesFrameBuffer) {
|
||||
// Setup PPU with necessary background and sprite data
|
||||
// Call RenderScanline and check if the framebuffer is updated correctly
|
||||
}
|
||||
|
||||
// Test Mode and Register Handling
|
||||
TEST_F(PpuTest, Mode0Rendering) {
|
||||
// Set PPU to Mode0 and verify correct rendering behavior
|
||||
}
|
||||
|
||||
// Test Interrupts and Counters
|
||||
TEST_F(PpuTest, VBlankInterruptTriggered) {
|
||||
// Simulate conditions for V-Blank and test if the interrupt is triggered
|
||||
}
|
||||
|
||||
// Test Composite Rendering and Output
|
||||
TEST_F(PpuTest, FrameComposition) {
|
||||
// Setup various layers and sprites, call ComposeLayers, and verify the frame
|
||||
// buffer
|
||||
}
|
||||
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
466
test/emu/spc700_test.cc
Normal file
466
test/emu/spc700_test.cc
Normal file
@@ -0,0 +1,466 @@
|
||||
#include "app/emu/audio/spc700.h"
|
||||
|
||||
#include <gmock/gmock-nice-strict.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
|
||||
class MockAudioRam : public AudioRam {
|
||||
public:
|
||||
MOCK_METHOD(void, reset, (), (override));
|
||||
MOCK_METHOD(uint8_t, read, (uint16_t address), (const, override));
|
||||
MOCK_METHOD(uint8_t&, mutable_read, (uint16_t address), (override));
|
||||
MOCK_METHOD(void, write, (uint16_t address, uint8_t value), (override));
|
||||
|
||||
void SetupMemory(uint16_t address, const std::vector<uint8_t>& values) {
|
||||
if (address > internal_audio_ram_.size()) {
|
||||
internal_audio_ram_.resize(address + values.size());
|
||||
}
|
||||
int i = 0;
|
||||
for (const auto& each : values) {
|
||||
internal_audio_ram_[address + i] = each;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() {
|
||||
// internal_audio_ram_.resize(0x10000); // 64 K (0x10000)
|
||||
// std::fill(internal_audio_ram_.begin(), internal_audio_ram_.end(), 0);
|
||||
ON_CALL(*this, read(_)).WillByDefault([this](uint16_t address) {
|
||||
return internal_audio_ram_[address];
|
||||
});
|
||||
ON_CALL(*this, mutable_read(_))
|
||||
.WillByDefault([this](uint16_t address) -> uint8_t& {
|
||||
return internal_audio_ram_[address];
|
||||
});
|
||||
ON_CALL(*this, write(_, _))
|
||||
.WillByDefault([this](uint16_t address, uint8_t value) {
|
||||
internal_audio_ram_[address] = value;
|
||||
});
|
||||
ON_CALL(*this, reset()).WillByDefault([this]() {
|
||||
std::fill(internal_audio_ram_.begin(), internal_audio_ram_.end(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<uint8_t> internal_audio_ram_ = std::vector<uint8_t>(0x10000, 0);
|
||||
};
|
||||
|
||||
class Spc700Test : public ::testing::Test {
|
||||
public:
|
||||
Spc700Test() = default;
|
||||
void SetUp() override {
|
||||
// Set up the mock
|
||||
audioRAM.SetUp();
|
||||
|
||||
// Set the Spc700 to bank 01
|
||||
spc700.PC = 0x0100;
|
||||
}
|
||||
|
||||
testing::StrictMock<MockAudioRam> audioRAM;
|
||||
Spc700 spc700{audioRAM};
|
||||
};
|
||||
|
||||
// ========================================================
|
||||
// 8-bit Move Memory to Register
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_Immediate) {
|
||||
// MOV A, imm
|
||||
uint8_t opcode = 0xE8;
|
||||
uint8_t immediate_value = 0x5A;
|
||||
audioRAM.SetupMemory(0x0100, {opcode, immediate_value});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, immediate_value);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_X) {
|
||||
// MOV A, X
|
||||
uint8_t opcode = 0x7D;
|
||||
spc700.X = 0x5A;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, spc700.X);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_Y) {
|
||||
// MOV A, Y
|
||||
uint8_t opcode = 0xDD;
|
||||
spc700.Y = 0x5A;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, spc700.Y);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp) {
|
||||
// MOV A, dp
|
||||
uint8_t opcode = 0xE4;
|
||||
uint8_t dp_value = 0x5A;
|
||||
audioRAM.SetupMemory(0x005A, {0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value))
|
||||
.WillOnce(Return(0x42));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x42);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp_plus_x) {
|
||||
// MOV A, dp+X
|
||||
uint8_t opcode = 0xF4;
|
||||
uint8_t dp_value = 0x5A;
|
||||
spc700.X = 0x01;
|
||||
audioRAM.SetupMemory(0x005B, {0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value + spc700.X))
|
||||
.WillOnce(Return(0x42));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x42);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp_indirect_plus_y) {
|
||||
// MOV A, [dp]+Y
|
||||
uint8_t opcode = 0xF7;
|
||||
uint8_t dp_value = 0x5A;
|
||||
spc700.Y = 0x01;
|
||||
audioRAM.SetupMemory(0x005A, {0x00, 0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
audioRAM.SetupMemory(0x4201, {0x69});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value))
|
||||
.WillOnce(Return(0x4200))
|
||||
.WillOnce(Return(0x69));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x69);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp_plus_x_indirect) {
|
||||
// MOV A, [dp+X]
|
||||
uint8_t opcode = 0xE7;
|
||||
uint8_t dp_value = 0x5A;
|
||||
spc700.X = 0x01;
|
||||
audioRAM.SetupMemory(0x005B, {0x00, 0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
audioRAM.SetupMemory(0x4200, {0x69});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value + 1))
|
||||
.WillOnce(Return(0x4200))
|
||||
.WillOnce(Return(0x69));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x69);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_abs) {
|
||||
// MOV A, !abs
|
||||
uint8_t opcode = 0xE5;
|
||||
uint16_t abs_addr = 0x1234;
|
||||
uint8_t abs_value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(abs_addr & 0xFF)) // Low byte
|
||||
.WillOnce(Return(abs_addr >> 8)); // High byte
|
||||
|
||||
EXPECT_CALL(audioRAM, read(abs_addr)).WillOnce(Return(abs_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, abs_value);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 8-bit Move Register to Memory
|
||||
|
||||
TEST_F(Spc700Test, MOV_Immediate) {
|
||||
// MOV A, imm
|
||||
uint8_t opcode = 0xE8;
|
||||
uint8_t immediate_value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, immediate_value);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
TEST_F(Spc700Test, NOP_DoesNothing) {
|
||||
// NOP opcode
|
||||
uint8_t opcode = 0x00;
|
||||
|
||||
uint16_t initialPC = spc700.PC;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
// PC should increment by 1, no other changes
|
||||
EXPECT_EQ(spc700.PC, initialPC + 1);
|
||||
// Add checks for other registers if needed
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ADC_A_Immediate) {
|
||||
// ADC A, #imm
|
||||
uint8_t opcode = 0x88;
|
||||
uint8_t immediate_value = 0x10;
|
||||
spc700.A = 0x01;
|
||||
spc700.PSW.C = 1; // Assume carry is set
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
// Verify A, and flags
|
||||
EXPECT_EQ(spc700.A, 0x12); // 0x01 + 0x10 + 1 (carry)
|
||||
// Check for other flags (Z, C, etc.) based on the result
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, BEQ_BranchesIfZeroFlagSet) {
|
||||
// BEQ rel
|
||||
uint8_t opcode = 0xF0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 1; // Set Zero flag
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, STA_Absolute) {
|
||||
// STA !abs
|
||||
uint8_t opcode = 0x85;
|
||||
uint16_t abs_addr = 0x1234;
|
||||
spc700.A = 0x80;
|
||||
|
||||
// Set up the mock to return the address for the absolute addressing
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(abs_addr & 0xFF)) // Low byte
|
||||
.WillOnce(Return(abs_addr >> 8)); // High byte
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteADCWithImmediate) {
|
||||
// ADC A, imm
|
||||
uint8_t opcode = 0x88; // Replace with opcode for ADC A, imm
|
||||
uint8_t immediate_value = 0x10;
|
||||
spc700.A = 0x15;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x25); // 0x15 + 0x10
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
EXPECT_EQ(spc700.PSW.C, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBRA) {
|
||||
// BRA
|
||||
uint8_t opcode = 0x2F;
|
||||
int8_t offset = 0x05;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
// rel() moves the PC forward one after read
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ReadFromAudioRAM) {
|
||||
uint16_t address = 0x1234;
|
||||
uint8_t expected_value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(address)).WillOnce(Return(expected_value));
|
||||
|
||||
uint8_t value = spc700.read(address);
|
||||
EXPECT_EQ(value, expected_value);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, WriteToAudioRAM) {
|
||||
uint16_t address = 0x1234;
|
||||
uint8_t value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, write(address, value));
|
||||
|
||||
spc700.write(address, value);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteANDWithImmediate) {
|
||||
// AND A, imm
|
||||
uint8_t opcode = 0x28;
|
||||
uint8_t immediate_value = 0x0F;
|
||||
spc700.A = 0x5A; // 0101 1010
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x0A); // 0101 1010 & 0000 1111 = 0000 1010
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteORWithImmediate) {
|
||||
// OR A, imm
|
||||
uint8_t opcode = 0x08;
|
||||
uint8_t immediate_value = 0x0F;
|
||||
spc700.A = 0xA0; // 1010 0000
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0xAF); // 1010 0000 | 0000 1111 = 1010 1111
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
// EXPECT_EQ(spc700.PSW.N, 1);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteEORWithImmediate) {
|
||||
// EOR A, imm
|
||||
uint8_t opcode = 0x48;
|
||||
uint8_t immediate_value = 0x5A;
|
||||
spc700.A = 0x5A; // 0101 1010
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x00); // 0101 1010 ^ 0101 1010 = 0000 0000
|
||||
EXPECT_EQ(spc700.PSW.Z, 1);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteINC) {
|
||||
// INC A
|
||||
uint8_t opcode = 0xBC;
|
||||
spc700.A = 0xFF;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x00);
|
||||
EXPECT_EQ(spc700.PSW.Z, 1);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteDEC) {
|
||||
// DEC A
|
||||
uint8_t opcode = 0x9C;
|
||||
spc700.A = 0x01;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x00);
|
||||
EXPECT_EQ(spc700.PSW.Z, 1);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBNEWhenNotEqual) {
|
||||
// BNE
|
||||
uint8_t opcode = 0xD0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 0;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBNEWhenEqual) {
|
||||
// BNE
|
||||
uint8_t opcode = 0xD0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 1;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + 1); // +1 because of reading the offset
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBEQWhenEqual) {
|
||||
// BEQ
|
||||
uint8_t opcode = 0xF0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 1;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBEQWhenNotEqual) {
|
||||
// BEQ
|
||||
uint8_t opcode = 0xF0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 0;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + 1); // +1 because of reading the offset
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, BootIplRomOk) {
|
||||
// Boot the IPL ROM
|
||||
// spc700.BootIplRom();
|
||||
// EXPECT_EQ(spc700.PC, 0xFFC1 + 0x3F);
|
||||
}
|
||||
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
Reference in New Issue
Block a user