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  byte value;
16  switch (port & 0x07) {
17  case 0:
18  value = controller.getStatusReg(time);
19  break;
20  case 1:
21  value = controller.getTrackReg(time);
22  break;
23  case 2:
24  value = controller.getSectorReg(time);
25  break;
26  case 3:
27  value = controller.getDataReg(time);
28  break;
29  case 4:
30  value = 0x7F;
31  if (controller.getIRQ(time)) value |= 0x80;
32  if (controller.getDTRQ(time)) value &= ~0x40;
33  break;
34  default:
35  value = 255;
36  break;
37  }
38  return value;
39 }
40 
41 byte AVTFDC::peekIO(word port, EmuTime::param time) const
42 {
43  byte value;
44  switch (port & 0x07) {
45  case 0:
46  value = controller.peekStatusReg(time);
47  break;
48  case 1:
49  value = controller.peekTrackReg(time);
50  break;
51  case 2:
52  value = controller.peekSectorReg(time);
53  break;
54  case 3:
55  value = controller.peekDataReg(time);
56  break;
57  case 4:
58  value = 0x7F;
59  if (controller.peekIRQ(time)) value |= 0x80;
60  if (controller.peekDTRQ(time)) value &= ~0x40;
61  break;
62  default:
63  value = 255;
64  break;
65  }
66  return value;
67 }
68 
69 void AVTFDC::writeIO(word port, byte value, EmuTime::param time)
70 {
71  switch (port & 0x07) {
72  case 0:
73  controller.setCommandReg(value, time);
74  break;
75  case 1:
76  controller.setTrackReg(value, time);
77  break;
78  case 2:
79  controller.setSectorReg(value, time);
80  break;
81  case 3:
82  controller.setDataReg(value, time);
83  break;
84  case 4: /* nothing only read... */
85  break;
86  case 5:
87  // From mohai
88  // bit 0: drive select A (and motor on, as this is a WD1770,
89  // we use this as workaround)
90  // bit 1: drive select B (and motor on, as this is a WD1770,
91  // we use this as workaround)
92  // bit 2: side select
93  // bit 3: density: 1=single 0=double (not supported by openMSX)
94  //
95  // Set correct drive
97  switch (value & 0x03) {
98  case 1:
100  break;
101  case 2:
103  break;
104  default:
105  // No drive selected or two drives at same time
106  // The motor is enabled for all drives at the same time, so
107  // in a real machine you must take care to do not select more
108  // than one drive at the same time (you could get data
109  // collision).
111  }
112  multiplexer.selectDrive(drive, time);
113  multiplexer.setSide((value & 0x04) != 0);
115  break;
116  }
117 }
118 
119 
120 template<typename Archive>
121 void AVTFDC::serialize(Archive& ar, unsigned /*version*/)
122 {
123  ar.template serializeBase<WD2793BasedFDC>(*this);
124 }
126 REGISTER_MSXDEVICE(AVTFDC, "AVTFDC");
127 
128 } // namespace openmsx
byte peekDataReg(EmuTime::param time) const
Definition: WD2793.cc:320
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
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:69
void setCommandReg(byte value, EmuTime::param time)
Definition: WD2793.cc:122
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
void serialize(Archive &ar, unsigned version)
Definition: AVTFDC.cc:121
byte getStatusReg(EmuTime::param time)
Definition: WD2793.cc:166
byte peekSectorReg(EmuTime::param time) const
Definition: WD2793.cc:237
byte getSectorReg(EmuTime::param time)
Definition: WD2793.cc:232
bool getDTRQ(EmuTime::param time)
Definition: WD2793.cc:90
DriveMultiplexer multiplexer
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: AVTFDC.cc:41
void setMotor(bool status, EmuTime::param time) override
Set motor on/off.
void setSectorReg(byte value, EmuTime::param time)
Definition: WD2793.cc:227
AVTFDC(const DeviceConfig &config)
Definition: AVTFDC.cc:8
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
byte getDataReg(EmuTime::param time)
Definition: WD2793.cc:256
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:840
byte peekStatusReg(EmuTime::param time) const
Definition: WD2793.cc:206
void setSide(bool side) override
Side select.
bool peekIRQ(EmuTime::param time) const
Definition: WD2793.cc:110
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
byte peekTrackReg(EmuTime::param time) const
Definition: WD2793.cc:222
void setTrackReg(byte value, EmuTime::param time)
Definition: WD2793.cc:212
bool getIRQ(EmuTime::param time)
Definition: WD2793.cc:105
void selectDrive(DriveNum num, EmuTime::param time)
byte getTrackReg(EmuTime::param time)
Definition: WD2793.cc:217
bool peekDTRQ(EmuTime::param time) const
Definition: WD2793.cc:95
void setDataReg(byte value, EmuTime::param time)
Definition: WD2793.cc:242