forked from OpenCBM/nibtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ihs.c
executable file
·745 lines (635 loc) · 18 KB
/
ihs.c
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/* NIBTOOLS IHS routines */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <ctype.h>
#include "mnibarch.h"
#include "gcr.h"
#include "nibtools.h"
int Use_SCPlus_IHS = 0; // "-j"
int track_align_report = 0; // "-x"
int Deep_Bitrate_SCPlus_IHS = 0; // "-y"
int Test_SCPlus_IHS = 0; // "-z"
BYTE IHSresult = 0;
int use_floppycode_ihs = 0;
char *logline;
BYTE DBG_IHS = 0; // set this to "1" for IHS debugging messages
static BYTE read_mem(CBM_FILE fd, unsigned short addr);
static BYTE get_default_bitrate(int track);
// Check for 1541/1571 (SC+ compatible) IHS presence
// 0 = found
// 8 = hole not detected, or IHS not working, or IHS not present
// 16 = IHS disabled (must enable first!)
BYTE Check_SCPlus_IHS(CBM_FILE fd, BYTE KeepOn)
{
BYTE ihs_detected = 8;
BYTE buffer1[NIB_TRACK_LENGTH];
BYTE *buffer = buffer1;
int i, res;
motor_on(fd);
// turn SC+ IHS on
send_mnib_cmd(fd, FL_IHS_ON, NULL, 0);
burst_read(fd);
for (i = 0; i < 10; i++)
{
memset(buffer, 0x55, NIB_TRACK_LENGTH);
// check SC+ IHS presence
send_mnib_cmd(fd, FL_IHS_PRESENT, NULL, 0);
burst_read(fd);
res = burst_read_track(fd, buffer, NIB_TRACK_LENGTH);
if (!res)
{
printf("(timeout) ");
fprintf(fplog, "(timeout) ");
fflush(stdout);
burst_read(fd);
//delay(500);
burst_read(fd);
}
else
break;
}
if (res)
{
for (i = 0; i < NIB_TRACK_LENGTH; i++)
{
if (buffer[i] == 0) ihs_detected = 0; // 0 = found, 8 = not found
else if (buffer[i] != 8)
{
ihs_detected = buffer[i]; // 16 = IHS disabled
break; // everything else = unknown error
}
}
}
else ihs_detected = 99; // unknown error
if (KeepOn == 0)
{
// turn SC+ IHS off
send_mnib_cmd(fd, FL_IHS_OFF, NULL, 0);
burst_read(fd);
}
return (ihs_detected);
}
// Check for 1541/1571 (SC+ compatible) IHS presence
// 0 = found
// 8 = hole not detected, or IHS not working, or IHS not present
// 16 = IHS disabled (must enable first!)
BYTE Check_SCPlus_IHS_2(CBM_FILE fd, BYTE KeepOn)
{
BYTE ihs_detected = 1;
motor_on(fd);
// turn SCPlus IHS on
send_mnib_cmd(fd, FL_IHS_ON, NULL, 0);
burst_read(fd);
// check SCPlus IHS presence
send_mnib_cmd(fd, FL_IHS_PRESENT2, NULL, 0);
ihs_detected = burst_read(fd);
if (KeepOn == 0)
{
// turn SCPlus IHS off
send_mnib_cmd(fd, FL_IHS_OFF, NULL, 0);
burst_read(fd);
}
return (ihs_detected);
}
void OutputIHSResult(int ToConsole, int ToLogfile, BYTE IHSresult, FILE *fplog)
{
if (ToLogfile) fprintf(fplog, "\nTesting 1541/1571 Index Hole Sensor (SC+ compatible).\n");
switch (IHSresult)
{
case 0:
if (ToConsole) printf("\nIndex Hole Sensor detected.\n");
if (ToLogfile) fprintf(fplog, "Index Hole Sensor detected.\n");
break;
case 0x10:
if (ToConsole) printf("\nIHS Error #%d: IHS not enabled.\n",IHSresult);
if (ToLogfile) fprintf(fplog,"IHS Error #%d: IHS not enabled.\n",IHSresult);
break;
case 0x08:
if (ToConsole) printf("\nIHS Error #%d: Index Hole not detected, sensor not working or not present.\nWrong disk side?\n",IHSresult);
if (ToLogfile) fprintf(fplog,"IHS Error #%d: Index Hole not detected, Sensor not working or not present.\nWrong disk side?\n",IHSresult);
break;
default:
if (ToConsole) printf("\nIHS Error #%d: Unknown error.\n",IHSresult);
if (ToLogfile) fprintf(fplog,"IHS Error #%d: Unknown error.\n",IHSresult);
}
}
// Track Alignment Report
// First version with timeouts in drive code
// requires 1541/1571 SC+ compatible IHS
int TrackAlignmentReport2(CBM_FILE fd, BYTE *buffer)
{
int i, m, track, ht, res, NumSync;
BYTE density;
int EvenTrack;
int dump_retry = 10;
if (Check_SCPlus_IHS(fd,1) != 0)
{
fprintf(fplog, "Error: Index Hole Sensor *NOT* detected!\n");
printf("\nError: Index Hole Sensor *NOT* detected!\n");
goto finish1;
}
fprintf(fplog, "\nIndex Hole Sensor detected. Starting Track Alignment Analysis.\n\n");
printf("\nIndex Hole Sensor detected. Starting Track Alignment Analysis.\n\n");
if (track_inc == 1)
{
printf(" | Full Track | Half Track (+0.5) \n");
printf(" #T +--------------------------------+-------------------------------\n");
printf(" RA | pre #sync data BYTEs | pre #sync data BYTEs \n");
printf(" CK | BR lo hi lo hi A1 A2 A3 A4 A5 | BR lo hi lo hi A1 A2 A3 A4 A5\n");
printf("----+--------------------------------+-------------------------------");
fprintf(fplog, " | Full Track | Half Track (+0.5) \n");
fprintf(fplog, " #T +--------------------------------+-------------------------------\n");
fprintf(fplog, " RA | pre #sync data BYTEs | pre #sync data BYTEs \n");
fprintf(fplog, " CK | BR lo hi lo hi A1 A2 A3 A4 A5 | BR lo hi lo hi A1 A2 A3 A4 A5\n");
fprintf(fplog, "----+--------------------------------+-------------------------------");
}
else
{
printf(" | Full Track \n");
printf(" | pre #sync data BYTEs \n");
printf(" | BR lo hi lo hi A1 A2 A3 A4 A5\n");
printf("----+-------------------------------");
fprintf(fplog, " | Full Track\n");
fprintf(fplog, " | pre #sync data BYTEs \n");
fprintf(fplog, " | BR lo hi lo hi A1 A2 A3 A4 A5\n");
fprintf(fplog, "----+-------------------------------");
}
// Don't forget to analyze final half track if half tracks are enabled
ht = (track_inc == 1) ? 1 : 0;
for (track = start_track; track <= end_track+ht; track += track_inc)
{
step_to_halftrack(fd, track);
// deep scan track density (1541/1571 SC+ compatible IHS)
density = Scan_Track_SCPlus_IHS(fd, track, buffer);
set_density(fd, density&3);
if ((EvenTrack = (track == (track/2)*2)) )
{
printf("\n %2.2d ", track/2);
fprintf(fplog, "\n %2.2d ", track/2);
}
if (density & BM_FF_TRACK)
{
printf("| <*> KILLER ");
fprintf(fplog, "| <*> KILLER ");
continue;
}
else if (density & BM_NO_SYNC)
{
printf("| <*> NOSYNC ");
fprintf(fplog, "| <*> NOSYNC ");
continue;
}
else
{
printf("| <%d> ", density);
fprintf(fplog, "| <%d> ", density);
}
// Try to get track dump "dump_retry" times
for (i = 0; i < dump_retry; i++)
{
memset(buffer, 0x00, NIB_TRACK_LENGTH);
send_mnib_cmd(fd, FL_IHS_READ_SCP, NULL, 0);
burst_read(fd);
res = burst_read_track(fd, buffer, NIB_TRACK_LENGTH);
if (!res)
{
printf("(timeout #%d: T%d D%d)", i+1, track, density); // &3
fflush(stdout);
burst_read(fd);
delay(500);
burst_read(fd);
}
else
break;
}
if (res)
{
// Evaluate track image
// Find first sync (we checked for NOSYNC)
// for (i = 0; i < NIB_TRACK_LENGTH; i++) // a single 0xFF
// if (buffer[i] == 0xFF) break; // may be a data BYTE
i = 0;
if (buffer[i] != 0xFF)
{
for (i = 1; i < NIB_TRACK_LENGTH-1; i++)
if ((buffer[i] == 0xFF) && (buffer[i+1] == 0xFF)) break;
}
if (i == NIB_TRACK_LENGTH-1) i++; // final single 0xFF is handled as data BYTE here
// Print number of data BYTEs before first sync
printf("%2.2X %2.2X ", i%256, i/256); // lo/hi
fprintf(fplog, "%2.2X %2.2X ", i%256, i/256); // lo/hi
// Find end of sync, count 0xFFs
NumSync = 0;
for (m = i; m < NIB_TRACK_LENGTH; m++)
if (buffer[m] == 0xFF) NumSync++;
else break;
// Print number of 0xFF sync BYTEs
printf("%2.2X %2.2X ", NumSync%256, NumSync/256); // lo/hi
fprintf(fplog, "%2.2X %2.2X ", NumSync%256, NumSync/256); // lo/hi
// Dump first 5 data BYTEs after sync
for (i = 0; i < 5; i++)
{
if (m+i >= NIB_TRACK_LENGTH)
{
printf(" ");
fprintf(fplog, " ");
}
else // (0xFF possible)
{
printf("%2.2X ", buffer[m+i]);
fprintf(fplog, "%2.2X ", buffer[m+i]);
}
}
}
else
{
// Call to "burst_read_track" was 10x unsuccessful.
printf("\nToo many errors.");
fprintf(fplog, "\nToo many errors.");
exit(2);
}
}
printf("\n");
fprintf(fplog, "\n");
finish1:
// turn SCPlus IHS off
send_mnib_cmd(fd, FL_IHS_OFF, NULL, 0);
burst_read(fd);
return 0;
}
// Deep Bitrate Analysis
// requires 1541/1571 SC+ compatible IHS
int DeepBitrateAnalysis(CBM_FILE fd, char *filename, BYTE *buffer, char *logline)
{
int i, m, track, res;
BYTE density, killer_info, t1;
DWORD dw;
unsigned short NumSync;
BYTE header[0x200], thdr[7];
char fname[256];
FILE * fpout[4];
int dump_retry = 10;
if (Check_SCPlus_IHS(fd,1) != 0)
{
fprintf(fplog, "Error: Index Hole Sensor *NOT* detected!\n");
printf("\nError: Index Hole Sensor *NOT* detected!\n");
goto finish2;
}
fprintf(fplog, "\nIndex Hole Sensor detected. Starting Deep Bitrate Scan.\n\n");
printf("\nIndex Hole Sensor detected. Starting Deep Bitrate Scan.\n\n");
// Create and init raw bitrate dump files
for (density=0; density < 4; density++)
{
sprintf(fname, "%s.br%d", filename, (int)density);
if ((fpout[density] = fopen(fname, "wb")) == NULL)
{
printf( "Error creating deep scan dump file %s.\n", fname);
exit(2);
}
// Write initial BRX-header
memset(header, 0x00, sizeof(header));
sprintf(header, "BR%d-1541",density);
header[8] = 0; // BRX file version number
header[9] = (BYTE) 84; // max number of halftracks
header[10] = (BYTE) (NIB_TRACK_LENGTH % 256); // Size of each stored track = 8KByte
header[11] = (BYTE) (NIB_TRACK_LENGTH / 256);
// header[12..15] = 0;
if (fwrite(header, sizeof(header), 1, fpout[density]) != 1)
{
printf("Cannot write BR%d header.\n", density);
exit(2);
}
// Update file offset
dw = 0x0200;
}
for (track = start_track; track <= end_track; track += track_inc)
{
step_to_halftrack(fd, track);
for (density = 0; density <= 3; density++)
{
set_density(fd, density);
printf("T%2.1f: ", (float) track/2);
fprintf(fplog, "T%2.1f: ", (float) track/2);
if (track < 10*2)
{
printf(" ");
fprintf(fplog, " ");
}
printf("<%d> ", density);
fprintf(fplog, "<%d> ", density);
// Scan for killer track
send_mnib_cmd(fd, FL_SCANKILLER, NULL, 0);
killer_info = burst_read(fd);
if (killer_info & BM_FF_TRACK)
{
printf("KILLER\n");
fprintf(fplog, "KILLER\n");
// Write killer track to BRX file
memset(buffer, 0xFF, NIB_TRACK_LENGTH);
// Set end-of-data marker 0x55
buffer[NIB_TRACK_LENGTH-7] = (BYTE) 0x55;
}
else
{
// Try to get bitrate dump "dump_retry" times
for (i = 0; i < dump_retry; i++)
{
memset(buffer, 0x00, NIB_TRACK_LENGTH);
send_mnib_cmd(fd, FL_DBR_ANALYSIS, NULL, 0);
burst_read(fd);
res = burst_read_n(fd, buffer, NIB_TRACK_LENGTH-6);
if (!res)
{
printf("(deep scan timeout #%d: T%d D%d)", i+1, track, density);
fprintf(fplog, "(deep scan timeout #%d: T%d D%d)", i+1, track, density);
fflush(stdout);
burst_read(fd);
delay(500);
burst_read(fd);
}
else
break;
}
if (res)
{
// Read number of sync marks
NumSync = ( ((unsigned short) read_mem(fd, 0xcd)) << 8 ) | read_mem(fd, 0xcc);
// Evaluate density dump
BitrateStats( buffer, logline, NumSync );
printf("\n");
fprintf(fplog, "\n");
}
else
{
// Call to "burst_read_n" was 10x unsuccessful.
// BRX files may be asynchronous.
printf("Too many errors.\n");
fprintf(fplog, "Too many errors.\n");
exit(2);
}
}
// Write track to BRX file. Regardless if bitrate data, killer or no sync.
// Write bitrate track header
sprintf(thdr, "[%4.1f]", (float)track/2 );
if (fwrite(thdr, 6, 1, fpout[density]) != 1)
{
printf("Cannot write track [%d] header (BR%d).\n", track, density);
exit(2);
}
// Save raw bitrate track to BRX file
if (fwrite(buffer, NIB_TRACK_LENGTH-6, 1, fpout[density]) != 1)
{
printf("Cannot write track [%d] data (BR%d).\n", track, density);
exit(2);
}
} // for (density = 0; density <= 3; density++)
if (DBG_IHS)
{
// Print "best" density for reading,
t1 = Scan_Track_SCPlus_IHS(fd, track, buffer);
printf(">>%d\n", t1);
fprintf(fplog, ">>%d\n", t1);
}
// Register track in BRX header index
for (m=0; m < 4; m++)
header[ 16 + ((track-2) * 4) + m ] = (dw >> m*8) & 0xff;
// Update file offset
dw += NIB_TRACK_LENGTH; // = 0x2000
printf("\n");
fprintf(fplog, "\n");
} // for (track = start_track; track <= end_track; track += track_inc)
// Update BRX headers and close
for (density=0; density < 4; density++)
{
rewind(fpout[density]);
sprintf(header, "BR%d-1541", density);
if (fwrite(header, sizeof(header), 1, fpout[density]) != 1)
{
printf("Error updating BRX header (BR%d).\n", density);
exit(2);
}
fclose(fpout[density]);
}
finish2:
// turn SCPlus IHS off
send_mnib_cmd(fd, FL_IHS_OFF, NULL, 0);
burst_read(fd);
return 0;
}
// Bitrate Statistics
// buffer = {{0-5}FF}55
int BitrateStats(BYTE *buffer, char *logline, unsigned short NumSync)
{
char workstr[50];
int j, k, m, total, subtotal, avr, SyncNum;
int SectorStats[NIB_TRACK_LENGTH], TrackStats[6], SectorAverages[NIB_TRACK_LENGTH], work[6];
logline[0] = '\0';
SectorStats[0] = '\0';
SectorAverages[0] = '\0';
k=0;
total=0;
SyncNum=0;
for (j=0; j < 6; j++)
{
TrackStats[j]=0;
work[j]=0;
}
for (j=0; j < NIB_TRACK_LENGTH-6; j++)
{
if (buffer[j] == 0x55)
{
SectorStats[k++] = 0x55;
strcat(logline, "<55>");
// Buffer needs cleaning before dumping to disk
for (m=j+1; m < NIB_TRACK_LENGTH; m++) buffer[m] = 0;
break;
}
if (buffer[j] != 0xFF) work[buffer[j]]++;
else
{
SyncNum += 1;
subtotal=0; avr=0;
strcat(logline, "[");
for (m=0; m < 6; m++)
{
SectorStats[k++] = work[m];
TrackStats[m]+= work[m];
sprintf(workstr, "%.4d",work[m]);
if (m < 6) strcat(workstr, ",");
strcat(logline, workstr);
subtotal+= work[m];
avr+= work[m]*(m+1);
work[m] = 0;
}
total+= subtotal;
SectorStats[k++] = 0xFF;
strcat(logline, "FF]");
if (subtotal == 0) sprintf(workstr, "<=0.0> ");
else sprintf(workstr, "<=%1.1f> ", (float) avr/subtotal-1);
strcat(logline, workstr);
}
}
if (SyncNum != 0)
{
// Print Track "length"
printf("[%4.1d] ",total);
fprintf(fplog, "[%4.1d] ",total);
if (NumSync > 256)
{
printf("(%4.1d!) <",NumSync);
fprintf(fplog, "(%4.1d!) <",NumSync);
}
else
{
// Print number of detected Syncs
printf("(%4.1dS) <",SyncNum);
fprintf(fplog, "(%4.1dS) <",SyncNum);
}
// Print TrackStat
subtotal=0;
for (m=0; m < 6; m++)
{
printf("%4.1d",TrackStats[m]);
fprintf(fplog, "%4.1d",TrackStats[m]);
subtotal+= TrackStats[m]*(m+1);
if (m < 5)
{
printf(",");
fprintf(fplog, ",");
}
}
if (total == 0) total = subtotal = 1;
printf("> <=%1.1f>", (float) subtotal/total-1);
fprintf(fplog, "><=%1.1f> ", (float) subtotal/total-1);
// Print SectorStats to logfile
fprintf(fplog, logline);
}
else
{
printf("NOSYNC");
fprintf(fplog, "NOSYNC");
}
return(0);
}
// Deep Density Scan Track
// requires 1541/1571 SC+ compatible IHS
BYTE
Scan_Track_SCPlus_IHS(CBM_FILE fd, int track, BYTE *buffer)
{
BYTE density, killer_info;
int j, m, MaxDenso, MaxNum, res;
int TrackStats[4][6], Killer[4];
int dump_retry = 10;
for (density = 0; density <= 3; density++)
{
Killer[density] = 0;
for (j = 0; j <= 5; j++)
TrackStats[density][j] = 0;
}
if (DBG_IHS)
printf("Scan_Track_SCPlus_IHS:\n");
for (density = 0; density <= 3; density++)
{
set_density(fd, density);
/* Scan for killer track! */
send_mnib_cmd(fd, FL_SCANKILLER, NULL, 0);
killer_info = burst_read(fd);
if (killer_info & BM_FF_TRACK)
{
Killer[density] = 1;
if (DBG_IHS)
{
printf("D%d:Killer!\n",density);
fprintf(fplog, "D%d:Killer!\n",density);
}
}
else
{
// Try to get bitrate dump "dump_retry" times
for (m = 0; m < dump_retry; m++)
{
memset(buffer, 0x00, NIB_TRACK_LENGTH);
send_mnib_cmd(fd, FL_DBR_ANALYSIS, NULL, 0);
burst_read(fd);
res = burst_read_n(fd, buffer, NIB_TRACK_LENGTH);
if (!res)
{
printf("(deep scan timeout #%d: T%.1f D%d)", m+1, (float) track/2, density);
fprintf(fplog, "(deep scan timeout #%d: T%.1f D%d)", m+1, (float) track/2, density);
fflush(stdout);
burst_read(fd);
delay(500);
burst_read(fd);
}
else
break;
}
if (res)
{
for (j=0; j < NIB_TRACK_LENGTH; j++)
{
if (buffer[j] == 0x55) break;
if (buffer[j] != 0xFF) TrackStats[density][buffer[j]]++;
}
}
else
{
// Call to "burst_read_n" was 10x unsuccessful.
printf("Too many errors.\n");
fprintf(fplog, "Too many errors.\n");
exit(2);
}
}
}
if (DBG_IHS)
{
for (density = 0; density <= 3; density++)
{
printf(":D%d-K%d: <", density,Killer[density]);
for (j = 0; j <= 5; j++) {
printf("%d", TrackStats[density][j]);
if (j <5) printf(",");
}
printf(">\n");
}
}
// Return BM_FF_TRACK if Killer track detected for all bitrates.
if (Killer[0] == 1 || Killer[1] == 1 || Killer[2] == 1 || Killer[3] == 1)
return(get_default_bitrate(track) | BM_FF_TRACK);
// We may have found something, determine max density.
MaxDenso = MaxNum = 0;
for (density = 0; density <= 3; density++)
for (j = 0; j <= 5; j++)
if (TrackStats[density][j] >= MaxNum)
{
MaxDenso = j;
MaxNum = TrackStats[density][j];
}
if (DBG_IHS)
printf(">MaxDenso=%d, MaxNum=%d - ",MaxDenso,MaxNum);
// Return BM_NO_SYNC if no Syncs detected for all bitrates.
if (MaxNum == 0)
return(get_default_bitrate(track) | BM_NO_SYNC);
// Normalize MaxDenso
if (MaxDenso == 5) MaxDenso = 4;
if (MaxDenso > 0) MaxDenso -= 1;
return((BYTE)MaxDenso);
}
// read drive memory location, returns 8bit value from 16bit address
static BYTE
read_mem(CBM_FILE fd, unsigned short addr)
{
send_mnib_cmd(fd, FL_READ_MEM, NULL, 0);
burst_write(fd, (BYTE)(addr & 0xff) );
burst_write(fd, (BYTE)((addr >> 8) & 0xff) );
return burst_read(fd);
}
// return default bitrate for track
static BYTE
get_default_bitrate(int track)
{
return (speed_map[track/2]);
}