Subversion Repositories Shiroi

Rev

Rev 18 | Rev 20 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 nishi 1
/* $Id: text.c 19 2024-08-29 07:16:04Z nishi $ */
2
 
3
#include "text.h"
4
 
5
#include "video.h"
6
#include "math.h"
7
 
8
#include "../char.h"
9
#include "../io.h"
10
 
11
char caps;
12
 
13
unsigned short posx;
14
unsigned short posy;
15
unsigned short curx;
16
unsigned short cury;
17
unsigned char cursorcolor;
18
unsigned char cursorindex;
19
 
20
short text_kbd_data;
21
 
22
extern int scrwidth;
23
extern int scrheight;
24
 
25
extern unsigned char keylist[];
26
extern unsigned char keylist_caps[];
27
 
28
char agetch(void){
29
	char k;
30
rep:
31
	if((k = inp(text_kbd_data)) == 0) return 0;
32
	while(inp(text_kbd_data) != 0);
33
	unsigned char top = (k & 0xf0) >> 4;
34
	unsigned char bot = (k & 0x0f);
35
	top--;
36
	bot--;
37
	if(keylist[top * 13 + bot] == '!'){
38
		caps = caps == 0 ? 1 : 0;
39
		goto rep;
40
	}
41
	return caps ? keylist_caps[top * 13 + bot] : keylist[top * 13 + bot];
42
}
43
 
44
char getch(void){
45
	char k = 0;
46
rep:
47
	while((k = inp(text_kbd_data)) == 0);
48
	while(inp(text_kbd_data) != 0);
49
	unsigned char top = (k & 0xf0) >> 4;
50
	unsigned char bot = (k & 0x0f);
51
	top--;
52
	bot--;
53
	if(keylist[top * 13 + bot] == '!'){
54
		caps = caps == 0 ? 1 : 0;
55
		goto rep;
56
	}
57
	return caps ? keylist_caps[top * 13 + bot] : keylist[top * 13 + bot];
58
}
59
 
60
void clear(void){
61
	int i;
62
	int size = muli(scrwidth, scrheight);
63
	setvramaddr(0);
64
	for(i = 0; i < size; i++) vramchar(' ');
65
}
66
 
67
void print_ptr(void* ptr){
68
	unsigned short p = (unsigned short)ptr;
69
	int i;
70
	const char hex[] = "0123456789ABCDEF";
71
	putstr("0x");
72
	for(i = 0; i < 4; i++){
73
		putchar(hex[(p & 0xf000) >> 12]);
74
		p = p << 4;
75
	}
76
}
77
 
78
void cursor(void){
79
	setvramaddr(muli(posy, scrwidth) + posx);
80
	_vramchar(136 + 8 * cursorcolor);
81
	cursorindex++;
82
	if(cursorindex == 2){
83
		cursorcolor++;
84
		cursorindex = 0;
85
		if(cursorcolor == 15) cursorcolor = 0;
86
	}
87
	curx = posx;
88
	cury = posy;
89
	if(curx == scrwidth){
90
		curx = 0;
91
		cury++;
92
	}
93
}
94
 
95
void killcursor(void){
96
	setvramaddr(muli(cury, scrwidth) + curx);
97
	vramchar(' ');
98
}
99
 
100
void putchar(char c){
101
	if(c == '\r'){
102
		posx = 0;
103
	}else if(c == '\n'){
104
		posy++;
105
	}else{
106
		setvramaddr(muli(posy, scrwidth) + posx);
107
		vramchar(c);
108
		posx++;
109
		if(posx == scrwidth){
110
			posx = 0;
111
			posy++;
112
		}
113
	}
114
	if(posy == scrheight){
115
		scroll_y();
116
		posy = scrheight - 1;
117
		posx = 0;
118
	}
119
}
120
 
121
void putstr(char* str){
122
	int i;
123
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
124
}
125
 
126
void text_init(void){
127
	posx = 0;
128
	posy = 0;
129
	curx = 0;
130
	cury = 0;
131
	caps = 0;
132
	cursorcolor = 0;
133
	cursorindex = 0;
134
}
135
 
136
void text_card(int t, int port){
137
	if(t == 0x22){
138
		text_kbd_data = port - 2;
139
	}
140
}