summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/dvdrom.cpp
blob: 36dc29e7215234ec29bf32165b6f1c976567cf16 (plain) (blame)
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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles,R. Belmont
/***************************************************************************

    dvdrom.c

    Generic MAME DVD-ROM utilties - build IDE and SCSI DVD-ROMs on top of this

***************************************************************************/

#include "dvdrom.h"

#include "corestr.h"
#include "osdfile.h"
#include "strformat.h"

#include <cassert>
#include <cstdlib>



/**
 * @fn  constructor
 *
 * @brief   Open a dvdrom for a file.
 *
 * @param   inputfile   The inputfile.
 */

dvdrom_file::dvdrom_file(std::string_view inputfile)
{
	fhandle = nullptr;
}

/*-------------------------------------------------
    constructor - "open" a DVD-ROM file from an
    already-opened CHD file
-------------------------------------------------*/

/**
 * @fn  dvdrom_file *dvdrom_open(chd_file *chd)
 *
 * @brief   Queries if a given dvdrom open.
 *
 * @param [in,out]  chd If non-null, the chd.
 *
 * @return  null if it fails, else a dvdrom_file*.
 */

dvdrom_file::dvdrom_file(chd_file *_chd)
{
	chd = _chd;

	/* validate the CHD information */
	if (chd->hunk_bytes() != 2048)
		throw nullptr;
	if (chd->unit_bytes() != 2048)
		throw nullptr;

	/* check it's actually a DVD-ROM */
	if (!chd->is_dvd())
		throw nullptr;

	sector_count = chd->unit_count();
}


/*-------------------------------------------------
    destructor - "close" a DVD-ROM file
-------------------------------------------------*/

dvdrom_file::~dvdrom_file()
{
}



/***************************************************************************
    CORE READ ACCESS
***************************************************************************/


/*-------------------------------------------------
    dvdrom_read_data - read one 2048 bytes sector
    from a DVD-ROM
-------------------------------------------------*/

/**
 * @fn  bool read_data(uint32_t lbasector, void *buffer)
 *
 * @brief   Dvdrom read data.
 *
 * @param   lbasector       The lbasector.
 * @param   buffer          The buffer.
 *
 * @return  Success status.
 */

std::error_condition dvdrom_file::read_data(uint32_t lbasector, void *buffer)
{
	if (lbasector >= sector_count)
		return std::error_condition(chd_file::error::HUNK_OUT_OF_RANGE);

	return chd->read_hunk(lbasector, buffer);
}