ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/IEC.cpp
(Generate patch)

Comparing Frodo4/Src/IEC.cpp (file contents):
Revision 1.7 by cebix, 2004-01-14T16:54:46Z vs.
Revision 1.8 by cebix, 2004-01-14T17:26:29Z

# Line 49 | Line 49
49   #include "1541t64.h"
50   #include "Prefs.h"
51   #include "Display.h"
52 + #include "main.h"
53 +
54 +
55 + // IEC command codes
56 + enum {
57 +        CMD_DATA = 0x60,        // Data transfer
58 +        CMD_CLOSE = 0xe0,       // Close channel
59 +        CMD_OPEN = 0xf0         // Open channel
60 + };
61 +
62 + // IEC ATN codes
63 + enum {
64 +        ATN_LISTEN = 0x20,
65 +        ATN_UNLISTEN = 0x30,
66 +        ATN_TALK = 0x40,
67 +        ATN_UNTALK = 0x50
68 + };
69  
70  
71   /*
72   *  Constructor: Initialize variables
73   */
74  
75 + Drive *IEC::create_drive(const char *path)
76 + {
77 +        if (IsDirectory(path)) {
78 +                // Mount host directory
79 +                return new FSDrive(this, path);
80 +        } else {
81 +                // Not a directory, check for mountable file type
82 +                int type;
83 +                if (IsMountableFile(path, type)) {
84 +                        if (type == FILE_IMAGE) {
85 +                                // Mount disk image
86 +                                return new ImageDrive(this, path);
87 +                        } else {
88 +                                // Mount archive type file
89 +                                return new ArchDrive(this, path);
90 +                        }
91 +                } else {
92 +                        // Unknown file type
93 +                        // print error?
94 +                }
95 +        }
96 + }
97 +
98   IEC::IEC(C64Display *display) : the_display(display)
99   {
100          int i;
# Line 63 | Line 103 | IEC::IEC(C64Display *display) : the_disp
103          for (i=0; i<4; i++)
104                  drive[i] = NULL;        // Important because UpdateLEDs is called from the drive constructors (via set_error)
105  
106 <        if (!ThePrefs.Emul1541Proc)
107 <                for (i=0; i<4; i++) {
108 <                        if (ThePrefs.DriveType[i] == DRVTYPE_DIR)
109 <                                drive[i] = new FSDrive(this, ThePrefs.DrivePath[i]);
70 <                        else if (ThePrefs.DriveType[i] == DRVTYPE_D64)
71 <                                drive[i] = new ImageDrive(this, ThePrefs.DrivePath[i]);
72 <                        else
73 <                                drive[i] = new ArchDrive(this, ThePrefs.DrivePath[i]);
74 <                }
106 >        if (!ThePrefs.Emul1541Proc) {
107 >                for (i=0; i<4; i++)
108 >                        drive[i] = create_drive(ThePrefs.DrivePath[i]);
109 >        }
110  
111          listener_active = talker_active = false;
112          listening = false;
# Line 112 | Line 147 | void IEC::Reset(void)
147   void IEC::NewPrefs(Prefs *prefs)
148   {
149          // Delete and recreate all changed drives
150 <        for (int i=0; i<4; i++)
151 <                if ((ThePrefs.DriveType[i] != prefs->DriveType[i]) || strcmp(ThePrefs.DrivePath[i], prefs->DrivePath[i]) || ThePrefs.Emul1541Proc != prefs->Emul1541Proc) {
150 >        for (int i=0; i<4; i++) {
151 >                if (strcmp(ThePrefs.DrivePath[i], prefs->DrivePath[i]) || ThePrefs.Emul1541Proc != prefs->Emul1541Proc) {
152                          delete drive[i];
153                          drive[i] = NULL;        // Important because UpdateLEDs is called from drive constructors (via set_error())
154 <                        if (!prefs->Emul1541Proc) {
155 <                                if (prefs->DriveType[i] == DRVTYPE_DIR)
121 <                                        drive[i] = new FSDrive(this, prefs->DrivePath[i]);
122 <                                else if (prefs->DriveType[i] == DRVTYPE_D64)
123 <                                        drive[i] = new ImageDrive(this, prefs->DrivePath[i]);
124 <                                else
125 <                                        drive[i] = new ArchDrive(this, prefs->DrivePath[i]);
126 <                        }
154 >                        if (!prefs->Emul1541Proc)
155 >                                drive[i] = create_drive(prefs->DrivePath[i]);
156                  }
157 +        }
158  
159          UpdateLEDs();
160   }
# Line 873 | Line 903 | void petscii2ascii(char *dest, const uin
903   {
904          while (n-- && (*dest++ = petscii2ascii(*src++))) ;
905   }
906 +
907 +
908 + /*
909 + *  Check whether file is a mountable disk image or archive file, return type
910 + */
911 +
912 + bool IsMountableFile(const char *path, int &type)
913 + {
914 +        // Read header and determine file size
915 +        uint8 header[64];
916 +        memset(header, 0, sizeof(header));
917 +        FILE *f = fopen(path, "rb");
918 +        if (f == NULL)
919 +                return false;
920 +        fseek(f, 0, SEEK_END);
921 +        long size = ftell(f);
922 +        fseek(f, 0, SEEK_SET);
923 +        fread(header, 1, sizeof(header), f);
924 +        fclose(f);
925 +
926 +        if (IsImageFile(path, header, size)) {
927 +                type = FILE_IMAGE;
928 +                return true;
929 +        } else if (IsArchFile(path, header, size)) {
930 +                type = FILE_ARCH;
931 +                return true;
932 +        } else
933 +                return false;
934 + }
935 +
936 +
937 + /*
938 + *  Read directory of mountable disk image or archive file into c64_dir_entry vector,
939 + *  returns false on error
940 + */
941 +
942 + bool ReadDirectory(const char *path, int type, vector<c64_dir_entry> &vec)
943 + {
944 +        vec.clear();
945 +        switch (type) {
946 +                case FILE_IMAGE:
947 +                        return ReadImageDirectory(path, vec);
948 +                case FILE_ARCH:
949 +                        return ReadArchDirectory(path, vec);
950 +                default:
951 +                        return false;
952 +        }
953 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines