Subversion Repositories Shiroi

Rev

Details | Last modification | View Log | RSS feed

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