aboutsummaryrefslogtreecommitdiffstats
path: root/src/crt.c
blob: 5f5656b2ccf33c46d4eedc8e0260e18b56728451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * crt.c:
 *
 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] = "$Id$";

/*
 * $Log$
 * Revision 1.10  2008/02/22 17:07:00  james
 * *** empty log message ***
 *
 * Revision 1.9  2008/02/07 13:22:51  james
 * *** empty log message ***
 *
 * Revision 1.8  2008/02/07 13:19:48  james
 * *** empty log message ***
 *
 * Revision 1.7  2008/02/07 12:41:06  james
 * *** empty log message ***
 *
 * Revision 1.6  2008/02/07 12:16:04  james
 * *** empty log message ***
 *
 * Revision 1.5  2008/02/06 11:30:37  james
 * *** empty log message ***
 *
 * Revision 1.4  2008/02/05 01:11:46  james
 * *** empty log message ***
 *
 * Revision 1.3  2008/02/04 20:23:55  james
 * *** empty log message ***
 *
 * Revision 1.2  2008/02/04 02:05:06  james
 * *** empty log message ***
 *
 * Revision 1.1  2008/02/03 23:31:25  james
 * *** empty log message ***
 *
 */

#include "project.h"

void
crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
{
  CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)];
  CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)];

  while (ps <= pe)
    {
      ps->chr = ' ';
      if (ea)
        {
          ps->attr = CRT_ATTR_NORMAL;
          ps->color = color;
        }
      ps++;
    }

}

void
crt_cls (CRT * c)
{
  CRT_Pos s = { 0, 0 };
  CRT_Pos e = { CRT_COLS - 1, CRT_ROWS - 1 };
  int i;

  crt_erase (c, s, e, 1, CRT_COLOR_NORMAL);
  c->sh.dir = 0;
}

void
crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
{
  int l, n;
  int p;


  s.x = 0;
  e.x = CRT_COLS - 1;

  c->sh.s = s;
  c->sh.e = e;
  c->sh.dir = -1;

  l = e.x - s.x;
  l++;
  l *= sizeof (CRT_CA);

  n = e.y - s.y;


  p = CRT_ADDR_POS (&s);

  while (n--)
    {
      memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l);
      p += CRT_COLS;
    }

  s.y = e.y;
  crt_erase (c, s, e, ea,color);

}

void
crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
{
  int l, n;
  int p;

  s.x = 0;
  e.x = CRT_COLS - 1;

  c->sh.s = s;
  c->sh.e = e;
  c->sh.dir = 1;

  l = e.x - s.x;
  l++;
  l *= sizeof (CRT_CA);

  n = e.y - s.y;
  n++;

  p = CRT_ADDR_POS (&e);

  while (n--)
    {
      memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l);
      p -= CRT_COLS;
    }

  e.y = s.y;
  crt_erase (c, s, e, ea,color);

}

void
crt_reset (CRT * c)
{
  crt_cls (c);

  c->pos.x = 0;
  c->pos.y = 0;
  c->hide_cursor = 1;
  c->sh.dir = 0;
}

void
crt_insert (CRT * c, CRT_CA ca)
{
  if (c->pos.x < 0)
    c->pos.x = 0;
  if (c->pos.x >= CRT_COLS)
    c->pos.x = CRT_COLS - 1;
  if (c->pos.y < 0)
    c->pos.y = 0;
  if (c->pos.y >= CRT_ROWS)
    c->pos.y = CRT_ROWS - 1;

  c->screen[CRT_ADDR (c->pos.y, c->pos.x)] = ca;

  c->sh.dir = 0;
}