2015-07-17 00:15:30 +00:00
|
|
|
//
|
|
|
|
// Machine.m
|
2015-07-26 19:25:11 +00:00
|
|
|
// CLK
|
2015-07-17 00:15:30 +00:00
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 29/06/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2017-05-15 12:18:57 +00:00
|
|
|
#import "TestMachine6502.h"
|
2015-07-17 00:15:30 +00:00
|
|
|
#include <stdint.h>
|
2017-05-15 02:08:15 +00:00
|
|
|
#include "6502AllRAM.hpp"
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-05-15 12:18:57 +00:00
|
|
|
const uint8_t CSTestMachine6502JamOpcode = CPU::MOS6502::JamOpcode;
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
#pragma mark - C++ jam handler
|
|
|
|
|
2017-05-15 02:08:15 +00:00
|
|
|
class MachineJamHandler: public CPU::MOS6502::AllRAMProcessor::JamHandler {
|
2015-07-17 00:15:30 +00:00
|
|
|
public:
|
2017-05-15 12:18:57 +00:00
|
|
|
MachineJamHandler(CSTestMachine6502 *targetMachine) : _targetMachine(targetMachine) {}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-05-15 02:08:15 +00:00
|
|
|
void processor_did_jam(CPU::MOS6502::AllRAMProcessor::Processor *processor, uint16_t address) override {
|
2015-07-17 00:15:30 +00:00
|
|
|
[_targetMachine.jamHandler testMachine:_targetMachine didJamAtAddress:address];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-05-15 12:18:57 +00:00
|
|
|
CSTestMachine6502 *_targetMachine;
|
2015-07-17 00:15:30 +00:00
|
|
|
};
|
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
#pragma mark - Register enum map
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
static CPU::MOS6502::Register registerForRegister(CSTestMachine6502Register reg) {
|
2015-07-17 00:15:30 +00:00
|
|
|
switch (reg) {
|
2017-05-15 12:18:57 +00:00
|
|
|
case CSTestMachine6502RegisterProgramCounter: return CPU::MOS6502::Register::ProgramCounter;
|
|
|
|
case CSTestMachine6502RegisterLastOperationAddress: return CPU::MOS6502::Register::LastOperationAddress;
|
|
|
|
case CSTestMachine6502RegisterFlags: return CPU::MOS6502::Register::Flags;
|
|
|
|
case CSTestMachine6502RegisterA: return CPU::MOS6502::Register::A;
|
|
|
|
case CSTestMachine6502RegisterX: return CPU::MOS6502::Register::X;
|
|
|
|
case CSTestMachine6502RegisterY: return CPU::MOS6502::Register::Y;
|
|
|
|
case CSTestMachine6502RegisterStackPointer: return CPU::MOS6502::Register::S;
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
#pragma mark - Test class
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
@implementation CSTestMachine6502 {
|
|
|
|
CPU::MOS6502::AllRAMProcessor _processor;
|
|
|
|
MachineJamHandler *_cppJamHandler;
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
#pragma mark - Lifecycle
|
2015-07-17 00:15:30 +00:00
|
|
|
|
|
|
|
- (instancetype)init {
|
|
|
|
self = [super init];
|
|
|
|
|
2016-04-25 02:32:24 +00:00
|
|
|
if(self) {
|
2015-07-17 00:15:30 +00:00
|
|
|
_cppJamHandler = new MachineJamHandler(self);
|
|
|
|
_processor.set_jam_handler(_cppJamHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
delete _cppJamHandler;
|
|
|
|
}
|
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
#pragma mark - Accessors
|
|
|
|
|
|
|
|
- (uint8_t)valueForAddress:(uint16_t)address {
|
|
|
|
uint8_t value;
|
|
|
|
_processor.perform_bus_operation(CPU::MOS6502::BusOperation::Read, address, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setValue:(uint8_t)value forAddress:(uint16_t)address {
|
|
|
|
_processor.perform_bus_operation(CPU::MOS6502::BusOperation::Write, address, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setValue:(uint16_t)value forRegister:(CSTestMachine6502Register)reg {
|
|
|
|
_processor.set_value_of_register(registerForRegister(reg), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint16_t)valueForRegister:(CSTestMachine6502Register)reg {
|
|
|
|
return _processor.get_value_of_register(registerForRegister(reg));
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setData:(NSData *)data atAddress:(uint16_t)startAddress {
|
|
|
|
_processor.set_data_at_address(startAddress, data.length, (const uint8_t *)data.bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isJammed {
|
|
|
|
return _processor.is_jammed();
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:06:56 +00:00
|
|
|
- (uint32_t)timestamp {
|
|
|
|
return _processor.get_timestamp();
|
|
|
|
}
|
|
|
|
|
2016-06-29 01:29:43 +00:00
|
|
|
- (void)setIrqLine:(BOOL)irqLine {
|
|
|
|
_irqLine = irqLine;
|
|
|
|
_processor.set_irq_line(irqLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setNmiLine:(BOOL)nmiLine {
|
|
|
|
_nmiLine = nmiLine;
|
|
|
|
_processor.set_nmi_line(nmiLine);
|
|
|
|
}
|
|
|
|
|
2017-05-17 02:05:42 +00:00
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
|
|
- (void)returnFromSubroutine {
|
|
|
|
_processor.return_from_subroutine();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)runForNumberOfCycles:(int)cycles {
|
|
|
|
_processor.run_for_cycles(cycles);
|
|
|
|
}
|
|
|
|
|
2015-07-17 00:15:30 +00:00
|
|
|
@end
|