-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootpack.c
156 lines (122 loc) · 3.15 KB
/
bootpack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>
#include "head.h"
struct FIFO8 keyfifo;
struct FIFO8 mousefifo;
struct MOUSE_DEC mdec;
void wait_KBC_sendready(void){
for(;;){
if( (io_in8(PORT_KEYSTA) & KEYSTA_SEND_NOTREADY) == 0)
break;
}
return;
}
void init_keyboard(void){
wait_KBC_sendready();
io_out8(PORT_KEYCMD, KEYCMD_WRITE_MODE);
wait_KBC_sendready();
io_out8(PORT_KEYDAT, KBC_MODE);
return;
}
void enable_mouse(struct MOUSE_DEC *mdec){
wait_KBC_sendready();
io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);
wait_KBC_sendready();
io_out8(PORT_KEYDAT, MOUSECMD_ENABLE);
mdec->phase=0;
return;
}
int mouse_decode(struct MOUSE_DEC *mdec, int data){
if(mdec->phase == 0){
if(data == 0xfa)
mdec->phase = 1;
return 0;
}else if(mdec->phase == 1){
if((data & 0xc8) == 0x08){
mdec->buf[0] = data;
mdec->phase = 2;
}
return 0;
}else if(mdec->phase == 2){
mdec->buf[1] = data;
mdec->phase = 3;
return 0;
}else if(mdec->phase == 3){
mdec->buf[2] = data;
mdec->phase = 1;
mdec->btn = mdec->buf[0] & 0x07;
mdec->x = mdec->buf[1];
mdec->y = mdec->buf[2];
if((mdec->buf[0] & 0x10) != 0)
mdec->x |= 0xffffff00;
if((mdec->buf[0] & 0x20) != 0)
mdec->y |= 0xffffff00;
mdec->y = -mdec->y;
return 1;
}
return -1;
}
void HariMain(void){
char *vram;
int xsize, ysize;
struct BOOTINFO *binfo;
char mcursor[16*8];
char s[30];
unsigned char data;
char keybuf[KEYBUF_LEN];
char mousebuf[MOUSEBUF_LEN];
fifo8_init(&keyfifo, KEYBUF_LEN, keybuf);
fifo8_init(&mousefifo, MOUSEBUF_LEN, mousebuf);
binfo = (struct BOOTINFO*) ADR_BOOTINFO;
xsize = binfo->scrnx;
ysize = binfo->scrny;
vram = binfo->vram;
init_gdtidt();
init_pic();
io_sti();
init_palette();
init_screen8(vram, xsize, ysize);
putfonts8_asc(binfo->vram, binfo->scrnx, 8, 8, col_white, "Hello World");
init_mouse_cursor8(mcursor, col_blue_l_d);
putblock8_8(binfo->vram, binfo->scrnx, 8, 16, 32, 32, mcursor, 8);
sprintf(s, "*scrnx = %d", binfo->scrnx);
putfonts8_asc(binfo->vram, binfo->scrnx, 16, 64, col_white, s);
io_out8(PIC0_IMR, 0xf9); /* PIC1‚ƃL[ƒ{[ƒh‚ð‹–‰Â(11111001) */
io_out8(PIC1_IMR, 0xef); /* ƒ}ƒEƒX‚ð‹–‰Â(11101111) */
init_keyboard();
enable_mouse(&mdec);
for( ; ; )
{
io_cli();
if(fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0)
io_stihlt();
else{
if(fifo8_status(&keyfifo) != 0){
data = fifo8_get(&keyfifo);
io_sti();
sprintf(s, "%02X", data);
boxfill8(binfo->vram, binfo->scrnx, col_blue_l_d, 0, 16, 15, 31);
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, col_white, s);
}
if(fifo8_status(&mousefifo) != 0){
data = fifo8_get(&mousefifo);
io_sti();
if(mouse_decode(&mdec, data) == 1){
sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y);
if((mdec.btn & 0x01) != 0)
s[1] = 'L';
if((mdec.btn & 0x02) != 0)
s[2] = 'R';
if((mdec.btn & 0x04) != 0)
s[3] = 'C';
boxfill8(binfo->vram, binfo->scrnx, col_blue_l_d, 32, 16, 32 + 15*8-1, 31);
putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, col_white, s);
}
}
}
}
// io_hlt();
}
// 14, 8,7,8,7,7,15,15,0,0,15,15,7,7
// col_white, col_gray
// col_black
// col_blue_l_d, col_gray_d