filename | src/gdrom/gdrom.c |
changeset | 561:533f6b478071 |
prev | 492:84e33e4dda1c |
next | 613:c2dd87f947b2 |
author | nkeynes |
date | Mon Jan 14 10:23:49 2008 +0000 (16 years ago) |
branch | lxdream-mmu |
permissions | -rw-r--r-- |
last change | Remove asm file and convert to inline (easier to cope with platform conventions) Add breakpoint support Add MMU store-queue support |
view | annotate | diff | log | raw |
2 /**
3 * $Id$
4 *
5 * GD-Rom access functions.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <errno.h>
23 #include "gdrom/ide.h"
24 #include "gdrom/gdrom.h"
25 #include "gdrom/packet.h"
26 #include "dream.h"
28 extern gdrom_disc_t gdrom_disc;
30 gdrom_image_class_t gdrom_image_classes[] = { &cdrom_device_class,
31 &nrg_image_class,
32 &cdi_image_class,
33 &gdi_image_class,
34 NULL };
36 char *gdrom_mode_names[] = { "Mode1", "Mode2", "XA 1", "XA2", "Audio", "GD-Rom" };
37 uint32_t gdrom_sector_size[] = { 2048, 2336, 2048, 2324, 2352, 2336 };
39 gdrom_disc_t gdrom_image_open( const gchar *filename )
40 {
41 const gchar *ext = strrchr(filename, '.');
42 gdrom_disc_t disc = NULL;
44 int fd = open( filename, O_RDONLY | O_NONBLOCK );
45 FILE *f;
46 int i;
47 gdrom_image_class_t extclz = NULL;
49 if( fd == -1 ) {
50 return NULL;
51 }
53 f = fdopen(fd, "ro");
56 /* try extensions */
57 if( ext != NULL ) {
58 ext++; /* Skip the '.' */
59 for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
60 if( gdrom_image_classes[i]->extension != NULL &&
61 strcasecmp( gdrom_image_classes[i]->extension, ext ) == 0 ) {
62 extclz = gdrom_image_classes[i];
63 if( extclz->is_valid_file(f) ) {
64 disc = extclz->open_image_file(filename, f);
65 if( disc != NULL )
66 return disc;
67 }
68 break;
69 }
70 }
71 }
73 /* Okay, fall back to magic */
74 gboolean recognized = FALSE;
75 for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
76 if( gdrom_image_classes[i] != extclz &&
77 gdrom_image_classes[i]->is_valid_file(f) ) {
78 recognized = TRUE;
79 disc = gdrom_image_classes[i]->open_image_file(filename, f);
80 if( disc != NULL )
81 return disc;
82 }
83 }
85 fclose(f);
86 return NULL;
87 }
89 void gdrom_mount_disc( gdrom_disc_t disc )
90 {
91 gdrom_unmount_disc();
92 gdrom_disc = disc;
93 gdrom_image_dump_info( disc );
94 }
96 gboolean gdrom_mount_image( const gchar *filename )
97 {
98 gdrom_disc_t disc = gdrom_image_open(filename);
99 if( disc != NULL ) {
100 gdrom_mount_disc( disc );
101 return TRUE;
102 }
103 return FALSE;
104 }
106 void gdrom_unmount_disc( )
107 {
108 if( gdrom_disc != NULL ) {
109 gdrom_disc->close(gdrom_disc);
110 }
111 gdrom_disc = NULL;
113 }
115 gdrom_disc_t gdrom_get_current_disc()
116 {
117 return gdrom_disc;
118 }
.