chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / crt.c
1 /*
2  * crt.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.5  2008/02/06 11:30:37  james
14  * *** empty log message ***
15  *
16  * Revision 1.4  2008/02/05 01:11:46  james
17  * *** empty log message ***
18  *
19  * Revision 1.3  2008/02/04 20:23:55  james
20  * *** empty log message ***
21  *
22  * Revision 1.2  2008/02/04 02:05:06  james
23  * *** empty log message ***
24  *
25  * Revision 1.1  2008/02/03 23:31:25  james
26  * *** empty log message ***
27  *
28  */
29
30 #include "project.h"
31
32 void
33 crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
34 {
35   CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)];
36   CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)];
37
38   while (ps <= pe)
39     {
40       ps->chr = ' ';
41       if (ea)
42         ps->attr = CRT_ATTR_NORMAL;
43       ps++;
44     }
45
46 }
47
48 void
49 crt_cls (CRT * c)
50 {
51   CRT_Pos s = { 0, 0 };
52   CRT_Pos e = { CRT_COLS - 1, CRT_ROWS - 1 };
53   int i;
54
55   crt_erase (c, s, e, 1);
56
57 #if 0
58   for (i = 0; i < CRT_ROWS; ++i)
59     {
60       c->screen[CRT_ADDR (i, i)].chr = '@' + i;
61       c->screen[CRT_ADDR (i, i)].attr = CRT_ATTR_NORMAL;
62     }
63 #endif
64
65 }
66
67 void
68 crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
69 {
70   int l, n;
71   int p;
72
73   s.x = 0;
74   e.x = CRT_COLS - 1;
75
76   l = e.x - s.x;
77   l++;
78   l *= sizeof (CRT_CA);
79
80   n = e.y - s.y;
81
82   p = CRT_ADDR_POS (&s);
83
84   while (n--)
85     {
86       memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l);
87       p += CRT_COLS;
88     }
89
90   s.y = e.y;
91   crt_erase (c, s, e, ea);
92
93 }
94
95 void
96 crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
97 {
98   int l, n;
99   int p;
100
101   s.x = 0;
102   e.x = CRT_COLS - 1;
103
104   l = e.x - s.x;
105   l++;
106   l *= sizeof (CRT_CA);
107
108   n = e.y - s.y;
109   n++;
110
111   p = CRT_ADDR_POS (&e);
112
113   while (n--)
114     {
115       memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l);
116       p -= CRT_COLS;
117     }
118
119   e.y = s.y;
120   crt_erase (c, s, e, ea);
121
122 }
123
124 void
125 crt_reset (CRT * c)
126 {
127   crt_cls (c);
128
129   c->pos.x = 0;
130   c->pos.y = 0;
131   c->hide_cursor = 1;
132 }
133
134 void
135 crt_insert (CRT * c, CRT_CA ca)
136 {
137   if (c->pos.x < 0)
138     c->pos.x = 0;
139   if (c->pos.x >= CRT_COLS)
140     c->pos.x = CRT_COLS - 1;
141   if (c->pos.y < 0)
142     c->pos.y = 0;
143   if (c->pos.y >= CRT_ROWS)
144     c->pos.y = CRT_ROWS - 1;
145
146   c->screen[CRT_ADDR (c->pos.y, c->pos.x)] = ca;
147
148
149
150 }