forked from publicres/xv6_gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c.texttest
170 lines (161 loc) · 6.21 KB
/
init.c.texttest
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
// init: The initial user-level program
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "guientity_attrvalue.h"
char *argv[] = { "sh", 0 };
uchar *readImg(char *fileName, uchar picMode) //0:3channel,1:4channel
{
int fd1 = open(fileName, 0);
if (fd1 < 0)
{
printf(1, "open file error\n");
return 0;
}
uchar w,h;
read(fd1, &w, 1);
read(fd1, &h, 1);
int size=(uint)w*(uint)h,i;
uchar *p=malloc(size*4+2);
uchar *q,*tp,*tq;
p[0]=w;
p[1]=h;
if (picMode==1)
{
read(fd1, p+2, size*4);
}
else if (picMode==0)
{
q=malloc(size*3);
read(fd1, q, size*3);
tp=p+2;
tq=q;
for (i=0;i<size;i++)
{
*(tp++)=*(q++);
*(tp++)=*(q++);
*(tp++)=*(q++);
*(tp++)=0;
}
free(tq);
}
close(fd1);
return p;
}
void initMouse()
{
contentStruct pic;
uchar *p=readImg("cursor.matrix",1);
pic.pics=p;
pic.isRepeat=0;
setattr(GUIENT_IMG,0xfffffffe,GUIATTR_IMG_CONTENT,&pic);
free(p);
}
void initLetters()
{
char* cont="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?";
int fd1 = open("letters.matrix", 0);
uchar w,h;
uchar *p;
int size,num,i,j;
if (fd1 < 0)
{
printf(1, "open file error\n");
return;
}
read(fd1, &w, 1);
read(fd1, &h, 1);
num=strlen(cont);
size=(1+(uint)w*(uint)h)*num;
p=malloc(size+4);
size=(uint)w*(uint)h;
p[0]=0;
p[1]=w;
p[2]=h;
p[3]=(uchar)strlen(cont);
j=4;
for (i=0;i<num;i++)
{
p[j]=(uchar)cont[i];
read(fd1, p+j+1, size);
j=j+1+size;
}
close(fd1);
//SYSCALL HERE!
uint x=0;
uint y=(uint)-1;
setattr(GUIENT_TXT,x,GUIATTR_TXT_FONT,p);
createdom(GUIENT_TXT,0xffffffff,&x);
uint xx=50;
uint yy=50;
uint ww=400;
uint hh=50;
uchar color[3]={0,0,255};
//uint aa=1;
//char c='C';
//char d='A';
//char* s="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?";
char* ss=(char*)malloc(179);
// memset(s,0,179);
// memset(s,65,178);
setattr(GUIENT_TXT,x,GUIATTR_TXT_X,&xx);
setattr(GUIENT_TXT,x,GUIATTR_TXT_Y,&yy);
setattr(GUIENT_TXT,x,GUIATTR_TXT_WIDTH,&ww);
setattr(GUIENT_TXT,x,GUIATTR_TXT_HEIGHT,&hh);
//setattr(GUIENT_TXT,x,GUIATTR_TXT_STR,s);
char* s="Yo\nuasdsadasdsadasdsadasdsadasdjsadjlskad12903dsaa9rjldclkc,xzmnfslkfj9wu0rsldfkjas09348508egfsdlkslkalsdfjsailf09348502385340sdiflkfjaskjasdsldkasldkjaskdjsaldksajdklasjdlsajdksajdlasjdlksajdladiwqoreoifdsjjnc,candklasaads\n!";
setattr(GUIENT_TXT,x,GUIATTR_TXT_STR,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_COLOR,color);
setattr(GUIENT_TXT,x,GUIATTR_TXT_SETCURS,&y);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
getattr(GUIENT_TXT,x,GUIATTR_TXT_STR,ss);
printf(1, "str:%s\n", ss);
//setattr(GUIENT_TXT,x,GUIATTR_TXT_FONTIDX,&aa);
//setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
// setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
// setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
// setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
// setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
// setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
// setattr(GUIENT_TXT,x,GUIATTR_TXT_INCCURS,s);
//getattr(GUIENT_TXT,x,GUIATTR_TXT_DELETE,&d);
//printf(1, "char:%c\n", d);
//setattr(GUIENT_TXT,x,GUIATTR_TXT_INSERT,&c);
//free((void*)s);
free(p);
}
int
main(void)
{
int pid, wpid;
if(open("console", O_RDWR) < 0){
mknod("console", 1, 1);
open("console", O_RDWR);
}
dup(0); // stdout
dup(0); // stderr
initMouse();
initLetters();
for(;;){
printf(1, "init: starting sh\n");
pid = fork();
if(pid < 0){
printf(1, "init: fork failed\n");
exit();
}
if(pid == 0){
exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
}
while((wpid=wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n");
}
}