1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
$NetBSD: patch-ad,v 1.1.1.1 2004/07/26 18:23:25 dillo Exp $
--- src/gens/segacd/cd_file.c.orig 2004-05-18 22:34:00.000000000 +0200
+++ src/gens/segacd/cd_file.c
@@ -39,7 +39,7 @@ FILE_End (void)
int
Load_ISO (char *buf, char *iso_name)
{
- FILE *File_Size;
+ int fmt;
int i, j, num_track, Cur_LBA;
FILE *tmp_file;
char tmp_name[1024], tmp_ext[10];
@@ -52,41 +52,62 @@ Load_ISO (char *buf, char *iso_name)
Unload_ISO ();
- if (Detect_Format (iso_name) == SEGACD_IMAGE + 1)
+ fmt = Detect_Format (iso_name);
+ if (fmt == SEGACD_IMAGE + 1)
Tracks[0].Type = TYPE_BIN;
- else if (Detect_Format (iso_name) == SEGACD_IMAGE)
+ else if (fmt == SEGACD_IMAGE)
Tracks[0].Type = TYPE_ISO;
else
return -2;
- File_Size = fopen (iso_name, "rb");
- fseek (File_Size, 0, SEEK_END);
- Tracks[0].Lenght = ftell (File_Size);
- fseek (File_Size, 0, SEEK_SET);
+ if (!stricmp (".chd", &iso_name[strlen (iso_name) -4]))
+ {
+ Tracks[0].F = NULL;
+ Tracks[0].chd = chd_open(iso_name, NULL);
+
+ if (Tracks[0].chd == NULL)
+ {
+ Tracks[0].Type = 0;
+ Tracks[0].Lenght = 0;
+ return -1;
+ }
- if (Tracks[0].Type == TYPE_ISO)
- Tracks[0].Lenght >>= 11; // size in sectors
+ Tracks[0].Lenght = Tracks[0].chd->total_len;
+
+ if (Tracks[0].Type == TYPE_ISO)
+ chd_read_range(Tracks[0].chd, buf, 0x100, 0x200);
+ else
+ chd_read_range(Tracks[0].chd, buf, 0x110, 0x200);
+ }
else
- Tracks[0].Lenght /= 2352; // size in sectors
+ {
+ Tracks[0].F = fopen (iso_name, "rb");
+ Tracks[0].chd = NULL;
+
+ if (Tracks[0].F == NULL)
+ {
+ Tracks[0].Type = 0;
+ Tracks[0].Lenght = 0;
+ return -1;
+ }
- fclose (File_Size);
+ fseek (Tracks[0].F, 0, SEEK_END);
+ Tracks[0].Lenght = ftell (Tracks[0].F);
- Tracks[0].F = fopen (iso_name, "rb");
+ if (Tracks[0].Type == TYPE_ISO)
+ fseek (Tracks[0].F, 0x100, SEEK_SET);
+ else
+ fseek (Tracks[0].F, 0x110, SEEK_SET);
+
+ fread (buf, 1, 0x200, Tracks[0].F);
+ fseek (Tracks[0].F, 0, SEEK_SET);
- if (Tracks[0].F == NULL)
- {
- Tracks[0].Type = 0;
- Tracks[0].Lenght = 0;
- return -1;
}
if (Tracks[0].Type == TYPE_ISO)
- fseek (Tracks[0].F, 0x100, SEEK_SET);
+ Tracks[0].Lenght >>= 11; // size in sectors
else
- fseek (Tracks[0].F, 0x110, SEEK_SET);
-
- fread (buf, 1, 0x200, Tracks[0].F);
- fseek (Tracks[0].F, 0, SEEK_SET);
+ Tracks[0].Lenght /= 2352; // size in sectors
SCD.TOC.First_Track = 1;
@@ -219,6 +240,10 @@ Unload_ISO (void)
Track_Played = 99;
+ if (Tracks[0].chd)
+ chd_close(Tracks[0].chd);
+ Tracks[0].chd = NULL;
+
for (i = 0; i < 100; i++)
{
if (Tracks[i].F)
@@ -237,7 +262,7 @@ FILE_Read_One_LBA_CDC (void)
if (CDD.Control & 0x0100) // DATA
{
- if (Tracks[0].F == NULL)
+ if (Tracks[0].F == NULL && Tracks[0].chd == NULL)
return -1;
if (SCD.Cur_LBA < 0)
@@ -254,8 +279,13 @@ FILE_Read_One_LBA_CDC (void)
// memset(cp_buf, 0, 2048);
- fseek (Tracks[0].F, where_read, SEEK_SET);
- fread (cp_buf, 1, 2048, Tracks[0].F);
+ if (Tracks[0].chd != NULL)
+ chd_read_range(Tracks[0].chd, cp_buf, where_read, 2048);
+ else
+ {
+ fseek (Tracks[0].F, where_read, SEEK_SET);
+ fread (cp_buf, 1, 2048, Tracks[0].F);
+ }
#ifdef DEBUG_CD
fprintf (debug_SCD_file, "\n\nRead file CDC 1 data sector :\n");
|