Lines 54-60
Link Here
|
54 |
}; |
54 |
}; |
55 |
|
55 |
|
56 |
// File handles are pointers to these structures |
56 |
// File handles are pointers to these structures |
57 |
struct file_handle { |
57 |
struct basilisk_file_handle { |
58 |
char *name; // Copy of device/file name |
58 |
char *name; // Copy of device/file name |
59 |
HANDLE fh; |
59 |
HANDLE fh; |
60 |
bool is_file; // Flag: plain file or physical device? |
60 |
bool is_file; // Flag: plain file or physical device? |
Lines 68-88
Link Here
|
68 |
}; |
68 |
}; |
69 |
|
69 |
|
70 |
// Open file handles |
70 |
// Open file handles |
71 |
struct open_file_handle { |
71 |
struct open_basilisk_file_handle { |
72 |
file_handle *fh; |
72 |
basilisk_file_handle *fh; |
73 |
open_file_handle *next; |
73 |
open_basilisk_file_handle *next; |
74 |
}; |
74 |
}; |
75 |
static open_file_handle *open_file_handles = NULL; |
75 |
static open_basilisk_file_handle *open_basilisk_file_handles = NULL; |
76 |
|
76 |
|
77 |
// File handle of first floppy drive (for SysMountFirstFloppy()) |
77 |
// File handle of first floppy drive (for SysMountFirstFloppy()) |
78 |
static file_handle *first_floppy = NULL; |
78 |
static basilisk_file_handle *first_floppy = NULL; |
79 |
|
79 |
|
80 |
// CD-ROM variables |
80 |
// CD-ROM variables |
81 |
static const int CD_READ_AHEAD_SECTORS = 16; |
81 |
static const int CD_READ_AHEAD_SECTORS = 16; |
82 |
static char *sector_buffer = NULL; |
82 |
static char *sector_buffer = NULL; |
83 |
|
83 |
|
84 |
// Prototypes |
84 |
// Prototypes |
85 |
static bool is_cdrom_readable(file_handle *fh); |
85 |
static bool is_cdrom_readable(basilisk_file_handle *fh); |
86 |
|
86 |
|
87 |
|
87 |
|
88 |
/* |
88 |
/* |
Lines 114-138
Link Here
|
114 |
* Manage open file handles |
114 |
* Manage open file handles |
115 |
*/ |
115 |
*/ |
116 |
|
116 |
|
117 |
static void sys_add_file_handle(file_handle *fh) |
117 |
static void sys_add_basilisk_file_handle(basilisk_file_handle *fh) |
118 |
{ |
118 |
{ |
119 |
open_file_handle *p = new open_file_handle; |
119 |
open_basilisk_file_handle *p = new open_basilisk_file_handle; |
120 |
p->fh = fh; |
120 |
p->fh = fh; |
121 |
p->next = open_file_handles; |
121 |
p->next = open_basilisk_file_handles; |
122 |
open_file_handles = p; |
122 |
open_basilisk_file_handles = p; |
123 |
} |
123 |
} |
124 |
|
124 |
|
125 |
static void sys_remove_file_handle(file_handle *fh) |
125 |
static void sys_remove_basilisk_file_handle(basilisk_file_handle *fh) |
126 |
{ |
126 |
{ |
127 |
open_file_handle *p = open_file_handles; |
127 |
open_basilisk_file_handle *p = open_basilisk_file_handles; |
128 |
open_file_handle *q = NULL; |
128 |
open_basilisk_file_handle *q = NULL; |
129 |
|
129 |
|
130 |
while (p) { |
130 |
while (p) { |
131 |
if (p->fh == fh) { |
131 |
if (p->fh == fh) { |
132 |
if (q) |
132 |
if (q) |
133 |
q->next = p->next; |
133 |
q->next = p->next; |
134 |
else |
134 |
else |
135 |
open_file_handles = p->next; |
135 |
open_basilisk_file_handles = p->next; |
136 |
delete p; |
136 |
delete p; |
137 |
break; |
137 |
break; |
138 |
} |
138 |
} |
Lines 148-155
Link Here
|
148 |
|
148 |
|
149 |
void mount_removable_media(int media) |
149 |
void mount_removable_media(int media) |
150 |
{ |
150 |
{ |
151 |
for (open_file_handle *p = open_file_handles; p != NULL; p = p->next) { |
151 |
for (open_basilisk_file_handle *p = open_basilisk_file_handles; p != NULL; p = p->next) { |
152 |
file_handle * const fh = p->fh; |
152 |
basilisk_file_handle * const fh = p->fh; |
153 |
|
153 |
|
154 |
if (fh->is_cdrom && (media & MEDIA_CD)) { |
154 |
if (fh->is_cdrom && (media & MEDIA_CD)) { |
155 |
cache_clear(&fh->cache); |
155 |
cache_clear(&fh->cache); |
Lines 266-272
Link Here
|
266 |
* Can't give too much however, would be annoying, this is difficult.. |
266 |
* Can't give too much however, would be annoying, this is difficult.. |
267 |
*/ |
267 |
*/ |
268 |
|
268 |
|
269 |
static inline int cd_read_with_retry(file_handle *fh, ULONG LBA, int count, char *buf ) |
269 |
static inline int cd_read_with_retry(basilisk_file_handle *fh, ULONG LBA, int count, char *buf ) |
270 |
{ |
270 |
{ |
271 |
if (!fh || !fh->fh) |
271 |
if (!fh || !fh->fh) |
272 |
return 0; |
272 |
return 0; |
Lines 274-280
Link Here
|
274 |
return CdenableSysReadCdBytes(fh->fh, LBA, count, buf); |
274 |
return CdenableSysReadCdBytes(fh->fh, LBA, count, buf); |
275 |
} |
275 |
} |
276 |
|
276 |
|
277 |
static int cd_read(file_handle *fh, cachetype *cptr, ULONG LBA, int count, char *buf) |
277 |
static int cd_read(basilisk_file_handle *fh, cachetype *cptr, ULONG LBA, int count, char *buf) |
278 |
{ |
278 |
{ |
279 |
ULONG l1, l2, cc; |
279 |
ULONG l1, l2, cc; |
280 |
int i, c_count, got_bytes = 0, nblocks, s_inx, ss, first_block; |
280 |
int i, c_count, got_bytes = 0, nblocks, s_inx, ss, first_block; |
Lines 373-379
Link Here
|
373 |
* Check if file handle FH represents a readable CD-ROM |
373 |
* Check if file handle FH represents a readable CD-ROM |
374 |
*/ |
374 |
*/ |
375 |
|
375 |
|
376 |
static bool is_cdrom_readable(file_handle *fh) |
376 |
static bool is_cdrom_readable(basilisk_file_handle *fh) |
377 |
{ |
377 |
{ |
378 |
if (!fh || !fh->fh) |
378 |
if (!fh || !fh->fh) |
379 |
return false; |
379 |
return false; |
Lines 418-424
Link Here
|
418 |
|
418 |
|
419 |
void *Sys_open(const char *path_name, bool read_only) |
419 |
void *Sys_open(const char *path_name, bool read_only) |
420 |
{ |
420 |
{ |
421 |
file_handle * fh = NULL; |
421 |
basilisk_file_handle * fh = NULL; |
422 |
|
422 |
|
423 |
// Parse path name and options |
423 |
// Parse path name and options |
424 |
char name[MAX_PATH]; |
424 |
char name[MAX_PATH]; |
Lines 448-454
Link Here
|
448 |
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
448 |
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
449 |
|
449 |
|
450 |
if (h != INVALID_HANDLE_VALUE) { |
450 |
if (h != INVALID_HANDLE_VALUE) { |
451 |
fh = new file_handle; |
451 |
fh = new basilisk_file_handle; |
452 |
fh->name = strdup(name); |
452 |
fh->name = strdup(name); |
453 |
fh->fh = h; |
453 |
fh->fh = h; |
454 |
fh->is_file = false; |
454 |
fh->is_file = false; |
Lines 487-493
Link Here
|
487 |
} |
487 |
} |
488 |
|
488 |
|
489 |
if (h != INVALID_HANDLE_VALUE) { |
489 |
if (h != INVALID_HANDLE_VALUE) { |
490 |
fh = new file_handle; |
490 |
fh = new basilisk_file_handle; |
491 |
fh->name = strdup(name); |
491 |
fh->name = strdup(name); |
492 |
fh->fh = h; |
492 |
fh->fh = h; |
493 |
fh->is_file = true; |
493 |
fh->is_file = true; |
Lines 509-515
Link Here
|
509 |
first_floppy = fh; |
509 |
first_floppy = fh; |
510 |
|
510 |
|
511 |
if (fh) |
511 |
if (fh) |
512 |
sys_add_file_handle(fh); |
512 |
sys_add_basilisk_file_handle(fh); |
513 |
|
513 |
|
514 |
return fh; |
514 |
return fh; |
515 |
} |
515 |
} |
Lines 521-531
Link Here
|
521 |
|
521 |
|
522 |
void Sys_close(void *arg) |
522 |
void Sys_close(void *arg) |
523 |
{ |
523 |
{ |
524 |
file_handle *fh = (file_handle *)arg; |
524 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
525 |
if (!fh) |
525 |
if (!fh) |
526 |
return; |
526 |
return; |
527 |
|
527 |
|
528 |
sys_remove_file_handle(fh); |
528 |
sys_remove_basilisk_file_handle(fh); |
529 |
|
529 |
|
530 |
if (fh->is_cdrom) { |
530 |
if (fh->is_cdrom) { |
531 |
cache_final(&fh->cache); |
531 |
cache_final(&fh->cache); |
Lines 549-555
Link Here
|
549 |
|
549 |
|
550 |
size_t Sys_read(void *arg, void *buffer, loff_t offset, size_t length) |
550 |
size_t Sys_read(void *arg, void *buffer, loff_t offset, size_t length) |
551 |
{ |
551 |
{ |
552 |
file_handle *fh = (file_handle *)arg; |
552 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
553 |
if (!fh) |
553 |
if (!fh) |
554 |
return 0; |
554 |
return 0; |
555 |
|
555 |
|
Lines 599-605
Link Here
|
599 |
|
599 |
|
600 |
size_t Sys_write(void *arg, void *buffer, loff_t offset, size_t length) |
600 |
size_t Sys_write(void *arg, void *buffer, loff_t offset, size_t length) |
601 |
{ |
601 |
{ |
602 |
file_handle *fh = (file_handle *)arg; |
602 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
603 |
if (!fh) |
603 |
if (!fh) |
604 |
return 0; |
604 |
return 0; |
605 |
|
605 |
|
Lines 629-635
Link Here
|
629 |
|
629 |
|
630 |
loff_t SysGetFileSize(void *arg) |
630 |
loff_t SysGetFileSize(void *arg) |
631 |
{ |
631 |
{ |
632 |
file_handle *fh = (file_handle *)arg; |
632 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
633 |
if (!fh) |
633 |
if (!fh) |
634 |
return true; |
634 |
return true; |
635 |
|
635 |
|
Lines 650-656
Link Here
|
650 |
|
650 |
|
651 |
void SysEject(void *arg) |
651 |
void SysEject(void *arg) |
652 |
{ |
652 |
{ |
653 |
file_handle *fh = (file_handle *)arg; |
653 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
654 |
if (!fh) |
654 |
if (!fh) |
655 |
return; |
655 |
return; |
656 |
|
656 |
|
Lines 688-694
Link Here
|
688 |
|
688 |
|
689 |
bool SysFormat(void *arg) |
689 |
bool SysFormat(void *arg) |
690 |
{ |
690 |
{ |
691 |
file_handle *fh = (file_handle *)arg; |
691 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
692 |
if (!fh) |
692 |
if (!fh) |
693 |
return false; |
693 |
return false; |
694 |
|
694 |
|
Lines 703-709
Link Here
|
703 |
|
703 |
|
704 |
bool SysIsReadOnly(void *arg) |
704 |
bool SysIsReadOnly(void *arg) |
705 |
{ |
705 |
{ |
706 |
file_handle *fh = (file_handle *)arg; |
706 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
707 |
if (!fh) |
707 |
if (!fh) |
708 |
return true; |
708 |
return true; |
709 |
|
709 |
|
Lines 717-723
Link Here
|
717 |
|
717 |
|
718 |
bool SysIsFixedDisk(void *arg) |
718 |
bool SysIsFixedDisk(void *arg) |
719 |
{ |
719 |
{ |
720 |
file_handle *fh = (file_handle *)arg; |
720 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
721 |
if (!fh) |
721 |
if (!fh) |
722 |
return true; |
722 |
return true; |
723 |
|
723 |
|
Lines 736-742
Link Here
|
736 |
|
736 |
|
737 |
bool SysIsDiskInserted(void *arg) |
737 |
bool SysIsDiskInserted(void *arg) |
738 |
{ |
738 |
{ |
739 |
file_handle *fh = (file_handle *)arg; |
739 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
740 |
if (!fh) |
740 |
if (!fh) |
741 |
return false; |
741 |
return false; |
742 |
|
742 |
|
Lines 761-767
Link Here
|
761 |
|
761 |
|
762 |
void SysPreventRemoval(void *arg) |
762 |
void SysPreventRemoval(void *arg) |
763 |
{ |
763 |
{ |
764 |
file_handle *fh = (file_handle *)arg; |
764 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
765 |
if (!fh) |
765 |
if (!fh) |
766 |
return; |
766 |
return; |
767 |
|
767 |
|
Lines 776-782
Link Here
|
776 |
|
776 |
|
777 |
void SysAllowRemoval(void *arg) |
777 |
void SysAllowRemoval(void *arg) |
778 |
{ |
778 |
{ |
779 |
file_handle *fh = (file_handle *)arg; |
779 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
780 |
if (!fh) |
780 |
if (!fh) |
781 |
return; |
781 |
return; |
782 |
|
782 |
|
Lines 791-797
Link Here
|
791 |
|
791 |
|
792 |
bool SysCDReadTOC(void *arg, uint8 *toc) |
792 |
bool SysCDReadTOC(void *arg, uint8 *toc) |
793 |
{ |
793 |
{ |
794 |
file_handle *fh = (file_handle *)arg; |
794 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
795 |
if (!fh || !fh->fh || !fh->is_cdrom) |
795 |
if (!fh || !fh->fh || !fh->is_cdrom) |
796 |
return false; |
796 |
return false; |
797 |
|
797 |
|
Lines 811-817
Link Here
|
811 |
|
811 |
|
812 |
bool SysCDGetPosition(void *arg, uint8 *pos) |
812 |
bool SysCDGetPosition(void *arg, uint8 *pos) |
813 |
{ |
813 |
{ |
814 |
file_handle *fh = (file_handle *)arg; |
814 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
815 |
if (!fh || !fh->fh || !fh->is_cdrom) |
815 |
if (!fh || !fh->fh || !fh->is_cdrom) |
816 |
return false; |
816 |
return false; |
817 |
|
817 |
|
Lines 841-847
Link Here
|
841 |
|
841 |
|
842 |
bool SysCDPlay(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, uint8 end_m, uint8 end_s, uint8 end_f) |
842 |
bool SysCDPlay(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, uint8 end_m, uint8 end_s, uint8 end_f) |
843 |
{ |
843 |
{ |
844 |
file_handle *fh = (file_handle *)arg; |
844 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
845 |
if (!fh || !fh->fh || !fh->is_cdrom) |
845 |
if (!fh || !fh->fh || !fh->is_cdrom) |
846 |
return false; |
846 |
return false; |
847 |
|
847 |
|
Lines 869-875
Link Here
|
869 |
|
869 |
|
870 |
bool SysCDPause(void *arg) |
870 |
bool SysCDPause(void *arg) |
871 |
{ |
871 |
{ |
872 |
file_handle *fh = (file_handle *)arg; |
872 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
873 |
if (!fh || !fh->fh || !fh->is_cdrom) |
873 |
if (!fh || !fh->fh || !fh->is_cdrom) |
874 |
return false; |
874 |
return false; |
875 |
|
875 |
|
Lines 889-895
Link Here
|
889 |
|
889 |
|
890 |
bool SysCDResume(void *arg) |
890 |
bool SysCDResume(void *arg) |
891 |
{ |
891 |
{ |
892 |
file_handle *fh = (file_handle *)arg; |
892 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
893 |
if (!fh || !fh->fh || !fh->is_cdrom) |
893 |
if (!fh || !fh->fh || !fh->is_cdrom) |
894 |
return false; |
894 |
return false; |
895 |
|
895 |
|
Lines 908-914
Link Here
|
908 |
|
908 |
|
909 |
bool SysCDStop(void *arg, uint8 lead_out_m, uint8 lead_out_s, uint8 lead_out_f) |
909 |
bool SysCDStop(void *arg, uint8 lead_out_m, uint8 lead_out_s, uint8 lead_out_f) |
910 |
{ |
910 |
{ |
911 |
file_handle *fh = (file_handle *)arg; |
911 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
912 |
if (!fh || !fh->fh || !fh->is_cdrom) |
912 |
if (!fh || !fh->fh || !fh->is_cdrom) |
913 |
return false; |
913 |
return false; |
914 |
|
914 |
|
Lines 928-934
Link Here
|
928 |
|
928 |
|
929 |
bool SysCDScan(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, bool reverse) |
929 |
bool SysCDScan(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, bool reverse) |
930 |
{ |
930 |
{ |
931 |
file_handle *fh = (file_handle *)arg; |
931 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
932 |
if (!fh || !fh->fh || !fh->is_cdrom) |
932 |
if (!fh || !fh->fh || !fh->is_cdrom) |
933 |
return false; |
933 |
return false; |
934 |
|
934 |
|
Lines 953-959
Link Here
|
953 |
|
953 |
|
954 |
void SysCDSetVolume(void *arg, uint8 left, uint8 right) |
954 |
void SysCDSetVolume(void *arg, uint8 left, uint8 right) |
955 |
{ |
955 |
{ |
956 |
file_handle *fh = (file_handle *)arg; |
956 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
957 |
if (!fh || !fh->fh || !fh->is_cdrom) |
957 |
if (!fh || !fh->fh || !fh->is_cdrom) |
958 |
return; |
958 |
return; |
959 |
|
959 |
|
Lines 979-985
Link Here
|
979 |
|
979 |
|
980 |
void SysCDGetVolume(void *arg, uint8 &left, uint8 &right) |
980 |
void SysCDGetVolume(void *arg, uint8 &left, uint8 &right) |
981 |
{ |
981 |
{ |
982 |
file_handle *fh = (file_handle *)arg; |
982 |
basilisk_file_handle *fh = (basilisk_file_handle *)arg; |
983 |
if (!fh) |
983 |
if (!fh) |
984 |
return; |
984 |
return; |
985 |
|
985 |
|