2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Base class for console units
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>
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.
37 struct intConUnit intunit
;
42 #define ConsoleDevice ((struct ConsoleBase *)cl->cl_UserData)
45 /*********************
47 *********************/
48 static Object
*console_new(Class
*cl
, Object
*o
, struct opSet
*msg
)
51 EnterFunc(bug("Console::New()\n"));
53 /* Get console window */
54 win
= (struct Window
*)GetTagData(A_Console_Window
, 0, msg
->ops_AttrList
);
56 ReturnPtr ("Console::New", Object
*, NULL
);
58 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
62 struct consoledata
*data
;
63 struct RastPort
*rp
= win
->RPort
;
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
)
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);
146 Console_Up(o
, scrollcount
);
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
)
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);
184 Console_Down(o
, scrollcount
);
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 /********************
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
));
210 if (CHECK_MODE(o
, PMB_ASM
))
212 IPTR scroll_param
= -YCCP
;
215 Console_DoCommand(o
, C_SCROLL_DOWN
, 1, &scroll_param
);
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
));
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
);
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
)
271 D(bug("Set LF mode ON\n"));
273 /* ICU(o)->conFlags |= CF_LF_MODE_ON ; */
277 case C_RESET_LF_MODE
:
279 D(bug("Set LF mode OFF\n"));
280 /* ICU(o)->conFlags &= ~CF_LF_MODE_ON; */
281 CLEAR_MODE(o
, M_LNM
);
284 case C_SET_AUTOSCROLL_MODE
:
285 SET_MODE(o
, PMB_ASM
);
288 case C_RESET_AUTOSCROLL_MODE
:
289 CLEAR_MODE(o
, PMB_ASM
);
292 case C_SET_AUTOWRAP_MODE
:
293 SET_MODE(o
, PMB_AWM
);
296 case C_RESET_AUTOWRAP_MODE
:
297 CLEAR_MODE(o
, PMB_AWM
);
300 case C_SELECT_GRAPHIC_RENDITION
:
301 D(bug("Select graphic Rendition\n"));
305 for(i
= 0; i
< msg
->NumParams
; i
++)
307 param
= msg
->Params
[i
];
319 CU(o
)->cu_FgPen
= param
- 30;
330 CU(o
)->cu_BgPen
= param
- 40;
333 } /* switch(param) */
335 } /* for(i = 0; i < msg->NumParams; i++) */
340 case C_SET_RAWEVENTS
:
341 D(bug("Set Raw Events\n"));
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++) */
358 case C_RESET_RAWEVENTS
:
359 D(bug("Set Raw Events\n"));
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++) */
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
)
391 case C_CURSOR_FORWARD
:
392 case C_CURSOR_BACKWARD
:
393 case C_CURSOR_NEXT_LINE
:
394 case C_CURSOR_PREV_LINE
:
398 msg
->Params
[0] = YCCP
+ 1;
399 msg
->Params
[1] = XCCP
+ 1;
402 #warning Autodocs state commands in between here, has params RKRM: Devs saye the do not
410 case C_CURSOR_TAB_CTRL
:
411 msg
->Params
[0] = 0; /* set tab */
415 case C_CURSOR_BACKTAB
:
419 case C_SELECT_GRAPHIC_RENDITION
:
420 /* don't do anything, as params may be in any order */
423 case C_SET_RAWEVENTS
:
424 /* don't do anything, as params may be in any order */
427 case C_RESET_RAWEVENTS
:
428 /* don't do anything, as params may be in any order */
431 } /* switch (msg->Command) */
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
;
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
;
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
)
476 switch (msg
->MethodID
)
479 retval
= (IPTR
)console_new(cl
, o
, (struct opSet
*)msg
);
483 console_left(cl
, o
, (struct P_Console_Left
*)msg
);
486 case M_Console_Right
:
487 console_right(cl
, o
, (struct P_Console_Right
*)msg
);
491 console_up(cl
, o
, (struct P_Console_Up
*)msg
);
495 console_down(cl
, o
, (struct P_Console_Down
*)msg
);
498 case M_Console_DoCommand
:
499 console_docommand(cl
, o
, (struct P_Console_DoCommand
*)msg
);
502 case M_Console_GetDefaultParams
:
503 console_getdefaultparams(cl
, o
, (struct P_Console_GetDefaultParams
*)msg
);
506 case M_Console_NewWindowSize
:
507 console_newwindowsize(cl
, o
, (struct P_Console_NewWindowSize
*)msg
);
511 retval
= DoSuperMethodA(cl
, o
, msg
);
521 /************************
522 ** normalizecoords() **
523 ************************/
525 /* Normalizes "out of window" coords, so that they
529 #define ABS(a) (((a) < 0) ? -(a) : (a))
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",
541 if (*x_ptr
> CU(o
)->cu_XMax
) /* charpos too far to the right */
543 D(bug("Pos right of window\n"));
545 Console_Down(o
, *x_ptr
/ CHAR_XMAX(o
) );
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"));
555 Console_Up(o
, ABS(*x_ptr
) / CHAR_XMAX(o
) - CHAR_XMIN(o
) );
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");
586 Class
*makeConsoleClass(struct ConsoleBase
*ConsoleDevice
)
591 cl
= MakeClass(NULL
, ROOTCLASS
, NULL
, sizeof(struct consoledata
), 0UL);
594 cl
->cl_Dispatcher
.h_Entry
= (APTR
)dispatch_consoleclass
;
595 cl
->cl_Dispatcher
.h_SubEntry
= NULL
;
597 cl
->cl_UserData
= (IPTR
)ConsoleDevice
;