chiark / gitweb /
bc58a5d82148eb88dd63e6649f7cb40a942cf1cb
[sympathy.git] / src / crt.h
1 /*
2  * crt.h:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 /*
10  * $Id$
11  */
12
13 /*
14  * $Log$
15  * Revision 1.13  2008/02/27 09:42:22  james
16  * *** empty log message ***
17  *
18  * Revision 1.12  2008/02/26 23:23:17  james
19  * *** empty log message ***
20  *
21  * Revision 1.11  2008/02/26 19:08:27  james
22  * *** empty log message ***
23  *
24  * Revision 1.10  2008/02/24 00:42:53  james
25  * *** empty log message ***
26  *
27  * Revision 1.9  2008/02/20 19:25:09  james
28  * *** empty log message ***
29  *
30  * Revision 1.8  2008/02/13 09:12:21  james
31  * *** empty log message ***
32  *
33  * Revision 1.7  2008/02/13 01:08:18  james
34  * *** empty log message ***
35  *
36  * Revision 1.6  2008/02/07 13:22:51  james
37  * *** empty log message ***
38  *
39  * Revision 1.5  2008/02/07 12:41:06  james
40  * *** empty log message ***
41  *
42  * Revision 1.4  2008/02/07 12:16:04  james
43  * *** empty log message ***
44  *
45  * Revision 1.3  2008/02/06 11:30:37  james
46  * *** empty log message ***
47  *
48  * Revision 1.2  2008/02/04 20:23:55  james
49  * *** empty log message ***
50  *
51  * Revision 1.1  2008/02/03 23:31:25  james
52  * *** empty log message ***
53  *
54  */
55
56 #ifndef __CRT_H__
57 #define __CRT_H__
58
59 #define CRT_ROWS 25
60 #define CRT_COLS 132
61
62 #define CRT_CELS (CRT_ROWS*CRT_COLS)
63 #define CRT_ADDR(r,c) (((r)*CRT_COLS)+(c))
64 #define CRT_ADDR_POS(p) ((((p)->y)*CRT_COLS)+((p)->x))
65
66 #define CRT_ATTR_NORMAL    0x0
67 #define CRT_ATTR_UNDERLINE 0x1
68 #define CRT_ATTR_REVERSE   0x2
69 #define CRT_ATTR_BLINK     0x4
70 #define CRT_ATTR_BOLD      0x8
71
72
73 #define CRT_COLOR_BLACK         0x0
74 #define CRT_COLOR_RED           0x1
75 #define CRT_COLOR_GREEN         0x2
76 #define CRT_COLOR_YELLOW        0x3
77 #define CRT_COLOR_BLUE          0x4
78 #define CRT_COLOR_MAGENTA       0x5
79 #define CRT_COLOR_CYAN          0x6
80 #define CRT_COLOR_WHITE         0x7
81 #define CRT_COLOR_INTENSITY     0x8
82
83 #define CRT_COLOR_FG_MASK       0xf0
84 #define CRT_COLOR_FG_SHIFT      4
85
86 #define CRT_COLOR_BG_MASK       0xf
87 #define CRT_COLOR_BG_SHIFT      0
88
89 #define CRT_COLOR_BG(a)         (((a) & CRT_COLOR_BG_MASK) >> CRT_COLOR_BG_SHIFT)
90 #define CRT_COLOR_FG(a)         (((a) & CRT_COLOR_FG_MASK) >> CRT_COLOR_FG_SHIFT)
91
92 #define CRT_MAKE_COLOR(f,b)     (((f) << CRT_COLOR_FG_SHIFT)|(b))
93
94 #define CRT_BGCOLOR_NORMAL      CRT_COLOR_BLACK
95 #define CRT_FGCOLOR_NORMAL      CRT_COLOR_WHITE
96
97 #define CRT_COLOR_NORMAL        CRT_MAKE_COLOR(CRT_FGCOLOR_NORMAL,CRT_BGCOLOR_NORMAL)
98
99 typedef struct __attribute__ ((packed))
100 {
101   uint32_t chr;
102   uint8_t attr;
103   uint8_t color;
104 } CRT_CA;
105
106 typedef struct
107 {
108   int x;
109   int y;
110 } CRT_Pos;
111
112
113 typedef struct
114 {
115   CRT_Pos s;
116   CRT_Pos e;
117   int dir;
118 } CRT_ScrollHint;
119
120 typedef struct CRT_struct
121 {
122   CRT_CA screen[CRT_CELS];
123   CRT_Pos pos;
124   int hide_cursor;
125   CRT_Pos size;
126 } CRT;
127
128
129 static inline
130 crt_ca_cmp (CRT_CA a, CRT_CA b)
131 {
132   return memcmp (&a, &b, sizeof (a));
133 }
134
135 static inline
136 crt_pos_cmp (CRT_Pos a, CRT_Pos b)
137 {
138   return memcmp (&a, &b, sizeof (a));
139 }
140
141 #endif /* __CRT_H__ */