18#include "SubComponent.h"
21#include "DiskAnalyzer.h"
22#include "DriveMemory.h"
36class Drive final :
public SubComponent,
public Inspectable<DriveInfo> {
38 Descriptions descriptions = {
41 .description =
"First Floppy Drive"
45 .description =
"Second Floppy Drive"
49 ConfigOptions options = {
69 friend class DriveMemory;
83 static constexpr i64 powerSafeThreshold = 100;
93 const u64 delayBetweenTwoCarryPulses[4] = {
102 DriveConfig config = { };
111 DriveMemory mem = DriveMemory(c64, *
this);
112 CPU cpu = CPU(MOS_6502, c64);
113 VIA1 via1 = VIA1(c64, *
this);
114 VIA2 via2 = VIA2(c64, *
this);
115 PiaDolphin pia = PiaDolphin(c64, *
this);
118 std::unique_ptr<Disk> disk;
126 std::unique_ptr<Disk> diskToInsert;
136 bool spinning =
false;
142 InsertionStatus insertionStatus = DISK_FULLY_EJECTED;
174 i64 carryCounter = 0;
190 i16 bitReadyTimer = 0;
199 u8 byteReadyCounter = 0;
202 Halftrack halftrack = 0;
218 u16 readShiftreg = 0;
223 u8 writeShiftreg = 0;
239 bool byteReady =
false;
247 i64 watchdog = INT64_MAX;
250 bool needsEmulation =
false;
259 Drive(C64 &ref, isize
id);
261 Drive& operator= (
const Drive& other) {
276 CLONE(byteReadyCounter)
285 CLONE(insertionStatus)
289 if (other.disk && !disk) disk = std::make_unique<Disk>();
290 if (!other.disk) disk =
nullptr;
291 if (disk) *disk = *other.disk;
293 if (other.diskToInsert && !diskToInsert) diskToInsert = std::make_unique<Disk>();
294 if (!other.diskToInsert) diskToInsert =
nullptr;
295 if (diskToInsert) *diskToInsert = *other.diskToInsert;
308 void serialize(T& worker)
335 if (isSoftResetter(worker))
return;
341 if (isResetter(worker))
return;
353 << config.insertDelay
355 << config.powerVolume
357 << config.insertVolume
358 << config.ejectVolume
362 void operator << (SerResetter &worker)
override { serialize(worker); };
363 void operator << (SerChecker &worker)
override;
364 void operator << (SerCounter &worker)
override;
365 void operator << (SerReader &worker)
override;
366 void operator << (SerWriter &worker)
override;
375 const Descriptions &getDescriptions()
const override {
return descriptions; }
379 void _initialize()
override;
380 void _dump(Category category, std::ostream& os)
const override;
381 void _reset(
bool hard)
override;
390 void cacheInfo(DriveInfo &result)
const override;
399 const DriveConfig &getConfig()
const {
return config; }
400 const ConfigOptions &getOptions()
const override {
return options; }
401 i64 getFallback(
Option opt)
const override;
402 i64 getOption(
Option opt)
const override;
403 void checkOption(
Option opt, i64 value)
override;
404 void setOption(
Option opt, i64 value)
override;
405 void resetConfig()
override;
408 void autoConfigure();
418 isize getDeviceNr()
const {
return objid; }
421 bool isDrive8() {
return objid == DRIVE8; }
422 bool isDrive9() {
return objid == DRIVE9; }
424 ParCableType getParCableType()
const {
return config.parCable; }
430 bool connectedAndOn() {
return config.connected && config.switchedOn; }
433 bool isIdle()
const {
return watchdog < 0; }
436 bool getRedLED()
const {
return redLED; };
439 void setRedLED(
bool b);
442 bool isRotating()
const {
return spinning; };
445 void setRotating(
bool b);
448 void wakeUp(isize awakeness = powerSafeThreshold);
458 bool hasDisk()
const;
459 bool hasPartiallyRemovedDisk()
const;
460 bool hasProtectedDisk()
const {
return hasDisk() && disk->isWriteProtected(); }
461 bool hasModifiedDisk()
const {
return hasDisk() && disk->isModified(); }
462 bool hasUnmodifiedDisk()
const {
return hasDisk() && !hasModifiedDisk(); }
463 bool hasUnprotectedDisk()
const {
return hasDisk() && !hasProtectedDisk(); }
466 void setModificationFlag(
bool value);
467 void markDiskAsModified() { setModificationFlag(
true); }
468 void markDiskAsUnmodified() { setModificationFlag(
false); }
471 void setProtection(
bool value);
472 void protectDisk() { setProtection(
true); }
473 void unprotectDisk() { setProtection(
false); }
474 void toggleProtection();
483 bool getLightBarrier()
const {
486 || hasPartiallyRemovedDisk()
487 || hasProtectedDisk();
498 void insertDisk(
const fs::path &path,
bool wp)
throws;
499 void insertDisk(std::unique_ptr<Disk> disk);
500 void insertNewDisk(
DOSType fstype,
string name);
501 void insertMediaFile(
class MediaFile &file,
bool wp);
502 void insertD64(
const class D64File &d64,
bool wp);
503 void insertG64(
const class G64File &g64,
bool wp);
504 void insertCollection(
class AnyCollection &archive,
bool wp)
throws;
505 void insertFileSystem(
const class FileSystem &device,
bool wp);
518 void execute(u64 duration);
528 bool readMode()
const {
return via2.getCB2(); }
529 bool writeMode()
const {
return !readMode(); }
532 Halftrack getHalftrack()
const {
return halftrack; }
533 Track getTrack()
const {
return (halftrack + 1) / 2; }
536 isize sizeOfHalftrack(Halftrack ht) {
537 return hasDisk() ? disk->lengthOfHalftrack(ht) : 0; }
538 isize sizeOfCurrentHalftrack() {
return sizeOfHalftrack(halftrack); }
541 HeadPos getOffset()
const {
return offset; }
550 bool getSync()
const {
return sync; }
557 void updateByteReady();
560 void raiseByteReady();
563 bool getZone()
const {
return zone; }
566 void setZone(isize value);
569 u8 readBitFromHead()
const;
572 void writeBitToHead(u8 bit);
588 void processCommand(
const Cmd &cmd);
591 void scheduleFirstDiskChangeEvent(EventID
id);
594 void processDiskChangeEvent(EventID
id);
Inspection interface.
Definition Inspectable.h:32
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
DOS_TYPE
File system type.
Definition FSTypes.h:27
OPT
Configuration option.
Definition OptionTypes.h:26
@ OPT_DRV_PARCABLE
Parallel cable type.
Definition OptionTypes.h:138
@ OPT_DRV_EJECT_DELAY
Disk ejection delay.
Definition OptionTypes.h:142
@ OPT_DRV_TYPE
Drive model.
Definition OptionTypes.h:135
@ OPT_DRV_SWAP_DELAY
Disk swap delay.
Definition OptionTypes.h:143
@ OPT_DRV_AUTO_CONFIG
Auto-configure drives based on the Drive Rom.
Definition OptionTypes.h:134
@ OPT_DRV_PAN
Pan.
Definition OptionTypes.h:145
@ OPT_DRV_INSERT_DELAY
Disk insertion delay.
Definition OptionTypes.h:144
@ OPT_DRV_POWER_SWITCH
Power switch (on/off)
Definition OptionTypes.h:140
@ OPT_DRV_RAM
Drive Ram.
Definition OptionTypes.h:136
@ OPT_DRV_SAVE_ROMS
Save Roms in snapshots.
Definition OptionTypes.h:137
@ OPT_DRV_INSERT_VOL
Volume (disk insertion)
Definition OptionTypes.h:148
@ OPT_DRV_EJECT_VOL
Volume (disk ejection)
Definition OptionTypes.h:149
@ OPT_DRV_CONNECT
Connection status.
Definition OptionTypes.h:139
@ OPT_DRV_POWER_VOL
Volume (power-up sound)
Definition OptionTypes.h:146
@ OPT_DRV_POWER_SAVE
Enable fast-paths.
Definition OptionTypes.h:141
@ OPT_DRV_STEP_VOL
Volume (head steps)
Definition OptionTypes.h:147
PAR_CABLE_TYPE
Parallel cable type.
Definition ParCableTypes.h:26
@ PAR_CABLE_NONE
No parallel cable attached.
Definition ParCableTypes.h:27