2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
11 #include <aros/libcall.h>
12 #include <exec/execbase.h>
13 #include <exec/devices.h>
14 #include <exec/semaphores.h>
16 #include <devices/conunit.h>
17 #include <intuition/classes.h>
19 #include <proto/alib.h>
25 #define COTASK_STACKSIZE (AROS_STACKSIZE + 4)
26 #define COTASK_PRIORITY 10
29 /* Minimum x & y char positions */
31 #define DEF_CHAR_XMIN 0
32 #define DEF_CHAR_YMIN 0
35 #define CHAR_XMIN(o) DEF_CHAR_XMIN
36 #define CHAR_YMIN(o) DEF_CHAR_YMIN
38 #define CHAR_XMAX(o) (CU(o)->cu_XMax)
39 #define CHAR_YMAX(o) (CU(o)->cu_YMax)
42 #define XCP (CU(o)->cu_XCP) /* Character X pos */
43 #define YCP (CU(o)->cu_YCP) /* Character Y pos */
45 #define XCCP (CU(o)->cu_XCCP) /* Cursor X pos */
46 #define YCCP (CU(o)->cu_YCCP) /* Cusror Y pos */
48 #define XRSIZE (CU(o)->cu_XRSize)
49 #define YRSIZE (CU(o)->cu_YRSize)
51 #define CP_X(o) (GFX_X(o, CU(o)->cu_XCCP))
52 #define CP_Y(o) (GFX_Y(o, CU(o)->cu_YCCP))
54 /* Macros that convert from char to gfx coords */
56 #define GFX_X(o, x) (CU(o)->cu_XROrigin + ((x) * CU(o)->cu_XRSize))
57 #define GFX_Y(o, y) (CU(o)->cu_YROrigin + ((y) * CU(o)->cu_YRSize))
59 #define GFX_XMIN(o) (GFX_X((o), CHAR_XMIN(o)))
60 #define GFX_YMIN(o) (GFX_Y((o), CHAR_YMIN(o)))
62 #define GFX_XMAX(o) ((GFX_X((o), CHAR_XMAX(o) + 1)) - 1)
63 #define GFX_YMAX(o) ((GFX_Y((o), CHAR_YMAX(o) + 1)) - 1)
65 /* Macros to set/reset/check rawevents */
67 #define SET_RAWEVENT(o, which) (CU(o)->cu_RawEvents[(which) / 8] |= (1 << ((which) & 7)))
68 #define RESET_RAWEVENT(o, which) (CU(o)->cu_RawEvents[(which) / 8] &= ~(1 << ((which) & 7)))
69 #define CHECK_RAWEVENT(o, which) (CU(o)->cu_RawEvents[(which) / 8] & (1 << ((which) & 7)))
71 #define SET_MODE(o, which) (CU(o)->cu_Modes[(which) / 8] |= (1 << ((which) & 7)))
72 #define CLEAR_MODE(o, which) (CU(o)->cu_Modes[(which) / 8] &= ~(1 << ((which) & 7)))
73 #define CHECK_MODE(o, which) (CU(o)->cu_Modes[(which) / 8] & (1 << ((which) & 7)))
75 #define CONSOLECLASSPTR (ConsoleDevice->consoleClass)
76 #define STDCONCLASSPTR (ConsoleDevice->stdConClass)
77 #define CHARMAPCLASSPTR (ConsoleDevice->charMapClass)
78 #define SNIPMAPCLASSPTR (ConsoleDevice->snipMapClass)
80 #define CU(x) ((struct ConUnit *)x)
82 #define ICU(x) ((struct intConUnit *)x)
84 #define WINDOW(o) CU(o)->cu_Window
85 #define RASTPORT(o) WINDOW(o)->RPort
88 #define MAX(a, b) ((a) > (b) ? a : b)
89 #define MIN(a, b) ((a) < (b) ? a : b)
92 #define CON_TXTFLAGS_MASK (FSF_BOLD | FSF_ITALIC | FSF_UNDERLINED)
93 #define CON_TXTFLAGS_BOLD FSF_BOLD
94 #define CON_TXTFLAGS_ITALIC FSF_ITALIC
95 #define CON_TXTFLAGS_UNDERLINED FSF_UNDERLINED
96 #define CON_TXTFLAGS_REVERSED 0x08
97 #define CON_TXTFLAGS_CONCEALED 0x10
99 /* Console write commands */
122 C_DEVICE_STATUS_REPORT
,
143 C_SELECT_GRAPHIC_RENDITION
,
144 C_WINDOW_STATUS_REQUEST
,
153 C_RESET_AUTOWRAP_MODE
,
154 C_SET_AUTOSCROLL_MODE
,
155 C_RESET_AUTOSCROLL_MODE
,
172 struct ConsoleBase
*consoleDevice
;
173 struct Task
*parentTask
;
180 struct intConUnit
*unit
;
182 ULONG pasteBufferSize
;
185 #define CON_INPUTBUF_SIZE 512
191 /* Buffer where characters received from the console input handler
194 UBYTE inputBuf
[CON_INPUTBUF_SIZE
];
195 /* Number of charcters currently stored in the buffer */
196 ULONG numStoredChars
;
198 /* Data to be copied into the inputBuf for processing */
199 struct MinList pasteData
;
201 /* Position in the first pasteData element */
202 ULONG pasteBufferPos
;
206 #define CF_DELAYEDDISPOSE (1L << 0)
207 #define CF_DISPOSE (1L << 1)
210 /* Determining whether linefeed (LF==LF+CR) mode is on */
211 #define CF_LF_MODE_ON (1L << 2)
217 /* The unit that the user input should go to */
220 struct InputEvent ie
;
223 /* Data passed to the console device input handler */
227 struct ConsoleBase
*consoleDevice
;
228 /* Port to which we send input to the console device
229 from the console device input handler.
231 struct MsgPort
*inputPort
;
233 /* The port the console.device task replies to telling
234 the console.device input handler that it is finished
237 struct MsgPort
*cdihReplyPort
;
239 /* The message struct used to pass user input to the console device */
240 struct cdihMessage
*cdihMsg
;
249 struct Interrupt
*initCDIH(struct ConsoleBase
*ConsoleDevice
);
250 VOID
cleanupCDIH(struct Interrupt
*cdihandler
,
251 struct ConsoleBase
*ConsoleDevice
);
253 VOID
consoleTaskEntry(struct ConsoleBase
*ConsoleDevice
);
255 struct Task
*createConsoleTask(APTR taskparams
,
256 struct ConsoleBase
*ConsoleDevice
);
259 ULONG
writeToConsole(struct ConUnit
*unit
, STRPTR buf
, ULONG towrite
,
260 struct ConsoleBase
*ConsoleDevice
);
262 Class
*makeConsoleClass(struct ConsoleBase
*ConsoleDevice
);
263 Class
*makeStdConClass(struct ConsoleBase
*ConsoleDevice
);
264 Class
*makeCharMapConClass(struct ConsoleBase
*ConsoleDevice
);
265 Class
*makeSnipMapConClass(struct ConsoleBase
*ConsoleDevice
);
267 VOID
con_inject(struct ConsoleBase
*ConsoleDevice
, struct ConUnit
*cu
,
268 const UBYTE
*data
, LONG size
);
270 VOID
printstring(STRPTR string
, ULONG len
,
271 struct ConsoleBase
*ConsoleDevice
);
273 VOID
setabpen(struct Library
*GfxBase
, struct RastPort
*rp
, UBYTE tflags
,
274 UBYTE FgPen
, UBYTE BgPen
);
278 struct Device device
;
280 struct MinList unitList
;
281 struct SignalSemaphore unitListLock
;
282 struct SignalSemaphore consoleTaskLock
;
284 struct Interrupt
*inputHandler
;
285 struct Task
*consoleTask
;
286 struct MsgPort
*commandPort
;
288 /* Queued read requests */
289 struct MinList readRequests
;
298 This buffer is shared across all console units. It is used by
299 conunits of type CONU_SNIPMAP to provide built in copy/paste.
301 If ConClip is running, this buffer is passed to ConClip on copy,
302 and is not used on Paste. Instead, <CSI> 0 v (Hex 9B 30 20 76)
303 is put into the console units input buffer to signal to the app
304 (console handler or otherwise) to paste.
306 Access to the copyBuffer is protected by a semaphore.
308 const char *copyBuffer
;
309 ULONG copyBufferSize
;
310 struct SignalSemaphore copyBufferLock
;
311 struct MinList sniphooks
;
313 struct Library
*cb_IntuitionBase
;
314 struct Library
*cb_KeymapBase
;
318 #define CB(x) ((struct ConsoleBase *)x)
321 #define IntuitionBase (((const struct ConsoleBase *)ConsoleDevice)->cb_IntuitionBase)
324 #define KeymapBase (((const struct ConsoleBase *)ConsoleDevice)->cb_KeymapBase)
326 #endif /* CONSOLE_GCC_H */