Files
86Box/src/disk/hdc.c

196 lines
4.5 KiB
C
Raw Normal View History

/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
* This file is part of the 86Box distribution.
*
* Common code to handle all sorts of disk controllers.
*
2020-03-25 00:46:02 +02:00
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
2017-10-17 01:59:09 -04:00
*
* Copyright 2016-2018 Miran Grca.
2023-01-06 15:36:29 -05:00
* Copyright 2017-2018 Fred N. van Kempen.
*/
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#define HAVE_STDARG_H
#include <86box/86box.h>
#include <86box/machine.h>
#include <86box/timer.h>
#include <86box/device.h>
#include <86box/hdc.h>
#include <86box/hdc_ide.h>
#include <86box/hdd.h>
2022-09-18 17:13:50 -04:00
int hdc_current;
#ifdef ENABLE_HDC_LOG
int hdc_do_log = ENABLE_HDC_LOG;
static void
hdc_log(const char *fmt, ...)
{
va_list ap;
if (hdc_do_log) {
2022-09-18 17:13:50 -04:00
va_start(ap, fmt);
pclog_ex(fmt, ap);
va_end(ap);
}
}
#else
2022-09-18 17:13:50 -04:00
# define hdc_log(fmt, ...)
#endif
2022-02-02 18:00:06 -05:00
static const device_t hdc_none_device = {
2022-09-18 17:13:50 -04:00
.name = "None",
2022-03-13 09:37:19 -04:00
.internal_name = "none",
2022-09-18 17:13:50 -04:00
.flags = 0,
.local = 0,
2022-10-27 12:03:17 -04:00
.init = NULL,
.close = NULL,
2022-09-18 17:13:50 -04:00
.reset = NULL,
2022-03-13 09:37:19 -04:00
{ .available = NULL },
.speed_changed = NULL,
2022-09-18 17:13:50 -04:00
.force_redraw = NULL,
.config = NULL
2022-02-02 18:00:06 -05:00
};
2022-03-13 09:37:19 -04:00
static const device_t hdc_internal_device = {
2022-09-18 17:13:50 -04:00
.name = "Internal",
2022-03-13 09:37:19 -04:00
.internal_name = "internal",
2022-09-18 17:13:50 -04:00
.flags = 0,
.local = 0,
2022-10-27 12:03:17 -04:00
.init = NULL,
.close = NULL,
2022-09-18 17:13:50 -04:00
.reset = NULL,
2022-03-13 09:37:19 -04:00
{ .available = NULL },
.speed_changed = NULL,
2022-09-18 17:13:50 -04:00
.force_redraw = NULL,
.config = NULL
};
static const struct {
2022-09-18 17:13:50 -04:00
const device_t *device;
} controllers[] = {
2022-09-18 17:13:50 -04:00
// clang-format off
2022-02-26 23:31:28 -05:00
{ &hdc_none_device },
{ &hdc_internal_device },
{ &st506_xt_xebec_device },
2022-12-20 23:12:41 -05:00
{ &st506_xt_wdxt_gen_device },
2022-02-26 23:31:28 -05:00
{ &st506_xt_dtc5150x_device },
{ &st506_xt_st11_m_device },
{ &st506_xt_wd1002a_wx1_device },
{ &st506_xt_wd1004a_wx1_device },
2022-02-26 23:31:28 -05:00
{ &st506_at_wd1003_device },
{ &st506_xt_st11_r_device },
{ &st506_xt_wd1002a_27x_device },
{ &st506_xt_wd1004_27x_device },
{ &st506_xt_wd1004a_27x_device },
{ &st506_xt_victor_v86p_device },
2022-02-26 23:31:28 -05:00
{ &esdi_at_wd1007vse1_device },
{ &ide_isa_device },
{ &ide_isa_2ch_device },
{ &xtide_at_device },
{ &xtide_at_ps2_device },
{ &xta_wdxt150_device },
{ &xtide_acculogic_device },
{ &xtide_device },
{ &esdi_ps2_device },
{ &ide_pci_device },
{ &ide_pci_2ch_device },
{ &ide_vlb_device },
{ &ide_vlb_2ch_device },
{ &mcide_device },
2022-03-13 09:37:19 -04:00
{ NULL }
2022-09-18 17:13:50 -04:00
// clang-format on
};
/* Initialize the 'hdc_current' value based on configured HDC name. */
void
hdc_init(void)
{
hdc_log("HDC: initializing..\n");
/* Zero all the hard disk image arrays. */
hdd_image_init();
}
/* Reset the HDC, whichever one that is. */
void
hdc_reset(void)
{
hdc_log("HDC: reset(current=%d, internal=%d)\n",
2022-09-18 17:13:50 -04:00
hdc_current, (machines[machine].flags & MACHINE_HDC) ? 1 : 0);
/* If we have a valid controller, add its device. */
if (hdc_current > 1)
2022-09-18 17:13:50 -04:00
device_add(controllers[hdc_current].device);
/* Now, add the tertiary and/or quaternary IDE controllers. */
if (ide_ter_enabled)
2022-09-18 17:13:50 -04:00
device_add(&ide_ter_device);
if (ide_qua_enabled)
2022-09-18 17:13:50 -04:00
device_add(&ide_qua_device);
}
2023-08-21 20:22:55 -04:00
const char *
hdc_get_internal_name(int hdc)
{
return device_get_internal_name(controllers[hdc].device);
}
int
hdc_get_from_internal_name(char *s)
{
int c = 0;
while (controllers[c].device != NULL) {
2023-08-21 20:22:55 -04:00
if (!strcmp(controllers[c].device->internal_name, s))
2022-09-18 17:13:50 -04:00
return c;
c++;
}
return 0;
}
const device_t *
hdc_get_device(int hdc)
{
2022-09-18 17:13:50 -04:00
return (controllers[hdc].device);
}
int
hdc_has_config(int hdc)
{
const device_t *dev = hdc_get_device(hdc);
2022-09-18 17:13:50 -04:00
if (dev == NULL)
2023-05-29 01:30:51 -04:00
return 0;
2022-09-18 17:13:50 -04:00
if (!device_has_config(dev))
2023-05-29 01:30:51 -04:00
return 0;
2023-05-29 01:30:51 -04:00
return 1;
}
int
hdc_get_flags(int hdc)
{
2022-09-18 17:13:50 -04:00
return (controllers[hdc].device->flags);
}
int
hdc_available(int hdc)
{
2022-09-18 17:13:50 -04:00
return (device_available(controllers[hdc].device));
}