1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 20:29:42 +00:00

Added test for NOP, discovering the undocumented ones to be the incorrect length.

This commit is contained in:
Thomas Harte 2015-08-13 07:32:50 +01:00
parent 6616265d93
commit cc98534f94
2 changed files with 69 additions and 7 deletions

View File

@ -41,6 +41,14 @@ class TimingTests: XCTestCase, CSTestMachineJamHandler {
self.runTest(code, expectedRunLength: 48)
}
func testBIT() {
let code: [UInt8] = [
0x24, 0x2a, // [3] BIT $2a
0x2c, 0x2a, 0x2b, // [4] BIT $2b2a
CSTestMachineJamOpcode]
self.runTest(code, expectedRunLength: 7)
}
func testSTA() {
let code: [UInt8] = [
0x85, 0x00, // [3] STA $00
@ -140,6 +148,53 @@ class TimingTests: XCTestCase, CSTestMachineJamHandler {
self.runTest(code, expectedRunLength: 11)
}
func testSnippet3() {
let code: [UInt8] = [
0x20, 0x04, 0x02, // [6] JSR $0204
CSTestMachineJamOpcode,
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x85, 0x09, // [3] STA $09
0x85, 0x09, // [3] STA $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x85, 0x09, // [3] STA $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x85, 0x09, // [3] STA $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x86, 0x09, // [3] STX $09
0x87, 0x09, // [3] SAX $09
0x60, // [6] RTS
CSTestMachineJamOpcode]
self.runTest(code, expectedRunLength: 66)
}
func testNOP() {
let code: [UInt8] = [
0x04, 0x00, // [3] NOP zpg
0x14, 0x00, // [4] NOP zpg, x
0x34, 0x00, // [4] NOP zpg, x
0x44, 0x00, // [3] NOP zpg
0x54, 0x00, // [4] NOP zpg, x
0x64, 0x00, // [3] NOP zpg
0x74, 0x00, // [4] NOP zpg, x
0x80, 0x00, // [2] NOP #
0x82, 0x00, // [2] NOP #
0x89, 0x00, // [2] NOP #
0xc2, 0x00, // [2] NOP #
0xd4, 0x00, // [4] NOP zpg, x
0xe2, 0x00, // [2] NOP #
0xf4, 0x00, // [4] NOP zpg, x
CSTestMachineJamOpcode]
self.runTest(code, expectedRunLength: 43)
}
func runTest(code: [UInt8], expectedRunLength: UInt32) {
let machine = CSTestMachine()

View File

@ -149,14 +149,14 @@ template <class T> class Processor {
#define IndirectIndexedr CycleIncrementPCFetchAddressLowFromOperand, CycleIncrementOperandFetchAddressHigh, CycleAddYToAddressLow, OperationCorrectAddressHigh
#define IndirectIndexed CycleIncrementPCFetchAddressLowFromOperand, CycleIncrementOperandFetchAddressHigh, CycleAddYToAddressLowRead, OperationCorrectAddressHigh
#define Read(op) CycleFetchOperandFromAddress, op
#define Write(op) op, CycleWriteOperandToAddress
#define Read(...) CycleFetchOperandFromAddress, __VA_ARGS__
#define Write(...) __VA_ARGS__, CycleWriteOperandToAddress
#define ReadModifyWrite(...) CycleFetchOperandFromAddress, CycleWriteOperandToAddress, __VA_ARGS__, CycleWriteOperandToAddress
#define AbsoluteRead(op) Program(Absolute, Read(op))
#define AbsoluteXRead(op) Program(AbsoluteXr, Read(op))
#define AbsoluteYRead(op) Program(AbsoluteYr, Read(op))
#define ZeroRead(op) Program(Zero, Read(op))
#define ZeroRead(...) Program(Zero, Read(__VA_ARGS__))
#define ZeroXRead(op) Program(ZeroX, Read(op))
#define ZeroYRead(op) Program(ZeroY, Read(op))
#define IndexedIndirectRead(op) Program(IndexedIndirect, Read(op))
@ -183,8 +183,8 @@ template <class T> class Processor {
#define Immediate(op) Program(OperationIncrementPC, op)
#define Implied(op) Program(OperationCopyOperandFromA, op, OperationCopyOperandToA)
#define ZeroNop() Program(Zero)
#define ZeroXNop() Program(ZeroX)
#define ZeroNop() Program(Zero, CycleFetchOperandFromAddress)
#define ZeroXNop() Program(ZeroX, CycleFetchOperandFromAddress)
#define AbsoluteNop() Program(Absolute)
#define AbsoluteXNop() Program(AbsoluteX)
#define ImpliedNop() {OperationMoveToNextProgram}
@ -460,11 +460,18 @@ template <class T> class Processor {
#pragma mark - Fetch/Decode
case CycleFetchOperation:
case CycleFetchOperation: {
_lastOperationPC = _pc;
_pc.full++;
read_op(_operation, _lastOperationPC.full);
break;
// static int last_cycles_left_to_run = 0;
// if(last_cycles_left_to_run > _cycles_left_to_run)
// printf("%02x %d\n", _operation, last_cycles_left_to_run - _cycles_left_to_run);
// else
// printf("%02x\n", _operation);
// last_cycles_left_to_run = _cycles_left_to_run;
} break;
case CycleFetchOperand:
read_mem(_operand, _pc.full);