blob: a3019880e01f4f5a0e2f0350a656e95d8a9e1524 [file] [log] [blame]
Martin Roth9b1b3352016-02-24 12:27:06 -08001/* screen_buffer.c - MemTest-86 Version 3.3
2 *
3 * Released under version 2 of the Gnu Public License.
4 * By Jani Averbach, Jaa@iki.fi, 2001
5 */
6
7#include "test.h"
8#include "screen_buffer.h"
9
10#define SCREEN_X 80
11#define SCREEN_Y 25
12#define Y_SIZE SCREEN_Y
13/*
Martin Roth4dcd13d2016-02-24 13:53:07 -080014 * X-size should by one of by screen size,
Martin Roth9b1b3352016-02-24 12:27:06 -080015 * so that there is room for ending '\0'
16 */
17#define X_SIZE SCREEN_X+1
18
19static char screen_buf[Y_SIZE][X_SIZE];
20
21#ifdef SCRN_DEBUG
22
23char *padding = "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
24
25#define CHECK_BOUNDS(y,x) do {if (y < 0 || Y_SIZE <= y || x < 0 || X_SIZE <= x) print_error("out of index");}while(0)
26
27#else /* ! SCRN_DEBUG */
28
29#define CHECK_BOUNDS(y,x)
30
31#endif /* SCRN_DEBUG */
32
33char
34get_scrn_buf(const int y,
35 const int x)
36{
37 CHECK_BOUNDS(y,x);
38 return screen_buf[y][x];
39}
40
41
42void
43set_scrn_buf(const int y,
44 const int x,
45 const char val)
46{
47 CHECK_BOUNDS(y,x);
48 screen_buf[y][x] = val;
49}
50
51void clear_screen_buf()
52{
53 int y, x;
54
55 for (y=0; y < SCREEN_Y; ++y){
56 for (x=0; x < SCREEN_X; ++x){
57 CHECK_BOUNDS(y,x);
58 screen_buf[y][x] = ' ';
59 }
60 CHECK_BOUNDS(y,SCREEN_X);
61 screen_buf[y][SCREEN_X] = '\0';
62 }
63}
64
Martin Roth4dcd13d2016-02-24 13:53:07 -080065void tty_print_region(const int pi_top,
Martin Roth9b1b3352016-02-24 12:27:06 -080066 const int pi_left,
67 const int pi_bottom,
68 const int pi_right)
69{
70 int y;
71 char tmp;
72
73 for (y=pi_top; y < pi_bottom; ++y){
74 CHECK_BOUNDS(y, pi_right);
Martin Roth4dcd13d2016-02-24 13:53:07 -080075
Martin Roth9b1b3352016-02-24 12:27:06 -080076 tmp = screen_buf[y][pi_right];
77 screen_buf[y][pi_right] = '\0';
78
79 CHECK_BOUNDS(y, pi_left);
Martin Roth4dcd13d2016-02-24 13:53:07 -080080 ttyprint(y, pi_left, &(screen_buf[y][pi_left]));
Martin Roth9b1b3352016-02-24 12:27:06 -080081
82 screen_buf[y][pi_right] = tmp;
83 }
84}
85
86void tty_print_line(
87 int y, int x, const char *text)
88{
89 for(; *text && (x < SCREEN_X); x++, text++) {
90 if (*text != screen_buf[y][x]) {
91 break;
92 }
93 }
94 /* If there is nothing to do return */
95 if (*text == '\0') {
96 return;
97 }
98 ttyprint(y, x, text);
99 for(; *text && (x < SCREEN_X); x++, text++) {
100 screen_buf[y][x] = *text;
101 }
102}
103
104
105void tty_print_screen(void)
106{
107#ifdef SCRN_DEBUG
Martin Roth4dcd13d2016-02-24 13:53:07 -0800108 int i;
Martin Roth9b1b3352016-02-24 12:27:06 -0800109
110 for (i=0; i < SCREEN_Y; ++i)
111 ttyprint(i,0, padding);
112#endif /* SCRN_DEBUG */
113
114 tty_print_region(0, 0, SCREEN_Y, SCREEN_X);
115}
116
117void print_error(char *pstr)
118{
119
120#ifdef SCRN_DEBUG
121 ttyprint(0,0, padding);
122#endif /* SCRN_DEBUG */
123
Martin Roth4dcd13d2016-02-24 13:53:07 -0800124 ttyprint(0,35, pstr);
125
Martin Roth9b1b3352016-02-24 12:27:06 -0800126 while(1);
127}