Files
86Box/src/cdrom-iso.c

437 lines
8.0 KiB
C
Raw Normal View History

/* Copyright holders: RichardG867, Tenshi
see COPYING for more details
*/
/*ISO CD-ROM support*/
#include "ibm.h"
#include "cdrom.h"
#include "cdrom-iso.h"
#include <sys/stat.h>
static CDROM iso_cdrom;
uint32_t last_block = 0;
static uint64_t image_size = 0;
static int iso_inited = 0;
char iso_path[1024];
void iso_close(void);
static FILE* iso_image;
static int iso_changed = 0;
static uint32_t iso_cd_pos = 0, iso_cd_end = 0;
void iso_audio_callback(int16_t *output, int len)
{
memset(output, 0, len * 2);
return;
}
void iso_audio_stop()
{
// pclog("iso_audio_stop stub\n");
}
static int get_track_nr(uint32_t pos)
{
// pclog("get_track_nr stub\n");
return 0;
}
static void iso_playaudio(uint32_t pos, uint32_t len, int ismsf)
{
// pclog("iso_playaudio stub\n");
return;
}
static void iso_pause(void)
{
// pclog("iso_pause stub\n");
return;
}
static void iso_resume(void)
{
// pclog("iso_resume stub\n");
return;
}
static void iso_stop(void)
{
// pclog("iso_stop stub\n");
return;
}
static void iso_seek(uint32_t pos)
{
// pclog("iso_seek stub\n");
return;
}
static int iso_ready(void)
{
if (strlen(iso_path) == 0)
{
return 0;
}
if (old_cdrom_drive != cdrom_drive)
{
// old_cdrom_drive = cdrom_drive;
return 1;
}
if (iso_changed)
{
iso_changed = 0;
return 1;
}
return 1;
}
/* Always return 0, because there is no way to change the ISO without unmounting and remounting it. */
static int iso_medium_changed(void)
{
if (strlen(iso_path) == 0)
{
return 0;
}
if (old_cdrom_drive != cdrom_drive)
{
old_cdrom_drive = cdrom_drive;
return 1;
}
if (iso_changed)
{
iso_changed = 0;
return 1;
}
return 0;
}
static uint8_t iso_getcurrentsubchannel(uint8_t *b, int msf)
{
// pclog("iso_getcurrentsubchannel stub\n");
return 0;
}
static void iso_eject(void)
{
// pclog("iso_eject stub\n");
}
static void iso_load(void)
{
// pclog("iso_load stub\n");
}
static void lba_to_msf(uint8_t *buf, int lba)
{
lba += 150;
buf[0] = (lba / 75) / 60;
buf[1] = (lba / 75) % 60;
buf[2] = lba % 75;
}
Applied all mainline PCem commits; Added experimental NVidia Riva TNT2 emulation (patch from MoochMcGee); ASUS P/I-P54TP4XE, ASUS P/I-P55T2P4, and ASUS P/I-P55TVP4 are back; National Semiconductor PC87306 Super I/O chip now correctly reenables devices after a chip power cycle; Several FDC improvements and the behavior is now a bit closer to real hardware (based on actual tests); Added MR Intel Advanced/ATX with Microid Research BIOS with support for 4 floppy drives and up to 4 IDE controllers; Added floppy drives 3 and 4, bringing the maximum to 4; You can now connect hard disks to the tertiary IDE controller; Correct undocumented behavior of the LEA instruction with register is back on 286 and later CPU's; Pentium-rea models with Intel chipsets now have port 92 (with alternate reset and alternate A20 toggle); Overhauled DMA channel read and write routines and fixed cascading; Improved IMG detection of a bad BPB (or complete lack of a BPB); Added preliminary emulation of PS/2 1.44 MB and PC-98 1.25 MB 3-mode drives (both have an inverted DENSEL pin); Removed the incorrect Amstrad mouse patch from TheCollector1995; Fixed ATAPI CD-ROM disk change detection; Windows IOCTL CD-ROM handler now tries to use direct SCSI passthrough for more things, including obtaining CD-ROM capacity; The Diamond Stealth32 (ET4000/W32p) now also works correctly on the two Award SiS 496/497 boxes; The (S)VGA handler now converts 6-bit RAMDAC RGB channels to standard 8-bit RGB using a lookup table generated at emulator start, calculated using the correct intensity conversion method and treating intensity 64 as equivalent to 63; Moved a few options from the Configuration dialog box to the menu; SIO, PIIX, and PIIX3 now have the reset control register on port CF9 as they should; Several bugfixes.
2016-12-23 03:16:24 +01:00
static int iso_sector_data_type(int sector, int ismsf)
{
Applied all mainline PCem commits; Added experimental NVidia Riva TNT2 emulation (patch from MoochMcGee); ASUS P/I-P54TP4XE, ASUS P/I-P55T2P4, and ASUS P/I-P55TVP4 are back; National Semiconductor PC87306 Super I/O chip now correctly reenables devices after a chip power cycle; Several FDC improvements and the behavior is now a bit closer to real hardware (based on actual tests); Added MR Intel Advanced/ATX with Microid Research BIOS with support for 4 floppy drives and up to 4 IDE controllers; Added floppy drives 3 and 4, bringing the maximum to 4; You can now connect hard disks to the tertiary IDE controller; Correct undocumented behavior of the LEA instruction with register is back on 286 and later CPU's; Pentium-rea models with Intel chipsets now have port 92 (with alternate reset and alternate A20 toggle); Overhauled DMA channel read and write routines and fixed cascading; Improved IMG detection of a bad BPB (or complete lack of a BPB); Added preliminary emulation of PS/2 1.44 MB and PC-98 1.25 MB 3-mode drives (both have an inverted DENSEL pin); Removed the incorrect Amstrad mouse patch from TheCollector1995; Fixed ATAPI CD-ROM disk change detection; Windows IOCTL CD-ROM handler now tries to use direct SCSI passthrough for more things, including obtaining CD-ROM capacity; The Diamond Stealth32 (ET4000/W32p) now also works correctly on the two Award SiS 496/497 boxes; The (S)VGA handler now converts 6-bit RAMDAC RGB channels to standard 8-bit RGB using a lookup table generated at emulator start, calculated using the correct intensity conversion method and treating intensity 64 as equivalent to 63; Moved a few options from the Configuration dialog box to the menu; SIO, PIIX, and PIIX3 now have the reset control register on port CF9 as they should; Several bugfixes.
2016-12-23 03:16:24 +01:00
return 2; /* Always Mode 1 */
}
static void iso_readsector_raw(uint8_t *b, int sector, int ismsf)
{
uint32_t temp;
if (!cdrom_drive) return;
memset(b, 0, 2856);
if (ismsf)
{
int m = (sector >> 16) & 0xff;
int s = (sector >> 8) & 0xff;
int f = sector & 0xff;
sector = (m * 60 * 75) + (s * 75) + f;
if (sector < 150)
{
memset(b, 0, 2856);
return;
}
sector -= 150;
}
iso_image = fopen(iso_path, "rb");
fseek(iso_image, sector*2048, SEEK_SET);
fread(b+16, 2048, 1, iso_image);
fclose(iso_image);
/* sync bytes */
b[0] = 0;
memset(b + 1, 0xff, 10);
b[11] = 0;
b += 12;
lba_to_msf(b, sector);
b[3] = 1; /* mode 1 data */
b += 4;
b += 2048;
memset(b, 0, 288);
b += 288;
memset(b, 0, 392);
}
static int iso_readtoc(unsigned char *buf, unsigned char start_track, int msf, int maxlen, int single)
{
uint8_t *q;
int len;
if (start_track > 1 && start_track != 0xaa)
return -1;
q = buf + 2;
*q++ = 1; /* first session */
*q++ = 1; /* last session */
if (start_track <= 1) {
*q++ = 0; /* reserved */
*q++ = 0x14; /* ADR, control */
*q++ = 1; /* track number */
*q++ = 0; /* reserved */
if (msf) {
*q++ = 0; /* reserved */
lba_to_msf(q, 0);
q += 3;
} else {
/* sector 0 */
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
}
}
/* lead out track */
*q++ = 0; /* reserved */
*q++ = 0x16; /* ADR, control */
*q++ = 0xaa; /* track number */
*q++ = 0; /* reserved */
last_block = image_size >> 11;
if (msf) {
*q++ = 0; /* reserved */
lba_to_msf(q, last_block);
q += 3;
} else {
*q++ = last_block >> 24;
*q++ = last_block >> 16;
*q++ = last_block >> 8;
*q++ = last_block;
}
len = q - buf;
if (len > maxlen)
{
len = maxlen;
}
buf[0] = (uint8_t)(((len-2) >> 8) & 0xff);
buf[1] = (uint8_t)((len-2) & 0xff);
return len;
}
static int iso_readtoc_session(unsigned char *buf, int msf, int maxlen)
{
uint8_t *q;
q = buf + 2;
*q++ = 1; /* first session */
*q++ = 1; /* last session */
*q++ = 1; /* session number */
*q++ = 0x14; /* data track */
*q++ = 0; /* track number */
*q++ = 0xa0; /* lead-in */
*q++ = 0; /* min */
*q++ = 0; /* sec */
*q++ = 0; /* frame */
*q++ = 0;
if (maxlen < 12)
{
return maxlen;
}
return 12;
}
static int iso_readtoc_raw(unsigned char *buf, int msf, int maxlen)
{
uint8_t *q;
int len;
q = buf + 2;
*q++ = 1; /* first session */
*q++ = 1; /* last session */
*q++ = 1; /* session number */
*q++ = 0x14; /* data track */
*q++ = 0; /* track number */
*q++ = 0xa0; /* lead-in */
*q++ = 0; /* min */
*q++ = 0; /* sec */
*q++ = 0; /* frame */
*q++ = 0;
*q++ = 1; /* first track */
*q++ = 0x00; /* disk type */
*q++ = 0x00;
*q++ = 1; /* session number */
*q++ = 0x14; /* data track */
*q++ = 0; /* track number */
*q++ = 0xa1;
*q++ = 0; /* min */
*q++ = 0; /* sec */
*q++ = 0; /* frame */
*q++ = 0;
*q++ = 1; /* last track */
*q++ = 0x00;
*q++ = 0x00;
*q++ = 1; /* session number */
*q++ = 0x14; /* data track */
*q++ = 0; /* track number */
*q++ = 0xa2; /* lead-out */
*q++ = 0; /* min */
*q++ = 0; /* sec */
*q++ = 0; /* frame */
last_block = image_size >> 11;
/* this is raw, must be msf */
if (msf)
{
*q++ = 0; /* reserved */
lba_to_msf(q, last_block);
q += 3;
}
else
{
*q++ = (last_block >> 24) & 0xff;
*q++ = (last_block >> 16) & 0xff;
*q++ = (last_block >> 8) & 0xff;
*q++ = last_block & 0xff;
}
*q++ = 1; /* session number */
*q++ = 0x14; /* ADR, control */
*q++ = 0; /* track number */
*q++ = 1; /* point */
*q++ = 0; /* min */
*q++ = 0; /* sec */
*q++ = 0; /* frame */
/* same here */
if (msf)
{
*q++ = 0; /* reserved */
lba_to_msf(q, 0);
q += 3;
}
else
{
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
}
len = q - buf;
if (len > maxlen)
{
len = maxlen;
}
buf[0] = (uint8_t)(((len-2) >> 8) & 0xff);
buf[1] = (uint8_t)((len-2) & 0xff);
return len;
}
static uint32_t iso_size()
{
unsigned char b[4096];
cdrom->readtoc(b, 0, 0, 4096, 0);
return last_block;
}
static int iso_status()
{
if (!(iso_ready()) && (cdrom_drive != 200)) return CD_STATUS_EMPTY;
return CD_STATUS_DATA_ONLY;
}
void iso_reset()
{
}
int iso_open(char *fn)
{
struct stat st;
if (strcmp(fn, iso_path) != 0)
{
iso_changed = 1;
}
/* Make sure iso_changed stays when changing from ISO to another ISO. */
if (!iso_inited && (cdrom_drive != 200)) iso_changed = 0;
if (!iso_inited || iso_changed)
{
sprintf(iso_path, "%s", fn);
// pclog("Path is %s\n", iso_path);
}
iso_image = fopen(iso_path, "rb");
cdrom = &iso_cdrom;
if (!iso_inited || iso_changed)
{
if (!iso_inited) iso_inited = 1;
fclose(iso_image);
}
stat(iso_path, &st);
image_size = st.st_size;
return 0;
}
void iso_close(void)
{
if (iso_image) fclose(iso_image);
memset(iso_path, 0, 1024);
}
static void iso_exit(void)
{
// iso_stop();
iso_inited = 0;
}
static int iso_is_track_audio(uint32_t pos, int ismsf)
{
return 0;
}
static CDROM iso_cdrom =
{
iso_ready,
iso_medium_changed,
iso_readtoc,
iso_readtoc_session,
iso_readtoc_raw,
iso_getcurrentsubchannel,
Applied all mainline PCem commits; Added experimental NVidia Riva TNT2 emulation (patch from MoochMcGee); ASUS P/I-P54TP4XE, ASUS P/I-P55T2P4, and ASUS P/I-P55TVP4 are back; National Semiconductor PC87306 Super I/O chip now correctly reenables devices after a chip power cycle; Several FDC improvements and the behavior is now a bit closer to real hardware (based on actual tests); Added MR Intel Advanced/ATX with Microid Research BIOS with support for 4 floppy drives and up to 4 IDE controllers; Added floppy drives 3 and 4, bringing the maximum to 4; You can now connect hard disks to the tertiary IDE controller; Correct undocumented behavior of the LEA instruction with register is back on 286 and later CPU's; Pentium-rea models with Intel chipsets now have port 92 (with alternate reset and alternate A20 toggle); Overhauled DMA channel read and write routines and fixed cascading; Improved IMG detection of a bad BPB (or complete lack of a BPB); Added preliminary emulation of PS/2 1.44 MB and PC-98 1.25 MB 3-mode drives (both have an inverted DENSEL pin); Removed the incorrect Amstrad mouse patch from TheCollector1995; Fixed ATAPI CD-ROM disk change detection; Windows IOCTL CD-ROM handler now tries to use direct SCSI passthrough for more things, including obtaining CD-ROM capacity; The Diamond Stealth32 (ET4000/W32p) now also works correctly on the two Award SiS 496/497 boxes; The (S)VGA handler now converts 6-bit RAMDAC RGB channels to standard 8-bit RGB using a lookup table generated at emulator start, calculated using the correct intensity conversion method and treating intensity 64 as equivalent to 63; Moved a few options from the Configuration dialog box to the menu; SIO, PIIX, and PIIX3 now have the reset control register on port CF9 as they should; Several bugfixes.
2016-12-23 03:16:24 +01:00
NULL,
NULL,
NULL,
NULL,
Applied all mainline PCem commits; Added experimental NVidia Riva TNT2 emulation (patch from MoochMcGee); ASUS P/I-P54TP4XE, ASUS P/I-P55T2P4, and ASUS P/I-P55TVP4 are back; National Semiconductor PC87306 Super I/O chip now correctly reenables devices after a chip power cycle; Several FDC improvements and the behavior is now a bit closer to real hardware (based on actual tests); Added MR Intel Advanced/ATX with Microid Research BIOS with support for 4 floppy drives and up to 4 IDE controllers; Added floppy drives 3 and 4, bringing the maximum to 4; You can now connect hard disks to the tertiary IDE controller; Correct undocumented behavior of the LEA instruction with register is back on 286 and later CPU's; Pentium-rea models with Intel chipsets now have port 92 (with alternate reset and alternate A20 toggle); Overhauled DMA channel read and write routines and fixed cascading; Improved IMG detection of a bad BPB (or complete lack of a BPB); Added preliminary emulation of PS/2 1.44 MB and PC-98 1.25 MB 3-mode drives (both have an inverted DENSEL pin); Removed the incorrect Amstrad mouse patch from TheCollector1995; Fixed ATAPI CD-ROM disk change detection; Windows IOCTL CD-ROM handler now tries to use direct SCSI passthrough for more things, including obtaining CD-ROM capacity; The Diamond Stealth32 (ET4000/W32p) now also works correctly on the two Award SiS 496/497 boxes; The (S)VGA handler now converts 6-bit RAMDAC RGB channels to standard 8-bit RGB using a lookup table generated at emulator start, calculated using the correct intensity conversion method and treating intensity 64 as equivalent to 63; Moved a few options from the Configuration dialog box to the menu; SIO, PIIX, and PIIX3 now have the reset control register on port CF9 as they should; Several bugfixes.
2016-12-23 03:16:24 +01:00
iso_sector_data_type,
iso_readsector_raw,
iso_playaudio,
iso_seek,
iso_load,
iso_eject,
iso_pause,
iso_resume,
iso_size,
iso_status,
iso_is_track_audio,
iso_stop,
iso_exit
};