HP85 GPIB Disk Emulator  1.0
HP85GPIBDiskEmulator
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
td02lif.h
Go to the documentation of this file.
1 
41 #ifndef _TD02LIF_H_
42 #define _TD02LIF_H_
43 
45 #define TD_HEADER_SIZE 12
46 #define TD_COMMENT_SIZE 10
48 #define TD_TRACK_SIZE 4
50 #define TD_SECTOR_SIZE 6
52 
55 #define MAXSECTORS 255
56 
59 #define MAXSIDES 2
60 
62 #define MAXCYL 255
63 
64 #define MAXTRACKS (MAXCYL * MAXSIDES)
65 
66 typedef struct tm tm_t;
67 extern int debuglevel;
68 
70 enum
71 {
74 };
75 
77 enum
78 {
86 };
87 
89 typedef struct
90 {
91  uint8_t Header[2+1]; // Teledisk header + room for EOS
92  uint8_t VolNO; // Volume sequence number
93  uint8_t ChkSig; // Check signature
94 // Used only for multi volume support
95 // All volumes must have the same value
96  uint8_t TDVersion; // Teledisk version, (11 = v1.1)
97  uint8_t Density; // Source disk density
98 // 0 = 250K
99 // 1 = 300K
100 // 2 = 500K
101 // 128 = single-density FM)
102  uint8_t DriveType; // Source drive type
103 // 1 = 360K
104 // 2 = 1.2M
105 // 3 = 720K
106 // 4 = 1.44M
107  uint8_t TrackDensity; // Track Density with respect to source density
108 // 0 = single sensity
109 // 1 = double density
110 // 2 = quad density)
111 // If bit 7 is set we have a comment block
112  uint8_t DosMode; // DOS allocation information used ?
113 // !0 teledisk used DOS allocation info
114 // When creating image
115  uint8_t Sides; // Disk sides stored in the image
116  uint16_t CRC; // 16-bit CRC for this header
117 } td_header_t;
118 
121 typedef struct
122 {
123  uint16_t CRC; // Comment block CRC
124  uint16_t Size; // Comment Length
125  uint8_t Year; // Year -1900 offset
126  uint8_t Month; // Month 0..11
127  uint8_t Day; // Day 1..31
128  uint8_t Hour; // Hour 0..23
129  uint8_t Minute; // Minute 0..59
130  uint8_t Second; // Second 0..59
131 } td_comment_t;
132 
136 typedef struct
137 {
138  uint8_t PSectors; // Physical sectors in this track
139 // 0xff implies end of TeleDisk image
140  uint8_t PCyl; // Physical (device) track
141  uint8_t PSide; // PSide & 0x7f = Physical (device) side
142 // PSide & 0x80 = IBM format density
143 // 0x00 = IBM Double Desnity
144 // 0x80 = IBM Single Sensity
145  uint8_t CRC; // LSB of first 3 bytes of track header CRC16
146 } td_track_t;
147 
151 typedef struct
152 {
153  uint8_t Cyl; // Logical Track number
154  uint8_t Side; // Logical Side
155  uint8_t Sector; // Logical Sector number
156  uint8_t SizeExp; // Size = 2 ** Slen
157 // We support 0=128,1=256,2=512,4=1024
158  uint8_t Flags; // Sector bit flags
159 // 0x01 = Unsupported ?
160 // 0x02 = Unsupported use alternate crc
161 // 0x04 = Unsupported use altrenate data CRC
162 // 0x08 = Unsupported ?
163 // 0x10 = Unsupported ?
164 // 0x20 = Unsuported missing data address mark
165 // 0x40 = Unsupported ?
166 // 0x80 = Unsupported ?
167  uint8_t CRC; // LSB of sector data CRC16
168 } td_sector_t;
169 
192 
193 typedef struct
194 {
195  int cylinder; // Sectory ID Cylinder
196  int side; // Sector ID Side
197  int sector; // Sector ID Sector Number
198  int size; // Sector ID Sector Size converted to Bytes
199  uint8_t *data; // Sector Data
200 } sector_t;
201 
202 typedef struct
203 {
204  int Cyl; // From TeleDisk Track Header Cylinder Number
205  int Side; // From TeleDisk Track Header Side Number
206  int Sectors; // TeleDisk count of Sectors on this track
207  int First;
208  int Last;
209  int Size; // Size of first sector
210  sector_t sectors[MAXSECTORS]; // Disk Sectors
211 } track_t;
212 
213 typedef struct
214 {
215  FILE *fi; // TeleDisk image file handle
216  char *td0_name; // TeleDisk file name
217  int compressed; // TeleDIsk Image is compressed
218  time_t t; // LIF image date in epoch format
219  td_header_t td_header; // TeleDisk Header
220  td_comment_t td_comment; // Comment Header
221  uint8_t *comment; // Optional comment string if td_comment.Size != 0
222  track_t track[MAXTRACKS]; // Track and Sector Data
223 } disk_t;
224 
228 typedef struct
229 {
230 // TD0 to LIF stae information
231  int error; // TD0 to LIF error state
232  int state; // TD0 to LIF process state machine
233  long sectorindex; // Sector index reading LIF image inside TeleDisk image
234  long writeindex; // Sector offset writting LIF image
235 
237  int Sectors; // LIF image Sectors
238  int Size; // LIF image Sector Size
239  int Tracks; // LIF image Tracks
240  int Sides; // LIF image Sides
241  int Cylinders; // LIF image Cylinders
242 
247  struct
248  {
249  int first[2]; // First - lowest sector number found in 30 tracks on each side
250  int size[2]; // Size - of First Sector on each side
251  int last[2]; // Last - highest sector number found (<100) in 30 tracks on each side
252  int sectors[2]; // Sectors - maximum number of sectors found per track in 30 tracks matching Size on each side
253  } s;
254 
282  struct
283  {
284  int size; // User size override, ONLY use this option if sector with the LOWEST number is does NOT have default SIZE
285  int sides; // User sides overrride, you can specify LESS then found but not MORE then analise pass
286  int tracks; // user Tracks override
287  } u;
288 } liftel_t;
289 
290 extern liftel_t liftel;
291 
292 /* td02lif.c */
293 void td0_B2S ( uint8_t *B , int index , uint8_t *name , int size );
294 uint16_t td0_crc16 ( uint8_t *B , uint16_t crc , uint16_t poly , int size );
295 void td0_hexdump ( uint8_t *data , int size );
296 int td0_unpack_disk_header ( uint8_t *B , td_header_t *p );
297 int td0_unpack_comment_header ( uint8_t *B , td_comment_t *p );
298 int td0_unpack_track_header ( uint8_t *B , td_track_t *p );
299 int td0_unpack_sector_header ( uint8_t *B , td_sector_t *p );
300 void td0_compressed ( int flag );
301 int td0_read ( void *p , int osize , int size , FILE *fp );
302 int td0_rle ( uint8_t *dst , uint8_t *src , int max );
303 void td0_trackinfo ( disk_t *disk , int trackind , int index );
304 void td0_sectorinfo ( td_sector_t *P );
305 long td0_density2bitrate ( uint8_t density );
306 int td0_open ( disk_t *disk , char *name );
307 int td0_read_disk ( disk_t *disk );
309 int td0_save_lif ( disk_t *disk , lif_t *LIF );
310 int td0_save_lif_sector ( disk_t *disk , uint8_t *data , int size , lif_t *LIF );
311 void td0_help ( int full );
312 void td0_init_liftel ( void );
313 void td0_init_sectors ( disk_t *disk );
314 int td02lif ( int argc , char *argv []);
315 #endif
liftel_t::state
int state
Definition: td02lif.h:232
td_track_t::CRC
uint8_t CRC
Definition: td02lif.h:145
track_t::First
int First
Definition: td02lif.h:207
td0_open
int td0_open(disk_t *disk, char *name)
Opne TeleDisk image file process header and optional comment block.
Definition: td02lif.c:506
disk_t::compressed
int compressed
Definition: td02lif.h:217
sector_t::cylinder
int cylinder
Definition: td02lif.h:195
td_comment_t
Comment header Only used when bit 7 of TrackDensity in TeleDisk Header is set.
Definition: td02lif.h:121
td0_help
void td0_help(int full)
Definition: td02lif.c:1556
td0_init_sectors
void td0_init_sectors(disk_t *disk)
Initialize track sector information Optionally decompress the data if decompression is enabled.
Definition: td02lif.c:1614
disk_t::comment
uint8_t * comment
Definition: td02lif.h:221
IBMFORMAT_SD
@ IBMFORMAT_SD
Definition: td02lif.h:72
td0_crc16
uint16_t td0_crc16(uint8_t *B, uint16_t crc, uint16_t poly, int size)
Compute CRC16 of 8bit data.
Definition: td02lif.c:87
disk_t::td_comment
td_comment_t td_comment
Definition: td02lif.h:220
lif_t
Master LIF data structure Contains image file name Volume Structure Current Directory Entry read/writ...
Definition: lifutils.h:114
td_track_t::PCyl
uint8_t PCyl
Definition: td02lif.h:140
liftel_t::Size
int Size
Definition: td02lif.h:238
TD0_DONE
@ TD0_DONE
Definition: td02lif.h:85
MAXTRACKS
#define MAXTRACKS
Definition: td02lif.h:64
sector_t::side
int side
Definition: td02lif.h:196
td_header_t::CRC
uint16_t CRC
Definition: td02lif.h:116
td_comment_t::Minute
uint8_t Minute
Definition: td02lif.h:129
td0_unpack_track_header
int td0_unpack_track_header(uint8_t *B, td_track_t *p)
Extract TeleDisk track header data in architecture nutral way.
Definition: td02lif.c:201
dst
dst_t dst
DST start and stop in GMT epoch.
Definition: time.c:52
sector_t
Sector information and Sector "ID".
Definition: td02lif.h:193
td_header_t::DosMode
uint8_t DosMode
Definition: td02lif.h:112
track_t::Size
int Size
Definition: td02lif.h:209
TD0_DIRECTORY
@ TD0_DIRECTORY
Definition: td02lif.h:82
TD0_WAIT_DIRECTORY
@ TD0_WAIT_DIRECTORY
Definition: td02lif.h:81
td_sector_t::Cyl
uint8_t Cyl
Definition: td02lif.h:153
td_comment_t::Year
uint8_t Year
Definition: td02lif.h:125
liftel
liftel_t liftel
Teledisk liftel analysis and user overrides.
Definition: td02lif.c:60
td_track_t::PSide
uint8_t PSide
Definition: td02lif.h:141
td_header_t::DriveType
uint8_t DriveType
Definition: td02lif.h:102
td_comment_t::CRC
uint16_t CRC
Definition: td02lif.h:123
td_sector_t::SizeExp
uint8_t SizeExp
Definition: td02lif.h:156
disk_t::t
time_t t
Definition: td02lif.h:218
MAXSECTORS
#define MAXSECTORS
Maximum number of sectors per track Used for sector data and sorting tables.
Definition: td02lif.h:55
td0_unpack_disk_header
int td0_unpack_disk_header(uint8_t *B, td_header_t *p)
Extract TeleDisk image header data in architecture nutral way.
Definition: td02lif.c:151
disk
disk_t disk
Dave Dunfiled LZSS expander.
Definition: td02lif.c:57
td_sector_t::Side
uint8_t Side
Definition: td02lif.h:154
td_header_t::TrackDensity
uint8_t TrackDensity
Definition: td02lif.h:107
track_t::Cyl
int Cyl
Definition: td02lif.h:204
td0_sectorinfo
void td0_sectorinfo(td_sector_t *P)
Display TeleDisk sector data.
Definition: td02lif.c:458
td_header_t
TeleDisk Image Header.
Definition: td02lif.h:89
sector_t::sector
int sector
Definition: td02lif.h:197
liftel_t
Master TeleDisk Format Analisis structure We look for the specifications of LIF image stored inside t...
Definition: td02lif.h:228
sector_t::size
int size
Definition: td02lif.h:198
td0_rle
int td0_rle(uint8_t *dst, uint8_t *src, int max)
Expand a Run Length encoded TeleDisk sector Notes: the source length is encoded in the source data Cr...
Definition: td02lif.c:307
__file
FILE type structure.
Definition: posix.h:158
td_comment_t::Month
uint8_t Month
Definition: td02lif.h:126
td02lif
int td02lif(int argc, char *argv[])
Convert a Teledisk LIF formatted disk image into a pure LIF image.
Definition: td02lif.c:1650
disk_t::fi
FILE * fi
Definition: td02lif.h:215
liftel_t::Sectors
int Sectors
Parameters of LIf image inside TeleDisk image - AFTER analysis.
Definition: td02lif.h:237
td0_density2bitrate
long td0_density2bitrate(uint8_t density)
Convert Denisity to bitrate @We don't care about the density except as a possible filter.
Definition: td02lif.c:472
IBMFORMAT_DD
@ IBMFORMAT_DD
Definition: td02lif.h:73
disk_t::td_header
td_header_t td_header
Definition: td02lif.h:219
track_t::Sectors
int Sectors
Definition: td02lif.h:206
disk_t::td0_name
char * td0_name
Definition: td02lif.h:216
TD0_WAIT_FILE
@ TD0_WAIT_FILE
Definition: td02lif.h:83
TD0_START
@ TD0_START
Definition: td02lif.h:80
liftel_t::tracks
int tracks
Definition: td02lif.h:286
td0_hexdump
void td0_hexdump(uint8_t *data, int size)
hex listing of data
Definition: td02lif.c:110
td0_B2S
void td0_B2S(uint8_t *B, int index, uint8_t *name, int size)
Create a string from data that has no EOS but known size.
Definition: td02lif.c:68
td0_read
int td0_read(void *p, int osize, int size, FILE *fp)
Read TeleDisk image data block Optionally decompress the data if decompression is enabled.
Definition: td02lif.c:264
td_comment_t::Second
uint8_t Second
Definition: td02lif.h:130
td_header_t::Sides
uint8_t Sides
Definition: td02lif.h:115
td0_unpack_comment_header
int td0_unpack_comment_header(uint8_t *B, td_comment_t *p)
Extract TeleDisk comment header data in architecture nutral way.
Definition: td02lif.c:178
track_t
Definition: td02lif.h:202
td_comment_t::Size
uint16_t Size
Definition: td02lif.h:124
td0_analize_format
int td0_analize_format(disk_t *disk)
Analize TeleDisk disk sector data Problem: We may have a disk that was reformatted multiple times Eac...
Definition: td02lif.c:896
liftel_t::Sides
int Sides
Definition: td02lif.h:240
TD0_FILE
@ TD0_FILE
Definition: td02lif.h:84
td0_save_lif
int td0_save_lif(disk_t *disk, lif_t *LIF)
save remaining sectors as LIF data
Definition: td02lif.c:1303
td_sector_t::Sector
uint8_t Sector
Definition: td02lif.h:155
td0_compressed
void td0_compressed(int flag)
Enable TeleDisk image compression mode.
Definition: td02lif.c:250
td_header_t::ChkSig
uint8_t ChkSig
Definition: td02lif.h:93
td_comment_t::Day
uint8_t Day
Definition: td02lif.h:127
track_t::Side
int Side
Definition: td02lif.h:205
debuglevel
int debuglevel
Debug flag - used to log GPIB and emulator messages.
Definition: gpib_task.c:33
td_comment_t::Hour
uint8_t Hour
Definition: td02lif.h:128
liftel_t::sides
int sides
Definition: td02lif.h:285
track_t::Last
int Last
Definition: td02lif.h:208
td0_init_liftel
void td0_init_liftel(void)
TeleDisk image Analisis structure Find attributes of LIF image stored in TeleDisk image.
Definition: td02lif.c:1577
td0_trackinfo
void td0_trackinfo(disk_t *disk, int trackind, int index)
Display TeleDisk track sector values.
Definition: td02lif.c:443
tm
POSIX struct tm.
Definition: time.h:40
td_track_t
Track Header Contains the Physical Sectors, Cylinder, Side number From the original physical disk use...
Definition: td02lif.h:136
time_t
uint32_t time_t
type of EPOCH result.
Definition: time.h:34
liftel_t::Cylinders
int Cylinders
Definition: td02lif.h:241
td0_read_disk
int td0_read_disk(disk_t *disk)
Read TeleDisk image file and save all sector data.
Definition: td02lif.c:643
td_sector_t::Flags
uint8_t Flags
Definition: td02lif.h:158
disk_t
Definition: td02lif.h:213
liftel_t::sectorindex
long sectorindex
Definition: td02lif.h:233
td_header_t::VolNO
uint8_t VolNO
Definition: td02lif.h:92
td0_unpack_sector_header
int td0_unpack_sector_header(uint8_t *B, td_sector_t *p)
Extract TeleDisk sector header data in architecture nutral way.
Definition: td02lif.c:232
td0_save_lif_sector
int td0_save_lif_sector(disk_t *disk, uint8_t *data, int size, lif_t *LIF)
Process all sectors on a track from TeleDisk image.
Definition: td02lif.c:1366
liftel_t::error
int error
Definition: td02lif.h:231
sector_t::data
uint8_t * data
Definition: td02lif.h:199
td_track_t::PSectors
uint8_t PSectors
Definition: td02lif.h:138
TD0_INIT
@ TD0_INIT
Definition: td02lif.h:79
td_header_t::TDVersion
uint8_t TDVersion
Definition: td02lif.h:96
td_sector_t::CRC
uint8_t CRC
Definition: td02lif.h:167
liftel_t::writeindex
long writeindex
Definition: td02lif.h:234
td_sector_t
Sector Header Contents of the Sector ID fields which preceeded the sector data From the original phys...
Definition: td02lif.h:151
liftel_t::Tracks
int Tracks
Definition: td02lif.h:239
td_header_t::Density
uint8_t Density
Definition: td02lif.h:97