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