102 lines
5.0 KiB
Plaintext
102 lines
5.0 KiB
Plaintext
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
#import <XCTest/XCTest.h>
|
|
#include "../../../src/core/MachineSession.h"
|
|
#include "../../../src/core/hd6309.h"
|
|
#include <algorithm>
|
|
using namespace VCC::Mac;
|
|
namespace {
|
|
void prepare(MachineSession& machine, std::uint16_t count, bool native = false, std::uint8_t post = 0x12) {
|
|
std::vector<std::uint8_t> rom(0x8000,0x12);
|
|
rom[0x7ffe]=0x40; rom[0x7fff]=0;
|
|
rom[0x7ff0]=0x50; rom[0x7ff1]=0;
|
|
machine.load(rom,Processor::HD6309);
|
|
machine.debuggerWriteMemory(0x4000,{
|
|
0x10,0xce,0x70,0x00, // LDS #$7000
|
|
0x8e,0x60,0x00, // LDX #$6000
|
|
0x10,0x8e,0x61,0x00, // LDY #$6100
|
|
0x10,0x86,std::uint8_t(count >> 8),std::uint8_t(count), // LDW #count
|
|
0x11,0x38,post,0x12}); // TFM X+,Y+; NOP
|
|
machine.debuggerWriteMemory(0x6000,{0xa5,0x5a,0x42});
|
|
machine.debuggerWriteMemory(0x5000,{0x7c,0x62,0x00,0x20,0xfb}); // Handler must not run during trapping step.
|
|
if (native) {
|
|
machine.debuggerWriteMemory(0x5100,{0x11,0x3d,1});
|
|
machine.debuggerSetPC(0x5100); machine.debuggerStep(); machine.debuggerSetPC(0x4000);
|
|
}
|
|
for (unsigned i=0;i<4;++i) machine.debuggerStep();
|
|
}
|
|
}
|
|
@interface DebuggerTFMTests : XCTestCase
|
|
@end
|
|
@implementation DebuggerTFMTests
|
|
- (void)testCSourceStepDoesNotMistakeTFMTransfersForOneLineLoopIterations {
|
|
for (bool native : {false,true}) {
|
|
MachineSession machine; prepare(machine,3,native);
|
|
const auto at = machine.snapshot();
|
|
machine.debuggerStepSource(SourceStepMode::Into, {{0x400f,1,{0x11,0x38,0x12}},{0x4012,2,{0x12}}},
|
|
at.generation,at.debuggerProgramRevision,at.debuggerMappingFingerprint,at.cpu.PC);
|
|
machine.advance();
|
|
const auto after = machine.debuggerSnapshot(0x6100,3);
|
|
XCTAssertEqual(after.state,RunState::Paused); XCTAssertEqual(after.cpu.PC,0x4012);
|
|
XCTAssertEqual(after.cpu.X,0x6003); XCTAssertEqual(after.cpu.Y,0x6103);
|
|
XCTAssertEqual(after.cpu.E,0); XCTAssertEqual(after.cpu.F,0);
|
|
XCTAssertEqual(after.memory,(std::vector<std::uint8_t>{0xa5,0x5a,0x42}));
|
|
}
|
|
}
|
|
- (void)testTFMStepCompletesWholeTransferInBoth6309Modes {
|
|
for (bool native : {false,true}) {
|
|
MachineSession machine; prepare(machine,3,native);
|
|
const auto before=machine.debuggerSnapshot();
|
|
machine.debuggerStep();
|
|
const auto after=machine.debuggerSnapshot(0x6100,3);
|
|
XCTAssertEqual(after.cpu.PC,0x4012); XCTAssertEqual(after.cpu.X,0x6003); XCTAssertEqual(after.cpu.Y,0x6103);
|
|
XCTAssertEqual(after.cpu.E,0); XCTAssertEqual(after.cpu.F,0);
|
|
XCTAssertEqual(after.cpu.IsNative6309,native);
|
|
XCTAssertEqual(after.memory,(std::vector<std::uint8_t>{0xa5,0x5a,0x42}));
|
|
XCTAssertEqual(after.state,RunState::Paused); XCTAssertEqual(after.generation,before.generation);
|
|
XCTAssertEqual(after.cycles-before.cycles,15u);
|
|
machine.debuggerStep(); XCTAssertEqual(machine.debuggerSnapshot().cpu.PC,0x4013);
|
|
}
|
|
}
|
|
- (void)testPCChangeAndResetAbandonPreviousTFMContinuation {
|
|
for (bool reset : {false,true}) {
|
|
MachineSession machine; prepare(machine,100);
|
|
machine.debuggerSetPC(0x400f); // Release the preceding step's halt for one ordinary CPU slice.
|
|
HD6309Exec(1);
|
|
XCTAssertEqual(machine.debuggerSnapshot().cpu.PC,0x400f);
|
|
XCTAssertEqual(machine.debuggerSnapshot().cpu.F,99);
|
|
if (reset) {
|
|
machine.softReset();
|
|
machine.debuggerStep();
|
|
XCTAssertEqual(machine.debuggerSnapshot().cpu.PC,0x4004);
|
|
} else {
|
|
machine.debuggerWriteMemory(0x5200,{0x12,0x20,0xfd});
|
|
machine.debuggerSetPC(0x5200); machine.debuggerStep();
|
|
XCTAssertEqual(machine.debuggerSnapshot().cpu.PC,0x5201);
|
|
}
|
|
}
|
|
}
|
|
- (void)testInvalidTFMStopsAtTrapWithoutExecutingHandler {
|
|
MachineSession machine; prepare(machine,3,false,0x56);
|
|
const auto before=machine.debuggerSnapshot(0x6200,1);
|
|
machine.debuggerStep();
|
|
const auto after=machine.debuggerSnapshot(0x6200,1);
|
|
XCTAssertEqual(after.cpu.PC,0x5000); XCTAssertNotEqual(after.cpu.MD & 0x40,0);
|
|
XCTAssertEqual(after.memory,before.memory); XCTAssertEqual(after.state,RunState::Paused);
|
|
machine.debuggerStep(); XCTAssertEqual(machine.debuggerSnapshot().cpu.PC,0x5003);
|
|
}
|
|
- (void)testLargeTFMAccountsForEveryCompletedVideoFrame {
|
|
MachineSession machine; prepare(machine,20000);
|
|
// TFM X,Y+ reads a constant byte; keep the destination away from the
|
|
// instruction and stack so this is a long transfer, not self-modifying code.
|
|
machine.debuggerWriteMemory(0x400f,{0x11,0x3b,0x12});
|
|
machine.debuggerWriteMemory(0x4012,{0x12});
|
|
machine.debuggerSetPC(0x400f);
|
|
const auto before=machine.snapshot();
|
|
machine.debuggerStep();
|
|
const auto after=machine.snapshot();
|
|
XCTAssertEqual(after.cpu.PC,0x4012); XCTAssertGreaterThan(after.frames-before.frames,1u);
|
|
XCTAssertNotEqual(after.frame,nullptr); XCTAssertEqual(after.frame->number,after.frames);
|
|
XCTAssertEqual(after.cycles-before.cycles,60006u); XCTAssertEqual(after.state,RunState::Paused);
|
|
}
|
|
@end
|