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