PCem
view src/device.c @ 154:d0d530adce12
Initial port to Linux (using Allegro).
64-bit fixes.
Some changes to aid portability.
A few other tweaks.
| author | TomW |
|---|---|
| date | Thu Sep 04 21:07:24 2014 +0100 |
| parents | 24b744b9a632 |
| children |
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 for (c = 0; c < 256; c++)
99 {
100 if (devices[c] != NULL)
101 {
102 if (devices[c]->add_status_info != NULL)
103 devices[c]->add_status_info(s, max_len, device_priv[c]);
104 }
105 }
106 }
108 int device_get_config_int(char *s)
109 {
110 device_config_t *config = current_device->config;
112 while (config->type != -1)
113 {
114 if (!strcmp(s, config->name))
115 return config_get_int(current_device->name, s, config->default_int);
117 config++;
118 }
119 return 0;
120 }
122 char *device_get_config_string(char *s)
123 {
124 device_config_t *config = current_device->config;
126 while (config->type != -1)
127 {
128 if (!strcmp(s, config->name))
129 return config_get_string(current_device->name, s, config->default_string);
131 config++;
132 }
133 return NULL;
134 }
