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