2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Code for CONU_STANDARD console units.
10 #include <proto/graphics.h>
11 #include <proto/intuition.h>
12 #include <intuition/intuition.h>
13 #include <graphics/rastport.h>
14 #include <aros/asmcall.h>
18 #include <aros/debug.h>
20 #include "console_gcc.h"
21 #include "consoleif.h"
27 WORD rendercursorcount
;
33 #define ConsoleDevice ((struct ConsoleBase *)cl->cl_UserData)
37 /*********** StdCon::New() **********************/
39 static Object
*stdcon_new(Class
*cl
, Object
*o
, struct opSet
*msg
)
41 EnterFunc(bug("StdCon::New()\n"));
42 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
45 struct stdcondata
*data
= INST_DATA(cl
, o
);
46 ULONG dispmid
= OM_DISPOSE
;
47 /* Clear for checking inside dispose() whether stuff was allocated.
48 Basically this is bug-prevention.
50 memset(data
, 0, sizeof (struct stdcondata
));
52 data
->dri
= GetScreenDrawInfo(CU(o
)->cu_Window
->WScreen
);
55 CU(o
)->cu_BgPen
= data
->dri
->dri_Pens
[BACKGROUNDPEN
];
56 CU(o
)->cu_FgPen
= data
->dri
->dri_Pens
[TEXTPEN
];
58 data
->cursorvisible
= TRUE
;
59 Console_RenderCursor(o
);
61 ReturnPtr("StdCon::New", Object
*, o
);
63 CoerceMethodA(cl
, o
, (Msg
)&dispmid
);
65 ReturnPtr("StdCon::New", Object
*, NULL
);
69 /*********** StdCon::Dispose() **************************/
71 static VOID
stdcon_dispose(Class
*cl
, Object
*o
, Msg msg
)
73 struct stdcondata
*data
= INST_DATA(cl
, o
);
75 FreeScreenDrawInfo(CU(o
)->cu_Window
->WScreen
, data
->dri
);
77 /* Let superclass free its allocations */
78 DoSuperMethodA(cl
, o
, msg
);
83 /********* StdCon::DoCommand() ****************************/
85 static VOID
stdcon_docommand(Class
*cl
, Object
*o
, struct P_Console_DoCommand
*msg
)
89 struct Window
*w
= CU(o
)->cu_Window
;
90 struct RastPort
*rp
= w
->RPort
;
91 IPTR
*params
= msg
->Params
;
92 struct stdcondata
*data
= INST_DATA(cl
, o
);
94 EnterFunc(bug("StdCon::DoCommand(o=%p, cmd=%d, params=%p)\n",
95 o
, msg
->Command
, params
));
101 D(bug("Writing char %c at (%d, %d)\n",
102 params
[0], CP_X(o
), CP_Y(o
) + rp
->Font
->tf_Baseline
));
104 Console_UnRenderCursor(o
);
106 SetAPen(rp
, CU(o
)->cu_FgPen
);
107 SetBPen(rp
, CU(o
)->cu_BgPen
);
109 Move(rp
, CP_X(o
), CP_Y(o
) + rp
->Font
->tf_Baseline
);
117 /* Rerender the cursor */
118 Console_RenderCursor(o
);
124 D(bug("Writing string %.*s at (%d, %d)\n",
125 (int)params
[1], (char *)params
[0], CP_X(o
), CP_Y(o
) + rp
->Font
->tf_Baseline
));
127 Console_UnRenderCursor(o
);
129 SetAPen(rp
, CU(o
)->cu_FgPen
);
130 SetBPen(rp
, CU(o
)->cu_BgPen
);
134 ULONG len
= params
[1];
135 STRPTR str
= (STRPTR
)params
[0];
139 ULONG remaining_space
= CHAR_XMAX(o
)+1-XCCP
;
140 ULONG line_len
= len
< remaining_space
? len
: remaining_space
;
142 Move(rp
, CP_X(o
), CP_Y(o
) + rp
->Font
->tf_Baseline
);
143 Text(rp
, str
, line_len
);
145 Console_Right(o
, line_len
);
152 /* Rerender the cursor */
153 Console_RenderCursor(o
);
158 /* Clear the console */
160 UBYTE oldpen
= rp
->FgPen
;
161 IPTR newcurpos
[2] = {0,0};
163 Console_UnRenderCursor(o
);
165 SetAPen( rp
, CU(o
)->cu_BgPen
);
170 ,CU(o
)->cu_YRExtant
);
174 Console_DoCommand(o
, C_CURSOR_POS
, 2, newcurpos
);
176 Console_RenderCursor(o
);
182 /* !!! maybe trouble with LockLayers() here !!! */
183 // DisplayBeep(CU(o)->cu_Window->WScreen);
187 Console_UnRenderCursor(o
);
189 Console_RenderCursor(o
);
192 case C_CURSOR_BACKWARD
:
193 Console_UnRenderCursor(o
);
194 Console_Left(o
, params
[0]);
195 Console_RenderCursor(o
);
198 case C_CURSOR_FORWARD
:
199 Console_UnRenderCursor(o
);
200 Console_Right(o
, params
[0]);
201 Console_RenderCursor(o
);
204 case C_DELETE_CHAR
: /* FIXME: can it have params!? */
205 Console_UnRenderCursor(o
);
206 Console_ClearCell(o
, XCCP
, YCCP
);
207 Console_RenderCursor(o
);
212 WORD x
= XCCP
, i
= 0;
214 while( (CU(o
)->cu_TabStops
[i
] != (UWORD
)-1) &&
215 (CU(o
)->cu_TabStops
[i
] <= x
) )
219 if (CU(o
)->cu_TabStops
[i
] != (UWORD
)-1)
221 Console_UnRenderCursor(o
);
222 Console_Right(o
, CU(o
)->cu_TabStops
[i
] - x
);
223 Console_RenderCursor(o
);
236 Console_DoCommand(o
, C_HTAB
, 0, &dummy
);
242 case C_CURSOR_BACKTAB
:
244 WORD count
= params
[0];
246 Console_UnRenderCursor(o
);
250 WORD x
= XCCP
, i
= 0;
252 while( (CU(o
)->cu_TabStops
[i
] != (UWORD
)-1) &&
253 (CU(o
)->cu_TabStops
[i
] < x
) )
260 if (i
>= 0) if (CU(o
)->cu_TabStops
[i
] != (UWORD
)-1)
262 Console_Left(o
, x
- CU(o
)->cu_TabStops
[i
]);
265 } while (--count
> 0);
267 Console_RenderCursor(o
);
273 D(bug("Got linefeed command\n"));
274 /*Console_ClearCell(o, XCCP, YCCP);*/
275 Console_UnRenderCursor(o
);
279 /* Check for linefeed mode (LF or LF+CR) */
281 D(bug("conflags: %d\n", ICU(o
)->conFlags
));
283 /* if (ICU(o)->conFlags & CF_LF_MODE_ON) */
284 if (CHECK_MODE(o
, M_LNM
))
286 CU(o
)->cu_XCP
= CHAR_XMIN(o
);
287 CU(o
)->cu_XCCP
= CHAR_XMIN(o
);
289 Console_RenderCursor(o
);
297 case C_CARRIAGE_RETURN
:
298 /* Goto start of line */
300 Console_UnRenderCursor(o
);
301 CU(o
)->cu_XCP
= CHAR_XMIN(o
);
302 CU(o
)->cu_XCCP
= CHAR_XMIN(o
);
303 Console_RenderCursor(o
);
312 D(bug("Got NEXT LINE cmd\n"));
314 Console_Left(o
, XCP
);
323 WORD y
= ((WORD
)params
[0]) - 1;
324 WORD x
= ((WORD
)params
[1]) - 1;
326 if (x
< CHAR_XMIN(o
))
330 else if (x
> CHAR_XMAX(o
))
335 if (y
< CHAR_YMIN(o
))
339 else if (y
> CHAR_YMAX(o
))
344 Console_UnRenderCursor(o
);
349 Console_RenderCursor(o
);
353 case C_ERASE_IN_LINE
:
356 UBYTE oldpen
= rp
->FgPen
;
358 Console_UnRenderCursor(o
);
362 SetAPen( rp
, CU(o
)->cu_BgPen
);
366 ,CU(o
)->cu_XROrigin
+ XCP
* XRSIZE
367 ,CU(o
)->cu_YROrigin
+ YCP
* YRSIZE
369 ,CU(o
)->cu_YROrigin
+ (YCP
+ 1) * YRSIZE
- 1);
374 Console_RenderCursor(o
);
378 case C_ERASE_IN_DISPLAY
:
381 UBYTE oldpen
= rp
->FgPen
;
384 Console_DoCommand(o
, C_ERASE_IN_LINE
, 1, ¶m
);
386 /* Clear rest of area */
388 Console_UnRenderCursor(o
);
390 SetAPen( rp
, CU(o
)->cu_BgPen
);
395 ,CU(o
)->cu_YROrigin
+ (YCP
+ 1) * YRSIZE
397 ,CU(o
)->cu_YRExtant
);
401 Console_RenderCursor(o
);
408 UBYTE oldpen
= rp
->FgPen
;
410 Console_UnRenderCursor(o
);
411 SetAPen(rp
, CU(o
)->cu_BgPen
);
423 Console_RenderCursor(o
);
429 UBYTE oldpen
= rp
->FgPen
;
431 Console_UnRenderCursor(o
);
432 SetAPen(rp
, CU(o
)->cu_BgPen
);
444 Console_RenderCursor(o
);
450 UBYTE oldpen
= rp
->FgPen
;
452 D(bug("C_SCROLL_UP area (%d, %d) to (%d, %d), %d\n",
453 GFX_XMIN(o
), GFX_YMIN(o
), GFX_XMAX(o
), GFX_YMAX(o
), YRSIZE
* params
[0]));
455 Console_UnRenderCursor(o
);
457 SetAPen( rp
, CU(o
)->cu_BgPen
);
458 #warning LockLayers problem here ?
468 Console_RenderCursor(o
);
475 UBYTE oldpen
= rp
->FgPen
;
477 D(bug("C_SCROLL_DOWN area (%d, %d) to (%d, %d), %d\n",
478 GFX_XMIN(o
), GFX_YMIN(o
), GFX_XMAX(o
), GFX_YMAX(o
), YRSIZE
* params
[0]));
480 Console_UnRenderCursor(o
);
482 SetAPen( rp
, CU(o
)->cu_BgPen
);
483 #warning LockLayers problem here ?
486 , -YRSIZE
* params
[0]
493 Console_RenderCursor(o
);
498 case C_CURSOR_VISIBLE
:
499 if (!data
->cursorvisible
)
501 data
->cursorvisible
= TRUE
;
502 data
->rendercursorcount
--;
503 Console_RenderCursor(o
);
507 case C_CURSOR_INVISIBLE
:
508 if (data
->cursorvisible
)
510 Console_UnRenderCursor(o
);
511 data
->cursorvisible
= FALSE
;
512 data
->rendercursorcount
++;
529 DoSuperMethodA(cl
, o
, (Msg
)msg
);
533 ReturnVoid("StdCon::DoCommand");
536 /********* StdCon::RenderCursor() ****************************/
537 static VOID
stdcon_rendercursor(Class
*cl
, Object
*o
, struct P_Console_RenderCursor
*msg
)
539 struct RastPort
*rp
= RASTPORT(o
);
540 struct stdcondata
*data
= INST_DATA(cl
, o
);
542 /* SetAPen(rp, data->dri->dri_Pens[FILLPEN]); */
544 data
->rendercursorcount
++;
546 if (data
->cursorvisible
&& (data
->rendercursorcount
== 1))
548 SetDrMd(rp
, COMPLEMENT
);
552 , CP_X(o
) + XRSIZE
- 1
553 , CP_Y(o
) + YRSIZE
- 1
559 /********* StdCon::UnRenderCursor() ****************************/
560 static VOID
stdcon_unrendercursor(Class
*cl
, Object
*o
, struct P_Console_UnRenderCursor
*msg
)
562 struct RastPort
*rp
= RASTPORT(o
);
563 struct stdcondata
*data
= INST_DATA(cl
, o
);
565 data
->rendercursorcount
--;
567 /* SetAPen(rp, data->dri->dri_Pens[FILLPEN]); */
569 if (data
->cursorvisible
&& (data
->rendercursorcount
== 0))
571 SetDrMd(rp
, COMPLEMENT
);
575 , CP_X(o
) + XRSIZE
- 1
576 , CP_Y(o
) + YRSIZE
- 1
582 /**************************
583 ** StdCon::ClearCell() **
584 **************************/
585 static VOID
stdcon_clearcell(Class
*cl
, Object
*o
, struct P_Console_ClearCell
*msg
)
587 struct RastPort
*rp
= RASTPORT(o
);
588 struct stdcondata
*data
= INST_DATA(cl
, o
);
590 SetAPen(rp
, data
->dri
->dri_Pens
[BACKGROUNDPEN
]);
595 , GFX_X(o
, msg
->X
) + XRSIZE
- 1
596 , GFX_Y(o
, msg
->Y
) + YRSIZE
- 1
600 /*******************************
601 ** StdCon::NewWindowSize() **
602 *******************************/
603 static VOID
stdcon_newwindowsize(Class
*cl
, Object
*o
, struct P_Console_NewWindowSize
*msg
)
605 struct RastPort
*rp
= RASTPORT(o
);
606 struct stdcondata
*data
= INST_DATA(cl
, o
);
607 WORD old_xmax
= CHAR_XMAX(o
);
608 WORD old_ymax
= CHAR_YMAX(o
);
614 DoSuperMethodA(cl
, o
, (Msg
)msg
);
616 if (CHAR_XMAX(o
) < old_xmax
)
618 x1
= GFX_XMAX(o
) + 1;
620 x2
= WINDOW(o
)->Width
- WINDOW(o
)->BorderRight
- 1;
621 y2
= WINDOW(o
)->Height
- WINDOW(o
)->BorderBottom
- 1;
623 if ((x2
>= x1
) && (y2
>= y1
))
627 RectFill(rp
, x1
, y1
, x2
, y2
);
631 if (CHAR_YMAX(o
) < old_ymax
)
634 y1
= GFX_YMAX(o
) + 1;
635 x2
= WINDOW(o
)->Width
- WINDOW(o
)->BorderRight
- 1;
636 y2
= WINDOW(o
)->Height
- WINDOW(o
)->BorderBottom
- 1;
638 if ((x2
>= x1
) && (y2
>= y1
))
642 RectFill(rp
, x1
, y1
, x2
, y2
);
646 if ((old_xcp
!= XCP
) || (old_ycp
!= YCP
))
651 RectFill(rp
, GFX_XMIN(o
), GFX_YMIN(o
), GFX_XMAX(o
), GFX_YMAX(o
));
656 /* Scroll up one line */
662 GFX_XMIN(o
), GFX_YMIN(o
), GFX_XMAX(o
), GFX_YMAX(o
));
664 /* Move cursor to column 0 */
670 data
->rendercursorcount
--;
671 Console_RenderCursor(o
);
678 AROS_UFH3S(IPTR
, dispatch_stdconclass
,
679 AROS_UFHA(Class
*, cl
, A0
),
680 AROS_UFHA(Object
*, o
, A2
),
681 AROS_UFHA(Msg
, msg
, A1
)
688 switch (msg
->MethodID
)
691 retval
= (IPTR
)stdcon_new(cl
, o
, (struct opSet
*)msg
);
695 stdcon_dispose(cl
, o
, msg
);
698 case M_Console_DoCommand
:
699 stdcon_docommand(cl
, o
, (struct P_Console_DoCommand
*)msg
);
702 case M_Console_RenderCursor
:
703 stdcon_rendercursor(cl
, o
, (struct P_Console_RenderCursor
*)msg
);
706 case M_Console_UnRenderCursor
:
707 stdcon_unrendercursor(cl
, o
, (struct P_Console_UnRenderCursor
*)msg
);
710 case M_Console_ClearCell
:
711 stdcon_clearcell(cl
, o
, (struct P_Console_ClearCell
*)msg
);
714 case M_Console_NewWindowSize
:
715 stdcon_newwindowsize(cl
, o
, (struct P_Console_NewWindowSize
*)msg
);
719 retval
= DoSuperMethodA(cl
, o
, msg
);
730 Class
*makeStdConClass(struct ConsoleBase
*ConsoleDevice
)
735 cl
= MakeClass(NULL
, NULL
,CONSOLECLASSPTR
, sizeof(struct stdcondata
), 0UL);
738 cl
->cl_Dispatcher
.h_Entry
= (APTR
)dispatch_stdconclass
;
739 cl
->cl_Dispatcher
.h_SubEntry
= NULL
;
741 cl
->cl_UserData
= (IPTR
)ConsoleDevice
;