aboutsummaryrefslogtreecommitdiffstats
path: root/src/crt.c
blob: 36011a986ba710cd936159e404f3987b9dc101d8 (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
/*
 * crt.c:
 *
 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

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

/*
 * $Log$
 * 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)
{
  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++;
    }

}

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);

#if 0
  for (i = 0; i < CRT_ROWS; ++i)
    {
      c->screen[CRT_ADDR (i, i)].chr = '@' + i;
      c->screen[CRT_ADDR (i, i)].attr = CRT_ATTR_NORMAL;
    }
#endif

}

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

  s.x=0;
  e.x=CRT_COLS-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);

}

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

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

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

  n = e.y - s.y;

  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);

}

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

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

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;



}