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.4  2008/02/05 01:11:46  james
14  * *** empty log message ***
15  *
16  * Revision 1.3  2008/02/04 20:23:55  james
17  * *** empty log message ***
18  *
19  * Revision 1.2  2008/02/04 02:05:06  james
20  * *** empty log message ***
21  *
22  * Revision 1.1  2008/02/03 23:31:25  james
23  * *** empty log message ***
24  *
25  */
26
27 #include "project.h"
28
29 void
30 crt_erase (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
31 {
32   CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)];
33   CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)];
34
35   while (ps <= pe)
36     {
37       ps->chr = ' ';
38       if (ea)
39       ps->attr = CRT_ATTR_NORMAL;
40       ps++;
41     }
42
43 }
44
45 void
46 crt_cls (CRT * c)
47 {
48   CRT_Pos s = { 0, 0 };
49   CRT_Pos e = { CRT_COLS - 1, CRT_ROWS - 1 };
50   int i;
51
52   crt_erase (c, s, e,1);
53
54 #if 0
55   for (i = 0; i < CRT_ROWS; ++i)
56     {
57       c->screen[CRT_ADDR (i, i)].chr = '@' + i;
58       c->screen[CRT_ADDR (i, i)].attr = CRT_ATTR_NORMAL;
59     }
60 #endif
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 }