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