2007-05-29 03:06:33 +00:00
|
|
|
//
|
|
|
|
// Apple 2 floppy disk support
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef __FLOPPY_H__
|
|
|
|
#define __FLOPPY_H__
|
|
|
|
|
|
|
|
// MAX_PATH isn't defined in stdlib.h on *nix, so we do it here...
|
|
|
|
#ifdef __GCCUNIX__
|
|
|
|
#include <limits.h>
|
|
|
|
#define MAX_PATH _POSIX_PATH_MAX
|
|
|
|
#else
|
|
|
|
#include <stdlib.h> // for MAX_PATH on MinGW/Darwin
|
|
|
|
#endif
|
2013-09-09 02:18:23 +00:00
|
|
|
#include <stdint.h>
|
2007-05-29 03:06:33 +00:00
|
|
|
|
2014-03-30 18:07:30 +00:00
|
|
|
enum { DFT_UNKNOWN, DT_DOS33, DT_DOS33_HDR, DT_PRODOS, DT_NYBBLE };
|
2013-10-12 03:13:08 +00:00
|
|
|
enum { DLS_OFF, DLS_READ, DLS_WRITE };
|
2007-05-29 03:06:33 +00:00
|
|
|
|
|
|
|
class FloppyDrive
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FloppyDrive();
|
|
|
|
~FloppyDrive();
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
bool LoadImage(const char * filename, uint8_t driveNum = 0);
|
|
|
|
bool SaveImage(uint8_t driveNum = 0);
|
|
|
|
bool SaveImageAs(const char * filename, uint8_t driveNum = 0);
|
|
|
|
void CreateBlankImage(uint8_t driveNum = 0);
|
2007-05-29 03:06:33 +00:00
|
|
|
void SwapImages(void);
|
2013-10-13 20:22:19 +00:00
|
|
|
const char * ImageName(uint8_t driveNum = 0);
|
2013-09-09 02:18:23 +00:00
|
|
|
void EjectImage(uint8_t driveNum = 0);
|
2013-10-13 20:22:19 +00:00
|
|
|
bool IsEmpty(uint8_t driveNum = 0);
|
|
|
|
bool IsWriteProtected(uint8_t driveNum = 0);
|
2013-09-09 02:18:23 +00:00
|
|
|
void SetWriteProtect(bool, uint8_t driveNum = 0);
|
2013-10-12 03:13:08 +00:00
|
|
|
int DriveLightStatus(uint8_t driveNum = 0);
|
2007-05-29 03:06:33 +00:00
|
|
|
|
|
|
|
// I/O functions ($C0Ex accesses)
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
void ControlStepper(uint8_t addr);
|
|
|
|
void ControlMotor(uint8_t addr);
|
|
|
|
void DriveEnable(uint8_t addr);
|
|
|
|
uint8_t ReadWrite(void);
|
|
|
|
uint8_t GetLatchValue(void);
|
|
|
|
void SetLatchValue(uint8_t value);
|
2007-05-29 03:06:33 +00:00
|
|
|
void SetReadMode(void);
|
|
|
|
void SetWriteMode(void);
|
|
|
|
|
|
|
|
protected:
|
2013-09-09 02:18:23 +00:00
|
|
|
void DetectImageType(const char * filename, uint8_t driveNum);
|
|
|
|
void NybblizeImage(uint8_t driveNum);
|
|
|
|
void DenybblizeImage(uint8_t driveNum);
|
2007-05-29 03:06:33 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
char imageName[2][MAX_PATH];
|
2013-09-09 02:18:23 +00:00
|
|
|
uint8_t * disk[2];
|
|
|
|
uint32_t diskSize[2];
|
|
|
|
uint8_t diskType[2];
|
2007-05-29 03:06:33 +00:00
|
|
|
bool imageDirty[2];
|
2009-02-04 14:19:00 +00:00
|
|
|
bool writeProtected[2];
|
2013-09-09 02:18:23 +00:00
|
|
|
uint8_t motorOn;
|
|
|
|
uint8_t activeDrive;
|
|
|
|
uint8_t ioMode;
|
|
|
|
uint8_t latchValue;
|
|
|
|
uint8_t phase;
|
|
|
|
uint8_t track;
|
2013-10-12 03:13:08 +00:00
|
|
|
bool ioHappened;
|
2007-05-29 03:06:33 +00:00
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
uint8_t nybblizedImage[2][232960];
|
|
|
|
uint32_t currentPos;
|
2007-05-29 03:06:33 +00:00
|
|
|
|
|
|
|
// And here are some private class variables (to reduce function redundancy):
|
2013-09-09 02:18:23 +00:00
|
|
|
static uint8_t header[21];
|
|
|
|
static uint8_t doSector[16];
|
|
|
|
static uint8_t poSector[16];
|
2009-02-02 15:25:25 +00:00
|
|
|
static char nameBuf[MAX_PATH];
|
2007-05-29 03:06:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __FLOPPY_H__
|