Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

1541job.h

Go to the documentation of this file.
00001 /*
00002  *  1541job.h - Emulation of 1541 GCR disk reading/writing
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  */
00006 
00007 #ifndef _1541JOB_H
00008 #define _1541JOB_H
00009 
00010 
00011 class MOS6502_1541;
00012 class Prefs;
00013 class C64;
00014 struct Job1541State;
00015 
00016 class Job1541 {
00017 public:
00018         Job1541(uint8 *ram1541, C64* c64);
00019         ~Job1541();
00020 
00021         void GetState(Job1541State *state);
00022         void SetState(Job1541State *state);
00023         void NewPrefs(Prefs *prefs);
00024         void MoveHeadOut(void);
00025         void MoveHeadIn(void);
00026         bool SyncFound(void);
00027         uint8 ReadGCRByte(void);
00028         uint8 WPState(void);
00029         void WriteSector(void);
00030         void FormatTrack(void);
00031 
00032 private:
00033         void open_d64_file(char *filepath);
00034         void close_d64_file(void);
00035         bool read_sector(int track, int sector, uint8 *buffer);
00036         bool write_sector(int track, int sector, uint8 *buffer);
00037         void format_disk(void);
00038         int secnum_from_ts(int track, int sector);
00039         int offset_from_ts(int track, int sector);
00040         void gcr_conv4(uint8 *from, uint8 *to);
00041         void sector2gcr(int track, int sector);
00042         void disk2gcr(void);
00043 
00044         uint8 *ram;                             // Pointer to 1541 RAM
00045         FILE *the_file;                 // File pointer for .d64 file
00046         int image_header;               // Length of .d64/.x64 file header
00047 
00048         uint8 id1, id2;                 // ID of disk
00049         uint8 error_info[683];  // Sector error information (1 byte/sector)
00050 
00051         uint8 *gcr_data;                // Pointer to GCR encoded disk data
00052         uint8 *gcr_ptr;                 // Pointer to GCR data under R/W head
00053         uint8 *gcr_track_start; // Pointer to start of GCR data of current track
00054         uint8 *gcr_track_end;   // Pointer to end of GCR data of current track
00055         int current_halftrack;  // Current halftrack number (2..70)
00056 
00057         bool write_protected;   // Flag: Disk write-protected
00058         bool disk_changed;              // Flag: Disk changed (WP sensor strobe control)
00059         Prefs& ThePrefs;
00060 };
00061 
00062 // 1541 GCR state
00063 struct Job1541State {
00064         int current_halftrack;
00065         uint32 gcr_ptr;
00066         bool write_protected;
00067         bool disk_changed;
00068 };
00069 
00070 
00071 /*
00072  *  Check if R/W head is over SYNC
00073  */
00074 
00075 inline bool Job1541::SyncFound(void)
00076 {
00077         if (*gcr_ptr == 0xff)
00078                 return true;
00079         else {
00080                 gcr_ptr++;              // Rotate disk
00081                 if (gcr_ptr == gcr_track_end)
00082                         gcr_ptr = gcr_track_start;
00083                 return false;
00084         }
00085 }
00086 
00087 
00088 /*
00089  *  Read one GCR byte from disk
00090  */
00091 
00092 inline uint8 Job1541::ReadGCRByte(void)
00093 {
00094         uint8 byte = *gcr_ptr++;        // Rotate disk
00095         if (gcr_ptr == gcr_track_end)
00096                 gcr_ptr = gcr_track_start;
00097         return byte;
00098 }
00099 
00100 
00101 /*
00102  *  Return state of write protect sensor
00103  */
00104 
00105 inline uint8 Job1541::WPState(void)
00106 {
00107         if (disk_changed) {     // Disk change -> WP sensor strobe
00108                 disk_changed = false;
00109                 return write_protected ? 0x10 : 0;
00110         } else
00111                 return write_protected ? 0 : 0x10;
00112 }
00113 
00114 #endif

Generated on Tue Feb 8 04:07:14 2005 for E32frodo by doxygen 1.3.3