dev_lpt.cc Source File
Back to the index.
src
devices
dev_lpt.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2005-2009 Anders Gavare. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
*
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* 3. The name of the author may not be used to endorse or promote products
13
* derived from this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*
27
*
28
* COMMENT: LPT (parallel printer) controller
29
*/
30
31
#include <stdio.h>
32
#include <stdlib.h>
33
#include <string.h>
34
35
#include "
console.h
"
36
#include "
cpu.h
"
37
#include "
device.h
"
38
#include "
interrupt.h
"
39
#include "
machine.h
"
40
#include "
memory.h
"
41
#include "
misc.h
"
42
43
#include "
thirdparty/lptreg.h
"
44
45
46
/* #define debug fatal */
47
48
#define TICK_SHIFT 18
49
#define DEV_LPT_LENGTH 3
50
51
struct
lpt_data
{
52
const
char
*
name
;
53
struct
interrupt
irq
;
54
int
console_handle
;
55
56
uint8_t
data
;
57
uint8_t
control
;
58
};
59
60
61
DEVICE_TICK
(lpt)
62
{
63
/* struct lpt_data *d = extra; */
64
65
/* TODO */
66
}
67
68
69
DEVICE_ACCESS
(lpt)
70
{
71
uint64_t idata = 0, odata=0;
72
struct
lpt_data
*d = (
struct
lpt_data
*) extra;
73
74
if
(writeflag ==
MEM_WRITE
)
75
idata =
memory_readmax64
(
cpu
,
data
, len);
76
77
switch
(relative_addr) {
78
79
case
LPT_DATA
:
80
if
(writeflag ==
MEM_READ
)
81
odata = d->
data
;
82
else
83
d->
data
= idata;
84
break
;
85
86
case
LPT_STATUS
:
87
odata =
LPS_NBSY
|
LPS_NACK
|
LPS_SELECT
|
LPS_NERR
;
88
break
;
89
90
case
LPT_CONTROL
:
91
if
(writeflag ==
MEM_WRITE
) {
92
if
(idata != d->
control
) {
93
if
(idata &
LPC_STROBE
) {
94
/* data strobe */
95
console_putchar
(d->
console_handle
,
96
d->
data
);
97
}
98
}
99
d->
control
= idata;
100
}
101
break
;
102
}
103
104
if
(writeflag ==
MEM_READ
)
105
memory_writemax64
(
cpu
,
data
, len, odata);
106
107
return
1;
108
}
109
110
111
DEVINIT
(lpt)
112
{
113
struct
lpt_data
*d;
114
size_t
nlen;
115
char
*
name
;
116
117
CHECK_ALLOCATION
(d = (
struct
lpt_data
*) malloc(
sizeof
(
struct
lpt_data
)));
118
memset(d, 0,
sizeof
(
struct
lpt_data
));
119
120
INTERRUPT_CONNECT
(
devinit
->
interrupt_path
, d->
irq
);
121
122
d->
name
=
devinit
->
name2
!= NULL?
devinit
->
name2
:
""
;
123
d->
console_handle
=
console_start_slave
(
devinit
->
machine
,
devinit
->
name
,
124
CONSOLE_OUTPUT_ONLY
);
125
126
nlen =
strlen
(
devinit
->
name
) + 10;
127
if
(
devinit
->
name2
!= NULL)
128
nlen +=
strlen
(
devinit
->
name2
);
129
CHECK_ALLOCATION
(
name
= (
char
*) malloc(nlen));
130
if
(
devinit
->
name2
!= NULL &&
devinit
->
name2
[0])
131
snprintf(
name
, nlen,
"%s [%s]"
,
devinit
->
name
,
devinit
->
name2
);
132
else
133
snprintf(
name
, nlen,
"%s"
,
devinit
->
name
);
134
135
memory_device_register
(
devinit
->
machine
->
memory
,
name
,
devinit
->
addr
,
136
DEV_LPT_LENGTH
, dev_lpt_access, d,
DM_DEFAULT
, NULL);
137
machine_add_tickfunction
(
devinit
->
machine
, dev_lpt_tick, d,
138
TICK_SHIFT
);
139
140
/*
141
* NOTE: Ugly cast into a pointer, because this is a convenient way
142
* to return the console handle to code in src/machine.c.
143
*/
144
devinit
->
return_ptr
= (
void
*)(
size_t
)d->
console_handle
;
145
146
return
1;
147
}
148
CONSOLE_OUTPUT_ONLY
#define CONSOLE_OUTPUT_ONLY
Definition:
console.h:39
data
u_short data
Definition:
siireg.h:79
lpt_data::data
uint8_t data
Definition:
dev_lpt.cc:56
console_putchar
void console_putchar(int handle, int ch)
Definition:
console.cc:410
INTERRUPT_CONNECT
#define INTERRUPT_CONNECT(name, istruct)
Definition:
interrupt.h:77
lpt_data::name
const char * name
Definition:
dev_lpt.cc:52
LPS_NBSY
#define LPS_NBSY
Definition:
lptreg.h:68
lpt_data::console_handle
int console_handle
Definition:
dev_lpt.cc:54
devinit::addr
uint64_t addr
Definition:
device.h:46
memory_device_register
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition:
memory.cc:339
DEVINIT
DEVINIT(lpt)
Definition:
dev_lpt.cc:111
MEM_READ
#define MEM_READ
Definition:
memory.h:116
LPT_DATA
#define LPT_DATA
Definition:
lptreg.h:61
DM_DEFAULT
#define DM_DEFAULT
Definition:
memory.h:130
devinit::machine
struct machine * machine
Definition:
device.h:41
console.h
TICK_SHIFT
#define TICK_SHIFT
Definition:
dev_lpt.cc:48
device.h
MEM_WRITE
#define MEM_WRITE
Definition:
memory.h:117
LPT_CONTROL
#define LPT_CONTROL
Definition:
lptreg.h:70
machine_add_tickfunction
void machine_add_tickfunction(struct machine *machine, void(*func)(struct cpu *, void *), void *extra, int clockshift)
Definition:
machine.cc:280
devinit::interrupt_path
char * interrupt_path
Definition:
device.h:50
strlen
void COMBINE() strlen(struct cpu *cpu, struct arm_instr_call *ic, int low_addr)
Definition:
cpu_arm_instr.cc:2686
interrupt.h
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition:
memory.cc:55
machine.h
devinit::name
char * name
Definition:
device.h:43
DEVICE_ACCESS
DEVICE_ACCESS(lpt)
Definition:
dev_lpt.cc:69
lpt_data
Definition:
dev_lpt.cc:51
LPC_STROBE
#define LPC_STROBE
Definition:
lptreg.h:71
devinit
Definition:
device.h:40
console_start_slave
int console_start_slave(struct machine *machine, const char *consolename, int use_for_input)
Definition:
console.cc:673
cpu.h
machine::memory
struct memory * memory
Definition:
machine.h:126
devinit::return_ptr
void * return_ptr
Definition:
device.h:56
lpt_data::irq
struct interrupt irq
Definition:
dev_lpt.cc:53
DEVICE_TICK
DEVICE_TICK(lpt)
Definition:
dev_lpt.cc:61
lptreg.h
lpt_data::control
uint8_t control
Definition:
dev_lpt.cc:57
interrupt
Definition:
interrupt.h:36
devinit::name2
char * name2
Definition:
device.h:44
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition:
memory.cc:89
LPS_NERR
#define LPS_NERR
Definition:
lptreg.h:64
cpu
Definition:
cpu.h:326
LPS_SELECT
#define LPS_SELECT
Definition:
lptreg.h:65
DEV_LPT_LENGTH
#define DEV_LPT_LENGTH
Definition:
dev_lpt.cc:49
LPT_STATUS
#define LPT_STATUS
Definition:
lptreg.h:63
memory.h
LPS_NACK
#define LPS_NACK
Definition:
lptreg.h:67
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition:
misc.h:239
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18