--- cwcbm/common.h 2004/01/07 15:37:45 1.1 +++ cwcbm/common.h 2004/01/10 14:05:59 1.3 @@ -1,89 +1,99 @@ /* * common.h - Common parts of readcbm and writecbm * - * Written in 2003 by Christian Bauer + * Written in 2003-2004 by Christian Bauer */ #ifndef COMMON_H #define COMMON_H -/* Number of tracks (tracks are numbered 1..NUM_TRACKS) */ -#define NUM_TRACKS 35 +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Disk format description */ +struct format_t { + int sides; + int tracks_per_side; + const int *bps; // bps for each speed zone + const int *std_speed; // zone for each track + const int *num_sectors; // number of sectors for each track +}; + +/* Selected format */ +extern const struct format_t *format; + /* Maximum number of sectors per track */ -#define MAX_SECTORS 21 +#define MAX_SECTORS 29 /* Bytes per sector */ #define SECTOR_SIZE 256 -/* 1541 crystal frequency (16 MHz) */ -#define CRYSTAL_FREQ 16000000 - -/* 1541 RPM */ -#define NOMINAL_RPM 300 +/* Track buffer */ +extern unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; -/* Catweasel frequency (7 MHz) */ -#define CW_FREQ 7080500.0 /* Bit rate for each speed zone */ -const int bps[4] = { - CRYSTAL_FREQ / 16 / 4, CRYSTAL_FREQ / 15 / 4, - CRYSTAL_FREQ / 14 / 4, CRYSTAL_FREQ / 13 / 4 -}; +extern const int bps[4]; -/* Standard speeds for tracks */ -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 -}; -/* Number of sectors per track, for all tracks */ -const int num_sectors[NUM_TRACKS + 1] = { - 0, - 21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21, - 19,19,19,19,19,19,19, - 18,18,18,18,18,18, - 17,17,17,17,17 -}; +/* Drive number */ +extern int drive_num; + +/* Actual RPM of the drive, and whether it's 40 or 80 tracks */ +extern int drive_rpm; +extern int drive_40tracks; + +/* Name of file to read from/write to */ +extern const char *file_name; + + +/* Catweasel controller struct */ +extern catweasel_contr c; -/* Actual RPM of the drive, and double step flag */ -static int drive_rpm = 300; -static int double_step = 0; /* Clock table (nominal number of Catweasel clocks per inter-flux-change gap) */ -static int clock_table[4] = {0, 0, 0, 0}; +extern int clock_table[4]; /* Threshold table */ -static int thresh_table[3] = {0, 0, 0}; +extern int thresh_table[3]; -/* Track buffer */ -static unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; -/* Catweasel controller struct */ -catweasel_contr c; +/* + * Parse command line arguments and set + * c.iobase + * c.type + * drive_num + * drive_rpm + * drive_40tracks + * file_name + * Also initializes the catweasel_contr struct + */ +extern void parse_args(int argc, char **argv); +/* Obtain access to I/O ports */ +extern void ioport_access(void); /* Delay specified number of milliseconds */ -static void msdelay(int ms) -{ - usleep(ms * 1000); -} - - -/* Set speed zone and tables */ -static void set_zone(int track) -{ - int zone = std_speed[track]; - clock_table[0] = 0; - clock_table[1] = CW_FREQ * NOMINAL_RPM * 1 / (bps[zone] * drive_rpm); - clock_table[2] = CW_FREQ * NOMINAL_RPM * 2 / (bps[zone] * drive_rpm); - clock_table[3] = CW_FREQ * NOMINAL_RPM * 3 / (bps[zone] * drive_rpm); - thresh_table[0] = (clock_table[0] + clock_table[1]) / 2; - thresh_table[1] = (clock_table[1] + clock_table[2]) / 2; - thresh_table[2] = (clock_table[2] + clock_table[3]) / 2; -} +extern void msdelay(int ms); + +/* Select disk format */ +extern void select_format(int type); + +/* Seek to given CBM track (1..35) and select correct side and speed zone */ +extern void seek_to(int drive, int track); + +/* Start drive */ +extern void start_drive(int drive); + +/* Stop drive */ +extern void stop_drive(int drive); #endif