Cleanup of the logging options. Logging menu is now submenu of Tools.
Other minor changes and cleanups, as needed.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Common code to handle all sorts of disk controllers.
|
||||
*
|
||||
* Version: @(#)hdc.c 1.0.3 2018/03/18
|
||||
* Version: @(#)hdc.c 1.0.4 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include "../emu.h"
|
||||
#include "../machine/machine.h"
|
||||
#include "../device.h"
|
||||
@@ -47,6 +48,9 @@
|
||||
|
||||
char *hdc_name; /* configured HDC name */
|
||||
int hdc_current;
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
int hdc_do_log = ENABLE_HDC_LOG;
|
||||
#endif
|
||||
|
||||
|
||||
static void *
|
||||
@@ -150,13 +154,30 @@ static const struct {
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
hdc_log(const char *fmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_IDE_LOG
|
||||
va_list ap;
|
||||
|
||||
if (hdc_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Initialize the 'hdc_current' value based on configured HDC name. */
|
||||
void
|
||||
hdc_init(char *name)
|
||||
{
|
||||
int c;
|
||||
|
||||
pclog("HDC: initializing..\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("HDC: initializing..\n");
|
||||
#endif
|
||||
|
||||
for (c=0; controllers[c].device; c++) {
|
||||
if (! strcmp(name, (char *)controllers[c].internal_name)) {
|
||||
@@ -171,8 +192,10 @@ hdc_init(char *name)
|
||||
void
|
||||
hdc_reset(void)
|
||||
{
|
||||
pclog("HDC: reset(current=%d, internal=%d)\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("HDC: reset(current=%d, internal=%d)\n",
|
||||
hdc_current, (machines[machine].flags & MACHINE_HDC)?1:0);
|
||||
#endif
|
||||
|
||||
/* If we have a valid controller, add its device. */
|
||||
if (hdc_current > 1)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Definitions for the common disk controller handler.
|
||||
*
|
||||
* Version: @(#)hdc.h 1.0.2 2018/03/15
|
||||
* Version: @(#)hdc.h 1.0.3 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -46,10 +46,11 @@
|
||||
* least 7 devices, with each device being
|
||||
* able to support 8 units, but hey... */
|
||||
|
||||
extern char *hdc_name;
|
||||
extern int hdc_current;
|
||||
|
||||
extern char *hdc_name;
|
||||
extern int hdc_current;
|
||||
extern int hdc_do_log;
|
||||
|
||||
#ifdef EMU_DEVICE_H
|
||||
extern const device_t mfm_xt_xebec_device; /* mfm_xt_xebec */
|
||||
extern const device_t mfm_xt_dtc5150x_device; /* mfm_xt_dtc */
|
||||
extern const device_t mfm_at_wd1003_device; /* mfm_at_wd1003 */
|
||||
@@ -69,8 +70,10 @@ extern const device_t xtide_device; /* xtide_xt */
|
||||
extern const device_t xtide_at_device; /* xtide_at */
|
||||
extern const device_t xtide_acculogic_device; /* xtide_ps2 */
|
||||
extern const device_t xtide_at_ps2_device; /* xtide_at_ps2 */
|
||||
#endif
|
||||
|
||||
|
||||
extern void hdc_log(const char *fmt, ...);
|
||||
extern void hdc_init(char *name);
|
||||
extern void hdc_reset(void);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Driver for the ESDI controller (WD1007-vse1) for PC/AT.
|
||||
*
|
||||
* Version: @(#)hdc_esdi_at.c 1.0.6 2018/04/01
|
||||
* Version: @(#)hdc_esdi_at.c 1.0.6 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -122,7 +122,8 @@ typedef struct {
|
||||
} esdi_t;
|
||||
|
||||
|
||||
static __inline void irq_raise(esdi_t *esdi)
|
||||
static __inline void
|
||||
irq_raise(esdi_t *esdi)
|
||||
{
|
||||
/* If not already pending.. */
|
||||
if (! esdi->irqstat) {
|
||||
@@ -138,7 +139,8 @@ static __inline void irq_raise(esdi_t *esdi)
|
||||
}
|
||||
|
||||
|
||||
static __inline void irq_lower(esdi_t *esdi)
|
||||
static __inline void
|
||||
irq_lower(esdi_t *esdi)
|
||||
{
|
||||
/* If raised.. */
|
||||
if (esdi->irqstat) {
|
||||
@@ -164,12 +166,16 @@ get_sector(esdi_t *esdi, off64_t *addr)
|
||||
int c, h, s;
|
||||
|
||||
if (esdi->head > heads) {
|
||||
pclog("esdi_get_sector: past end of configured heads\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("esdi_get_sector: past end of configured heads\n");
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (esdi->sector >= sectors+1) {
|
||||
pclog("esdi_get_sector: past end of configured sectors\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("esdi_get_sector: past end of configured sectors\n");
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
@@ -238,8 +244,8 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
{
|
||||
esdi_t *esdi = (esdi_t *)priv;
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("WD1007 write(%04x, %02x)\n", port, val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007 write(%04x, %02x)\n", port, val);
|
||||
#endif
|
||||
|
||||
switch (port) {
|
||||
@@ -282,8 +288,8 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
esdi->command = val;
|
||||
esdi->error = 0;
|
||||
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1007: command %02x\n", val & 0xf0);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: command %02x\n", val & 0xf0);
|
||||
#endif
|
||||
switch (val & 0xf0) {
|
||||
case CMD_RESTORE:
|
||||
@@ -374,7 +380,9 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
pclog("WD1007: bad command %02X\n", val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: bad command %02X\n", val);
|
||||
#endif
|
||||
case 0xe8: /*???*/
|
||||
esdi->status = STAT_BUSY;
|
||||
timer_clock();
|
||||
@@ -478,8 +486,8 @@ esdi_read(uint16_t port, void *priv)
|
||||
break;
|
||||
}
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("WD1007 read(%04x) = %02x\n", port, temp);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007 read(%04x) = %02x\n", port, temp);
|
||||
#endif
|
||||
|
||||
return(temp);
|
||||
@@ -508,8 +516,8 @@ esdi_callback(void *priv)
|
||||
return;
|
||||
}
|
||||
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1007: command %02x\n", esdi->command);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: command %02x\n", esdi->command);
|
||||
#endif
|
||||
|
||||
switch (esdi->command) {
|
||||
@@ -656,8 +664,8 @@ esdi_callback(void *priv)
|
||||
|
||||
drive->cfg_spt = esdi->secount;
|
||||
drive->cfg_hpc = esdi->head+1;
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1007: parameters: spt=%i hpc=%i\n", drive->cfg_spt,drive->cfg_hpc);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: parameters: spt=%i hpc=%i\n", drive->cfg_spt,drive->cfg_hpc);
|
||||
#endif
|
||||
if (! esdi->secount)
|
||||
fatal("WD1007: secount=0\n");
|
||||
@@ -697,8 +705,11 @@ esdi_callback(void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
pclog("WD1007: bad read config %02x\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: bad read config %02x\n",
|
||||
esdi->cylinder >> 8);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
esdi->status = STAT_READY|STAT_DSC;
|
||||
irq_raise(esdi);
|
||||
@@ -754,7 +765,9 @@ esdi_callback(void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
pclog("WD1007: callback on unknown command %02x\n", esdi->command);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: callback on unknown command %02x\n", esdi->command);
|
||||
#endif
|
||||
/*FALLTHROUGH*/
|
||||
|
||||
case 0xe8:
|
||||
@@ -774,7 +787,9 @@ loadhd(esdi_t *esdi, int hdd_num, int d, const wchar_t *fn)
|
||||
drive_t *drive = &esdi->drives[hdd_num];
|
||||
|
||||
if (! hdd_image_load(d)) {
|
||||
pclog("WD1007: drive %d not present!\n", d);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1007: drive %d not present!\n", d);
|
||||
#endif
|
||||
drive->present = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
* however, are auto-configured by the system software as
|
||||
* shown above.
|
||||
*
|
||||
* Version: @(#)hdc_esdi_mca.c 1.0.5 2018/04/01
|
||||
* Version: @(#)hdc_esdi_mca.c 1.0.5 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Sarah Walker, <tommowalker@tommowalker.co.uk>
|
||||
@@ -227,7 +227,6 @@ clear_irq(esdi_t *dev)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
cmd_unsupported(esdi_t *dev)
|
||||
{
|
||||
@@ -245,6 +244,7 @@ cmd_unsupported(esdi_t *dev)
|
||||
dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL;
|
||||
dev->irq_status = dev->cmd_dev | IRQ_CMD_COMPLETE_FAILURE;
|
||||
dev->irq_in_progress = 1;
|
||||
|
||||
set_irq(dev);
|
||||
}
|
||||
|
||||
@@ -266,26 +266,30 @@ device_not_present(esdi_t *dev)
|
||||
dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL;
|
||||
dev->irq_status = dev->cmd_dev | IRQ_CMD_COMPLETE_FAILURE;
|
||||
dev->irq_in_progress = 1;
|
||||
|
||||
set_irq(dev);
|
||||
}
|
||||
|
||||
static void rba_out_of_range(esdi_t *dev)
|
||||
{
|
||||
dev->status_len = 9;
|
||||
dev->status_data[0] = dev->command | STATUS_LEN(9) | dev->cmd_dev;
|
||||
dev->status_data[1] = 0x0e01; /*Command block error, invalid parameter*/
|
||||
dev->status_data[2] = 0x0007; /*RBA out of range*/
|
||||
dev->status_data[3] = 0;
|
||||
dev->status_data[4] = 0;
|
||||
dev->status_data[5] = 0;
|
||||
dev->status_data[6] = 0;
|
||||
dev->status_data[7] = 0;
|
||||
dev->status_data[8] = 0;
|
||||
|
||||
dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL;
|
||||
dev->irq_status = dev->cmd_dev | IRQ_CMD_COMPLETE_FAILURE;
|
||||
dev->irq_in_progress = 1;
|
||||
set_irq(dev);
|
||||
static void
|
||||
rba_out_of_range(esdi_t *dev)
|
||||
{
|
||||
dev->status_len = 9;
|
||||
dev->status_data[0] = dev->command | STATUS_LEN(9) | dev->cmd_dev;
|
||||
dev->status_data[1] = 0x0e01; /*Command block error, invalid parameter*/
|
||||
dev->status_data[2] = 0x0007; /*RBA out of range*/
|
||||
dev->status_data[3] = 0;
|
||||
dev->status_data[4] = 0;
|
||||
dev->status_data[5] = 0;
|
||||
dev->status_data[6] = 0;
|
||||
dev->status_data[7] = 0;
|
||||
dev->status_data[8] = 0;
|
||||
|
||||
dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL;
|
||||
dev->irq_status = dev->cmd_dev | IRQ_CMD_COMPLETE_FAILURE;
|
||||
dev->irq_in_progress = 1;
|
||||
|
||||
set_irq(dev);
|
||||
}
|
||||
|
||||
#define ESDI_ADAPTER_ONLY() do \
|
||||
@@ -562,7 +566,7 @@ esdi_callback(void *priv)
|
||||
dev->status_data[5] = drive->hpc | (drive->spt << 16);
|
||||
|
||||
#if 0
|
||||
pclog("CMD_GET_DEV_CONFIG %i %04x %04x %04x %04x %04x %04x\n",
|
||||
hdc_log("CMD_GET_DEV_CONFIG %i %04x %04x %04x %04x %04x %04x\n",
|
||||
drive->sectors,
|
||||
dev->status_data[0], dev->status_data[1],
|
||||
dev->status_data[2], dev->status_data[3],
|
||||
@@ -723,7 +727,7 @@ esdi_callback(void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("BAD COMMAND %02x %i\n", dev->command, dev->cmd_dev);
|
||||
hdc_log("BAD COMMAND %02x %i\n", dev->command, dev->cmd_dev);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,7 +749,7 @@ esdi_read(uint16_t port, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("esdi_read port=%04x\n", port);
|
||||
hdc_log("esdi_read port=%04x\n", port);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
@@ -757,8 +761,8 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
{
|
||||
esdi_t *dev = (esdi_t *)priv;
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("ESDI: wr(%04x, %02x)\n", port-dev->base, val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ESDI: wr(%04x, %02x)\n", port-dev->base, val);
|
||||
#endif
|
||||
switch (port-dev->base) {
|
||||
case 2: /*Basic control register*/
|
||||
@@ -799,7 +803,7 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Bad attention request %02x\n", val);
|
||||
hdc_log("Bad attention request %02x\n", val);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -821,7 +825,7 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Bad attention request %02x\n", val);
|
||||
hdc_log("Bad attention request %02x\n", val);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -843,17 +847,17 @@ esdi_write(uint16_t port, uint8_t val, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Bad attention request %02x\n", val);
|
||||
hdc_log("Bad attention request %02x\n", val);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Attention to unknown device %02x\n", val);
|
||||
hdc_log("Attention to unknown device %02x\n", val);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("esdi_write port=%04x val=%02x\n", port, val);
|
||||
hdc_log("esdi_write port=%04x val=%02x\n", port, val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,7 +880,7 @@ esdi_readw(uint16_t port, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("esdi_readw port=%04x\n", port);
|
||||
hdc_log("esdi_readw port=%04x\n", port);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
@@ -888,8 +892,8 @@ esdi_writew(uint16_t port, uint16_t val, void *priv)
|
||||
{
|
||||
esdi_t *dev = (esdi_t *)priv;
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("ESDI: wrw(%04x, %04x)\n", port-dev->base, val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ESDI: wrw(%04x, %04x)\n", port-dev->base, val);
|
||||
#endif
|
||||
switch (port-dev->base) {
|
||||
case 0: /*Command Interface Register*/
|
||||
@@ -912,7 +916,7 @@ esdi_writew(uint16_t port, uint16_t val, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("esdi_writew port=%04x val=%04x\n", port, val);
|
||||
hdc_log("esdi_writew port=%04x val=%04x\n", port, val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -922,8 +926,8 @@ esdi_mca_read(int port, void *priv)
|
||||
{
|
||||
esdi_t *dev = (esdi_t *)priv;
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("ESDI: mcard(%04x)\n", port);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ESDI: mcard(%04x)\n", port);
|
||||
#endif
|
||||
return(dev->pos_regs[port & 7]);
|
||||
}
|
||||
@@ -934,8 +938,8 @@ esdi_mca_write(int port, uint8_t val, void *priv)
|
||||
{
|
||||
esdi_t *dev = (esdi_t *)priv;
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("ESDI: mcawr(%04x, %02x) pos[2]=%02x pos[3]=%02x\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ESDI: mcawr(%04x, %02x) pos[2]=%02x pos[3]=%02x\n",
|
||||
port, val, dev->pos_regs[2], dev->pos_regs[3]);
|
||||
#endif
|
||||
if (port < 0x102) return;
|
||||
@@ -1053,7 +1057,7 @@ esdi_mca_write(int port, uint8_t val, void *priv)
|
||||
}
|
||||
|
||||
/* Say hello. */
|
||||
pclog("ESDI: I/O=%04x, IRQ=%d, DMA=%d, BIOS @%05X\n",
|
||||
hdc_log("ESDI: I/O=%04x, IRQ=%d, DMA=%d, BIOS @%05X\n",
|
||||
dev->base, dev->irq, dev->dma, dev->bios);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Emulation of hard disk, CD-ROM and ZIP IDE/ATAPI devices.
|
||||
*
|
||||
* Version: @(#)hdc_ide.c 1.0.15 2018/03/27
|
||||
* Version: @(#)hdc_ide.c 1.0.16 2018/04/02
|
||||
*
|
||||
* Authors: Miran Grca, <mgrca8@gmail.com>
|
||||
* Sarah Walker, <tommowalker@tommowalker.co.uk>
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include "../emu.h"
|
||||
#include "../version.h"
|
||||
#include "../cpu/cpu.h"
|
||||
@@ -137,26 +136,6 @@ int cur_ide[5];
|
||||
int ide_init_ch[2] = {0, 0};
|
||||
|
||||
|
||||
#ifdef ENABLE_IDE_LOG
|
||||
int ide_do_log = ENABLE_IDE_LOG;
|
||||
#endif
|
||||
|
||||
|
||||
static void ide_log(const char *fmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_IDE_LOG
|
||||
va_list ap;
|
||||
|
||||
if (ide_do_log)
|
||||
{
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t getstat(IDE *ide) { return ide->atastat; }
|
||||
|
||||
|
||||
@@ -213,7 +192,7 @@ int ide_irq[5] = { 14, 15, 10, 11, 0 };
|
||||
|
||||
void ide_irq_raise(IDE *ide)
|
||||
{
|
||||
/* ide_log("Attempting to raise IRQ %i (board %i)\n", ide_irq[ide->board], ide->board); */
|
||||
/* hdc_log("Attempting to raise IRQ %i (board %i)\n", ide_irq[ide->board], ide->board); */
|
||||
|
||||
if ((ide->board > 3) || ide->irqstat)
|
||||
{
|
||||
@@ -223,7 +202,9 @@ void ide_irq_raise(IDE *ide)
|
||||
return;
|
||||
}
|
||||
|
||||
ide_log("Raising IRQ %i (board %i)\n", ide_irq[ide->board], ide->board);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Raising IRQ %i (board %i)\n", ide_irq[ide->board], ide->board);
|
||||
#endif
|
||||
|
||||
if (!(ide->fdisk&2))
|
||||
{
|
||||
@@ -257,7 +238,9 @@ void ide_irq_lower(IDE *ide)
|
||||
return;
|
||||
}
|
||||
|
||||
ide_log("Lowering IRQ %i (board %i)\n", ide_irq[ide->board], ide->board);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Lowering IRQ %i (board %i)\n", ide_irq[ide->board], ide->board);
|
||||
#endif
|
||||
|
||||
if (pci_use_mirq(0) && (ide->board == 1))
|
||||
{
|
||||
@@ -342,7 +325,9 @@ static void ide_identify(IDE *ide)
|
||||
|
||||
device_identify[6] = (ide->hdd_num / 10) + 0x30;
|
||||
device_identify[7] = (ide->hdd_num % 10) + 0x30;
|
||||
ide_log("IDE Identify: %s\n", device_identify);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE Identify: %s\n", device_identify);
|
||||
#endif
|
||||
|
||||
memset(ide->buffer, 0, 512);
|
||||
d_spt = ide->spt;
|
||||
@@ -366,7 +351,9 @@ static void ide_identify(IDE *ide)
|
||||
ide->buffer[3] = 16; /* Heads in default CHS translation. */
|
||||
ide->buffer[6] = 63; /* Heads in default CHS translation. */
|
||||
}
|
||||
ide_log("Default CHS translation: %i, %i, %i\n", ide->buffer[1], ide->buffer[3], ide->buffer[6]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Default CHS translation: %i, %i, %i\n", ide->buffer[1], ide->buffer[3], ide->buffer[6]);
|
||||
#endif
|
||||
|
||||
ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */
|
||||
ide_padstr((char *) (ide->buffer + 23), EMU_VERSION, 8); /* Firmware */
|
||||
@@ -384,7 +371,9 @@ static void ide_identify(IDE *ide)
|
||||
if ((ide->tracks >= 1024) || (ide->hpc > 16) || (ide->spt > 63))
|
||||
{
|
||||
ide->buffer[49] |= (1 << 9);
|
||||
ide_log("LBA supported\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("LBA supported\n");
|
||||
#endif
|
||||
}
|
||||
ide->buffer[50] = 0x4000; /* Capabilities */
|
||||
ide->buffer[51] = 2 << 8; /*PIO timing mode*/
|
||||
@@ -393,7 +382,9 @@ static void ide_identify(IDE *ide)
|
||||
{
|
||||
ide->buffer[60] = full_size & 0xFFFF; /* Total addressable sectors (LBA) */
|
||||
ide->buffer[61] = (full_size >> 16) & 0x0FFF;
|
||||
ide_log("Full size: %" PRIu64 "\n", full_size);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Full size: %" PRIu64 "\n", full_size);
|
||||
#endif
|
||||
|
||||
ide->buffer[53] |= 1;
|
||||
|
||||
@@ -418,7 +409,9 @@ static void ide_identify(IDE *ide)
|
||||
ide->buffer[57] = full_size & 0xFFFF; /* Total addressable sectors (LBA) */
|
||||
ide->buffer[58] = (full_size >> 16) & 0x0FFF;
|
||||
|
||||
ide_log("Current CHS translation: %i, %i, %i\n", ide->buffer[54], ide->buffer[55], ide->buffer[56]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Current CHS translation: %i, %i, %i\n", ide->buffer[54], ide->buffer[55], ide->buffer[56]);
|
||||
#endif
|
||||
}
|
||||
|
||||
ide->buffer[59] = ide->blocksize ? (ide->blocksize | 0x100) : 0;
|
||||
@@ -446,7 +439,9 @@ static void ide_identify(IDE *ide)
|
||||
ide->buffer[64] |= d;
|
||||
} else
|
||||
ide->buffer[62] |= d;
|
||||
ide_log(" IDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log(" IDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
|
||||
#endif
|
||||
}
|
||||
ide->buffer[65] = 120;
|
||||
ide->buffer[66] = 120;
|
||||
@@ -471,7 +466,9 @@ static void ide_atapi_identify(IDE *ide)
|
||||
cdrom_id = atapi_cdrom_drives[ide->channel];
|
||||
|
||||
device_identify[7] = cdrom_id + 0x30;
|
||||
ide_log("ATAPI Identify: %s\n", device_identify);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ATAPI Identify: %s\n", device_identify);
|
||||
#endif
|
||||
|
||||
ide->buffer[0] = 0x8000 | (5<<8) | 0x80 | (2<<5); /* ATAPI device, CD-ROM drive, removable media, accelerated DRQ */
|
||||
ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */
|
||||
@@ -505,7 +502,9 @@ static void ide_atapi_identify(IDE *ide)
|
||||
ide->buffer[64] |= d;
|
||||
} else
|
||||
ide->buffer[62] |= d;
|
||||
ide_log("PIDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("PIDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
|
||||
#endif
|
||||
}
|
||||
ide->buffer[65] = 120;
|
||||
ide->buffer[66] = 120;
|
||||
@@ -584,7 +583,9 @@ static void ide_atapi_zip_identify(IDE *ide)
|
||||
if ((ide->mdma_mode & 0xff) >= 3)
|
||||
ide->buffer[64] |= d;
|
||||
}
|
||||
ide_log("PIDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("PIDENTIFY DMA Mode: %04X, %04X\n", ide->buffer[62], ide->buffer[63]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -712,14 +713,18 @@ static int ide_set_features(IDE *ide)
|
||||
max_pio = 4;
|
||||
}
|
||||
|
||||
ide_log("Features code %02X\n", features);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Features code %02X\n", features);
|
||||
|
||||
ide_log("IDE %02X: Set features: %02X, %02X\n", ide->channel, features, features_data);
|
||||
hdc_log("IDE %02X: Set features: %02X, %02X\n", ide->channel, features, features_data);
|
||||
#endif
|
||||
|
||||
switch(features)
|
||||
{
|
||||
case FEATURE_SET_TRANSFER_MODE: /* Set transfer mode. */
|
||||
ide_log("Transfer mode %02X\n", features_data >> 3);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Transfer mode %02X\n", features_data >> 3);
|
||||
#endif
|
||||
|
||||
mode = (features_data >> 3);
|
||||
submode = features_data & 7;
|
||||
@@ -732,7 +737,9 @@ static int ide_set_features(IDE *ide)
|
||||
return 0;
|
||||
}
|
||||
ide->mdma_mode = -1;
|
||||
ide_log("IDE %02X: Setting DPIO mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %02X: Setting DPIO mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 0x01: /* PIO mode */
|
||||
@@ -741,7 +748,9 @@ static int ide_set_features(IDE *ide)
|
||||
return 0;
|
||||
}
|
||||
ide->mdma_mode = (1 << submode) | 0x400;
|
||||
ide_log("IDE %02X: Setting PIO mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %02X: Setting PIO mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 0x02: /* Singleword DMA mode */
|
||||
@@ -750,7 +759,9 @@ static int ide_set_features(IDE *ide)
|
||||
return 0;
|
||||
}
|
||||
ide->mdma_mode = (1 << submode);
|
||||
ide_log("IDE %02X: Setting SDMA mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %02X: Setting SDMA mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 0x04: /* Multiword DMA mode */
|
||||
@@ -759,7 +770,9 @@ static int ide_set_features(IDE *ide)
|
||||
return 0;
|
||||
}
|
||||
ide->mdma_mode = (1 << submode) | 0x100;
|
||||
ide_log("IDE %02X: Setting MDMA mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %02X: Setting MDMA mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 0x08: /* Ultra DMA mode */
|
||||
@@ -768,7 +781,9 @@ static int ide_set_features(IDE *ide)
|
||||
return 0;
|
||||
}
|
||||
ide->mdma_mode = (1 << submode) | 0x200;
|
||||
ide_log("IDE %02X: Setting UDMA mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %02X: Setting UDMA mode: %02X, %08X\n", ide->channel, submode, ide->mdma_mode);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -878,13 +893,17 @@ void ide_reset(void)
|
||||
idecallback[2]=idecallback[3]=0LL;
|
||||
idecallback[4]=0LL;
|
||||
|
||||
ide_log("IDE: loading disks...\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE: loading disks...\n");
|
||||
#endif
|
||||
c = 0;
|
||||
for (d = 0; d < HDD_NUM; d++)
|
||||
{
|
||||
if (((hdd[d].bus == HDD_BUS_IDE_PIO_ONLY) || (hdd[d].bus == HDD_BUS_IDE_PIO_AND_DMA)) && (hdd[d].ide_channel < IDE_NUM))
|
||||
{
|
||||
ide_log("Found IDE hard disk on channel %i\n", hdd[d].ide_channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Found IDE hard disk on channel %i\n", hdd[d].ide_channel);
|
||||
#endif
|
||||
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);
|
||||
@@ -892,14 +911,18 @@ void ide_reset(void)
|
||||
}
|
||||
if ((hdd[d].bus==HDD_BUS_XTIDE) && (hdd[d].xtide_channel < XTIDE_NUM))
|
||||
{
|
||||
ide_log("Found XT IDE hard disk on channel %i\n", hdd[d].xtide_channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Found XT IDE hard disk on channel %i\n", hdd[d].xtide_channel);
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
}
|
||||
ide_log("IDE: done, loaded %d disks.\n", c);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE: done, loaded %d disks.\n", c);
|
||||
#endif
|
||||
|
||||
for (d = 0; d < IDE_NUM; d++)
|
||||
{
|
||||
@@ -1057,7 +1080,9 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
|
||||
IDE *ide = &ide_drives[cur_ide[ide_board]];
|
||||
IDE *ide_other = &ide_drives[cur_ide[ide_board] ^ 1];
|
||||
|
||||
ide_log("WriteIDE %04X %02X from %04X(%08X):%08X\n", addr, val, CS, cs, cpu_state.pc);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WriteIDE %04X %02X from %04X(%08X):%08X\n", addr, val, CS, cs, cpu_state.pc);
|
||||
#endif
|
||||
addr|=0x90;
|
||||
addr&=0xFFF7;
|
||||
|
||||
@@ -1073,12 +1098,16 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
|
||||
case 0x1F1: /* Features */
|
||||
if (ide_drive_is_zip(ide))
|
||||
{
|
||||
ide_log("ATAPI transfer mode: %s\n", (val & 1) ? "DMA" : "PIO");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ATAPI transfer mode: %s\n", (val & 1) ? "DMA" : "PIO");
|
||||
#endif
|
||||
zip[atapi_zip_drives[cur_ide[ide_board]]].features = val;
|
||||
}
|
||||
else if (ide_drive_is_cdrom(ide))
|
||||
{
|
||||
ide_log("ATAPI transfer mode: %s\n", (val & 1) ? "DMA" : "PIO");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("ATAPI transfer mode: %s\n", (val & 1) ? "DMA" : "PIO");
|
||||
#endif
|
||||
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->features = val;
|
||||
}
|
||||
ide->cylprecomp = val;
|
||||
@@ -1097,24 +1126,32 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
|
||||
case 0x1F2: /* Sector count */
|
||||
if (ide_drive_is_zip(ide))
|
||||
{
|
||||
ide_log("Sector count write: %i\n", val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Sector count write: %i\n", val);
|
||||
#endif
|
||||
zip[atapi_zip_drives[cur_ide[ide_board]]].phase = val;
|
||||
}
|
||||
else if (ide_drive_is_cdrom(ide))
|
||||
{
|
||||
ide_log("Sector count write: %i\n", val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Sector count write: %i\n", val);
|
||||
#endif
|
||||
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->phase = val;
|
||||
}
|
||||
ide->secount = val;
|
||||
|
||||
if (ide_drive_is_zip(ide_other))
|
||||
{
|
||||
ide_log("Other sector count write: %i\n", val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Other sector count write: %i\n", val);
|
||||
#endif
|
||||
zip[atapi_zip_drives[cur_ide[ide_board] ^ 1]].phase = val;
|
||||
}
|
||||
else if (ide_drive_is_cdrom(ide_other))
|
||||
{
|
||||
ide_log("Other sector count write: %i\n", val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Other sector count write: %i\n", val);
|
||||
#endif
|
||||
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->phase = val;
|
||||
}
|
||||
ide_other->secount = val;
|
||||
@@ -1678,7 +1715,9 @@ uint32_t ide_read_data(int ide_board, int length)
|
||||
ide->pos = 0;
|
||||
if (!ide_drive_is_zip(ide) && !ide_drive_is_cdrom(ide))
|
||||
{
|
||||
ide_log("Drive not ZIP or CD-ROM (position: %i)\n", ide->pos);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Drive not ZIP or CD-ROM (position: %i)\n", ide->pos);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
if (ide_drive_is_zip(ide))
|
||||
@@ -1920,7 +1959,9 @@ uint8_t readide(int ide_board, uint16_t addr)
|
||||
temp = 0xff;
|
||||
break;
|
||||
}
|
||||
/* if (ide_board) */ ide_log("Read IDEb %04X %02X %02X %02X %i %04X:%04X %i\n", addr, temp, ide->atastat,(ide->atastat & ~DSC_STAT) | (ide->service ? SERVICE_STAT : 0),cur_ide[ide_board],CS,cpu_state.pc,ide_board);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
/* if (ide_board) */ hdc_log("Read IDEb %04X %02X %02X %02X %i %04X:%04X %i\n", addr, temp, ide->atastat,(ide->atastat & ~DSC_STAT) | (ide->service ? SERVICE_STAT : 0),cur_ide[ide_board],CS,cpu_state.pc,ide_board);
|
||||
#endif
|
||||
return temp;
|
||||
}
|
||||
|
||||
@@ -1965,7 +2006,9 @@ void callbackide(int ide_board)
|
||||
ext_ide = ide;
|
||||
|
||||
if (ide->command==0x30) times30++;
|
||||
/*if (ide_board) */ide_log("CALLBACK %02X %i %i %i\n",ide->command,times30,ide->reset,cur_ide[ide_board]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
/*if (ide_board) */hdc_log("CALLBACK %02X %i %i %i\n",ide->command,times30,ide->reset,cur_ide[ide_board]);
|
||||
#endif
|
||||
|
||||
if (ide->reset)
|
||||
{
|
||||
@@ -2165,12 +2208,16 @@ void callbackide(int ide_board)
|
||||
case WIN_READ_DMA_ALT:
|
||||
if (ide_drive_is_zip(ide) || ide_drive_is_cdrom(ide) || (ide->board >= 2))
|
||||
{
|
||||
ide_log("IDE %i: DMA read aborted (bad device or board)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA read aborted (bad device or board)\n", ide->channel);
|
||||
#endif
|
||||
goto abort_cmd;
|
||||
}
|
||||
if (!ide->specify_success)
|
||||
{
|
||||
ide_log("IDE %i: DMA read aborted (SPECIFY failed)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA read aborted (SPECIFY failed)\n", ide->channel);
|
||||
#endif
|
||||
goto id_not_found;
|
||||
}
|
||||
|
||||
@@ -2191,13 +2238,17 @@ void callbackide(int ide_board)
|
||||
{
|
||||
if (ide_bus_master_read(ide_board, ide->sector_buffer, ide->sector_pos * 512))
|
||||
{
|
||||
ide_log("IDE %i: DMA read aborted (failed)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA read aborted (failed)\n", ide->channel);
|
||||
#endif
|
||||
goto abort_cmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*DMA successful*/
|
||||
ide_log("IDE %i: DMA read successful\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA read successful\n", ide->channel);
|
||||
#endif
|
||||
|
||||
ide->atastat = READY_STAT | DSC_STAT;
|
||||
|
||||
@@ -2205,7 +2256,9 @@ void callbackide(int ide_board)
|
||||
ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0);
|
||||
}
|
||||
} else {
|
||||
ide_log("IDE %i: DMA read aborted (no bus master)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA read aborted (no bus master)\n", ide->channel);
|
||||
#endif
|
||||
goto abort_cmd;
|
||||
}
|
||||
|
||||
@@ -2292,12 +2345,16 @@ void callbackide(int ide_board)
|
||||
case WIN_WRITE_DMA_ALT:
|
||||
if (ide_drive_is_zip(ide) || ide_drive_is_cdrom(ide) || (ide_board >= 2))
|
||||
{
|
||||
ide_log("IDE %i: DMA write aborted (bad device type or board)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA write aborted (bad device type or board)\n", ide->channel);
|
||||
#endif
|
||||
goto abort_cmd;
|
||||
}
|
||||
if (!ide->specify_success)
|
||||
{
|
||||
ide_log("IDE %i: DMA write aborted (SPECIFY failed)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA write aborted (SPECIFY failed)\n", ide->channel);
|
||||
#endif
|
||||
goto id_not_found;
|
||||
}
|
||||
|
||||
@@ -2310,13 +2367,17 @@ void callbackide(int ide_board)
|
||||
|
||||
if (ide_bus_master_write(ide_board, ide->sector_buffer, ide->sector_pos * 512))
|
||||
{
|
||||
ide_log("IDE %i: DMA write aborted (failed)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA write aborted (failed)\n", ide->channel);
|
||||
#endif
|
||||
goto abort_cmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*DMA successful*/
|
||||
ide_log("IDE %i: DMA write successful\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA write successful\n", ide->channel);
|
||||
#endif
|
||||
|
||||
hdd_image_write(ide->hdd_num, ide_get_sector(ide), ide->sector_pos, ide->sector_buffer);
|
||||
|
||||
@@ -2326,7 +2387,9 @@ void callbackide(int ide_board)
|
||||
ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0);
|
||||
}
|
||||
} else {
|
||||
ide_log("IDE %i: DMA write aborted (no bus master)\n", ide->channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE %i: DMA write aborted (no bus master)\n", ide->channel);
|
||||
#endif
|
||||
goto abort_cmd;
|
||||
}
|
||||
|
||||
@@ -2555,7 +2618,9 @@ void callbackide(int ide_board)
|
||||
zip_phase_callback(atapi_zip_drives[cur_ide[ide_board]]);
|
||||
else
|
||||
cdrom_phase_callback(atapi_cdrom_drives[cur_ide[ide_board]]);
|
||||
ide_log("IDE callback now: %i\n", idecallback[ide_board]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("IDE callback now: %i\n", idecallback[ide_board]);
|
||||
#endif
|
||||
return;
|
||||
|
||||
case 0xFF:
|
||||
@@ -2745,12 +2810,16 @@ void ide_pri_enable_ex(void)
|
||||
{
|
||||
if (ide_base_main[0] & 0x300)
|
||||
{
|
||||
ide_log("Enabling primary base (%04X)...\n", ide_base_main[0]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Enabling primary base (%04X)...\n", ide_base_main[0]);
|
||||
#endif
|
||||
io_sethandler(ide_base_main[0], 0x0008, ide_read_pri, ide_read_pri_w, ide_read_pri_l, ide_write_pri, ide_write_pri_w, ide_write_pri_l, NULL);
|
||||
}
|
||||
if (ide_side_main[0] & 0x300)
|
||||
{
|
||||
ide_log("Enabling primary side (%04X)...\n", ide_side_main[0]);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Enabling primary side (%04X)...\n", ide_side_main[0]);
|
||||
#endif
|
||||
io_sethandler(ide_side_main[0], 0x0001, ide_read_pri, NULL, NULL, ide_write_pri, NULL, NULL , NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Definitions for the IDE module.
|
||||
*
|
||||
* Version: @(#)hdc_ide.h 1.0.5 2018/03/27
|
||||
* Version: @(#)hdc_ide.h 1.0.6 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* based design. Most cards were WD1003-WA2 or -WAH, where the
|
||||
* -WA2 cards had a floppy controller as well (to save space.)
|
||||
*
|
||||
* Version: @(#)hdc_mfm_at.c 1.0.4 2018/04/01
|
||||
* Version: @(#)hdc_mfm_at.c 1.0.4 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Sarah Walker, <tommowalker@tommowalker.co.uk>
|
||||
@@ -128,7 +128,8 @@ typedef struct {
|
||||
} mfm_t;
|
||||
|
||||
|
||||
static __inline void irq_raise(mfm_t *mfm)
|
||||
static __inline void
|
||||
irq_raise(mfm_t *mfm)
|
||||
{
|
||||
/* If not already pending.. */
|
||||
if (! mfm->irqstat) {
|
||||
@@ -144,7 +145,8 @@ static __inline void irq_raise(mfm_t *mfm)
|
||||
}
|
||||
|
||||
|
||||
static __inline void irq_lower(mfm_t *mfm)
|
||||
static __inline void
|
||||
irq_lower(mfm_t *mfm)
|
||||
{
|
||||
/* If raised.. */
|
||||
if (mfm->irqstat) {
|
||||
@@ -178,31 +180,41 @@ get_sector(mfm_t *mfm, off64_t *addr)
|
||||
drive_t *drive = &mfm->drives[mfm->drvsel];
|
||||
|
||||
if (drive->curcyl != mfm->cylinder) {
|
||||
pclog("WD1003(%d) sector: wrong cylinder\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) sector: wrong cylinder\n");
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (mfm->head > drive->cfg_hpc) {
|
||||
pclog("WD1003(%d) get_sector: past end of configured heads\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) get_sector: past end of configured heads\n",
|
||||
mfm->drvsel);
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (mfm->sector >= drive->cfg_spt+1) {
|
||||
pclog("WD1003(%d) get_sector: past end of configured sectors\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) get_sector: past end of configured sectors\n",
|
||||
mfm->drvsel);
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* We should check this in the SET_DRIVE_PARAMETERS command! --FvK */
|
||||
if (mfm->head > drive->hpc) {
|
||||
pclog("WD1003(%d) get_sector: past end of heads\n", mfm->drvsel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) get_sector: past end of heads\n", mfm->drvsel);
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (mfm->sector >= drive->spt+1) {
|
||||
pclog("WD1003(%d) get_sector: past end of sectors\n", mfm->drvsel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) get_sector: past end of sectors\n", mfm->drvsel);
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
#endif
|
||||
@@ -239,8 +251,10 @@ mfm_cmd(mfm_t *mfm, uint8_t val)
|
||||
|
||||
if (! drive->present) {
|
||||
/* This happens if sofware polls all drives. */
|
||||
pclog("WD1003(%d) command %02x on non-present drive\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) command %02x on non-present drive\n",
|
||||
mfm->drvsel, val);
|
||||
#endif
|
||||
mfm->command = 0xff;
|
||||
mfm->status = STAT_BUSY;
|
||||
timer_clock();
|
||||
@@ -256,8 +270,8 @@ mfm_cmd(mfm_t *mfm, uint8_t val)
|
||||
switch (val & 0xf0) {
|
||||
case CMD_RESTORE:
|
||||
drive->steprate = (val & 0x0f);
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) restore, step=%d\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) restore, step=%d\n",
|
||||
mfm->drvsel, drive->steprate);
|
||||
#endif
|
||||
drive->curcyl = 0;
|
||||
@@ -281,8 +295,8 @@ mfm_cmd(mfm_t *mfm, uint8_t val)
|
||||
case CMD_READ+1:
|
||||
case CMD_READ+2:
|
||||
case CMD_READ+3:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) read, opt=%d\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) read, opt=%d\n",
|
||||
mfm->drvsel, val&0x03);
|
||||
#endif
|
||||
mfm->command = (val & 0xf0);
|
||||
@@ -298,8 +312,8 @@ mfm_cmd(mfm_t *mfm, uint8_t val)
|
||||
case CMD_WRITE+1:
|
||||
case CMD_WRITE+2:
|
||||
case CMD_WRITE+3:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) write, opt=%d\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) write, opt=%d\n",
|
||||
mfm->drvsel, val & 0x03);
|
||||
#endif
|
||||
mfm->command = (val & 0xf0);
|
||||
@@ -353,13 +367,17 @@ mfm_cmd(mfm_t *mfm, uint8_t val)
|
||||
/* Only accept after RESET or DIAG. */
|
||||
drive->cfg_spt = mfm->secount;
|
||||
drive->cfg_hpc = mfm->head+1;
|
||||
pclog("WD1003(%d) parameters: tracks=%d, spt=%i, hpc=%i\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) parameters: tracks=%d, spt=%i, hpc=%i\n",
|
||||
mfm->drvsel, drive->tracks,
|
||||
drive->cfg_spt, drive->cfg_hpc);
|
||||
#endif
|
||||
} else {
|
||||
pclog("WD1003(%d) parameters: tracks=%d,spt=%i,hpc=%i (IGNORED)\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) parameters: tracks=%d,spt=%i,hpc=%i (IGNORED)\n",
|
||||
mfm->drvsel, drive->tracks,
|
||||
drive->cfg_spt, drive->cfg_hpc);
|
||||
#endif
|
||||
}
|
||||
mfm->command = 0x00;
|
||||
mfm->status = STAT_READY|STAT_DSC;
|
||||
@@ -368,7 +386,9 @@ mfm_cmd(mfm_t *mfm, uint8_t val)
|
||||
break;
|
||||
|
||||
default:
|
||||
pclog("WD1003: bad command %02X\n", val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003: bad command %02X\n", val);
|
||||
#endif
|
||||
mfm->status = STAT_BUSY;
|
||||
timer_clock();
|
||||
mfm->callback = 200LL*MFM_TIME;
|
||||
@@ -402,8 +422,8 @@ mfm_write(uint16_t port, uint8_t val, void *priv)
|
||||
{
|
||||
mfm_t *mfm = (mfm_t *)priv;
|
||||
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("WD1003 write(%04x, %02x)\n", port, val);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003 write(%04x, %02x)\n", port, val);
|
||||
#endif
|
||||
switch (port) {
|
||||
case 0x01f0: /* data */
|
||||
@@ -538,8 +558,8 @@ mfm_read(uint16_t port, void *priv)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#if ENABLE_HDC_LOG > 1
|
||||
pclog("WD1003 read(%04x) = %02x\n", port, ret);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003 read(%04x) = %02x\n", port, ret);
|
||||
#endif
|
||||
|
||||
return(ret);
|
||||
@@ -551,8 +571,8 @@ do_seek(mfm_t *mfm)
|
||||
{
|
||||
drive_t *drive = &mfm->drives[mfm->drvsel];
|
||||
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) seek(%d) max=%d\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) seek(%d) max=%d\n",
|
||||
mfm->drvsel,mfm->cylinder,drive->tracks);
|
||||
#endif
|
||||
if (mfm->cylinder < drive->tracks)
|
||||
@@ -571,8 +591,8 @@ do_callback(void *priv)
|
||||
|
||||
mfm->callback = 0LL;
|
||||
if (mfm->reset) {
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) reset\n", mfm->drvsel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) reset\n", mfm->drvsel);
|
||||
#endif
|
||||
mfm->status = STAT_READY|STAT_DSC;
|
||||
mfm->error = 1;
|
||||
@@ -593,8 +613,8 @@ do_callback(void *priv)
|
||||
|
||||
switch (mfm->command) {
|
||||
case CMD_SEEK:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) seek, step=%d\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) seek, step=%d\n",
|
||||
mfm->drvsel, drive->steprate);
|
||||
#endif
|
||||
do_seek(mfm);
|
||||
@@ -603,8 +623,8 @@ do_callback(void *priv)
|
||||
break;
|
||||
|
||||
case CMD_READ:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) read(%d,%d,%d)\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) read(%d,%d,%d)\n",
|
||||
mfm->drvsel, mfm->cylinder, mfm->head, mfm->sector);
|
||||
#endif
|
||||
do_seek(mfm);
|
||||
@@ -624,8 +644,8 @@ do_callback(void *priv)
|
||||
break;
|
||||
|
||||
case CMD_WRITE:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) write(%d,%d,%d)\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) write(%d,%d,%d)\n",
|
||||
mfm->drvsel, mfm->cylinder, mfm->head, mfm->sector);
|
||||
#endif
|
||||
do_seek(mfm);
|
||||
@@ -653,8 +673,8 @@ do_callback(void *priv)
|
||||
break;
|
||||
|
||||
case CMD_VERIFY:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) verify(%d,%d,%d)\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) verify(%d,%d,%d)\n",
|
||||
mfm->drvsel, mfm->cylinder, mfm->head, mfm->sector);
|
||||
#endif
|
||||
do_seek(mfm);
|
||||
@@ -665,8 +685,8 @@ do_callback(void *priv)
|
||||
break;
|
||||
|
||||
case CMD_FORMAT:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) format(%d,%d)\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) format(%d,%d)\n",
|
||||
mfm->drvsel, mfm->cylinder, mfm->head);
|
||||
#endif
|
||||
do_seek(mfm);
|
||||
@@ -685,8 +705,8 @@ do_callback(void *priv)
|
||||
break;
|
||||
|
||||
case CMD_DIAGNOSE:
|
||||
#if ENABLE_HDC_LOG
|
||||
pclog("WD1003(%d) diag\n", mfm->drvsel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) diag\n", mfm->drvsel);
|
||||
#endif
|
||||
drive->steprate = 0x0f;
|
||||
mfm->error = 1;
|
||||
@@ -695,8 +715,10 @@ do_callback(void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
pclog("WD1003(%d) callback on unknown command %02x\n",
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d) callback on unknown command %02x\n",
|
||||
mfm->drvsel, mfm->command);
|
||||
#endif
|
||||
mfm->status = STAT_READY|STAT_ERR|STAT_DSC;
|
||||
mfm->error = ERR_ABRT;
|
||||
irq_raise(mfm);
|
||||
@@ -730,7 +752,9 @@ mfm_init(const device_t *info)
|
||||
mfm_t *mfm;
|
||||
int c, d;
|
||||
|
||||
pclog("WD1003: ISA MFM/RLL Fixed Disk Adapter initializing ...\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003: ISA MFM/RLL Fixed Disk Adapter initializing ...\n");
|
||||
#endif
|
||||
mfm = malloc(sizeof(mfm_t));
|
||||
memset(mfm, 0x00, sizeof(mfm_t));
|
||||
|
||||
@@ -739,8 +763,10 @@ mfm_init(const device_t *info)
|
||||
if ((hdd[d].bus == HDD_BUS_MFM) && (hdd[d].mfm_channel < MFM_NUM)) {
|
||||
loadhd(mfm, hdd[d].mfm_channel, d, hdd[d].fn);
|
||||
|
||||
pclog("WD1003(%d): (%ls) geometry %d/%d/%d\n", c, hdd[d].fn,
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("WD1003(%d): (%ls) geometry %d/%d/%d\n", c, hdd[d].fn,
|
||||
(int)hdd[d].tracks, (int)hdd[d].hpc, (int)hdd[d].spt);
|
||||
#endif
|
||||
|
||||
if (++c >= MFM_NUM) break;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
* Since all controllers (including the ones made by DTC) use
|
||||
* (mostly) the same API, we keep them all in this module.
|
||||
*
|
||||
* Version: @(#)hdc_mfm_xt.c 1.0.5 2018/03/31
|
||||
* Version: @(#)hdc_mfm_xt.c 1.0.5 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Sarah Walker, <tommowalker@tommowalker.co.uk>
|
||||
@@ -261,7 +261,7 @@ mfm_write(uint16_t port, uint8_t val, void *priv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Write data unknown state - %i %02x\n", dev->state, dev->status);
|
||||
hdc_log("Write data unknown state - %i %02x\n", dev->state, dev->status);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -301,7 +301,9 @@ mfm_error(mfm_t *dev, uint8_t error)
|
||||
dev->completion_byte |= 0x02;
|
||||
dev->error = error;
|
||||
|
||||
pclog("mfm_error - %02x\n", dev->error);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("mfm_error - %02x\n", dev->error);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -312,22 +314,30 @@ get_sector(mfm_t *dev, off64_t *addr)
|
||||
int heads = drive->cfg_hpc;
|
||||
|
||||
if (drive->current_cylinder != dev->cylinder) {
|
||||
pclog("mfm_get_sector: wrong cylinder\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("mfm_get_sector: wrong cylinder\n");
|
||||
#endif
|
||||
dev->error = ERR_ILLEGAL_SECTOR_ADDRESS;
|
||||
return(1);
|
||||
}
|
||||
if (dev->head > heads) {
|
||||
pclog("mfm_get_sector: past end of configured heads\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("mfm_get_sector: past end of configured heads\n");
|
||||
#endif
|
||||
dev->error = ERR_ILLEGAL_SECTOR_ADDRESS;
|
||||
return(1);
|
||||
}
|
||||
if (dev->head > drive->hpc) {
|
||||
pclog("mfm_get_sector: past end of heads\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("mfm_get_sector: past end of heads\n");
|
||||
#endif
|
||||
dev->error = ERR_ILLEGAL_SECTOR_ADDRESS;
|
||||
return(1);
|
||||
}
|
||||
if (dev->sector >= 17) {
|
||||
pclog("mfm_get_sector: past end of sectors\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("mfm_get_sector: past end of sectors\n");
|
||||
#endif
|
||||
dev->error = ERR_ILLEGAL_SECTOR_ADDRESS;
|
||||
return(1);
|
||||
}
|
||||
@@ -418,7 +428,9 @@ mfm_callback(void *priv)
|
||||
dev->sector_count = dev->command[4];
|
||||
do {
|
||||
if (get_sector(dev, &addr)) {
|
||||
pclog("get_sector failed\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("get_sector failed\n");
|
||||
#endif
|
||||
mfm_error(dev, dev->error);
|
||||
mfm_complete(dev);
|
||||
return;
|
||||
@@ -445,7 +457,9 @@ mfm_callback(void *priv)
|
||||
dev->head = dev->command[1] & 0x1f;
|
||||
|
||||
if (get_sector(dev, &addr)) {
|
||||
pclog("get_sector failed\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("get_sector failed\n");
|
||||
#endif
|
||||
mfm_error(dev, dev->error);
|
||||
mfm_complete(dev);
|
||||
return;
|
||||
@@ -493,7 +507,9 @@ mfm_callback(void *priv)
|
||||
int val = dma_channel_write(3, dev->sector_buf[dev->data_pos]);
|
||||
|
||||
if (val == DMA_NODATA) {
|
||||
pclog("CMD_READ_SECTORS out of data!\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("CMD_READ_SECTORS out of data!\n");
|
||||
#endif
|
||||
dev->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ;
|
||||
dev->callback = MFM_TIME;
|
||||
return;
|
||||
@@ -566,7 +582,9 @@ mfm_callback(void *priv)
|
||||
int val = dma_channel_read(3);
|
||||
|
||||
if (val == DMA_NODATA) {
|
||||
pclog("CMD_WRITE_SECTORS out of data!\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("CMD_WRITE_SECTORS out of data!\n");
|
||||
#endif
|
||||
dev->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ;
|
||||
dev->callback = MFM_TIME;
|
||||
return;
|
||||
@@ -640,7 +658,9 @@ mfm_callback(void *priv)
|
||||
case STATE_RECEIVED_DATA:
|
||||
drive->cfg_cyl = dev->data[1] | (dev->data[0] << 8);
|
||||
drive->cfg_hpc = dev->data[2];
|
||||
pclog("Drive %i: cylinders=%i, heads=%i\n", dev->drive_sel, drive->cfg_cyl, drive->cfg_hpc);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Drive %i: cylinders=%i, heads=%i\n", dev->drive_sel, drive->cfg_cyl, drive->cfg_hpc);
|
||||
#endif
|
||||
mfm_complete(dev);
|
||||
break;
|
||||
|
||||
@@ -669,7 +689,7 @@ mfm_callback(void *priv)
|
||||
int val = dma_channel_read(3);
|
||||
|
||||
if (val == DMA_NODATA) {
|
||||
pclog("CMD_WRITE_SECTOR_BUFFER out of data!\n");
|
||||
hdc_log("CMD_WRITE_SECTOR_BUFFER out of data!\n");
|
||||
dev->status = STAT_BSY | STAT_CD | STAT_IO | STAT_REQ;
|
||||
dev->callback = MFM_TIME;
|
||||
return;
|
||||
@@ -718,7 +738,9 @@ mfm_callback(void *priv)
|
||||
dev->data[0] = drive->tracks & 0xff;
|
||||
dev->data[1] = 17 | ((drive->tracks >> 2) & 0xc0);
|
||||
dev->data[2] = drive->hpc-1;
|
||||
pclog("Get drive params %02x %02x %02x %i\n", dev->data[0], dev->data[1], dev->data[2], drive->tracks);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Get drive params %02x %02x %02x %i\n", dev->data[0], dev->data[1], dev->data[2], drive->tracks);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case STATE_SENT_DATA:
|
||||
@@ -824,9 +846,11 @@ mfm_set_switches(mfm_t *dev)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
if (c == 4)
|
||||
pclog("WARNING: drive %d has unsupported format %d/%d/%d !\n",
|
||||
hdc_log("WARNING: drive %d has unsupported format %d/%d/%d !\n",
|
||||
d, drive->tracks, drive->hpc, drive->spt);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -841,17 +865,23 @@ mfm_init(const device_t *info)
|
||||
dev = malloc(sizeof(mfm_t));
|
||||
memset(dev, 0x00, sizeof(mfm_t));
|
||||
|
||||
pclog("MFM: looking for disks..\n");
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("MFM: looking for disks..\n");
|
||||
#endif
|
||||
c = 0;
|
||||
for (i=0; i<HDD_NUM; i++) {
|
||||
if ((hdd[i].bus == HDD_BUS_MFM) && (hdd[i].mfm_channel < MFM_NUM)) {
|
||||
pclog("Found MFM hard disk on channel %i\n", hdd[i].mfm_channel);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("Found MFM hard disk on channel %i\n", hdd[i].mfm_channel);
|
||||
#endif
|
||||
loadhd(dev, i, hdd[i].mfm_channel, hdd[i].fn);
|
||||
|
||||
if (++c > MFM_NUM) break;
|
||||
}
|
||||
}
|
||||
pclog("MFM: %d disks loaded.\n", c);
|
||||
#ifdef ENABLE_HDC_LOG
|
||||
hdc_log("MFM: %d disks loaded.\n", c);
|
||||
#endif
|
||||
|
||||
switch(info->local) {
|
||||
case 0: /* Xebec */
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* already on their way out, the newer IDE standard based on the
|
||||
* PC/AT controller and 16b design became the IDE we now know.
|
||||
*
|
||||
* Version: @(#)hdc_xtide.c 1.0.4 2018/03/31
|
||||
* Version: @(#)hdc_xtide.c 1.0.5 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Common code to handle all sorts of hard disk images.
|
||||
*
|
||||
* Version: @(#)hdd.c 1.0.1 2018/02/14
|
||||
* Version: @(#)hdd.c 1.0.2 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -37,7 +37,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include "../emu.h"
|
||||
#include "../plat.h"
|
||||
#include "../ui.h"
|
||||
@@ -45,6 +47,24 @@
|
||||
|
||||
|
||||
hard_disk_t hdd[HDD_NUM];
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
int hdd_do_log = ENABLE_HDD_LOG;
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
hdd_log(const char *fmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
va_list ap;
|
||||
|
||||
if (hdd_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
@@ -73,8 +93,7 @@ no_cdrom:
|
||||
return(HDD_BUS_MFM);
|
||||
}
|
||||
|
||||
/* FIXME: delete 'rll' in a year or so.. --FvK */
|
||||
if (!strcmp(str, "esdi") || !strcmp(str, "rll")) {
|
||||
if (! strcmp(str, "esdi")) {
|
||||
if (cdrom) goto no_cdrom;
|
||||
|
||||
return(HDD_BUS_ESDI);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Definitions for the hard disk image handler.
|
||||
*
|
||||
* Version: @(#)hdd.h 1.0.3 2018/03/31
|
||||
* Version: @(#)hdd.h 1.0.4 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -92,10 +92,12 @@ typedef struct {
|
||||
} hard_disk_t;
|
||||
|
||||
|
||||
extern hard_disk_t hdd[HDD_NUM];
|
||||
extern const hddtab_t hdd_table[128];
|
||||
extern hard_disk_t hdd[HDD_NUM];
|
||||
extern int hdd_do_log;
|
||||
|
||||
|
||||
extern void hdd_log(const char *fmt, ...);
|
||||
extern int hdd_init(void);
|
||||
extern int hdd_string_to_bus(char *str, int cdrom);
|
||||
extern char *hdd_bus_to_string(int bus, int cdrom);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Handling of hard disk image files.
|
||||
*
|
||||
* Version: @(#)hdd_image.c 1.0.3 2018/03/31
|
||||
* Version: @(#)hdd_image.c 1.0.4 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -41,436 +41,461 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <errno.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include "../emu.h"
|
||||
#include "../plat.h"
|
||||
#include "hdd.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE *file;
|
||||
uint32_t base;
|
||||
uint32_t last_sector;
|
||||
uint8_t type;
|
||||
uint8_t loaded;
|
||||
typedef struct {
|
||||
FILE *file;
|
||||
uint32_t base;
|
||||
uint32_t last_sector;
|
||||
uint8_t type;
|
||||
uint8_t loaded;
|
||||
} hdd_image_t;
|
||||
|
||||
|
||||
hdd_image_t hdd_images[HDD_NUM];
|
||||
|
||||
static char empty_sector[512];
|
||||
static char *empty_sector_1mb;
|
||||
hdd_image_t hdd_images[HDD_NUM];
|
||||
|
||||
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
int hdd_image_do_log = ENABLE_HDD_LOG;
|
||||
#endif
|
||||
static char empty_sector[512];
|
||||
static char *empty_sector_1mb;
|
||||
|
||||
|
||||
static void
|
||||
hdd_image_log(const char *fmt, ...)
|
||||
int
|
||||
image_is_hdi(const wchar_t *s)
|
||||
{
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
va_list ap;
|
||||
wchar_t ext[5] = { 0, 0, 0, 0, 0 };
|
||||
char *ws = (char *)s;
|
||||
int len;
|
||||
|
||||
if (hdd_image_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
len = wcslen(s);
|
||||
if ((len < 4) || (s[0] == L'.')) return 0;
|
||||
|
||||
memcpy(ext, ws + ((len - 4) << 1), 8);
|
||||
if (! wcscasecmp(ext, L".HDI")) return 1;
|
||||
|
||||
int image_is_hdi(const wchar_t *s)
|
||||
{
|
||||
int len;
|
||||
wchar_t ext[5] = { 0, 0, 0, 0, 0 };
|
||||
char *ws = (char *) s;
|
||||
len = wcslen(s);
|
||||
if ((len < 4) || (s[0] == L'.')) return 0;
|
||||
|
||||
memcpy(ext, ws + ((len - 4) << 1), 8);
|
||||
if (! wcscasecmp(ext, L".HDI")) return 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
image_is_hdx(const wchar_t *s, int check_signature)
|
||||
{
|
||||
int len;
|
||||
FILE *f;
|
||||
uint64_t filelen;
|
||||
uint64_t signature;
|
||||
char *ws = (char *) s;
|
||||
wchar_t ext[5] = { 0, 0, 0, 0, 0 };
|
||||
len = wcslen(s);
|
||||
if ((len < 4) || (s[0] == L'.')) return 0;
|
||||
wchar_t ext[5] = { 0, 0, 0, 0, 0 };
|
||||
char *ws = (char *)s;
|
||||
uint64_t signature;
|
||||
uint64_t filelen;
|
||||
FILE *f;
|
||||
int len;
|
||||
|
||||
memcpy(ext, ws + ((len - 4) << 1), 8);
|
||||
if (wcscasecmp(ext, L".HDX") == 0) {
|
||||
if (check_signature) {
|
||||
f = plat_fopen((wchar_t *)s, L"rb");
|
||||
if (!f)
|
||||
return 0;
|
||||
fseeko64(f, 0, SEEK_END);
|
||||
filelen = ftello64(f);
|
||||
fseeko64(f, 0, SEEK_SET);
|
||||
if (filelen < 44)
|
||||
return 0;
|
||||
fread(&signature, 1, 8, f);
|
||||
fclose(f);
|
||||
if (signature == 0xD778A82044445459ll)
|
||||
return 1;
|
||||
len = wcslen(s);
|
||||
if ((len < 4) || (s[0] == L'.')) return 0;
|
||||
|
||||
memcpy(ext, ws + ((len - 4) << 1), 8);
|
||||
if (wcscasecmp(ext, L".HDX") == 0) {
|
||||
if (check_signature) {
|
||||
f = plat_fopen((wchar_t *)s, L"rb");
|
||||
if (!f)
|
||||
return 0;
|
||||
}
|
||||
fseeko64(f, 0, SEEK_END);
|
||||
filelen = ftello64(f);
|
||||
fseeko64(f, 0, SEEK_SET);
|
||||
if (filelen < 44)
|
||||
return 0;
|
||||
fread(&signature, 1, 8, f);
|
||||
fclose(f);
|
||||
if (signature == 0xD778A82044445459ll)
|
||||
return 1;
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int hdd_image_load(int id)
|
||||
int
|
||||
hdd_image_load(int id)
|
||||
{
|
||||
uint32_t sector_size = 512;
|
||||
uint32_t zero = 0;
|
||||
uint64_t signature = 0xD778A82044445459ll;
|
||||
uint64_t s = 0, t, full_size = 0;
|
||||
int spt = 0, hpc = 0, tracks = 0;
|
||||
int c, i;
|
||||
wchar_t *fn = hdd[id].fn;
|
||||
int is_hdx[2] = { 0, 0 };
|
||||
uint64_t signature = 0xD778A82044445459ll;
|
||||
uint64_t s = 0, t, full_size = 0;
|
||||
int spt = 0, hpc = 0, tracks = 0;
|
||||
uint32_t sector_size = 512;
|
||||
wchar_t *fn = hdd[id].fn;
|
||||
int is_hdx[2] = { 0, 0 };
|
||||
uint32_t zero = 0;
|
||||
int c, i;
|
||||
|
||||
memset(empty_sector, 0, sizeof(empty_sector));
|
||||
memset(empty_sector, 0, sizeof(empty_sector));
|
||||
|
||||
hdd_images[id].base = 0;
|
||||
hdd_images[id].base = 0;
|
||||
|
||||
if (hdd_images[id].loaded) {
|
||||
if (hdd_images[id].file) {
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
}
|
||||
hdd_images[id].loaded = 0;
|
||||
if (hdd_images[id].loaded) {
|
||||
if (hdd_images[id].file) {
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
}
|
||||
hdd_images[id].loaded = 0;
|
||||
}
|
||||
|
||||
is_hdx[0] = image_is_hdx(fn, 0);
|
||||
is_hdx[1] = image_is_hdx(fn, 1);
|
||||
is_hdx[0] = image_is_hdx(fn, 0);
|
||||
is_hdx[1] = image_is_hdx(fn, 1);
|
||||
|
||||
/* Try to open existing hard disk image */
|
||||
if (fn[0] == '.') {
|
||||
hdd_image_log("File name starts with .\n");
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
hdd_images[id].file = plat_fopen(fn, L"rb+");
|
||||
if (hdd_images[id].file == NULL) {
|
||||
/* Failed to open existing hard disk image */
|
||||
if (errno == ENOENT) {
|
||||
/* Failed because it does not exist,
|
||||
so try to create new file */
|
||||
if (hdd[id].wp) {
|
||||
hdd_image_log("A write-protected image must exist\n");
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
/* Try to open existing hard disk image */
|
||||
if (fn[0] == '.') {
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("File name starts with .\n");
|
||||
#endif
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
|
||||
hdd_images[id].file = plat_fopen(fn, L"wb+");
|
||||
if (hdd_images[id].file == NULL) {
|
||||
hdd_image_log("Unable to open image\n");
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
} else {
|
||||
if (image_is_hdi(fn)) {
|
||||
full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
hdd_images[id].base = 0x1000;
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd_images[id].base), 1, 4, hdd_images[id].file);
|
||||
fwrite(&full_size, 1, 4, hdd_images[id].file);
|
||||
fwrite(§or_size, 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].spt), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].hpc), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].tracks), 1, 4, hdd_images[id].file);
|
||||
for (c = 0; c < 0x3f8; c++)
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
hdd_images[id].type = 1;
|
||||
} else if (is_hdx[0]) {
|
||||
full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
hdd_images[id].base = 0x28;
|
||||
fwrite(&signature, 1, 8, hdd_images[id].file);
|
||||
fwrite(&full_size, 1, 8, hdd_images[id].file);
|
||||
fwrite(§or_size, 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].spt), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].hpc), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].tracks), 1, 4, hdd_images[id].file);
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
hdd_images[id].type = 2;
|
||||
} else {
|
||||
hdd_images[id].type = 0;
|
||||
}
|
||||
hdd_images[id].last_sector = 0;
|
||||
}
|
||||
|
||||
s = full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
|
||||
goto prepare_new_hard_disk;
|
||||
} else {
|
||||
/* Failed for another reason */
|
||||
hdd_image_log("Failed for another reason\n");
|
||||
hdd_images[id].file = plat_fopen(fn, L"rb+");
|
||||
if (hdd_images[id].file == NULL) {
|
||||
/* Failed to open existing hard disk image */
|
||||
if (errno == ENOENT) {
|
||||
/* Failed because it does not exist,
|
||||
so try to create new file */
|
||||
if (hdd[id].wp) {
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("A write-protected image must exist\n");
|
||||
#endif
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (image_is_hdi(fn)) {
|
||||
fseeko64(hdd_images[id].file, 0x8, SEEK_SET);
|
||||
fread(&(hdd_images[id].base), 1, 4, hdd_images[id].file);
|
||||
fseeko64(hdd_images[id].file, 0xC, SEEK_SET);
|
||||
full_size = 0;
|
||||
fread(&full_size, 1, 4, hdd_images[id].file);
|
||||
fseeko64(hdd_images[id].file, 0x10, SEEK_SET);
|
||||
fread(§or_size, 1, 4, hdd_images[id].file);
|
||||
if (sector_size != 512) {
|
||||
/* Sector size is not 512 */
|
||||
hdd_image_log("HDI: Sector size is not 512\n");
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
fread(&spt, 1, 4, hdd_images[id].file);
|
||||
fread(&hpc, 1, 4, hdd_images[id].file);
|
||||
fread(&tracks, 1, 4, hdd_images[id].file);
|
||||
if (hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) {
|
||||
if ((spt != hdd[id].spt) || (hpc != hdd[id].hpc) || (tracks != hdd[id].tracks)) {
|
||||
hdd_image_log("HDI: Geometry mismatch\n");
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
hdd[id].spt = (uint8_t)spt;
|
||||
hdd[id].hpc = (uint8_t)hpc;
|
||||
hdd[id].tracks = (uint16_t)tracks;
|
||||
hdd_images[id].type = 1;
|
||||
} else if (is_hdx[1]) {
|
||||
hdd_images[id].base = 0x28;
|
||||
fseeko64(hdd_images[id].file, 8, SEEK_SET);
|
||||
fread(&full_size, 1, 8, hdd_images[id].file);
|
||||
fseeko64(hdd_images[id].file, 0x10, SEEK_SET);
|
||||
fread(§or_size, 1, 4, hdd_images[id].file);
|
||||
if (sector_size != 512) {
|
||||
/* Sector size is not 512 */
|
||||
hdd_image_log("HDX: Sector size is not 512\n");
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
fread(&spt, 1, 4, hdd_images[id].file);
|
||||
fread(&hpc, 1, 4, hdd_images[id].file);
|
||||
fread(&tracks, 1, 4, hdd_images[id].file);
|
||||
if (hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) {
|
||||
if ((spt != hdd[id].spt) || (hpc != hdd[id].hpc) || (tracks != hdd[id].tracks)) {
|
||||
hdd_image_log("HDX: Geometry mismatch\n");
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
hdd[id].spt = (uint8_t)spt;
|
||||
hdd[id].hpc = (uint8_t)hpc;
|
||||
hdd[id].tracks = (uint16_t)tracks;
|
||||
fread(&(hdd[id].at_spt), 1, 4, hdd_images[id].file);
|
||||
fread(&(hdd[id].at_hpc), 1, 4, hdd_images[id].file);
|
||||
hdd_images[id].type = 2;
|
||||
|
||||
hdd_images[id].file = plat_fopen(fn, L"wb+");
|
||||
if (hdd_images[id].file == NULL) {
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("Unable to open image\n");
|
||||
#endif
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
} else {
|
||||
full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
hdd_images[id].type = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fseeko64(hdd_images[id].file, 0, SEEK_END);
|
||||
if (ftello64(hdd_images[id].file) < (int64_t)(full_size + hdd_images[id].base)) {
|
||||
s = (full_size + hdd_images[id].base) - ftello64(hdd_images[id].file);
|
||||
prepare_new_hard_disk:
|
||||
s >>= 9;
|
||||
t = (s >> 11) << 11;
|
||||
s -= t;
|
||||
t >>= 11;
|
||||
|
||||
empty_sector_1mb = (char *) malloc(1048576);
|
||||
memset(empty_sector_1mb, 0, 1048576);
|
||||
|
||||
if (s > 0) {
|
||||
for (i = 0; i < s; i++) {
|
||||
fwrite(empty_sector, 1, 512, hdd_images[id].file);
|
||||
if (image_is_hdi(fn)) {
|
||||
full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
hdd_images[id].base = 0x1000;
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd_images[id].base), 1, 4, hdd_images[id].file);
|
||||
fwrite(&full_size, 1, 4, hdd_images[id].file);
|
||||
fwrite(§or_size, 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].spt), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].hpc), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].tracks), 1, 4, hdd_images[id].file);
|
||||
for (c = 0; c < 0x3f8; c++)
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
hdd_images[id].type = 1;
|
||||
} else if (is_hdx[0]) {
|
||||
full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
hdd_images[id].base = 0x28;
|
||||
fwrite(&signature, 1, 8, hdd_images[id].file);
|
||||
fwrite(&full_size, 1, 8, hdd_images[id].file);
|
||||
fwrite(§or_size, 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].spt), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].hpc), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].tracks), 1, 4, hdd_images[id].file);
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
fwrite(&zero, 1, 4, hdd_images[id].file);
|
||||
hdd_images[id].type = 2;
|
||||
} else {
|
||||
hdd_images[id].type = 0;
|
||||
}
|
||||
hdd_images[id].last_sector = 0;
|
||||
}
|
||||
|
||||
if (t > 0) {
|
||||
for (i = 0; i < t; i++) {
|
||||
fwrite(empty_sector_1mb, 1, 1045876, hdd_images[id].file);
|
||||
}
|
||||
}
|
||||
s = full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
|
||||
free(empty_sector_1mb);
|
||||
goto prepare_new_hard_disk;
|
||||
} else {
|
||||
/* Failed for another reason */
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("Failed for another reason\n");
|
||||
#endif
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
|
||||
hdd_images[id].last_sector = (uint32_t) (full_size >> 9) - 1;
|
||||
|
||||
hdd_images[id].loaded = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void hdd_image_seek(uint8_t id, uint32_t sector)
|
||||
{
|
||||
off64_t addr = sector;
|
||||
addr = (uint64_t)sector * 512;
|
||||
|
||||
fseeko64(hdd_images[id].file, addr + hdd_images[id].base, SEEK_SET);
|
||||
}
|
||||
|
||||
void hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fread(buffer, 1, count * 512, hdd_images[id].file);
|
||||
}
|
||||
|
||||
uint32_t hdd_sectors(uint8_t id)
|
||||
{
|
||||
fseeko64(hdd_images[id].file, 0, SEEK_END);
|
||||
return (uint32_t) (ftello64(hdd_images[id].file) >> 9);
|
||||
}
|
||||
|
||||
int hdd_image_read_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
uint32_t transfer_sectors = count;
|
||||
uint32_t sectors = hdd_sectors(id);
|
||||
|
||||
if ((sectors - sector) < transfer_sectors)
|
||||
transfer_sectors = sectors - sector;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fread(buffer, 1, transfer_sectors * 512, hdd_images[id].file);
|
||||
|
||||
if (count != transfer_sectors)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fwrite(buffer, count * 512, 1, hdd_images[id].file);
|
||||
}
|
||||
|
||||
int hdd_image_write_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
uint32_t transfer_sectors = count;
|
||||
uint32_t sectors = hdd_sectors(id);
|
||||
|
||||
if ((sectors - sector) < transfer_sectors)
|
||||
transfer_sectors = sectors - sector;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fwrite(buffer, transfer_sectors * 512, 1, hdd_images[id].file);
|
||||
|
||||
if (count != transfer_sectors)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
for (i = 0; i < count; i++)
|
||||
fwrite(empty_sector, 512, 1, hdd_images[id].file);
|
||||
}
|
||||
|
||||
int hdd_image_zero_ex(uint8_t id, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
uint32_t transfer_sectors = count;
|
||||
uint32_t sectors = hdd_sectors(id);
|
||||
|
||||
if ((sectors - sector) < transfer_sectors)
|
||||
transfer_sectors = sectors - sector;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
for (i = 0; i < transfer_sectors; i++)
|
||||
fwrite(empty_sector, 1, 512, hdd_images[id].file);
|
||||
|
||||
if (count != transfer_sectors)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t hdd_image_get_last_sector(uint8_t id)
|
||||
{
|
||||
return hdd_images[id].last_sector;
|
||||
}
|
||||
|
||||
uint8_t hdd_image_get_type(uint8_t id)
|
||||
{
|
||||
return hdd_images[id].type;
|
||||
}
|
||||
|
||||
void hdd_image_specify(uint8_t id, int hpc, int spt)
|
||||
{
|
||||
if (hdd_images[id].type == 2) {
|
||||
hdd[id].at_hpc = (uint8_t)hpc;
|
||||
hdd[id].at_spt = (uint8_t)spt;
|
||||
fseeko64(hdd_images[id].file, 0x20, SEEK_SET);
|
||||
fwrite(&(hdd[id].at_spt), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].at_hpc), 1, 4, hdd_images[id].file);
|
||||
}
|
||||
}
|
||||
|
||||
void hdd_image_unload(uint8_t id, int fn_preserve)
|
||||
{
|
||||
if (wcslen(hdd[id].fn) == 0)
|
||||
return;
|
||||
|
||||
if (hdd_images[id].loaded) {
|
||||
if (hdd_images[id].file != NULL) {
|
||||
} else {
|
||||
if (image_is_hdi(fn)) {
|
||||
fseeko64(hdd_images[id].file, 0x8, SEEK_SET);
|
||||
fread(&(hdd_images[id].base), 1, 4, hdd_images[id].file);
|
||||
fseeko64(hdd_images[id].file, 0xC, SEEK_SET);
|
||||
full_size = 0;
|
||||
fread(&full_size, 1, 4, hdd_images[id].file);
|
||||
fseeko64(hdd_images[id].file, 0x10, SEEK_SET);
|
||||
fread(§or_size, 1, 4, hdd_images[id].file);
|
||||
if (sector_size != 512) {
|
||||
/* Sector size is not 512 */
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("HDI: Sector size is not 512\n");
|
||||
#endif
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
fread(&spt, 1, 4, hdd_images[id].file);
|
||||
fread(&hpc, 1, 4, hdd_images[id].file);
|
||||
fread(&tracks, 1, 4, hdd_images[id].file);
|
||||
if (hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) {
|
||||
if ((spt != hdd[id].spt) || (hpc != hdd[id].hpc) || (tracks != hdd[id].tracks)) {
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("HDI: Geometry mismatch\n");
|
||||
#endif
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
hdd[id].spt = (uint8_t)spt;
|
||||
hdd[id].hpc = (uint8_t)hpc;
|
||||
hdd[id].tracks = (uint16_t)tracks;
|
||||
hdd_images[id].type = 1;
|
||||
} else if (is_hdx[1]) {
|
||||
hdd_images[id].base = 0x28;
|
||||
fseeko64(hdd_images[id].file, 8, SEEK_SET);
|
||||
fread(&full_size, 1, 8, hdd_images[id].file);
|
||||
fseeko64(hdd_images[id].file, 0x10, SEEK_SET);
|
||||
fread(§or_size, 1, 4, hdd_images[id].file);
|
||||
if (sector_size != 512) {
|
||||
/* Sector size is not 512 */
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("HDX: Sector size is not 512\n");
|
||||
#endif
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
fread(&spt, 1, 4, hdd_images[id].file);
|
||||
fread(&hpc, 1, 4, hdd_images[id].file);
|
||||
fread(&tracks, 1, 4, hdd_images[id].file);
|
||||
if (hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) {
|
||||
if ((spt != hdd[id].spt) || (hpc != hdd[id].hpc) || (tracks != hdd[id].tracks)) {
|
||||
#ifdef ENABLE_HDD_LOG
|
||||
hdd_log("HDX: Geometry mismatch\n");
|
||||
#endif
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
hdd[id].spt = (uint8_t)spt;
|
||||
hdd[id].hpc = (uint8_t)hpc;
|
||||
hdd[id].tracks = (uint16_t)tracks;
|
||||
fread(&(hdd[id].at_spt), 1, 4, hdd_images[id].file);
|
||||
fread(&(hdd[id].at_hpc), 1, 4, hdd_images[id].file);
|
||||
hdd_images[id].type = 2;
|
||||
} else {
|
||||
full_size = hdd[id].spt * hdd[id].hpc * hdd[id].tracks * 512;
|
||||
hdd_images[id].type = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fseeko64(hdd_images[id].file, 0, SEEK_END);
|
||||
if (ftello64(hdd_images[id].file) < (int64_t)(full_size + hdd_images[id].base)) {
|
||||
s = (full_size + hdd_images[id].base) - ftello64(hdd_images[id].file);
|
||||
prepare_new_hard_disk:
|
||||
s >>= 9;
|
||||
t = (s >> 11) << 11;
|
||||
s -= t;
|
||||
t >>= 11;
|
||||
|
||||
empty_sector_1mb = (char *) malloc(1048576);
|
||||
memset(empty_sector_1mb, 0, 1048576);
|
||||
|
||||
if (s > 0) {
|
||||
for (i = 0; i < s; i++) {
|
||||
fwrite(empty_sector, 1, 512, hdd_images[id].file);
|
||||
}
|
||||
hdd_images[id].loaded = 0;
|
||||
}
|
||||
|
||||
hdd_images[id].last_sector = -1;
|
||||
if (t > 0) {
|
||||
for (i = 0; i < t; i++) {
|
||||
fwrite(empty_sector_1mb, 1, 1045876, hdd_images[id].file);
|
||||
}
|
||||
}
|
||||
|
||||
memset(hdd[id].prev_fn, 0, sizeof(hdd[id].prev_fn));
|
||||
if (fn_preserve)
|
||||
wcscpy(hdd[id].prev_fn, hdd[id].fn);
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
free(empty_sector_1mb);
|
||||
}
|
||||
|
||||
hdd_images[id].last_sector = (uint32_t) (full_size >> 9) - 1;
|
||||
|
||||
hdd_images[id].loaded = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void hdd_image_close(uint8_t id)
|
||||
|
||||
void
|
||||
hdd_image_seek(uint8_t id, uint32_t sector)
|
||||
{
|
||||
off64_t addr = sector;
|
||||
addr = (uint64_t)sector * 512;
|
||||
|
||||
fseeko64(hdd_images[id].file, addr + hdd_images[id].base, SEEK_SET);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fread(buffer, 1, count * 512, hdd_images[id].file);
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
hdd_sectors(uint8_t id)
|
||||
{
|
||||
fseeko64(hdd_images[id].file, 0, SEEK_END);
|
||||
|
||||
return (uint32_t) (ftello64(hdd_images[id].file) >> 9);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hdd_image_read_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
uint32_t transfer_sectors = count;
|
||||
uint32_t sectors = hdd_sectors(id);
|
||||
|
||||
if ((sectors - sector) < transfer_sectors)
|
||||
transfer_sectors = sectors - sector;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fread(buffer, 1, transfer_sectors * 512, hdd_images[id].file);
|
||||
|
||||
if (count != transfer_sectors)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fwrite(buffer, count * 512, 1, hdd_images[id].file);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hdd_image_write_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
uint32_t transfer_sectors = count;
|
||||
uint32_t sectors = hdd_sectors(id);
|
||||
|
||||
if ((sectors - sector) < transfer_sectors)
|
||||
transfer_sectors = sectors - sector;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
fwrite(buffer, transfer_sectors * 512, 1, hdd_images[id].file);
|
||||
|
||||
if (count != transfer_sectors)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
for (i = 0; i < count; i++)
|
||||
fwrite(empty_sector, 512, 1, hdd_images[id].file);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hdd_image_zero_ex(uint8_t id, uint32_t sector, uint32_t count)
|
||||
{
|
||||
uint32_t transfer_sectors = count;
|
||||
uint32_t sectors = hdd_sectors(id);
|
||||
uint32_t i;
|
||||
|
||||
if ((sectors - sector) < transfer_sectors)
|
||||
transfer_sectors = sectors - sector;
|
||||
|
||||
fseeko64(hdd_images[id].file, ((uint64_t)sector * 512) + hdd_images[id].base, SEEK_SET);
|
||||
for (i = 0; i < transfer_sectors; i++)
|
||||
fwrite(empty_sector, 1, 512, hdd_images[id].file);
|
||||
|
||||
if (count != transfer_sectors)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
hdd_image_get_last_sector(uint8_t id)
|
||||
{
|
||||
return hdd_images[id].last_sector;
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
hdd_image_get_type(uint8_t id)
|
||||
{
|
||||
return hdd_images[id].type;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hdd_image_specify(uint8_t id, int hpc, int spt)
|
||||
{
|
||||
if (hdd_images[id].type == 2) {
|
||||
hdd[id].at_hpc = (uint8_t)hpc;
|
||||
hdd[id].at_spt = (uint8_t)spt;
|
||||
fseeko64(hdd_images[id].file, 0x20, SEEK_SET);
|
||||
fwrite(&(hdd[id].at_spt), 1, 4, hdd_images[id].file);
|
||||
fwrite(&(hdd[id].at_hpc), 1, 4, hdd_images[id].file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hdd_image_unload(uint8_t id, int fn_preserve)
|
||||
{
|
||||
if (wcslen(hdd[id].fn) == 0) return;
|
||||
|
||||
if (hdd_images[id].loaded) {
|
||||
if (hdd_images[id].file != NULL) {
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
}
|
||||
hdd_images[id].loaded = 0;
|
||||
}
|
||||
|
||||
hdd_images[id].last_sector = -1;
|
||||
|
||||
memset(hdd[id].prev_fn, 0, sizeof(hdd[id].prev_fn));
|
||||
if (fn_preserve)
|
||||
wcscpy(hdd[id].prev_fn, hdd[id].fn);
|
||||
memset(hdd[id].fn, 0, sizeof(hdd[id].fn));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hdd_image_close(uint8_t id)
|
||||
{
|
||||
if (hdd_images[id].file != NULL) {
|
||||
fclose(hdd_images[id].file);
|
||||
hdd_images[id].file = NULL;
|
||||
}
|
||||
|
||||
hdd_images[id].loaded = 0;
|
||||
}
|
||||
|
||||
128
src/disk/zip.c
128
src/disk/zip.c
@@ -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.9 2018/03/27
|
||||
* Version: @(#)zip.c 1.0.10 2018/04/02
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -481,6 +481,7 @@ int zip_do_log = ENABLE_ZIP_LOG;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
static void
|
||||
zip_log(const char *format, ...)
|
||||
{
|
||||
@@ -495,6 +496,7 @@ zip_log(const char *format, ...)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int find_zip_for_channel(uint8_t channel)
|
||||
@@ -533,7 +535,9 @@ int zip_load(uint8_t id, wchar_t *fn)
|
||||
|
||||
if (zip_drives[id].is_250) {
|
||||
if ((size != (ZIP_250_SECTORS << 9)) && (size != (ZIP_SECTORS << 9))) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("File is incorrect size for a ZIP image\nMust be exactly %i or %i bytes\n", ZIP_250_SECTORS << 9, ZIP_SECTORS << 9);
|
||||
#endif
|
||||
fclose(zip_drives[id].f);
|
||||
zip_drives[id].f = NULL;
|
||||
zip_drives[id].medium_size = 0;
|
||||
@@ -542,7 +546,9 @@ int zip_load(uint8_t id, wchar_t *fn)
|
||||
}
|
||||
} else {
|
||||
if (size != (ZIP_SECTORS << 9)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("File is incorrect size for a ZIP image\nMust be exactly %i bytes\n", ZIP_SECTORS << 9);
|
||||
#endif
|
||||
fclose(zip_drives[id].f);
|
||||
zip_drives[id].f = NULL;
|
||||
zip_drives[id].medium_size = 0;
|
||||
@@ -672,7 +678,9 @@ void zip_init(int id, int cdb_len_setting)
|
||||
zip_drives[id].bus_mode |= 2;
|
||||
if (zip_drives[id].bus_type < ZIP_BUS_SCSI)
|
||||
zip_drives[id].bus_mode |= 1;
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Bus type %i, bus mode %i\n", id, zip_drives[id].bus_type, zip_drives[id].bus_mode);
|
||||
#endif
|
||||
if (zip_drives[id].bus_type < ZIP_BUS_SCSI)
|
||||
zip_set_signature(id);
|
||||
zip[id].status = READY_STAT | DSC_STAT;
|
||||
@@ -699,13 +707,17 @@ int zip_current_mode(int id)
|
||||
if (!zip_supports_pio(id) && !zip_supports_dma(id))
|
||||
return 0;
|
||||
if (zip_supports_pio(id) && !zip_supports_dma(id)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Drive does not support DMA, setting to PIO\n", id);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
if (!zip_supports_pio(id) && zip_supports_dma(id))
|
||||
return 2;
|
||||
if (zip_supports_pio(id) && zip_supports_dma(id)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Drive supports both, setting to %s\n", id, (zip[id].features & 1) ? "DMA" : "PIO", id);
|
||||
#endif
|
||||
return (zip[id].features & 1) ? 2 : 1;
|
||||
}
|
||||
|
||||
@@ -909,7 +921,9 @@ uint32_t zip_mode_sense(uint8_t id, uint8_t *buf, uint32_t pos, uint8_t type, ui
|
||||
buf[pos++] = zip_mode_sense_read(id, page_control, i, 0);
|
||||
msplen = zip_mode_sense_read(id, page_control, i, 1);
|
||||
buf[pos++] = msplen;
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: MODE SENSE: Page [%02X] length %i\n", id, i, msplen);
|
||||
#endif
|
||||
for (j = 0; j < msplen; j++)
|
||||
buf[pos++] = zip_mode_sense_read(id, page_control, i, 2 + j);
|
||||
}
|
||||
@@ -1023,7 +1037,9 @@ static void zip_command_write_dma(uint8_t id)
|
||||
direction = Transfer direction (0 = read from host, 1 = write to host). */
|
||||
static void zip_data_command_finish(uint8_t id, int len, int block_len, int alloc_len, int direction)
|
||||
{
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", id, zip[id].current_cdb[0], len, block_len, alloc_len, direction, zip[id].request_length);
|
||||
#endif
|
||||
zip[id].pos=0;
|
||||
if (alloc_len >= 0) {
|
||||
if (alloc_len < len) {
|
||||
@@ -1057,7 +1073,9 @@ static void zip_data_command_finish(uint8_t id, int len, int block_len, int allo
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", id, zip[id].packet_status, zip[id].request_length, zip[id].packet_len, zip[id].pos, zip[id].phase);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void zip_sense_clear(int id, int command)
|
||||
@@ -1089,7 +1107,9 @@ static void zip_cmd_error(uint8_t id)
|
||||
zip[id].packet_status = 0x80;
|
||||
zip[id].callback = 50LL * ZIP_TIME;
|
||||
zip_set_callback(id);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: [%02X] ERROR: %02X/%02X/%02X\n", id, zip[id].current_cdb[0], zip_sense_key, zip_asc, zip_ascq);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void zip_unit_attention(uint8_t id)
|
||||
@@ -1104,7 +1124,9 @@ static void zip_unit_attention(uint8_t id)
|
||||
zip[id].packet_status = 0x80;
|
||||
zip[id].callback = 50LL * ZIP_TIME;
|
||||
zip_set_callback(id);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: UNIT ATTENTION\n", id);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void zip_not_ready(uint8_t id)
|
||||
@@ -1189,18 +1211,24 @@ int zip_blocks(uint8_t id, uint32_t *len, int first_batch, int out)
|
||||
*len = zip[id].requested_blocks << 9;
|
||||
|
||||
if (zip[id].sector_pos >= zip_drives[id].medium_size) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Trying to %s beyond the end of disk\n", id, out ? "write" : "read");
|
||||
#endif
|
||||
zip_lba_out_of_range(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
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);
|
||||
#endif
|
||||
if (out)
|
||||
fwrite(zipbufferb, 1, *len, zip_drives[id].f);
|
||||
else
|
||||
fread(zipbufferb, 1, *len, zip_drives[id].f);
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len);
|
||||
#endif
|
||||
|
||||
zip[id].sector_pos += zip[id].requested_blocks;
|
||||
zip[id].sector_len -= zip[id].requested_blocks;
|
||||
@@ -1227,27 +1255,35 @@ int zip_pre_execution_check(uint8_t id, uint8_t *cdb)
|
||||
|
||||
if (zip_drives[id].bus_type == ZIP_BUS_SCSI) {
|
||||
if (((zip[id].request_length >> 5) & 7) != zip_drives[id].scsi_device_lun) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", id, ((zip[id].request_length >> 5) & 7));
|
||||
#endif
|
||||
zip_invalid_lun(id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(zip_command_flags[cdb[0]] & IMPLEMENTED)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Attempting to execute unknown command %02X over %s\n", id, cdb[0], (zip_drives[id].bus_type == ZIP_BUS_SCSI) ? "SCSI" : ((zip_drives[id].bus_type == ZIP_BUS_ATAPI_PIO_AND_DMA) ? "ATAPI PIO/DMA" : "ATAPI PIO"));
|
||||
#endif
|
||||
|
||||
zip_illegal_opcode(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((zip_drives[id].bus_type < ZIP_BUS_SCSI) && (zip_command_flags[cdb[0]] & SCSI_ONLY)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Attempting to execute SCSI-only command %02X over ATAPI\n", id, cdb[0]);
|
||||
#endif
|
||||
zip_illegal_opcode(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((zip_drives[id].bus_type == ZIP_BUS_SCSI) && (zip_command_flags[cdb[0]] & ATAPI_ONLY)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Attempting to execute ATAPI-only command %02X over SCSI\n", id, cdb[0]);
|
||||
#endif
|
||||
zip_illegal_opcode(id);
|
||||
return 0;
|
||||
}
|
||||
@@ -1265,16 +1301,22 @@ int zip_pre_execution_check(uint8_t id, uint8_t *cdb)
|
||||
if (zip[id].unit_attention == 1) {
|
||||
/* Only increment the unit attention phase if the command can not pass through it. */
|
||||
if (!(zip_command_flags[cdb[0]] & ALLOW_UA)) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: Unit attention now 2\n", id); */
|
||||
#endif
|
||||
zip[id].unit_attention = 2;
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", id, cdb[0]);
|
||||
#endif
|
||||
zip_unit_attention(id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (zip[id].unit_attention == 2) {
|
||||
if (cdb[0] != GPCMD_REQUEST_SENSE) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: Unit attention now 0\n", id); */
|
||||
#endif
|
||||
zip[id].unit_attention = 0;
|
||||
}
|
||||
}
|
||||
@@ -1291,12 +1333,16 @@ int zip_pre_execution_check(uint8_t id, uint8_t *cdb)
|
||||
zip[id].media_status = (zip[id].unit_attention) ? MEC_NEW_MEDIA : MEC_NO_CHANGE;
|
||||
|
||||
if ((zip_command_flags[cdb[0]] & CHECK_READY) && !ready) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Not ready (%02X)\n", id, cdb[0]);
|
||||
#endif
|
||||
zip_not_ready(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Continuing with command %02X\n", id, cdb[0]);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1314,7 +1360,9 @@ void zip_clear_callback(uint8_t channel)
|
||||
|
||||
static void zip_seek(uint8_t id, uint32_t pos)
|
||||
{
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: Seek %08X\n", id, pos); */
|
||||
#endif
|
||||
zip[id].sector_pos = pos;
|
||||
}
|
||||
|
||||
@@ -1356,7 +1404,9 @@ void zip_request_sense(uint8_t id, uint8_t *buffer, uint8_t alloc_length, int de
|
||||
buffer[desc ? 3 : 13]=0;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Reporting sense: %02X %02X %02X\n", id, buffer[2], buffer[12], buffer[13]);
|
||||
#endif
|
||||
|
||||
if (buffer[desc ? 1 : 2] == SENSE_UNIT_ATTENTION) {
|
||||
/* If the last remaining sense is unit attention, clear
|
||||
@@ -1395,20 +1445,26 @@ void zip_set_buf_len(uint8_t id, int32_t *BufLen, uint32_t *src_len)
|
||||
*BufLen = MIN(*src_len, (uint32_t)*BufLen);
|
||||
*src_len = *BufLen;
|
||||
}
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Actual transfer length: %i\n", id, *BufLen);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void zip_buf_alloc(uint8_t id, uint32_t len)
|
||||
{
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Allocated buffer length: %i\n", id, len);
|
||||
#endif
|
||||
zipbufferb = (uint8_t *) malloc(len);
|
||||
}
|
||||
|
||||
void zip_buf_free(uint8_t id)
|
||||
{
|
||||
if (zipbufferb) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Freeing buffer...\n", id);
|
||||
#endif
|
||||
free(zipbufferb);
|
||||
zipbufferb = NULL;
|
||||
}
|
||||
@@ -1444,6 +1500,7 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
|
||||
memcpy(zip[id].current_cdb, cdb, zip[id].cdb_len);
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
if (cdb[0] != 0) {
|
||||
zip_log("ZIP %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", id, cdb[0], zip_sense_key, zip_asc, zip_ascq, zip[id].unit_attention);
|
||||
zip_log("ZIP %i: Request length: %04X\n", id, zip[id].request_length);
|
||||
@@ -1452,6 +1509,7 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7],
|
||||
cdb[8], cdb[9], cdb[10], cdb[11]);
|
||||
}
|
||||
#endif
|
||||
|
||||
zip[id].sector_len = 0;
|
||||
|
||||
@@ -1564,12 +1622,16 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
case GPCMD_READ_6:
|
||||
zip[id].sector_len = cdb[4];
|
||||
zip[id].sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Length: %i, LBA: %i\n", id, zip[id].sector_len, zip[id].sector_pos);
|
||||
#endif
|
||||
break;
|
||||
case GPCMD_READ_10:
|
||||
zip[id].sector_len = (cdb[7] << 8) | cdb[8];
|
||||
zip[id].sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5];
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Length: %i, LBA: %i\n", id, zip[id].sector_len, zip[id].sector_pos);
|
||||
#endif
|
||||
break;
|
||||
case GPCMD_READ_12:
|
||||
zip[id].sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]);
|
||||
@@ -1579,7 +1641,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
|
||||
if (!zip[id].sector_len) {
|
||||
zip_set_phase(id, SCSI_PHASE_STATUS);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: All done - callback set\n", id); */
|
||||
#endif
|
||||
zip[id].packet_status = ZIP_PHASE_COMPLETE;
|
||||
zip[id].callback = 20LL * ZIP_TIME;
|
||||
zip_set_callback(id);
|
||||
@@ -1647,7 +1711,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
case GPCMD_WRITE_AND_VERIFY_10:
|
||||
zip[id].sector_len = (cdb[7] << 8) | cdb[8];
|
||||
zip[id].sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5];
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Length: %i, LBA: %i\n", id, zip[id].sector_len, zip[id].sector_pos);
|
||||
#endif
|
||||
break;
|
||||
case GPCMD_VERIFY_12:
|
||||
case GPCMD_WRITE_12:
|
||||
@@ -1673,7 +1739,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
|
||||
if (!zip[id].sector_len) {
|
||||
zip_set_phase(id, SCSI_PHASE_STATUS);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: All done - callback set\n", id); */
|
||||
#endif
|
||||
zip[id].packet_status = ZIP_PHASE_COMPLETE;
|
||||
zip[id].callback = 20LL * ZIP_TIME;
|
||||
zip_set_callback(id);
|
||||
@@ -1737,7 +1805,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
|
||||
if (!zip[id].sector_len) {
|
||||
zip_set_phase(id, SCSI_PHASE_STATUS);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: All done - callback set\n", id); */
|
||||
#endif
|
||||
zip[id].packet_status = ZIP_PHASE_COMPLETE;
|
||||
zip[id].callback = 20LL * ZIP_TIME;
|
||||
zip_set_callback(id);
|
||||
@@ -1784,7 +1854,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
}
|
||||
|
||||
zip[id].current_page_code = cdb[2] & 0x3F;
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("Mode sense page: %02X\n", zip[id].current_page_code);
|
||||
#endif
|
||||
|
||||
if (!(zip_mode_sense_page_flags & (1LL << zip[id].current_page_code))) {
|
||||
zip_invalid_field(id);
|
||||
@@ -1816,7 +1888,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
|
||||
zip_set_buf_len(id, BufLen, &len);
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Reading mode page: %02X...\n", id, cdb[2]);
|
||||
#endif
|
||||
|
||||
zip_data_command_finish(id, len, len, alloc_length, 0);
|
||||
return;
|
||||
@@ -1918,7 +1992,9 @@ void zip_command(uint8_t id, uint8_t *cdb)
|
||||
idx += 20;
|
||||
break;
|
||||
default:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("INQUIRY: Invalid page: %02X\n", cdb[2]);
|
||||
#endif
|
||||
zip_invalid_field(id);
|
||||
zip_buf_free(id);
|
||||
return;
|
||||
@@ -2091,7 +2167,9 @@ atapi_out:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
/* zip_log("ZIP %i: Phase: %02X, request length: %i\n", zip[id].phase, zip[id].request_length); */
|
||||
#endif
|
||||
|
||||
if (zip_atapi_phase_to_scsi(id) == SCSI_PHASE_STATUS)
|
||||
zip_buf_free(id);
|
||||
@@ -2233,14 +2311,18 @@ void zip_pio_request(uint8_t id, uint8_t out)
|
||||
int ret = 0;
|
||||
|
||||
if (zip_drives[id].bus_type < ZIP_BUS_SCSI) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Lowering IDE IRQ\n", id);
|
||||
#endif
|
||||
ide_irq_lower(&(ide_drives[zip_drives[id].ide_channel]));
|
||||
}
|
||||
|
||||
zip[id].status = BUSY_STAT;
|
||||
|
||||
if (zip[id].pos >= zip[id].packet_len) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: %i bytes %s, command done\n", id, zip[id].pos, out ? "written" : "read");
|
||||
#endif
|
||||
|
||||
zip[id].pos = zip[id].request_pos = 0;
|
||||
if (out) {
|
||||
@@ -2255,7 +2337,9 @@ void zip_pio_request(uint8_t id, uint8_t out)
|
||||
ui_sb_update_icon(SB_ZIP | id, 0);
|
||||
zip_buf_free(id);
|
||||
} else {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: %i bytes %s, %i bytes are still left\n", id, zip[id].pos, out ? "written" : "read", zip[id].packet_len - zip[id].pos);
|
||||
#endif
|
||||
|
||||
/* Make sure to keep pos, and reset request_pos to 0. */
|
||||
/* Also make sure to not reset total_read. */
|
||||
@@ -2300,7 +2384,9 @@ int zip_read_from_scsi_dma(uint8_t scsi_id, uint8_t scsi_lun)
|
||||
if (id > ZIP_NUM)
|
||||
return 0;
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("Reading from SCSI DMA: SCSI ID %02X, init length %i\n", scsi_id, *BufLen);
|
||||
#endif
|
||||
memcpy(zipbufferb, SCSIDevices[scsi_id][scsi_lun].CmdBuffer, *BufLen);
|
||||
return 1;
|
||||
}
|
||||
@@ -2313,11 +2399,15 @@ void zip_irq_raise(uint8_t id)
|
||||
|
||||
int zip_read_from_dma(uint8_t id)
|
||||
{
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
int32_t *BufLen = &SCSIDevices[zip_drives[id].scsi_device_id][zip_drives[id].scsi_device_lun].BufferLength;
|
||||
#endif
|
||||
|
||||
int ret = 0;
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
int in_data_length = 0;
|
||||
#endif
|
||||
|
||||
if (zip_drives[id].bus_type == ZIP_BUS_SCSI)
|
||||
ret = zip_read_from_scsi_dma(zip_drives[id].scsi_device_id, zip_drives[id].scsi_device_lun);
|
||||
@@ -2328,11 +2418,15 @@ int zip_read_from_dma(uint8_t id)
|
||||
return 0;
|
||||
|
||||
if (zip_drives[id].bus_type == ZIP_BUS_SCSI) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
in_data_length = *BufLen;
|
||||
zip_log("ZIP %i: SCSI Input data length: %i\n", id, in_data_length);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
in_data_length = zip[id].max_transfer_len;
|
||||
zip_log("ZIP %i: ATAPI Input data length: %i\n", id, in_data_length);
|
||||
#endif
|
||||
}
|
||||
|
||||
ret = zip_phase_data_out(id);
|
||||
@@ -2358,7 +2452,9 @@ int zip_write_to_ide_dma(uint8_t channel)
|
||||
uint8_t id = atapi_zip_drives[channel];
|
||||
|
||||
if (id > ZIP_NUM) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Drive not found\n", id);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2380,10 +2476,14 @@ int zip_write_to_scsi_dma(uint8_t scsi_id, uint8_t scsi_lun)
|
||||
if (id > ZIP_NUM)
|
||||
return 0;
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("Writing to SCSI DMA: SCSI ID %02X, init length %i\n", scsi_id, *BufLen);
|
||||
#endif
|
||||
memcpy(SCSIDevices[scsi_id][scsi_lun].CmdBuffer, zipbufferb, *BufLen);
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: Data from CD buffer: %02X %02X %02X %02X %02X %02X %02X %02X\n", id, zipbufferb[0], zipbufferb[1], zipbufferb[2], zipbufferb[3], zipbufferb[4], zipbufferb[5], zipbufferb[6], zipbufferb[7]);
|
||||
zip_log("ZIP %i: Data from SCSI DMA : %02X %02X %02X %02X %02X %02X %02X %02X\n", id, SCSIDevices[scsi_id][scsi_lun].CmdBuffer[0], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[1], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[2], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[3], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[4], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[5], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[6], SCSIDevices[scsi_id][scsi_lun].CmdBuffer[7]);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2392,7 +2492,9 @@ int zip_write_to_dma(uint8_t id)
|
||||
int ret = 0;
|
||||
|
||||
if (zip_drives[id].bus_type == ZIP_BUS_SCSI) {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("Write to SCSI DMA: (%02X:%02X)\n", zip_drives[id].scsi_device_id, zip_drives[id].scsi_device_lun);
|
||||
#endif
|
||||
ret = zip_write_to_scsi_dma(zip_drives[id].scsi_device_id, zip_drives[id].scsi_device_lun);
|
||||
} else
|
||||
ret = zip_write_to_ide_dma(zip_drives[id].ide_channel);
|
||||
@@ -2418,19 +2520,25 @@ void zip_phase_callback(uint8_t id)
|
||||
{
|
||||
switch(zip[id].packet_status) {
|
||||
case ZIP_PHASE_IDLE:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_IDLE\n", id);
|
||||
#endif
|
||||
zip[id].pos=0;
|
||||
zip[id].phase = 1;
|
||||
zip[id].status = READY_STAT | DRQ_STAT | (zip[id].status & ERR_STAT);
|
||||
return;
|
||||
case ZIP_PHASE_COMMAND:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_COMMAND\n", id);
|
||||
#endif
|
||||
zip[id].status = BUSY_STAT | (zip[id].status &ERR_STAT);
|
||||
memcpy(zip[id].atapi_cdb, zipbufferb, zip[id].cdb_len);
|
||||
zip_command(id, zip[id].atapi_cdb);
|
||||
return;
|
||||
case ZIP_PHASE_COMPLETE:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_COMPLETE\n", id);
|
||||
#endif
|
||||
zip[id].status = READY_STAT;
|
||||
zip[id].phase = 3;
|
||||
zip[id].packet_status = 0xFF;
|
||||
@@ -2438,27 +2546,37 @@ void zip_phase_callback(uint8_t id)
|
||||
zip_irq_raise(id);
|
||||
return;
|
||||
case ZIP_PHASE_DATA_OUT:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_DATA_OUT\n", id);
|
||||
#endif
|
||||
zip[id].status = READY_STAT | DRQ_STAT | (zip[id].status & ERR_STAT);
|
||||
zip[id].phase = 0;
|
||||
zip_irq_raise(id);
|
||||
return;
|
||||
case ZIP_PHASE_DATA_OUT_DMA:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_DATA_OUT_DMA\n", id);
|
||||
#endif
|
||||
zip_read_from_dma(id);
|
||||
return;
|
||||
case ZIP_PHASE_DATA_IN:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_DATA_IN\n", id);
|
||||
#endif
|
||||
zip[id].status = READY_STAT | DRQ_STAT | (zip[id].status & ERR_STAT);
|
||||
zip[id].phase = 2;
|
||||
zip_irq_raise(id);
|
||||
return;
|
||||
case ZIP_PHASE_DATA_IN_DMA:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_DATA_IN_DMA\n", id);
|
||||
#endif
|
||||
zip_write_to_dma(id);
|
||||
return;
|
||||
case ZIP_PHASE_ERROR:
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP %i: ZIP_PHASE_ERROR\n", id);
|
||||
#endif
|
||||
zip[id].status = READY_STAT | ERR_STAT;
|
||||
zip[id].phase = 3;
|
||||
zip[id].packet_status = 0xFF;
|
||||
@@ -2513,13 +2631,19 @@ uint32_t zip_read(uint8_t channel, int length)
|
||||
if (zip[id].packet_status == ZIP_PHASE_DATA_IN) {
|
||||
if ((zip[id].request_pos >= zip[id].max_transfer_len) || (zip[id].pos >= zip[id].packet_len)) {
|
||||
/* Time for a DRQ. */
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
// zip_log("ZIP %i: Issuing read callback\n", id);
|
||||
#endif
|
||||
zip_pio_request(id, 0);
|
||||
}
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
// zip_log("ZIP %i: Returning: %02X (buffer position: %i, request position: %i)\n", id, temp, zip[id].pos, zip[id].request_pos);
|
||||
#endif
|
||||
return temp;
|
||||
} else {
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
// zip_log("ZIP %i: Returning zero (buffer position: %i, request position: %i)\n", id, zip[id].pos, zip[id].request_pos);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -2605,7 +2729,9 @@ zip_hard_reset(void)
|
||||
if (zip_drives[c].bus_type)
|
||||
SCSIReset(zip_drives[c].scsi_device_id, zip_drives[c].scsi_device_lun);
|
||||
|
||||
#ifdef ENABLE_ZIP_LOG
|
||||
zip_log("ZIP hard_reset drive=%d host=%02x\n", c, zip_drives[c].host_drive);
|
||||
#endif
|
||||
if (wcslen(zip_drives[c].image_path))
|
||||
zip_load(c, zip_drives[c].image_path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user