2017-06-04 01:22:16 +00:00
|
|
|
//
|
|
|
|
// TestMachine.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/06/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-06-04 01:22:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "TestMachine.h"
|
|
|
|
#import "TestMachine+ForSubclassEyesOnly.h"
|
|
|
|
#include "AllRAMProcessor.hpp"
|
|
|
|
|
|
|
|
@interface CSTestMachine ()
|
|
|
|
- (void)testMachineDidTrapAtAddress:(uint16_t)address;
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark - C++ delegate handlers
|
|
|
|
|
|
|
|
class MachineTrapHandler: public CPU::AllRAMProcessor::TrapHandler {
|
2024-12-02 02:44:14 +00:00
|
|
|
public:
|
|
|
|
MachineTrapHandler(CSTestMachine *targetMachine) : target_(targetMachine) {}
|
2017-06-04 01:22:16 +00:00
|
|
|
|
2024-12-02 02:44:14 +00:00
|
|
|
void processor_did_trap(CPU::AllRAMProcessor &, uint16_t address) {
|
|
|
|
[target_ testMachineDidTrapAtAddress:address];
|
|
|
|
}
|
2017-06-04 01:22:16 +00:00
|
|
|
|
2024-12-02 02:44:14 +00:00
|
|
|
private:
|
|
|
|
CSTestMachine *target_;
|
2017-06-04 01:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma mark - The test machine
|
|
|
|
|
|
|
|
@implementation CSTestMachine {
|
|
|
|
MachineTrapHandler *_cppTrapHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init {
|
|
|
|
if(self = [super init]) {
|
|
|
|
_cppTrapHandler = new MachineTrapHandler(self);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
delete _cppTrapHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addTrapAddress:(uint16_t)trapAddress {
|
|
|
|
self.processor->set_trap_handler(_cppTrapHandler);
|
|
|
|
self.processor->add_trap_address(trapAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testMachineDidTrapAtAddress:(uint16_t)address {
|
|
|
|
[self.trapHandler testMachine:self didTrapAtAddress:address];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|