openMSX
NowindHost.cc
Go to the documentation of this file.
1#include "NowindHost.hh"
2
3#include "DiskContainer.hh"
4#include "FileOperations.hh"
5#include "MSXException.hh"
7
8#include "enumerate.hh"
9#include "narrow.hh"
10#include "one_of.hh"
11#include "serialize.hh"
12#include "serialize_stl.hh"
13#include "unreachable.hh"
14#include "view.hh"
15#include "xrange.hh"
16
17#include <algorithm>
18#include <array>
19#include <bit>
20#include <cassert>
21#include <cctype>
22#include <cstdio>
23#include <cstdarg>
24#include <ctime>
25#include <fstream>
26#include <memory>
27
28using std::string;
29
30namespace openmsx {
31
32static constexpr unsigned SECTOR_SIZE = sizeof(SectorBuffer);
33
34static void DBERR(const char* message, ...)
35{
36 (void)message;
37#if 0
38 va_list args;
39 va_start(args, message);
40 printf("nowind: ");
41 vprintf(message, args);
42 va_end(args);
43#endif
44}
45
46
48 : drives(drives_)
49{
50}
51
52NowindHost::~NowindHost() = default;
53
54byte NowindHost::peek() const
55{
56 return isDataAvailable() ? hostToMsxFifo.front() : 0xFF;
57}
58
59// receive: msx <- pc
61{
62 return isDataAvailable() ? hostToMsxFifo.pop_front() : 0xFF;
63}
64
66{
67 return !hostToMsxFifo.empty();
68}
69
70
71// send: msx -> pc
72void NowindHost::write(byte data, unsigned time)
73{
74 unsigned duration = time - lastTime;
75 lastTime = time;
76 if (duration >= 500) {
77 // timeout (500ms), start looking for AF05
78 purge();
79 state = STATE_SYNC1;
80 }
81
82 switch (state) {
83 case STATE_SYNC1:
84 if (data == 0xAF) state = STATE_SYNC2;
85 break;
86 case STATE_SYNC2:
87 switch (data) {
88 case 0x05: state = STATE_COMMAND; recvCount = 0; break;
89 case 0xAF: state = STATE_SYNC2; break;
90 case 0xFF: state = STATE_SYNC1; msxReset(); break;
91 default: state = STATE_SYNC1; break;
92 }
93 break;
94 case STATE_COMMAND:
95 assert(recvCount < 9);
96 cmdData[recvCount] = data;
97 if (++recvCount == 9) {
98 executeCommand();
99 }
100 break;
101 case STATE_DISKREAD:
102 assert(recvCount < 2);
103 extraData[recvCount] = data;
104 if (++recvCount == 2) {
105 doDiskRead2();
106 }
107 break;
108 case STATE_DISKWRITE:
109 assert(recvCount < (transferSize + 2));
110 extraData[recvCount] = data;
111 if (++recvCount == (transferSize + 2)) {
112 doDiskWrite2();
113 }
114 break;
115 case STATE_DEVOPEN:
116 assert(recvCount < 11);
117 extraData[recvCount] = data;
118 if (++recvCount == 11) {
119 deviceOpen();
120 }
121 break;
122 case STATE_IMAGE:
123 assert(recvCount < 40);
124 extraData[recvCount] = data;
125 if (data == one_of(byte(0), byte(':')) ||
126 (++recvCount == 40)) {
127 auto* eData = std::bit_cast<char*>(extraData.data());
128 callImage(string(eData, recvCount));
129 state = STATE_SYNC1;
130 }
131 break;
132 case STATE_MESSAGE:
133 assert(recvCount < (240 - 1));
134 extraData[recvCount] = data;
135 if ((data == 0) || (++recvCount == (240 - 1))) {
136 extraData[recvCount] = 0;
137 DBERR("%s\n", std::bit_cast<char*>(extraData.data()));
138 state = STATE_SYNC1;
139 }
140 break;
141 default:
143 }
144}
145
146void NowindHost::msxReset()
147{
148 for (auto& dev : devices) {
149 dev.fs.reset();
150 }
151 DBERR("MSX reset\n");
152}
153
154SectorAccessibleDisk* NowindHost::getDisk() const
155{
156 byte num = cmdData[7]; // reg_a
157 if (num >= drives.size()) {
158 return nullptr;
159 }
160 return drives[num]->getSectorAccessibleDisk();
161}
162
163void NowindHost::executeCommand()
164{
165 assert(recvCount == 9);
166 byte cmd = cmdData[8];
167 switch (cmd) {
168 //case 0x0D: BDOS_0DH_DiskReset();
169 //case 0x0F: BDOS_0FH_OpenFile();
170 //case 0x10: BDOS_10H_CloseFile();
171 //case 0x11: BDOS_11H_FindFirst();
172 //case 0x12: BDOS_12H_FindNext();
173 //case 0x13: BDOS_13H_DeleteFile();
174 //case 0x14: BDOS_14H_ReadSeq();
175 //case 0x15: BDOS_15H_WriteSeq();
176 //case 0x16: BDOS_16H_CreateFile();
177 //case 0x17: BDOS_17H_RenameFile();
178 //case 0x21: BDOS_21H_ReadRandomFile();
179 //case 0x22: BDOS_22H_WriteRandomFile();
180 //case 0x23: BDOS_23H_GetFileSize();
181 //case 0x24: BDOS_24H_SetRandomRecordField();
182 //case 0x26: BDOS_26H_WriteRandomBlock();
183 //case 0x27: BDOS_27H_ReadRandomBlock();
184 //case 0x28: BDOS_28H_WriteRandomFileWithZeros();
185 //case 0x2A: BDOS_2AH_GetDate();
186 //case 0x2B: BDOS_2BH_SetDate();
187 //case 0x2C: BDOS_2CH_GetTime();
188 //case 0x2D: BDOS_2DH_SetTime();
189 //case 0x2E: BDOS_2EH_Verify();
190 //case 0x2F: BDOS_2FH_ReadLogicalSector();
191 //case 0x30: BDOS_30H_WriteLogicalSector();
192
193 case 0x80: { // DSKIO
194 auto* disk = getDisk();
195 if (!disk) {
196 // no such drive or no disk inserted
197 // (causes a timeout on the MSX side)
198 state = STATE_SYNC1;
199 return;
200 }
201 if (byte reg_f = cmdData[6]; reg_f & 1) { // carry flag
202 diskWriteInit(*disk);
203 } else {
204 diskReadInit(*disk);
205 }
206 break;
207 }
208
209 case 0x81: DSKCHG(); state = STATE_SYNC1; break;
210 //case 0x82: GETDPB();
211 //case 0x83: CHOICE();
212 //case 0x84: DSKFMT();
213 case 0x85: DRIVES(); state = STATE_SYNC1; break;
214 case 0x86: INIENV(); state = STATE_SYNC1; break;
215 case 0x87: setDateMSX(); state = STATE_SYNC1; break;
216 case 0x88: state = STATE_DEVOPEN; recvCount = 0; break;
217 case 0x89: deviceClose(); state = STATE_SYNC1; break;
218 //case 0x8A: deviceRandomIO(fcb);
219 case 0x8B: deviceWrite(); state = STATE_SYNC1; break;
220 case 0x8C: deviceRead(); state = STATE_SYNC1; break;
221 //case 0x8D: deviceEof(fcb);
222 //case 0x8E: auxIn();
223 //case 0x8F: auxOut();
224 case 0x90: state = STATE_MESSAGE; recvCount = 0; break;
225 case 0xA0: state = STATE_IMAGE; recvCount = 0; break;
226 //case 0xFF: vramDump();
227 default:
228 // Unknown USB command!
229 state = STATE_SYNC1;
230 break;
231 }
232}
233
234// send: pc -> msx
235void NowindHost::send(byte value)
236{
237 hostToMsxFifo.push_back(value);
238}
239void NowindHost::send16(word value)
240{
241 hostToMsxFifo.push_back(narrow_cast<byte>(value & 255));
242 hostToMsxFifo.push_back(narrow_cast<byte>(value >> 8));
243}
244
245void NowindHost::purge()
246{
247 hostToMsxFifo.clear();
248}
249
250void NowindHost::sendHeader()
251{
252 send(0xFF); // needed because first read might fail!
253 send(0xAF);
254 send(0x05);
255}
256
257void NowindHost::DSKCHG()
258{
259 auto* disk = getDisk();
260 if (!disk) {
261 // no such drive or no disk inserted
262 return;
263 }
264
265 sendHeader();
266 byte num = cmdData[7]; // reg_a
267 assert(num < drives.size());
268 if (drives[num]->diskChanged()) {
269 send(255); // changed
270 // read first FAT sector (contains media descriptor)
271 SectorBuffer sectorBuffer;
272 try {
273 disk->readSectors(std::span{&sectorBuffer, 1}, 1);
274 } catch (MSXException&) {
275 // TODO read error
276 sectorBuffer.raw[0] = 0;
277 }
278 send(sectorBuffer.raw[0]); // new media descriptor
279 } else {
280 send(0); // not changed
281 // TODO shouldn't we send some (dummy) byte here?
282 // nowind-disk-rom seems to read it (but doesn't use it)
283 }
284}
285
286void NowindHost::DRIVES()
287{
288 // at least one drive (MSX-DOS1 cannot handle 0 drives)
289 byte numberOfDrives = std::max<byte>(1, byte(drives.size()));
290
291 byte reg_a = cmdData[7];
292 sendHeader();
293 send(getEnablePhantomDrives() ? 0x02 : 0);
294 send(reg_a | (getAllowOtherDiskRoms() ? 0 : 0x80));
295 send(numberOfDrives);
296
297 romDisk = 255; // no rom disk
298 for (auto [i, drv] : enumerate(drives)) {
299 if (drv->isRomDisk()) {
300 romDisk = byte(i);
301 break;
302 }
303 }
304}
305
306void NowindHost::INIENV()
307{
308 sendHeader();
309 send(romDisk); // calculated in DRIVES()
310}
311
312void NowindHost::setDateMSX()
313{
314 auto td = time(nullptr);
315 auto* tm = localtime(&td);
316
317 sendHeader();
318 send(narrow_cast<uint8_t>(tm->tm_mday)); // day
319 send(narrow_cast<uint8_t>(tm->tm_mon + 1)); // month
320 send16(narrow_cast<uint16_t>(tm->tm_year + 1900)); // year
321}
322
323
324unsigned NowindHost::getSectorAmount() const
325{
326 byte reg_b = cmdData[1];
327 return reg_b;
328}
329unsigned NowindHost::getStartSector() const
330{
331 byte reg_c = cmdData[0];
332 byte reg_e = cmdData[2];
333 byte reg_d = cmdData[3];
334 unsigned startSector = reg_e + (reg_d * 256);
335 if (reg_c < 0x80) {
336 // FAT16 read/write sector
337 startSector += reg_c << 16;
338 }
339 return startSector;
340}
341unsigned NowindHost::getStartAddress() const
342{
343 byte reg_l = cmdData[4];
344 byte reg_h = cmdData[5];
345 return reg_h * 256 + reg_l;
346}
347unsigned NowindHost::getCurrentAddress() const
348{
349 unsigned startAddress = getStartAddress();
350 return startAddress + transferred;
351}
352
353
354void NowindHost::diskReadInit(const SectorAccessibleDisk& disk)
355{
356 unsigned sectorAmount = getSectorAmount();
357 buffer.resize(sectorAmount);
358 unsigned startSector = getStartSector();
359 try {
360 disk.readSectors(std::span{buffer.data(), sectorAmount}, startSector);
361 } catch (MSXException&) {
362 // read error
363 state = STATE_SYNC1;
364 return;
365 }
366
367 transferred = 0;
368 retryCount = 0;
369 doDiskRead1();
370}
371
372void NowindHost::doDiskRead1()
373{
374 unsigned bytesLeft = unsigned(buffer.size() * SECTOR_SIZE) - transferred;
375 if (bytesLeft == 0) {
376 sendHeader();
377 send(0x01); // end of receive-loop
378 send(0x00); // no more data
379 state = STATE_SYNC1;
380 return;
381 }
382
383 constexpr unsigned NUMBER_OF_BLOCKS = 32; // 32 * 64 bytes = 2048 bytes
384 transferSize = std::min(bytesLeft, NUMBER_OF_BLOCKS * 64); // hardcoded in firmware
385
386 unsigned address = getCurrentAddress();
387 if (address >= 0x8000) {
388 if (transferSize & 0x003F) {
389 transferSectors(address, transferSize);
390 } else {
391 transferSectorsBackwards(address, transferSize);
392 }
393 } else {
394 // transfer below 0x8000
395 // TODO shouldn't we also test for (transferSize & 0x3F)?
396 unsigned endAddress = address + transferSize;
397 if (endAddress <= 0x8000) {
398 transferSectorsBackwards(address, transferSize);
399 } else {
400 transferSize = 0x8000 - address;
401 transferSectors(address, transferSize);
402 }
403 }
404
405 // wait for 2 bytes
406 state = STATE_DISKREAD;
407 recvCount = 0;
408}
409
410void NowindHost::doDiskRead2()
411{
412 // disk rom sends back the last two bytes read
413 assert(recvCount == 2);
414 byte tail1 = extraData[0];
415 byte tail2 = extraData[1];
416 if ((tail1 == 0xAF) && (tail2 == 0x07)) {
417 transferred += transferSize;
418 retryCount = 0;
419
420 unsigned address = getCurrentAddress();
421 size_t bytesLeft = (buffer.size() * SECTOR_SIZE) - transferred;
422 if ((address == 0x8000) && (bytesLeft > 0)) {
423 sendHeader();
424 send(0x01); // end of receive-loop
425 send(0xff); // more data for page 2/3
426 }
427
428 // continue the rest of the disk read
429 doDiskRead1();
430 } else {
431 purge();
432 if (++retryCount == 10) {
433 // do nothing, timeout on MSX
434 // too many retries, aborting readDisk()
435 state = STATE_SYNC1;
436 return;
437 }
438
439 // try again, wait for two bytes
440 state = STATE_DISKREAD;
441 recvCount = 0;
442 }
443}
444
445// sends "02" + "transfer_addr" + "amount" + "data" + "0F 07"
446void NowindHost::transferSectors(unsigned transferAddress, unsigned amount)
447{
448 sendHeader();
449 send(0x00); // don't exit command, (more) data is coming
450 send16(narrow_cast<uint16_t>(transferAddress));
451 send16(narrow_cast<uint16_t>(amount));
452
453 std::span fullBuf{buffer[0].raw.data(), buffer.size() * SECTOR_SIZE};
454 for (auto buf = fullBuf.subspan(transferred, amount);
455 auto b : buf) {
456 send(b);
457 }
458 send(0xAF);
459 send(0x07); // used for validation
460}
461
462// sends "02" + "transfer_addr" + "amount" + "data" + "0F 07"
463void NowindHost::transferSectorsBackwards(unsigned transferAddress, unsigned amount)
464{
465 sendHeader();
466 send(0x02); // don't exit command, (more) data is coming
467 send16(narrow_cast<uint16_t>(transferAddress + amount));
468 send(narrow_cast<uint8_t>(amount / 64));
469
470 std::span fullBuf{buffer[0].raw.data(), buffer.size() * SECTOR_SIZE};
471 for (auto buf = fullBuf.subspan(transferred, amount);
472 auto b : view::reverse(buf)) {
473 send(b);
474 }
475 send(0xAF);
476 send(0x07); // used for validation
477}
478
479
480void NowindHost::diskWriteInit(const SectorAccessibleDisk& disk)
481{
482 if (disk.isWriteProtected()) {
483 sendHeader();
484 send(1);
485 send(0); // WRITE PROTECTED
486 state = STATE_SYNC1;
487 return;
488 }
489
490 unsigned sectorAmount = std::min(128u, getSectorAmount());
491 buffer.resize(sectorAmount);
492 transferred = 0;
493 doDiskWrite1();
494}
495
496void NowindHost::doDiskWrite1()
497{
498 unsigned bytesLeft = unsigned(buffer.size() * SECTOR_SIZE) - transferred;
499 if (bytesLeft == 0) {
500 // All data transferred!
501 auto sectorAmount = unsigned(buffer.size());
502 unsigned startSector = getStartSector();
503 if (auto* disk = getDisk()) {
504 try {
505 disk->writeSectors(std::span{buffer.data(), sectorAmount}, startSector);
506 } catch (MSXException&) {
507 // TODO write error
508 }
509 }
510 sendHeader();
511 send(255);
512 state = STATE_SYNC1;
513 return;
514 }
515
516 constexpr unsigned BLOCKSIZE = 240;
517 transferSize = std::min(bytesLeft, BLOCKSIZE);
518
519 unsigned address = getCurrentAddress();
520 unsigned endAddress = address + transferSize;
521 if ((address ^ endAddress) & 0x8000) {
522 // would cross page 1-2 boundary -> limit to page 1
523 transferSize = 0x8000 - address;
524 }
525
526 sendHeader();
527 send(0); // data ahead!
528 send16(narrow_cast<uint16_t>(address));
529 send16(narrow_cast<uint16_t>(transferSize));
530 send(0xaa);
531
532 // wait for data
533 state = STATE_DISKWRITE;
534 recvCount = 0;
535}
536
537void NowindHost::doDiskWrite2()
538{
539 assert(recvCount == (transferSize + 2));
540 //auto* buf = &buffer[0].raw[transferred];
541 std::span fullBuf{buffer[0].raw.data(), buffer.size() * SECTOR_SIZE};
542 auto dst = fullBuf.subspan(transferred, transferSize);
543 auto src = subspan(extraData, 1, transferSize);
544 ranges::copy(src, dst);
545
546 byte seq1 = extraData[0];
547 byte seq2 = extraData[transferSize + 1];
548 if ((seq1 == 0xaa) && (seq2 == 0xaa)) {
549 // good block received
550 transferred += transferSize;
551
552 unsigned address = getCurrentAddress();
553 size_t bytesLeft = (buffer.size() * SECTOR_SIZE) - transferred;
554 if ((address == 0x8000) && (bytesLeft > 0)) {
555 sendHeader();
556 send(254); // more data for page 2/3
557 }
558 } else {
559 // ERROR!!!
560 // This situation is still not handled correctly!
561 purge();
562 }
563
564 // continue the rest of the disk write
565 doDiskWrite1();
566}
567
568
569word NowindHost::getFCB() const
570{
571 // note: same code as getStartAddress(), merge???
572 byte reg_l = cmdData[4];
573 byte reg_h = cmdData[5];
574 return word(reg_h * 256 + reg_l);
575}
576
577string NowindHost::extractName(int begin, int end) const
578{
579 string result;
580 for (auto i : xrange(begin, end)) {
581 auto c = narrow_cast<char>(extraData[i]);
582 if (c == ' ') break;
583 result += char(toupper(c));
584 }
585 return result;
586}
587
588int NowindHost::getDeviceNum() const
589{
590 auto fcb = getFCB();
591 for (auto [i, dev] : enumerate(devices)) {
592 if (dev.fs && dev.fcb == fcb) {
593 return int(i);
594 }
595 }
596 return -1;
597}
598
599int NowindHost::getFreeDeviceNum()
600{
601 if (int dev = getDeviceNum(); dev != -1) {
602 // There already was a device open with this fcb address,
603 // reuse that device.
604 return dev;
605 }
606 // Search for free device.
607 for (auto [i, dev] : enumerate(devices)) {
608 if (!dev.fs) return int(i);
609 }
610 // All devices are in use. This can't happen when the MSX software
611 // functions correctly. We'll simply reuse the first device. It would
612 // be nicer if we reuse the oldest device, but that's harder to
613 // implement, and actually it doesn't really matter.
614 return 0;
615}
616
617void NowindHost::deviceOpen()
618{
619 state = STATE_SYNC1;
620
621 assert(recvCount == 11);
622 string filename = extractName(0, 8);
623 string ext = extractName(8, 11);
624 if (!ext.empty()) {
625 strAppend(filename, '.', ext);
626 }
627
628 auto fcb = getFCB();
629 unsigned dev = getFreeDeviceNum();
630 devices[dev].fs.emplace(); // takes care of deleting old fs
631 devices[dev].fcb = fcb;
632
633 sendHeader();
634 byte errorCode = 0;
635 byte openMode = cmdData[2]; // reg_e
636 switch (openMode) {
637 case 1: // read-only mode
638 devices[dev].fs->open(filename.c_str(), std::ios::in | std::ios::binary);
639 errorCode = 53; // file not found
640 break;
641 case 2: // create new file, write-only
642 devices[dev].fs->open(filename.c_str(), std::ios::out | std::ios::binary);
643 errorCode = 56; // bad file name
644 break;
645 case 8: // append to existing file, write-only
646 devices[dev].fs->open(filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
647 errorCode = 53; // file not found
648 break;
649 case 4:
650 send(58); // sequential I/O only
651 return;
652 default:
653 send(0xFF); // TODO figure out a good error number
654 return;
655 }
656 assert(errorCode != 0);
657 if (devices[dev].fs->fail()) {
658 devices[dev].fs.reset();
659 send(errorCode);
660 return;
661 }
662
663 unsigned readLen = 0;
664 bool eof = false;
665 std::array<char, 256> buf;
666 if (openMode == 1) {
667 // read-only mode, already buffer first 256 bytes
668 readLen = readHelper1(dev, buf);
669 assert(readLen <= 256);
670 eof = readLen < 256;
671 }
672
673 send(0x00); // no error
674 send16(fcb);
675 send16(narrow_cast<uint16_t>(9 + readLen + (eof ? 1 : 0))); // number of bytes to transfer
676
677 send(openMode);
678 send(0);
679 send(0);
680 send(0);
681 send(cmdData[3]); // reg_d
682 send(0);
683 send(0);
684 send(0);
685 send(0);
686
687 if (openMode == 1) {
688 readHelper2(subspan(buf, 0, readLen));
689 }
690}
691
692void NowindHost::deviceClose()
693{
694 int dev = getDeviceNum();
695 if (dev == -1) return;
696 devices[dev].fs.reset();
697}
698
699void NowindHost::deviceWrite()
700{
701 int dev = getDeviceNum();
702 if (dev == -1) return;
703 auto data = narrow_cast<char>(cmdData[0]); // reg_c
704 devices[dev].fs->write(&data, 1);
705}
706
707void NowindHost::deviceRead()
708{
709 int dev = getDeviceNum();
710 if (dev == -1) return;
711
712 std::array<char, 256> buf;
713 unsigned readLen = readHelper1(dev, buf);
714 bool eof = readLen < 256;
715 send(0xAF);
716 send(0x05);
717 send(0x00); // dummy
718 send16(narrow_cast<uint16_t>(getFCB() + 9));
719 send16(narrow_cast<uint16_t>(readLen + (eof ? 1 : 0)));
720 readHelper2(subspan(buf, 0, readLen));
721}
722
723unsigned NowindHost::readHelper1(unsigned dev, std::span<char, 256> buf)
724{
725 assert(dev < MAX_DEVICES);
726 unsigned len = 0;
727 for (; len < 256; ++len) {
728 devices[dev].fs->read(&buf[len], 1);
729 if (devices[dev].fs->eof()) break;
730 }
731 return len;
732}
733
734void NowindHost::readHelper2(std::span<const char> buf)
735{
736 for (auto c : buf) {
737 send(c);
738 }
739 if (buf.size() < 256) {
740 send(0x1A); // end-of-file
741 }
742}
743
744
745// strips a string from outer double-quotes and anything outside them
746// ie: 'pre("foo")bar' will result in 'foo'
747static constexpr std::string_view stripQuotes(std::string_view str)
748{
749 auto first = str.find_first_of('\"');
750 if (first == string::npos) {
751 // There are no quotes, return the whole string.
752 return str;
753 }
754 auto last = str.find_last_of ('\"');
755 if (first == last) {
756 // Error, there's only a single double-quote char.
757 return {};
758 }
759 // Return the part between the quotes.
760 return str.substr(first + 1, last - first - 1);
761}
762
763void NowindHost::callImage(const string& filename)
764{
765 byte num = cmdData[7]; // reg_a
766 if (num >= drives.size()) {
767 // invalid drive number
768 return;
769 }
770 if (drives[num]->insertDisk(FileOperations::expandTilde(string(stripQuotes(filename))))) {
771 // TODO error handling
772 }
773}
774
775
776static constexpr std::initializer_list<enum_string<NowindHost::State>> stateInfo = {
777 { "SYNC1", NowindHost::STATE_SYNC1 },
778 { "SYNC2", NowindHost::STATE_SYNC2 },
779 { "COMMAND", NowindHost::STATE_COMMAND },
780 { "DISKREAD", NowindHost::STATE_DISKREAD },
781 { "DISKWRITE", NowindHost::STATE_DISKWRITE },
782 { "DEVOPEN", NowindHost::STATE_DEVOPEN },
783 { "IMAGE", NowindHost::STATE_IMAGE },
784};
786
787template<typename Archive>
788void NowindHost::serialize(Archive& ar, unsigned /*version*/)
789{
790 // drives is serialized elsewhere
791
792 ar.serialize("hostToMsxFifo", hostToMsxFifo,
793 "lastTime", lastTime,
794 "state", state,
795 "recvCount", recvCount,
796 "cmdData", cmdData,
797 "extraData", extraData);
798
799 // for backwards compatibility, serialize buffer as a vector<byte>
800 size_t bufSize = buffer.size() * sizeof(SectorBuffer);
801 std::span<uint8_t> buf{buffer.data()->raw.data(), bufSize};
802 auto tmp = to_vector(buf);
803 ar.serialize("buffer", tmp);
804 ranges::copy(tmp, buf);
805
806 ar.serialize("transfered", transferred, // for bw compat, keep typo in serialize name
807 "retryCount", retryCount,
808 "transferSize", transferSize,
809 "romdisk", romDisk,
810 "allowOtherDiskroms", allowOtherDiskRoms,
811 "enablePhantomDrives", enablePhantomDrives);
812
813 // Note: We don't serialize 'devices'. So after a loadstate it will be
814 // as-if the devices are closed again. The reason for not serializing
815 // this is that it's very hard to serialize a fstream (and we anyway
816 // can't restore the state of the host filesystem).
817}
819
820} // namespace openmsx
bool empty() const
void push_back(U &&u)
const T & front() const
byte peek() const
Definition NowindHost.cc:54
NowindHost(const Drives &drives)
Definition NowindHost.cc:47
void serialize(Archive &ar, unsigned version)
void write(byte data, unsigned time)
Definition NowindHost.cc:72
std::vector< std::unique_ptr< DiskContainer > > Drives
Definition NowindHost.hh:23
bool isDataAvailable() const
Definition NowindHost.cc:65
bool getAllowOtherDiskRoms() const
Definition NowindHost.hh:43
bool getEnablePhantomDrives() const
Definition NowindHost.hh:46
constexpr auto enumerate(Iterable &&iterable)
Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta....
Definition enumerate.hh:28
string expandTilde(string path)
Expand the '~' character to the users home directory.
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint8_t byte
8 bit unsigned integer
Definition openmsx.hh:26
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
auto copy(InputRange &&range, OutputIter out)
Definition ranges.hh:250
constexpr auto reverse(Range &&range)
Definition view.hh:514
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
Definition ranges.hh:471
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define SERIALIZE_ENUM(TYPE, INFO)
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))> >
Definition stl.hh:275
void strAppend(std::string &result, Ts &&...ts)
Definition strCat.hh:752
#define UNREACHABLE
constexpr auto xrange(T e)
Definition xrange.hh:132
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)