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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
//
// http://en.wikipedia.org/wiki/VT52
//
#include "vt52.h"
#include "kernel/kmalloc.h"
//TODO: check?
#define VT52_WIDTH 80
#define VT52_HEIGHT 25
#define VT52_ESC 0x33
static uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y)
{
return tty->width*y+x;
}
static void clear(vt52_tty *tty)
{
for(int x=0;x<tty->width;x++)
for(int y=0;y<tty->height;y++)
{
tty->data[index(tty,x,y)]='.';
tty->screen->put_char('.',0xf,x,y);
}
}
vt52_tty vt52_init(term_screen *screen)
{
vt52_tty tty;
tty.data=kballoc(1);
tty.screen=screen;
tty.x=0;
tty.y=0;
tty.width=VT52_WIDTH;
tty.height=VT52_HEIGHT;
clear(&tty);
return tty;
}
static void set_char(vt52_tty *tty, uint32_t x, uint32_t y, uint32_t c)
{
tty->data[index(tty,x,y)]=c;
}
// send one ASCII character to the terminal
void vt52_put(vt52_tty *tty, uint8_t c)
{
if(c!='\n')
{
tty->data[index(tty,tty->x,tty->y)]=c;
tty->screen->put_char(c,0xf,tty->x,tty->y);
}
else
{
tty->y++;
tty->x=0;
}
tty->x++;
if(tty->x>=tty->width)
{
tty->x=0;
tty->y++;
}
//autoscroll
if(tty->y>=tty->height)
{
tty->y--;
for(uint32_t y=0;y<tty->height;y++)
{
for(uint32_t x=0;x<tty->width-1;x++)
{
uint32_t c=tty->data[index(tty,x,y+1)];
tty->data[index(tty,x,y)] = c;
tty->screen->put_char(c,0xf,x,y);
}
}
for(uint32_t x=0;x<tty->width;x++)
{
}
}
}
|