2016-11-22 00:12:53 +00:00
|
|
|
//
|
|
|
|
// Microdisc.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 22/11/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Microdisc.hpp"
|
|
|
|
|
|
|
|
using namespace Oric;
|
|
|
|
|
2016-12-02 02:13:16 +00:00
|
|
|
namespace {
|
2016-12-02 23:36:47 +00:00
|
|
|
// The number below, in cycles against an 8Mhz clock, was arrived at fairly unscientifically,
|
|
|
|
// by comparing the amount of time this emulator took to show a directory versus a video of
|
|
|
|
// a real Oric. It therefore assumes all other timing measurements were correct on the day
|
|
|
|
// of the test. More work to do, I think.
|
2016-12-02 02:13:16 +00:00
|
|
|
const int head_load_request_counter_target = 7653333;
|
|
|
|
}
|
|
|
|
|
2016-11-22 14:09:52 +00:00
|
|
|
Microdisc::Microdisc() :
|
|
|
|
irq_enable_(false),
|
|
|
|
delegate_(nullptr),
|
2016-11-26 15:29:30 +00:00
|
|
|
paging_flags_(BASICDisable),
|
2016-12-02 02:13:16 +00:00
|
|
|
head_load_request_counter_(-1),
|
2016-12-28 23:49:32 +00:00
|
|
|
WD1770(P1793),
|
|
|
|
last_control_(0)
|
|
|
|
{
|
|
|
|
set_control_register(last_control_, 0xff);
|
|
|
|
}
|
2016-11-22 00:12:53 +00:00
|
|
|
|
|
|
|
void Microdisc::set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int drive)
|
|
|
|
{
|
|
|
|
if(!drives_[drive])
|
|
|
|
{
|
|
|
|
drives_[drive].reset(new Storage::Disk::Drive);
|
|
|
|
if(drive == selected_drive_) set_drive(drives_[drive]);
|
|
|
|
}
|
|
|
|
drives_[drive]->set_disk(disk);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Microdisc::set_control_register(uint8_t control)
|
|
|
|
{
|
2016-12-28 23:29:37 +00:00
|
|
|
uint8_t changes = last_control_ ^ control;
|
|
|
|
last_control_ = control;
|
2016-12-28 23:49:32 +00:00
|
|
|
set_control_register(control, changes);
|
|
|
|
}
|
2016-12-02 23:36:47 +00:00
|
|
|
|
2016-12-28 23:49:32 +00:00
|
|
|
void Microdisc::set_control_register(uint8_t control, uint8_t changes)
|
|
|
|
{
|
2016-11-22 14:09:52 +00:00
|
|
|
// b2: data separator clock rate select (1 = double) [TODO]
|
2016-11-22 00:12:53 +00:00
|
|
|
|
|
|
|
// b65: drive select
|
2016-12-28 23:29:37 +00:00
|
|
|
if((changes >> 5)&3)
|
|
|
|
{
|
|
|
|
selected_drive_ = (control >> 5)&3;
|
|
|
|
set_drive(drives_[selected_drive_]);
|
|
|
|
}
|
2016-11-22 00:12:53 +00:00
|
|
|
|
|
|
|
// b4: side select
|
2016-12-28 23:29:37 +00:00
|
|
|
if(changes & 0x10)
|
2016-11-22 00:12:53 +00:00
|
|
|
{
|
2016-12-28 23:29:37 +00:00
|
|
|
unsigned int head = (control & 0x10) ? 1 : 0;
|
|
|
|
for(int c = 0; c < 4; c++)
|
|
|
|
{
|
|
|
|
if(drives_[c]) drives_[c]->set_head(head);
|
|
|
|
}
|
2016-11-22 00:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// b3: double density select (0 = double)
|
2016-12-28 23:29:37 +00:00
|
|
|
if(changes & 0x08)
|
|
|
|
{
|
|
|
|
set_is_double_density(!(control & 0x08));
|
|
|
|
}
|
2016-11-22 00:12:53 +00:00
|
|
|
|
|
|
|
// b0: IRQ enable
|
2016-12-28 23:29:37 +00:00
|
|
|
if(changes & 0x01)
|
2016-11-26 01:35:44 +00:00
|
|
|
{
|
2016-12-28 23:29:37 +00:00
|
|
|
bool had_irq = get_interrupt_request_line();
|
|
|
|
irq_enable_ = !!(control & 0x01);
|
|
|
|
bool has_irq = get_interrupt_request_line();
|
|
|
|
if(has_irq != had_irq && delegate_)
|
|
|
|
{
|
|
|
|
delegate_->wd1770_did_change_output(this);
|
|
|
|
}
|
2016-11-26 01:35:44 +00:00
|
|
|
}
|
2016-11-22 14:09:52 +00:00
|
|
|
|
|
|
|
// b7: EPROM select (0 = select)
|
|
|
|
// b1: ROM disable (0 = disable)
|
2016-12-28 23:29:37 +00:00
|
|
|
if(changes & 0x82)
|
2016-11-22 14:09:52 +00:00
|
|
|
{
|
2016-12-28 23:29:37 +00:00
|
|
|
paging_flags_ = ((control & 0x02) ? 0 : BASICDisable) | ((control & 0x80) ? MicrodscDisable : 0);
|
2016-11-22 14:09:52 +00:00
|
|
|
if(delegate_) delegate_->microdisc_did_change_paging_flags(this);
|
|
|
|
}
|
2016-11-22 00:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Microdisc::get_interrupt_request_line()
|
|
|
|
{
|
|
|
|
return irq_enable_ && WD1770::get_interrupt_request_line();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Microdisc::get_interrupt_request_register()
|
|
|
|
{
|
2016-12-07 02:16:29 +00:00
|
|
|
return 0x7f | (WD1770::get_interrupt_request_line() ? 0x00 : 0x80);
|
2016-11-22 00:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Microdisc::get_data_request_register()
|
|
|
|
{
|
2016-11-25 13:24:59 +00:00
|
|
|
return 0x7f | (get_data_request_line() ? 0x00 : 0x80);
|
2016-11-22 00:12:53 +00:00
|
|
|
}
|
2016-12-02 01:12:22 +00:00
|
|
|
|
|
|
|
void Microdisc::set_head_load_request(bool head_load)
|
|
|
|
{
|
|
|
|
set_motor_on(head_load);
|
2016-12-02 02:13:16 +00:00
|
|
|
if(head_load)
|
|
|
|
{
|
|
|
|
head_load_request_counter_ = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
head_load_request_counter_ = head_load_request_counter_target;
|
|
|
|
set_head_loaded(head_load);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Microdisc::run_for_cycles(unsigned int number_of_cycles)
|
|
|
|
{
|
|
|
|
if(head_load_request_counter_ < head_load_request_counter_target)
|
|
|
|
{
|
|
|
|
head_load_request_counter_ += number_of_cycles;
|
|
|
|
if(head_load_request_counter_ >= head_load_request_counter_target) set_head_loaded(true);
|
|
|
|
}
|
|
|
|
WD::WD1770::run_for_cycles(number_of_cycles);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Microdisc::get_drive_is_ready()
|
|
|
|
{
|
|
|
|
return true;
|
2016-12-02 01:12:22 +00:00
|
|
|
}
|