31 for (
int rw = 1; rw < 25; rw++) {
32 for (
int cl = 0; cl < 80; cl++) {
33 int src = rw * 80 + cl;
34 int dst = (rw - 1) * 80 + cl;
38 for (
int cl = 0; cl < 80; cl++) {
39 int btm = 24 * 80 + cl;
40 vga[btm] = (0x0F << 8) |
' ';
64 if (x >= 80) { x = 79; };
65 if (x < 0) { x = 0; };
66 if (y >= 25 && x == 0) {
69 }
else if (y >= 25 && x > 0) { y = 24; }
70 if (y < 0) { y = 0; };
74 int ofst = y * 80 + x;
77 assert(ofst >= 0 && ofst < 2000,
"prt: vga buffer overflow");
84 vga[ofst] = (col << 8) | *txt;
141 prt(x, y, buff, col);
163 static const char chars[] =
"0123456789ABCDEF";
166 output[0] = chars[(hex >> 28) & 0xF];
167 output[1] = chars[(hex >> 24) & 0xF];
168 output[2] = chars[(hex >> 20) & 0xF];
169 output[3] = chars[(hex >> 16) & 0xF];
170 output[4] = chars[(hex >> 12) & 0xF];
171 output[5] = chars[(hex >> 8) & 0xF];
172 output[6] = chars[(hex >> 4) & 0xF];
173 output[7] = chars[hex & 0xF];
176 prt(x, y, output, col);
194 for (
int ctr = 0; ctr < 2000; ctr++) {
195 vga[ctr] = (0x0F << 8) |
' ';
218 assert(maxlen > 0,
"rdln: maxlen zero");
241 else if (nchr ==
'\b' && pos > 0) {
243 prt(cx - 1, cy,
" ", 0x0F);
248 else if (nchr >=
' ' && pos < maxlen - 1) {
249 buffer[pos] = (char)nchr;
251 char chr[2] = {(char)nchr, 0};
252 prt(cx, cy, chr, 0x0F);
282 assert(x1 >= 0 && x1 < 80,
"drw: invalid x1");
283 assert(y1 >= 0 && y1 < 25,
"drw: invalid y1");
284 assert(x2 >= 0 && x2 < 80,
"drw: invalid x2");
285 assert(y2 >= 0 && y2 < 25,
"drw: invalid y2");
292 int start = (x1 < x2) ? x1 : x2;
293 int end = (x1 > x2) ? x1 : x2;
294 for (tx = start; tx <= end; tx++) {
295 prt(tx, y1,
"#", col);
300 int start = (y1 < y2) ? y1 : y2;
301 int end = (y1 > y2) ? y1 : y2;
302 for (ty = start; ty <= end; ty++) {
303 prt(x1, ty,
"#", col);
308 int dx =
abs(x2 - x1);
309 int dy =
abs(y2 - y1);
310 int sx = (x1 < x2) ? 1 : -1;
311 int sy = (y1 < y2) ? 1 : -1;
318 prt(tx, ty,
"#", col);
319 if (tx == x2 && ty == y2)
break;
353 char str[2] = {chr, 0};
void itoa(int num, char *str)
itoa converts an integer to a decimal string
void __prtd(int x, int y, int num, uint8_t col)
prtd prints a decimal integer to the vga screen
void __scrl(void)
scrl scrolls the vga text screen up by one row
void __drw(int x1, int y1, int x2, int y2, uint8_t col)
drw draws a line on the vga screen using '#' characters
uint16_t * vga
the vga framebuffer pointer
void __rdln(char *buffer, int maxlen)
rdln reads a line of text input from the keyboard
void __pchr(int x, int y, char chr, uint8_t col)
pchr prints a single raw character to the vga screen
void __prt(int x, int y, const char *txt, uint8_t col)
prt prints a string to the vga screen at a given position
void __clscr(void)
clscr clears the entire vga text screen
void __prth(int x, int y, uint32_t hex, uint8_t col)
prth prints a 32 bit hex value to the vga screen