mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-04 14:30:19 +00:00
Merge pull request #37 from TomHarte/C++Style
Eliminates plain pointer passes for object types
This commit is contained in:
commit
6851a1b63b
@ -286,7 +286,7 @@ template <class T> class MOS6522 {
|
||||
void set_port_output(Port port, uint8_t value, uint8_t direction_mask) {}
|
||||
bool get_control_line(Port port, Line line) { return true; }
|
||||
void set_control_line_output(Port port, Line line, bool value) {}
|
||||
// void set_interrupt_status(bool status) {}
|
||||
void set_interrupt_status(bool status) {}
|
||||
|
||||
// Input/output multiplexer
|
||||
uint8_t get_port_input(Port port, uint8_t output_mask, uint8_t output)
|
||||
|
@ -12,6 +12,7 @@ using namespace MOS;
|
||||
|
||||
MOS6560::MOS6560() :
|
||||
_crt(new Outputs::CRT::CRT(65*4, 4, Outputs::CRT::NTSC60, 1)),
|
||||
_speaker(new Speaker),
|
||||
_horizontal_counter(0),
|
||||
_vertical_counter(0),
|
||||
_cycles_since_speaker_update(0),
|
||||
@ -34,7 +35,7 @@ MOS6560::MOS6560() :
|
||||
|
||||
// show only the centre
|
||||
_crt->set_visible_area(_crt->get_rect_for_area(16, 237, 11*4, 55*4, 4.0f / 3.0f));
|
||||
_speaker.set_input_rate(255681.75); // assuming NTSC; clock rate / 4
|
||||
_speaker->set_input_rate(255681.75); // assuming NTSC; clock rate / 4
|
||||
}
|
||||
|
||||
void MOS6560::set_output_mode(OutputMode output_mode)
|
||||
@ -119,13 +120,13 @@ void MOS6560::set_register(int address, uint8_t value)
|
||||
case 0xc:
|
||||
case 0xd:
|
||||
update_audio();
|
||||
_speaker.set_control(address - 0xa, value);
|
||||
_speaker->set_control(address - 0xa, value);
|
||||
break;
|
||||
|
||||
case 0xe:
|
||||
update_audio();
|
||||
_registers.auxiliary_colour = _colours[value >> 4];
|
||||
_speaker.set_volume(value & 0xf);
|
||||
_speaker->set_volume(value & 0xf);
|
||||
break;
|
||||
|
||||
case 0xf:
|
||||
@ -361,7 +362,7 @@ void MOS6560::set_graphics_value(uint8_t value, uint8_t colour_value)
|
||||
|
||||
void MOS6560::update_audio()
|
||||
{
|
||||
_speaker.run_for_cycles(_cycles_since_speaker_update >> 2);
|
||||
_speaker->run_for_cycles(_cycles_since_speaker_update >> 2);
|
||||
_cycles_since_speaker_update &= 3;
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ namespace MOS {
|
||||
class MOS6560 {
|
||||
public:
|
||||
MOS6560();
|
||||
Outputs::CRT::CRT *get_crt() { return _crt.get(); }
|
||||
Outputs::Speaker *get_speaker() { return &_speaker; }
|
||||
std::shared_ptr<Outputs::CRT::CRT> get_crt() { return _crt; }
|
||||
std::shared_ptr<Outputs::Speaker> get_speaker() { return _speaker; }
|
||||
|
||||
enum OutputMode {
|
||||
PAL, NTSC
|
||||
@ -63,7 +63,7 @@ class MOS6560 {
|
||||
uint8_t get_register(int address);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Outputs::CRT::CRT> _crt;
|
||||
std::shared_ptr<Outputs::CRT::CRT> _crt;
|
||||
|
||||
// audio state
|
||||
class Speaker: public ::Outputs::Filter<Speaker> {
|
||||
@ -81,7 +81,8 @@ class MOS6560 {
|
||||
unsigned int _shift_registers[4];
|
||||
uint8_t _control_registers[4];
|
||||
uint8_t _volume;
|
||||
} _speaker;
|
||||
};
|
||||
std::shared_ptr<Speaker> _speaker;
|
||||
unsigned int _cycles_since_speaker_update;
|
||||
void update_audio();
|
||||
|
||||
|
@ -56,7 +56,8 @@ Machine::Machine() :
|
||||
|
||||
void Machine::setup_output(float aspect_ratio)
|
||||
{
|
||||
_crt = new Outputs::CRT::CRT(228, 1, 263, Outputs::CRT::ColourSpace::YIQ, 228, 1, 1);
|
||||
_speaker.reset(new Speaker);
|
||||
_crt.reset(new Outputs::CRT::CRT(228, 1, 263, Outputs::CRT::ColourSpace::YIQ, 228, 1, 1));
|
||||
_crt->set_output_device(Outputs::CRT::Television);
|
||||
|
||||
// this is the NTSC phase offset function; see below for PAL
|
||||
@ -70,7 +71,7 @@ void Machine::setup_output(float aspect_ratio)
|
||||
"float phaseOffset = 6.283185308 * float(iPhase - 1u) / 13.0;"
|
||||
"return mix(float(y) / 14.0, step(1, iPhase) * cos(phase + phaseOffset), amplitude);"
|
||||
"}");
|
||||
_speaker.set_input_rate((float)(get_clock_rate() / 38.0));
|
||||
_speaker->set_input_rate((float)(get_clock_rate() / 38.0));
|
||||
}
|
||||
|
||||
void Machine::switch_region()
|
||||
@ -92,15 +93,14 @@ void Machine::switch_region()
|
||||
_crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1);
|
||||
|
||||
_is_pal_region = true;
|
||||
_speaker.set_input_rate((float)(get_clock_rate() / 38.0));
|
||||
_speaker->set_input_rate((float)(get_clock_rate() / 38.0));
|
||||
|
||||
if(delegate) delegate->machine_did_change_clock_rate(this);
|
||||
}
|
||||
|
||||
void Machine::close_output()
|
||||
{
|
||||
delete _crt;
|
||||
_crt = nullptr;
|
||||
_crt.reset();
|
||||
}
|
||||
|
||||
Machine::~Machine()
|
||||
@ -598,17 +598,17 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
|
||||
case 0x15: case 0x16:
|
||||
update_audio();
|
||||
_speaker.set_control(decodedAddress - 0x15, *value);
|
||||
_speaker->set_control(decodedAddress - 0x15, *value);
|
||||
break;
|
||||
|
||||
case 0x17: case 0x18:
|
||||
update_audio();
|
||||
_speaker.set_divider(decodedAddress - 0x17, *value);
|
||||
_speaker->set_divider(decodedAddress - 0x17, *value);
|
||||
break;
|
||||
|
||||
case 0x19: case 0x1a:
|
||||
update_audio();
|
||||
_speaker.set_volume(decodedAddress - 0x19, *value);
|
||||
_speaker->set_volume(decodedAddress - 0x19, *value);
|
||||
break;
|
||||
|
||||
case 0x1c:
|
||||
@ -781,7 +781,7 @@ void Machine::update_audio()
|
||||
// logged_time = time_now;
|
||||
// }
|
||||
|
||||
_speaker.run_for_cycles(audio_cycles);
|
||||
_speaker->run_for_cycles(audio_cycles);
|
||||
_cycles_since_speaker_update %= 114;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,8 @@ class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine {
|
||||
// to satisfy CRTMachine::Machine
|
||||
virtual void setup_output(float aspect_ratio);
|
||||
virtual void close_output();
|
||||
virtual Outputs::CRT::CRT *get_crt() { return _crt; }
|
||||
virtual Outputs::Speaker *get_speaker() { return &_speaker; }
|
||||
virtual std::shared_ptr<Outputs::CRT::CRT> get_crt() { return _crt; }
|
||||
virtual std::shared_ptr<Outputs::Speaker> get_speaker() { return _speaker; }
|
||||
virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles); }
|
||||
virtual double get_clock_rate();
|
||||
// TODO: different rate for PAL
|
||||
@ -197,8 +197,8 @@ class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine {
|
||||
void update_timers(int mask);
|
||||
|
||||
// outputs
|
||||
Outputs::CRT::CRT *_crt;
|
||||
Speaker _speaker;
|
||||
std::shared_ptr<Outputs::CRT::CRT> _crt;
|
||||
std::shared_ptr<Speaker> _speaker;
|
||||
|
||||
// current mode
|
||||
bool _is_pal_region;
|
||||
|
@ -24,8 +24,8 @@ class Machine {
|
||||
virtual void setup_output(float aspect_ratio) = 0;
|
||||
virtual void close_output() = 0;
|
||||
|
||||
virtual Outputs::CRT::CRT *get_crt() = 0;
|
||||
virtual Outputs::Speaker *get_speaker() = 0;
|
||||
virtual std::shared_ptr<Outputs::CRT::CRT> get_crt() = 0;
|
||||
virtual std::shared_ptr<Outputs::Speaker> get_speaker() = 0;
|
||||
|
||||
virtual void run_for_cycles(int number_of_cycles) = 0;
|
||||
|
||||
|
@ -59,6 +59,7 @@ Machine::Machine() :
|
||||
|
||||
void Machine::setup_output(float aspect_ratio)
|
||||
{
|
||||
_speaker.reset(new Speaker);
|
||||
_crt.reset(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1));
|
||||
_crt->set_rgb_sampling_function(
|
||||
"vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)"
|
||||
@ -74,7 +75,7 @@ void Machine::setup_output(float aspect_ratio)
|
||||
// The maximum output frequency is 62500Hz and all other permitted output frequencies are integral divisions of that;
|
||||
// however setting the speaker on or off can happen on any 2Mhz cycle, and probably (?) takes effect immediately. So
|
||||
// run the speaker at a 2000000Hz input rate, at least for the time being.
|
||||
_speaker.set_input_rate(2000000 / clock_rate_audio_divider);
|
||||
_speaker->set_input_rate(2000000 / clock_rate_audio_divider);
|
||||
}
|
||||
|
||||
void Machine::close_output()
|
||||
@ -201,7 +202,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
if(!isReadOperation(operation))
|
||||
{
|
||||
update_audio();
|
||||
_speaker.set_divider(*value);
|
||||
_speaker->set_divider(*value);
|
||||
_tape.set_counter(*value);
|
||||
}
|
||||
break;
|
||||
@ -227,10 +228,10 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
|
||||
// update speaker mode
|
||||
bool new_speaker_is_enabled = (*value & 6) == 2;
|
||||
if(new_speaker_is_enabled != _speaker.get_is_enabled())
|
||||
if(new_speaker_is_enabled != _speaker->get_is_enabled())
|
||||
{
|
||||
update_audio();
|
||||
_speaker.set_is_enabled(new_speaker_is_enabled);
|
||||
_speaker->set_is_enabled(new_speaker_is_enabled);
|
||||
_tape.set_is_enabled(!new_speaker_is_enabled);
|
||||
}
|
||||
|
||||
@ -508,7 +509,7 @@ inline void Machine::update_audio()
|
||||
{
|
||||
unsigned int difference = _frameCycles - _audioOutputPosition;
|
||||
_audioOutputPosition = _frameCycles;
|
||||
_speaker.run_for_cycles(difference / clock_rate_audio_divider);
|
||||
_speaker->run_for_cycles(difference / clock_rate_audio_divider);
|
||||
_audioOutputPositionError = difference % clock_rate_audio_divider;
|
||||
}
|
||||
|
||||
|
@ -159,8 +159,8 @@ class Machine:
|
||||
// to satisfy CRTMachine::Machine
|
||||
virtual void setup_output(float aspect_ratio);
|
||||
virtual void close_output();
|
||||
virtual Outputs::CRT::CRT *get_crt() { return _crt.get(); }
|
||||
virtual Outputs::Speaker *get_speaker() { return &_speaker; }
|
||||
virtual std::shared_ptr<Outputs::CRT::CRT> get_crt() { return _crt; }
|
||||
virtual std::shared_ptr<Outputs::Speaker> get_speaker() { return _speaker; }
|
||||
virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles); }
|
||||
virtual double get_clock_rate() { return 2000000; }
|
||||
|
||||
@ -227,8 +227,8 @@ class Machine:
|
||||
bool _fast_load_is_in_data;
|
||||
|
||||
// Outputs
|
||||
std::unique_ptr<Outputs::CRT::CRT> _crt;
|
||||
Speaker _speaker;
|
||||
std::shared_ptr<Outputs::CRT::CRT> _crt;
|
||||
std::shared_ptr<Speaker> _speaker;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ class UserPortVIA: public MOS::MOS6522<UserPortVIA>, public MOS::MOS6522IRQDeleg
|
||||
printf("Tape motor %s\n", value ? "on" : "off");
|
||||
}
|
||||
}
|
||||
|
||||
using MOS6522IRQDelegate::set_interrupt_status;
|
||||
};
|
||||
|
||||
class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDelegate {
|
||||
@ -108,6 +110,8 @@ class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDeleg
|
||||
}
|
||||
}
|
||||
|
||||
using MOS6522IRQDelegate::set_interrupt_status;
|
||||
|
||||
private:
|
||||
uint8_t _columns[8];
|
||||
uint8_t _activation_mask;
|
||||
@ -164,8 +168,8 @@ class Machine:
|
||||
// to satisfy CRTMachine::Machine
|
||||
virtual void setup_output(float aspect_ratio);
|
||||
virtual void close_output() {}
|
||||
virtual Outputs::CRT::CRT *get_crt() { return _mos6560->get_crt(); }
|
||||
virtual Outputs::Speaker *get_speaker() { return _mos6560->get_speaker(); }
|
||||
virtual std::shared_ptr<Outputs::CRT::CRT> get_crt() { return _mos6560->get_crt(); }
|
||||
virtual std::shared_ptr<Outputs::Speaker> get_speaker() { return _mos6560->get_speaker(); }
|
||||
virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles); }
|
||||
virtual double get_clock_rate() { return 1022727; }
|
||||
// TODO: or 1108405 for PAL; see http://www.antimon.org/dl/c64/code/stable.txt
|
||||
|
@ -684,7 +684,7 @@
|
||||
4BB73ECF1B587A6700552FC2 /* Clock Signal.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Clock Signal.entitlements"; sourceTree = "<group>"; };
|
||||
4BBB142F1CD2CECE00BDB55C /* IntermediateShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntermediateShader.cpp; sourceTree = "<group>"; };
|
||||
4BBB14301CD2CECE00BDB55C /* IntermediateShader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = IntermediateShader.hpp; sourceTree = "<group>"; };
|
||||
4BBC34241D2208B100FFC9DF /* CSCommonOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSCommonOptions.h; sourceTree = "<group>"; };
|
||||
4BBC34241D2208B100FFC9DF /* CSFastLoading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSFastLoading.h; sourceTree = "<group>"; };
|
||||
4BBF99081C8FBA6F0075DAFB /* CRTInputBufferBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CRTInputBufferBuilder.cpp; sourceTree = "<group>"; };
|
||||
4BBF99091C8FBA6F0075DAFB /* CRTInputBufferBuilder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CRTInputBufferBuilder.hpp; sourceTree = "<group>"; };
|
||||
4BBF990A1C8FBA6F0075DAFB /* CRTOpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CRTOpenGL.cpp; sourceTree = "<group>"; };
|
||||
@ -806,7 +806,7 @@
|
||||
4B2A53921D117D36003C6002 /* Machine */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4BBC34241D2208B100FFC9DF /* CSCommonOptions.h */,
|
||||
4BBC34241D2208B100FFC9DF /* CSFastLoading.h */,
|
||||
4B2A53931D117D36003C6002 /* CSKeyboardMachine.h */,
|
||||
4B2A53941D117D36003C6002 /* CSMachine+Subclassing.h */,
|
||||
4B2A53951D117D36003C6002 /* CSMachine.h */,
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#import "CSMachine.h"
|
||||
#import "CSKeyboardMachine.h"
|
||||
#import "CSCommonOptions.h"
|
||||
#import "CSFastLoading.h"
|
||||
|
||||
#import "CSAtari2600.h"
|
||||
#import "CSElectron.h"
|
||||
|
@ -184,9 +184,9 @@ class MachineDocument:
|
||||
|
||||
@IBOutlet var fastLoadingButton: NSButton!
|
||||
@IBAction func setFastLoading(sender: NSButton!) {
|
||||
if let commonOptionsMachine = machine as? CSCommonOptions {
|
||||
if let fastLoadingMachine = machine as? CSFastLoading {
|
||||
let useFastLoadingHack = sender.state == NSOnState
|
||||
commonOptionsMachine.useFastLoadingHack = useFastLoadingHack
|
||||
fastLoadingMachine.useFastLoadingHack = useFastLoadingHack
|
||||
NSUserDefaults.standardUserDefaults().setBool(useFastLoadingHack, forKey: fastLoadingUserDefaultsKey)
|
||||
}
|
||||
}
|
||||
@ -197,9 +197,9 @@ class MachineDocument:
|
||||
fastLoadingUserDefaultsKey: true
|
||||
])
|
||||
|
||||
if let commonOptionsMachine = machine as? CSCommonOptions {
|
||||
if let fastLoadingMachine = machine as? CSFastLoading {
|
||||
let useFastLoadingHack = standardUserDefaults.boolForKey(self.fastLoadingUserDefaultsKey)
|
||||
commonOptionsMachine.useFastLoadingHack = useFastLoadingHack
|
||||
fastLoadingMachine.useFastLoadingHack = useFastLoadingHack
|
||||
self.fastLoadingButton.state = useFastLoadingHack ? NSOnState : NSOffState
|
||||
}
|
||||
}
|
||||
|
11
OSBindings/Mac/Clock Signal/Machine/CSFastLoading.h
Normal file
11
OSBindings/Mac/Clock Signal/Machine/CSFastLoading.h
Normal file
@ -0,0 +1,11 @@
|
||||
//
|
||||
// CSFastLoading.h
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 05/06/2016.
|
||||
// Copyright © 2016 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
@protocol CSFastLoading <NSObject>
|
||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||
@end
|
@ -63,7 +63,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
|
||||
- (float)idealSamplingRateFromRange:(NSRange)range {
|
||||
@synchronized(self) {
|
||||
Outputs::Speaker *speaker = self.machine->get_speaker();
|
||||
std::shared_ptr<Outputs::Speaker> speaker = self.machine->get_speaker();
|
||||
if(speaker)
|
||||
{
|
||||
return speaker->get_ideal_clock_rate_in_range((float)range.location, (float)(range.location + range.length));
|
||||
@ -80,7 +80,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
|
||||
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(float)sampleRate bufferSize:(NSUInteger)bufferSize {
|
||||
@synchronized(self) {
|
||||
Outputs::Speaker *speaker = self.machine->get_speaker();
|
||||
std::shared_ptr<Outputs::Speaker> speaker = self.machine->get_speaker();
|
||||
if(speaker)
|
||||
{
|
||||
speaker->set_output_rate(sampleRate, (int)bufferSize);
|
||||
|
@ -8,9 +8,9 @@
|
||||
|
||||
#import "CSMachine.h"
|
||||
#import "CSKeyboardMachine.h"
|
||||
#import "CSCommonOptions.h"
|
||||
#import "CSFastLoading.h"
|
||||
|
||||
@interface CSElectron : CSMachine <CSKeyboardMachine, CSCommonOptions>
|
||||
@interface CSElectron : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||
|
||||
- (void)setOSROM:(nonnull NSData *)rom;
|
||||
- (void)setBASICROM:(nonnull NSData *)rom;
|
||||
|
@ -8,9 +8,9 @@
|
||||
|
||||
#import "CSMachine.h"
|
||||
#import "CSKeyboardMachine.h"
|
||||
#import "CSCommonOptions.h"
|
||||
#import "CSFastLoading.h"
|
||||
|
||||
@interface CSVic20 : CSMachine <CSKeyboardMachine, CSCommonOptions>
|
||||
@interface CSVic20 : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||
|
||||
- (void)setKernelROM:(nonnull NSData *)rom;
|
||||
- (void)setBASICROM:(nonnull NSData *)rom;
|
||||
|
Loading…
x
Reference in New Issue
Block a user