fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 234 lines 5.4 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/utils/pfi/info.c * 7 * Created: 2013-12-27 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2013-2021 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 <stdlib.h> 26#include <stdio.h> 27#include <string.h> 28 29#include <drivers/pfi/pfi.h> 30 31 32static 33void pfi_print_range (const char *str1, unsigned long v1, unsigned long v2, const char *str2) 34{ 35 fputs (str1, stdout); 36 37 if (v1 == v2) { 38 printf ("%lu", v1); 39 } 40 else { 41 printf ("%lu - %lu", v1, v2); 42 } 43 44 fputs (str2, stdout); 45} 46 47static 48void pfi_print_range_float (const char *str1, double v1, double v2, const char *str2) 49{ 50 fputs (str1, stdout); 51 52 if (v1 == v2) { 53 printf ("%.4f", v1); 54 } 55 else { 56 printf ("%.4f - %.4f", v1, v2); 57 } 58 59 fputs (str2, stdout); 60} 61 62int pfi_print_info (pfi_img_t *img) 63{ 64 unsigned long c, h, cn, hn, tn; 65 unsigned long h1, h2; 66 unsigned long len; 67 unsigned idx, idx1, idx2; 68 unsigned long clk, clk1, clk2; 69 double rpm, rpm1, rpm2; 70 pfi_cyl_t *cyl; 71 pfi_trk_t *trk; 72 73 cn = pfi_img_get_cyl_cnt (img); 74 tn = 0; 75 76 h1 = 0; 77 h2 = 0; 78 79 idx1 = 0; 80 idx2 = 0; 81 82 clk1 = 0; 83 clk2 = 0; 84 85 rpm1 = 0.0; 86 rpm2 = 0.0; 87 88 for (c = 0; c < cn; c++) { 89 cyl = pfi_img_get_cylinder (img, c, 0); 90 91 if (cyl == NULL) { 92 hn = 0; 93 } 94 else { 95 hn = pfi_cyl_get_trk_cnt (cyl); 96 } 97 98 h1 = ((c == 0) || (hn < h1)) ? hn : h1; 99 h2 = ((c == 0) || (hn > h2)) ? hn : h2; 100 101 if (cyl == NULL) { 102 continue; 103 } 104 105 for (h = 0; h < hn; h++) { 106 trk = pfi_cyl_get_track (cyl, h, 0); 107 108 if (trk == NULL) { 109 idx = 0; 110 clk = 0; 111 len = 0; 112 } 113 else { 114 idx = trk->index_cnt; 115 clk = pfi_trk_get_clock (trk); 116 len = (trk->index_cnt < 2) ? 0 : (trk->index[1] - trk->index[0]); 117 } 118 119 if (len > 0) { 120 rpm = (60.0 * clk) / len; 121 } 122 else { 123 rpm = 0.0; 124 } 125 126 idx1 = ((tn == 0) || (idx < idx1)) ? idx : idx1; 127 idx2 = ((tn == 0) || (idx > idx2)) ? idx : idx2; 128 129 clk1 = ((tn == 0) || (clk < clk1)) ? clk : clk1; 130 clk2 = ((tn == 0) || (clk > clk2)) ? clk : clk2; 131 132 rpm1 = ((tn == 0) || (rpm < rpm1)) ? rpm : rpm1; 133 rpm2 = ((tn == 0) || (rpm > rpm2)) ? rpm : rpm2; 134 135 tn += 1; 136 } 137 } 138 139 printf ("cylinders: %lu\n", cn); 140 pfi_print_range ("heads: ", h1, h2, "\n"); 141 printf ("tracks: %lu\n", tn); 142 pfi_print_range ("clock: ", clk1, clk2, "\n"); 143 pfi_print_range ("index: ", idx1, idx2, "\n"); 144 pfi_print_range_float ("rpm: ", rpm1, rpm2, "\n"); 145 146 if (img->comment_size > 0) { 147 fputs ("\n", stdout); 148 pfi_comment_show (img); 149 } 150 151 return (0); 152} 153 154 155static 156int pfi_list_track_cb (pfi_img_t *img, pfi_trk_t *trk, unsigned long c, unsigned long h, void *opaque) 157{ 158 unsigned i; 159 int *verb; 160 unsigned long len, clk, clock; 161 double rpm; 162 163 if (trk->pulse_cnt == 0) { 164 return (0); 165 } 166 167 verb = opaque; 168 169 clock = pfi_trk_get_clock (trk); 170 171 if (trk->index_cnt >= 2) { 172 len = trk->index[trk->index_cnt - 1] - trk->index[0]; 173 rpm = (60.0 * (trk->index_cnt - 1) * clock) / len; 174 } 175 else { 176 len = 0; 177 rpm = 0.0; 178 } 179 180 printf ("TRACK %2lu/%lu: PULSE=%6lu CLK=%lu LEN=%lu IDX=%u RPM=%.4f\n", 181 c, h, trk->pulse_cnt, clock, len, trk->index_cnt, rpm 182 ); 183 184 if (*verb == 0) { 185 return (0); 186 } 187 188 if (trk->index_cnt > 0) { 189 printf ("\t [%8lu, %8lu] T=%7.3f LEN=%lu\n", 190 0UL, 191 (unsigned long) trk->index[0], 192 (1000.0 * trk->index[0]) / clock, 193 (unsigned long) trk->index[0] 194 ); 195 } 196 197 for (i = 1; i < trk->index_cnt; i++) { 198 len = trk->index[i] - trk->index[i - 1]; 199 rpm = (60.0 * clock) / len; 200 201 printf ("\tR%u: [%8lu, %8lu] T=%7.3f LEN=%lu RPM=%.4f\n", 202 i, 203 (unsigned long) trk->index[i - 1], 204 (unsigned long) trk->index[i], 205 (1000.0 * len) / clock, 206 len, rpm 207 ); 208 } 209 210 if (trk->index_cnt > 0) { 211 clk = pfi_trk_get_clk (trk, trk->pulse_cnt); 212 213 if (clk < trk->index[trk->index_cnt - 1]) { 214 len = 0; 215 } 216 else { 217 len = clk - trk->index[trk->index_cnt - 1]; 218 } 219 220 printf ("\t [%8lu, %8lu] T=%7.3f LEN=%lu\n", 221 (unsigned long) trk->index[trk->index_cnt - 1], 222 clk, 223 (1000.0 * len) / clock, 224 len 225 ); 226 } 227 228 return (0); 229} 230 231int pfi_list_tracks (pfi_img_t *img, int verb) 232{ 233 return (pfi_for_all_tracks (img, pfi_list_track_cb, &verb)); 234}