fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/utils/psi/info.c *
7 * Created: 2013-06-09 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2013-2024 Hampa Hug <hampa@hampa.ch> *
9 *****************************************************************************/
10
11/*****************************************************************************
12 * This program is free software. You can redistribute it and / or modify it *
13 * under the terms of the GNU General Public License version 2 as published *
14 * by the Free Software Foundation. *
15 * *
16 * This program is distributed in the hope that it will be useful, but *
17 * WITHOUT ANY WARRANTY, without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
19 * Public License for more details. *
20 *****************************************************************************/
21
22
23#include "main.h"
24#include "comment.h"
25#include "info.h"
26
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30
31#include <drivers/psi/psi.h>
32
33
34static
35void psi_print_range (const char *str1, unsigned v1, unsigned v2, const char *str2)
36{
37 fputs (str1, stdout);
38
39 if (v1 == v2) {
40 printf ("%u", v1);
41 }
42 else {
43 printf ("%u-%u", v1, v2);
44 }
45
46 fputs (str2, stdout);
47}
48
49int psi_print_info (psi_img_t *img)
50{
51 int fc, fh, fs, ff;
52 unsigned c, h, s;
53 unsigned enc, mfm_size;
54 unsigned tcnt[2], scnt[2], ssize[2], srng[2];
55 unsigned long stotal, atotal;
56 unsigned long dsize;
57 unsigned long flags, tflags;
58 const psi_cyl_t *cyl;
59 const psi_trk_t *trk;
60 const psi_sct_t *sct, *alt;
61
62 fc = 1;
63 fh = 1;
64 fs = 1;
65
66 enc = 0;
67
68 tcnt[0] = 0;
69 tcnt[1] = 0;
70
71 scnt[0] = 0;
72 scnt[1] = 0;
73
74 srng[0] = 0;
75 srng[1] = 0;
76
77 ssize[0] = 0;
78 ssize[1] = 0;
79
80 stotal = 0;
81 atotal = 0;
82 dsize = 0;
83
84 flags = 0;
85 tflags = 0;
86
87 for (c = 0; c < img->cyl_cnt; c++) {
88 cyl = img->cyl[c];
89
90 if (fc || (cyl->trk_cnt < tcnt[0])) {
91 tcnt[0] = cyl->trk_cnt;
92 }
93
94 if (fc || (cyl->trk_cnt > tcnt[1])) {
95 tcnt[1] = cyl->trk_cnt;
96 }
97
98 fc = 0;
99
100 for (h = 0; h < cyl->trk_cnt; h++) {
101 trk = cyl->trk[h];
102
103 if (fh || (trk->sct_cnt < scnt[0])) {
104 scnt[0] = trk->sct_cnt;
105 }
106
107 if (fh || (trk->sct_cnt > scnt[1])) {
108 scnt[1] = trk->sct_cnt;
109 }
110
111 fh = 0;
112
113 for (s = 0; s < trk->sct_cnt; s++) {
114 sct = trk->sct[s];
115
116 if (psi_check_duplicate (trk, s)) {
117 tflags |= PSI_TRK_DUP;
118 }
119
120 if (fs || (sct->n < ssize[0])) {
121 ssize[0] = sct->n;
122 }
123
124 if (fs || (sct->n > ssize[1])) {
125 ssize[1] = sct->n;
126 }
127
128 if (fs || (sct->s < srng[0])) {
129 srng[0] = sct->s;
130 }
131
132 if (fs || (sct->s > srng[1])) {
133 srng[1] = sct->s;
134 }
135
136 if ((sct->c != c) || (sct->h != h)) {
137 tflags |= PSI_TRK_BAD_ID;
138 }
139
140 if ((enc != 0) && (enc != sct->encoding)) {
141 tflags |= PSI_TRK_ENCODING;
142 }
143
144 if (sct->encoding != 0) {
145 enc = sct->encoding;
146 }
147
148 if (psi_sct_get_read_time (sct) != 0) {
149 tflags |= PSI_TRK_TIME;
150 }
151
152 if (sct->have_mfm_size) {
153 mfm_size = psi_sct_get_mfm_size (sct);
154
155 if ((mfm_size > 8) || ((128U << mfm_size) != sct->n)) {
156 flags |= PSI_FLAG_MFM_SIZE;
157 }
158 }
159
160 fs = 0;
161
162 stotal += 1;
163 dsize += sct->n;
164 flags |= sct->flags;
165
166 alt = sct->next;
167
168 while (alt != NULL) {
169 atotal += 1;
170 flags |= sct->flags;
171 alt = alt->next;
172 }
173 }
174 }
175 }
176
177 printf ("cylinders: %u\n", img->cyl_cnt);
178 psi_print_range ("heads: ", tcnt[0], tcnt[1], "\n");
179 psi_print_range ("sectors: ", scnt[0], scnt[1], "\n");
180 psi_print_range ("sector range: ", srng[0], srng[1], "\n");
181 psi_print_range ("sector size: ", ssize[0], ssize[1], "\n");
182
183 printf ("flags: ");
184
185 ff = 1;
186
187 if (tflags & PSI_TRK_DUP) {
188 printf (" DUP");
189 ff = 0;
190 }
191
192 if (tflags & PSI_TRK_BAD_ID) {
193 printf (" BAD-ID");
194 ff = 0;
195 }
196
197 if (tflags & PSI_TRK_ENCODING) {
198 printf (" ENCODING");
199 ff = 0;
200 }
201
202 if (tflags & PSI_TRK_TIME) {
203 printf (" TIME");
204 ff = 0;
205 }
206
207 if (flags & PSI_FLAG_CRC_ID) {
208 printf (" CRC-ID");
209 ff = 0;
210 }
211
212 if (flags & PSI_FLAG_CRC_DATA) {
213 printf (" CRC-DATA");
214 ff = 0;
215 }
216
217 if (flags & PSI_FLAG_DEL_DAM) {
218 printf (" DEL-DAM");
219 ff = 0;
220 }
221
222 if (flags & PSI_FLAG_NO_DAM) {
223 printf (" NO-DAM");
224 ff = 0;
225 }
226
227 if (flags & PSI_FLAG_MFM_SIZE) {
228 printf (" MFM-SIZE");
229 ff = 0;
230 }
231
232 if (ff) {
233 printf (" -");
234 }
235
236 printf ("\n");
237
238 printf ("total sectors: %lu + %lu\n", stotal, atotal);
239 printf ("data size: %lu (%.2f KiB)\n", dsize, (double) dsize / 1024);
240 printf ("comment size: %u\n", img->comment_size);
241
242 return (0);
243}