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
//
//
//
// ------------
// PROG <---> | VT 52 | <--- Keyboard
// | | ---> Screen
// ------------
// Interface:
//
// struct vt52_tty_struct; // TODO: check what is better to put in header!
// vt52_tty vt52_init();
// put(vt52_tty *tty, uint8_t c);
//
//
// REQUIREMENTS
// * kballoc // block wise in-kernel allocation
#include <stdint.h>
#include "kernel/kmalloc.h"
//TODO: check?
#define VT52_WIDTH 80
#define VT52_HEIGHT 24
#define VT52_ESC 0x33
typedef struct vt52_tty_struct
{
uint32_t width;
uint32_t height;
uint32_t x;
uint32_t y;
uint32_t *data; // screen data
}vt52_tty;
vt52_tty vt52_init()
{
vt52_tty tty;
tty.data=kballoc(1);
tty.x=0;
tty.y=0;
tty.width=VT52_WIDTH;
tty.height=VT52_HEIGHT;
return tty;
}
uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y)
{
return tty->width*y+x;
}
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 put(vt52_tty *tty, uint8_t c)
{
set_char(tty,tty->x,tty->y,c);
if(tty->x>tty->width)
{
tty->x=0;
tty->y++;
}
//autoscroll
if(tty->y>=tty->height)
{
tty->y--;
for(uint32_t l=tty->y; l>0; l--)
{
for(uint32_t x=0;x<tty->width;x++)
{
tty->data[index(tty,x,l-1)] = tty->data[index(tty,x,l)];
}
}
}
}
|