clang-format in src/cdrom/

This commit is contained in:
Jasmine Iwanek
2022-09-18 17:11:56 -04:00
parent e6dbaefeb1
commit d044f8d1f6
3 changed files with 323 additions and 380 deletions

View File

@@ -29,12 +29,11 @@
#include <86box/scsi_device.h> #include <86box/scsi_device.h>
#include <86box/sound.h> #include <86box/sound.h>
/* 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. */
#undef MSFtoLBA #undef MSFtoLBA
#define MSFtoLBA(m,s,f) ((((m*60)+s)*75)+f) #define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f)
#define RAW_SECTOR_SIZE 2352 #define RAW_SECTOR_SIZE 2352
#define COOKED_SECTOR_SIZE 2048 #define COOKED_SECTOR_SIZE 2048
@@ -43,9 +42,9 @@
#define MAX_SEEK 333333 #define MAX_SEEK 333333
#define CD_BCD(x) (((x) % 10) | (((x) / 10) << 4)) #define CD_BCD(x) (((x) % 10) | (((x) / 10) << 4))
#define CD_DCB(x) ((((x) & 0xf0) >> 4) * 10 + ((x) & 0x0f)) #define CD_DCB(x) ((((x) &0xf0) >> 4) * 10 + ((x) &0x0f))
#pragma pack(push,1) #pragma pack(push, 1)
typedef struct { typedef struct {
uint8_t user_data[2048], uint8_t user_data[2048],
ecc[288]; ecc[288];
@@ -87,19 +86,15 @@ typedef union {
} sector_buffer_t; } sector_buffer_t;
#pragma pack(pop) #pragma pack(pop)
static int cdrom_sector_size; static int cdrom_sector_size;
static uint8_t raw_buffer[2856]; /* Needs to be the same size as sector_buffer_t in the structs. */ static uint8_t raw_buffer[2856]; /* Needs to be the same size as sector_buffer_t in the structs. */
static uint8_t extra_buffer[296]; static uint8_t extra_buffer[296];
cdrom_t cdrom[CDROM_NUM]; cdrom_t cdrom[CDROM_NUM];
#ifdef ENABLE_CDROM_LOG #ifdef ENABLE_CDROM_LOG
int cdrom_do_log = ENABLE_CDROM_LOG; int cdrom_do_log = ENABLE_CDROM_LOG;
void void
cdrom_log(const char *fmt, ...) cdrom_log(const char *fmt, ...)
{ {
@@ -112,10 +107,9 @@ cdrom_log(const char *fmt, ...)
} }
} }
#else #else
#define cdrom_log(fmt, ...) # define cdrom_log(fmt, ...)
#endif #endif
int int
cdrom_lba_to_msf_accurate(int lba) cdrom_lba_to_msf_accurate(int lba)
{ {
@@ -134,11 +128,10 @@ cdrom_lba_to_msf_accurate(int lba)
return ((m << 16) | (s << 8) | f); return ((m << 16) | (s << 8) | f);
} }
static double static double
cdrom_get_short_seek(cdrom_t *dev) cdrom_get_short_seek(cdrom_t *dev)
{ {
switch(dev->cur_speed) { switch (dev->cur_speed) {
case 0: case 0:
fatal("CD-ROM %i: 0x speed\n", dev->id); fatal("CD-ROM %i: 0x speed\n", dev->id);
return 0.0; return 0.0;
@@ -148,16 +141,37 @@ cdrom_get_short_seek(cdrom_t *dev)
return 160.0; return 160.0;
case 3: case 3:
return 150.0; return 150.0;
case 4: case 5: case 6: case 7: case 8: case 4:
case 9: case 10: case 11: case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
return 112.0; return 112.0;
case 12: case 13: case 14: case 15: case 12:
case 13:
case 14:
case 15:
return 75.0; return 75.0;
case 16: case 17: case 18: case 19: case 16:
case 17:
case 18:
case 19:
return 58.0; return 58.0;
case 20: case 21: case 22: case 23: case 20:
case 40: case 41: case 42: case 43: case 21:
case 44: case 45: case 46: case 47: case 22:
case 23:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48: case 48:
return 50.0; return 50.0;
default: default:
@@ -166,11 +180,10 @@ cdrom_get_short_seek(cdrom_t *dev)
} }
} }
static double static double
cdrom_get_long_seek(cdrom_t *dev) cdrom_get_long_seek(cdrom_t *dev)
{ {
switch(dev->cur_speed) { switch (dev->cur_speed) {
case 0: case 0:
fatal("CD-ROM %i: 0x speed\n", dev->id); fatal("CD-ROM %i: 0x speed\n", dev->id);
return 0.0; return 0.0;
@@ -180,16 +193,37 @@ cdrom_get_long_seek(cdrom_t *dev)
return 1000.0; return 1000.0;
case 3: case 3:
return 900.0; return 900.0;
case 4: case 5: case 6: case 7: case 8: case 4:
case 9: case 10: case 11: case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
return 675.0; return 675.0;
case 12: case 13: case 14: case 15: case 12:
case 13:
case 14:
case 15:
return 400.0; return 400.0;
case 16: case 17: case 18: case 19: case 16:
case 17:
case 18:
case 19:
return 350.0; return 350.0;
case 20: case 21: case 22: case 23: case 20:
case 40: case 41: case 42: case 43: case 21:
case 44: case 45: case 46: case 47: case 22:
case 23:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48: case 48:
return 300.0; return 300.0;
default: default:
@@ -198,7 +232,6 @@ cdrom_get_long_seek(cdrom_t *dev)
} }
} }
double double
cdrom_seek_time(cdrom_t *dev) cdrom_seek_time(cdrom_t *dev)
{ {
@@ -215,7 +248,6 @@ cdrom_seek_time(cdrom_t *dev)
return cdrom_get_short_seek(dev) + ((cdrom_get_long_seek(dev) * ((double) diff)) / sd); return cdrom_get_short_seek(dev) + ((cdrom_get_long_seek(dev) * ((double) diff)) / sd);
} }
void void
cdrom_stop(cdrom_t *dev) cdrom_stop(cdrom_t *dev)
{ {
@@ -223,7 +255,6 @@ cdrom_stop(cdrom_t *dev)
dev->cd_status = CD_STATUS_STOPPED; dev->cd_status = CD_STATUS_STOPPED;
} }
void void
cdrom_seek(cdrom_t *dev, uint32_t pos) cdrom_seek(cdrom_t *dev, uint32_t pos)
{ {
@@ -236,7 +267,6 @@ cdrom_seek(cdrom_t *dev, uint32_t pos)
cdrom_stop(dev); cdrom_stop(dev);
} }
int int
cdrom_is_pre(cdrom_t *dev, uint32_t lba) cdrom_is_pre(cdrom_t *dev, uint32_t lba)
{ {
@@ -246,7 +276,6 @@ cdrom_is_pre(cdrom_t *dev, uint32_t lba)
return 0; return 0;
} }
int int
cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len) cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len)
{ {
@@ -292,7 +321,6 @@ cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len)
return ret; return ret;
} }
uint8_t uint8_t
cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf) cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf)
{ {
@@ -355,7 +383,6 @@ cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf)
return 1; return 1;
} }
uint8_t uint8_t
cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit) cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit)
{ {
@@ -388,7 +415,6 @@ cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit)
return 1; return 1;
} }
uint8_t uint8_t
cdrom_toshiba_audio_play(cdrom_t *dev, uint32_t pos, int type) cdrom_toshiba_audio_play(cdrom_t *dev, uint32_t pos, int type)
{ {
@@ -424,7 +450,6 @@ cdrom_toshiba_audio_play(cdrom_t *dev, uint32_t pos, int type)
return 1; return 1;
} }
void void
cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume) cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume)
{ {
@@ -432,7 +457,6 @@ cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume)
dev->cd_status = (dev->cd_status & 0xfe) | (resume & 0x01); dev->cd_status = (dev->cd_status & 0xfe) | (resume & 0x01);
} }
uint8_t uint8_t
cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf)
{ {
@@ -489,7 +513,6 @@ cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf)
return ret; return ret;
} }
uint8_t uint8_t
cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b) cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b)
{ {
@@ -522,7 +545,6 @@ cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b)
return ret; return ret;
} }
static int static int
read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf) read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf)
{ {
@@ -593,7 +615,6 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m
return len; return len;
} }
static int static int
read_toc_session(cdrom_t *dev, unsigned char *b, int msf) read_toc_session(cdrom_t *dev, unsigned char *b, int msf)
{ {
@@ -631,7 +652,6 @@ read_toc_session(cdrom_t *dev, unsigned char *b, int msf)
return len; return len;
} }
static int static int
read_toc_raw(cdrom_t *dev, unsigned char *b) read_toc_raw(cdrom_t *dev, unsigned char *b)
{ {
@@ -666,13 +686,12 @@ read_toc_raw(cdrom_t *dev, unsigned char *b)
return len; return len;
} }
int int
cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_track, int msf, int max_len) cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_track, int msf, int max_len)
{ {
int len; int len;
switch(type) { switch (type) {
case CD_TOC_NORMAL: case CD_TOC_NORMAL:
len = read_toc_normal(dev, b, start_track, msf); len = read_toc_normal(dev, b, start_track, msf);
break; break;
@@ -695,7 +714,6 @@ cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_tra
return len; return len;
} }
/* A new API call for Mitsumi CD-ROM. */ /* A new API call for Mitsumi CD-ROM. */
void void
cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf) cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf)
@@ -720,7 +738,6 @@ cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf)
memset(buf, 0x00, 9); memset(buf, 0x00, 9);
} }
void void
cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type) cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type)
{ {
@@ -760,7 +777,6 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in
} }
} }
static int static int
track_type_is_valid(uint8_t id, int type, int flags, int audio, int mode2) track_type_is_valid(uint8_t id, int type, int flags, int audio, int mode2)
{ {
@@ -805,7 +821,6 @@ track_type_is_valid(uint8_t id, int type, int flags, int audio, int mode2)
return 1; return 1;
} }
static void static void
read_sector_to_buffer(cdrom_t *dev, uint8_t *rbuf, uint32_t msf, uint32_t lba, int mode2, int len) read_sector_to_buffer(cdrom_t *dev, uint8_t *rbuf, uint32_t msf, uint32_t lba, int mode2, int len)
{ {
@@ -833,7 +848,6 @@ read_sector_to_buffer(cdrom_t *dev, uint8_t *rbuf, uint32_t msf, uint32_t lba, i
memset(bb, 0, 288); memset(bb, 0, 288);
} }
static void static void
read_audio(cdrom_t *dev, uint32_t lba, uint8_t *b) read_audio(cdrom_t *dev, uint32_t lba, uint8_t *b)
{ {
@@ -844,7 +858,6 @@ read_audio(cdrom_t *dev, uint32_t lba, uint8_t *b)
cdrom_sector_size = 2352; cdrom_sector_size = 2352;
} }
static void static void
read_mode1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) read_mode1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b)
{ {
@@ -899,7 +912,6 @@ read_mode1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int
} }
} }
static void static void
read_mode2_non_xa(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) read_mode2_non_xa(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b)
{ {
@@ -944,7 +956,6 @@ read_mode2_non_xa(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t m
} }
} }
static void static void
read_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) read_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b)
{ {
@@ -996,7 +1007,6 @@ read_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t
} }
} }
static void static void
read_mode2_xa_form2(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) read_mode2_xa_form2(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b)
{ {
@@ -1040,7 +1050,6 @@ read_mode2_xa_form2(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t
} }
} }
int int
cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type,
int cdrom_sector_flags, int *len) int cdrom_sector_flags, int *len)
@@ -1185,7 +1194,6 @@ cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int c
return 1; return 1;
} }
/* Peform a master init on the entire module. */ /* Peform a master init on the entire module. */
void void
cdrom_global_init(void) cdrom_global_init(void)
@@ -1194,7 +1202,6 @@ cdrom_global_init(void)
memset(cdrom, 0x00, sizeof(cdrom)); memset(cdrom, 0x00, sizeof(cdrom));
} }
static void static void
cdrom_drive_reset(cdrom_t *dev) cdrom_drive_reset(cdrom_t *dev)
{ {
@@ -1205,7 +1212,6 @@ cdrom_drive_reset(cdrom_t *dev)
dev->get_channel = NULL; dev->get_channel = NULL;
} }
void void
cdrom_hard_reset(void) cdrom_hard_reset(void)
{ {
@@ -1221,7 +1227,7 @@ cdrom_hard_reset(void)
cdrom_drive_reset(dev); cdrom_drive_reset(dev);
switch(dev->bus_type) { switch (dev->bus_type) {
case CDROM_BUS_ATAPI: case CDROM_BUS_ATAPI:
case CDROM_BUS_SCSI: case CDROM_BUS_SCSI:
scsi_cdrom_drive_reset(i); scsi_cdrom_drive_reset(i);
@@ -1241,7 +1247,6 @@ cdrom_hard_reset(void)
sound_cd_thread_reset(); sound_cd_thread_reset();
} }
void void
cdrom_close(void) cdrom_close(void)
{ {
@@ -1267,7 +1272,6 @@ cdrom_close(void)
} }
} }
/* Signal disc change to the emulated machine. */ /* Signal disc change to the emulated machine. */
void void
cdrom_insert(uint8_t id) cdrom_insert(uint8_t id)
@@ -1280,7 +1284,6 @@ cdrom_insert(uint8_t id)
} }
} }
/* The mechanics of ejecting a CD-ROM from a drive. */ /* The mechanics of ejecting a CD-ROM from a drive. */
void void
cdrom_eject(uint8_t id) cdrom_eject(uint8_t id)
@@ -1310,15 +1313,13 @@ cdrom_eject(uint8_t id)
config_save(); config_save();
} }
/* The mechanics of re-loading a CD-ROM drive. */ /* The mechanics of re-loading a CD-ROM drive. */
void void
cdrom_reload(uint8_t id) cdrom_reload(uint8_t id)
{ {
cdrom_t *dev = &cdrom[id]; cdrom_t *dev = &cdrom[id];
if ((dev->host_drive == dev->prev_host_drive) || if ((dev->host_drive == dev->prev_host_drive) || (dev->prev_host_drive == 0) || (dev->host_drive != 0)) {
(dev->prev_host_drive == 0) || (dev->host_drive != 0)) {
/* Switch from empty to empty. Do nothing. */ /* Switch from empty to empty. Do nothing. */
return; return;
} }

View File

@@ -33,11 +33,9 @@
#include <86box/cdrom.h> #include <86box/cdrom.h>
#include <86box/cdrom_image.h> #include <86box/cdrom_image.h>
#ifdef ENABLE_CDROM_IMAGE_LOG #ifdef ENABLE_CDROM_IMAGE_LOG
int cdrom_image_do_log = ENABLE_CDROM_IMAGE_LOG; int cdrom_image_do_log = ENABLE_CDROM_IMAGE_LOG;
void void
cdrom_image_log(const char *fmt, ...) cdrom_image_log(const char *fmt, ...)
{ {
@@ -50,30 +48,27 @@ cdrom_image_log(const char *fmt, ...)
} }
} }
#else #else
#define cdrom_image_log(fmt, ...) # define cdrom_image_log(fmt, ...)
#endif #endif
/* 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 void static void
image_get_tracks(cdrom_t *dev, int *first, int *last) image_get_tracks(cdrom_t *dev, int *first, int *last)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
TMSF tmsf; TMSF tmsf;
cdi_get_audio_tracks(img, first, last, &tmsf); cdi_get_audio_tracks(img, first, last, &tmsf);
} }
static void static void
image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
TMSF tmsf; TMSF tmsf;
cdi_get_audio_track_info(img, end, track, &ti->number, &tmsf, &ti->attr); cdi_get_audio_track_info(img, end, track, &ti->number, &tmsf, &ti->attr);
@@ -83,11 +78,10 @@ image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti)
ti->f = tmsf.fr; ti->f = tmsf.fr;
} }
static void static void
image_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc) image_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
TMSF rel_pos, abs_pos; TMSF rel_pos, abs_pos;
cdi_get_audio_sub(img, lba, &subc->attr, &subc->track, &subc->index, cdi_get_audio_sub(img, lba, &subc->attr, &subc->track, &subc->index,
@@ -102,11 +96,10 @@ image_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc)
subc->rel_f = rel_pos.fr; subc->rel_f = rel_pos.fr;
} }
static int static int
image_get_capacity(cdrom_t *dev) image_get_capacity(cdrom_t *dev)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
int first_track, last_track; int first_track, last_track;
int number, c; int number, c;
unsigned char attr; unsigned char attr;
@@ -126,11 +119,10 @@ image_get_capacity(cdrom_t *dev)
return lb; return lb;
} }
static int static int
image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
uint8_t attr; uint8_t attr;
TMSF tmsf; TMSF tmsf;
int m, s, f; int m, s, f;
@@ -156,11 +148,10 @@ image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf)
} }
} }
static int static int
image_is_track_pre(cdrom_t *dev, uint32_t lba) image_is_track_pre(cdrom_t *dev, uint32_t lba)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
int track; int track;
/* GetTrack requires LBA. */ /* GetTrack requires LBA. */
@@ -172,20 +163,18 @@ image_is_track_pre(cdrom_t *dev, uint32_t lba)
return 0; return 0;
} }
static int static int
image_sector_size(struct cdrom *dev, uint32_t lba) image_sector_size(struct cdrom *dev, uint32_t lba)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
return cdi_get_sector_size(img, lba); return cdi_get_sector_size(img, lba);
} }
static int static int
image_read_sector(struct cdrom *dev, int type, uint8_t *b, uint32_t lba) image_read_sector(struct cdrom *dev, int type, uint8_t *b, uint32_t lba)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
switch (type) { switch (type) {
case CD_READ_DATA: case CD_READ_DATA:
@@ -203,11 +192,10 @@ image_read_sector(struct cdrom *dev, int type, uint8_t *b, uint32_t lba)
} }
} }
static int static int
image_track_type(cdrom_t *dev, uint32_t lba) image_track_type(cdrom_t *dev, uint32_t lba)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
if (img) { if (img) {
if (image_is_track_audio(dev, lba, 0)) if (image_is_track_audio(dev, lba, 0))
@@ -221,11 +209,10 @@ image_track_type(cdrom_t *dev, uint32_t lba)
return 0; return 0;
} }
static void static void
image_exit(cdrom_t *dev) image_exit(cdrom_t *dev)
{ {
cd_img_t *img = (cd_img_t *)dev->image; cd_img_t *img = (cd_img_t *) dev->image;
cdrom_image_log("CDROM: image_exit(%s)\n", dev->image_path); cdrom_image_log("CDROM: image_exit(%s)\n", dev->image_path);
dev->cd_status = CD_STATUS_EMPTY; dev->cd_status = CD_STATUS_EMPTY;
@@ -238,7 +225,6 @@ image_exit(cdrom_t *dev)
dev->ops = NULL; dev->ops = NULL;
} }
static const cdrom_ops_t cdrom_image_ops = { static const cdrom_ops_t cdrom_image_ops = {
image_get_tracks, image_get_tracks,
image_get_track_info, image_get_track_info,
@@ -250,7 +236,6 @@ static const cdrom_ops_t cdrom_image_ops = {
image_exit image_exit
}; };
static int static int
image_open_abort(cdrom_t *dev) image_open_abort(cdrom_t *dev)
{ {
@@ -261,7 +246,6 @@ image_open_abort(cdrom_t *dev)
return 1; return 1;
} }
int int
cdrom_image_open(cdrom_t *dev, const char *fn) cdrom_image_open(cdrom_t *dev, const char *fn)
{ {
@@ -288,7 +272,7 @@ cdrom_image_open(cdrom_t *dev, const char *fn)
return image_open_abort(dev); return image_open_abort(dev);
/* All good, reset state. */ /* All good, reset state. */
if (! strcasecmp(path_get_extension((char *) fn), "ISO")) if (!strcasecmp(path_get_extension((char *) fn), "ISO"))
dev->cd_status = CD_STATUS_DATA_ONLY; dev->cd_status = CD_STATUS_DATA_ONLY;
else else
dev->cd_status = CD_STATUS_STOPPED; dev->cd_status = CD_STATUS_STOPPED;
@@ -303,7 +287,6 @@ cdrom_image_open(cdrom_t *dev, const char *fn)
return 0; return 0;
} }
void void
cdrom_image_close(cdrom_t *dev) cdrom_image_close(cdrom_t *dev)
{ {

View File

@@ -37,21 +37,17 @@
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/cdrom_image_backend.h> #include <86box/cdrom_image_backend.h>
#define CDROM_BCD(x) (((x) % 10) | (((x) / 10) << 4)) #define CDROM_BCD(x) (((x) % 10) | (((x) / 10) << 4))
#define MAX_LINE_LENGTH 512 #define MAX_LINE_LENGTH 512
#define MAX_FILENAME_LENGTH 256 #define MAX_FILENAME_LENGTH 256
#define CROSS_LEN 512 #define CROSS_LEN 512
static char temp_keyword[1024]; static char temp_keyword[1024];
#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG #ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG
int cdrom_image_backend_do_log = ENABLE_CDROM_IMAGE_BACKEND_LOG; int cdrom_image_backend_do_log = ENABLE_CDROM_IMAGE_BACKEND_LOG;
void void
cdrom_image_backend_log(const char *fmt, ...) cdrom_image_backend_log(const char *fmt, ...)
{ {
@@ -64,10 +60,9 @@ cdrom_image_backend_log(const char *fmt, ...)
} }
} }
#else #else
#define cdrom_image_backend_log(fmt, ...) # define cdrom_image_backend_log(fmt, ...)
#endif #endif
/* Binary file functions. */ /* Binary file functions. */
static int static int
bin_read(void *p, uint8_t *buffer, uint64_t seek, size_t count) bin_read(void *p, uint8_t *buffer, uint64_t seek, size_t count)
@@ -97,7 +92,6 @@ bin_read(void *p, uint8_t *buffer, uint64_t seek, size_t count)
return 1; return 1;
} }
static uint64_t static uint64_t
bin_get_length(void *p) bin_get_length(void *p)
{ {
@@ -116,7 +110,6 @@ bin_get_length(void *p)
return len; return len;
} }
static void static void
bin_close(void *p) bin_close(void *p)
{ {
@@ -135,7 +128,6 @@ bin_close(void *p)
free(p); free(p);
} }
static track_file_t * static track_file_t *
bin_init(const char *filename, int *error) bin_init(const char *filename, int *error)
{ {
@@ -166,7 +158,6 @@ bin_init(const char *filename, int *error)
return tf; return tf;
} }
static track_file_t * static track_file_t *
track_file_init(const char *filename, int *error) track_file_init(const char *filename, int *error)
{ {
@@ -175,7 +166,6 @@ track_file_init(const char *filename, int *error)
return bin_init(filename, error); return bin_init(filename, error);
} }
static void static void
track_file_close(track_t *trk) track_file_close(track_t *trk)
{ {
@@ -192,7 +182,6 @@ track_file_close(track_t *trk)
trk->file = NULL; trk->file = NULL;
} }
/* Root functions. */ /* Root functions. */
static void static void
cdi_clear_tracks(cd_img_t *cdi) cdi_clear_tracks(cd_img_t *cdi)
@@ -223,7 +212,6 @@ cdi_clear_tracks(cd_img_t *cdi)
cdi->tracks_num = 0; cdi->tracks_num = 0;
} }
void void
cdi_close(cd_img_t *cdi) cdi_close(cd_img_t *cdi)
{ {
@@ -231,7 +219,6 @@ cdi_close(cd_img_t *cdi)
free(cdi); free(cdi);
} }
int int
cdi_set_device(cd_img_t *cdi, const char *path) cdi_set_device(cd_img_t *cdi, const char *path)
{ {
@@ -244,7 +231,6 @@ cdi_set_device(cd_img_t *cdi, const char *path)
return 0; return 0;
} }
/* TODO: This never returns anything other than 1, should it even be an int? */ /* TODO: This never returns anything other than 1, should it even be an int? */
int int
cdi_get_audio_tracks(cd_img_t *cdi, int *st_track, int *end, TMSF *lead_out) cdi_get_audio_tracks(cd_img_t *cdi, int *st_track, int *end, TMSF *lead_out)
@@ -256,7 +242,6 @@ cdi_get_audio_tracks(cd_img_t *cdi, int *st_track, int *end, TMSF *lead_out)
return 1; return 1;
} }
/* TODO: This never returns anything other than 1, should it even be an int? */ /* TODO: This never returns anything other than 1, should it even be an int? */
int int
cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_out) cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_out)
@@ -268,7 +253,6 @@ cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_
return 1; return 1;
} }
int int
cdi_get_audio_track_pre(cd_img_t *cdi, int track) cdi_get_audio_track_pre(cd_img_t *cdi, int track)
{ {
@@ -280,7 +264,6 @@ cdi_get_audio_track_pre(cd_img_t *cdi, int track)
return trk->pre; return trk->pre;
} }
/* 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
cdi_get_audio_track_info(cd_img_t *cdi, int end, int track, int *track_num, TMSF *start, uint8_t *attr) cdi_get_audio_track_info(cd_img_t *cdi, int end, int track, int *track_num, TMSF *start, uint8_t *attr)
@@ -301,7 +284,6 @@ cdi_get_audio_track_info(cd_img_t *cdi, int end, int track, int *track_num, TMSF
return 1; return 1;
} }
int int
cdi_get_audio_track_info_lba(cd_img_t *cdi, int end, int track, int *track_num, uint32_t *start, uint8_t *attr) cdi_get_audio_track_info_lba(cd_img_t *cdi, int end, int track, int *track_num, uint32_t *start, uint8_t *attr)
{ {
@@ -318,7 +300,6 @@ cdi_get_audio_track_info_lba(cd_img_t *cdi, int end, int track, int *track_num,
return 1; return 1;
} }
int int
cdi_get_track(cd_img_t *cdi, uint32_t sector) cdi_get_track(cd_img_t *cdi, uint32_t sector)
{ {
@@ -341,7 +322,6 @@ cdi_get_track(cd_img_t *cdi, uint32_t sector)
return -1; return -1;
} }
/* TODO: See if track start is adjusted by 150 or not. */ /* TODO: See if track start is adjusted by 150 or not. */
int int
cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos) cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos)
@@ -365,7 +345,6 @@ cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track,
return 1; return 1;
} }
int int
cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector) cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector)
{ {
@@ -428,7 +407,6 @@ cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector)
return trk->file->read(trk->file, buffer, seek, length); return trk->file->read(trk->file, buffer, seek, length);
} }
int int
cdi_read_sectors(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector, uint32_t num) cdi_read_sectors(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector, uint32_t num)
{ {
@@ -448,8 +426,7 @@ cdi_read_sectors(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector, uint3
break; break;
/* Based on the DOSBox patch, but check all 8 bytes and makes sure it's not an /* Based on the DOSBox patch, but check all 8 bytes and makes sure it's not an
audio track. */ audio track. */
if (raw && sector < cdi->tracks[0].length && !cdi->tracks[0].mode2 && if (raw && sector < cdi->tracks[0].length && !cdi->tracks[0].mode2 && (cdi->tracks[0].attr != AUDIO_TRACK) && *(uint64_t *) &(buf[i * sector_size + 2068]))
(cdi->tracks[0].attr != AUDIO_TRACK) && *(uint64_t *) &(buf[i * sector_size + 2068]))
return 0; return 0;
} }
@@ -460,7 +437,6 @@ cdi_read_sectors(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector, uint3
return success; return success;
} }
/* TODO: Do CUE+BIN images with a sector size of 2448 even exist? */ /* TODO: Do CUE+BIN images with a sector size of 2448 even exist? */
int int
cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector) cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector)
@@ -480,7 +456,6 @@ cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector)
return trk->file->read(trk->file, buffer, seek, 2448); return trk->file->read(trk->file, buffer, seek, 2448);
} }
int int
cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) cdi_get_sector_size(cd_img_t *cdi, uint32_t sector)
{ {
@@ -494,7 +469,6 @@ cdi_get_sector_size(cd_img_t *cdi, uint32_t sector)
return trk->sector_size; return trk->sector_size;
} }
int int
cdi_is_mode2(cd_img_t *cdi, uint32_t sector) cdi_is_mode2(cd_img_t *cdi, uint32_t sector)
{ {
@@ -509,7 +483,6 @@ cdi_is_mode2(cd_img_t *cdi, uint32_t sector)
return !!(trk->mode2); return !!(trk->mode2);
} }
int int
cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector) cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector)
{ {
@@ -524,7 +497,6 @@ cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector)
return trk->form; return trk->form;
} }
static int static int
cdi_can_read_pvd(track_file_t *file, uint64_t sector_size, int mode2, int form) cdi_can_read_pvd(track_file_t *file, uint64_t sector_size, int mode2, int form)
{ {
@@ -538,11 +510,9 @@ cdi_can_read_pvd(track_file_t *file, uint64_t sector_size, int mode2, int form)
file->read(file, pvd, seek, COOKED_SECTOR_SIZE); file->read(file, pvd, seek, COOKED_SECTOR_SIZE);
return ((pvd[0] == 1 && !strncmp((char*)(&pvd[1]), "CD001", 5) && pvd[6] == 1) || return ((pvd[0] == 1 && !strncmp((char *) (&pvd[1]), "CD001", 5) && pvd[6] == 1) || (pvd[8] == 1 && !strncmp((char *) (&pvd[9]), "CDROM", 5) && pvd[14] == 1));
(pvd[8] == 1 && !strncmp((char*)(&pvd[9]), "CDROM", 5) && pvd[14] == 1));
} }
/* This reallocates the array and returns the pointer to the last track. */ /* This reallocates the array and returns the pointer to the last track. */
static void static void
cdi_track_push_back(cd_img_t *cdi, track_t *trk) cdi_track_push_back(cd_img_t *cdi, track_t *trk)
@@ -559,7 +529,6 @@ cdi_track_push_back(cd_img_t *cdi, track_t *trk)
cdi->tracks_num++; cdi->tracks_num++;
} }
int int
cdi_load_iso(cd_img_t *cdi, const char *filename) cdi_load_iso(cd_img_t *cdi, const char *filename)
{ {
@@ -619,7 +588,6 @@ cdi_load_iso(cd_img_t *cdi, const char *filename)
return 1; return 1;
} }
static int static int
cdi_cue_get_buffer(char *str, char **line, int up) cdi_cue_get_buffer(char *str, char **line, int up)
{ {
@@ -630,8 +598,8 @@ cdi_cue_get_buffer(char *str, char **line, int up)
int space = 1; int space = 1;
/* Copy to local buffer until we have end of string or whitespace. */ /* Copy to local buffer until we have end of string or whitespace. */
while (! done) { while (!done) {
switch(*s) { switch (*s) {
case '\0': case '\0':
if (quote) { if (quote) {
/* Ouch, unterminated string.. */ /* Ouch, unterminated string.. */
@@ -644,11 +612,12 @@ cdi_cue_get_buffer(char *str, char **line, int up)
quote ^= 1; quote ^= 1;
break; break;
case ' ': case '\t': case ' ':
case '\t':
if (space) if (space)
break; break;
if (! quote) { if (!quote) {
done = 1; done = 1;
break; break;
} }
@@ -663,7 +632,7 @@ cdi_cue_get_buffer(char *str, char **line, int up)
break; break;
} }
if (! done) if (!done)
s++; s++;
} }
*p = '\0'; *p = '\0';
@@ -673,7 +642,6 @@ cdi_cue_get_buffer(char *str, char **line, int up)
return 1; return 1;
} }
static int static int
cdi_cue_get_keyword(char **dest, char **line) cdi_cue_get_keyword(char **dest, char **line)
{ {
@@ -686,7 +654,6 @@ cdi_cue_get_keyword(char **dest, char **line)
return success; return success;
} }
/* Get a string from the input line, handling quotes properly. */ /* Get a string from the input line, handling quotes properly. */
static uint64_t static uint64_t
cdi_cue_get_number(char **line) cdi_cue_get_number(char **line)
@@ -703,7 +670,6 @@ cdi_cue_get_number(char **line)
return num; return num;
} }
static int static int
cdi_cue_get_frame(uint64_t *frames, char **line) cdi_cue_get_frame(uint64_t *frames, char **line)
{ {
@@ -724,7 +690,6 @@ cdi_cue_get_frame(uint64_t *frames, char **line)
return 1; return 1;
} }
static int static int
cdi_cue_get_flags(track_t *cur, char **line) cdi_cue_get_flags(track_t *cur, char **line)
{ {
@@ -745,7 +710,6 @@ cdi_cue_get_flags(track_t *cur, char **line)
return 1; return 1;
} }
static int static int
cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, uint64_t *total_pregap, uint64_t cur_pregap) cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, uint64_t *total_pregap, uint64_t cur_pregap)
{ {
@@ -813,7 +777,6 @@ cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, u
return 1; return 1;
} }
int int
cdi_load_cue(cd_img_t *cdi, const char *cuefile) cdi_load_cue(cd_img_t *cdi, const char *cuefile)
{ {
@@ -955,7 +918,7 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
index = cdi_cue_get_number(&line); index = cdi_cue_get_number(&line);
success = cdi_cue_get_frame(&frame, &line); success = cdi_cue_get_frame(&frame, &line);
switch(index) { switch (index) {
case 0: case 0:
prestart = frame; prestart = frame;
break; break;
@@ -1010,9 +973,7 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
success = cdi_cue_get_frame(&cur_pregap, &line); success = cdi_cue_get_frame(&cur_pregap, &line);
else if (!strcmp(command, "FLAGS")) else if (!strcmp(command, "FLAGS"))
success = cdi_cue_get_flags(&trk, &line); success = cdi_cue_get_flags(&trk, &line);
else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || !strcmp(command, "ISRC") || else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || !strcmp(command, "POSTGAP") || !strcmp(command, "REM") || !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || !strcmp(command, "")) {
!strcmp(command, "PERFORMER") || !strcmp(command, "POSTGAP") || !strcmp(command, "REM") ||
!strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || !strcmp(command, "")) {
/* Ignored commands. */ /* Ignored commands. */
success = 1; success = 1;
} else { } else {
@@ -1047,7 +1008,6 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile)
return 1; return 1;
} }
int int
cdi_has_data_track(cd_img_t *cdi) cdi_has_data_track(cd_img_t *cdi)
{ {
@@ -1065,7 +1025,6 @@ cdi_has_data_track(cd_img_t *cdi)
return 0; return 0;
} }
int int
cdi_has_audio_track(cd_img_t *cdi) cdi_has_audio_track(cd_img_t *cdi)
{ {