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