Skip to content

Commit a09b055

Browse files
committed
Work on FloppyDrive TrackDevice interface
1 parent 56a8b79 commit a09b055

File tree

8 files changed

+78
-92
lines changed

8 files changed

+78
-92
lines changed

Core/Components/Paula/DiskController/DiskController.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ DiskController::readByte()
283283
FloppyDrive *drive = getSelectedDrive();
284284

285285
// Read a byte from the drive
286-
incoming = drive ? drive->readByteAndRotate() : 0;
286+
incoming = drive ? drive->read8AndRotate() : 0;
287287

288288
// Set the byte ready flag (shows up in DSKBYT)
289289
incoming |= 0x8000;
@@ -343,7 +343,7 @@ DiskController::writeByte()
343343
u8 outgoing = readFifo();
344344

345345
// Write byte to disk
346-
if (drive) drive->writeByteAndRotate(outgoing);
346+
if (drive) drive->write8AndRotate(outgoing);
347347
}
348348
}
349349

@@ -466,7 +466,7 @@ DiskController::performDMAWrite(FloppyDrive *drive, u32 remaining)
466466
while (!fifoIsEmpty()) {
467467

468468
u8 value = readFifo();
469-
if (drive) drive->writeByteAndRotate(value);
469+
if (drive) drive->write8AndRotate(value);
470470
}
471471
setState(DriveDmaState::OFF);
472472

@@ -529,7 +529,7 @@ DiskController::performTurboRead(FloppyDrive *drive)
529529
for (isize i = 0; i < (dsklen & 0x3FFF); i++) {
530530

531531
// Read word from disk
532-
u16 word = drive->readWordAndRotate();
532+
u16 word = drive->read16AndRotate();
533533

534534
// Write word into memory
535535
if (DSK_CHECKSUM) {
@@ -570,7 +570,7 @@ DiskController::performTurboWrite(FloppyDrive *drive)
570570
agnus.dskpt += 2;
571571

572572
// Write word to disk
573-
drive->writeWordAndRotate(word);
573+
drive->write16AndRotate(word);
574574
}
575575

576576
debug(DSK_CHECKSUM,

Core/Misc/RetroShell/NavigatorConsole.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,33 @@ NavigatorConsole::initCommands(RSCommand &root)
635635
});
636636
}
637637

638+
root.add({
639+
640+
.tokens = { "unmount" },
641+
.chelp = { "Unmount the file system" },
642+
.flags = vAmigaDOS ? rs::disabled : 0,
643+
.func = [this] (std::ostream &os, const Arguments &args, const std::vector<isize> &values) {
644+
645+
requireFS();
646+
647+
fs->flush();
648+
fs = nullptr;
649+
}
650+
});
651+
652+
root.add({
653+
654+
.tokens = { "flush" },
655+
.chelp = { "Flush the file system cache" },
656+
.flags = vAmigaDOS ? rs::disabled : 0,
657+
.func = [this] (std::ostream &os, const Arguments &args, const std::vector<isize> &values) {
658+
659+
requireFS();
660+
661+
fs->flush();
662+
}
663+
});
664+
638665
root.add({
639666

640667
.tokens = { "import" },

Core/Peripherals/Drive/DiskEncoder.cpp

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ DiskEncoder::decodeAmigaTrack(ByteView track, TrackNr t, MutableByteView dst)
213213
// Find all sectors
214214
auto offsets = seekSectors(track);
215215

216+
/*
216217
for (isize i = 0; i < count; ++i) {
217218
if (!offsets.contains(i)) {
218219
warn("Sector %ld not found. Aborting.\n", i);
@@ -223,6 +224,7 @@ DiskEncoder::decodeAmigaTrack(ByteView track, TrackNr t, MutableByteView dst)
223224
warn("Found %zd sectors, expected %ld. Aborting.\n", offsets.size(), count);
224225
throw DeviceError(DeviceError::DSK_WRONG_SECTOR_COUNT);
225226
}
227+
*/
226228

227229
// Decode all sectors
228230
for (SectorNr s = 0; s < count; s++) {
@@ -235,41 +237,6 @@ DiskEncoder::decodeAmigaTrack(ByteView track, TrackNr t, MutableByteView dst)
235237
auto *secData = dst.data() + s * bsize;
236238
decodeAmigaSector(track, offsets[s], span<u8>(secData, bsize));
237239
}
238-
239-
/*
240-
// Find all sync marks
241-
auto it = track.cyclic_begin();
242-
std::vector<isize> syncMarks;
243-
syncMarks.reserve(count);
244-
245-
constexpr isize syncMarkLen = 4;
246-
for (isize i = 0; i < track.size() + syncMarkLen; ++i, ++it) {
247-
248-
// Scan MFM stream for $4489 $4489
249-
if (it[0] != 0x44) continue;
250-
if (it[1] != 0x89) continue;
251-
if (it[2] != 0x44) continue;
252-
if (it[3] != 0x89) continue;
253-
254-
// Make sure it's not a DOS track
255-
if (it[5] == 0x89) continue;
256-
257-
syncMarks.push_back(it.offset());
258-
}
259-
260-
if (ADF_DEBUG) fprintf(stderr, "Found %zd sectors (expected %ld)\n", syncMarks.size(), count);
261-
262-
// Check that the track contains the proper amount of sync marks
263-
if (isize(syncMarks.size()) != count) {
264-
265-
warn("Found %zd sectors, expected %ld. Aborting.\n", syncMarks.size(), count);
266-
throw DeviceError(DeviceError::DSK_WRONG_SECTOR_COUNT);
267-
}
268-
269-
// Decode all sectors
270-
for (SectorNr s = 0; s < count; s++)
271-
decodeAmigaSector(track, syncMarks[s], dst);
272-
*/
273240
}
274241

275242
void
@@ -280,36 +247,19 @@ DiskEncoder::decodeAmigaSector(ByteView track, isize offset, MutableByteView dst
280247

281248
if (MFM_DEBUG) fprintf(stderr, "Decoding sector at offset %ld\n", offset);
282249

283-
// Skip sync mark
284-
offset += 4;
285-
286-
/*
287-
// Decode sector info
288-
u8 info[4]; decodeOddEven(info, &track[offset], 4);
250+
// Skip sync mark + sector header
251+
offset += 4 + 56;
289252

290-
// Extract the sector number
291-
auto secNr = SectorNr(info[2]);
253+
// Determine the source address
254+
auto *mfmData = &track[offset];
292255

293-
if (MFM_DEBUG) fprintf(stderr, "Decoding sector %ld\n", secNr);
294-
*/
256+
for (isize i = 0; i < 16; ++i) { printf("%0X ", mfmData[i]); } printf("\n");
295257

296-
// Check that the sector number is valid
297-
/*
298-
if (secNr * bsize + bsize > dst.size()) {
299-
300-
warn("Invalid sector number %ld. Aborting.\n", secNr);
301-
throw DeviceError(DeviceError::DSK_INVALID_SECTOR_NUMBER);
302-
}
303-
*/
304-
305-
// Determine the destination address
306-
// auto *secData = dst.data() + secNr * bsize;
307-
308-
// Determine the source address (adding 56 skips the sector header)
309-
auto *mfmData = &track[offset + 56];
310258

311259
// Decode sector data
312260
decodeOddEven(dst.data(), mfmData, bsize);
261+
262+
for (isize i = 0; i < 8; ++i) { printf("%0X ", dst.data()[i]); } printf("\n");
313263
}
314264

315265
optional<isize>

Core/Peripherals/Drive/FloppyDisk.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ FloppyDisk::readBlock(u8 *dst, isize nr) const
115115
if (!offset)
116116
throw IOError(DeviceError::DEV_SEEK_ERR, "Block " + std::to_string(nr));
117117

118-
debug(MFM_DEBUG, "Found sector (%ld,%ld) at offset %ld\n", t, s, *offset);
118+
debug(MFM_DEBUG, "Found (%ld,%ld) at offset %ld\n", t, s, *offset);
119119
DiskEncoder::decodeAmigaSector(tdata, *offset, std::span<u8>(dst, 512));
120120
}
121121

@@ -131,7 +131,7 @@ FloppyDisk::writeBlock(const u8 *src, isize nr)
131131
if (!offset)
132132
throw IOError(DeviceError::DEV_SEEK_ERR, "Block " + std::to_string(nr));
133133

134-
debug(MFM_DEBUG, "Found sector (%ld,%ld) at offset %ld\n", t, s, *offset);
134+
debug(MFM_DEBUG, "Found (%ld,%ld) at offset %ld\n", t, s, *offset);
135135
DiskEncoder::encodeAmigaSector(tdata, *offset, t, s, std::span<const u8>(src, 512));
136136
}
137137

Core/Peripherals/Drive/FloppyDrive.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ FloppyDrive::selectSide(HeadNr h)
792792
}
793793

794794
u8
795-
FloppyDrive::readByte() const
795+
FloppyDrive::read8() const
796796
{
797797
// Case 1: No disk is inserted
798798
if (!disk) return 0xFF;
@@ -805,42 +805,42 @@ FloppyDrive::readByte() const
805805
}
806806

807807
u8
808-
FloppyDrive::readByteAndRotate()
808+
FloppyDrive::read8AndRotate()
809809
{
810-
u8 result = readByte();
810+
u8 result = read8();
811811
if (motor) rotate();
812812
return result;
813813
}
814814

815815
u16
816-
FloppyDrive::readWordAndRotate()
816+
FloppyDrive::read16AndRotate()
817817
{
818-
u8 byte1 = readByteAndRotate();
819-
u8 byte2 = readByteAndRotate();
818+
u8 byte1 = read8AndRotate();
819+
u8 byte2 = read8AndRotate();
820820

821821
return HI_LO(byte1, byte2);
822822
}
823823

824824
void
825-
FloppyDrive::writeByte(u8 value)
825+
FloppyDrive::write8(u8 value)
826826
{
827827
if (disk) {
828828
disk->write8(head.cylinder, head.head, head.offset, value);
829829
}
830830
}
831831

832832
void
833-
FloppyDrive::writeByteAndRotate(u8 value)
833+
FloppyDrive::write8AndRotate(u8 value)
834834
{
835-
writeByte(value);
835+
write8(value);
836836
if (motor) rotate();
837837
}
838838

839839
void
840-
FloppyDrive::writeWordAndRotate(u16 value)
840+
FloppyDrive::write16AndRotate(u16 value)
841841
{
842-
writeByteAndRotate(HI_BYTE(value));
843-
writeByteAndRotate(LO_BYTE(value));
842+
write8AndRotate(HI_BYTE(value));
843+
write8AndRotate(LO_BYTE(value));
844844
}
845845

846846
void
@@ -869,8 +869,8 @@ FloppyDrive::findSyncMark()
869869

870870
for (isize i = 0; i < length; i++) {
871871

872-
if (readByteAndRotate() != 0x44) continue;
873-
if (readByteAndRotate() != 0x89) continue;
872+
if (read8AndRotate() != 0x44) continue;
873+
if (read8AndRotate() != 0x89) continue;
874874
break;
875875
}
876876

Core/Peripherals/Drive/FloppyDrive.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ class FloppyDrive final : public Drive, public TrackDevice {
362362
void selectSide(HeadNr h);
363363

364364
// Reads a value from the drive head and optionally rotates the disk
365-
u8 readByte() const;
366-
u8 readByteAndRotate();
367-
u16 readWordAndRotate();
365+
u8 read8() const;
366+
u8 read8AndRotate();
367+
u16 read16AndRotate();
368368

369369
// Writes a value to the drive head and optionally rotates the disk
370-
void writeByte(u8 value);
371-
void writeByteAndRotate(u8 value);
372-
void writeWordAndRotate(u16 value);
370+
void write8(u8 value);
371+
void write8AndRotate(u8 value);
372+
void write16AndRotate(u16 value);
373373

374374
// Emulate a disk rotation (moves head to the next byte)
375375
void rotate();

Core/Storage/FileSystems/FSDescriptor.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "config.h"
1111
#include "FSDescriptor.h"
1212
#include "BlockDevice.h"
13+
#include "ADFFile.h"
1314
#include "FSError.h"
1415
#include "utl/io.h"
1516
#include "utl/types/Literals.h"
@@ -53,16 +54,24 @@ FSDescriptor::init(isize numBlocks, FSFormat dos)
5354
this->dos = dos;
5455

5556
// Determine the location of the root block
56-
isize highKey = numBlocks - 1;
57-
isize rootKey = (numReserved + highKey) / 2;
58-
rootBlock = BlockNr(rootKey);
57+
if (numBlocks * 512 == ADFFile::ADFSIZE_35_DD_81 ||
58+
numBlocks * 512 == ADFFile::ADFSIZE_35_DD_82 ||
59+
numBlocks * 512 == ADFFile::ADFSIZE_35_DD_83 ||
60+
numBlocks * 512 == ADFFile::ADFSIZE_35_DD_84) {
5961

60-
assert(rootKey == numBlocks / 2);
62+
rootBlock = 880;
63+
64+
} else {
65+
66+
isize highKey = numBlocks - 1;
67+
isize rootKey = (numReserved + highKey) / 2;
68+
rootBlock = BlockNr(rootKey);
69+
}
6170

6271
// Determine the number of required bitmap blocks
6372
isize bitsPerBlock = (bsize - 4) * 8;
6473
isize neededBlocks = (numBlocks + bitsPerBlock - 1) / bitsPerBlock;
65-
isize bmKey = rootKey + 1;
74+
isize bmKey = rootBlock + 1;
6675

6776
// Add bitmap blocks
6877
for (isize i = 0; i < neededBlocks; i++) {

Core/utlib/src/abilities/Dumpable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Dumpable::dump(std::ostream &os, const DumpOpt &opt, const string &fmt, DataProv
109109
};
110110

111111
// Continue as long as data is available
112-
while (reader(bcnt, 1) != -1 && reader(ccnt, 1) != -1) {
112+
while (reader(bcnt, 1).has_value() && reader(ccnt, 1).has_value()) {
113113

114114
// Rewind to the beginning of the format string
115115
const char *p = fmt.c_str();

0 commit comments

Comments
 (0)