2 Copyright © 1995-2014, 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)
44 /*********************
46 *********************/
47 static Object
*console_new(Class
*cl
, Object
*o
, struct opSet
*msg
)
50 EnterFunc(bug("Console::New()\n"));
51 struct Library
*UtilityBase
;
53 UtilityBase
= TaggedOpenLibrary(TAGGEDOPEN_UTILITY
);
55 ReturnPtr("Console::New", Object
*, NULL
);
57 /* Get console window */
59 (struct Window
*)GetTagData(A_Console_Window
, 0, msg
->ops_AttrList
);
60 CloseLibrary(UtilityBase
);
63 ReturnPtr("Console::New", Object
*, NULL
);
66 o
= (Object
*) DoSuperMethodA(cl
, o
, (Msg
) msg
);
70 struct consoledata
*data
;
71 struct RastPort
*rp
= win
->RPort
;
74 data
= INST_DATA(cl
, o
);
76 unit
= (struct ConUnit
*)data
;
78 memset(data
, 0, sizeof(struct consoledata
));
80 /* Initialize the unit fields */
81 unit
->cu_Window
= win
;
83 /* For now one should use only non-proportional fonts */
84 unit
->cu_XRSize
= rp
->Font
->tf_XSize
;
85 unit
->cu_YRSize
= rp
->Font
->tf_YSize
;
87 D(bug("cu_XRSize: %d, cu_YRSize: %d\n",
88 unit
->cu_XRSize
, unit
->cu_YRSize
));
90 /* Use whole window for console. */
92 (win
->Width
- (win
->BorderLeft
+
93 win
->BorderRight
)) / unit
->cu_XRSize
- 1;
95 (win
->Height
- (win
->BorderTop
+
96 win
->BorderBottom
)) / unit
->cu_YRSize
- 1;
99 win
->Flags
& WFLG_GIMMEZEROZERO
? 0 : win
->BorderLeft
;
101 win
->Flags
& WFLG_GIMMEZEROZERO
? 0 : win
->BorderTop
;
103 D(bug("cu_XROrigin: %d, cu_YROrigin: %d\n",
104 unit
->cu_XROrigin
, unit
->cu_YROrigin
));
107 unit
->cu_XROrigin
+ (unit
->cu_XRSize
* (unit
->cu_XMax
+ 1) - 1);
109 unit
->cu_YROrigin
+ (unit
->cu_YRSize
* (unit
->cu_YMax
+ 1) - 1);
111 unit
->cu_XCP
= DEF_CHAR_XMIN
;
112 unit
->cu_YCP
= DEF_CHAR_YMIN
;
114 unit
->cu_XCCP
= DEF_CHAR_XMIN
;
115 unit
->cu_YCCP
= DEF_CHAR_YMIN
;
117 for (i
= 0; i
< MAXTABS
- 1; i
++)
119 unit
->cu_TabStops
[i
] = i
* 8;
121 unit
->cu_TabStops
[i
] = (UWORD
) - 1;
123 ICU(o
)->conFlags
= 0UL;
124 ICU(o
)->numStoredChars
= 0;
126 NEWLIST(&ICU(o
)->pasteData
);
128 SET_MODE(o
, PMB_ASM
); /* auto-scroll-mode ON */
129 SET_MODE(o
, PMB_AWM
); /* auto-wrap-mode ON */
131 /* RKM: Default mode is SET */
132 SET_MODE(o
, M_LNM
); /* linefeed mode = linefeed+carriage return */
135 ReturnPtr("Console::New", Object
*, o
);
138 /**********************
139 ** Console::Left() **
140 **********************/
141 static VOID
console_left(Class
*cl
, Object
*o
, struct P_Console_Left
*msg
)
145 EnterFunc(bug("Console::Left()\n"));
147 newx
= XCCP
- msg
->Num
;
149 if (CHECK_MODE(o
, PMB_AWM
))
151 WORD scrollcount
= 0;
153 while (newx
< CHAR_XMIN(o
))
155 newx
+= (CHAR_XMAX(o
) + 1);
161 Console_Up(o
, scrollcount
);
165 if (newx
< CHAR_XMIN(o
))
169 XCP
= XCCP
= newx
; /* XCP always same as XCCP?? */
171 D(bug("XCP=%d, XCCP=%d\n", XCP
, XCCP
));
173 ReturnVoid("Console::Left");
176 /***********************
177 ** Console::Right() **
178 ***********************/
179 static VOID
console_right(Class
*cl
, Object
*o
, struct P_Console_Right
*msg
)
183 EnterFunc(bug("Console::Right()\n"));
185 newx
= XCCP
+ msg
->Num
;
187 if (CHECK_MODE(o
, PMB_AWM
))
189 WORD scrollcount
= 0;
191 while (newx
> CHAR_XMAX(o
))
193 newx
-= (CHAR_XMAX(o
) + 1);
199 Console_Down(o
, scrollcount
);
203 if (newx
> CHAR_XMAX(o
))
207 XCP
= XCCP
= newx
; /* XCP always same as XCCP?? */
209 D(bug("XCP=%d, XCCP=%d\n", XCP
, XCCP
));
211 ReturnVoid("Console::Right");
214 /********************
216 ********************/
217 static VOID
console_up(Class
*cl
, Object
*o
, struct P_Console_Up
*msg
)
219 EnterFunc(bug("Console::Up(num=%d)\n", msg
->Num
));
225 if (CHECK_MODE(o
, PMB_ASM
))
227 IPTR scroll_param
= -YCCP
;
230 Console_DoCommand(o
, C_SCROLL_DOWN
, 1, &scroll_param
);
237 YCP
= YCCP
; /* YCP always same as YCCP ?? */
239 D(bug("New coords: char (%d, %d), gfx (%d, %d)\n",
240 XCCP
, YCCP
, CP_X(o
), CP_Y(o
)));
241 ReturnVoid("Console::Up");
246 /**********************
247 ** Console::Down() **
248 **********************/
249 static VOID
console_down(Class
*cl
, Object
*o
, struct P_Console_Down
*msg
)
251 EnterFunc(bug("Console::Down(num=%d)\n", msg
->Num
));
255 if (YCCP
> CHAR_YMAX(o
))
257 if (CHECK_MODE(o
, PMB_ASM
))
259 IPTR scroll_param
= YCCP
- CHAR_YMAX(o
);
261 YCCP
= YCP
= CHAR_YMAX(o
);
262 Console_DoCommand(o
, C_SCROLL_UP
, 1, &scroll_param
);
269 YCP
= YCCP
; /* YCP always same as YCCP ?? */
271 D(bug("New coords: char (%d, %d), gfx (%d, %d)\n",
272 XCCP
, YCCP
, CP_X(o
), CP_Y(o
)));
273 ReturnVoid("Console::Down");
276 /***************************
277 ** Console::DoCommand() **
278 ***************************/
279 static VOID
console_docommand(Class
*cl
, Object
*o
,
280 struct P_Console_DoCommand
*msg
)
282 EnterFunc(bug("Console::DoCommand(cmd=%d)\n", msg
->Command
));
284 switch (msg
->Command
)
287 D(bug("Set LF mode ON\n"));
289 /* ICU(o)->conFlags |= CF_LF_MODE_ON ; */
293 case C_RESET_LF_MODE
:
295 D(bug("Set LF mode OFF\n"));
296 /* ICU(o)->conFlags &= ~CF_LF_MODE_ON; */
297 CLEAR_MODE(o
, M_LNM
);
300 case C_SET_AUTOSCROLL_MODE
:
301 SET_MODE(o
, PMB_ASM
);
304 case C_RESET_AUTOSCROLL_MODE
:
305 CLEAR_MODE(o
, PMB_ASM
);
308 case C_SET_AUTOWRAP_MODE
:
309 SET_MODE(o
, PMB_AWM
);
312 case C_RESET_AUTOWRAP_MODE
:
313 CLEAR_MODE(o
, PMB_AWM
);
316 case C_SELECT_GRAPHIC_RENDITION
:
317 D(bug("Select graphic Rendition, params=%d\n", msg
->NumParams
));
321 for (i
= 0; i
< msg
->NumParams
; i
++)
323 param
= msg
->Params
[i
];
324 D(bug("param%d=%d\n", i
, param
));
331 CU(o
)->cu_TxFlags
= 0;
334 CU(o
)->cu_TxFlags
|= CON_TXTFLAGS_BOLD
;
340 CU(o
)->cu_TxFlags
|= CON_TXTFLAGS_ITALIC
;
343 CU(o
)->cu_TxFlags
|= CON_TXTFLAGS_UNDERLINED
;
346 CU(o
)->cu_TxFlags
|= CON_TXTFLAGS_REVERSED
;
349 CU(o
)->cu_TxFlags
|= CON_TXTFLAGS_CONCEALED
;
352 CU(o
)->cu_TxFlags
&= ~CON_TXTFLAGS_BOLD
;
355 CU(o
)->cu_TxFlags
&= ~CON_TXTFLAGS_ITALIC
;
358 CU(o
)->cu_TxFlags
&= ~CON_TXTFLAGS_UNDERLINED
;
361 CU(o
)->cu_TxFlags
&= ~CON_TXTFLAGS_REVERSED
;
364 CU(o
)->cu_TxFlags
&= ~CON_TXTFLAGS_CONCEALED
;
374 CU(o
)->cu_FgPen
= param
- 30;
388 CU(o
)->cu_BgPen
= param
- 40;
394 } /* switch(param) */
395 } /* for(i = 0; i < msg->NumParams; i++) */
399 case C_SET_RAWEVENTS
:
400 D(bug("Set Raw Events\n"));
404 for (i
= 0; i
< msg
->NumParams
; i
++)
406 param
= msg
->Params
[i
];
408 if (param
<= IECLASS_MAX
)
410 SET_RAWEVENT(o
, param
);
413 } /* for(i = 0; i < msg->NumParams; i++) */
417 case C_RESET_RAWEVENTS
:
418 D(bug("Set Raw Events\n"));
422 for (i
= 0; i
< msg
->NumParams
; i
++)
424 param
= msg
->Params
[i
];
426 if (param
<= IECLASS_MAX
)
428 RESET_RAWEVENT(o
, param
);
431 } /* for(i = 0; i < msg->NumParams; i++) */
434 } /* switch (msg->Command) */
436 ReturnVoid("Console::DoCommand");
439 /**********************************
440 ** Console::GetDefaultParams() **
441 **********************************/
442 static VOID
console_getdefaultparams(Class
*cl
, Object
*o
,
443 struct P_Console_GetDefaultParams
*msg
)
445 switch (msg
->Command
)
450 case C_CURSOR_FORWARD
:
451 case C_CURSOR_BACKWARD
:
452 case C_CURSOR_NEXT_LINE
:
453 case C_CURSOR_PREV_LINE
:
454 case C_SET_TOP_OFFSET
:
455 case C_SET_PAGE_LENGTH
:
459 msg
->Params
[0] = YCCP
+ 1;
460 msg
->Params
[1] = XCCP
+ 1;
463 /* FIXME: Autodocs state commands in between here, has params RKRM: Devs saye the do not */
471 case C_CURSOR_TAB_CTRL
:
472 msg
->Params
[0] = 0; /* set tab */
475 case C_CURSOR_BACKTAB
:
479 case C_SELECT_GRAPHIC_RENDITION
:
480 /* don't do anything, as params may be in any order */
483 case C_SET_RAWEVENTS
:
484 /* don't do anything, as params may be in any order */
487 case C_RESET_RAWEVENTS
:
488 /* don't do anything, as params may be in any order */
490 } /* switch (msg->Command) */
495 /*******************************
496 ** Console::NewWindowSize() **
497 *******************************/
498 static VOID
console_newwindowsize(Class
*cl
, Object
*o
,
499 struct P_Console_NewWindowSize
*msg
)
501 struct ConUnit
*unit
;
502 struct consoledata
*data
;
505 data
= INST_DATA(cl
, o
);
506 unit
= (struct ConUnit
*)data
;
508 win
= unit
->cu_Window
;
511 (win
->Width
- win
->BorderRight
-
512 unit
->cu_XROrigin
) / unit
->cu_XRSize
- 1;
514 (win
->Height
- win
->BorderBottom
-
515 unit
->cu_YROrigin
) / unit
->cu_YRSize
- 1;
518 unit
->cu_XROrigin
+ (unit
->cu_XRSize
* (unit
->cu_XMax
+ 1) - 1);
520 unit
->cu_YROrigin
+ (unit
->cu_YRSize
* (unit
->cu_YMax
+ 1) - 1);
522 if (unit
->cu_XCCP
> unit
->cu_XMax
)
523 unit
->cu_XCCP
= unit
->cu_XMax
;
524 if (unit
->cu_YCCP
> unit
->cu_YMax
)
525 unit
->cu_YCCP
= unit
->cu_YMax
;
527 unit
->cu_XCP
= unit
->cu_XCCP
;
528 unit
->cu_YCP
= unit
->cu_YCCP
;
535 /********* Console class dispatcher **********************************/
536 AROS_UFH3S(IPTR
, dispatch_consoleclass
,
537 AROS_UFHA(Class
*, cl
, A0
),
538 AROS_UFHA(Object
*, o
, A2
), AROS_UFHA(Msg
, msg
, A1
))
544 switch (msg
->MethodID
)
547 retval
= (IPTR
) console_new(cl
, o
, (struct opSet
*)msg
);
551 console_left(cl
, o
, (struct P_Console_Left
*)msg
);
554 case M_Console_Right
:
555 console_right(cl
, o
, (struct P_Console_Right
*)msg
);
559 console_up(cl
, o
, (struct P_Console_Up
*)msg
);
563 console_down(cl
, o
, (struct P_Console_Down
*)msg
);
566 case M_Console_DoCommand
:
567 console_docommand(cl
, o
, (struct P_Console_DoCommand
*)msg
);
570 case M_Console_GetDefaultParams
:
571 console_getdefaultparams(cl
, o
,
572 (struct P_Console_GetDefaultParams
*)msg
);
575 case M_Console_NewWindowSize
:
576 console_newwindowsize(cl
, o
, (struct P_Console_NewWindowSize
*)msg
);
580 retval
= DoSuperMethodA(cl
, o
, msg
);
589 /************************
590 ** normalizecoords() **
591 ************************/
593 /* Normalizes "out of window" coords, so that they
597 #define ABS(a) (((a) < 0) ? -(a) : (a))
601 #define ConsoleDevice ((struct ConsoleBase *)OCLASS(o)->cl_UserData)
603 /* FIXME: Currently dead code */
604 VOID
normalizecoords(Object
*o
, WORD
*x_ptr
, WORD
*y_ptr
)
606 EnterFunc(bug("normalizecoords(o=%p, x=%d, y=%d)\n",
609 if (*x_ptr
> CU(o
)->cu_XMax
) /* charpos too far to the right */
611 D(bug("Pos right of window\n"));
613 Console_Down(o
, *x_ptr
/ CHAR_XMAX(o
));
616 *x_ptr
= *x_ptr
% (CHAR_XMAX(o
) - CHAR_XMIN(o
));
618 else if (*x_ptr
< CHAR_XMIN(o
))
620 D(bug("Pos left of window\n"));
623 Console_Up(o
, ABS(*x_ptr
) / CHAR_XMAX(o
) - CHAR_XMIN(o
));
626 *x_ptr
= *x_ptr
% (CHAR_XMAX(o
) - CHAR_XMIN(o
));
629 if (*y_ptr
> CHAR_YMAX(o
)) /* pos below window bounds */
632 *y_ptr
= CHAR_YMAX(o
);
634 else if (*y_ptr
< CHAR_YMIN(o
)) /* pos above window bounds */
636 UBYTE scroll_param
= CHAR_YMIN(o
) - *y_ptr
;
638 D(bug("Pos above window\n"));
640 Console_DoCommand(o
, C_SCROLL_DOWN
, 1, &scroll_param
);
642 *y_ptr
= CHAR_YMIN(o
);
645 ReturnVoid("normalizecoords");
651 Class
*makeConsoleClass(struct ConsoleBase
*ConsoleDevice
)
655 cl
= MakeClass(NULL
, ROOTCLASS
, NULL
, sizeof(struct consoledata
), 0UL);
658 cl
->cl_Dispatcher
.h_Entry
= (APTR
) dispatch_consoleclass
;
659 cl
->cl_Dispatcher
.h_SubEntry
= NULL
;
661 cl
->cl_UserData
= (IPTR
) ConsoleDevice
;