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