PCem

view src/device.c @ 113:f749363ad763

Added per-device configuration. Reworked configuration parser a bit. Added configuration for S3 ViRGE and 8-bit Sound Blasters. IRQ 2 routed to IRQ 9 on AT machines.
author TomW
date Mon Jun 30 21:31:28 2014 +0100
parents c5989dbbc2ce
children 24b744b9a632
line source
1 #include "ibm.h"
2 #include "config.h"
3 #include "device.h"
5 static void *device_priv[256];
6 static device_t *devices[256];
8 static device_t *current_device;
10 void device_init()
11 {
12 memset(devices, 0, sizeof(devices));
13 }
15 void device_add(device_t *d)
16 {
17 int c = 0;
18 void *priv;
20 while (devices[c] != NULL && c < 256)
21 c++;
23 if (c >= 256)
24 fatal("device_add : too many devices\n");
26 current_device = d;
28 priv = d->init();
29 if (priv == NULL)
30 fatal("device_add : device init failed\n");
32 devices[c] = d;
33 device_priv[c] = priv;
34 }
36 void device_close_all()
37 {
38 int c;
40 for (c = 0; c < 256; c++)
41 {
42 if (devices[c] != NULL)
43 {
44 devices[c]->close(device_priv[c]);
45 devices[c] = device_priv[c] = NULL;
46 }
47 }
48 }
50 int device_available(device_t *d)
51 {
52 #ifdef RELEASE_BUILD
53 if (d->flags & DEVICE_NOT_WORKING)
54 return 0;
55 #endif
56 if (d->available)
57 return d->available();
59 return 1;
60 }
62 void device_speed_changed()
63 {
64 int c;
66 for (c = 0; c < 256; c++)
67 {
68 if (devices[c] != NULL)
69 {
70 if (devices[c]->speed_changed != NULL)
71 {
72 devices[c]->speed_changed(device_priv[c]);
73 }
74 }
75 }
76 }
78 void device_force_redraw()
79 {
80 int c;
82 for (c = 0; c < 256; c++)
83 {
84 if (devices[c] != NULL)
85 {
86 if (devices[c]->force_redraw != NULL)
87 {
88 devices[c]->force_redraw(device_priv[c]);
89 }
90 }
91 }
92 }
94 char *device_add_status_info(char *s, int max_len)
95 {
96 int c;
98 s += strlen(s);
100 for (c = 0; c < 256; c++)
101 {
102 if (devices[c] != NULL)
103 {
104 if (devices[c]->add_status_info != NULL)
105 {
106 int len = devices[c]->add_status_info(s, max_len, device_priv[c]);
107 s += len;
108 max_len -= len;
109 }
110 }
111 }
112 }
114 int device_get_config_int(char *s)
115 {
116 device_config_t *config = current_device->config;
118 while (config->type != -1)
119 {
120 if (!strcmp(s, config->name))
121 return get_config_int(current_device->name, s, config->default_int);
123 config++;
124 }
125 return 0;
126 }
128 char *device_get_config_string(char *s)
129 {
130 device_config_t *config = current_device->config;
132 while (config->type != -1)
133 {
134 if (!strcmp(s, config->name))
135 return get_config_string(current_device->name, s, config->default_string);
137 config++;
138 }
139 return NULL;
140 }