1 |
|
/* |
2 |
|
* IEC.cpp - IEC bus routines, 1541 emulation (DOS level) |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002-2003 Christian Bauer |
4 |
> |
* Frodo (C) 1994-1997,2002-2004 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
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; |
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 T64Drive(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; |
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 T64Drive(this, prefs->DrivePath[i]); |
126 |
< |
} |
154 |
> |
if (!prefs->Emul1541Proc) |
155 |
> |
drive[i] = create_drive(prefs->DrivePath[i]); |
156 |
|
} |
157 |
+ |
} |
158 |
|
|
159 |
|
UpdateLEDs(); |
160 |
|
} |
878 |
|
* Convert PETSCII<->ASCII |
879 |
|
*/ |
880 |
|
|
881 |
< |
char ascii2petscii(char c) |
881 |
> |
uint8 ascii2petscii(char c) |
882 |
|
{ |
883 |
|
if ((c >= 'A') && (c <= 'Z') || (c >= 'a') && (c <= 'z')) |
884 |
|
return c ^ 0x20; |
885 |
|
return c; |
886 |
|
} |
887 |
|
|
888 |
< |
void ascii2petscii(char *dest, const char *src, int n) |
888 |
> |
void ascii2petscii(uint8 *dest, const char *src, int n) |
889 |
|
{ |
890 |
|
while (n-- && (*dest++ = ascii2petscii(*src++))) ; |
891 |
|
} |
899 |
|
return c; |
900 |
|
} |
901 |
|
|
902 |
< |
void petscii2ascii(char *dest, const char *src, int n) |
902 |
> |
void petscii2ascii(char *dest, const uint8 *src, int n) |
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 |
+ |
} |