2019-02-20 12:50:51 +00:00
|
|
|
#ifndef __WOZ_H
|
|
|
|
#define __WOZ_H
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "nibutil.h"
|
|
|
|
#include "disktypes.h"
|
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
#define DUMP_TRACK 0x01
|
|
|
|
#define DUMP_QTMAP 0x02
|
|
|
|
#define DUMP_QTCRC 0x04
|
|
|
|
// these all require DUMP_TRACK:
|
|
|
|
#define DUMP_TOFILE 0x10
|
|
|
|
#define DUMP_SECTOR 0x20
|
|
|
|
#define DUMP_RAWTRACK 0x40
|
|
|
|
#define DUMP_ORDEREDSECTOR 0x80
|
|
|
|
|
|
|
|
|
2019-02-20 12:50:51 +00:00
|
|
|
typedef struct _diskInfo {
|
|
|
|
uint8_t version; // Woz format version #
|
|
|
|
uint8_t diskType; // 1 = 5.25"; 2 = 3.5"
|
|
|
|
uint8_t writeProtected; // 1 = true
|
|
|
|
uint8_t synchronized; // were tracks written with cross-track sync?
|
|
|
|
uint8_t cleaned; // were MC3470 "fake bits" removed?
|
|
|
|
char creator[33]; // 32 chars of creator string and one terminator
|
|
|
|
uint8_t diskSides; // always 1 for a 5.25" disk
|
|
|
|
uint8_t bootSectorFormat; // 0=Unknown; 1=16-sector; 2=13-sector; 3=both
|
|
|
|
uint8_t optimalBitTiming; // 125-nS increments; standard == 32 (4uS)
|
|
|
|
uint16_t compatHardware; // 0=unknown compatability
|
|
|
|
uint16_t requiredRam; // value in K. 0 = unknown
|
|
|
|
uint16_t largestTrack; // # of 512-byte blocks used for largest track
|
|
|
|
} diskInfo;
|
|
|
|
|
|
|
|
typedef struct _trackInfo {
|
|
|
|
uint16_t startingBlock; // v2
|
|
|
|
uint32_t startingByte; // v1
|
|
|
|
uint16_t blockCount;
|
|
|
|
uint32_t bitCount;
|
|
|
|
uint8_t *trackData;
|
|
|
|
} trackInfo;
|
|
|
|
|
|
|
|
class Woz {
|
|
|
|
public:
|
2020-06-27 22:00:59 +00:00
|
|
|
Woz(bool verbose, uint8_t dumpflags);
|
2019-02-20 12:50:51 +00:00
|
|
|
~Woz();
|
|
|
|
|
2019-02-21 03:06:55 +00:00
|
|
|
bool readFile(const char *filename, bool preloadTracks, uint8_t forceType = T_AUTO);
|
2020-06-27 22:00:59 +00:00
|
|
|
bool writeFile(const char *filename, uint8_t forceType = T_AUTO);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
uint8_t getNextWozBit(uint8_t datatrack);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
|
|
|
void dumpInfo();
|
|
|
|
|
|
|
|
bool isSynchronized();
|
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
uint8_t dataTrackNumberForQuarterTrack(uint16_t qt);
|
|
|
|
|
|
|
|
bool flush();
|
|
|
|
|
2020-07-01 02:44:50 +00:00
|
|
|
void debug();
|
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
//protected:
|
|
|
|
// Interface for AiiE
|
|
|
|
bool writeNextWozBit(uint8_t datatrack, uint8_t bit);
|
|
|
|
bool writeNextWozByte(uint8_t datatrack, uint8_t b);
|
|
|
|
uint8_t nextDiskBit(uint8_t datatrack);
|
|
|
|
uint8_t nextDiskByte(uint8_t datatrack);
|
|
|
|
bool skipByte(uint8_t datatrack);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
|
|
|
private:
|
2020-07-01 02:44:50 +00:00
|
|
|
void loadTrackByte(uint8_t datatrack);
|
|
|
|
void advanceBitStream(uint8_t datatrack);
|
|
|
|
|
2019-02-21 03:06:55 +00:00
|
|
|
bool readWozFile(const char *filename, bool preloadTracks);
|
|
|
|
bool readDskFile(const char *filename, bool preloadTracks, uint8_t subtype);
|
|
|
|
bool readNibFile(const char *filename, bool preloadTracks);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
bool decodeWozTrackToNib(uint8_t phystrack, nibSector sectorData[16]);
|
|
|
|
bool decodeWozTrackToDsk(uint8_t phystrack, uint8_t subtype, uint8_t sectorData[256*16]);
|
|
|
|
|
|
|
|
bool writeWozFile(const char *filename, uint8_t subtype);
|
2020-06-28 12:29:05 +00:00
|
|
|
bool writeWozFile(int fd, uint8_t subtype);
|
2020-06-27 22:00:59 +00:00
|
|
|
bool writeDskFile(const char *filename, uint8_t subtype);
|
2020-06-28 12:29:05 +00:00
|
|
|
bool writeDskFile(int fd, uint8_t subtype);
|
2020-06-27 22:00:59 +00:00
|
|
|
bool writeNibFile(const char *filename);
|
2020-06-28 12:29:05 +00:00
|
|
|
bool writeNibFile(int fd);
|
2020-07-01 02:44:50 +00:00
|
|
|
|
|
|
|
bool writeWozTrack(int fd, uint8_t trackToWrite, uint8_t imageType);
|
|
|
|
bool writeDskTrack(int fd, uint8_t trackToWrite, uint8_t imageType);
|
|
|
|
bool writeNibTrack(int fd, uint8_t trackToWrite, uint8_t imageType);
|
2020-06-27 22:00:59 +00:00
|
|
|
|
2019-02-20 12:50:51 +00:00
|
|
|
uint8_t fakeBit();
|
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
bool parseTRKSChunk(uint32_t chunkSize);
|
|
|
|
bool parseTMAPChunk(uint32_t chunkSize);
|
|
|
|
bool parseInfoChunk(uint32_t chunkSize);
|
|
|
|
bool parseMetaChunk(uint32_t chunkSize);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
bool writeInfoChunk(uint8_t version, int fdout);
|
|
|
|
bool writeTMAPChunk(uint8_t version, int fdout);
|
|
|
|
bool writeTRKSChunk(uint8_t version, int fdout);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
bool readWozDataTrack(uint8_t datatrack);
|
|
|
|
bool readNibSectorData(uint8_t phystrack, uint8_t sector, nibSector *sectorData);
|
2019-02-20 12:50:51 +00:00
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
bool loadMissingTrackFromImage(uint8_t datatrack);
|
|
|
|
|
|
|
|
bool checksumWozDataTrack(uint8_t datatrack, uint32_t *retCRC);
|
2019-02-21 03:06:55 +00:00
|
|
|
|
2019-02-20 12:50:51 +00:00
|
|
|
void _initInfo();
|
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
private:
|
2019-02-21 03:06:55 +00:00
|
|
|
uint8_t imageType;
|
2020-06-27 22:00:59 +00:00
|
|
|
|
|
|
|
bool verbose;
|
|
|
|
uint8_t dumpflags;
|
2019-02-21 03:06:55 +00:00
|
|
|
|
2019-02-21 04:10:29 +00:00
|
|
|
bool autoFlushTrackData;
|
2020-07-01 02:44:50 +00:00
|
|
|
int8_t dataTrackDirty; // -1 means "none"
|
2020-06-27 22:00:59 +00:00
|
|
|
|
2019-02-20 12:50:51 +00:00
|
|
|
uint8_t quarterTrackMap[40*4];
|
|
|
|
diskInfo di;
|
|
|
|
trackInfo tracks[160];
|
2020-07-04 12:06:09 +00:00
|
|
|
uint8_t singleCachedTrack[0x1A00];
|
2019-02-20 12:50:51 +00:00
|
|
|
|
|
|
|
// cursor for track enumeration
|
2020-06-28 03:09:43 +00:00
|
|
|
protected:
|
|
|
|
int fd;
|
|
|
|
|
2019-02-20 12:50:51 +00:00
|
|
|
uint32_t trackPointer;
|
2020-07-01 02:44:50 +00:00
|
|
|
uint32_t lastReadPointer;
|
2019-02-22 05:21:05 +00:00
|
|
|
uint32_t trackBitCounter;
|
2019-02-20 12:50:51 +00:00
|
|
|
uint8_t trackByte;
|
|
|
|
uint8_t trackBitIdx;
|
|
|
|
uint8_t trackLoopCounter;
|
2020-06-28 03:09:43 +00:00
|
|
|
private:
|
2019-02-20 12:50:51 +00:00
|
|
|
char *metaData;
|
2019-02-22 05:21:05 +00:00
|
|
|
uint8_t randData, randPtr;
|
2019-02-20 12:50:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|