First Commit of my working state
[simh.git] / AltairZ80 / sim_imd.h
1 /*************************************************************************
2 * *
3 * $Id: sim_imd.h 1904 2008-05-21 06:57:57Z hharte $ *
4 * *
5 * Copyright (c) 2007-2008 Howard M. Harte. *
6 * http://www.hartetec.com *
7 * *
8 * Permission is hereby granted, free of charge, to any person obtaining *
9 * a copy of this software and associated documentation files (the *
10 * "Software"), to deal in the Software without restriction, including *
11 * without limitation the rights to use, copy, modify, merge, publish, *
12 * distribute, sublicense, and/or sell copies of the Software, and to *
13 * permit persons to whom the Software is furnished to do so, subject to *
14 * the following conditions: *
15 * *
16 * The above copyright notice and this permission notice shall be *
17 * included in all copies or substantial portions of the Software. *
18 * *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
22 * NONINFRINGEMENT. IN NO EVENT SHALL HOWARD M. HARTE BE LIABLE FOR ANY *
23 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
26 * *
27 * Except as contained in this notice, the name of Howard M. Harte shall *
28 * not be used in advertising or otherwise to promote the sale, use or *
29 * other dealings in this Software without prior written authorization *
30 * Howard M. Harte. *
31 * *
32 * SIMH Interface based on altairz80_hdsk.c, by Peter Schorn. *
33 * *
34 * Module Description: *
35 * ImageDisk Disk Image File access module for SIMH, definitions. *
36 * see : *
37 * for details on the ImageDisk format and other utilities. *
38 * *
39 * Environment: *
40 * User mode only *
41 * *
42 *************************************************************************/
43
44 typedef struct {
45 unsigned char mode;
46 unsigned char cyl;
47 unsigned char head;
48 unsigned char nsects;
49 unsigned char sectsize;
50 } IMD_HEADER;
51
52
53 #define IMD_FLAG_SECT_HEAD_MAP (1 << 6)
54 #define IMD_FLAG_SECT_CYL_MAP (1 << 7)
55
56 #define SECT_RECORD_UNAVAILABLE 0 /* Data could not be read from the original media */
57 #define SECT_RECORD_NORM 1 /* Normal Data */
58 #define SECT_RECORD_NORM_COMP 2 /* Compressed Normal Data */
59 #define SECT_RECORD_NORM_DAM 3 /* Normal Data with deleted address mark */
60 #define SECT_RECORD_NORM_DAM_COMP 4 /* Compressed Normal Data with deleted address mark */
61 #define SECT_RECORD_NORM_ERR 5 /* Normal Data */
62 #define SECT_RECORD_NORM_COMP_ERR 6 /* Compressed Normal Data */
63 #define SECT_RECORD_NORM_DAM_ERR 7 /* Normal Data with deleted address mark */
64 #define SECT_RECORD_NORM_DAM_COMP_ERR 8 /* Compressed Normal Data with deleted address mark */
65
66 #define MAX_CYL 80
67 #define MAX_HEAD 2
68 #define MAX_SPT 26
69
70 #define FD_FLAG_WRITELOCK 1
71
72 #define IMD_DISK_IO_ERROR_GENERAL (1 << 0) /* General data error. */
73 #define IMD_DISK_IO_ERROR_CRC (1 << 1) /* Data read/written, but got a CRC error. */
74 #define IMD_DISK_IO_DELETED_ADDR_MARK (1 << 2) /* Sector had a deleted address mark */
75 #define IMD_DISK_IO_COMPRESSED (1 << 3) /* Sector is compressed in the IMD file (Read Only) */
76
77 #define IMD_MODE_500K_FM 0
78 #define IMD_MODE_300K_FM 1
79 #define IMD_MODE_250K_FM 2
80 #define IMD_MODE_500K_MFM 3
81 #define IMD_MODE_300K_MFM 4
82 #define IMD_MODE_250K_MFM 5
83
84 #define IMD_MODE_FM(x) (x <= IMD_MODE_250K_FM)
85 #define IMD_MODE_MFM(x) (x >= IMD_MODE_500K_MFM)
86
87 typedef struct {
88 unsigned char mode;
89 unsigned char nsects;
90 unsigned int sectsize;
91 unsigned int sectorOffsetMap[MAX_SPT];
92 unsigned char start_sector;
93 } TRACK_INFO;
94
95 typedef struct {
96 FILE *file;
97 unsigned int ntracks;
98 unsigned char nsides;
99 unsigned char flags;
100 TRACK_INFO track[MAX_CYL][MAX_HEAD];
101 } DISK_INFO;
102
103 extern DISK_INFO *diskOpen(FILE *fileref, int isVerbose); /*char *filename); */
104 extern unsigned int diskClose(DISK_INFO *myDisk);
105 extern unsigned int imdGetSides(DISK_INFO *myDisk);
106 extern unsigned int imdIsWriteLocked(DISK_INFO *myDisk);
107
108 extern int sectSeek(DISK_INFO *myDisk, unsigned int Cyl, unsigned int Head);
109 extern int sectRead(DISK_INFO *myDisk, unsigned int Cyl, unsigned int Head, unsigned int Sector, unsigned char *buf, unsigned int buflen, unsigned int *flags, unsigned int *readlen);
110 extern int sectWrite(DISK_INFO *myDisk, unsigned int Cyl, unsigned int Head, unsigned int Sector, unsigned char *buf, unsigned int buflen, unsigned int *flags, unsigned int *writelen);