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

/*
 * $Id$
 */

/*
 * $Log$
 * Revision 1.12  2008/02/26 23:23:17  james
 * *** empty log message ***
 *
 * Revision 1.11  2008/02/26 19:08:27  james
 * *** empty log message ***
 *
 * Revision 1.10  2008/02/24 00:42:53  james
 * *** empty log message ***
 *
 * Revision 1.9  2008/02/20 19:25:09  james
 * *** empty log message ***
 *
 * Revision 1.8  2008/02/13 09:12:21  james
 * *** empty log message ***
 *
 * Revision 1.7  2008/02/13 01:08:18  james
 * *** empty log message ***
 *
 * Revision 1.6  2008/02/07 13:22:51  james
 * *** empty log message ***
 *
 * Revision 1.5  2008/02/07 12:41:06  james
 * *** empty log message ***
 *
 * Revision 1.4  2008/02/07 12:16:04  james
 * *** empty log message ***
 *
 * Revision 1.3  2008/02/06 11:30:37  james
 * *** empty log message ***
 *
 * Revision 1.2  2008/02/04 20:23:55  james
 * *** empty log message ***
 *
 * Revision 1.1  2008/02/03 23:31:25  james
 * *** empty log message ***
 *
 */

#ifndef __CRT_H__
#define __CRT_H__

#define CRT_ROWS 25
#define CRT_COLS 132

#define CRT_CELS (CRT_ROWS*CRT_COLS)
#define CRT_ADDR(r,c) (((r)*CRT_COLS)+(c))
#define CRT_ADDR_POS(p) ((((p)->y)*CRT_COLS)+((p)->x))

#define CRT_ATTR_NORMAL    0x0
#define CRT_ATTR_UNDERLINE 0x1
#define CRT_ATTR_REVERSE   0x2
#define CRT_ATTR_BLINK	   0x4
#define CRT_ATTR_BOLD	   0x8


#define CRT_COLOR_BLACK		0x0
#define CRT_COLOR_RED		0x1
#define CRT_COLOR_GREEN		0x2
#define CRT_COLOR_YELLOW	0x3
#define CRT_COLOR_BLUE		0x4
#define CRT_COLOR_MAGENTA	0x5
#define CRT_COLOR_CYAN		0x6
#define CRT_COLOR_WHITE		0x7
#define CRT_COLOR_INTENSITY	0x8

#define CRT_COLOR_FG_MASK	0xf0
#define CRT_COLOR_FG_SHIFT	4

#define CRT_COLOR_BG_MASK	0xf
#define CRT_COLOR_BG_SHIFT	0

#define CRT_COLOR_BG(a)		(((a) & CRT_COLOR_BG_MASK) >> CRT_COLOR_BG_SHIFT)
#define CRT_COLOR_FG(a)		(((a) & CRT_COLOR_FG_MASK) >> CRT_COLOR_FG_SHIFT)

#define CRT_MAKE_COLOR(f,b)	(((f) << CRT_COLOR_FG_SHIFT)|(b))

#define CRT_BGCOLOR_NORMAL	CRT_COLOR_BLACK
#define CRT_FGCOLOR_NORMAL	CRT_COLOR_WHITE

#define CRT_COLOR_NORMAL	CRT_MAKE_COLOR(CRT_FGCOLOR_NORMAL,CRT_BGCOLOR_NORMAL)

typedef struct __attribute__ ((packed))
{
  uint32_t chr;
  uint8_t attr;
  uint8_t color;
} CRT_CA;

typedef struct
{
  int x;
  int y;
} CRT_Pos;


typedef struct
{
  CRT_Pos s;
  CRT_Pos e;
  int dir;
} CRT_ScrollHint;

typedef struct CRT_struct
{
  CRT_CA screen[CRT_CELS];
  CRT_Pos pos;
  int hide_cursor;
  int width;
} CRT;


static inline
crt_ca_cmp (CRT_CA a, CRT_CA b)
{
  return memcmp (&a, &b, sizeof (a));
}

static inline
crt_pos_cmp (CRT_Pos a, CRT_Pos b)
{
  return memcmp (&a, &b, sizeof (a));
}

#endif /* __CRT_H__ */