void tty_putc(int wno, char c) /* print one character on the screen */ { int t; switch(c) { case '\r': /* -> carriage return */ window_info[wno].xpos = 0; break; case '\n': /* -> newline (with implicit cr) */ window_info[wno].xpos = 0; window_info[wno].ypos++; break; case 8: /* -> backspace */ t = window_info[wno].xpos + window_info[wno].ypos * window_info[wno].width; /* get linear address */ if(t > 0) t--; /* if not in home position, step back */ if(window_info[wno].xpos > 0) { window_info[wno].xpos--; } else if(window_info[wno].ypos > 0) { window_info[wno].ypos--; window_info[wno].xpos = window_info[wno].width - 1; } *(window_info[wno].buf + ((t / window_info[wno].width) * scrwidth) + ((t % window_info[wno].width))) = ' ' | (window_info[wno].colour << 8); /* put space under the cursor */ break; default: /* -> all other characters */ if(c < ' ') break; /* ignore non printable ascii chars */ t = window_info[wno].xpos + window_info[wno].ypos * window_info[wno].width; *(window_info[wno].buf + ((t / window_info[wno].width) * scrwidth) + ((t % window_info[wno].width))) = c | (window_info[wno].colour << 8); window_info[wno].xpos++; /* step cursor one character */ if(window_info[wno].xpos == window_info[wno].width) /* to next line if required */ { window_info[wno].xpos = 0; window_info[wno].ypos++; } break; } if(window_info[wno].ypos == window_info[wno].height) /* the cursor moved off of the screen? */ { tty_scrollup(wno); /* scroll the screen up */ window_info[wno].ypos--; /* and move the cursor back */ } /* and finally, set the cursor */ if (window_info[wno].movcursor == TRUE) { tty_setcursor(wno, window_info[wno].xpos, window_info[wno].ypos); } }
void cls(int wno) /* clear the screen by filling it with spaces */ { int t; for(t = 0; t < window_info[wno].width * window_info[wno].height; t++) /* clear the screen */ { *(window_info[wno].buf + ((t / window_info[wno].width) * scrwidth) + ((t % window_info[wno].width))) = ' ' | (window_info[wno].colour << 8); } window_info[wno].xpos = 0; window_info[wno].ypos = 0; /* set cursor to home location */ if (window_info[wno].movcursor == TRUE) { tty_setcursor(wno, 0, 0); /* call the hw. cursor setup */ } }
void tty_updatecursor() { tty_setcursor(tty_x, tty_y); }
void gotoxy(int wno, unsigned x, unsigned y) { window_info[wno].xpos = x; window_info[wno].ypos = y; /* set cursor to home location */ tty_setcursor(wno, x, y); /* call the hw. cursor setup */ }