2018-01-08 00:12:52 +00:00
|
|
|
//
|
|
|
|
// DiskROM.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 07/01/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-01-08 00:12:52 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "DiskROM.hpp"
|
|
|
|
|
|
|
|
using namespace MSX;
|
|
|
|
|
|
|
|
DiskROM::DiskROM(const std::vector<uint8_t> &rom) :
|
|
|
|
WD1770(P1793),
|
|
|
|
rom_(rom) {
|
2020-02-12 02:59:13 +00:00
|
|
|
emplace_drives(2, 8000000, 300, 2);
|
2018-01-08 00:12:52 +00:00
|
|
|
set_is_double_density(true);
|
|
|
|
}
|
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
void DiskROM::write(uint16_t address, uint8_t value, bool) {
|
2018-01-08 00:12:52 +00:00
|
|
|
switch(address) {
|
|
|
|
case 0x7ff8: case 0x7ff9: case 0x7ffa: case 0x7ffb:
|
2020-01-05 18:40:02 +00:00
|
|
|
WD::WD1770::write(address, value);
|
2018-01-08 00:12:52 +00:00
|
|
|
break;
|
2020-02-12 02:59:13 +00:00
|
|
|
case 0x7ffc: {
|
|
|
|
const int selected_head = value & 1;
|
2020-06-17 03:15:20 +00:00
|
|
|
for_all_drives([selected_head] (Storage::Disk::Drive &drive, size_t) {
|
2020-02-12 02:59:13 +00:00
|
|
|
drive.set_head(selected_head);
|
|
|
|
});
|
|
|
|
} break;
|
2018-01-08 01:02:40 +00:00
|
|
|
case 0x7ffd: {
|
2020-02-12 02:59:13 +00:00
|
|
|
set_drive(1 << (value & 1));
|
2018-01-08 01:02:40 +00:00
|
|
|
|
2020-02-12 02:59:13 +00:00
|
|
|
const bool drive_motor = value & 0x80;
|
2020-06-17 03:15:20 +00:00
|
|
|
for_all_drives([drive_motor] (Storage::Disk::Drive &drive, size_t) {
|
2020-02-12 02:59:13 +00:00
|
|
|
drive.set_motor_on(drive_motor);
|
|
|
|
});
|
2018-01-08 01:02:40 +00:00
|
|
|
} break;
|
2018-01-08 00:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t DiskROM::read(uint16_t address) {
|
|
|
|
if(address >= 0x7ff8 && address < 0x7ffc) {
|
2020-01-05 18:40:02 +00:00
|
|
|
return WD::WD1770::read(address);
|
2018-01-08 00:12:52 +00:00
|
|
|
}
|
2018-01-08 01:28:34 +00:00
|
|
|
if(address == 0x7fff) {
|
|
|
|
return (get_data_request_line() ? 0x00 : 0x80) | (get_interrupt_request_line() ? 0x00 : 0x40);
|
|
|
|
}
|
2018-01-08 00:12:52 +00:00
|
|
|
return rom_[address & 0x3fff];
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiskROM::run_for(HalfCycles half_cycles) {
|
|
|
|
// Input clock is going to be 7159090/2 Mhz, but the drive controller
|
|
|
|
// needs an 8Mhz clock, so scale up. 8000000/7159090 simplifies to
|
|
|
|
// 800000/715909.
|
2019-10-30 02:36:29 +00:00
|
|
|
controller_cycles_ += 800000 * half_cycles.as_integral();
|
2020-05-10 03:00:39 +00:00
|
|
|
WD::WD1770::run_for(Cycles(int(controller_cycles_ / 715909)));
|
2018-01-08 00:12:52 +00:00
|
|
|
controller_cycles_ %= 715909;
|
|
|
|
}
|
|
|
|
|
2018-05-12 21:32:53 +00:00
|
|
|
void DiskROM::set_disk(std::shared_ptr<Storage::Disk::Disk> disk, size_t drive) {
|
2020-02-12 02:59:13 +00:00
|
|
|
get_drive(drive).set_disk(disk);
|
2018-01-08 00:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiskROM::set_head_load_request(bool head_load) {
|
|
|
|
// Magic!
|
|
|
|
set_head_loaded(head_load);
|
|
|
|
}
|
2018-05-12 21:32:53 +00:00
|
|
|
|
|
|
|
void DiskROM::set_activity_observer(Activity::Observer *observer) {
|
2020-02-12 02:59:13 +00:00
|
|
|
for_all_drives([observer] (Storage::Disk::Drive &drive, size_t index) {
|
|
|
|
drive.set_activity_observer(observer, "Drive " + std::to_string(index), true);
|
|
|
|
});
|
2018-05-12 21:32:53 +00:00
|
|
|
}
|