2019-05-06 01:55:34 +00:00
|
|
|
//
|
|
|
|
// IWM.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 05/05/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef IWM_hpp
|
|
|
|
#define IWM_hpp
|
|
|
|
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2019-06-01 22:43:47 +00:00
|
|
|
#include "../../Storage/Disk/Drive.hpp"
|
2019-05-06 01:55:34 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace Apple {
|
|
|
|
|
2019-06-05 02:13:00 +00:00
|
|
|
class IWM:
|
|
|
|
public Storage::Disk::Drive::EventDelegate {
|
2019-05-06 01:55:34 +00:00
|
|
|
public:
|
|
|
|
IWM(int clock_rate);
|
|
|
|
|
|
|
|
/// Sets the current external value of the data bus.
|
|
|
|
void write(int address, uint8_t value);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Submits an access to address @c address.
|
|
|
|
|
|
|
|
@returns The 8-bit value loaded to the data bus by the IWM.
|
|
|
|
*/
|
|
|
|
uint8_t read(int address);
|
|
|
|
|
2019-05-30 16:08:00 +00:00
|
|
|
/*!
|
|
|
|
Sets the current input of the IWM's SEL line.
|
|
|
|
*/
|
|
|
|
void set_select(bool enabled);
|
|
|
|
|
2019-05-06 01:55:34 +00:00
|
|
|
/// Advances the controller by @c cycles.
|
|
|
|
void run_for(const Cycles cycles);
|
|
|
|
|
2019-06-05 01:41:09 +00:00
|
|
|
/// Connects a drive to the IWM.
|
|
|
|
void set_drive(int slot, Storage::Disk::Drive *drive);
|
|
|
|
|
2019-05-06 01:55:34 +00:00
|
|
|
private:
|
2019-06-05 02:13:00 +00:00
|
|
|
// Storage::Disk::Drive::EventDelegate.
|
2019-07-02 19:43:03 +00:00
|
|
|
void process_event(const Storage::Disk::Drive::Event &event) override;
|
2019-06-05 02:13:00 +00:00
|
|
|
|
2019-06-01 22:43:47 +00:00
|
|
|
const int clock_rate_;
|
|
|
|
|
2019-06-05 02:13:00 +00:00
|
|
|
uint8_t data_register_ = 0;
|
2019-05-06 01:55:34 +00:00
|
|
|
uint8_t mode_ = 0;
|
|
|
|
bool read_write_ready_ = true;
|
|
|
|
bool write_overran_ = false;
|
|
|
|
|
2019-05-31 02:17:49 +00:00
|
|
|
int state_ = 0;
|
2019-05-06 01:55:34 +00:00
|
|
|
|
2019-06-01 22:43:47 +00:00
|
|
|
int active_drive_ = 0;
|
2019-06-05 01:41:09 +00:00
|
|
|
Storage::Disk::Drive *drives_[2] = {nullptr, nullptr};
|
|
|
|
bool drive_motor_on_ = false;
|
2019-06-01 22:43:47 +00:00
|
|
|
|
|
|
|
Cycles cycles_until_motor_off_;
|
|
|
|
|
2019-05-06 01:55:34 +00:00
|
|
|
void access(int address);
|
2019-06-01 23:08:29 +00:00
|
|
|
|
2019-06-05 02:13:00 +00:00
|
|
|
uint8_t shift_register_ = 0;
|
|
|
|
void propose_shift(uint8_t bit);
|
|
|
|
Cycles cycles_since_shift_;
|
2019-06-01 23:08:29 +00:00
|
|
|
Cycles bit_length_;
|
2019-06-15 20:08:54 +00:00
|
|
|
|
|
|
|
int step_direction_ = 0; // TODO: this should live on the drive.
|
2019-05-06 01:55:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* IWM_hpp */
|