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