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
6namespace openmsx {
7
9 : WD2793BasedFDC(config)
10{
11}
12
13byte 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
35byte 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
57void 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
107template<typename Archive>
108void AVTFDC::serialize(Archive& ar, unsigned /*version*/)
109{
110 ar.template serializeBase<WD2793BasedFDC>(*this);
111}
114
115} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:354
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
AVTFDC(const DeviceConfig &config)
Definition AVTFDC.cc:8
void serialize(Archive &ar, unsigned version)
Definition AVTFDC.cc:108
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 peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition AVTFDC.cc:35
void setMotor(bool status, EmuTime::param time) override
Set motor on/off.
void selectDrive(DriveNum num, EmuTime::param time)
void setSide(bool side) override
Side select.
DriveMultiplexer multiplexer
uint8_t peekDataReg(EmuTime::param time) const
Definition WD2793.cc:314
bool peekIRQ(EmuTime::param time) const
Definition WD2793.cc:99
uint8_t getStatusReg(EmuTime::param time)
Definition WD2793.cc:159
void setTrackReg(uint8_t value, EmuTime::param time)
Definition WD2793.cc:205
void setSectorReg(uint8_t value, EmuTime::param time)
Definition WD2793.cc:220
uint8_t getTrackReg(EmuTime::param time) const
Definition WD2793.cc:210
uint8_t peekSectorReg(EmuTime::param time) const
Definition WD2793.cc:230
bool peekDTRQ(EmuTime::param time) const
Definition WD2793.cc:84
void setCommandReg(uint8_t value, EmuTime::param time)
Definition WD2793.cc:111
uint8_t peekTrackReg(EmuTime::param time) const
Definition WD2793.cc:215
bool getDTRQ(EmuTime::param time) const
Definition WD2793.cc:79
uint8_t peekStatusReg(EmuTime::param time) const
Definition WD2793.cc:199
uint8_t getDataReg(EmuTime::param time)
Definition WD2793.cc:249
void setDataReg(uint8_t value, EmuTime::param time)
Definition WD2793.cc:235
bool getIRQ(EmuTime::param time) const
Definition WD2793.cc:94
uint8_t getSectorReg(EmuTime::param time) const
Definition WD2793.cc:225
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)