--- cwcbm/common.h 2004/01/07 15:37:45 1.1 +++ cwcbm/common.h 2004/01/07 16:53:58 1.2 @@ -1,12 +1,22 @@ /* * 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 +#include +#include +#include +#include +#include +#include +#include +#include + + /* Number of tracks (tracks are numbered 1..NUM_TRACKS) */ #define NUM_TRACKS 35 @@ -16,74 +26,68 @@ /* Bytes per sector */ #define SECTOR_SIZE 256 -/* 1541 crystal frequency (16 MHz) */ -#define CRYSTAL_FREQ 16000000 - -/* 1541 RPM */ -#define NOMINAL_RPM 300 - -/* 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 -}; +extern const int std_speed[NUM_TRACKS + 1]; /* 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 -}; - -/* Actual RPM of the drive, and double step flag */ -static int drive_rpm = 300; -static int double_step = 0; +extern const int num_sectors[NUM_TRACKS + 1]; + + +/* 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; + /* 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; +/* Track buffer */ +extern unsigned char track_buf[MAX_SECTORS * SECTOR_SIZE]; /* 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); + +/* Seek to given CBM track (1..35) and select correct side and speed zone */ +extern void seek_to(int drive, int track); + +/* + * 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); + +/* Start drive */ +extern void start_drive(int drive); + +/* Stop drive */ +extern void stop_drive(int drive); #endif