openMSX
AVTFDC.cc
Go to the documentation of this file.
1 #include "AVTFDC.hh"
2 #include "DriveMultiplexer.hh"
3 #include "WD2793.hh"
4 #include "serialize.hh"
5 
6 namespace openmsx {
7 
9  : WD2793BasedFDC(config)
10 {
11 }
12 
13 byte AVTFDC::readIO(word port, EmuTime::param time)
14 {
15  switch (port & 0x07) {
16  case 0:
17  return controller.getStatusReg(time);
18  case 1:
19  return controller.getTrackReg(time);
20  case 2:
21  return controller.getSectorReg(time);
22  case 3:
23  return controller.getDataReg(time);
24  case 4: {
25  byte value = 0x7F;
26  if (controller.getIRQ(time)) value |= 0x80;
27  if (controller.getDTRQ(time)) value &= ~0x40;
28  return value;
29  }
30  default:
31  return 255;
32  }
33 }
34 
35 byte AVTFDC::peekIO(word port, EmuTime::param time) const
36 {
37  switch (port & 0x07) {
38  case 0:
39  return controller.peekStatusReg(time);
40  case 1:
41  return controller.peekTrackReg(time);
42  case 2:
43  return controller.peekSectorReg(time);
44  case 3:
45  return controller.peekDataReg(time);
46  case 4: {
47  byte value = 0x7F;
48  if (controller.peekIRQ(time)) value |= 0x80;
49  if (controller.peekDTRQ(time)) value &= ~0x40;
50  return value;
51  }
52  default:
53  return 255;
54  }
55 }
56 
57 void AVTFDC::writeIO(word port, byte value, EmuTime::param time)
58 {
59  switch (port & 0x07) {
60  case 0:
61  controller.setCommandReg(value, time);
62  break;
63  case 1:
64  controller.setTrackReg(value, time);
65  break;
66  case 2:
67  controller.setSectorReg(value, time);
68  break;
69  case 3:
70  controller.setDataReg(value, time);
71  break;
72  case 4: /* nothing only read... */
73  break;
74  case 5:
75  // From mohai
76  // bit 0: drive select A (and motor on, as this is a WD1770,
77  // we use this as workaround)
78  // bit 1: drive select B (and motor on, as this is a WD1770,
79  // we use this as workaround)
80  // bit 2: side select
81  // bit 3: density: 1=single 0=double (not supported by openMSX)
82  //
83  // Set correct drive
84  auto drive = [&] {
85  switch (value & 0x03) {
86  case 1:
88  case 2:
90  default:
91  // No drive selected or two drives at same time
92  // The motor is enabled for all drives at the same time, so
93  // in a real machine you must take care to do not select more
94  // than one drive at the same time (you could get data
95  // collision).
97  }
98  }();
99  multiplexer.selectDrive(drive, time);
100  multiplexer.setSide((value & 0x04) != 0);
102  break;
103  }
104 }
105 
106 
107 template<typename Archive>
108 void AVTFDC::serialize(Archive& ar, unsigned /*version*/)
109 {
110  ar.template serializeBase<WD2793BasedFDC>(*this);
111 }
114 
115 } // namespace openmsx
openmsx::WD2793BasedFDC::multiplexer
DriveMultiplexer multiplexer
Definition: WD2793BasedFDC.hh:25
openmsx::AVTFDC::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: AVTFDC.cc:35
serialize.hh
openmsx::AVTFDC::writeIO
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition: AVTFDC.cc:57
openmsx::AVTFDC
Definition: AVTFDC.hh:9
openmsx::WD2793BasedFDC::controller
WD2793 controller
Definition: WD2793BasedFDC.hh:26
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::WD2793::getDataReg
byte getDataReg(EmuTime::param time)
Definition: WD2793.cc:260
openmsx::WD2793::peekStatusReg
byte peekStatusReg(EmuTime::param time) const
Definition: WD2793.cc:210
openmsx::WD2793::peekIRQ
bool peekIRQ(EmuTime::param time) const
Definition: WD2793.cc:110
openmsx::WD2793::getStatusReg
byte getStatusReg(EmuTime::param time)
Definition: WD2793.cc:170
openmsx::AVTFDC::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: AVTFDC.cc:13
openmsx::WD2793BasedFDC
Definition: WD2793BasedFDC.hh:12
openmsx::DriveMultiplexer::setMotor
void setMotor(bool status, EmuTime::param time) override
Set motor on/off.
Definition: DriveMultiplexer.cc:69
openmsx::DriveMultiplexer::NO_DRIVE
@ NO_DRIVE
Definition: DriveMultiplexer.hh:20
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
AVTFDC.hh
openmsx::DriveMultiplexer::setSide
void setSide(bool side) override
Side select.
Definition: DriveMultiplexer.cc:48
openmsx::DriveMultiplexer::DRIVE_B
@ DRIVE_B
Definition: DriveMultiplexer.hh:17
openmsx::WD2793::getDTRQ
bool getDTRQ(EmuTime::param time) const
Definition: WD2793.cc:90
openmsx::WD2793::getIRQ
bool getIRQ(EmuTime::param time) const
Definition: WD2793.cc:105
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:982
openmsx::WD2793::getSectorReg
byte getSectorReg(EmuTime::param time) const
Definition: WD2793.cc:236
openmsx::DriveMultiplexer::DRIVE_A
@ DRIVE_A
Definition: DriveMultiplexer.hh:16
openmsx::WD2793::setDataReg
void setDataReg(byte value, EmuTime::param time)
Definition: WD2793.cc:246
DriveMultiplexer.hh
WD2793.hh
openmsx::WD2793::getTrackReg
byte getTrackReg(EmuTime::param time) const
Definition: WD2793.cc:221
openmsx::AVTFDC::serialize
void serialize(Archive &ar, unsigned version)
Definition: AVTFDC.cc:108
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::AVTFDC::AVTFDC
AVTFDC(const DeviceConfig &config)
Definition: AVTFDC.cc:8
openmsx::WD2793::peekSectorReg
byte peekSectorReg(EmuTime::param time) const
Definition: WD2793.cc:241
openmsx::DriveMultiplexer::selectDrive
void selectDrive(DriveNum num, EmuTime::param time)
Definition: DriveMultiplexer.cc:18
openmsx::WD2793::setCommandReg
void setCommandReg(byte value, EmuTime::param time)
Definition: WD2793.cc:122
openmsx::WD2793::peekDataReg
byte peekDataReg(EmuTime::param time) const
Definition: WD2793.cc:325
openmsx::WD2793::peekDTRQ
bool peekDTRQ(EmuTime::param time) const
Definition: WD2793.cc:95
openmsx::WD2793::peekTrackReg
byte peekTrackReg(EmuTime::param time) const
Definition: WD2793.cc:226
openmsx::WD2793::setSectorReg
void setSectorReg(byte value, EmuTime::param time)
Definition: WD2793.cc:231
openmsx::WD2793::setTrackReg
void setTrackReg(byte value, EmuTime::param time)
Definition: WD2793.cc:216
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5