ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/sys_windows.cpp
(Generate patch)

Comparing BasiliskII/src/Windows/sys_windows.cpp (file contents):
Revision 1.1 by gbeauche, 2004-12-05T17:11:15Z vs.
Revision 1.4 by gbeauche, 2006-05-08T12:15:58Z

# Line 1 | Line 1
1   /*
2   *  sys_windows.cpp - System dependent routines, Windows implementation
3   *
4 < *  Basilisk II (C) 1997-2004 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 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
# Line 59 | Line 59 | struct file_handle {
59          bool is_media_present;
60   };
61  
62 + // Open file handles
63 + struct open_file_handle {
64 +        file_handle *fh;
65 +        open_file_handle *next;
66 + };
67 + static open_file_handle *open_file_handles = NULL;
68 +
69   // File handle of first floppy drive (for SysMountFirstFloppy())
70   static file_handle *first_floppy = NULL;
71  
# Line 66 | Line 73 | static file_handle *first_floppy = NULL;
73   static const int CD_READ_AHEAD_SECTORS = 16;
74   static char *sector_buffer = NULL;
75  
76 + // Prototypes
77 + static bool is_cdrom_readable(file_handle *fh);
78 +
79  
80   /*
81   *  Initialization
# Line 93 | Line 103 | void SysExit(void)
103  
104  
105   /*
106 + *  Manage open file handles
107 + */
108 +
109 + static void sys_add_file_handle(file_handle *fh)
110 + {
111 +        open_file_handle *p = new open_file_handle;
112 +        p->fh = fh;
113 +        p->next = open_file_handles;
114 +        open_file_handles = p;
115 + }
116 +
117 + static void sys_remove_file_handle(file_handle *fh)
118 + {
119 +        open_file_handle *p = open_file_handles;
120 +        open_file_handle *q = NULL;
121 +
122 +        while (p) {
123 +                if (p->fh == fh) {
124 +                        if (q)
125 +                                q->next = p->next;
126 +                        else
127 +                                open_file_handles = p->next;
128 +                        delete p;
129 +                        break;
130 +                }
131 +                q = p;
132 +                p = p->next;
133 +        }
134 + }
135 +
136 +
137 + /*
138 + *  Mount removable media now
139 + */
140 +
141 + void mount_removable_media(int media)
142 + {
143 +        for (open_file_handle *p = open_file_handles; p != NULL; p = p->next) {
144 +                file_handle * const fh = p->fh;
145 +
146 +                if (fh->is_cdrom && (media & MEDIA_CD)) {
147 +                        cache_clear(&fh->cache);
148 +                        fh->start_byte = 0;
149 +
150 +                        if (fh->fh && fh->fh != INVALID_HANDLE_VALUE)
151 +                                CloseHandle(fh->fh);
152 +
153 +                        // Re-open device
154 +                        char device_name[MAX_PATH];
155 +                        sprintf(device_name, "\\\\.\\%c:", fh->name[0]);
156 +                        fh->fh = CreateFile(
157 +                                device_name,
158 +                                GENERIC_READ,
159 +                                FILE_SHARE_READ | FILE_SHARE_WRITE,
160 +                                NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
161 +
162 +                        if (fh->fh != INVALID_HANDLE_VALUE) {
163 +                                fh->is_media_present = is_cdrom_readable(fh);
164 +                                if (fh->is_media_present)
165 +                                        MountVolume(fh);
166 +                        } else {
167 +                                fh->is_media_present = false;
168 +                        }
169 +                }
170 +        }
171 + }
172 +
173 +
174 + /*
175 + *  Account for media that has just arrived
176 + */
177 +
178 + void SysMediaArrived(void)
179 + {
180 +        mount_removable_media(MEDIA_REMOVABLE);
181 + }
182 +
183 +
184 + /*
185 + *  Account for media that has just been removed
186 + */
187 +
188 + void SysMediaRemoved(void)
189 + {
190 + }
191 +
192 +
193 + /*
194   *  Mount first floppy disk
195   */
196  
# Line 350 | Line 448 | void *Sys_open(const char *path_name, bo
448                                  fh->start_byte = 0;
449                                  fh->is_floppy = false;
450                                  fh->is_cdrom = true;
451 +                                memset(&fh->cache, 0, sizeof(cachetype));
452 +                                cache_init(&fh->cache);
453 +                                cache_clear(&fh->cache);
454                                  if (!PrefsFindBool("nocdrom"))
455                                          fh->is_media_present = is_cdrom_readable(fh);
456                          }
# Line 399 | Line 500 | void *Sys_open(const char *path_name, bo
500          if (fh->is_floppy && first_floppy == NULL)
501                  first_floppy = fh;
502  
503 +        if (fh)
504 +                sys_add_file_handle(fh);
505 +
506          return fh;
507   }
508  
# Line 413 | Line 517 | void Sys_close(void *arg)
517          if (!fh)
518                  return;
519  
520 +        sys_remove_file_handle(fh);
521 +
522          if (fh->is_cdrom) {
523                  cache_final(&fh->cache);
524                  SysAllowRemoval((void *)fh);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines