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.13  2008/02/26 23:56:12  james
14  * *** empty log message ***
15  *
16  * Revision 1.12  2008/02/26 23:23:17  james
17  * *** empty log message ***
18  *
19  * Revision 1.11  2008/02/23 11:48:37  james
20  * *** empty log message ***
21  *
22  * Revision 1.10  2008/02/22 17:07:00  james
23  * *** empty log message ***
24  *
25  * Revision 1.9  2008/02/07 13:22:51  james
26  * *** empty log message ***
27  *
28  * Revision 1.8  2008/02/07 13:19:48  james
29  * *** empty log message ***
30  *
31  * Revision 1.7  2008/02/07 12:41:06  james
32  * *** empty log message ***
33  *
34  * Revision 1.6  2008/02/07 12:16:04  james
35  * *** empty log message ***
36  *
37  * Revision 1.5  2008/02/06 11:30:37  james
38  * *** empty log message ***
39  *
40  * Revision 1.4  2008/02/05 01:11:46  james
41  * *** empty log message ***
42  *
43  * Revision 1.3  2008/02/04 20:23:55  james
44  * *** empty log message ***
45  *
46  * Revision 1.2  2008/02/04 02:05:06  james
47  * *** empty log message ***
48  *
49  * Revision 1.1  2008/02/03 23:31:25  james
50  * *** empty log message ***
51  *
52  */
53
54 #include "project.h"
55
56 void
57 crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
58 {
59   CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)];
60   CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)];
61
62   while (ps <= pe)
63     {
64       ps->chr = ' ';
65       if (ea)
66         {
67           ps->attr = CRT_ATTR_NORMAL;
68           ps->color = color;
69         }
70       ps++;
71     }
72
73 }
74
75 void
76 crt_cls (CRT * c)
77 {
78   CRT_Pos s = { 0, 0 };
79   CRT_Pos e = { CRT_COLS - 1, CRT_ROWS - 1 };
80   int i;
81
82   crt_erase (c, s, e, 1, CRT_COLOR_NORMAL);
83 #if 0
84   c->sh.dir = 0;
85 #endif
86 }
87
88 void
89 crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
90 {
91   int l, n;
92   int p;
93
94
95   s.x = 0;
96   e.x = CRT_COLS - 1;
97
98 #if 0
99   c->sh.s = s;
100   c->sh.e = e;
101   c->sh.dir = -1;
102 #endif
103
104   l = e.x - s.x;
105   l++;
106   l *= sizeof (CRT_CA);
107
108   n = e.y - s.y;
109
110
111   p = CRT_ADDR_POS (&s);
112
113   while (n--)
114     {
115       memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l);
116       p += CRT_COLS;
117     }
118
119   s.y = e.y;
120   crt_erase (c, s, e, ea, color);
121
122 }
123
124 void
125 crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
126 {
127   int l, n;
128   int p;
129
130   s.x = 0;
131   e.x = CRT_COLS - 1;
132
133 #if 0
134   c->sh.s = s;
135   c->sh.e = e;
136   c->sh.dir = 1;
137 #endif
138
139   l = e.x - s.x;
140   l++;
141   l *= sizeof (CRT_CA);
142
143   n = e.y - s.y;
144   n++;
145
146   p = CRT_ADDR_POS (&e);
147
148   while (n--)
149     {
150       memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l);
151       p -= CRT_COLS;
152     }
153
154   e.y = s.y;
155   crt_erase (c, s, e, ea, color);
156
157 }
158
159 void
160 crt_reset (CRT * c)
161 {
162   crt_cls (c);
163
164   c->pos.x = 0;
165   c->pos.y = 0;
166   c->hide_cursor = 1;
167   c->width = CRT_COLS;
168 #if 0
169   c->sh.dir = 0;
170 #endif
171 }
172
173 void
174 crt_insert (CRT * c, CRT_CA ca)
175 {
176   if (c->pos.x < 0)
177     c->pos.x = 0;
178   if (c->pos.x >= CRT_COLS)
179     c->pos.x = CRT_COLS - 1;
180   if (c->pos.y < 0)
181     c->pos.y = 0;
182   if (c->pos.y >= CRT_ROWS)
183     c->pos.y = CRT_ROWS - 1;
184
185   c->screen[CRT_ADDR (c->pos.y, c->pos.x)] = ca;
186
187 #if 0
188   c->sh.dir = 0;
189 #endif
190 }