|
|
1.1 root 1: #include "u.h"
2: #include "lib.h"
3: #include "mem.h"
4: #include "dat.h"
5: #include "fns.h"
6:
7: #define WIDTH 160
8: #define HEIGHT 24
9: #define SCREEN ((char *)(0xB8000|KZERO))
10: #define ATTR 0x02
11:
12: static int inited;
13: static int pos;
14:
15: static uchar
16: cgaregr(uchar index)
17: {
18: outb(0x03D4, index);
19: return inb(0x03D4+1);
20: }
21:
22: static void
23: cgaregw(uchar index, uchar data)
24: {
25: outb(0x03D4, index);
26: outb(0x03D4+1, data);
27: }
28:
29: static void
30: clearline(int lineno)
31: {
32: char *p;
33: int i;
34:
35: p = &SCREEN[WIDTH*lineno];
36: for(i = 0; i < WIDTH; i += 2){
37: *p++ = 0x00;
38: *p++ = ATTR;
39: }
40: }
41:
42: static void
43: movecursor(void)
44: {
45: cgaregw(0x0E, (pos/2>>8) & 0xFF);
46: cgaregw(0x0F, pos/2 & 0xFF);
47: }
48:
49: void
50: cgainit(void)
51: {
52: int i;
53:
54: for(i = pos/WIDTH; i < HEIGHT; i++)
55: clearline(i);
56: movecursor();
57: inited = 1;
58: }
59:
60: static void
61: cgaputc(int c)
62: {
63: int i;
64:
65: if(c == '\n'){
66: if(inited == 0){
67: for(i = (pos % WIDTH); i < WIDTH; i += 2)
68: cgaputc(' ');
69: }
70: else{
71: pos = pos/WIDTH;
72: pos = (pos+1)*WIDTH;
73: }
74: } else if(c == '\t'){
75: i = 4 - ((pos/2)&3);
76: while(i-->0)
77: cgaputc(' ');
78: } else if(c == '\b'){
79: if(pos >= 2)
80: pos -= 2;
81: cgaputc(' ');
82: pos -= 2;
83: } else {
84: SCREEN[pos++] = c;
85: SCREEN[pos++] = ATTR;
86: }
87: if(pos >= WIDTH*HEIGHT){
88: memmove(SCREEN, &SCREEN[WIDTH], WIDTH*(HEIGHT-1));
89: clearline(HEIGHT-1);
90: pos = WIDTH*(HEIGHT-1);
91: }
92: movecursor();
93: }
94:
95: void
96: cgaputs(IOQ*, char *s, int n)
97: {
98: while(n-- > 0)
99: cgaputc(*s++);
100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.