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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*********************************************************************
Code to interface the image code with CHD-CD core.
Based on harddriv.c by Raphael Nabet 2003
*********************************************************************/
#include "emu.h"
#include "cdrom.h"
#include "chd_cd.h"
static const char *const error_strings[] =
{
"no error",
"no drive interface",
"out of memory",
"invalid file",
"invalid parameter",
"invalid data",
"file not found",
"requires parent",
"file not writeable",
"read error",
"write error",
"codec error",
"invalid parent",
"hunk out of range",
"decompression error",
"compression error",
"can't create file",
"can't verify file"
"operation not supported",
"can't find metadata",
"invalid metadata size",
"unsupported CHD version"
};
static const char *chd_get_error_string(int chderr)
{
if ((chderr < 0 ) || (chderr >= ARRAY_LENGTH(error_strings)))
return NULL;
return error_strings[chderr];
}
static OPTION_GUIDE_START(cd_option_guide)
OPTION_INT('K', "hunksize", "Hunk Bytes")
OPTION_GUIDE_END
static const char cd_option_spec[] = "K512/1024/2048/[4096]";
// device type definition
const device_type CDROM = &device_creator<cdrom_image_device>;
//-------------------------------------------------
// cdrom_image_device - constructor
//-------------------------------------------------
cdrom_image_device::cdrom_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, CDROM, "Cdrom", tag, owner, clock),
device_image_interface(mconfig, *this)
{
}
//-------------------------------------------------
// cdrom_image_device - destructor
//-------------------------------------------------
cdrom_image_device::~cdrom_image_device()
{
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void cdrom_image_device::device_config_complete()
{
// inherit a copy of the static data
const cdrom_interface *intf = reinterpret_cast<const cdrom_interface *>(static_config());
if (intf != NULL)
*static_cast<cdrom_interface *>(this) = *intf;
// or initialize to defaults if none provided
else
{
memset(&m_interface, 0, sizeof(m_interface));
memset(&m_device_displayinfo, 0, sizeof(m_device_displayinfo));
}
image_device_format *format = global_alloc_clear(image_device_format);;
format->m_index = 0;
format->m_name = "chdcd";
format->m_description = "CHD CD-ROM drive";
format->m_extensions = "chd";
format->m_optspec = cd_option_spec;
format->m_next = NULL;
m_formatlist = format;
// set brief and instance name
update_names();
}
const option_guide *cdrom_image_device::create_option_guide() const
{
return cd_option_guide;
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void cdrom_image_device::device_start()
{
m_cdrom_handle = NULL;
}
bool cdrom_image_device::call_load()
{
chd_error err = (chd_error)0;
chd_file *chd = NULL;
astring tempstring;
if (software_entry() == NULL)
{
err = chd_open_file( image_core_file(), CHD_OPEN_READ, NULL, &chd ); /* CDs are never writeable */
if ( err )
goto error;
} else {
chd = get_disk_handle(device().machine(), device().subtag(tempstring,"cdrom"));
}
/* open the CHD file */
m_cdrom_handle = cdrom_open( chd );
if ( ! m_cdrom_handle )
goto error;
return IMAGE_INIT_PASS;
error:
if ( chd )
chd_close( chd );
if ( err )
seterror( IMAGE_ERROR_UNSPECIFIED, chd_get_error_string( err ) );
return IMAGE_INIT_FAIL;
}
void cdrom_image_device::call_unload()
{
assert(m_cdrom_handle);
cdrom_close(m_cdrom_handle);
m_cdrom_handle = NULL;
}
|