2018-12-16 04:39:08 +00:00
|
|
|
/*
|
|
|
|
epple2
|
|
|
|
|
|
|
|
Copyright © 2018, Christopher Alan Mosher, Shelton, CT, USA. <cmosher01@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY, without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WOZFILE_H
|
|
|
|
#define WOZFILE_H
|
|
|
|
|
2022-12-08 13:47:23 +00:00
|
|
|
#include <filesystem>
|
2018-12-16 04:39:08 +00:00
|
|
|
#include <string>
|
2018-12-18 13:46:46 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
2018-12-23 21:44:30 +00:00
|
|
|
static const std::uint8_t C_QTRACK(160);
|
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
/**
|
|
|
|
* @brief WOZ file (floppy disk image)
|
|
|
|
* Represents a floppy disk. We only handle 5.25" disks.
|
2018-12-23 21:44:30 +00:00
|
|
|
* A standard disk has 141 quarter-track possible positions
|
|
|
|
* (0.00, 0.25, 0.5, 0.75, 1.00, ..., 33.5, 33.75, 34.00),
|
|
|
|
* but will typically have 35 tracks (0.00, 1.00, ..., 34.00).
|
|
|
|
*
|
|
|
|
* Non-standard disks can have more tracks. Especially, modified DOSes
|
|
|
|
* exists that can easily handle one additional track. Also, the WOZ2
|
|
|
|
* specification allows for more tracks.
|
|
|
|
*
|
|
|
|
* Here we handle what the WOZ2 specification can handle, that is,
|
|
|
|
* 160 quarter-track positions, tracks 0.00 through 39.75.
|
|
|
|
*
|
2018-12-18 13:46:46 +00:00
|
|
|
* The floppy disk "knows" it's rotational position.
|
|
|
|
*
|
2018-12-23 21:44:30 +00:00
|
|
|
* Note, the floppy disk has no concept of a "current" track;
|
2018-12-18 13:46:46 +00:00
|
|
|
* rather, that information is known by the stepper motor and arm.
|
|
|
|
*/
|
2018-12-16 04:39:08 +00:00
|
|
|
class WozFile {
|
2022-12-08 13:47:23 +00:00
|
|
|
std::filesystem::path filePath;
|
2018-12-16 04:39:08 +00:00
|
|
|
bool loaded;
|
|
|
|
bool modified;
|
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
// represents (negation of) write-protect tab
|
|
|
|
// We consider the disk to be write-protected if the user does
|
|
|
|
// not have write access to the file OR the WOZ file INFO chuck
|
|
|
|
// indicates that the floppy was write-protected.
|
|
|
|
bool writable;
|
|
|
|
|
2018-12-23 21:44:30 +00:00
|
|
|
// map of quarter-tracks from T00.00 through T39.75, values are indexes into trk
|
|
|
|
std::uint8_t* tmap;
|
|
|
|
// first actual quarter-track (e.g., 0 for normal 35-track disk), or 0xFF if no tracks
|
2018-12-27 20:03:46 +00:00
|
|
|
std::uint8_t initialQtrack;
|
2018-12-23 21:44:30 +00:00
|
|
|
// last actual quarter-track (e.g., 136 for normal 35-track disk), or 0xFF if no tracks
|
|
|
|
std::uint8_t finalQtrack;
|
|
|
|
|
|
|
|
// array of track buffers (null if no track data)
|
|
|
|
std::uint8_t* trk[C_QTRACK];
|
|
|
|
// count of bits in each track
|
|
|
|
std::uint32_t trk_bits[C_QTRACK];
|
2018-12-27 20:03:46 +00:00
|
|
|
// count of allocated bytes
|
|
|
|
std::uint16_t trk_byts[C_QTRACK];
|
2018-12-16 04:39:08 +00:00
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
// bit and byt together represent the rotational position
|
|
|
|
// of the floppy disk.
|
|
|
|
// bit is a mask indicating current bit within current byte (byt).
|
|
|
|
// WOZ file bits are packed into bytes starting at bit 7
|
|
|
|
// through bit 0 of the first byte, then bits 7-0 of the
|
2018-12-23 21:44:30 +00:00
|
|
|
// next byte, etc., from bits 0 through trk_bits[qt]-1
|
2018-12-18 13:46:46 +00:00
|
|
|
std::uint8_t bit;
|
|
|
|
std::uint16_t byt;
|
|
|
|
|
2018-12-18 20:44:06 +00:00
|
|
|
// We need to store which track were on, only so we can detect
|
|
|
|
// a change in tracks, and if so adjust our current byt/bit
|
|
|
|
// to be proportional with the new track. This is discussed
|
|
|
|
// in the WOZ file spec.
|
2018-12-18 13:46:46 +00:00
|
|
|
std::uint8_t lastQuarterTrack;
|
|
|
|
|
2018-12-23 21:44:30 +00:00
|
|
|
// optimal timing, in "one-eighth microseconds per bit" units
|
|
|
|
// standard is 32 ( = 4 microseconds per bit)
|
|
|
|
std::uint8_t timing;
|
|
|
|
|
|
|
|
bool sync;
|
|
|
|
bool cleaned;
|
|
|
|
std::string creator;
|
|
|
|
|
2018-12-16 04:39:08 +00:00
|
|
|
void checkForWriteProtection();
|
2019-01-01 14:12:19 +00:00
|
|
|
void expandTracks();
|
|
|
|
void reduceTracks();
|
|
|
|
bool trackIsZeroes(std::uint8_t qt);
|
|
|
|
bool tracksAreIdentical(std::uint8_t qt1, std::uint8_t qt2);
|
|
|
|
void removeTrack(const int trackIndex);
|
|
|
|
std::uint32_t calcNewTrackLengthBits(std::uint8_t qt);
|
|
|
|
void copyTrack(std::uint8_t qt_dest, std::uint8_t qt_src);
|
|
|
|
void createNewTrack(const std::uint8_t qt);
|
|
|
|
void dumpTmap();
|
|
|
|
void dumpTracks();
|
|
|
|
void rawSet(std::uint8_t currentQuarterTrack, bool on);
|
2018-12-16 04:39:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
WozFile();
|
|
|
|
~WozFile();
|
|
|
|
|
2022-12-09 01:33:52 +00:00
|
|
|
bool load(const std::filesystem::path& filePath);
|
2018-12-16 04:39:08 +00:00
|
|
|
|
2019-06-23 01:21:27 +00:00
|
|
|
bool isLoaded() const {
|
2018-12-16 04:39:08 +00:00
|
|
|
return this->loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void save();
|
|
|
|
void unload();
|
2019-06-23 01:21:27 +00:00
|
|
|
bool isWriteProtected() const {
|
2018-12-16 04:39:08 +00:00
|
|
|
return !this->writable;
|
|
|
|
}
|
|
|
|
|
2019-06-23 01:21:27 +00:00
|
|
|
bool isModified() const {
|
2018-12-16 04:39:08 +00:00
|
|
|
return this->modified;
|
|
|
|
}
|
2018-12-18 13:46:46 +00:00
|
|
|
|
|
|
|
void rotateOneBit(std::uint8_t currentQuarterTrack);
|
2020-04-18 17:26:21 +00:00
|
|
|
bool exists(std::uint8_t currentQuarterTrack);
|
2018-12-18 13:46:46 +00:00
|
|
|
bool getBit(std::uint8_t currentQuarterTrack);
|
2018-12-18 20:44:06 +00:00
|
|
|
void setBit(std::uint8_t currentQuarterTrack, bool on);
|
2019-01-01 14:12:19 +00:00
|
|
|
void rawSet();
|
2019-06-23 01:41:42 +00:00
|
|
|
|
|
|
|
int optimal_timing() const {
|
|
|
|
if (this->loaded) {
|
|
|
|
return this->timing;
|
|
|
|
}
|
|
|
|
return 32;
|
|
|
|
}
|
2018-12-16 04:39:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WOZFILE_H
|