1 /* disk.c: Routines for handling disk images
2 Copyright (c) 2007-2017 Gergely Szasz
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 Author contact information:
20 Philip: philip-fuse@shadowmagic.org.uk
24 //==========================================================================
28 //==========================================================================
29 static int open_sad (buffer_t
*buffer
, disk_t
*d
, int preindex
) {
30 int i
, j
, sectors
, seclen
;
33 d
->cylinders
= buff
[19];
39 /* create a DD disk */
41 if (disk_alloc(d
) != DISK_OK
) return d
->status
;
43 for (j
= 0; j
< d
->sides
; ++j
) {
44 for (i
= 0; i
< d
->cylinders
; ++i
) {
45 if (trackgen(d
, buffer
, j
, i
, 1, sectors
, seclen
, preindex
,
46 GAP_MGT_PLUSD
, NO_INTERLEAVE
, NO_AUTOFILL
))
48 return (d
->status
= DISK_GEOM
);
53 return (d
->status
= DISK_OK
);
57 //==========================================================================
61 //==========================================================================
62 static int write_sad (FILE *file
, disk_t
*d
) {
63 int i
, j
, sbase
, sectors
, seclen
, mfm
, cyl
;
66 if (check_disk_geom(d
, &sbase
, §ors
, &seclen
, &mfm
, &cyl
) || sbase
!= 1) {
67 return d
->status
= DISK_GEOM
;
70 if (cyl
== -1) cyl
= d
->cylinders
;
71 memcpy(head
, "Aley's disk backup", 18);
77 if (fwrite(head
, 22, 1, file
) != 1) return (d
->status
= DISK_WRPART
);
79 for (j
= 0; j
< d
->sides
; ++j
) {
80 for (i
= 0; i
< cyl
; ++i
) {
81 if (savetrack(d
, file
, j
, i
, 1, sectors
, seclen
)) {
82 return (d
->status
= DISK_GEOM
);
87 return (d
->status
= DISK_OK
);