25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_lpt.c,v 1.11 2007/04/20 11:17:24 debug Exp $ |
* $Id: dev_lpt.c,v 1.14 2007/06/15 19:11:15 debug Exp $ |
29 |
* |
* |
30 |
* LPT (parallel printer) controller. |
* COMMENT: LPT (parallel printer) controller |
31 |
*/ |
*/ |
32 |
|
|
33 |
#include <stdio.h> |
#include <stdio.h> |
37 |
#include "console.h" |
#include "console.h" |
38 |
#include "cpu.h" |
#include "cpu.h" |
39 |
#include "device.h" |
#include "device.h" |
40 |
|
#include "interrupt.h" |
41 |
#include "machine.h" |
#include "machine.h" |
42 |
#include "memory.h" |
#include "memory.h" |
43 |
#include "misc.h" |
#include "misc.h" |
51 |
#define DEV_LPT_LENGTH 3 |
#define DEV_LPT_LENGTH 3 |
52 |
|
|
53 |
struct lpt_data { |
struct lpt_data { |
54 |
int irqnr; |
char *name; |
55 |
char *name; |
struct interrupt irq; |
56 |
int console_handle; |
int console_handle; |
57 |
|
|
58 |
unsigned char data; |
uint8_t data; |
59 |
unsigned char control; |
uint8_t control; |
60 |
}; |
}; |
61 |
|
|
62 |
|
|
112 |
|
|
113 |
DEVINIT(lpt) |
DEVINIT(lpt) |
114 |
{ |
{ |
115 |
struct lpt_data *d = malloc(sizeof(struct lpt_data)); |
struct lpt_data *d; |
116 |
size_t nlen; |
size_t nlen; |
117 |
char *name; |
char *name; |
118 |
|
|
119 |
if (d == NULL) { |
CHECK_ALLOCATION(d = malloc(sizeof(struct lpt_data))); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
120 |
memset(d, 0, sizeof(struct lpt_data)); |
memset(d, 0, sizeof(struct lpt_data)); |
121 |
d->irqnr = devinit->irq_nr; |
|
122 |
|
INTERRUPT_CONNECT(devinit->interrupt_path, d->irq); |
123 |
|
|
124 |
d->name = devinit->name2 != NULL? devinit->name2 : ""; |
d->name = devinit->name2 != NULL? devinit->name2 : ""; |
125 |
d->console_handle = console_start_slave(devinit->machine, devinit->name, |
d->console_handle = console_start_slave(devinit->machine, devinit->name, |
126 |
CONSOLE_OUTPUT_ONLY); |
CONSOLE_OUTPUT_ONLY); |
128 |
nlen = strlen(devinit->name) + 10; |
nlen = strlen(devinit->name) + 10; |
129 |
if (devinit->name2 != NULL) |
if (devinit->name2 != NULL) |
130 |
nlen += strlen(devinit->name2); |
nlen += strlen(devinit->name2); |
131 |
name = malloc(nlen); |
CHECK_ALLOCATION(name = malloc(nlen)); |
|
if (name == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
132 |
if (devinit->name2 != NULL && devinit->name2[0]) |
if (devinit->name2 != NULL && devinit->name2[0]) |
133 |
snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2); |
snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2); |
134 |
else |
else |
137 |
memory_device_register(devinit->machine->memory, name, devinit->addr, |
memory_device_register(devinit->machine->memory, name, devinit->addr, |
138 |
DEV_LPT_LENGTH, dev_lpt_access, d, DM_DEFAULT, NULL); |
DEV_LPT_LENGTH, dev_lpt_access, d, DM_DEFAULT, NULL); |
139 |
machine_add_tickfunction(devinit->machine, dev_lpt_tick, d, |
machine_add_tickfunction(devinit->machine, dev_lpt_tick, d, |
140 |
TICK_SHIFT, 0.0); |
TICK_SHIFT); |
141 |
|
|
142 |
/* |
/* |
143 |
* NOTE: Ugly cast into a pointer, because this is a convenient way |
* NOTE: Ugly cast into a pointer, because this is a convenient way |