| 1 |
/* |
/* |
| 2 |
* common.h - Common parts of readcbm and writecbm |
* common.h - Common parts of readcbm and writecbm |
| 3 |
* |
* |
| 4 |
* Written in 2003 by Christian Bauer <Christian.Bauer@uni-mainz.de> |
* Written in 2003-2004 by Christian Bauer <Christian.Bauer@uni-mainz.de> |
| 5 |
*/ |
*/ |
| 6 |
|
|
| 7 |
#ifndef COMMON_H |
#ifndef COMMON_H |
| 8 |
#define COMMON_H |
#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) */ |
/* Number of tracks (tracks are numbered 1..NUM_TRACKS) */ |
| 21 |
#define NUM_TRACKS 35 |
#define NUM_TRACKS 35 |
| 22 |
|
|
| 26 |
/* Bytes per sector */ |
/* Bytes per sector */ |
| 27 |
#define SECTOR_SIZE 256 |
#define SECTOR_SIZE 256 |
| 28 |
|
|
|
/* 1541 crystal frequency (16 MHz) */ |
|
|
#define CRYSTAL_FREQ 16000000 |
|
|
|
|
|
/* 1541 RPM */ |
|
|
#define NOMINAL_RPM 300 |
|
|
|
|
|
/* Catweasel frequency (7 MHz) */ |
|
|
#define CW_FREQ 7080500.0 |
|
| 29 |
|
|
| 30 |
/* Bit rate for each speed zone */ |
/* Bit rate for each speed zone */ |
| 31 |
const int bps[4] = { |
extern const int bps[4]; |
|
CRYSTAL_FREQ / 16 / 4, CRYSTAL_FREQ / 15 / 4, |
|
|
CRYSTAL_FREQ / 14 / 4, CRYSTAL_FREQ / 13 / 4 |
|
|
}; |
|
| 32 |
|
|
| 33 |
/* Standard speeds for tracks */ |
/* Standard speeds for tracks */ |
| 34 |
const int std_speed[NUM_TRACKS + 1] = { |
extern const int std_speed[NUM_TRACKS + 1]; |
|
0, |
|
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
|
|
2, 2, 2, 2, 2, 2, 2, |
|
|
1, 1, 1, 1, 1, 1, |
|
|
0, 0, 0, 0, 0 |
|
|
}; |
|
| 35 |
|
|
| 36 |
/* Number of sectors per track, for all tracks */ |
/* Number of sectors per track, for all tracks */ |
| 37 |
const int num_sectors[NUM_TRACKS + 1] = { |
extern 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, |
/* Drive number */ |
| 41 |
18,18,18,18,18,18, |
extern int drive_num; |
| 42 |
17,17,17,17,17 |
|
| 43 |
}; |
/* Actual RPM of the drive, and whether it's 40 or 80 tracks */ |
| 44 |
|
extern int drive_rpm; |
| 45 |
/* Actual RPM of the drive, and double step flag */ |
extern int drive_40tracks; |
| 46 |
static int drive_rpm = 300; |
|
| 47 |
static int double_step = 0; |
/* 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) */ |
/* Clock table (nominal number of Catweasel clocks per inter-flux-change gap) */ |
| 56 |
static int clock_table[4] = {0, 0, 0, 0}; |
extern int clock_table[4]; |
| 57 |
|
|
| 58 |
/* Threshold table */ |
/* Threshold table */ |
| 59 |
static int thresh_table[3] = {0, 0, 0}; |
extern int thresh_table[3]; |
| 60 |
|
|
|
/* Track buffer */ |
|
|
static unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; |
|
| 61 |
|
|
| 62 |
/* Catweasel controller struct */ |
/* Track buffer */ |
| 63 |
catweasel_contr c; |
extern unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; |
| 64 |
|
|
| 65 |
|
|
| 66 |
/* Delay specified number of milliseconds */ |
/* Delay specified number of milliseconds */ |
| 67 |
static void msdelay(int ms) |
extern void msdelay(int ms); |
| 68 |
{ |
|
| 69 |
usleep(ms * 1000); |
/* 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 |
/* Set speed zone and tables */ |
* Parse command line arguments and set |
| 74 |
static void set_zone(int track) |
* c.iobase |
| 75 |
{ |
* c.type |
| 76 |
int zone = std_speed[track]; |
* drive_num |
| 77 |
clock_table[0] = 0; |
* drive_rpm |
| 78 |
clock_table[1] = CW_FREQ * NOMINAL_RPM * 1 / (bps[zone] * drive_rpm); |
* drive_40tracks |
| 79 |
clock_table[2] = CW_FREQ * NOMINAL_RPM * 2 / (bps[zone] * drive_rpm); |
* file_name |
| 80 |
clock_table[3] = CW_FREQ * NOMINAL_RPM * 3 / (bps[zone] * drive_rpm); |
* Also initializes the catweasel_contr struct |
| 81 |
thresh_table[0] = (clock_table[0] + clock_table[1]) / 2; |
*/ |
| 82 |
thresh_table[1] = (clock_table[1] + clock_table[2]) / 2; |
extern void parse_args(int argc, char **argv); |
| 83 |
thresh_table[2] = (clock_table[2] + clock_table[3]) / 2; |
|
| 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 |
#endif |