-
Notifications
You must be signed in to change notification settings - Fork 0
/
KLIB.H
217 lines (190 loc) · 2.92 KB
/
KLIB.H
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
#ifndef __KLIB_H__
#define __KLIB_H__
/********* C library *********/
get_event()
{
#asm
mov eax,10
int 0x40
#endasm
}
get_key()
{
#asm
mov eax,2
int 0x40
and eax,0x0000ff00
shr eax,8
#endasm
}
get_button()
{
#asm
mov eax,17
int 0x40
shr eax,8
#endasm
}
begin_draw()
{
#asm
mov ebx,1
mov eax,12
int 0x40
#endasm
}
end_draw()
{
#asm
mov ebx,2
mov eax,12
int 0x40
#endasm
}
window(x1,y1,w,h,c_area,c_grab,c_fram)
int x1,y1,w,h; /* esp +32 +28 +24 +20 */
int c_area,c_grab,c_fram; /* esp +16 +12 +8 */
{
#asm
; color of frames
mov edi,[esp+8]
; color of grab bar bit 8->color gl
mov esi,[esp+12]
; color of work area bit 8-> color gl
mov edx,[esp+16]
;left / width
mov ebx,[esp+32]
shl ebx,16
mov bx,[esp+24]
;top / height
mov ecx,[esp+28]
shl ecx,16
mov cx,[esp+20]
;execute
mov eax,0
int 0x40
#endasm
}
label(x,y,color,p_string)
int x,y,color; /* esp +20 +16 +12 */
char *p_string; /* esp +8 */
{
#asm
mov ebx,[esp+20]
shl ebx,16
mov bx,[esp+16]
mov ecx,[esp+12]
mov edx,[esp+8]
;find text lenght
xor esi,esi
.next:
cmp byte [edx+esi],0
jz .good
inc esi
jmp .next
.good:
mov eax,4
int 0x40
#endasm
}
// Button + Text
buttonT(x1,y1,w,h,color,id,p_string, str_color)
int x1,y1,w,h; /* esp +28 +24 +20 +16 */
int color,id;
char *p_string;
int str_color;
{
button(x1,y1,w,h,color,id);
label(x1+4,y1+2,str_color,p_string);
}
// Button
button(x1,y1,w,h,color,id)
int x1,y1,w,h; /* esp +28 +24 +20 +16 */
int color,id; /* esp +12 +8 */
{
#asm
;left / width
mov ebx,[esp+28]
shl ebx,16
mov bx,[esp+20]
;top / height
mov ecx,[esp+24]
shl ecx,16
mov cx,[esp+16]
mov edx,[esp+8]
mov esi,[esp+12]
mov eax,8
int 0x40
#endasm
}
// CONTROLS:
#define CheckBox 1
/* CheckBox
array[ ]:
0 int type
1 int id
2 int x,
3 int y,
4 int color,
5 int colorText
6 int checked
*/
char cbt[2] = " ";
chkbox(cb)
int *cb;
{
if (cb[6] == 1) // checked is set
cbt[0] = 'X';
else
cbt[0] = ' ';
buttonT(cb[2], cb[3], 12,10,cb[4],cb[1],cbt,cb[5]);
}
eventControls(control,count,id)
int* control;
int count;
int id;
{
int i;
int *cont;
for (i=0; i<count; i++)
{
cont = control[i];
switch (cont[0])
{
case CheckBox:
if (cont[1]==id)
{
cont[6] = 1 - cont[6];
renderControls(control,count);
return 1;
}
break;
}
}
return 0;
}
renderControls(control, count)
int* control;
int count;
{
int i;
int *cont;
for (i=0; i<count; i++)
{
cont = control[i];
switch (cont[0])
{
case CheckBox:
chkbox(cont);
break;
}
}
}
s_quit()
{
#asm
mov eax,-1
int 0x40
#endasm
}
#endif