6 template <
unsigned int scr_base_uint = 0xD000,
7 unsigned int video_ram_size = 0x400,
8 unsigned int screen_width = 0x1B,
9 unsigned int screen_height = 0x1B,
10 unsigned int screen_firstchar =
12 unsigned int scroll_dist =
17 static unsigned char cursor_x;
18 static unsigned char cursor_y;
20 static constexpr
unsigned int scroll_length(
void) {
21 return (screen_height - 1) * scroll_dist;
24 static constexpr
char *scr_base(
void) {
return (
char *)scr_base_uint; }
26 static char *cursor_pos_mem(
void) {
27 return scr_base() + screen_firstchar + cursor_y * scroll_dist + cursor_x;
30 static void newline(
void) {
33 if (cursor_y == screen_height) {
37 char *
const scr_firstchar_addr = scr_base() + screen_firstchar;
38 char *
const scroll_dest = scr_firstchar_addr;
39 char *
const scroll_src = scr_firstchar_addr + scroll_dist;
41 memmove(scroll_dest, scroll_src, scroll_length());
44 char *
const last_line_start = scr_firstchar_addr + scroll_length();
47 memset(last_line_start,
' ', screen_width);
52 static void clrscr(
void) {
53 memset((
void *)scr_base(),
' ', video_ram_size);
54 cursor_x = cursor_y = 0;
57 static void cputc(
char c) {
60 }
else if (
c ==
'\r') {
63 char *
const dest = cursor_pos_mem();
65 if (cursor_x >= screen_width - 1) {
75 extern "C" void __putchar(
char c);
77 #endif // _OSI_SCREEN_H