2 Copyright © 1995-2011, 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
;
251 struct Interrupt
*initCDIH(struct ConsoleBase
*ConsoleDevice
);
252 VOID
cleanupCDIH(struct Interrupt
*cdihandler
, struct ConsoleBase
*ConsoleDevice
);
254 VOID
consoleTaskEntry(struct ConsoleBase
*ConsoleDevice
);
256 struct Task
*createConsoleTask(APTR taskparams
, 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
, const UBYTE
*data
, LONG size
);
269 VOID
printstring(STRPTR string
, ULONG len
, struct ConsoleBase
*ConsoleDevice
);
271 VOID
setabpen(struct Library
*GfxBase
, struct RastPort
*rp
, UBYTE tflags
, UBYTE FgPen
, UBYTE BgPen
);
275 struct Device device
;
277 struct MinList unitList
;
278 struct SignalSemaphore unitListLock
;
279 struct SignalSemaphore consoleTaskLock
;
281 struct Interrupt
*inputHandler
;
282 struct Task
*consoleTask
;
283 struct MsgPort
*commandPort
;
285 /* Queued read requests */
286 struct MinList readRequests
;
295 This buffer is shared across all console units. It is used by
296 conunits of type CONU_SNIPMAP to provide built in copy/paste.
298 If ConClip is running, this buffer is passed to ConClip on copy,
299 and is not used on Paste. Instead, <CSI> 0 v (Hex 9B 30 20 76)
300 is put into the console units input buffer to signal to the app
301 (console handler or otherwise) to paste.
303 Access to the copyBuffer is protected by a semaphore.
305 const char * copyBuffer
;
306 ULONG copyBufferSize
;
307 struct SignalSemaphore copyBufferLock
;
308 struct MinList sniphooks
;
310 struct Library
*cb_IntuitionBase
;
311 struct Library
*cb_KeymapBase
;
315 #define CB(x) ((struct ConsoleBase *)x)
318 #define IntuitionBase (((const struct ConsoleBase *)ConsoleDevice)->cb_IntuitionBase)
321 #define KeymapBase (((const struct ConsoleBase *)ConsoleDevice)->cb_KeymapBase)
323 #endif /* CONSOLE_GCC_H */