summaryrefslogtreecommitdiff
path: root/terminal
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-17 17:14:07 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-17 17:14:07 +0200
commit29ea3208b004f15dafa48ae29a75ba7f0c093a74 (patch)
treebc39ac9b187753e9a16dbac5bf9c2523b32097f9 /terminal
parent819a4e871058f2dc4a2e255ecbe5a2c49cc8450c (diff)
working on vt52 layer
Diffstat (limited to 'terminal')
-rw-r--r--terminal/vt52.c92
-rw-r--r--terminal/vt52.h33
2 files changed, 79 insertions, 46 deletions
diff --git a/terminal/vt52.c b/terminal/vt52.c
index 1dc7289..4a9cb0a 100644
--- a/terminal/vt52.c
+++ b/terminal/vt52.c
@@ -1,50 +1,39 @@
//
// 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 "vt52.h"
#include "kernel/kmalloc.h"
+
//TODO: check?
#define VT52_WIDTH 80
-#define VT52_HEIGHT 24
+#define VT52_HEIGHT 25
#define VT52_ESC 0x33
-typedef struct vt52_tty_struct
+static uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y)
{
+ return tty->width*y+x;
+}
- uint32_t width;
- uint32_t height;
- uint32_t x;
- uint32_t y;
- uint32_t *data; // screen data
-
-}vt52_tty;
-
+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()
+vt52_tty vt52_init(term_screen *screen)
{
+
vt52_tty tty;
tty.data=kballoc(1);
+ tty.screen=screen;
tty.x=0;
tty.y=0;
@@ -52,25 +41,34 @@ vt52_tty vt52_init()
tty.width=VT52_WIDTH;
tty.height=VT52_HEIGHT;
+ clear(&tty);
+
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)
+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 put(vt52_tty *tty, uint8_t c)
-{
- set_char(tty,tty->x,tty->y,c);
+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)
+ if(tty->x>=tty->width)
{
tty->x=0;
tty->y++;
@@ -80,17 +78,19 @@ void put(vt52_tty *tty, uint8_t c)
if(tty->y>=tty->height)
{
tty->y--;
- for(uint32_t l=tty->y; l>0; l--)
+ for(uint32_t y=0;y<tty->height;y++)
{
- for(uint32_t x=0;x<tty->width;x++)
+ for(uint32_t x=0;x<tty->width-1;x++)
{
- tty->data[index(tty,x,l-1)] = tty->data[index(tty,x,l)];
+ 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++)
+ {
+ }
+ }
+}
diff --git a/terminal/vt52.h b/terminal/vt52.h
new file mode 100644
index 0000000..557c247
--- /dev/null
+++ b/terminal/vt52.h
@@ -0,0 +1,33 @@
+#ifndef VT52_H
+#define VT52_H
+
+#include <stdint.h>
+
+
+// REQUIREMENTS
+// * kballoc // block wise in-kernel allocation
+
+
+typedef struct term_screen_struct
+{
+
+ void (*put_char)(uint8_t c,uint8_t color, uint32_t x, uint32_t y);
+
+}term_screen;
+
+typedef struct vt52_tty_struct
+{
+
+ uint32_t width;
+ uint32_t height;
+ uint32_t x;
+ uint32_t y;
+ uint32_t *data; // screen data
+ term_screen *screen;
+
+}vt52_tty;
+
+vt52_tty vt52_init(term_screen *screen);
+void vt52_put(vt52_tty *tty, uint8_t c);
+
+#endif