1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-16 18:30:32 +00:00

Added enough of a Z80 test machine to bridge up into Swift.

This commit is contained in:
Thomas Harte 2017-05-16 22:05:42 -04:00
parent 4f0775cc7c
commit 189317b80c
5 changed files with 120 additions and 37 deletions

View File

@ -413,6 +413,7 @@
4BF829661D8F732B001BAE39 /* Disk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF829641D8F732B001BAE39 /* Disk.cpp */; };
4BFCA1201ECBDC1500AC40C1 /* Z80AllRAM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA11D1ECBD9BD00AC40C1 /* Z80AllRAM.cpp */; };
4BFCA1241ECBDCB400AC40C1 /* AllRAMProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA1211ECBDCAF00AC40C1 /* AllRAMProcessor.cpp */; };
4BFCA1271ECBE33200AC40C1 /* TestMachineZ80.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA1261ECBE33200AC40C1 /* TestMachineZ80.mm */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -978,6 +979,8 @@
4BFCA11E1ECBD9BD00AC40C1 /* Z80AllRAM.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Z80AllRAM.hpp; path = Z80/Z80AllRAM.hpp; sourceTree = "<group>"; };
4BFCA1211ECBDCAF00AC40C1 /* AllRAMProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AllRAMProcessor.cpp; sourceTree = "<group>"; };
4BFCA1221ECBDCAF00AC40C1 /* AllRAMProcessor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = AllRAMProcessor.hpp; sourceTree = "<group>"; };
4BFCA1251ECBE33200AC40C1 /* TestMachineZ80.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestMachineZ80.h; sourceTree = "<group>"; };
4BFCA1261ECBE33200AC40C1 /* TestMachineZ80.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestMachineZ80.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -1181,11 +1184,13 @@
4B3BA0C81D318B44005DD7A7 /* MOS6522Bridge.h */,
4B3BA0CA1D318B44005DD7A7 /* MOS6532Bridge.h */,
4B3BA0CC1D318B44005DD7A7 /* TestMachine6502.h */,
4BFCA1251ECBE33200AC40C1 /* TestMachineZ80.h */,
4B3BA0C61D318B44005DD7A7 /* C1540Bridge.mm */,
4BEF6AA91D35CE9E00E73575 /* DigitalPhaseLockedLoopBridge.mm */,
4B3BA0C91D318B44005DD7A7 /* MOS6522Bridge.mm */,
4B3BA0CB1D318B44005DD7A7 /* MOS6532Bridge.mm */,
4B3BA0CD1D318B44005DD7A7 /* TestMachine6502.mm */,
4BFCA1261ECBE33200AC40C1 /* TestMachineZ80.mm */,
);
path = Bridges;
sourceTree = "<group>";
@ -2576,6 +2581,7 @@
4BD4A8D01E077FD20020D856 /* PCMTrackTests.mm in Sources */,
4B049CDD1DA3C82F00322067 /* BCDTest.swift in Sources */,
4B1D08061E0F7A1100763741 /* TimeTests.mm in Sources */,
4BFCA1271ECBE33200AC40C1 /* TestMachineZ80.mm in Sources */,
4B121F951E05E66800BFDA12 /* PCMPatchedTrackTests.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -3,6 +3,7 @@
//
#import "TestMachine6502.h"
#import "TestMachineZ80.h"
#import "MOS6522Bridge.h"
#import "MOS6532Bridge.h"
#import "C1540Bridge.h"

View File

@ -12,6 +12,8 @@
const uint8_t CSTestMachine6502JamOpcode = CPU::MOS6502::JamOpcode;
#pragma mark - C++ jam handler
class MachineJamHandler: public CPU::MOS6502::AllRAMProcessor::JamHandler {
public:
MachineJamHandler(CSTestMachine6502 *targetMachine) : _targetMachine(targetMachine) {}
@ -24,26 +26,9 @@ class MachineJamHandler: public CPU::MOS6502::AllRAMProcessor::JamHandler {
CSTestMachine6502 *_targetMachine;
};
@implementation CSTestMachine6502 {
CPU::MOS6502::AllRAMProcessor _processor;
MachineJamHandler *_cppJamHandler;
}
#pragma mark - Register enum map
- (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)returnFromSubroutine {
_processor.return_from_subroutine();
}
- (CPU::MOS6502::Register)registerForRegister:(CSTestMachine6502Register)reg {
static CPU::MOS6502::Register registerForRegister(CSTestMachine6502Register reg) {
switch (reg) {
case CSTestMachine6502RegisterProgramCounter: return CPU::MOS6502::Register::ProgramCounter;
case CSTestMachine6502RegisterLastOperationAddress: return CPU::MOS6502::Register::LastOperationAddress;
@ -52,29 +37,17 @@ class MachineJamHandler: public CPU::MOS6502::AllRAMProcessor::JamHandler {
case CSTestMachine6502RegisterX: return CPU::MOS6502::Register::X;
case CSTestMachine6502RegisterY: return CPU::MOS6502::Register::Y;
case CSTestMachine6502RegisterStackPointer: return CPU::MOS6502::Register::S;
default: break;
}
}
- (void)setValue:(uint16_t)value forRegister:(CSTestMachine6502Register)reg {
_processor.set_value_of_register([self registerForRegister:reg], value);
#pragma mark - Test class
@implementation CSTestMachine6502 {
CPU::MOS6502::AllRAMProcessor _processor;
MachineJamHandler *_cppJamHandler;
}
- (uint16_t)valueForRegister:(CSTestMachine6502Register)reg {
return _processor.get_value_of_register([self registerForRegister:reg]);
}
- (void)setData:(NSData *)data atAddress:(uint16_t)startAddress {
_processor.set_data_at_address(startAddress, data.length, (const uint8_t *)data.bytes);
}
- (void)runForNumberOfCycles:(int)cycles {
_processor.run_for_cycles(cycles);
}
- (BOOL)isJammed {
return _processor.is_jammed();
}
#pragma mark - Lifecycle
- (instancetype)init {
self = [super init];
@ -91,6 +64,34 @@ class MachineJamHandler: public CPU::MOS6502::AllRAMProcessor::JamHandler {
delete _cppJamHandler;
}
#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();
}
- (uint32_t)timestamp {
return _processor.get_timestamp();
}
@ -105,4 +106,14 @@ class MachineJamHandler: public CPU::MOS6502::AllRAMProcessor::JamHandler {
_processor.set_nmi_line(nmiLine);
}
#pragma mark - Actions
- (void)returnFromSubroutine {
_processor.return_from_subroutine();
}
- (void)runForNumberOfCycles:(int)cycles {
_processor.run_for_cycles(cycles);
}
@end

View File

@ -0,0 +1,24 @@
//
// TestMachineZ80.h
// Clock Signal
//
// Created by Thomas Harte on 16/05/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CSTestMachineZ80Register) {
CSTestMachineZ80RegisterProgramCounter,
CSTestMachineZ80RegisterStackPointer,
};
@interface TestMachineZ80 : NSObject
- (void)setData:(NSData *)data atAddress:(uint16_t)startAddress;
- (void)runForNumberOfCycles:(int)cycles;
- (void)setValue:(uint16_t)value forRegister:(CSTestMachineZ80Register)reg;
- (uint16_t)valueForRegister:(CSTestMachineZ80Register)reg;
@end

View File

@ -0,0 +1,41 @@
//
// TestMachineZ80.m
// Clock Signal
//
// Created by Thomas Harte on 16/05/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#import "TestMachineZ80.h"
#include "Z80AllRAM.hpp"
static CPU::Z80::Register registerForRegister(CSTestMachineZ80Register reg) {
switch (reg) {
case CSTestMachineZ80RegisterProgramCounter: return CPU::Z80::Register::ProgramCounter;
case CSTestMachineZ80RegisterStackPointer: return CPU::Z80::Register::StackPointer;
}
}
@implementation TestMachineZ80 {
CPU::Z80::AllRAMProcessor _processor;
}
#pragma mark - Accessors
- (void)setData:(NSData *)data atAddress:(uint16_t)startAddress {
_processor.set_data_at_address(startAddress, data.length, (const uint8_t *)data.bytes);
}
- (void)runForNumberOfCycles:(int)cycles {
_processor.run_for_cycles(cycles);
}
- (void)setValue:(uint16_t)value forRegister:(CSTestMachineZ80Register)reg {
_processor.set_value_of_register(registerForRegister(reg), value);
}
- (uint16_t)valueForRegister:(CSTestMachineZ80Register)reg {
return _processor.get_value_of_register(registerForRegister(reg));
}
@end