fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/utils/pri/info.c *
7 * Created: 2013-12-19 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2013-2019 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
25#include <stdio.h>
26#include <string.h>
27
28#include <drivers/pri/pri.h>
29
30
31#define TAG "%-16s"
32
33
34static
35void pri_print_range (const char *str1, unsigned long v1, unsigned long v2, const char *str2)
36{
37 printf (TAG, str1);
38
39 if (v1 == v2) {
40 printf ("%lu", v1);
41 }
42 else {
43 printf ("%lu - %lu", v1, v2);
44 }
45
46 fputs (str2, stdout);
47}
48
49static
50void pri_print_range_float (const char *str1, double v1, double v2, const char *str2)
51{
52 printf (TAG, str1);
53
54 if (v1 == v2) {
55 printf ("%.4f", v1);
56 }
57 else {
58 printf ("%.4f - %.4f", v1, v2);
59 }
60
61 fputs (str2, stdout);
62}
63
64int pri_print_info (pri_img_t *img)
65{
66 unsigned long c, h, cn, hn, tn;
67 unsigned long h1, h2;
68 unsigned long len, len1, len2;
69 unsigned long clk, clk1, clk2;
70 double rpm, rpm1, rpm2;
71 pri_cyl_t *cyl;
72 pri_trk_t *trk;
73
74 cn = pri_img_get_cyl_cnt (img);
75 tn = 0;
76
77 h1 = 0;
78 h2 = 0;
79
80 clk1 = 0;
81 clk2 = 0;
82
83 len1 = 0;
84 len2 = 0;
85
86 rpm1 = 0.0;
87 rpm2 = 0.0;
88
89 for (c = 0; c < cn; c++) {
90 cyl = pri_img_get_cylinder (img, c, 0);
91
92 if (cyl == NULL) {
93 hn = 0;
94 }
95 else {
96 hn = pri_cyl_get_trk_cnt (cyl);
97 }
98
99 h1 = ((c == 0) || (hn < h1)) ? hn : h1;
100 h2 = ((c == 0) || (hn > h2)) ? hn : h2;
101
102 if (cyl == NULL) {
103 continue;
104 }
105
106 for (h = 0; h < hn; h++) {
107 trk = pri_cyl_get_track (cyl, h, 0);
108
109 if (trk == NULL) {
110 clk = 0;
111 len = 0;
112 }
113 else {
114 clk = pri_trk_get_clock (trk);
115 len = pri_trk_get_size (trk);
116 }
117
118 if (len > 0) {
119 rpm = (60.0 * clk) / len;
120 }
121 else {
122 rpm = 0.0;
123 }
124
125 clk1 = ((tn == 0) || (clk < clk1)) ? clk : clk1;
126 clk2 = ((tn == 0) || (clk > clk2)) ? clk : clk2;
127
128 len1 = ((tn == 0) || (len < len1)) ? len : len1;
129 len2 = ((tn == 0) || (len > len2)) ? len : len2;
130
131 rpm1 = ((tn == 0) || (rpm < rpm1)) ? rpm : rpm1;
132 rpm2 = ((tn == 0) || (rpm > rpm2)) ? rpm : rpm2;
133
134 tn += 1;
135 }
136 }
137
138 printf (TAG "%lu\n", "cylinders:", cn);
139 pri_print_range ("heads:", h1, h2, "\n");
140 printf (TAG "%lu\n", "tracks:", tn);
141 pri_print_range ("clock:", clk1, clk2, "\n");
142 pri_print_range ("track length:", len1, len2, "\n");
143 pri_print_range_float ("rpm:", rpm1, rpm2, "\n");
144 printf (TAG "%d\n", "read-only:", img->readonly != 0);
145 printf (TAG "%d\n", "woz-cleaned:", img->woz_cleaned != 0);
146 printf (TAG "%d\n", "woz-track-sync:", img->woz_track_sync != 0);
147
148 if (img->comment_size > 0) {
149 fputs ("\n", stdout);
150 pri_comment_show (img);
151 }
152
153 return (0);
154}