1 #ifndef CAPS_CAPSIMAGE_H
2 #define CAPS_CAPSIMAGE_H
3 
4 #ifdef __AMIGA__
5 #include <exec/types.h>
6 typedef UBYTE CapsUByte;
7 typedef LONG  CapsLong;
8 typedef ULONG CapsULong;
9 #else
10 #include <stdint.h>
11 typedef uint8_t  CapsUByte;
12 typedef int32_t  CapsLong;
13 typedef uint32_t CapsULong;
14 #endif // __AMIGA__
15 
16 #define CAPS_FILEEXT "ipf"
17 #define CAPS_FILEPFX ".ipf"
18 #define CAPS_NAME "capsimage.device"
19 
20 #define CAPS_UNITS 10
21 
22 // Flags provided for locking, in order:
23 // 0: re-align data as index synced recording
24 // 1: decode track to word aligned size
25 // 2: generate cell density for variable density tracks
26 // 3: generate density for automatically sized cells
27 // 4: generate density for unformatted cells
28 // 5: generate unformatted data
29 // 6: generate unformatted data, that changes each revolution
30 // 7: directly use source memory buffer supplied with LockImageMemory
31 // 8: flakey data is created on one revolution, updated with each lock
32 // 9: ...Info.type holds the expected structure type
33 #define DI_LOCK_INDEX    (1L<<0)
34 #define DI_LOCK_ALIGN    (1L<<1)
35 #define DI_LOCK_DENVAR   (1L<<2)
36 #define DI_LOCK_DENAUTO  (1L<<3)
37 #define DI_LOCK_DENNOISE (1L<<4)
38 #define DI_LOCK_NOISE    (1L<<5)
39 #define DI_LOCK_NOISEREV (1L<<6)
40 #define DI_LOCK_MEMREF   (1L<<7)
41 #define DI_LOCK_UPDATEFD (1L<<8)
42 #define DI_LOCK_TYPE     (1L<<9)
43 
44 #define CAPS_MAXPLATFORM 4
45 #define CAPS_MTRS 5
46 
47 #define CTIT_FLAG_FLAKEY (1L<<31)
48 #define CTIT_MASK_TYPE 0xff
49 
50 #if defined(__GNUC__) && !defined(__mc68000__)
51 #pragma pack(1)
52 #endif // __GNUC__
53 
54 // decoded caps date.time
55 struct CapsDateTimeExt {
56 	CapsULong year;
57 	CapsULong month;
58 	CapsULong day;
59 	CapsULong hour;
60 	CapsULong min;
61 	CapsULong sec;
62 	CapsULong tick;
63 };
64 
65 // library version information block
66 struct CapsVersionInfo {
67 	CapsULong type;     // library type
68 	CapsULong release;  // release ID
69 	CapsULong revision; // revision ID
70 	CapsULong flag;     // supported flags
71 };
72 
73 // disk image information block
74 struct CapsImageInfo {
75 	CapsULong type;        // image type
76 	CapsULong release;     // release ID
77 	CapsULong revision;    // release revision ID
78 	CapsULong mincylinder; // lowest cylinder number
79 	CapsULong maxcylinder; // highest cylinder number
80 	CapsULong minhead;     // lowest head number
81 	CapsULong maxhead;     // highest head number
82 	struct CapsDateTimeExt crdt; // image creation date.time
83 	CapsULong platform[CAPS_MAXPLATFORM]; // intended platform(s)
84 };
85 
86 // disk track information block
87 struct CapsTrackInfo {
88 	CapsULong type;       // track type
89 	CapsULong cylinder;   // cylinder#
90 	CapsULong head;       // head#
91 	CapsULong sectorcnt;  // available sectors
92 	CapsULong sectorsize; // sector size
93 	CapsULong trackcnt;   // track variant count
94 	CapsUByte *trackbuf;  // track buffer memory
95 	CapsULong tracklen;   // track buffer memory length
96 	CapsUByte *trackdata[CAPS_MTRS]; // track data pointer if available
97 	CapsULong tracksize[CAPS_MTRS]; // track data size
98 	CapsULong timelen;    // timing buffer length
99 	CapsULong *timebuf;   // timing buffer
100 };
101 
102 // disk track information block
103 struct CapsTrackInfoT1 {
104 	CapsULong type;       // track type
105 	CapsULong cylinder;   // cylinder#
106 	CapsULong head;       // head#
107 	CapsULong sectorcnt;  // available sectors
108 	CapsULong sectorsize; // sector size
109 	CapsUByte *trackbuf;  // track buffer memory
110 	CapsULong tracklen;   // track buffer memory length
111 	CapsULong timelen;    // timing buffer length
112 	CapsULong *timebuf;   // timing buffer
113 	CapsULong overlap;    // overlap position
114 };
115 
116 #if defined(__GNUC__) && !defined(__mc68000__)
117 #pragma pack()
118 #endif // __GNUC__
119 
120 // image type
121 enum {
122 	ciitNA=0, // invalid image type
123 	ciitFDD   // floppy disk
124 };
125 
126 // platform IDs, not about configuration, but intended use
127 enum {
128 	ciipNA=0,    // invalid platform (dummy entry)
129 	ciipAmiga,   // Amiga
130 	ciipAtariST, // Atari ST
131 	ciipPC       // PC
132 };
133 
134 // track type
135 enum {
136 	ctitNA=0,  // invalid type
137 	ctitNoise, // cells are unformatted (random size)
138 	ctitAuto,  // automatic cell size, according to track size
139 	ctitVar    // variable density
140 };
141 
142 // image error status
143 enum {
144 	imgeOk,
145 	imgeUnsupported,
146 	imgeGeneric,
147 	imgeOutOfRange,
148 	imgeReadOnly,
149 	imgeOpen,
150 	imgeType,
151 	imgeShort,
152 	imgeTrackHeader,
153 	imgeTrackStream,
154 	imgeTrackData,
155 	imgeDensityHeader,
156 	imgeDensityStream,
157 	imgeDensityData,
158 	imgeIncompatible,
159 	imgeUnsupportedType
160 };
161 
162 #ifndef CLIB_CAPSIMAGE_PROTOS_H
163 
164 #ifdef __cplusplus
165 extern "C" {
166 #endif // __cplusplus
167 
168 CapsLong CAPSInit(void);
169 CapsLong CAPSExit(void);
170 CapsLong CAPSAddImage(void);
171 CapsLong CAPSRemImage(CapsLong id);
172 CapsLong CAPSLockImage(CapsLong id, char *name);
173 CapsLong CAPSLockImageMemory(CapsLong id, CapsUByte *buffer, CapsULong length, CapsULong flag);
174 CapsLong CAPSUnlockImage(CapsLong id);
175 CapsLong CAPSLoadImage(CapsLong id, CapsULong flag);
176 CapsLong CAPSGetImageInfo(struct CapsImageInfo *pi, CapsLong id);
177 CapsLong CAPSLockTrack(struct CapsTrackInfo *pi, CapsLong id, CapsULong cylinder, CapsULong head, CapsULong flag);
178 CapsLong CAPSUnlockTrack(CapsLong id, CapsULong cylinder, CapsULong head);
179 CapsLong CAPSUnlockAllTracks(CapsLong id);
180 char *CAPSGetPlatformName(CapsULong pid);
181 CapsLong CAPSGetVersionInfo(struct CapsVersionInfo *pi, CapsULong flag);
182 
183 #ifdef __cplusplus
184 }
185 #endif // __cplusplus
186 
187 #endif // CLIB_CAPSIMAGE_PROTOS_H
188 
189 #endif // CAPS_CAPSIMAGE_H
190