1 /*************************************************************************** 2 * * 3 * LIBDSK: General floppy and diskimage access library * 4 * Copyright (C) 2001-2,2007 John Elliott <seasip.webmaster@gmail.com> * 5 * * 6 * This library is free software; you can redistribute it and/or * 7 * modify it under the terms of the GNU Library General Public * 8 * License as published by the Free Software Foundation; either * 9 * version 2 of the License, or (at your option) any later version. * 10 * * 11 * This library is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 14 * Library General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU Library General Public * 17 * License along with this library; if not, write to the Free * 18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 19 * MA 02111-1307, USA * 20 * * 21 ***************************************************************************/ 22 23 /* Declarations for the Teledisk driver */ 24 25 /* This structure (for the file header) is based on 26 * <http://www.fpns.net/willy/wteledsk.htm> 27 */ 28 29 typedef unsigned char tele_byte; 30 typedef unsigned short tele_word; 31 32 typedef struct 33 { 34 char magic[3]; 35 tele_byte volume_seq; /* 0 for first file in sequence, 1 for 2nd... */ 36 tele_byte volume_id; /* All files must have the same volume ID */ 37 tele_byte ver; /* Version of Teledisk used to create file */ 38 tele_byte datarate; /* 0=250Kbps (360k/720k) 1=300Kbps (1.2M) 39 2=500Kbps (1.4M). Bit 7 set for FM. */ 40 tele_byte drivetype; /* 1=360k 2=1.2M 3=720k 4=1.4M */ 41 tele_byte doubletrack; /* 0=media matched drive 42 1=48tpi media, 96tpi drive 43 2=96tpi media, 48tpi drive 44 45 Bit 7 set if comment present. */ 46 tele_byte dosmode; /* Only allocated sectors backed up? */ 47 tele_byte sides; /* Number of heads */ 48 tele_word crc; 49 } TELE_HEADER; 50 51 typedef struct 52 { 53 int year, mon, day; 54 int hour, min, sec; 55 char text[1]; 56 } TELE_COMMENT; 57 58 typedef struct 59 { 60 tele_byte sectors; 61 tele_byte cylinder; 62 tele_byte head; 63 tele_byte crc; 64 } TELE_TRKHEAD; 65 66 typedef struct 67 { 68 tele_byte cylinder_id; /* On-disk sector ID */ 69 tele_byte head_id; 70 tele_byte sector_id; 71 size_t sector_len; 72 tele_byte syndrome; /* Various errors: 73 * bit 0: Sector appeared more than once 74 * bit 1: CRC error 75 * bit 2: Deleted data 76 * bit 4: Unallocated sector not saved 77 * bit 5: Sector ID but no data 78 * bit 6: Data but no sector ID */ 79 tele_byte header_crc; 80 /* Strictly speaking the last 2 members are the start of the sector data 81 * rather than the end of the sector header. But there's not a lot of 82 * difference - you just have to be sure not to load them if 83 * (syndrome & 0x30). */ 84 tele_word compressed_len; 85 tele_byte encoding; 86 } TELE_SECHEAD; 87 88 typedef struct 89 { 90 DSK_DRIVER tele_super; 91 TELE_HEADER tele_head; 92 FILE *tele_fp; 93 TELE_COMMENT *tele_comment; 94 /* Fake sector for READ ID command */ 95 unsigned int tele_sector; 96 /* Addresses of track headers */ 97 long tele_track_addr[100][2]; 98 TELE_TRKHEAD tele_trackhead; 99 TELE_SECHEAD tele_sechead; 100 } TELE_DSK_DRIVER; 101 102 103 dsk_err_t tele_open(DSK_DRIVER *self, const char *filename); 104 dsk_err_t tele_creat(DSK_DRIVER *self, const char *filename); 105 dsk_err_t tele_close(DSK_DRIVER *self); 106 dsk_err_t tele_read(DSK_DRIVER *self, const DSK_GEOMETRY *geom, 107 void *buf, dsk_pcyl_t cylinder, 108 dsk_phead_t head, dsk_psect_t sector); 109 dsk_err_t tele_write(DSK_DRIVER *self, const DSK_GEOMETRY *geom, 110 const void *buf, dsk_pcyl_t cylinder, 111 dsk_phead_t head, dsk_psect_t sector); 112 dsk_err_t tele_format(DSK_DRIVER *self, DSK_GEOMETRY *geom, 113 dsk_pcyl_t cylinder, dsk_phead_t head, 114 const DSK_FORMAT *format, unsigned char filler); 115 dsk_err_t tele_secid(DSK_DRIVER *self, const DSK_GEOMETRY *geom, 116 dsk_pcyl_t cylinder, dsk_phead_t head, 117 DSK_FORMAT *result); 118 dsk_err_t tele_xseek(DSK_DRIVER *self, const DSK_GEOMETRY *geom, 119 dsk_pcyl_t cylinder, dsk_phead_t head); 120 dsk_err_t tele_xread(DSK_DRIVER *self, const DSK_GEOMETRY *geom, void *buf, 121 dsk_pcyl_t cylinder, dsk_phead_t head, 122 dsk_pcyl_t cyl_expected, dsk_phead_t head_expected, 123 dsk_psect_t sector, size_t sector_size, int *deleted); 124 dsk_err_t tele_xwrite(DSK_DRIVER *self, const DSK_GEOMETRY *geom, const void *buf, 125 dsk_pcyl_t cylinder, dsk_phead_t head, 126 dsk_pcyl_t cyl_expected, dsk_phead_t head_expected, 127 dsk_psect_t sector, size_t sector_size, int deleted); 128 dsk_err_t tele_trackids(DSK_DRIVER *self, const DSK_GEOMETRY *geom, 129 dsk_pcyl_t cylinder, dsk_phead_t head, 130 dsk_psect_t *count, DSK_FORMAT **result); 131 dsk_err_t tele_status(DSK_DRIVER *self, const DSK_GEOMETRY *geom, 132 dsk_phead_t head, unsigned char *result); 133 134 dsk_err_t tele_option_enum(DSK_DRIVER *self, int idx, char **optname); 135 136 dsk_err_t tele_option_set(DSK_DRIVER *self, const char *optname, int value); 137 dsk_err_t tele_option_get(DSK_DRIVER *self, const char *optname, int *value); 138 139 dsk_err_t tele_getgeom(DSK_DRIVER *self, DSK_GEOMETRY *dg); 140 141