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.3 by gbeauche, 2006-03-28T07:01:19Z

# 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 45 | Line 45 | using std::min;
45   #include "debug.h"
46  
47  
48 + // Supported media types
49 + enum {
50 +        MEDIA_FLOPPY            = 1,
51 +        MEDIA_CD                        = 2,
52 +        MEDIA_HD                        = 4,
53 +        MEDIA_REMOVABLE         = MEDIA_FLOPPY | MEDIA_CD
54 + };
55 +
56   // File handles are pointers to these structures
57   struct file_handle {
58          char *name;                     // Copy of device/file name
# Line 59 | Line 67 | struct file_handle {
67          bool is_media_present;
68   };
69  
70 + // Open file handles
71 + struct open_file_handle {
72 +        file_handle *fh;
73 +        open_file_handle *next;
74 + };
75 + static open_file_handle *open_file_handles = NULL;
76 +
77   // File handle of first floppy drive (for SysMountFirstFloppy())
78   static file_handle *first_floppy = NULL;
79  
# Line 66 | Line 81 | static file_handle *first_floppy = NULL;
81   static const int CD_READ_AHEAD_SECTORS = 16;
82   static char *sector_buffer = NULL;
83  
84 + // Prototypes
85 + static bool is_cdrom_readable(file_handle *fh);
86 +
87  
88   /*
89   *  Initialization
# Line 93 | Line 111 | void SysExit(void)
111  
112  
113   /*
114 + *  Manage open file handles
115 + */
116 +
117 + static void sys_add_file_handle(file_handle *fh)
118 + {
119 +        open_file_handle *p = new open_file_handle;
120 +        p->fh = fh;
121 +        p->next = open_file_handles;
122 +        open_file_handles = p;
123 + }
124 +
125 + static void sys_remove_file_handle(file_handle *fh)
126 + {
127 +        open_file_handle *p = open_file_handles;
128 +        open_file_handle *q = NULL;
129 +
130 +        while (p) {
131 +                if (p->fh == fh) {
132 +                        if (q)
133 +                                q->next = p->next;
134 +                        else
135 +                                open_file_handles = p->next;
136 +                        delete p;
137 +                        break;
138 +                }
139 +                q = p;
140 +                p = p->next;
141 +        }
142 + }
143 +
144 +
145 + /*
146 + *  Mount removable media now
147 + */
148 +
149 + void mount_removable_media(int media)
150 + {
151 +        for (open_file_handle *p = open_file_handles; p != NULL; p = p->next) {
152 +                file_handle * const fh = p->fh;
153 +
154 +                if (fh->is_cdrom && (media & MEDIA_CD)) {
155 +                        cache_clear(&fh->cache);
156 +                        fh->start_byte = 0;
157 +
158 +                        if (fh->fh && fh->fh != INVALID_HANDLE_VALUE)
159 +                                CloseHandle(fh->fh);
160 +
161 +                        // Re-open device
162 +                        char device_name[MAX_PATH];
163 +                        sprintf(device_name, "\\\\.\\%c:", fh->name[0]);
164 +                        fh->fh = CreateFile(
165 +                                device_name,
166 +                                GENERIC_READ,
167 +                                FILE_SHARE_READ | FILE_SHARE_WRITE,
168 +                                NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
169 +
170 +                        if (fh->fh != INVALID_HANDLE_VALUE) {
171 +                                fh->is_media_present = is_cdrom_readable(fh);
172 +                                if (fh->is_media_present)
173 +                                        MountVolume(fh);
174 +                        } else {
175 +                                fh->is_media_present = false;
176 +                        }
177 +                }
178 +        }
179 + }
180 +
181 +
182 + /*
183 + *  Account for media that has just arrived
184 + */
185 +
186 + void SysMediaArrived(void)
187 + {
188 +        mount_removable_media(MEDIA_REMOVABLE);
189 + }
190 +
191 +
192 + /*
193 + *  Account for media that has just been removed
194 + */
195 +
196 + void SysMediaRemoved(void)
197 + {
198 + }
199 +
200 +
201 + /*
202   *  Mount first floppy disk
203   */
204  
# Line 350 | Line 456 | void *Sys_open(const char *path_name, bo
456                                  fh->start_byte = 0;
457                                  fh->is_floppy = false;
458                                  fh->is_cdrom = true;
459 +                                memset(&fh->cache, 0, sizeof(cachetype));
460 +                                cache_init(&fh->cache);
461 +                                cache_clear(&fh->cache);
462                                  if (!PrefsFindBool("nocdrom"))
463                                          fh->is_media_present = is_cdrom_readable(fh);
464                          }
# Line 399 | Line 508 | void *Sys_open(const char *path_name, bo
508          if (fh->is_floppy && first_floppy == NULL)
509                  first_floppy = fh;
510  
511 +        if (fh)
512 +                sys_add_file_handle(fh);
513 +
514          return fh;
515   }
516  
# Line 413 | Line 525 | void Sys_close(void *arg)
525          if (!fh)
526                  return;
527  
528 +        sys_remove_file_handle(fh);
529 +
530          if (fh->is_cdrom) {
531                  cache_final(&fh->cache);
532                  SysAllowRemoval((void *)fh);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines