2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
11 #include <aros/libcall.h>
12 #include <exec/execbase.h>
13 #include <exec/devices.h>
16 #ifndef DEVICES_CONUNIT_H
17 # include <devices/conunit.h>
20 #ifndef INTUITION_CLASSES_H
21 # include <intuition/classes.h>
23 #ifndef EXEC_SEMAPHORES_H
24 # include <exec/semaphores.h>
31 #define COTASK_STACKSIZE (AROS_STACKSIZE + 4)
32 #define COTASK_PRIORITY 10
35 /* Minimum x & y char positions */
37 #define DEF_CHAR_XMIN 0
38 #define DEF_CHAR_YMIN 0
41 #define CHAR_XMIN(o) DEF_CHAR_XMIN
42 #define CHAR_YMIN(o) DEF_CHAR_YMIN
44 #define CHAR_XMAX(o) (CU(o)->cu_XMax)
45 #define CHAR_YMAX(o) (CU(o)->cu_YMax)
48 #define XCP (CU(o)->cu_XCP) /* Character X pos */
49 #define YCP (CU(o)->cu_YCP) /* Character Y pos */
51 #define XCCP (CU(o)->cu_XCCP) /* Cursor X pos */
52 #define YCCP (CU(o)->cu_YCCP) /* Cusror Y pos */
54 #define XRSIZE (CU(o)->cu_XRSize)
55 #define YRSIZE (CU(o)->cu_YRSize)
57 #define CP_X(o) (GFX_X(o, CU(o)->cu_XCCP))
58 #define CP_Y(o) (GFX_Y(o, CU(o)->cu_YCCP))
60 /* Macros that convert from char to gfx coords */
62 #define GFX_X(o, x) (CU(o)->cu_XROrigin + ((x) * CU(o)->cu_XRSize))
63 #define GFX_Y(o, y) (CU(o)->cu_YROrigin + ((y) * CU(o)->cu_YRSize))
65 #define GFX_XMIN(o) (GFX_X((o), CHAR_XMIN(o)))
66 #define GFX_YMIN(o) (GFX_Y((o), CHAR_YMIN(o)))
68 #define GFX_XMAX(o) ((GFX_X((o), CHAR_XMAX(o) + 1)) - 1)
69 #define GFX_YMAX(o) ((GFX_Y((o), CHAR_YMAX(o) + 1)) - 1)
71 /* Macros to set/reset/check rawevents */
73 #define SET_RAWEVENT(o, which) (CU(o)->cu_RawEvents[(which) / 8] |= (1 << ((which) & 7)))
74 #define RESET_RAWEVENT(o, which) (CU(o)->cu_RawEvents[(which) / 8] &= ~(1 << ((which) & 7)))
75 #define CHECK_RAWEVENT(o, which) (CU(o)->cu_RawEvents[(which) / 8] & (1 << ((which) & 7)))
77 #define SET_MODE(o, which) (CU(o)->cu_Modes[(which) / 8] |= (1 << ((which) & 7)))
78 #define CLEAR_MODE(o, which) (CU(o)->cu_Modes[(which) / 8] &= ~(1 << ((which) & 7)))
79 #define CHECK_MODE(o, which) (CU(o)->cu_Modes[(which) / 8] & (1 << ((which) & 7)))
81 #define CONSOLECLASSPTR (ConsoleDevice->consoleClass)
82 #define STDCONCLASSPTR (ConsoleDevice->stdConClass)
83 #define CHARMAPCLASSPTR (ConsoleDevice->charMapClass)
84 #define SNIPMAPCLASSPTR (ConsoleDevice->snipMapClass)
86 #define CU(x) ((struct ConUnit *)x)
88 #define ICU(x) ((struct intConUnit *)x)
90 #define WINDOW(o) CU(o)->cu_Window
91 #define RASTPORT(o) WINDOW(o)->RPort
94 #define MAX(a, b) ((a) > (b) ? a : b)
95 #define MIN(a, b) ((a) < (b) ? a : b)
97 /* Console write commands */
119 C_DEVICE_STATUS_REPORT
,
140 C_SELECT_GRAPHIC_RENDITION
,
149 C_RESET_AUTOWRAP_MODE
,
150 C_SET_AUTOSCROLL_MODE
,
151 C_RESET_AUTOSCROLL_MODE
,
168 struct ConsoleBase
*consoleDevice
;
169 struct Task
*parentTask
;
173 #define CON_INPUTBUF_SIZE 512
179 /* Buffer where characters received from the console input handler
182 UBYTE inputBuf
[CON_INPUTBUF_SIZE
];
183 /* Number of charcters currently stored in the buffer */
184 ULONG numStoredChars
;
189 #define CF_DELAYEDDISPOSE (1L << 0)
190 #define CF_DISPOSE (1L << 1)
193 /* Determining whether linefeed (LF==LF+CR) mode is on */
194 #define CF_LF_MODE_ON (1L << 2)
200 /* The unit that the user input should go to */
203 struct InputEvent ie
;
206 /* Data passed to the console device input handler */
210 struct ConsoleBase
*consoleDevice
;
211 /* Port to which we send input to the console device
212 from the console device input handler.
214 struct MsgPort
*inputPort
;
216 /* The port the console.device task replies to telling
217 the console.device input handler that it is finished
220 struct MsgPort
*cdihReplyPort
;
222 /* The message struct used to pass user input to the console device */
223 struct cdihMessage
*cdihMsg
;
234 struct Interrupt
*initCDIH(struct ConsoleBase
*ConsoleDevice
);
235 VOID
cleanupCDIH(struct Interrupt
*cdihandler
, struct ConsoleBase
*ConsoleDevice
);
237 VOID
consoleTaskEntry(struct ConsoleBase
*ConsoleDevice
);
239 struct Task
*createConsoleTask(APTR taskparams
, struct ConsoleBase
*ConsoleDevice
);
241 APTR
CreateCharMap(ULONG numchars
, struct ConsoleBase
*ConsoleDevice
);
242 VOID
FreeCharMap (APTR map
, struct ConsoleBase
*ConsoleDevice
);
243 ULONG
RewindChars (APTR map
, ULONG num
);
244 ULONG
ForwardChars (APTR map
, ULONG num
);
245 UBYTE
GetChar (APTR map
);
246 BOOL
NextChar (APTR map
, UBYTE
*char_ptr
);
247 BOOL
LastChar (APTR map
, UBYTE
*char_ptr
);
248 BOOL
InsertChar (APTR map
, UBYTE c
, struct ConsoleBase
*ConsoleDevice
);
251 ULONG
writeToConsole(struct ConUnit
*unit
, STRPTR buf
, ULONG towrite
252 , struct ConsoleBase
*ConsoleDevice
);
254 Class
*makeConsoleClass(struct ConsoleBase
*ConsoleDevice
);
255 Class
*makeStdConClass(struct ConsoleBase
*ConsoleDevice
);
258 VOID
printstring(STRPTR string
, ULONG len
, struct ConsoleBase
*ConsoleDevice
);
262 struct Device device
;
264 struct MinList unitList
;
265 struct SignalSemaphore unitListLock
;
266 struct SignalSemaphore consoleTaskLock
;
268 struct Interrupt
*inputHandler
;
269 struct Task
*consoleTask
;
270 struct MsgPort commandPort
;
272 /* Queued read requests */
273 struct MinList readRequests
;
281 /* The following typedefs are necessary, because the names of the global
282 variables storing the library base pointers and the corresponding
284 This is a hack, of course. */
285 typedef struct GfxBase GraphicsBase
;
286 typedef struct IntuitionBase IntuiBase
;
289 __AROS_LC0(BPTR, expunge, struct ConsoleBase *, ConsoleDevice, 3, Console)
293 #define CB(x) ((struct ConsoleBase *)x)
295 #endif /* CONSOLE_GCC_H */