1 /* 2 * ZX Interface 1 and Microdrive low level support 3 * 4 * Stefano Bodrato - 6/9/2004 5 * 6 * $Id: zxinterface1.h $ 7 */ 8 9 10 #ifndef __ZXINTERFACE1_H__ 11 #define __ZXINTERFACE1_H__ 12 13 #include <sys/compiler.h> 14 #include <sys/types.h> 15 #include <fcntl.h> 16 17 18 #ifndef __ZX_CHANNELS__ 19 #define __ZX_CHANNELS__ 20 21 struct BASE_CHAN { 22 // base channel descriptor 23 u16_t errptr1; /* first pointer to main ERROR-1 */ 24 u16_t errptr2; /* second pointer to main ERROR-1 */ 25 u8_t id_char; /* inverted or regular "M"/"N" char */ 26 u16_t out; /* pointer to the output routine */ 27 u16_t in; /* pointer to the input routine */ 28 u16_t len; /* length of channel */ 29 }; 30 31 // M_CHAN is 603 bytes long 32 struct M_CHAN { 33 // base channel descriptor 34 struct BASE_CHAN base; 35 // "M" channel specific stuff 36 u16_t bytecount; /* (IX+$0B) Count bytes in record */ 37 u8_t record; 38 char name[10]; /* file name */ 39 u8_t flag; 40 u8_t drive; /* drive number (0-7)*/ 41 u16_t map; /* Address of MAP for this microdrive.*/ 42 char hdpreamble[12]; /* 12 bytes of header preamble */ 43 u8_t hdflag; 44 u8_t sector; /* sector number */ 45 u16_t unused; 46 char hdname[10]; /* cartridge name */ 47 u8_t hdchk; /* Header checksum */ 48 char dpreamble[12]; /* 12 bytes of data block preamble */ 49 u8_t recflg; /* bit 1 set for EOF, bit 2 set for PRINT file type */ 50 u8_t recnum; /* Record number in the range 0-255 */ 51 u16_t reclen; /* (IX+$45) Number of databytes in record 0-512 */ 52 char recname[10]; /* file name */ 53 u8_t recchk; /* Record description checksum */ 54 char data[512]; /* the 512 bytes of data. */ 55 //char datahd[10]; /* first 9 bytes of the 512 bytes of data. */ 56 //char data[502] /* real program */ 57 u8_t datachk; /* Checksum of preceding 512 bytes */ 58 59 /* These values are added for the file handling 60 the ROM shouldn't overwrite those fileds */ 61 long position; /** NEW** - current position in file */ 62 int flags; 63 mode_t mode; 64 }; 65 66 67 struct M_SECT { 68 char foo[3072]; 69 }; 70 71 72 struct M_MAP { 73 char map[32]; /* 32 bytes = 256 bits for a microdrive map */ 74 }; 75 76 77 struct N_CHAN { 78 // base channel descriptor 79 struct BASE_CHAN base; 80 // "N" channel specific stuff 81 u8_t remote; /* The destination station number */ 82 u8_t local; /* This Spectrum's station number */ 83 u16_t nc_number; /* The block number */ 84 u8_t nc_type; /* The packet type code . 0 data, 1 EOF */ 85 u8_t nc_obl; /* Number of bytes in data block */ 86 u8_t datachk; /* The data checksum */ 87 u8_t hdachk; /* The header checksum */ 88 u8_t nc_cur; /* The position of last buffer char taken */ 89 u8_t nc_ibl; /* Number of bytes in the input buffer */ 90 char data[255]; /* 255 byte data buffer */ 91 }; 92 93 #endif /*__ZX_CHANNELS__*/ 94 95 96 // Load a sector identified by file name and record number 97 extern int __LIB__ if1_load_record (int drive, char *filename, int record, struct M_CHAN *buffer) __smallc; 98 99 // Load a sector identified by the sector number 100 extern int __LIB__ if1_load_sector (int drive, int sector, struct M_CHAN *buffer) __smallc; 101 102 // Write the sector in "buffer" 103 extern int __LIB__ if1_write_sector (int drive, int sector, struct M_CHAN *buffer) __smallc; 104 105 // Add a record containing the data in "buffer" 106 extern int __LIB__ if1_write_record (int drive, struct M_CHAN *buffer) __smallc; 107 108 // Put a 10 characters file name at the specified location; return with the file name length 109 extern int __LIB__ if1_setname(char* name, char *location) __smallc; 110 111 extern char __LIB__ *if1_getname(char *location); 112 113 // Delete a file 114 extern int __LIB__ if1_remove_file(int drive, char *filename) __smallc; 115 116 // Create a file if it doesn't exist 117 extern int __LIB__ if1_touch_file(int drive, char *filename) __smallc; 118 119 // Create a file and return handle 120 extern int __LIB__ if1_init_file (int drive, char *filename, struct M_CHAN *buffer) __smallc; 121 122 // Load the map values for the specified drive 123 extern void __LIB__ if1_update_map (int drive, char *mdvmap) __smallc; 124 125 // Find a free sector 126 extern int __LIB__ if1_find_sector (int drive); 127 128 // Find a free sector in the specified map 129 extern int __LIB__ if1_find_sector_map (char *mdvmap); 130 131 // Returns true if the current program has been loaded from microdrive 132 extern bool_t __LIB__ if1_from_mdv(); 133 134 // Returns true if the system variables are already present 135 extern bool_t __LIB__ if1_installed(); 136 137 // Returns the ROM version of the Interface 1 138 extern int __LIB__ if1_edition(); 139 140 // Returns true if the Interface 1 is present 141 extern int __LIB__ zx_interface1(); 142 143 // Returns the microdrive status 0=ok, 1=wr protect, 2=not present 144 extern int __LIB__ if1_mdv_status(int drive); 145 146 // Count the free sectors in the given drive 147 extern int __LIB__ if1_free_sectors(int drive); 148 149 #endif /* _ZXINTERFACE1_H */ 150