]> Shamusworld >> Repos - apple2/blob - src/floppy.h
7fe310f2a4951bc5d01f34990d8a37907bb8c701
[apple2] / src / floppy.h
1 //
2 // Apple 2 floppy disk support
3 //
4
5 #ifndef __FLOPPY_H__
6 #define __FLOPPY_H__
7
8 // MAX_PATH isn't defined in stdlib.h on *nix, so we do it here...
9 #ifdef __GCCUNIX__
10 #include <limits.h>
11 #define MAX_PATH                _POSIX_PATH_MAX
12 #else
13 #include <stdlib.h>                                                             // for MAX_PATH on MinGW/Darwin
14 #endif
15 #include "types.h"
16
17 enum { DT_UNKNOWN, DT_DOS33, DT_PRODOS, DT_NYBBLE };
18
19 class FloppyDrive
20 {
21         public:
22                 FloppyDrive();
23                 ~FloppyDrive();
24
25                 bool LoadImage(const char * filename, uint8 driveNum = 0);
26                 bool SaveImage(uint8 driveNum = 0);
27                 bool SaveImageAs(const char * filename, uint8 driveNum = 0);
28                 void CreateBlankImage(uint8 driveNum = 0);
29                 void SwapImages(void);
30                 const char * GetImageName(uint8 driveNum = 0);
31                 void EjectImage(uint8 driveNum = 0);
32                 bool DriveIsEmpty(uint8 driveNum = 0);
33
34                 // I/O functions ($C0Ex accesses)
35
36                 void ControlStepper(uint8 addr);
37                 void ControlMotor(uint8 addr);
38                 void DriveEnable(uint8 addr);
39                 uint8 ReadWrite(void);
40                 uint8 GetLatchValue(void);
41                 void SetLatchValue(uint8 value);
42                 void SetReadMode(void);
43                 void SetWriteMode(void);
44
45         protected:
46                 void DetectImageType(const char * filename, uint8 driveNum);
47                 void NybblizeImage(uint8 driveNum);
48                 void DenybblizeImage(uint8 driveNum);
49
50         private:
51                 char imageName[2][MAX_PATH];
52                 uint8 * disk[2];
53                 uint32 diskSize[2];
54                 uint8 diskType[2];
55                 bool imageDirty[2];
56                 uint8 motorOn;
57                 uint8 activeDrive;
58                 uint8 ioMode;
59                 uint8 latchValue;
60                 uint8 phase;
61                 uint8 track;
62
63                 uint8 nybblizedImage[2][232960];
64                 uint32 currentPos;
65
66                 // And here are some private class variables (to reduce function redundancy):
67                 static uint8 header[21];
68                 static uint8 doSector[16];
69                 static uint8 poSector[16];
70                 static char nameBuf[MAX_PATH];
71 };
72
73 #endif  // __FLOPPY_H__