/
pixel.h
82 lines (57 loc) · 1.35 KB
/
pixel.h
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
#ifndef PIXEL_H
#define PIXEL_H
#define LINEBYTES (((NUM_COLS-1)/8)+1)
extern unsigned char shl_table[];
extern unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES];
typedef struct {
unsigned char x;
unsigned char y;
} pixel;
enum direction{
up,
right,
down,
left
};
#ifdef NDEBUG
typedef unsigned char direction_t;
#else
typedef enum direction direction_t;
#endif
enum pixelmode{
clear,
set
};
#ifdef NDEBUG
typedef unsigned char pixelmode_t;
#else
typedef enum pixelmode pixelmode_t;
#endif
typedef struct cursor{
pixel pos;
direction_t dir;
pixelmode_t mode;
} cursor_t;
/****************************************************************************
* Pixel routines
*/
unsigned char get_pixel(pixel p);
inline static pixel next_pixel(pixel pix, direction_t dir){
static char const nDelta[] = {0, -1, 0, 1, 0};
return (pixel){pix.x + nDelta[dir], pix.y + nDelta[dir + 1]};
}
inline static unsigned char get_next_pixel(pixel p, direction_t dir){
return get_pixel(next_pixel(p, dir));
}
inline static direction_t direction_r(direction_t dir){
return (dir + 1u) % 4u;
}
void clear_screen(unsigned char value);
void setpixel(pixel p, unsigned char value);
#define clearpixel(p) setpixel(p, 0);
void shift_pixmap_l();
static inline void set_cursor(cursor_t* cur, pixel p){
cur->pos = p;
setpixel(p, cur->mode ? 3 : 0);
}
#endif // PIXEL_H