Attempt #2 to implement CD-ROM passthrough.
Still Windows only on the QT side.
This commit is contained in:
@@ -13,4 +13,4 @@
|
|||||||
# Copyright 2020-2021 David Hrdlička.
|
# Copyright 2020-2021 David Hrdlička.
|
||||||
#
|
#
|
||||||
|
|
||||||
add_library(cdrom OBJECT cdrom.c cdrom_image_backend.c cdrom_image_viso.c cdrom_image.c cdrom_mitsumi.c)
|
add_library(cdrom OBJECT cdrom.c cdrom_image_backend.c cdrom_image_viso.c cdrom_image.c cdrom_ioctl.c cdrom_mitsumi.c)
|
||||||
|
|||||||
@@ -1972,7 +1972,8 @@ cdrom_hard_reset(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
cdrom_image_open(dev, dev->image_path);
|
cdrom_image_open(dev, dev->image_path);
|
||||||
}
|
} else if (dev->host_drive == 201)
|
||||||
|
cdrom_ioctl_open(dev, dev->image_path, dev->letter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2028,7 +2029,7 @@ cdrom_eject(uint8_t id)
|
|||||||
if (dev->host_drive == 200)
|
if (dev->host_drive == 200)
|
||||||
strcpy(dev->prev_image_path, dev->image_path);
|
strcpy(dev->prev_image_path, dev->image_path);
|
||||||
|
|
||||||
dev->prev_host_drive = dev->host_drive;
|
dev->prev_host_drive = dev->host_drive + (dev->host ? 1 : 0);
|
||||||
dev->host_drive = 0;
|
dev->host_drive = 0;
|
||||||
|
|
||||||
dev->ops->exit(dev);
|
dev->ops->exit(dev);
|
||||||
@@ -2058,26 +2059,33 @@ cdrom_reload(uint8_t id)
|
|||||||
dev->ops = NULL;
|
dev->ops = NULL;
|
||||||
memset(dev->image_path, 0, sizeof(dev->image_path));
|
memset(dev->image_path, 0, sizeof(dev->image_path));
|
||||||
|
|
||||||
if (dev->prev_host_drive == 200) {
|
if (dev->prev_host_drive >= 200) {
|
||||||
/* Reload a previous image. */
|
/* Reload a previous image. */
|
||||||
strcpy(dev->image_path, dev->prev_image_path);
|
strcpy(dev->image_path, dev->prev_image_path);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
if (dev->prev_host_drive == 200) {
|
||||||
if ((strlen(dev->image_path) >= 1) && (dev->image_path[strlen(dev->image_path) - 1] == '/'))
|
if ((strlen(dev->image_path) >= 1) && (dev->image_path[strlen(dev->image_path) - 1] == '/'))
|
||||||
dev->image_path[strlen(dev->image_path) - 1] = '\\';
|
dev->image_path[strlen(dev->image_path) - 1] = '\\';
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
|
if (dev->prev_host_drive == 200) {
|
||||||
if ((strlen(dev->image_path) >= 1) && (dev->image_path[strlen(dev->image_path) - 1] == '\\'))
|
if ((strlen(dev->image_path) >= 1) && (dev->image_path[strlen(dev->image_path) - 1] == '\\'))
|
||||||
dev->image_path[strlen(dev->image_path) - 1] = '/';
|
dev->image_path[strlen(dev->image_path) - 1] = '/';
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (dev->prev_host_drive > 200)
|
||||||
|
cdrom_ioctl_open(dev, dev->image_path, dev->letter);
|
||||||
|
else
|
||||||
cdrom_image_open(dev, dev->image_path);
|
cdrom_image_open(dev, dev->image_path);
|
||||||
|
|
||||||
cdrom_insert(id);
|
cdrom_insert(id);
|
||||||
|
|
||||||
if (strlen(dev->image_path) == 0)
|
if ((strlen(dev->image_path) == 0) && !dev->letter)
|
||||||
dev->host_drive = 0;
|
dev->host_drive = 0;
|
||||||
else
|
else
|
||||||
dev->host_drive = 200;
|
dev->host_drive = 200 + (dev->host ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
plat_cdrom_ui_update(id, 1);
|
plat_cdrom_ui_update(id, 1);
|
||||||
|
|||||||
@@ -94,14 +94,29 @@ cdrom_ioctl_get_subchannel(UNUSED(cdrom_t *dev), uint32_t lba, subchannel_t *sub
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cdrom_ioctl_is_track_audio(uint32_t pos, int ismsf)
|
cdrom_ioctl_get_capacity(UNUSED(cdrom_t *dev))
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = plat_cdrom_get_last_block();
|
||||||
|
pclog("GetCapacity=%x.\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cdrom_ioctl_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf)
|
||||||
{
|
{
|
||||||
uint8_t attr;
|
uint8_t attr;
|
||||||
|
TMSF tmsf;
|
||||||
int m;
|
int m;
|
||||||
int s;
|
int s;
|
||||||
int f;
|
int f;
|
||||||
|
int number;
|
||||||
int track;
|
int track;
|
||||||
|
|
||||||
|
if (dev->cd_status == CD_STATUS_DATA_ONLY)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (ismsf) {
|
if (ismsf) {
|
||||||
m = (pos >> 16) & 0xff;
|
m = (pos >> 16) & 0xff;
|
||||||
s = (pos >> 8) & 0xff;
|
s = (pos >> 8) & 0xff;
|
||||||
@@ -110,13 +125,20 @@ cdrom_ioctl_is_track_audio(uint32_t pos, int ismsf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* GetTrack requires LBA. */
|
/* GetTrack requires LBA. */
|
||||||
return plat_cdrom_get_audio_track(pos);
|
return plat_cdrom_is_track_audio(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cdrom_ioctl_sector_size(UNUSED(cdrom_t *dev), UNUSED(uint32_t lba))
|
cdrom_ioctl_is_track_pre(UNUSED(cdrom_t *dev), UNUSED(uint32_t lba))
|
||||||
{
|
{
|
||||||
return plat_get_sector_size();
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cdrom_ioctl_sector_size(UNUSED(cdrom_t *dev), uint32_t lba)
|
||||||
|
{
|
||||||
|
pclog("LBA=%x.\n", lba);
|
||||||
|
return plat_cdrom_get_sector_size(lba);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -128,21 +150,18 @@ cdrom_ioctl_read_sector(UNUSED(cdrom_t *dev), int type, uint8_t *b, uint32_t lba
|
|||||||
case CD_READ_AUDIO:
|
case CD_READ_AUDIO:
|
||||||
return plat_cdrom_read_sector(b, 1, lba);
|
return plat_cdrom_read_sector(b, 1, lba);
|
||||||
case CD_READ_RAW:
|
case CD_READ_RAW:
|
||||||
if (plat_get_sector_size() == 2352)
|
|
||||||
return plat_cdrom_read_sector(b, 1, lba);
|
return plat_cdrom_read_sector(b, 1, lba);
|
||||||
else
|
|
||||||
return plat_cdrom_read_sector(b, 0, lba);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
cdrom_ioctl_log("cdrom_ioctl_read_sector(): Unknown CD read type.\n");
|
cdrom_ioctl_log("cdrom_ioctl_read_sector(): Unknown CD read type.\n");
|
||||||
return 0;
|
break;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cdrom_ioctl_track_type(UNUSED(cdrom_t *dev), uint32_t lba)
|
cdrom_ioctl_track_type(cdrom_t *dev, uint32_t lba)
|
||||||
{
|
{
|
||||||
if (cdrom_ioctl_is_track_audio(lba, 0))
|
if (cdrom_ioctl_is_track_audio(dev, lba, 0))
|
||||||
return CD_TRACK_AUDIO;
|
return CD_TRACK_AUDIO;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -151,9 +170,10 @@ cdrom_ioctl_track_type(UNUSED(cdrom_t *dev), uint32_t lba)
|
|||||||
static void
|
static void
|
||||||
cdrom_ioctl_exit(cdrom_t *dev)
|
cdrom_ioctl_exit(cdrom_t *dev)
|
||||||
{
|
{
|
||||||
|
cdrom_ioctl_log("CDROM: ioctl_exit(%s)\n", dev->image_path);
|
||||||
dev->cd_status = CD_STATUS_EMPTY;
|
dev->cd_status = CD_STATUS_EMPTY;
|
||||||
|
|
||||||
plat_cdrom_exit();
|
plat_cdrom_close();
|
||||||
|
|
||||||
dev->ops = NULL;
|
dev->ops = NULL;
|
||||||
}
|
}
|
||||||
@@ -162,7 +182,7 @@ static const cdrom_ops_t cdrom_ioctl_ops = {
|
|||||||
cdrom_ioctl_get_tracks,
|
cdrom_ioctl_get_tracks,
|
||||||
cdrom_ioctl_get_track_info,
|
cdrom_ioctl_get_track_info,
|
||||||
cdrom_ioctl_get_subchannel,
|
cdrom_ioctl_get_subchannel,
|
||||||
NULL,
|
cdrom_ioctl_is_track_pre,
|
||||||
cdrom_ioctl_sector_size,
|
cdrom_ioctl_sector_size,
|
||||||
cdrom_ioctl_read_sector,
|
cdrom_ioctl_read_sector,
|
||||||
cdrom_ioctl_track_type,
|
cdrom_ioctl_track_type,
|
||||||
@@ -170,48 +190,38 @@ static const cdrom_ops_t cdrom_ioctl_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
cdrom_ioctl_eject(void)
|
cdrom_ioctl_close(cdrom_t *dev)
|
||||||
{
|
{
|
||||||
plat_cdrom_eject();
|
cdrom_ioctl_log("CDROM: ioctl_close(%s)\n", dev->image_path);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
if (dev && dev->ops && dev->ops->exit)
|
||||||
cdrom_ioctl_load(void)
|
dev->ops->exit(dev);
|
||||||
{
|
|
||||||
plat_cdrom_load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cdrom_ioctl_open_abort(cdrom_t *dev)
|
cdrom_ioctl_open_abort(cdrom_t *dev)
|
||||||
{
|
{
|
||||||
if (dev && dev->ops && dev->ops->exit)
|
cdrom_ioctl_close(dev);
|
||||||
dev->ops->exit(dev);
|
|
||||||
|
|
||||||
dev->ops = NULL;
|
dev->ops = NULL;
|
||||||
dev->host_drive = 0;
|
dev->host_drive = 0;
|
||||||
dev->ioctl_path[0] = 0;
|
dev->image_path[0] = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cdrom_ioctl_open(cdrom_t *dev, const char *path)
|
cdrom_ioctl_open(cdrom_t *dev, char *path, int letter)
|
||||||
{
|
{
|
||||||
/* Open the drive. */
|
/* Open the image. */
|
||||||
if (plat_cdrom_open())
|
int i = plat_cdrom_open(path, letter);
|
||||||
|
if (!i)
|
||||||
return cdrom_ioctl_open_abort(dev);
|
return cdrom_ioctl_open_abort(dev);
|
||||||
|
|
||||||
/* Make sure to not STRCPY if the two are pointing
|
|
||||||
at the same place. */
|
|
||||||
if (path != dev->ioctl_path)
|
|
||||||
strcpy(dev->ioctl_path, path);
|
|
||||||
|
|
||||||
/* All good, reset state. */
|
/* All good, reset state. */
|
||||||
dev->cd_status = CD_STATUS_STOPPED;
|
dev->cd_status = CD_STATUS_STOPPED;
|
||||||
dev->is_dir = 0;
|
dev->is_dir = 0;
|
||||||
dev->seek_pos = 0;
|
dev->seek_pos = 0;
|
||||||
dev->cd_buflen = 0;
|
dev->cd_buflen = 0;
|
||||||
plat_cdrom_reset();
|
dev->cdrom_capacity = cdrom_ioctl_get_capacity(dev);
|
||||||
dev->cdrom_capacity = plat_cdrom_get_capacity();
|
|
||||||
pclog("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL);
|
pclog("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL);
|
||||||
|
|
||||||
/* Attach this handler to the drive. */
|
/* Attach this handler to the drive. */
|
||||||
@@ -219,3 +229,4 @@ cdrom_ioctl_open(cdrom_t *dev, const char *path)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1263,7 +1263,7 @@ load_floppy_and_cdrom_drives(void)
|
|||||||
path_normalize(cdrom[c].image_path);
|
path_normalize(cdrom[c].image_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cdrom[c].host_drive && (cdrom[c].host_drive != 200))
|
if (cdrom[c].host_drive && (cdrom[c].host_drive != 200) && (cdrom[c].host_drive != 201))
|
||||||
cdrom[c].host_drive = 0;
|
cdrom[c].host_drive = 0;
|
||||||
|
|
||||||
if ((cdrom[c].host_drive == 0x200) && (strlen(cdrom[c].image_path) == 0))
|
if ((cdrom[c].host_drive == 0x200) && (strlen(cdrom[c].image_path) == 0))
|
||||||
@@ -2575,7 +2575,7 @@ save_floppy_and_cdrom_drives(void)
|
|||||||
|
|
||||||
for (c = 0; c < CDROM_NUM; c++) {
|
for (c = 0; c < CDROM_NUM; c++) {
|
||||||
sprintf(temp, "cdrom_%02i_host_drive", c + 1);
|
sprintf(temp, "cdrom_%02i_host_drive", c + 1);
|
||||||
if ((cdrom[c].bus_type == 0) || (cdrom[c].host_drive != 200))
|
if ((cdrom[c].bus_type == 0) || ((cdrom[c].host_drive != 200) && (cdrom[c].host_drive != 201)))
|
||||||
ini_section_delete_var(cat, temp);
|
ini_section_delete_var(cat, temp);
|
||||||
else
|
else
|
||||||
ini_section_set_int(cat, temp, cdrom[c].host_drive);
|
ini_section_set_int(cat, temp, cdrom[c].host_drive);
|
||||||
|
|||||||
@@ -246,6 +246,8 @@ typedef struct cdrom {
|
|||||||
int audio_op;
|
int audio_op;
|
||||||
int audio_muted_soft;
|
int audio_muted_soft;
|
||||||
int sony_msf;
|
int sony_msf;
|
||||||
|
int host;
|
||||||
|
int letter;
|
||||||
|
|
||||||
const cdrom_ops_t *ops;
|
const cdrom_ops_t *ops;
|
||||||
|
|
||||||
@@ -309,7 +311,7 @@ extern void cdrom_image_reset(cdrom_t *dev);
|
|||||||
|
|
||||||
extern void cdrom_ioctl_eject(void);
|
extern void cdrom_ioctl_eject(void);
|
||||||
extern void cdrom_ioctl_load(void);
|
extern void cdrom_ioctl_load(void);
|
||||||
extern int cdrom_ioctl_open(cdrom_t *dev, const char d);
|
extern int cdrom_ioctl_open(cdrom_t *dev, char *path, int letter);
|
||||||
|
|
||||||
extern void cdrom_update_cdb(uint8_t *cdb, int lba_pos,
|
extern void cdrom_update_cdb(uint8_t *cdb, int lba_pos,
|
||||||
int number_of_blocks);
|
int number_of_blocks);
|
||||||
|
|||||||
32
src/include/86box/cdrom_ioctl.h
Normal file
32
src/include/86box/cdrom_ioctl.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||||
|
* running old operating systems and software designed for IBM
|
||||||
|
* PC systems and compatibles from 1981 through fairly recent
|
||||||
|
* system designs based on the PCI bus.
|
||||||
|
*
|
||||||
|
* This file is part of the 86Box distribution.
|
||||||
|
*
|
||||||
|
* CD-ROM image file handling module header, translated to C
|
||||||
|
* from cdrom_dosbox.h.
|
||||||
|
*
|
||||||
|
* Authors: RichardG,
|
||||||
|
* Miran Grca, <mgrca8@gmail.com>
|
||||||
|
*
|
||||||
|
* Copyright 2016-2022 RichardG.
|
||||||
|
* Copyright 2016-2022 Miran Grca.
|
||||||
|
*/
|
||||||
|
#ifndef CDROM_IOCTL_H
|
||||||
|
#define CDROM_IOCTL_H
|
||||||
|
|
||||||
|
/* this header file lists the functions provided by
|
||||||
|
various platform specific cdrom-ioctl files */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*CDROM_IOCTL_H*/
|
||||||
66
src/include/86box/plat_cdrom.h
Normal file
66
src/include/86box/plat_cdrom.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||||
|
* running old operating systems and software designed for IBM
|
||||||
|
* PC systems and compatibles from 1981 through fairly recent
|
||||||
|
* system designs based on the PCI bus.
|
||||||
|
*
|
||||||
|
* This file is part of the 86Box distribution.
|
||||||
|
*
|
||||||
|
* Definitions for platform specific serial to host passthrough.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Authors: Andreas J. Reichel <webmaster@6th-dimension.com>,
|
||||||
|
* Jasmine Iwanek <jasmine@iwanek.co.uk>
|
||||||
|
*
|
||||||
|
* Copyright 2021 Andreas J. Reichel.
|
||||||
|
* Copyright 2021-2022 Jasmine Iwanek.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PLAT_CDROM_H
|
||||||
|
#define PLAT_CDROM_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define RAW_SECTOR_SIZE 2352
|
||||||
|
#define COOKED_SECTOR_SIZE 2048
|
||||||
|
|
||||||
|
#define DATA_TRACK 0x14
|
||||||
|
#define AUDIO_TRACK 0x10
|
||||||
|
|
||||||
|
#define CD_FPS 75
|
||||||
|
#define FRAMES_TO_MSF(f, M, S, F) \
|
||||||
|
{ \
|
||||||
|
uint64_t value = f; \
|
||||||
|
*(F) = (value % CD_FPS) & 0xff; \
|
||||||
|
value /= CD_FPS; \
|
||||||
|
*(S) = (value % 60) & 0xff; \
|
||||||
|
value /= 60; \
|
||||||
|
*(M) = value & 0xff; \
|
||||||
|
}
|
||||||
|
#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F))
|
||||||
|
|
||||||
|
typedef struct SMSF {
|
||||||
|
uint16_t min;
|
||||||
|
uint8_t sec;
|
||||||
|
uint8_t fr;
|
||||||
|
} TMSF;
|
||||||
|
|
||||||
|
extern int plat_cdrom_is_track_audio(uint32_t sector);
|
||||||
|
extern int plat_cdrom_get_last_block(void);
|
||||||
|
extern void plat_cdrom_get_audio_tracks(int *st_track, int *end, TMSF *lead_out);
|
||||||
|
extern int plat_cdrom_get_audio_track_info(int end, int track, int *track_num, TMSF *start, uint8_t *attr);
|
||||||
|
extern int plat_cdrom_get_audio_sub(uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos);
|
||||||
|
extern int plat_cdrom_get_sector_size(uint32_t sector);
|
||||||
|
extern int plat_cdrom_read_sector(uint8_t *buffer, int raw, uint32_t sector);
|
||||||
|
extern void plat_cdrom_close(void);
|
||||||
|
extern int plat_cdrom_open(char *path, int letter);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -33,7 +33,11 @@ machine_status_init(void)
|
|||||||
machine_status.fdd[i].active = false;
|
machine_status.fdd[i].active = false;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < CDROM_NUM; ++i) {
|
for (size_t i = 0; i < CDROM_NUM; ++i) {
|
||||||
|
if (cdrom[i].host)
|
||||||
|
machine_status.cdrom[i].empty = cdrom[i].host_drive != 201;
|
||||||
|
else
|
||||||
machine_status.cdrom[i].empty = cdrom[i].host_drive != 200 || (strlen(cdrom[i].image_path) == 0);
|
machine_status.cdrom[i].empty = cdrom[i].host_drive != 200 || (strlen(cdrom[i].image_path) == 0);
|
||||||
|
|
||||||
machine_status.cdrom[i].active = false;
|
machine_status.cdrom[i].active = false;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < ZIP_NUM; i++) {
|
for (size_t i = 0; i < ZIP_NUM; i++) {
|
||||||
|
|||||||
@@ -533,7 +533,7 @@ MachineStatus::refresh(QStatusBar *sbar)
|
|||||||
|
|
||||||
iterateCDROM([this, sbar](int i) {
|
iterateCDROM([this, sbar](int i) {
|
||||||
d->cdrom[i].label = std::make_unique<ClickableLabel>();
|
d->cdrom[i].label = std::make_unique<ClickableLabel>();
|
||||||
d->cdrom[i].setEmpty(cdrom[i].host_drive != 200 || QString(cdrom[i].image_path).isEmpty());
|
d->cdrom[i].setEmpty(((cdrom[i].host_drive != 200) && (cdrom[i].host_drive != 201)) || QString(cdrom[i].image_path).isEmpty());
|
||||||
d->cdrom[i].setActive(false);
|
d->cdrom[i].setActive(false);
|
||||||
d->cdrom[i].refresh();
|
d->cdrom[i].refresh();
|
||||||
connect((ClickableLabel *) d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
connect((ClickableLabel *) d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
||||||
|
|||||||
@@ -29,6 +29,21 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
#define BITMAP WINDOWS_BITMAP
|
||||||
|
#undef UNICODE
|
||||||
|
#include <windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
|
#undef BITMAP
|
||||||
|
#endif
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#define HAVE_STDARG_H
|
||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
#include <86box/config.h>
|
#include <86box/config.h>
|
||||||
#include <86box/device.h>
|
#include <86box/device.h>
|
||||||
@@ -131,14 +146,25 @@ MediaMenu::refresh(QMenu *parentMenu)
|
|||||||
cdromMutePos = menu->children().count();
|
cdromMutePos = menu->children().count();
|
||||||
menu->addAction(QApplication::style()->standardIcon(QStyle::SP_MediaVolumeMuted), tr("&Mute"), [this, i]() { cdromMute(i); })->setCheckable(true);
|
menu->addAction(QApplication::style()->standardIcon(QStyle::SP_MediaVolumeMuted), tr("&Mute"), [this, i]() { cdromMute(i); })->setCheckable(true);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addAction(ProgSettings::loadIcon("/cdrom.ico"), tr("&Image..."), [this, i]() { cdromMount(i, 0); })->setCheckable(false);
|
menu->addAction(ProgSettings::loadIcon("/cdrom.ico"), tr("&Image..."), [this, i]() { cdrom[i].host = 0; cdrom[i].letter = 0; cdromMount(i, 0); })->setCheckable(false);
|
||||||
menu->addAction(QApplication::style()->standardIcon(QStyle::SP_DirIcon), tr("&Folder..."), [this, i]() { cdromMount(i, 1); })->setCheckable(false);
|
menu->addAction(QApplication::style()->standardIcon(QStyle::SP_DirIcon), tr("&Folder..."), [this, i]() { cdrom[i].host = 0; cdrom[i].letter = 0; cdromMount(i, 1); })->setCheckable(false);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
|
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
|
||||||
cdromImageHistoryPos[slot] = menu->children().count();
|
cdromImageHistoryPos[slot] = menu->children().count();
|
||||||
menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { cdromReload(i, slot); })->setCheckable(false);
|
menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { cdromReload(i, slot); })->setCheckable(false);
|
||||||
}
|
}
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
/* Loop through each Windows drive letter and test to see if
|
||||||
|
it's a CDROM */
|
||||||
|
for (auto &letter : driveLetters) {
|
||||||
|
auto drive = QString::asprintf("%c:\\", letter).toUtf8().constData();
|
||||||
|
if (GetDriveType(drive) == DRIVE_CDROM) {
|
||||||
|
menu->addAction(ProgSettings::loadIcon("/cdrom.ico"), tr("Host CD/DVD Drive (%1:)").arg(letter), [this, i, letter]() { cdrom[i].host = 1; cdrom[i].letter = letter; cdromMount(i, 0); })->setCheckable(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu->addSeparator();
|
||||||
|
#endif // _WIN32
|
||||||
cdromImagePos = menu->children().count();
|
cdromImagePos = menu->children().count();
|
||||||
cdromDirPos = menu->children().count();
|
cdromDirPos = menu->children().count();
|
||||||
menu->addAction(tr("E&ject"), [this, i]() { cdromEject(i); })->setCheckable(false);
|
menu->addAction(tr("E&ject"), [this, i]() { cdromEject(i); })->setCheckable(false);
|
||||||
@@ -467,17 +493,24 @@ MediaMenu::cdromMount(int i, const QString &filename)
|
|||||||
if ((fn.data() != NULL) && (strlen(fn.data()) >= 1) && (fn.data()[strlen(fn.data()) - 1] == '\\'))
|
if ((fn.data() != NULL) && (strlen(fn.data()) >= 1) && (fn.data()[strlen(fn.data()) - 1] == '\\'))
|
||||||
fn.data()[strlen(fn.data()) - 1] = '/';
|
fn.data()[strlen(fn.data()) - 1] = '/';
|
||||||
#endif
|
#endif
|
||||||
|
if (cdrom[i].host)
|
||||||
|
cdrom_ioctl_open(&(cdrom[i]), fn.data(), cdrom[i].letter);
|
||||||
|
else
|
||||||
cdrom_image_open(&(cdrom[i]), fn.data());
|
cdrom_image_open(&(cdrom[i]), fn.data());
|
||||||
/* Signal media change to the emulated machine. */
|
/* Signal media change to the emulated machine. */
|
||||||
if (cdrom[i].insert)
|
if (cdrom[i].insert)
|
||||||
cdrom[i].insert(cdrom[i].priv);
|
cdrom[i].insert(cdrom[i].priv);
|
||||||
cdrom[i].host_drive = (strlen(cdrom[i].image_path) == 0) ? 0 : 200;
|
cdrom[i].host_drive = (strlen(cdrom[i].image_path) == 0 && !cdrom[i].letter) ? 0 : (200 + (cdrom[i].host ? 1 : 0));
|
||||||
if (cdrom[i].host_drive == 200) {
|
|
||||||
|
pclog("HostDrive=%d, letter=%d.\n", cdrom[i].host_drive, cdrom[i].letter);
|
||||||
|
if (cdrom[i].host_drive >= 200) {
|
||||||
ui_sb_update_icon_state(SB_CDROM | i, 0);
|
ui_sb_update_icon_state(SB_CDROM | i, 0);
|
||||||
} else {
|
} else {
|
||||||
ui_sb_update_icon_state(SB_CDROM | i, 1);
|
ui_sb_update_icon_state(SB_CDROM | i, 1);
|
||||||
}
|
}
|
||||||
|
if (!cdrom[i].host)
|
||||||
mhm.addImageToHistory(i, ui::MediaType::Optical, cdrom[i].prev_image_path, cdrom[i].image_path);
|
mhm.addImageToHistory(i, ui::MediaType::Optical, cdrom[i].prev_image_path, cdrom[i].image_path);
|
||||||
|
|
||||||
cdromUpdateMenu(i);
|
cdromUpdateMenu(i);
|
||||||
ui_sb_update_tip(SB_CDROM | i);
|
ui_sb_update_tip(SB_CDROM | i);
|
||||||
config_save();
|
config_save();
|
||||||
@@ -489,6 +522,10 @@ MediaMenu::cdromMount(int i, int dir)
|
|||||||
QString filename;
|
QString filename;
|
||||||
QFileInfo fi(cdrom[i].image_path);
|
QFileInfo fi(cdrom[i].image_path);
|
||||||
|
|
||||||
|
pclog("IsHost?=%d.\n", cdrom[i].host);
|
||||||
|
if (cdrom[i].host) {
|
||||||
|
filename = QString(cdrom[i].letter);
|
||||||
|
} else {
|
||||||
if (dir) {
|
if (dir) {
|
||||||
filename = QFileDialog::getExistingDirectory(
|
filename = QFileDialog::getExistingDirectory(
|
||||||
parentWidget);
|
parentWidget);
|
||||||
@@ -503,6 +540,7 @@ MediaMenu::cdromMount(int i, int dir)
|
|||||||
if (filename.isEmpty()) {
|
if (filename.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cdromMount(i, filename);
|
cdromMount(i, filename);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ private:
|
|||||||
QString getMediaOpenDirectory();
|
QString getMediaOpenDirectory();
|
||||||
ui::MediaHistoryManager mhm;
|
ui::MediaHistoryManager mhm;
|
||||||
|
|
||||||
|
const QByteArray driveLetters = QByteArrayLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
|
||||||
int cassetteRecordPos;
|
int cassetteRecordPos;
|
||||||
int cassettePlayPos;
|
int cassettePlayPos;
|
||||||
int cassetteRewindPos;
|
int cassetteRewindPos;
|
||||||
|
|||||||
@@ -32,107 +32,89 @@
|
|||||||
#include <86box/plat_unused.h>
|
#include <86box/plat_unused.h>
|
||||||
#include <86box/plat_cdrom.h>
|
#include <86box/plat_cdrom.h>
|
||||||
|
|
||||||
static const char ioctl_path[8];
|
|
||||||
static HANDLE hIOCTL;
|
|
||||||
static CDROM_TOC toc;
|
|
||||||
|
|
||||||
/* The addresses sent from the guest are absolute, ie. a LBA of 0 corresponds to a MSF of 00:00:00. Otherwise, the counter displayed by the guest is wrong:
|
/* The addresses sent from the guest are absolute, ie. a LBA of 0 corresponds to a MSF of 00:00:00. Otherwise, the counter displayed by the guest is wrong:
|
||||||
there is a seeming 2 seconds in which audio plays but counter does not move, while a data track before audio jumps to 2 seconds before the actual start
|
there is a seeming 2 seconds in which audio plays but counter does not move, while a data track before audio jumps to 2 seconds before the actual start
|
||||||
of the audio while audio still plays. With an absolute conversion, the counter is fine. */
|
of the audio while audio still plays. With an absolute conversion, the counter is fine. */
|
||||||
#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f)
|
#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f)
|
||||||
|
|
||||||
static int
|
static HANDLE handle;
|
||||||
plat_cdrom_get_track(uint32_t sector)
|
static char ioctl_path[8];
|
||||||
{
|
|
||||||
int track = 0;
|
|
||||||
uint32_t track_addr;
|
|
||||||
|
|
||||||
for (int i = toc.FirstTrack; i < toc.LastTrack; i++) {
|
|
||||||
/* There must be at least two tracks - data and lead out. */
|
|
||||||
track_addr = MSFtoLBA(toc.TrackData[i].Address[1], toc.TrackData[i].Address[2], toc.TrackData[i].Address[3]);
|
|
||||||
if (track_addr <= sector) {
|
|
||||||
track = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pclog("GetTrack = %d.\n", track);
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
plat_cdrom_get_audio_track(uint32_t sector)
|
plat_cdrom_is_track_audio(uint32_t sector)
|
||||||
{
|
{
|
||||||
|
CDROM_TOC toc;
|
||||||
|
long size = 0;
|
||||||
|
int ret;
|
||||||
int control = 0;
|
int control = 0;
|
||||||
uint32_t track_addr;
|
uint32_t track_addr = 0;
|
||||||
|
|
||||||
for (int i = 0; toc.TrackData[i].TrackNumber != 0xaa; i++) {
|
DeviceIoControl(handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), (LPDWORD)&size, NULL);
|
||||||
/* There must be at least two tracks - data and lead out. */
|
plat_cdrom_close();
|
||||||
track_addr = MSFtoLBA(toc.TrackData[i].Address[1], toc.TrackData[i].Address[2], toc.TrackData[i].Address[3]);
|
|
||||||
if ((toc.TrackData[i].TrackNumber >= toc.FirstTrack) && (toc.TrackData[i].TrackNumber <= toc.LastTrack) &&
|
for (int c = 0; toc.TrackData[c].TrackNumber != 0xaa; c++) {
|
||||||
(track_addr >= sector)) {
|
track_addr = MSFtoLBA(toc.TrackData[c].Address[1], toc.TrackData[c].Address[2], toc.TrackData[c].Address[3]);
|
||||||
control = toc.TrackData[i].Control;
|
if ((toc.TrackData[c].TrackNumber >= toc.FirstTrack) && (toc.TrackData[c].TrackNumber <= toc.LastTrack) &&
|
||||||
|
(track_addr >= sector))
|
||||||
|
control = toc.TrackData[c].Control;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
ret = (control & 0x04) ? 0 : 1;
|
||||||
|
return ret;
|
||||||
return (control & 4) ? DATA_TRACK : AUDIO_TRACK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
plat_cdrom_get_audio_sub(uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos)
|
plat_cdrom_get_last_block(void)
|
||||||
{
|
{
|
||||||
CDROM_SUB_Q_DATA_FORMAT insub;
|
CDROM_TOC toc;
|
||||||
SUB_Q_CHANNEL_DATA sub;
|
int lb = 0;
|
||||||
DWORD size;
|
long size = 0;
|
||||||
int pos = 0;
|
uint32_t address = 0;
|
||||||
int cur_track = plat_cdrom_get_track(sector);
|
|
||||||
|
|
||||||
insub.Format = IOCTL_CDROM_CURRENT_POSITION;
|
DeviceIoControl(handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), (LPDWORD)&size, NULL);
|
||||||
if (plat_cdrom_open())
|
plat_cdrom_close();
|
||||||
return 0;
|
|
||||||
DeviceIoControl(hIOCTL,IOCTL_CDROM_READ_Q_CHANNEL, &insub, sizeof(insub), &sub, sizeof(sub), &size, NULL);
|
|
||||||
plat_cdrom_exit();
|
|
||||||
|
|
||||||
*attr = sub.CurrentPosition.Control;
|
for (int c = 0; c <= toc.LastTrack; c++) {
|
||||||
*track = (uint8_t)(cur_track + 1);
|
address = MSFtoLBA(toc.TrackData[c].Address[1], toc.TrackData[c].Address[2], toc.TrackData[c].Address[3]);
|
||||||
*index = sub.CurrentPosition.IndexNumber;
|
if (address > lb)
|
||||||
|
lb = address;
|
||||||
FRAMES_TO_MSF(sector + 150, &abs_pos->min, &abs_pos->sec, &abs_pos->fr);
|
}
|
||||||
|
pclog("LBCapacity=%x.\n", lb);
|
||||||
/* Absolute position should be adjusted by 150, not the relative ones. */
|
return lb;
|
||||||
FRAMES_TO_MSF(sector - toc.FirstTrack, &rel_pos->min, &rel_pos->sec, &rel_pos->fr);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
plat_cdrom_get_audio_tracks(int *st_track, int *end, TMSF *lead_out)
|
plat_cdrom_get_audio_tracks(int *st_track, int *end, TMSF *lead_out)
|
||||||
{
|
{
|
||||||
CDROM_TOC toc;
|
CDROM_TOC toc;
|
||||||
DWORD byteCount;
|
long size = 0;
|
||||||
|
|
||||||
*st_track = toc.FirstTrack;
|
DeviceIoControl(handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), (LPDWORD)&size, NULL);
|
||||||
|
plat_cdrom_close();
|
||||||
|
|
||||||
|
*st_track = 1;
|
||||||
*end = toc.LastTrack;
|
*end = toc.LastTrack;
|
||||||
FRAMES_TO_MSF(toc.TrackData[*end].TrackNumber + 150, &lead_out->min, &lead_out->sec, &lead_out->fr);
|
lead_out->min = toc.TrackData[toc.LastTrack].Address[1];
|
||||||
|
lead_out->sec = toc.TrackData[toc.LastTrack].Address[2];
|
||||||
return 1;
|
lead_out->fr = toc.TrackData[toc.LastTrack].Address[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This replaces both Info and EndInfo, they are specified by a variable. */
|
/* This replaces both Info and EndInfo, they are specified by a variable. */
|
||||||
int
|
int
|
||||||
plat_cdrom_get_audio_track_info(int end, int track, int *track_num, TMSF *start, uint8_t *attr)
|
plat_cdrom_get_audio_track_info(UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr)
|
||||||
{
|
{
|
||||||
int pos;
|
CDROM_TOC toc;
|
||||||
DWORD byteCount;
|
long size = 0;
|
||||||
|
|
||||||
pclog("plat_cdrom_get_audio_track_info(): start track = %d, last track = %d.\n", track, end);
|
DeviceIoControl(handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), (LPDWORD)&size, NULL);
|
||||||
|
plat_cdrom_close();
|
||||||
|
|
||||||
if ((track < 1) || (track > end))
|
if ((track < 1) || (track == 0xaa) || (track > (toc.LastTrack)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pos = toc.FirstTrack + 150;
|
start->min = toc.TrackData[track - 1].Address[1];
|
||||||
|
start->sec = toc.TrackData[track - 1].Address[2];
|
||||||
FRAMES_TO_MSF(pos, &start->min, &start->sec, &start->fr);
|
start->fr = toc.TrackData[track - 1].Address[3];
|
||||||
|
|
||||||
*track_num = toc.TrackData[track - 1].TrackNumber;
|
*track_num = toc.TrackData[track - 1].TrackNumber;
|
||||||
*attr = toc.TrackData[track - 1].Control;
|
*attr = toc.TrackData[track - 1].Control;
|
||||||
@@ -140,136 +122,100 @@ plat_cdrom_get_audio_track_info(int end, int track, int *track_num, TMSF *start,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
/* TODO: See if track start is adjusted by 150 or not. */
|
||||||
plat_get_sector_size(void)
|
int
|
||||||
|
plat_cdrom_get_audio_sub(UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos)
|
||||||
{
|
{
|
||||||
DISK_GEOMETRY dgCDROM;
|
CDROM_SUB_Q_DATA_FORMAT insub;
|
||||||
DWORD size;
|
SUB_Q_CHANNEL_DATA sub;
|
||||||
|
long size = 0;
|
||||||
|
|
||||||
if (plat_cdrom_open())
|
insub.Format = IOCTL_CDROM_CURRENT_POSITION;
|
||||||
return 0;
|
|
||||||
DeviceIoControl(hIOCTL, IOCTL_CDROM_GET_DRIVE_GEOMETRY, NULL, 0, &dgCDROM, sizeof(DISK_GEOMETRY), &size, NULL);
|
|
||||||
plat_cdrom_exit();
|
|
||||||
|
|
||||||
if (dgCDROM.MediaType != 11) // Removable Media Check
|
DeviceIoControl(handle, IOCTL_CDROM_READ_Q_CHANNEL, &insub, sizeof(insub), &sub, sizeof(sub), (LPDWORD)&size, NULL);
|
||||||
|
plat_cdrom_close();
|
||||||
|
|
||||||
|
if (sub.CurrentPosition.TrackNumber < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return dgCDROM.BytesPerSector;
|
*track = sub.CurrentPosition.TrackNumber;
|
||||||
|
*attr = sub.CurrentPosition.Control;
|
||||||
|
*index = sub.CurrentPosition.IndexNumber;
|
||||||
|
|
||||||
|
rel_pos->min = sub.CurrentPosition.TrackRelativeAddress[1];
|
||||||
|
rel_pos->sec = sub.CurrentPosition.TrackRelativeAddress[2];
|
||||||
|
rel_pos->fr = sub.CurrentPosition.TrackRelativeAddress[3];
|
||||||
|
abs_pos->min = sub.CurrentPosition.AbsoluteAddress[1];
|
||||||
|
abs_pos->sec = sub.CurrentPosition.AbsoluteAddress[2];
|
||||||
|
abs_pos->fr = sub.CurrentPosition.AbsoluteAddress[3];
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
plat_cdrom_get_sector_size(UNUSED(uint32_t sector))
|
||||||
|
{
|
||||||
|
return COOKED_SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
plat_cdrom_read_sector(uint8_t *buffer, int raw, uint32_t sector)
|
plat_cdrom_read_sector(uint8_t *buffer, int raw, uint32_t sector)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
LARGE_INTEGER pos;
|
LARGE_INTEGER pos;
|
||||||
RAW_READ_INFO in;
|
BOOL status;
|
||||||
DWORD byteCount;
|
long size = 0;
|
||||||
pclog("plat_cdrom_read_sector(): raw? = %d, sector = %02x.\n", raw, sector);
|
|
||||||
|
|
||||||
if (raw) {
|
int buflen = raw ? RAW_SECTOR_SIZE : COOKED_SECTOR_SIZE;
|
||||||
in.TrackMode = CDDA;
|
|
||||||
in.SectorCount = 1;
|
if (!raw) {
|
||||||
in.DiskOffset.QuadPart = sector * RAW_SECTOR_SIZE;
|
pclog("Cooked.\n");
|
||||||
if (plat_cdrom_open())
|
// Cooked
|
||||||
return 0;
|
int success = 0;
|
||||||
ret = DeviceIoControl(hIOCTL, IOCTL_CDROM_RAW_READ, &in, sizeof(RAW_READ_INFO), buffer, RAW_SECTOR_SIZE, &byteCount, NULL);
|
DWORD newPos = SetFilePointer(handle, sector * COOKED_SECTOR_SIZE, 0, FILE_BEGIN);
|
||||||
plat_cdrom_exit();
|
if (newPos != 0xFFFFFFFF)
|
||||||
return ret;
|
success = ReadFile(handle, buffer, buflen, (LPDWORD)&size, NULL);
|
||||||
|
status = (success != 0);
|
||||||
} else {
|
} else {
|
||||||
pos.QuadPart = sector * COOKED_SECTOR_SIZE;
|
pclog("Raw.\n");
|
||||||
if (plat_cdrom_open())
|
// Raw
|
||||||
return 0;
|
RAW_READ_INFO in;
|
||||||
SetFilePointer(hIOCTL, pos.LowPart, &pos.HighPart, FILE_BEGIN);
|
in.DiskOffset.LowPart = sector * COOKED_SECTOR_SIZE;
|
||||||
ret = ReadFile(hIOCTL, buffer, COOKED_SECTOR_SIZE, &byteCount, NULL);
|
in.DiskOffset.HighPart = 0;
|
||||||
plat_cdrom_exit();
|
in.SectorCount = 1;
|
||||||
pclog("plat_cdrom_read_sector(): ret = %x.\n", !ret);
|
in.TrackMode = CDDA;
|
||||||
return !ret;
|
status = DeviceIoControl(handle, IOCTL_CDROM_RAW_READ, &in, sizeof(in),
|
||||||
|
buffer, buflen, (LPDWORD)&size, NULL);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t
|
plat_cdrom_close();
|
||||||
plat_cdrom_get_capacity(void)
|
pclog("ReadSector status=%d, sector=%d, size=%d.\n", status, sector, size);
|
||||||
{
|
return (size == buflen) && (status > 0);
|
||||||
DWORD size;
|
|
||||||
int c;
|
|
||||||
DISK_GEOMETRY dgCDROM;
|
|
||||||
uint32_t totals;
|
|
||||||
|
|
||||||
if (plat_cdrom_open())
|
|
||||||
return 0;
|
|
||||||
DeviceIoControl(hIOCTL, IOCTL_CDROM_GET_DRIVE_GEOMETRY, NULL, 0, &dgCDROM, sizeof(DISK_GEOMETRY), &size, NULL);
|
|
||||||
plat_cdrom_exit();
|
|
||||||
|
|
||||||
totals = dgCDROM.SectorsPerTrack * dgCDROM.TracksPerCylinder * dgCDROM.Cylinders.QuadPart;
|
|
||||||
|
|
||||||
pclog("Total = %08x.\n", totals);
|
|
||||||
return totals;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
plat_cdrom_load(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
DWORD size;
|
|
||||||
|
|
||||||
if (plat_cdrom_open())
|
|
||||||
return 0;
|
|
||||||
DeviceIoControl(hIOCTL, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &size, NULL);
|
|
||||||
plat_cdrom_exit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
plat_cdrom_eject(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
DWORD size;
|
|
||||||
|
|
||||||
if (plat_cdrom_open())
|
|
||||||
return 0;
|
|
||||||
ret = DeviceIoControl(hIOCTL, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &size, NULL);
|
|
||||||
plat_cdrom_exit();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
plat_cdrom_exit(void)
|
|
||||||
{
|
|
||||||
if (hIOCTL) {
|
|
||||||
CloseHandle(hIOCTL);
|
|
||||||
hIOCTL = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
plat_cdrom_close(void)
|
plat_cdrom_close(void)
|
||||||
{
|
{
|
||||||
plat_cdrom_exit();
|
if (handle != NULL) {
|
||||||
|
CloseHandle(handle);
|
||||||
|
handle = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
plat_cdrom_load(char *path, int letter)
|
||||||
|
{
|
||||||
|
plat_cdrom_close();
|
||||||
|
strcpy(ioctl_path, "\\\\.\\");
|
||||||
|
strcat(ioctl_path, path);
|
||||||
|
|
||||||
|
/* Data track (shouldn't there be a lead in track?). */
|
||||||
|
handle = CreateFileW((LPCWSTR)ioctl_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
|
pclog("handle=%p, error=%x, drive=%s.\n", handle, GetLastError(), ioctl_path);
|
||||||
|
return (handle != INVALID_HANDLE_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
plat_cdrom_reset(void)
|
plat_cdrom_open(char *path, int letter)
|
||||||
{
|
{
|
||||||
CDROM_TOC ltoc;
|
return plat_cdrom_load(path, letter);
|
||||||
DWORD size;
|
|
||||||
|
|
||||||
if (plat_cdrom_open())
|
|
||||||
return 0;
|
|
||||||
DeviceIoControl(hIOCTL, IOCTL_CDROM_READ_TOC, NULL, 0, <oc, sizeof(ltoc), &size, NULL);
|
|
||||||
plat_cdrom_exit();
|
|
||||||
|
|
||||||
toc = ltoc;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
plat_cdrom_open(void)
|
|
||||||
{
|
|
||||||
plat_cdrom_exit();
|
|
||||||
hIOCTL = CreateFile((LPCWSTR)ioctl_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (hIOCTL == NULL)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user