2017-05-30 03:38:38 +02:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Implementation of the generic device interface to handle
|
|
|
|
|
* all devices attached to the emulator.
|
|
|
|
|
*
|
2017-10-17 01:59:09 -04:00
|
|
|
* Version: @(#)device.c 1.0.5 2017/10/16
|
2017-05-30 03:38:38 +02:00
|
|
|
*
|
2017-06-04 02:11:19 -04:00
|
|
|
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
2017-05-30 03:38:38 +02:00
|
|
|
* Miran Grca, <mgrca8@gmail.com>
|
2017-10-17 01:59:09 -04:00
|
|
|
*
|
2017-05-30 03:38:38 +02:00
|
|
|
* Copyright 2008-2016 Sarah Walker.
|
2017-08-25 02:21:26 -04:00
|
|
|
* Copyright 2016,2017 Miran Grca.
|
2017-05-30 03:38:38 +02:00
|
|
|
*/
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2017-10-17 01:59:09 -04:00
|
|
|
#include "86box.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ibm.h"
|
2017-08-27 04:33:47 +01:00
|
|
|
#include "cpu/cpu.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
#include "device.h"
|
2017-09-02 20:39:57 +02:00
|
|
|
#include "machine/machine.h"
|
2017-08-27 04:33:47 +01:00
|
|
|
#include "sound/sound.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
#define DEVICE_MAX 256 /* max # of devices */
|
|
|
|
|
|
|
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
static device_t *devices[DEVICE_MAX];
|
|
|
|
|
static void *device_priv[DEVICE_MAX];
|
|
|
|
|
static device_t *device_current;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-06-04 02:11:19 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_init(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
memset(devices, 0x00, sizeof(devices));
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-19 23:55:51 +02:00
|
|
|
void *
|
2017-10-07 00:46:54 -04:00
|
|
|
device_add(device_t *d)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
void *priv = NULL;
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
while (devices[c] != NULL && c < 256)
|
2016-06-26 00:34:39 +02:00
|
|
|
c++;
|
2017-10-07 00:46:54 -04:00
|
|
|
if (c >= DEVICE_MAX)
|
|
|
|
|
fatal("device_add: too many devices\n");
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
device_current = d;
|
|
|
|
|
|
|
|
|
|
if (d->init != NULL) {
|
|
|
|
|
priv = d->init(d);
|
|
|
|
|
if (priv == NULL)
|
|
|
|
|
fatal("device_add: device init failed\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
devices[c] = d;
|
2017-10-19 23:55:51 +02:00
|
|
|
device_priv[c] = priv;
|
|
|
|
|
|
|
|
|
|
return priv;
|
2017-10-07 00:46:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
device_close_all(void)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c=0; c<DEVICE_MAX; c++) {
|
|
|
|
|
if (devices[c] != NULL) {
|
|
|
|
|
if (devices[c]->close != NULL)
|
|
|
|
|
devices[c]->close(device_priv[c]);
|
|
|
|
|
devices[c] = device_priv[c] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_reset_all(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c=0; c<DEVICE_MAX; c++) {
|
|
|
|
|
if (devices[c] != NULL) {
|
|
|
|
|
if (devices[c]->reset != NULL)
|
|
|
|
|
devices[c]->reset(device_priv[c]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void *
|
|
|
|
|
device_get_priv(device_t *d)
|
2017-06-14 03:03:29 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c=0; c<DEVICE_MAX; c++) {
|
|
|
|
|
if (devices[c] != NULL) {
|
|
|
|
|
if (devices[c] == d)
|
|
|
|
|
return(device_priv[c]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(NULL);
|
2017-06-14 03:03:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
device_available(device_t *d)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
#ifdef RELEASE_BUILD
|
2017-10-07 00:46:54 -04:00
|
|
|
if (d->flags & DEVICE_NOT_WORKING) return(0);
|
2016-06-26 00:34:39 +02:00
|
|
|
#endif
|
2017-10-07 00:46:54 -04:00
|
|
|
if (d->available != NULL)
|
|
|
|
|
return(d->available());
|
|
|
|
|
|
|
|
|
|
return(1);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_speed_changed(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c=0; c<DEVICE_MAX; c++) {
|
|
|
|
|
if (devices[c] != NULL) {
|
|
|
|
|
if (devices[c]->speed_changed != NULL)
|
|
|
|
|
devices[c]->speed_changed(device_priv[c]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sound_speed_changed();
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_force_redraw(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c=0; c<DEVICE_MAX; c++) {
|
|
|
|
|
if (devices[c] != NULL) {
|
|
|
|
|
if (devices[c]->force_redraw != NULL)
|
2016-06-26 00:34:39 +02:00
|
|
|
devices[c]->force_redraw(device_priv[c]);
|
2017-10-07 00:46:54 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_add_status_info(char *s, int max_len)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c=0; c<DEVICE_MAX; c++) {
|
|
|
|
|
if (devices[c] != NULL) {
|
|
|
|
|
if (devices[c]->add_status_info != NULL)
|
|
|
|
|
devices[c]->add_status_info(s, max_len, device_priv[c]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
char *
|
|
|
|
|
device_get_config_string(char *s)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_string(device_current->name, s, c->default_string));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(NULL);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
device_get_config_int(char *s)
|
2017-05-17 21:56:31 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_int(device_current->name, s, c->default_int));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
2017-05-17 21:56:31 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
device_get_config_int_ex(char *s, int default_int)
|
2017-05-27 03:53:32 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_int(device_current->name, s, default_int));
|
2017-05-27 03:53:32 +02:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(default_int);
|
2017-05-27 03:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
device_get_config_hex16(char *s)
|
2017-05-27 03:53:32 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_hex16(device_current->name, s, c->default_int));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
2017-05-27 03:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
device_get_config_hex20(char *s)
|
2017-05-27 03:53:32 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_hex20(device_current->name, s, c->default_int));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
2017-05-27 03:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
device_get_config_mac(char *s, int default_int)
|
2017-05-17 21:56:31 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_mac(device_current->name, s, default_int));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(default_int);
|
2017-05-17 21:56:31 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_set_config_int(char *s, int val)
|
2017-05-27 03:53:32 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name)) {
|
|
|
|
|
config_set_int(device_current->name, s, val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
2017-05-27 03:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_set_config_hex16(char *s, int val)
|
2017-05-27 03:53:32 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name)) {
|
|
|
|
|
config_set_hex16(device_current->name, s, val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
2017-05-27 03:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_set_config_hex20(char *s, int val)
|
2017-05-27 03:53:32 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name)) {
|
|
|
|
|
config_set_hex20(device_current->name, s, val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
2017-05-27 03:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
void
|
|
|
|
|
device_set_config_mac(char *s, int val)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_config_t *c = device_current->config;
|
|
|
|
|
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name)) {
|
|
|
|
|
config_set_mac(device_current->name, s, val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-10 00:14:15 +02:00
|
|
|
int
|
|
|
|
|
device_is_valid(device_t *device, int machine_flags)
|
|
|
|
|
{
|
|
|
|
|
if (!device)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_AT) && !(machine_flags & MACHINE_AT)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_CBUS) && !(machine_flags & MACHINE_CBUS)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_ISA) && !(machine_flags & MACHINE_ISA)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_MCA) && !(machine_flags & MACHINE_MCA)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_EISA) && !(machine_flags & MACHINE_EISA)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_VLB) && !(machine_flags & MACHINE_VLB)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_PCI) && !(machine_flags & MACHINE_PCI)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_PS2) && !(machine_flags & MACHINE_PS2_HDD)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((device->flags & DEVICE_AGP) && !(machine_flags & MACHINE_AGP)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
int
|
|
|
|
|
machine_get_config_int(char *s)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_t *d = machine_getdevice(machine);
|
|
|
|
|
device_config_t *c;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
if (d == NULL) return(0);
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
c = d->config;
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_int(d->name, s, c->default_int));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 02:21:26 -04:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
char *
|
|
|
|
|
machine_get_config_string(char *s)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-10-07 00:46:54 -04:00
|
|
|
device_t *d = machine_getdevice(machine);
|
|
|
|
|
device_config_t *c;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
if (d == NULL) return(0);
|
|
|
|
|
|
|
|
|
|
c = d->config;
|
|
|
|
|
while (c && c->type != -1) {
|
|
|
|
|
if (! strcmp(s, c->name))
|
|
|
|
|
return(config_get_string(d->name, s, c->default_string));
|
|
|
|
|
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(NULL);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|