Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / devs / console / consoleclass.c
blobd345a0bea5f8410f784d5f03bad2171ca133ecad
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Base class for console units
6 Lang: english
7 */
9 #include <string.h>
11 #include <proto/intuition.h>
12 #include <proto/utility.h>
13 #include <aros/asmcall.h>
14 #include <devices/conunit.h>
15 #include <intuition/classes.h>
16 #include <intuition/intuition.h>
18 #define SDEBUG 0
19 #define DEBUG 0
20 #include <aros/debug.h>
22 #include "consoleif.h"
23 #include "console_gcc.h"
27 VOID normalizecoords(Object *o, WORD *x_ptr, WORD *y_ptr);
30 Base class for the classes handling standard, charmap and snipmap
31 consoles. This is a whitebox base class (like GADGETCLASS), which means subclasses
32 can have direct access to its instance data.
35 struct consoledata
37 struct intConUnit intunit;
41 #undef ConsoleDevice
42 #define ConsoleDevice ((struct ConsoleBase *)cl->cl_UserData)
45 /*********************
46 ** Console::New() **
47 *********************/
48 static Object *console_new(Class *cl, Object *o, struct opSet *msg)
50 struct Window *win;
51 EnterFunc(bug("Console::New()\n"));
53 /* Get console window */
54 win = (struct Window *)GetTagData(A_Console_Window, 0, msg->ops_AttrList);
55 if (!win)
56 ReturnPtr ("Console::New", Object *, NULL);
58 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
59 if (o)
61 struct ConUnit *unit;
62 struct consoledata *data;
63 struct RastPort *rp = win->RPort;
64 WORD i;
66 data = INST_DATA(cl, o);
68 unit = (struct ConUnit *)data;
70 memset(data, 0, sizeof(struct consoledata));
72 /* Initialize the unit fields */
73 unit->cu_Window = win;
76 /* For now one should use only non-proportional fonts */
77 unit->cu_XRSize = rp->Font->tf_XSize;
78 unit->cu_YRSize = rp->Font->tf_YSize;
80 D(bug("cu_XRSize: %d, cu_YRSize: %d\n",
81 unit->cu_XRSize, unit->cu_YRSize));
83 /* Use whole window for console. */
84 unit->cu_XMax = (win->Width - (win->BorderLeft + win->BorderRight )) / unit->cu_XRSize - 1;
85 unit->cu_YMax = (win->Height - (win->BorderTop + win->BorderBottom)) / unit->cu_YRSize - 1;
87 unit->cu_XROrigin = win->BorderLeft;
88 unit->cu_YROrigin = win->BorderTop;
90 D(bug("cu_XROrigin: %d, cu_YROrigin: %d\n",
91 unit->cu_XROrigin, unit->cu_YROrigin));
93 unit->cu_XRExtant = win->BorderLeft + (unit->cu_XRSize * (unit->cu_XMax + 1) - 1);
94 unit->cu_YRExtant = win->BorderTop + (unit->cu_YRSize * (unit->cu_YMax + 1) - 1);
96 unit->cu_XCP = DEF_CHAR_XMIN;
97 unit->cu_YCP = DEF_CHAR_YMIN;
99 unit->cu_XCCP = DEF_CHAR_XMIN;
100 unit->cu_YCCP = DEF_CHAR_YMIN;
102 for(i = 0; i < MAXTABS - 1; i++)
104 unit->cu_TabStops[i] = i * 8;
106 unit->cu_TabStops[i] = (UWORD)-1;
108 ICU(o)->conFlags = 0UL;
109 ICU(o)->numStoredChars = 0;
111 SET_MODE(o, PMB_ASM); /* auto-scroll-mode ON */
112 SET_MODE(o, PMB_AWM); /* auto-wrap-mode ON */
114 /* RKM: Default mode is SET */
115 SET_MODE(o, M_LNM); /* linefeed mode = linefeed+carriage return */
118 ReturnPtr("Console::New", Object *, o);
123 /**********************
124 ** Console::Left() **
125 **********************/
126 static VOID console_left(Class *cl, Object *o, struct P_Console_Left *msg)
128 WORD newx;
130 EnterFunc(bug("Console::Left()\n"));
132 newx = XCCP - msg->Num;
134 if (CHECK_MODE(o, PMB_AWM))
136 WORD scrollcount = 0;
138 while(newx < CHAR_XMIN(o))
140 newx += (CHAR_XMAX(o) + 1);
141 scrollcount++;
144 XCP = XCCP = newx;
146 Console_Up(o, scrollcount);
149 else
151 if (newx < CHAR_XMIN(o)) newx = CHAR_XMIN(o);
154 XCP = XCCP = newx; /* XCP always same as XCCP?? */
156 D(bug("XCP=%d, XCCP=%d\n", XCP, XCCP));
158 ReturnVoid("Console::Left");
161 /***********************
162 ** Console::Right() **
163 ***********************/
164 static VOID console_right(Class *cl, Object *o, struct P_Console_Right *msg)
166 WORD newx;
168 EnterFunc(bug("Console::Right()\n"));
170 newx = XCCP + msg->Num;
172 if (CHECK_MODE(o, PMB_AWM))
174 WORD scrollcount = 0;
176 while(newx > CHAR_XMAX(o))
178 newx -= (CHAR_XMAX(o) + 1);
179 scrollcount++;
182 XCP = XCCP = newx;
184 Console_Down(o, scrollcount);
187 else
189 if (newx > CHAR_XMAX(o)) newx = CHAR_XMAX(o);
192 XCP = XCCP = newx; /* XCP always same as XCCP?? */
194 D(bug("XCP=%d, XCCP=%d\n", XCP, XCCP));
196 ReturnVoid("Console::Right");
199 /********************
200 ** Console::Up() **
201 ********************/
202 static VOID console_up(Class *cl, Object *o, struct P_Console_Up *msg)
204 EnterFunc(bug("Console::Up(num=%d)\n", msg->Num));
206 YCCP -= msg->Num;
208 if (YCCP < 0)
210 if (CHECK_MODE(o, PMB_ASM))
212 IPTR scroll_param = -YCCP;
214 YCCP = YCP = 0;
215 Console_DoCommand(o, C_SCROLL_DOWN, 1, &scroll_param);
217 else
219 YCCP = 0;
222 YCP = YCCP; /* YCP always same as YCCP ?? */
224 D(bug("New coords: char (%d, %d), gfx (%d, %d)\n",
225 XCCP, YCCP, CP_X(o), CP_Y(o) ));
226 ReturnVoid("Console::Up");
231 /**********************
232 ** Console::Down() **
233 **********************/
234 static VOID console_down(Class *cl, Object *o, struct P_Console_Down *msg)
236 EnterFunc(bug("Console::Down(num=%d)\n", msg->Num));
238 YCCP += msg->Num;
240 if (YCCP > CHAR_YMAX(o))
242 if (CHECK_MODE(o, PMB_ASM))
244 IPTR scroll_param = YCCP - CHAR_YMAX(o);
246 YCCP = YCP = CHAR_YMAX(o);
247 Console_DoCommand(o, C_SCROLL_UP, 1, &scroll_param);
249 else
251 YCCP = CHAR_YMAX(o);
254 YCP = YCCP; /* YCP always same as YCCP ?? */
256 D(bug("New coords: char (%d, %d), gfx (%d, %d)\n",
257 XCCP, YCCP, CP_X(o), CP_Y(o) ));
258 ReturnVoid("Console::Down");
261 /***************************
262 ** Console::DoCommand() **
263 ***************************/
264 static VOID console_docommand(Class *cl, Object *o, struct P_Console_DoCommand *msg)
266 EnterFunc(bug("Console::DoCommand(cmd=%d)\n", msg->Command));
268 switch (msg->Command)
270 case C_SET_LF_MODE:
271 D(bug("Set LF mode ON\n"));
272 /* LF==LF+CR */
273 /* ICU(o)->conFlags |= CF_LF_MODE_ON ; */
274 SET_MODE(o, M_LNM);
275 break;
277 case C_RESET_LF_MODE:
278 /* LF==LF */
279 D(bug("Set LF mode OFF\n"));
280 /* ICU(o)->conFlags &= ~CF_LF_MODE_ON; */
281 CLEAR_MODE(o, M_LNM);
282 break;
284 case C_SET_AUTOSCROLL_MODE:
285 SET_MODE(o, PMB_ASM);
286 break;
288 case C_RESET_AUTOSCROLL_MODE:
289 CLEAR_MODE(o, PMB_ASM);
290 break;
292 case C_SET_AUTOWRAP_MODE:
293 SET_MODE(o, PMB_AWM);
294 break;
296 case C_RESET_AUTOWRAP_MODE:
297 CLEAR_MODE(o, PMB_AWM);
298 break;
300 case C_SELECT_GRAPHIC_RENDITION:
301 D(bug("Select graphic Rendition\n"));
303 UBYTE i, param;
305 for(i = 0; i < msg->NumParams; i++)
307 param = msg->Params[i];
309 switch(param)
311 case 30:
312 case 31:
313 case 32:
314 case 33:
315 case 34:
316 case 35:
317 case 36:
318 case 37:
319 CU(o)->cu_FgPen = param - 30;
320 break;
322 case 40:
323 case 41:
324 case 42:
325 case 43:
326 case 44:
327 case 45:
328 case 46:
329 case 47:
330 CU(o)->cu_BgPen = param - 40;
331 break;
333 } /* switch(param) */
335 } /* for(i = 0; i < msg->NumParams; i++) */
337 break;
340 case C_SET_RAWEVENTS:
341 D(bug("Set Raw Events\n"));
343 UBYTE i, param;
345 for(i = 0; i < msg->NumParams; i++)
347 param = msg->Params[i];
349 if (param <= IECLASS_MAX)
351 SET_RAWEVENT(o, param);
354 } /* for(i = 0; i < msg->NumParams; i++) */
356 break;
358 case C_RESET_RAWEVENTS:
359 D(bug("Set Raw Events\n"));
361 UBYTE i, param;
363 for(i = 0; i < msg->NumParams; i++)
365 param = msg->Params[i];
367 if (param <= IECLASS_MAX)
369 RESET_RAWEVENT(o, param);
372 } /* for(i = 0; i < msg->NumParams; i++) */
374 break;
376 } /* switch (msg->Command) */
378 ReturnVoid("Console::DoCommand");
381 /**********************************
382 ** Console::GetDefaultParams() **
383 **********************************/
384 static VOID console_getdefaultparams(Class *cl, Object *o, struct P_Console_GetDefaultParams *msg)
386 switch (msg->Command)
388 case C_INSERT_CHAR:
389 case C_CURSOR_UP:
390 case C_CURSOR_DOWN:
391 case C_CURSOR_FORWARD:
392 case C_CURSOR_BACKWARD:
393 case C_CURSOR_NEXT_LINE:
394 case C_CURSOR_PREV_LINE:
395 msg->Params[0] = 1;
396 break;
397 case C_CURSOR_POS:
398 msg->Params[0] = YCCP + 1;
399 msg->Params[1] = XCCP + 1;
400 break;
402 #warning Autodocs state commands in between here, has params RKRM: Devs saye the do not
403 case C_CURSOR_HTAB:
404 case C_DELETE_CHAR:
405 case C_SCROLL_UP:
406 case C_SCROLL_DOWN:
407 msg->Params[0] = 1;
408 break;
410 case C_CURSOR_TAB_CTRL:
411 msg->Params[0] = 0; /* set tab */
412 break;
415 case C_CURSOR_BACKTAB:
416 msg->Params[0] = 1;
417 break;
419 case C_SELECT_GRAPHIC_RENDITION:
420 /* don't do anything, as params may be in any order */
421 break;
423 case C_SET_RAWEVENTS:
424 /* don't do anything, as params may be in any order */
425 break;
427 case C_RESET_RAWEVENTS:
428 /* don't do anything, as params may be in any order */
429 break;
431 } /* switch (msg->Command) */
433 return;
436 /*******************************
437 ** Console::NewWindowSize() **
438 *******************************/
439 static VOID console_newwindowsize(Class *cl, Object *o, struct P_Console_NewWindowSize *msg)
441 struct ConUnit *unit;
442 struct consoledata *data;
443 struct Window *win;
445 data = INST_DATA(cl, o);
446 unit = (struct ConUnit *)data;
448 win = unit->cu_Window;
450 unit->cu_XMax = (win->Width - (win->BorderLeft + win->BorderRight )) / unit->cu_XRSize - 1;
451 unit->cu_YMax = (win->Height - (win->BorderTop + win->BorderBottom)) / unit->cu_YRSize - 1;
453 unit->cu_XRExtant = win->BorderLeft + (unit->cu_XRSize * (unit->cu_XMax + 1) - 1);
454 unit->cu_YRExtant = win->BorderTop + (unit->cu_YRSize * (unit->cu_YMax + 1) - 1);
456 if (unit->cu_XCCP > unit->cu_XMax) unit->cu_XCCP = unit->cu_XMax;
457 if (unit->cu_YCCP > unit->cu_YMax) unit->cu_YCCP = unit->cu_YMax;
459 unit->cu_XCP = unit->cu_XCCP;
460 unit->cu_YCP = unit->cu_YCCP;
462 return;
465 /********* Console class dispatcher **********************************/
466 AROS_UFH3S(IPTR, dispatch_consoleclass,
467 AROS_UFHA(Class *, cl, A0),
468 AROS_UFHA(Object *, o, A2),
469 AROS_UFHA(Msg, msg, A1)
472 AROS_USERFUNC_INIT
474 IPTR retval = 0UL;
476 switch (msg->MethodID)
478 case OM_NEW:
479 retval = (IPTR)console_new(cl, o, (struct opSet *)msg);
480 break;
482 case M_Console_Left:
483 console_left(cl, o, (struct P_Console_Left *)msg);
484 break;
486 case M_Console_Right:
487 console_right(cl, o, (struct P_Console_Right *)msg);
488 break;
490 case M_Console_Up:
491 console_up(cl, o, (struct P_Console_Up *)msg);
492 break;
494 case M_Console_Down:
495 console_down(cl, o, (struct P_Console_Down *)msg);
496 break;
498 case M_Console_DoCommand:
499 console_docommand(cl, o, (struct P_Console_DoCommand *)msg);
500 break;
502 case M_Console_GetDefaultParams:
503 console_getdefaultparams(cl, o, (struct P_Console_GetDefaultParams *)msg);
504 break;
506 case M_Console_NewWindowSize:
507 console_newwindowsize(cl, o, (struct P_Console_NewWindowSize *)msg);
508 break;
510 default:
511 retval = DoSuperMethodA(cl, o, msg);
512 break;
515 return (retval);
517 AROS_USERFUNC_EXIT
521 /************************
522 ** normalizecoords() **
523 ************************/
525 /* Normalizes "out of window" coords, so that they
526 fit into the window
529 #define ABS(a) (((a) < 0) ? -(a) : (a))
532 #undef ConsoleDevice
533 #define ConsoleDevice ((struct ConsoleBase *)OCLASS(o)->cl_UserData)
535 #warning Currently dead code
536 VOID normalizecoords(Object *o, WORD *x_ptr, WORD *y_ptr)
538 EnterFunc(bug("normalizecoords(o=%p, x=%d, y=%d)\n",
539 o, *x_ptr, *y_ptr));
541 if (*x_ptr > CU(o)->cu_XMax) /* charpos too far to the right */
543 D(bug("Pos right of window\n"));
544 /* Increase y */
545 Console_Down(o, *x_ptr / CHAR_XMAX(o) );
547 /* Normalize x */
548 *x_ptr = *x_ptr % (CHAR_XMAX(o) - CHAR_XMIN(o));
550 else if (*x_ptr < CHAR_XMIN(o))
552 D(bug("Pos left of window\n"));
554 /* Decrease y */
555 Console_Up(o, ABS(*x_ptr) / CHAR_XMAX(o) - CHAR_XMIN(o) );
557 /* Normalize Z */
558 *x_ptr = *x_ptr % (CHAR_XMAX(o) - CHAR_XMIN(o));
562 if (*y_ptr > CHAR_YMAX(o)) /* pos below window bounds */
565 *y_ptr = CHAR_YMAX(o);
567 else if (*y_ptr < CHAR_YMIN(o))
569 UBYTE scroll_param = CHAR_YMIN(o) - *y_ptr; /* pos above window bounds */
571 D(bug("Pos above window\n"));
573 Console_DoCommand(o, C_SCROLL_DOWN, 1, &scroll_param);
575 *y_ptr = CHAR_YMIN(o);
579 ReturnVoid("normalizecoords");
584 #undef ConsoleDevice
586 Class *makeConsoleClass(struct ConsoleBase *ConsoleDevice)
589 Class *cl;
591 cl = MakeClass(NULL, ROOTCLASS, NULL, sizeof(struct consoledata), 0UL);
592 if (cl)
594 cl->cl_Dispatcher.h_Entry = (APTR)dispatch_consoleclass;
595 cl->cl_Dispatcher.h_SubEntry = NULL;
597 cl->cl_UserData = (IPTR)ConsoleDevice;
599 return (cl);
601 return (NULL);