Subversion Repositories Shiroi

Rev

Rev 19 | Rev 28 | 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 20 2024-08-31 06:50:57Z 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;
20 nishi 40
	}else if(keylist[top * 13 + bot] == '?'){
41
		return 1;
18 nishi 42
	}
43
	return caps ? keylist_caps[top * 13 + bot] : keylist[top * 13 + bot];
44
}
45
 
46
char getch(void){
47
	char k = 0;
48
rep:
49
	while((k = inp(text_kbd_data)) == 0);
50
	while(inp(text_kbd_data) != 0);
51
	unsigned char top = (k & 0xf0) >> 4;
52
	unsigned char bot = (k & 0x0f);
53
	top--;
54
	bot--;
55
	if(keylist[top * 13 + bot] == '!'){
56
		caps = caps == 0 ? 1 : 0;
57
		goto rep;
20 nishi 58
	}else if(keylist[top * 13 + bot] == '?'){
59
		return 1;
18 nishi 60
	}
61
	return caps ? keylist_caps[top * 13 + bot] : keylist[top * 13 + bot];
62
}
63
 
64
void clear(void){
65
	int i;
66
	int size = muli(scrwidth, scrheight);
67
	setvramaddr(0);
68
	for(i = 0; i < size; i++) vramchar(' ');
69
}
70
 
71
void print_ptr(void* ptr){
72
	unsigned short p = (unsigned short)ptr;
73
	int i;
74
	const char hex[] = "0123456789ABCDEF";
75
	putstr("0x");
76
	for(i = 0; i < 4; i++){
77
		putchar(hex[(p & 0xf000) >> 12]);
78
		p = p << 4;
79
	}
80
}
81
 
82
void cursor(void){
83
	setvramaddr(muli(posy, scrwidth) + posx);
84
	_vramchar(136 + 8 * cursorcolor);
85
	cursorindex++;
86
	if(cursorindex == 2){
87
		cursorcolor++;
88
		cursorindex = 0;
89
		if(cursorcolor == 15) cursorcolor = 0;
90
	}
91
	curx = posx;
92
	cury = posy;
93
	if(curx == scrwidth){
94
		curx = 0;
95
		cury++;
96
	}
97
}
98
 
99
void killcursor(void){
100
	setvramaddr(muli(cury, scrwidth) + curx);
101
	vramchar(' ');
102
}
103
 
104
void putchar(char c){
105
	if(c == '\r'){
106
		posx = 0;
107
	}else if(c == '\n'){
108
		posy++;
109
	}else{
110
		setvramaddr(muli(posy, scrwidth) + posx);
111
		vramchar(c);
112
		posx++;
113
		if(posx == scrwidth){
114
			posx = 0;
115
			posy++;
116
		}
117
	}
118
	if(posy == scrheight){
119
		scroll_y();
120
		posy = scrheight - 1;
121
		posx = 0;
122
	}
123
}
124
 
125
void putstr(char* str){
126
	int i;
127
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
128
}
129
 
130
void text_init(void){
131
	posx = 0;
132
	posy = 0;
133
	curx = 0;
134
	cury = 0;
135
	caps = 0;
136
	cursorcolor = 0;
137
	cursorindex = 0;
138
}
139
 
140
void text_card(int t, int port){
141
	if(t == 0x22){
142
		text_kbd_data = port - 2;
143
	}
144
}