emu: deactivate debugger/memview when the other one is activated
[zymosis.git] / src / libfusefdc / disk_sad.c
blob822c972e8ccf669a315d0451dce6490e87da72cc
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 //==========================================================================
26 // open_sad
28 //==========================================================================
29 static int open_sad (buffer_t *buffer, disk_t *d, int preindex) {
30 int i, j, sectors, seclen;
32 d->sides = buff[18];
33 d->cylinders = buff[19];
34 GEOM_CHECK;
35 sectors = buff[20];
36 seclen = buff[21]*64;
37 buffer->index = 22;
39 /* create a DD disk */
40 d->density = DISK_DD;
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 //==========================================================================
59 // write_sad
61 //==========================================================================
62 static int write_sad (FILE *file, disk_t *d) {
63 int i, j, sbase, sectors, seclen, mfm, cyl;
64 uint8_t head[256];
66 if (check_disk_geom(d, &sbase, &sectors, &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);
72 head[18] = d->sides;
73 head[19] = cyl;
74 head[20] = sectors;
75 head[21] = seclen*4;
76 /* SAD head */
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);