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