Applied all relevant upstream commits.

This commit is contained in:
waltje
2018-03-20 22:40:04 -05:00
parent e01f05c0f1
commit 73a0ba8e39
16 changed files with 288 additions and 149 deletions

View File

@@ -6,10 +6,9 @@
*
* This file is part of the VARCem Project.
*
* Implementation of the IDE emulation for hard disks and ATAPI
* CD-ROM devices.
* Emulation of hard disk, CD-ROM and ZIP IDE/ATAPI devices.
*
* Version: @(#)hdc_ide.c 1.0.11 2018/03/18
* Version: @(#)hdc_ide.c 1.0.12 2018/03/20
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <tommowalker@tommowalker.co.uk>
@@ -523,11 +522,12 @@ static void ide_atapi_zip_identify(IDE *ide)
uint8_t zip_id;
int32_t d;
memset(ide->buffer, 0, 512);
zip_id = atapi_zip_drives[ide->channel];
/* Using (2<<5) below makes the ASUS P/I-P54TP4XE misdentify the ZIP drive
as a LS-120. */
ide->buffer[0] = 0x8000 | (0<<8) | 0x80 | (1<<5); /* ATAPI device, direct-access device, removable media, accelerated DRQ */
ide->buffer[0] = 0x8000 | (0<<8) | 0x80 | (1<<5); /* ATAPI device, direct-access device, removable media, interrupt DRQ */
ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */
if (zip_drives[zip_id].is_250) {
ide_padstr((char *) (ide->buffer + 23), "42.S", 8); /* Firmware */
@@ -536,6 +536,8 @@ static void ide_atapi_zip_identify(IDE *ide)
ide_padstr((char *) (ide->buffer + 23), "E.08", 8); /* Firmware */
ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 100 ATAPI", 40); /* Model */
}
ide->buffer[48] = 1; /*Dword transfers supported*/
ide->buffer[49] = 0x200; /* LBA supported */
/* Note by Kotori: Look at this if this is supported by ZIP at all. */
@@ -563,6 +565,7 @@ static void ide_atapi_zip_identify(IDE *ide)
ide->buffer[52] = 120;
ide->buffer[53] = 2; /*Words 64-70 are valid*/
ide->buffer[63] = 0x0003; /*Multi-word DMA 0 & 1*/
ide->buffer[88] = 7;
ide->buffer[64] = 0x0001; /*PIO Mode 3*/
ide->buffer[65] = 120;
ide->buffer[66] = 120;
@@ -575,11 +578,12 @@ static void ide_atapi_zip_identify(IDE *ide)
d <<= 8;
if ((ide->mdma_mode & 0x300) == 0x200)
ide->buffer[88] |= d;
else if ((ide->mdma_mode & 0x300) == 0x100)
ide->buffer[63] |= d;
else if ((ide->mdma_mode & 0x300) == 0x400) {
if ((ide->mdma_mode & 0xff) >= 3)
ide->buffer[64] |= d;
} else
ide->buffer[63] |= d;
}
ide_log("PIDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
}
}
@@ -705,7 +709,7 @@ static int ide_set_features(IDE *ide)
if (!PCI || !dma || (ide->board >= 2))
max_pio = 0;
else
max_pio = 2;
max_pio = 4;
}
ide_log("Features code %02X\n", features);
@@ -883,6 +887,7 @@ void ide_reset(void)
ide_log("Found IDE hard disk on channel %i\n", hdd[d].ide_channel);
loadhd(&ide_drives[hdd[d].ide_channel], d, hdd[d].fn);
ide_drives[hdd[d].ide_channel].sector_buffer = (uint8_t *) malloc(256*512);
memset(ide_drives[hdd[d].ide_channel].sector_buffer, 0, 256*512);
if (++c >= (IDE_NUM+XTIDE_NUM)) break;
}
if ((hdd[d].bus==HDD_BUS_XTIDE) && (hdd[d].xtide_channel < XTIDE_NUM))
@@ -890,6 +895,7 @@ void ide_reset(void)
ide_log("Found XT IDE hard disk on channel %i\n", hdd[d].xtide_channel);
loadhd(&ide_drives[hdd[d].xtide_channel | 8], d, hdd[d].fn);
ide_drives[hdd[d].xtide_channel | 8].sector_buffer = (uint8_t *) malloc(256*512);
memset(ide_drives[hdd[d].ide_channel].sector_buffer, 0, 256*512);
if (++c >= (IDE_NUM+XTIDE_NUM)) break;
}
}
@@ -902,8 +908,10 @@ void ide_reset(void)
else if (ide_drive_is_cdrom(&ide_drives[d]) && (ide_drives[d].type == IDE_NONE))
ide_drives[d].type = IDE_CDROM;
if (ide_drives[d].type != IDE_NONE)
if (ide_drives[d].type != IDE_NONE) {
ide_drives[d].buffer = (uint16_t *) malloc(65536 * sizeof(uint16_t));
memset(ide_drives[d].buffer, 0, 65536 * sizeof(uint16_t));
}
ide_set_signature(&ide_drives[d]);
@@ -929,6 +937,23 @@ void ide_reset(void)
}
void ide_set_all_signatures(void)
{
int d;
for (d = 0; d < IDE_NUM; d++)
{
ide_set_signature(&ide_drives[d]);
if (ide_drives[d].sector_buffer)
memset(ide_drives[d].sector_buffer, 0, 256*512);
if (ide_drives[d].buffer)
memset(ide_drives[d].buffer, 0, 65536 * sizeof(uint16_t));
}
}
void ide_reset_hard(void)
{
int d;
@@ -1536,14 +1561,15 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
zip[atapi_zip_drives[ide->channel]].packet_status = ZIP_PHASE_IDLE;
zip[atapi_zip_drives[ide->channel]].pos=0;
zip[atapi_zip_drives[ide->channel]].phase = 1;
zip[atapi_zip_drives[ide->channel]].status = READY_STAT | DRQ_STAT | (zip[atapi_zip_drives[ide->channel]].status & ERR_STAT);
zip[atapi_zip_drives[ide->channel]].status = READY_STAT | DRQ_STAT;
ide_irq_raise(ide); /* Interrupt IRQ, requires IRQ on any DRQ. */
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]]->packet_status = CDROM_PHASE_IDLE;
cdrom[atapi_cdrom_drives[ide->channel]]->pos=0;
cdrom[atapi_cdrom_drives[ide->channel]]->phase = 1;
cdrom[atapi_cdrom_drives[ide->channel]]->status = READY_STAT | DRQ_STAT | (cdrom[atapi_cdrom_drives[ide->channel]]->status & ERR_STAT);
cdrom[atapi_cdrom_drives[ide->channel]]->status = READY_STAT | DRQ_STAT;
}
else
{

View File

@@ -8,7 +8,7 @@
*
* Definitions for the IDE module.
*
* Version: @(#)hdc_ide.h 1.0.2 2018/03/15
* Version: @(#)hdc_ide.h 1.0.3 2018/03/20
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -106,6 +106,8 @@ extern void ide_init_first(void);
extern void ide_reset(void);
extern void ide_reset_hard(void);
extern void ide_set_all_signatures(void);
extern void ide_xtide_init(void);
extern void ide_pri_enable(void);

View File

@@ -9,7 +9,7 @@
* Implementation of the Iomega ZIP drive with SCSI(-like)
* commands, for both ATAPI and SCSI usage.
*
* Version: @(#)zip.c 1.0.6 2018/03/18
* Version: @(#)zip.c 1.0.7 2018/03/20
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -589,7 +589,7 @@ void zip_close(uint8_t id)
}
}
void build_atapi_zip_map()
void build_atapi_zip_map(void)
{
uint8_t i = 0;
@@ -613,7 +613,7 @@ int find_zip_for_scsi_id(uint8_t scsi_id, uint8_t scsi_lun)
return 0xff;
}
void build_scsi_zip_map()
void build_scsi_zip_map(void)
{
uint8_t i = 0;
uint8_t j = 0;
@@ -673,7 +673,6 @@ void zip_init(int id, int cdb_len_setting)
zip_log("ZIP %i: Bus type %i, bus mode %i\n", id, zip_drives[id].bus_type, zip_drives[id].bus_mode);
if (zip_drives[id].bus_type < ZIP_BUS_SCSI)
zip_set_signature(id);
zip_drives[id].max_blocks_at_once = 85;
zip[id].status = READY_STAT | DSC_STAT;
zip[id].pos = 0;
zip[id].packet_status = 0xff;
@@ -1174,9 +1173,18 @@ static void zip_data_phase_error(uint8_t id)
#define zipbufferb zip[id].buffer
int zip_data(uint8_t id, uint32_t *len, int out)
int zip_blocks(uint8_t id, uint32_t *len, int first_batch, int out)
{
int i = 0;
zip[id].data_pos = 0;
*len = 0;
if (!zip[id].sector_len) {
zip_command_complete(id);
return -1;
}
*len = zip[id].requested_blocks << 9;
if (zip[id].sector_pos >= zip_drives[id].medium_size) {
zip_log("ZIP %i: Trying to %s beyond the end of disk\n", id, out ? "write" : "read");
@@ -1184,40 +1192,15 @@ int zip_data(uint8_t id, uint32_t *len, int out)
return 0;
}
*len = 0;
zip_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len);
fseek(zip_drives[id].f, zip_drives[id].base + (zip[id].sector_pos << 9), SEEK_SET);
if (out)
fwrite(zipbufferb, 1, *len, zip_drives[id].f);
else
for (i = 0; i < zip[id].requested_blocks; i++) {
fseek(zip_drives[id].f, zip_drives[id].base + (zip[id].sector_pos << 9) + *len, SEEK_SET);
if (out)
fwrite(zipbufferb + *len, 1, 512, zip_drives[id].f);
else
fread(zipbufferb + *len, 1, 512, zip_drives[id].f);
*len += 512;
}
return 1;
}
int zip_blocks(uint8_t id, uint32_t *len, int first_batch, int out)
{
int ret = 0;
zip[id].data_pos = 0;
if (!zip[id].sector_len) {
zip_command_complete(id);
return -1;
}
zip_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", zip[id].requested_blocks, zip[id].sector_pos);
ret = zip_data(id, len, out);
zip_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len);
if (!ret)
return 0;
fread(zipbufferb, 1, *len, zip_drives[id].f);
zip_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len);
@@ -2414,6 +2397,7 @@ void zip_phase_callback(uint8_t id)
return;
case ZIP_PHASE_ERROR:
zip_log("ZIP %i: ZIP_PHASE_ERROR\n", id);
zip[id].status = READY_STAT | ERR_STAT;
zip[id].phase = 3;
zip[id].packet_status = 0xFF;
zip_irq_raise(id);

View File

@@ -9,7 +9,7 @@
* Implementation of the Iomega ZIP drive with SCSI(-like)
* commands, for both ATAPI and SCSI usage.
*
* Version: @(#)zip.h 1.0.3 2018/03/18
* Version: @(#)zip.h 1.0.4 2018/03/20
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -140,8 +140,6 @@ typedef struct {
} zip_t;
typedef struct {
int max_blocks_at_once;
int host_drive;
int prev_host_drive;