openMSX
NowindHost.hh
Go to the documentation of this file.
1 #ifndef NOWINDHOST_HH
2 #define NOWINDHOST_HH
3 
4 #include "NowindInterface.hh"
5 #include "DiskImageUtils.hh"
6 #include "circular_buffer.hh"
7 #include "openmsx.hh"
8 #include <vector>
9 #include <string>
10 #include <memory>
11 #include <iosfwd>
12 
13 namespace openmsx {
14 
15 class SectorAccessibleDisk;
16 
18 {
19 public:
20  explicit NowindHost(const NowindInterface::Drives& drives);
21  ~NowindHost();
22 
23  // public for usb-host implementation
24  bool isDataAvailable() const;
25 
26  // read one byte of response-data from the host (msx <- pc)
27  byte read();
28 
29  // like read(), but without side effects (doesn't consume the data)
30  byte peek() const;
31 
32  // Write one byte of command-data to the host (msx -> pc)
33  // Time parameter is in milliseconds. Emulators can pass emulation
34  // time, usbhost can pass real time.
35  void write(byte value, unsigned time);
36 
37  void setAllowOtherDiskroms(bool allow);
38  bool getAllowOtherDiskroms() const;
39 
40  void setEnablePhantomDrives(bool enable);
41  bool getEnablePhantomDrives() const;
42 
43  template<typename Archive>
44  void serialize(Archive& ar, unsigned version);
45 
46  // public for serialization
47  enum State {
48  STATE_SYNC1, // waiting for AF
49  STATE_SYNC2, // waiting for 05
50  STATE_COMMAND, // waiting for command (9 bytes)
51  STATE_DISKREAD, // waiting for AF07
52  STATE_DISKWRITE, // waiting for AA<data>AA
53  STATE_DEVOPEN, // waiting for filename (11 bytes)
54  STATE_IMAGE, // waiting for filename
55  STATE_MESSAGE, // waiting for null-terminated message
56  };
57 
58 private:
59  void msxReset();
60  SectorAccessibleDisk* getDisk() const;
61  void executeCommand();
62 
63  void send(byte value);
64  void send16(word value);
65  void sendHeader();
66  void purge();
67 
68  void DRIVES();
69  void DSKCHG();
70  void CHOICE();
71  void INIENV();
72  void setDateMSX();
73 
74  unsigned getSectorAmount() const;
75  unsigned getStartSector() const;
76  unsigned getStartAddress() const;
77  unsigned getCurrentAddress() const;
78 
79  void diskReadInit(SectorAccessibleDisk& disk);
80  void doDiskRead1();
81  void doDiskRead2();
82  void transferSectors(unsigned transferAddress, unsigned amount);
83  void transferSectorsBackwards(unsigned transferAddress, unsigned amount);
84 
85  void diskWriteInit(SectorAccessibleDisk& disk);
86  void doDiskWrite1();
87  void doDiskWrite2();
88 
89  unsigned getFCB() const;
90  std::string extractName(int begin, int end) const;
91  unsigned readHelper1(unsigned dev, char* buffer);
92  void readHelper2(unsigned len, const char* buffer);
93  int getDeviceNum() const;
94  int getFreeDeviceNum();
95  void deviceOpen();
96  void deviceClose();
97  void deviceWrite();
98  void deviceRead();
99 
100  void callImage(const std::string& filename);
101 
102 
103  static const unsigned MAX_DEVICES = 16;
104 
105  const NowindInterface::Drives& drives;
106 
107  cb_queue<byte> hostToMsxFifo;
108 
109  struct {
110  std::unique_ptr<std::fstream> fs; // not in use when fs == nullptr
111  unsigned fcb;
112  } devices[MAX_DEVICES];
113 
114  // state-machine
115  std::vector<SectorBuffer> buffer;// work buffer for diskread/write
116  unsigned lastTime; // last time a byte was received from MSX
117  State state;
118  unsigned recvCount; // how many bytes recv in this state
119  unsigned transfered; // progress within diskread/write
120  unsigned retryCount; // only used for diskread
121  unsigned transferSize; // size of current chunk
122  byte cmdData[9]; // reg_[cbedlhfa] + cmd
123  byte extraData[240 + 2]; // extra data for diskread/write
124 
125  byte romdisk; // index of romdisk (255 = no romdisk)
126  bool allowOtherDiskroms;
127  bool enablePhantomDrives;
128 };
129 
130 } // namespace openmsx
131 
132 #endif // NOWINDHOST_HH
std::vector< std::unique_ptr< DiskContainer > > Drives
NowindHost(const NowindInterface::Drives &drives)
Definition: NowindHost.cc:38
void setAllowOtherDiskroms(bool allow)
Definition: NowindHost.cc:53
byte peek() const
Definition: NowindHost.cc:72
bool getEnablePhantomDrives() const
Definition: NowindHost.cc:66
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:33
bool getAllowOtherDiskroms() const
Definition: NowindHost.cc:57
void write(byte value, unsigned time)
Definition: NowindHost.cc:90
std::unique_ptr< std::fstream > fs
Definition: NowindHost.hh:110
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:38
void serialize(Archive &ar, unsigned version)
Definition: NowindHost.cc:802
void setEnablePhantomDrives(bool enable)
Definition: NowindHost.cc:62
bool isDataAvailable() const
Definition: NowindHost.cc:83