1 /* $Id: console.c,v 1.1.1.1 2000/06/27 01:48:00 amura Exp $ */
2 /*
3  * These functions are taken directly from the
4  * console.device chapter in the Amiga V1.1
5  * ROM Kernel Manual.
6  */
7 
8 /*
9  * $Log: console.c,v $
10  * Revision 1.1.1.1  2000/06/27 01:48:00  amura
11  * import to CVS
12  *
13  */
14 
15 #include <exec/types.h>
16 #include <exec/io.h>
17 #include <devices/console.h>
18 #include <libraries/dos.h>
19 #include <intuition/intuition.h>
20 
21 #include	"config.h"	/* Dec. 15, 1992 by H.Ohkubo */
22 #ifdef	KANJI	/* Dec.27,1992 Add by H.Ohkubo */
23 #define	READBUF	64
24 static	UBYTE	getbuf[READBUF];
25 #endif
26 
27 extern	LONG	OpenDevice();
28 extern	LONG	DoIO();
29 extern	LONG	SendIO();
30 
31 /*
32  * Open a console device, given a read request
33  * and a write request message.
34  */
35 
OpenConsole(writerequest,readrequest,window)36 int OpenConsole(writerequest,readrequest,window)
37 struct IOStdReq *writerequest;
38 struct IOStdReq *readrequest;
39 struct Window *window;
40 {
41 	LONG error;
42 	writerequest->io_Data = (APTR) window;
43 	writerequest->io_Length = (ULONG) sizeof(*window);
44 	error = OpenDevice("console.device", 0L, writerequest, 0L);
45 
46 	/* clone required parts of the request */
47 	if (readrequest) {
48 		readrequest->io_Device = writerequest->io_Device;
49 		readrequest->io_Unit   = writerequest->io_Unit;
50 #ifdef	KANJI	/* Dec.19,1992 Add by H.Ohkubo */
51 		QueueRead(readrequest, getbuf);
52 #endif
53 	}
54 	return((int) error);
55 }
56 
57 #ifndef	BUGFIX	/* Dec.26,1992 by H.Ohkubo */
58 /*
59  * Output a single character
60  * to a specified console
61  */
62 
ConPutChar(request,character)63 int ConPutChar(request,character)
64 struct IOStdReq *request;
65 char character;
66 {
67 #ifdef	V11
68 	register int x;
69 #endif
70 	request->io_Command = CMD_WRITE;
71 	request->io_Data = (APTR)&character;
72 	request->io_Length = (ULONG)1;
73 	DoIO(request);
74 	/* caution: read comments in manual! */
75 	return(0);
76 }
77 
78 /*
79  * Output a NULL-terminated string of
80  * characters to a console
81  */
82 
ConPutStr(request,string)83 int ConPutStr(request,string)
84 struct IOStdReq *request;
85 char *string;
86 {
87 #ifdef	V11
88 	register int x;
89 #endif
90 	request->io_Command = CMD_WRITE;
91 	request->io_Data = (APTR)string;
92 	request->io_Length = (LONG)-1;
93 	DoIO(request);
94 	return(0);
95 }
96 #endif	/* BUGFIX */
97 /*
98  * Write out a string of predetermined
99  * length to the console
100  */
101 
ConWrite(request,string,len)102 int ConWrite(request,string,len)
103 struct IOStdReq *request;
104 char *string;
105 int len;
106 {
107 #ifdef	V11
108 	register int x;
109 #endif
110 	request->io_Command = CMD_WRITE;
111 	request->io_Data = (APTR)string;
112 	request->io_Length = (LONG)len;
113 	DoIO(request);
114 	return(0);
115 }
116 
117 /*
118  * Queue up a read request
119  * to a console
120  */
121 
QueueRead(request,whereto)122 int QueueRead(request,whereto)
123 struct IOStdReq *request;
124 char *whereto;
125 {
126 #ifdef	V11
127 	register int x;
128 #endif
129 	request->io_Command = CMD_READ;
130 	request->io_Data = (APTR)whereto;
131 #ifdef	KANJI	/* Dec.27,1992 by H.Ohkubo */
132 	request->io_Length = (LONG)READBUF;
133 #else	/* ORIGINAL Code */
134 	request->io_Length = (LONG)1;
135 #endif	/* KANJI */
136 	SendIO(request);
137 	return(0);
138 }
139 
140 #ifdef	KANJI	/* Dec.27,1992 Add by H.Ohkubo */
ConRead(mport,n)141 UBYTE	*ConRead(mport, n)
142 struct	MsgPort	*mport;
143 int	*n;
144 {
145 	static UBYTE	readbuf[READBUF];
146 	register UBYTE	*p;
147 	register struct IOStdReq *readreq;
148 
149 	p = readbuf;
150 	if (readreq = (struct IOStdReq *)GetMsg(mport)) {
151 		memcpy(p, getbuf, readreq->io_Actual);
152 		p += (*n = readreq->io_Actual);
153 		QueueRead(readreq, getbuf);
154 	}
155 	return readbuf;
156 }
157 #endif
158