-
Notifications
You must be signed in to change notification settings - Fork 67
/
graphic.c
253 lines (239 loc) · 6.8 KB
/
graphic.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include"nasmfunc.h"
#include"memory.h"
#include"sheet.h"
#include"graphic.h"
#include<stdio.h>
void boxfillOnSht(struct Sheet *sht,int x0,int y0,int pxsize,int pysize,unsigned char c)
{
int i,j;
for (j=y0;j<y0+pysize;j++)
for (i=x0;i<x0+pxsize;i++)
sht->buffer[j*sht->xsize+i]=c;
}
void putfont8Onsht(struct Sheet *sht,int x,int y,char color,char c)
{
int i,j;
char tmp[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
char *font=fontlib+c*16;
for (i=0;i<16;i++)
for (j=0;j<8;j++)
if ((font[i]&tmp[j])!=0)
sht->buffer[(y+i)*sht->xsize+x+j]=color;
}
void putStrOnSht(struct Sheet *sht,int x,int y,char color,char *str)
{
char *t=str;
while (*t!=0x00)
{
putfont8Onsht(sht,x,y,color,*t);
x+=8;
t++;
}
}
void putStrAndBackOnSht(struct Sheet *sht,int x,int y,int color,int backcolor,char *str,int length)
{
boxfillOnSht(sht,x,y,length*8,16,backcolor);
putStrOnSht(sht,x,y,color,str);
refreshSubInSheet(sht,x,y,length*8,16);
}
void initMouseCursor(struct Sheet *sht)
{
//鼠标坐标图
static char cursor[18][17] = {
"****************",
"****************",
"**************..",
"*OOOOOOOOOOO*...",
"*OOOOOOOOOO*....",
"*OOOOOOOOO*.....",
"*OOOOOOOO*......",
"*OOOOOOO*.......",
"*OOOOOOO*.......",
"*OOOOOOOO*......",
"*OOOO**OOO*.....",
"*OOO*..*OOO*....",
"*OO*....*OOO*...",
"*O*......*OOO*..",
"**........*OOO*.",
"*..........*OOO*",
"............*OO*",
".............***"
};
//此处无法理解,前两层为何无法显示,故跳过
for(int i=0;i<16;i++)
for (int j=0;j<16;j++)
switch(cursor[i+2][j])
{
case '*':
sht->buffer[i*16+j]=BLACK;
break;
case 'O':
sht->buffer[i*16+j]=WHITE;
break;
default:
sht->buffer[i*16+j]=sht->col_inv;
}
}
void putBlockOnSht(struct Sheet *sht,int x0,int y0,int pxsize,int pysize,char *block)
{
for (int y=0;y<pysize;y++)
for (int x=0;x<pxsize;x++)
if (block[y*pxsize+x]>=0)
sht->buffer[(y0+y)*sht->xsize+x0+x]=block[y*pxsize+x];
}
void initPalette()
{
static unsigned char table_rgb[16][3] =
{
{0x00, 0x00, 0x00}, //黑
{0xff, 0x00, 0x00}, //亮红
{0x00, 0xff, 0x00}, //亮绿
{0xff, 0xff, 0x00}, //亮黄
{0x00, 0x00, 0xff}, //亮蓝
{0xff, 0x00, 0xff}, //亮紫
{0x00, 0xff, 0xff}, //浅亮蓝
{0xff, 0xff, 0xff}, //白
{0xc6, 0xc6, 0xc6}, //亮灰
{0x84, 0x00, 0x00}, //暗红
{0x00, 0x84, 0x00}, //暗绿
{0x84, 0x84, 0x00}, //暗黄
{0x00, 0x00, 0x84}, //暗青
{0x84, 0x00, 0x84}, //暗紫
{0x00, 0x84, 0x84}, //浅暗蓝
{0x84, 0x84, 0x84} //暗灰
};
setPalette(0, 15, table_rgb);
return;
}
void setPalette(int start,int end,unsigned char rgb[16][3])
{
int i,eflags;
eflags=io_load_eflags();
io_cli();
io_out8(0x03c8,start);//从0号调色板开始设定
for (i=start;i<=end;i++)
{
//按RGB写入,调色板号码自动后移
io_out8(0x03c9,rgb[i][0]/4);//除4是为了改变深浅
io_out8(0x03c9,rgb[i][1]/4);
io_out8(0x03c9,rgb[i][2]/4);
}
io_store_eflags(eflags);
}
void initScreenOnSht(struct Sheet *sht)
{
//char *vram=sht->buffer;
int x=sht->xsize;
int y=sht->ysize;
//画任务框
boxfillOnSht(sht,0,0,x,y-28,LIGHTBLUE);
boxfillOnSht(sht,0,y-28,x,1,LIGHTGRAY);
boxfillOnSht(sht,0,y-27,x,1,LIGHTGRAY);
boxfillOnSht(sht,0,y-26,x,26,WHITE);
boxfillOnSht(sht,3,y-24,57,1,WHITE);
boxfillOnSht(sht,2,y-24,1,21,WHITE);
boxfillOnSht(sht,3,y-4,57,1,DULLGRAY);
boxfillOnSht(sht,59,y-23,1,19,DULLGRAY);
boxfillOnSht(sht,2,y-3,58,1,BLACK);
boxfillOnSht(sht,60,y-24,1,22,BLACK);
boxfillOnSht(sht,x-47,y-24,44,1,DULLGRAY);
boxfillOnSht(sht,x-47,y-23,1,20,DULLGRAY);
boxfillOnSht(sht,x-47,y-3,44,1,WHITE);
boxfillOnSht(sht,x-3,y-24,1,22,WHITE);
return;
}
void putfont8OnSrn(struct BootInfo *binfo,int x,int y,char color,char c)
{
int i,j;
char tmp[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
char *font=fontlib+c*16;
for (i=0;i<16;i++)
for (j=0;j<8;j++)
if ((font[i]&tmp[j])!=0)
binfo->vram[(y+i)*binfo->scrnx+x+j]=color;
}
void putStrOnSrn(struct BootInfo *binfo,int x,int y,char color,char *str)
{
char *t=str;
while (*t!=0x00)
{
putfont8OnSrn(binfo,x,y,color,*t);
x+=8;
t++;
}
}
void makeWindow(struct Sheet *sht,int xsize,int ysize,char *title)
{
//boxfillOnSht(sht,0,0,xsize,ysize,LIGHTRED);
static char closebtn[14][16] =
{
"OOOOOOOOOOOOOOO@",
"OQQQQQQQQQQQQQ$@",
"OQQQQQQQQQQQQQ$@",
"OQQQ@@QQQQ@@QQ$@",
"OQQQQ@@QQ@@QQQ$@",
"OQQQQQ@@@@QQQQ$@",
"OQQQQQQ@@QQQQQ$@",
"OQQQQQ@@@@QQQQ$@",
"OQQQQ@@QQ@@QQQ$@",
"OQQQ@@QQQQ@@QQ$@",
"OQQQQQQQQQQQQQ$@",
"OQQQQQQQQQQQQQ$@",
"O$$$$$$$$$$$$$$@",
"@@@@@@@@@@@@@@@@"
};
int x, y;
char c;
boxfillOnSht(sht, 0, 0, xsize , 1, LIGHTGRAY);
boxfillOnSht(sht, 1, 1, xsize - 2, 1, WHITE);
boxfillOnSht(sht, 0, 0, 1, ysize , LIGHTGRAY);
boxfillOnSht(sht, 1, 1, 1, ysize - 2, WHITE);
boxfillOnSht(sht, xsize - 2, 1, 1, ysize - 2, DULLGRAY);
boxfillOnSht(sht, xsize - 1, 0, 1, ysize, BLACK);
//if (title[11]=='2'){struct BootInfo *binfo=(struct BootInfo *) 0x00000ff0;char s[128];sprintf (s,"b21");putStrOnSrn(binfo,0,320,1,s);}
boxfillOnSht(sht, 2, 2, xsize - 4, ysize - 4, WHITE);//!
//if (title[11]=='2'){struct BootInfo *binfo=(struct BootInfo *) 0x00000ff0;char s[128];sprintf (s,"b22");putStrOnSrn(binfo,0,340,1,s);}
boxfillOnSht(sht, 3, 3, xsize - 6, 18, DULLINDIGO);//!
//if (title[11]=='2'){struct BootInfo *binfo=(struct BootInfo *) 0x00000ff0;char s[128];sprintf (s,"b27");putStrOnSrn(binfo,0,360,1,s);}
boxfillOnSht(sht, 1, ysize - 2, xsize - 2, 1, DULLGRAY);
//if (title[11]=='2'){struct BootInfo *binfo=(struct BootInfo *) 0x00000ff0;char s[128];sprintf (s,"b29");putStrOnSrn(binfo,0,380,1,s);}
boxfillOnSht(sht, 0, ysize - 1, xsize, 1, BLACK);
//if (title[11]=='2'){struct BootInfo *binfo=(struct BootInfo *) 0x00000ff0;char s[128];sprintf (s,"b3");putStrOnSrn(binfo,0,400,1,s);}
putStrOnSht(sht,16, 4, WHITE, title);
for (y = 0; y < 14; y++)
{
for (x = 0; x < 16; x++)
{
c = closebtn[y][x];
if (c == '@')
{
c = BLACK;
} else if (c == '$')
{
c = DULLGRAY;
} else if (c == 'Q')
{
c = LIGHTGRAY;
} else
{
c = WHITE;
}
sht->buffer[(5 + y) * xsize + (xsize - 21 + x)] = c;
}
}
return;
}
void makeTextBox(struct Sheet *sht, int x0, int y0, int sx, int sy, int c)
{
int x1 = x0 + sx, y1 = y0 + sy;
boxfillOnSht(sht, x0 - 2, y0 - 3, sx + 4, 1 , DULLGRAY);
boxfillOnSht(sht, x0 - 3, y0 - 3, 1 , sy + 5, DULLGRAY);
boxfillOnSht(sht, x0 - 3, y1 + 2, sx + 5, 1 , WHITE);
boxfillOnSht(sht, x1 + 2, y0 - 3, 1 , sy + 6, WHITE);
boxfillOnSht(sht, x0 - 1, y0 - 2, sx + 2, 1 , BLACK);
boxfillOnSht(sht, x0 - 2, y0 - 2, 1 , sy + 3, BLACK);
boxfillOnSht(sht, x0 - 2, y1 + 1, sx + 3, 1 , LIGHTGRAY);
boxfillOnSht(sht, x1 + 1, y0 - 2, 1 , sy + 4, LIGHTGRAY);
boxfillOnSht(sht, x0 - 1, y0 - 1, sx + 2, sy + 2, c);
return;
}