File: printfdprm.c

package info (click to toggle)
fdutils 5.3-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,004 kB
  • ctags: 621
  • sloc: ansic: 6,098; sh: 2,236; makefile: 279; sed: 4
file content (168 lines) | stat: -rw-r--r-- 3,546 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <stdio.h>
#include "printfdprm.h"


void print_params(drivedesc_t *drivedesc,
		  struct floppy_struct *ft,
		  level_t level, int cpm,
		  void (*print)(char *,int))
{
	int ssize, r, perp_ref, need_dtr, need_fm, need_tpi;
	ff_t formFactor;

	if(drivedesc)
		formFactor = drivedesc->type.ff;
	else
		formFactor = FF_UNKNOWN;

	need_dtr = 0;
	need_fm = 0;
	need_tpi = 0;
	
	switch(ft->head) {
		case 1:
			print("SS",0);
			break;
		case 2:
			print("DS",0);
			break;
	}
	perp_ref = 0;
	switch(r = ft->rate & 0x83) {
		case 0:			
			print("HD",0);
			break;
		case 0x80:
			need_tpi = need_fm = need_dtr = 1;
			print("DD", 0); /* 8 " DD */
			break;
		case 1:
		case 2:
			switch(formFactor) {
				case FF_35:
					if(r == 1)
						/* modified double-density
						 * format with slightly higher
						 * DTR */
						print("QD",0);
					else
						print("DD",0);
					break;
				case FF_525:
					if(ft->track >= 60)
						print("QD",0);
					else
						print("DD",0);
					break;
				default:
					/* we do not not the drive type.
					 * Guesswork */
					if(ft->track <= 60)
						/* this covers any 40 track
						 * formats */
						print("DD",0);
					else if(r == 1)
						/* this covers the special
						 * density 3 1/2 format, as
						 * well as the quad density 
						 * 5 1/4 format */
						print("QD",0);
					else
						/* this leaves norma 3 1/2 DD */
						print("DD",0);
					break;
			}
			break;
		case 3:
			perp_ref = 0x40;
			print("ED",0);
			break;
		default:
			need_tpi = need_fm = need_dtr = 1;
			print("SD",0);
			break;
	}

	switch(formFactor) {
		/* TPI is only meaningful for 5 1/4 drives.  As other
		 * drives have different physical sizes, the numbers of
		 * 48 or 96 would be inappropriate anyways: use stretch in
		 * that case */		   
		case FF_525:
			if(level >= LEV_ALL) {
				if(ft->track <= 60)
					print("tpi=48",0);
				else
					print("tpi=96",0);
			}
			break;
		case FF_UNKNOWN:
			if(level >= LEV_ALL && ft->track <= 60)
				print("tpi=48",0);
			break;
		default:
			if(level >= LEV_ALL || ft->stretch)
				print("stretch=%d", ft->stretch);
			break;			
	}

	if(level >= LEV_ALL || ft->size != ft->sect * ft->head * ft->track)
		print("size=%d", ft->size);

	ssize = (((ft->rate & 0x38) >> 3) + 2) % 8;
	if(ssize == 2)
		print("sect=%d", ft->sect);
	else {
		if( (ft->sect << 2) % (1 << ssize) == 0)
			print("sect=%d", ft->sect << 2 >> ssize);
		else {
			if(ft->sect % 2)
				print("tracksize=%db", ft->sect);
			else
				print("tracksize=%dKB", ft->sect / 2);
				
		}
	}

	if(level >= LEV_EXPL || need_dtr)
		print("dtr=%d", ft->rate & 3);

	if(level >= LEV_EXPL || perp_ref != (ft->rate & 0x40))
		print("perp=%d", (ft->rate & 0x40) >> 6);

	if(level >= LEV_EXPL || need_fm)
		print("fm=%d", (ft->rate & 0x80) >> 7);

	if(level >= LEV_EXPL || (ft->track != 80 && ft->track != 40))
		print("cyl=%d", ft->track);

#ifdef FD_SWAPSIDES
	if(ft->stretch & FD_SWAPSIDES)
		print("swapsides",0);			
#endif

	if(ft->rate & FD_2M)
		print("2M",0);
	
	if(level < LEV_ALL &&
	   ft->sect * 4 <  (2 << ssize) && ft->sect * 4 % (1 << ssize))
		print("mss", 0);
	else {
		if(ssize < 2)
			print("ssize=%d", 128 << ssize);
		else if(ssize > 2)
			print("ssize=%dKB", 1 << (ssize-3));
		else if(level >= LEV_ALL)
			print("ssize=512", 0);
	}

	/* useless stuff */
	if(level >= LEV_MOST) {		
		print("gap=0x%02x", (unsigned char) ft->gap);
		print("fmt_gap=0x%02x", (unsigned char) ft->fmt_gap);
	}

	if(level >= LEV_ALL)
		print("spec1=0x%02x", (unsigned char) ft->spec1);
	printf("\n");
}