2018-04-21 21:33:42 +00:00
|
|
|
//
|
|
|
|
// DiskII.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 20/04/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-04-21 21:33:42 +00:00
|
|
|
//
|
|
|
|
|
2024-01-17 04:34:46 +00:00
|
|
|
#pragma once
|
2018-04-21 21:33:42 +00:00
|
|
|
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2018-05-28 03:17:06 +00:00
|
|
|
#include "../../ClockReceiver/ClockingHintSource.hpp"
|
2018-04-24 15:29:05 +00:00
|
|
|
|
2018-04-25 02:44:45 +00:00
|
|
|
#include "../../Storage/Disk/Disk.hpp"
|
|
|
|
#include "../../Storage/Disk/Drive.hpp"
|
|
|
|
|
2018-05-11 02:17:13 +00:00
|
|
|
#include "../../Activity/Observer.hpp"
|
|
|
|
|
2018-05-10 02:03:59 +00:00
|
|
|
#include <array>
|
2018-04-21 21:33:42 +00:00
|
|
|
#include <cstdint>
|
2018-04-24 15:29:05 +00:00
|
|
|
#include <vector>
|
2018-04-21 21:33:42 +00:00
|
|
|
|
|
|
|
namespace Apple {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides an emulation of the Apple Disk II.
|
|
|
|
*/
|
2020-01-24 03:57:51 +00:00
|
|
|
class DiskII :
|
2018-04-29 21:51:10 +00:00
|
|
|
public Storage::Disk::Drive::EventDelegate,
|
2018-05-28 03:17:06 +00:00
|
|
|
public ClockingHint::Source,
|
|
|
|
public ClockingHint::Observer {
|
2018-04-21 21:33:42 +00:00
|
|
|
public:
|
2018-05-28 21:19:29 +00:00
|
|
|
DiskII(int clock_rate);
|
2018-04-25 02:44:45 +00:00
|
|
|
|
2018-05-18 01:39:11 +00:00
|
|
|
/// Sets the current external value of the data bus.
|
|
|
|
void set_data_input(uint8_t input);
|
2018-05-09 02:05:43 +00:00
|
|
|
|
2018-05-18 01:39:11 +00:00
|
|
|
/*!
|
|
|
|
Submits an access to address @c address.
|
|
|
|
|
|
|
|
@returns The 8-bit value loaded to the data bus by the DiskII if any;
|
|
|
|
@c DidNotLoad otherwise.
|
|
|
|
*/
|
|
|
|
int read_address(int address);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
The value returned by @c read_address if accessing that address
|
|
|
|
didn't cause the disk II to place anything onto the bus.
|
|
|
|
*/
|
2019-12-22 05:22:17 +00:00
|
|
|
static constexpr int DidNotLoad = -1;
|
2018-05-18 01:39:11 +00:00
|
|
|
|
|
|
|
/// Advances the controller by @c cycles.
|
2018-05-09 02:05:43 +00:00
|
|
|
void run_for(const Cycles cycles);
|
2018-05-18 01:39:11 +00:00
|
|
|
|
|
|
|
/*!
|
2018-11-24 03:32:32 +00:00
|
|
|
Supplies the image of the state machine (i.e. P6) ROM,
|
2018-05-18 01:39:11 +00:00
|
|
|
which dictates how the Disk II will respond to input.
|
|
|
|
|
|
|
|
To reduce processing costs, some assumptions are made by
|
|
|
|
the implementation as to the content of this ROM.
|
|
|
|
Including:
|
|
|
|
|
2018-05-20 03:15:28 +00:00
|
|
|
* If Q6 is set and Q7 is reset, the controller is testing
|
2018-05-18 01:39:11 +00:00
|
|
|
for write protect. If and when the shift register has
|
|
|
|
become full with the state of the write protect value,
|
|
|
|
no further processing is required.
|
2018-05-20 03:15:28 +00:00
|
|
|
|
|
|
|
* If both Q6 and Q7 are reset, the drive motor is disabled,
|
|
|
|
and the shift register is all zeroes, no further processing
|
|
|
|
is required.
|
2018-05-18 01:39:11 +00:00
|
|
|
*/
|
2018-05-09 02:05:43 +00:00
|
|
|
void set_state_machine(const std::vector<uint8_t> &);
|
|
|
|
|
2018-05-18 01:39:11 +00:00
|
|
|
/// Inserts @c disk into the drive @c drive.
|
2018-05-09 02:05:43 +00:00
|
|
|
void set_disk(const std::shared_ptr<Storage::Disk::Disk> &disk, int drive);
|
2018-05-18 01:39:11 +00:00
|
|
|
|
|
|
|
// As per Sleeper.
|
2020-05-10 01:22:51 +00:00
|
|
|
ClockingHint::Preference preferred_clocking() const final;
|
2018-05-09 02:05:43 +00:00
|
|
|
|
2018-05-18 01:39:11 +00:00
|
|
|
// The Disk II functions as a potential target for @c Activity::Sources.
|
2018-05-11 02:17:13 +00:00
|
|
|
void set_activity_observer(Activity::Observer *observer);
|
|
|
|
|
2018-06-09 16:51:53 +00:00
|
|
|
// Returns the Storage::Disk::Drive in use for drive @c index.
|
|
|
|
// *NOT FOR HARDWARE EMULATION USAGE*.
|
|
|
|
Storage::Disk::Drive &get_drive(int index);
|
|
|
|
|
2018-05-09 02:05:43 +00:00
|
|
|
private:
|
2018-04-21 21:33:42 +00:00
|
|
|
enum class Control {
|
|
|
|
P0, P1, P2, P3,
|
|
|
|
Motor,
|
|
|
|
};
|
|
|
|
enum class Mode {
|
|
|
|
Read, Write
|
|
|
|
};
|
|
|
|
void set_control(Control control, bool on);
|
|
|
|
void set_mode(Mode mode);
|
|
|
|
void select_drive(int drive);
|
|
|
|
|
2018-05-09 02:05:43 +00:00
|
|
|
uint8_t trigger_address(int address, uint8_t value);
|
2020-01-24 03:57:51 +00:00
|
|
|
void process_event(const Storage::Disk::Drive::Event &event) final;
|
|
|
|
void set_component_prefers_clocking(ClockingHint::Source *component, ClockingHint::Preference preference) final;
|
2018-04-25 02:44:45 +00:00
|
|
|
|
2019-10-30 02:36:29 +00:00
|
|
|
const Cycles::IntType clock_rate_ = 0;
|
2018-05-28 21:19:29 +00:00
|
|
|
|
2018-04-24 05:29:36 +00:00
|
|
|
uint8_t state_ = 0;
|
2018-04-24 15:29:05 +00:00
|
|
|
uint8_t inputs_ = 0;
|
2018-04-24 05:29:36 +00:00
|
|
|
uint8_t shift_register_ = 0;
|
|
|
|
|
2018-04-25 02:44:45 +00:00
|
|
|
int stepper_mask_ = 0;
|
|
|
|
int stepper_position_ = 0;
|
2019-10-30 02:36:29 +00:00
|
|
|
Cycles::IntType motor_off_time_ = -1;
|
2018-04-25 02:44:45 +00:00
|
|
|
|
2018-04-24 05:29:36 +00:00
|
|
|
bool is_write_protected();
|
2018-05-10 02:03:59 +00:00
|
|
|
std::array<uint8_t, 256> state_machine_;
|
2018-04-25 02:44:45 +00:00
|
|
|
Storage::Disk::Drive drives_[2];
|
2018-04-29 21:51:10 +00:00
|
|
|
bool drive_is_sleeping_[2];
|
2018-04-25 02:44:45 +00:00
|
|
|
int active_drive_ = 0;
|
2018-05-17 01:44:09 +00:00
|
|
|
bool motor_is_enabled_ = false;
|
2018-04-29 21:51:10 +00:00
|
|
|
|
2018-05-28 21:19:29 +00:00
|
|
|
void decide_clocking_preference();
|
|
|
|
ClockingHint::Preference clocking_preference_ = ClockingHint::Preference::RealTime;
|
2018-05-18 01:39:11 +00:00
|
|
|
|
|
|
|
uint8_t data_input_ = 0;
|
2018-08-01 03:01:11 +00:00
|
|
|
int flux_duration_ = 0;
|
2018-04-21 21:33:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|