1 |
|
/* |
2 |
|
* common.h - Common parts of readcbm and writecbm |
3 |
|
* |
4 |
< |
* Written in 2003 by Christian Bauer <Christian.Bauer@uni-mainz.de> |
4 |
> |
* Written in 2003-2004 by Christian Bauer <Christian.Bauer@uni-mainz.de> |
5 |
|
*/ |
6 |
|
|
7 |
|
#ifndef COMMON_H |
8 |
|
#define COMMON_H |
9 |
|
|
10 |
+ |
#include <stdio.h> |
11 |
+ |
#include <stdlib.h> |
12 |
+ |
#include <string.h> |
13 |
+ |
#include <time.h> |
14 |
+ |
#include <unistd.h> |
15 |
+ |
#include <getopt.h> |
16 |
+ |
#include <errno.h> |
17 |
+ |
#include <sys/io.h> |
18 |
+ |
|
19 |
+ |
|
20 |
|
/* Number of tracks (tracks are numbered 1..NUM_TRACKS) */ |
21 |
|
#define NUM_TRACKS 35 |
22 |
|
|
26 |
|
/* Bytes per sector */ |
27 |
|
#define SECTOR_SIZE 256 |
28 |
|
|
19 |
– |
/* 1541 crystal frequency (16 MHz) */ |
20 |
– |
#define CRYSTAL_FREQ 16000000 |
21 |
– |
|
22 |
– |
/* 1541 RPM */ |
23 |
– |
#define NOMINAL_RPM 300 |
24 |
– |
|
25 |
– |
/* Catweasel frequency (7 MHz) */ |
26 |
– |
#define CW_FREQ 7080500.0 |
29 |
|
|
30 |
|
/* Bit rate for each speed zone */ |
31 |
< |
const int bps[4] = { |
30 |
< |
CRYSTAL_FREQ / 16 / 4, CRYSTAL_FREQ / 15 / 4, |
31 |
< |
CRYSTAL_FREQ / 14 / 4, CRYSTAL_FREQ / 13 / 4 |
32 |
< |
}; |
31 |
> |
extern const int bps[4]; |
32 |
|
|
33 |
|
/* Standard speeds for tracks */ |
34 |
< |
const int std_speed[NUM_TRACKS + 1] = { |
36 |
< |
0, |
37 |
< |
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
38 |
< |
2, 2, 2, 2, 2, 2, 2, |
39 |
< |
1, 1, 1, 1, 1, 1, |
40 |
< |
0, 0, 0, 0, 0 |
41 |
< |
}; |
34 |
> |
extern const int std_speed[NUM_TRACKS + 1]; |
35 |
|
|
36 |
|
/* Number of sectors per track, for all tracks */ |
37 |
< |
const int num_sectors[NUM_TRACKS + 1] = { |
38 |
< |
0, |
39 |
< |
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21, |
40 |
< |
19,19,19,19,19,19,19, |
41 |
< |
18,18,18,18,18,18, |
42 |
< |
17,17,17,17,17 |
43 |
< |
}; |
44 |
< |
|
45 |
< |
/* Actual RPM of the drive, and double step flag */ |
46 |
< |
static int drive_rpm = 300; |
47 |
< |
static int double_step = 0; |
37 |
> |
extern const int num_sectors[NUM_TRACKS + 1]; |
38 |
> |
|
39 |
> |
|
40 |
> |
/* Drive number */ |
41 |
> |
extern int drive_num; |
42 |
> |
|
43 |
> |
/* Actual RPM of the drive, and whether it's 40 or 80 tracks */ |
44 |
> |
extern int drive_rpm; |
45 |
> |
extern int drive_40tracks; |
46 |
> |
|
47 |
> |
/* Name of file to read from/write to */ |
48 |
> |
extern const char *file_name; |
49 |
> |
|
50 |
> |
|
51 |
> |
/* Catweasel controller struct */ |
52 |
> |
extern catweasel_contr c; |
53 |
> |
|
54 |
|
|
55 |
|
/* Clock table (nominal number of Catweasel clocks per inter-flux-change gap) */ |
56 |
< |
static int clock_table[4] = {0, 0, 0, 0}; |
56 |
> |
extern int clock_table[4]; |
57 |
|
|
58 |
|
/* Threshold table */ |
59 |
< |
static int thresh_table[3] = {0, 0, 0}; |
59 |
> |
extern int thresh_table[3]; |
60 |
|
|
62 |
– |
/* Track buffer */ |
63 |
– |
static unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; |
61 |
|
|
62 |
< |
/* Catweasel controller struct */ |
63 |
< |
catweasel_contr c; |
62 |
> |
/* Track buffer */ |
63 |
> |
extern unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; |
64 |
|
|
65 |
|
|
66 |
|
/* Delay specified number of milliseconds */ |
67 |
< |
static void msdelay(int ms) |
68 |
< |
{ |
69 |
< |
usleep(ms * 1000); |
70 |
< |
} |
71 |
< |
|
72 |
< |
|
73 |
< |
/* Set speed zone and tables */ |
74 |
< |
static void set_zone(int track) |
75 |
< |
{ |
76 |
< |
int zone = std_speed[track]; |
77 |
< |
clock_table[0] = 0; |
78 |
< |
clock_table[1] = CW_FREQ * NOMINAL_RPM * 1 / (bps[zone] * drive_rpm); |
79 |
< |
clock_table[2] = CW_FREQ * NOMINAL_RPM * 2 / (bps[zone] * drive_rpm); |
80 |
< |
clock_table[3] = CW_FREQ * NOMINAL_RPM * 3 / (bps[zone] * drive_rpm); |
81 |
< |
thresh_table[0] = (clock_table[0] + clock_table[1]) / 2; |
82 |
< |
thresh_table[1] = (clock_table[1] + clock_table[2]) / 2; |
83 |
< |
thresh_table[2] = (clock_table[2] + clock_table[3]) / 2; |
84 |
< |
} |
67 |
> |
extern void msdelay(int ms); |
68 |
> |
|
69 |
> |
/* Seek to given CBM track (1..35) and select correct side and speed zone */ |
70 |
> |
extern void seek_to(int drive, int track); |
71 |
> |
|
72 |
> |
/* |
73 |
> |
* Parse command line arguments and set |
74 |
> |
* c.iobase |
75 |
> |
* c.type |
76 |
> |
* drive_num |
77 |
> |
* drive_rpm |
78 |
> |
* drive_40tracks |
79 |
> |
* file_name |
80 |
> |
* Also initializes the catweasel_contr struct |
81 |
> |
*/ |
82 |
> |
extern void parse_args(int argc, char **argv); |
83 |
> |
|
84 |
> |
/* Obtain access to I/O ports */ |
85 |
> |
extern void ioport_access(void); |
86 |
> |
|
87 |
> |
/* Start drive */ |
88 |
> |
extern void start_drive(int drive); |
89 |
> |
|
90 |
> |
/* Stop drive */ |
91 |
> |
extern void stop_drive(int drive); |
92 |
|
|
93 |
|
#endif |