Tabs to spaces; more consistent formatting.
[AROS.git] / rom / devs / console / console_gcc.h
blob4e0dd9b345bc16c29e6cbbc9096a87067d1ab8da
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang:
7 */
8 #ifndef CONSOLE_GCC_H
9 #define CONSOLE_GCC_H
11 #include <aros/libcall.h>
12 #include <exec/execbase.h>
13 #include <exec/devices.h>
14 #include <exec/semaphores.h>
15 #include <dos/dos.h>
16 #include <devices/conunit.h>
17 #include <intuition/classes.h>
19 #include <proto/alib.h>
21 /* Predeclaration */
22 struct ConsoleBase;
24 /* Constants */
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 */
100 enum
102 C_NIL = 0,
104 C_ASCII,
105 C_ESC,
106 C_BELL,
107 C_BACKSPACE,
108 C_HTAB,
109 C_LINEFEED,
110 C_VTAB,
111 C_FORMFEED,
112 C_CARRIAGE_RETURN,
113 C_SHIFT_IN,
114 C_SHIFT_OUT,
115 C_INDEX,
116 C_NEXT_LINE,
117 C_H_TAB_SET,
118 C_REVERSE_IDX,
120 C_SET_LF_MODE,
121 C_RESET_LF_MODE,
122 C_DEVICE_STATUS_REPORT,
124 C_INSERT_CHAR,
125 C_CURSOR_UP,
126 C_CURSOR_DOWN,
127 C_CURSOR_FORWARD,
128 C_CURSOR_BACKWARD,
129 C_CURSOR_NEXT_LINE,
130 C_CURSOR_PREV_LINE,
131 C_CURSOR_POS,
132 C_CURSOR_HTAB,
133 C_ERASE_IN_DISPLAY,
134 C_ERASE_IN_LINE,
135 C_INSERT_LINE,
136 C_DELETE_LINE,
137 C_DELETE_CHAR,
138 C_SCROLL_UP,
139 C_SCROLL_DOWN,
140 C_CURSOR_TAB_CTRL,
141 C_CURSOR_BACKTAB,
143 C_SELECT_GRAPHIC_RENDITION,
144 C_WINDOW_STATUS_REQUEST,
146 C_CURSOR_VISIBLE,
147 C_CURSOR_INVISIBLE,
149 C_SET_RAWEVENTS,
150 C_RESET_RAWEVENTS,
152 C_SET_AUTOWRAP_MODE,
153 C_RESET_AUTOWRAP_MODE,
154 C_SET_AUTOSCROLL_MODE,
155 C_RESET_AUTOSCROLL_MODE,
156 C_SET_PAGE_LENGTH,
157 C_SET_LINE_LENGTH,
158 C_SET_LEFT_OFFSET,
159 C_SET_TOP_OFFSET,
161 C_ASCII_STRING,
163 NUM_CONSOLE_COMMANDS
166 /**************
167 ** structs **
168 **************/
170 struct coTaskParams
172 struct ConsoleBase *consoleDevice;
173 struct Task *parentTask;
174 ULONG initSignal;
177 struct intPasteData
179 struct MinNode node;
180 struct intConUnit *unit;
181 STRPTR pasteBuffer;
182 ULONG pasteBufferSize;
185 #define CON_INPUTBUF_SIZE 512
186 struct intConUnit
188 struct ConUnit unit;
189 ULONG conFlags;
191 /* Buffer where characters received from the console input handler
192 will be stored
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;
205 /* The conFlags */
206 #define CF_DELAYEDDISPOSE (1L << 0)
207 #define CF_DISPOSE (1L << 1)
209 #if 0
210 /* Determining whether linefeed (LF==LF+CR) mode is on */
211 #define CF_LF_MODE_ON (1L << 2)
212 #endif
214 struct cdihMessage
216 struct Message msg;
217 /* The unit that the user input should go to */
218 Object *unit;
220 struct InputEvent ie;
223 /* Data passed to the console device input handler */
225 struct cdihData
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
235 with the output.
237 struct MsgPort *cdihReplyPort;
239 /* The message struct used to pass user input to the console device */
240 struct cdihMessage *cdihMsg;
245 /*****************
246 ** Prototypes **
247 *****************/
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);
258 /* Prototypes */
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);
276 struct ConsoleBase
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;
291 Class *consoleClass;
292 Class *stdConClass;
293 Class *charMapClass;
294 Class *snipMapClass;
296 /* Copy buffer
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;
317 #undef CB
318 #define CB(x) ((struct ConsoleBase *)x)
320 #undef IntuitionBase
321 #define IntuitionBase (((const struct ConsoleBase *)ConsoleDevice)->cb_IntuitionBase)
323 #undef KeymapBase
324 #define KeymapBase (((const struct ConsoleBase *)ConsoleDevice)->cb_KeymapBase)
326 #endif /* CONSOLE_GCC_H */