added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / devs / console / console_gcc.h
blob442a213b688e276a0d9f38e4124b4a47c3a7d969
1 /*
2 Copyright © 1995-2006, 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 <dos/dos.h>
16 #ifndef DEVICES_CONUNIT_H
17 # include <devices/conunit.h>
18 #endif
20 #ifndef INTUITION_CLASSES_H
21 # include <intuition/classes.h>
22 #endif
23 #ifndef EXEC_SEMAPHORES_H
24 # include <exec/semaphores.h>
25 #endif
27 /* Predeclaration */
28 struct ConsoleBase;
30 /* Constants */
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 */
98 enum
100 C_ASCII = 0,
102 C_ESC,
103 C_BELL,
104 C_BACKSPACE,
105 C_HTAB,
106 C_LINEFEED,
107 C_VTAB,
108 C_FORMFEED,
109 C_CARRIAGE_RETURN,
110 C_SHIFT_IN,
111 C_SHIFT_OUT,
112 C_INDEX,
113 C_NEXT_LINE,
114 C_H_TAB_SET,
115 C_REVERSE_IDX,
117 C_SET_LF_MODE,
118 C_RESET_LF_MODE,
119 C_DEVICE_STATUS_REPORT,
121 C_INSERT_CHAR,
122 C_CURSOR_UP,
123 C_CURSOR_DOWN,
124 C_CURSOR_FORWARD,
125 C_CURSOR_BACKWARD,
126 C_CURSOR_NEXT_LINE,
127 C_CURSOR_PREV_LINE,
128 C_CURSOR_POS,
129 C_CURSOR_HTAB,
130 C_ERASE_IN_DISPLAY,
131 C_ERASE_IN_LINE,
132 C_INSERT_LINE,
133 C_DELETE_LINE,
134 C_DELETE_CHAR,
135 C_SCROLL_UP,
136 C_SCROLL_DOWN,
137 C_CURSOR_TAB_CTRL,
138 C_CURSOR_BACKTAB,
140 C_SELECT_GRAPHIC_RENDITION,
142 C_CURSOR_VISIBLE,
143 C_CURSOR_INVISIBLE,
145 C_SET_RAWEVENTS,
146 C_RESET_RAWEVENTS,
148 C_SET_AUTOWRAP_MODE,
149 C_RESET_AUTOWRAP_MODE,
150 C_SET_AUTOSCROLL_MODE,
151 C_RESET_AUTOSCROLL_MODE,
152 C_SET_PAGE_LENGTH,
153 C_SET_LINE_LENGTH,
154 C_SET_LEFT_OFFSET,
155 C_SET_TOP_OFFSET,
157 C_ASCII_STRING,
159 NUM_CONSOLE_COMMANDS
162 /**************
163 ** structs **
164 **************/
166 struct coTaskParams
168 struct ConsoleBase *consoleDevice;
169 struct Task *parentTask;
170 ULONG initSignal;
173 #define CON_INPUTBUF_SIZE 512
174 struct intConUnit
176 struct ConUnit unit;
177 ULONG conFlags;
179 /* Buffer where characters received from the console input handler
180 will be stored
182 UBYTE inputBuf[CON_INPUTBUF_SIZE];
183 /* Number of charcters currently stored in the buffer */
184 ULONG numStoredChars;
188 /* The conFlags */
189 #define CF_DELAYEDDISPOSE (1L << 0)
190 #define CF_DISPOSE (1L << 1)
192 #if 0
193 /* Determining whether linefeed (LF==LF+CR) mode is on */
194 #define CF_LF_MODE_ON (1L << 2)
195 #endif
197 struct cdihMessage
199 struct Message msg;
200 /* The unit that the user input should go to */
201 Object *unit;
203 struct InputEvent ie;
206 /* Data passed to the console device input handler */
208 struct cdihData
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
218 with the output.
220 struct MsgPort *cdihReplyPort;
222 /* The message struct used to pass user input to the console device */
223 struct cdihMessage *cdihMsg;
230 /*****************
231 ** Prototypes **
232 *****************/
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);
250 /* Prototypes */
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);
260 struct ConsoleBase
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;
275 Class *consoleClass;
276 Class *stdConClass;
277 Class *charMapClass;
278 Class *snipMapClass;
281 /* The following typedefs are necessary, because the names of the global
282 variables storing the library base pointers and the corresponding
283 structs are equal.
284 This is a hack, of course. */
285 typedef struct GfxBase GraphicsBase;
286 typedef struct IntuitionBase IntuiBase;
288 #define expunge() \
289 __AROS_LC0(BPTR, expunge, struct ConsoleBase *, ConsoleDevice, 3, Console)
292 #undef CB
293 #define CB(x) ((struct ConsoleBase *)x)
295 #endif /* CONSOLE_GCC_H */