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