Rev 720 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 720 | Rev 9587 | ||
---|---|---|---|
1 | ; |
1 | ; |
2 | ; Port to KolibliOS |
2 | ; Port to KolibliOS |
3 | ; (jacekm.pl@gmail.com) |
3 | ; (jacekm.pl@gmail.com) |
4 | ; |
4 | ; |
5 | 5 | ||
6 | ;B+ System header |
6 | ;B+ System header |
7 | use32 |
7 | use32 |
8 | org 0x0 |
8 | org 0x0 |
9 | db 'MENUET01' |
9 | db 'MENUET01' |
10 | dd 0x01 |
10 | dd 0x01 |
11 | dd START |
11 | dd START |
12 | dd I_END |
12 | dd I_END |
13 | dd 0x500000 |
13 | dd 0x500000 |
14 | dd 0x7fff0 |
14 | dd 0x7fff0 |
15 | dd 0x0,0x0 |
15 | dd 0x0,0x0 |
16 | ;E:. |
16 | ;E:. |
17 | 17 | ||
18 | ;B+ Include C files |
18 | ;B+ Include C files |
19 | ; Compiler tools |
19 | ; Compiler tools |
20 | include "INTRINS.ASM" |
20 | include "INTRINS.ASM" |
21 | 21 | ||
22 | ; C Library ("stdio.asm") |
22 | ; C Library ("stdio.asm") |
23 | include "LIBSTD.ASM" |
23 | include "LIBSTD.ASM" |
24 | 24 | ||
25 | ; MenuetOS implement |
25 | ; MenuetOS implement |
26 | include "OSFUNC.ASM" |
26 | include "OSFUNC.ASM" |
27 | 27 | ||
28 | _fopen equ _OS_fopen |
28 | _fopen equ _OS_fopen |
29 | _fputc equ _OS_fputc |
29 | _fputc equ _OS_fputc |
30 | _fgetc equ _OS_fgetc |
30 | _fgetc equ _OS_fgetc |
31 | _fclose equ _OS_fclos |
31 | _fclose equ _OS_fclos |
32 | 32 | ||
33 | ;Main program (compiled from C) |
33 | ;Main program (compiled from C) |
34 | include "GETARG.ASM" |
34 | include "GETARG.ASM" |
35 | include "CC1.ASM" |
35 | include "CC1.ASM" |
36 | include "CC2.ASM" |
36 | include "CC2.ASM" |
37 | include "CC3.ASM" |
37 | include "CC3.ASM" |
38 | include "CC4.ASM" |
38 | include "CC4.ASM" |
39 | ;E:. |
39 | ;E:. |
40 | 40 | ||
41 | START: |
41 | START: |
42 | ;B+ Main cycle |
42 | ;B+ Main cycle |
43 | call draw_window |
43 | call draw_window |
44 | still: |
44 | still: |
45 | mov eax,10 |
45 | mov eax,10 |
46 | int 0x40 |
46 | int 0x40 |
47 | still1: |
47 | still1: |
48 | 48 | ||
49 | cmp eax,1 |
49 | cmp eax,1 |
50 | je red |
50 | je red |
51 | cmp eax,2 |
51 | cmp eax,2 |
52 | je key |
52 | je key |
53 | cmp eax,3 |
53 | cmp eax,3 |
54 | je button |
54 | je button |
55 | jmp still |
55 | jmp still |
56 | 56 | ||
57 | red: |
57 | red: |
58 | call draw_window |
58 | call draw_window |
59 | jmp still |
59 | jmp still |
60 | 60 | ||
61 | key: |
61 | key: |
62 | mov eax,2 |
62 | mov eax,2 |
63 | int 0x40 |
63 | int 0x40 |
64 | jmp still |
64 | jmp still |
65 | 65 | ||
66 | button: |
66 | button: |
67 | mov eax,17 |
67 | mov eax,17 |
68 | int 0x40 |
68 | int 0x40 |
69 | 69 | ||
70 | cmp ah,1 |
70 | cmp ah,1 |
71 | jne .noclose |
71 | jne .noclose |
72 | mov eax,-1 |
72 | mov eax,-1 |
73 | int 0x40 |
73 | int 0x40 |
74 | .noclose: |
74 | .noclose: |
75 | 75 | ||
76 | cmp ah,2 |
76 | cmp ah,2 |
77 | jne .no_run |
77 | jne .no_run |
78 | ; call begin_osfunc |
78 | ; call begin_osfunc |
79 | ;B+ Copy file path |
79 | ;B+ Copy file path |
80 | mov esi,inp_path |
80 | mov esi,inp_path |
81 | mov edi,filepath |
81 | mov edi,filepath |
82 | mov ecx,[p_len] |
82 | mov ecx,[p_len] |
83 | push ecx |
83 | push ecx |
84 | cld |
84 | cld |
85 | rep movsb |
85 | rep movsb |
86 | pop ecx |
86 | pop ecx |
87 | add ecx,filepath |
87 | add ecx,filepath |
88 | mov [p_filename],ecx |
88 | mov [p_filename],ecx |
89 | ;E:. |
89 | ;E:. |
90 | ;B+ Clear word area |
90 | ;B+ Clear word area |
91 | mov ebx,10 shl 16 + 280 |
91 | mov ebx,10 shl 16 + 280 |
92 | mov ecx,60 shl 16 + 250 |
92 | mov ecx,60 shl 16 + 250 |
93 | mov edx,0x303030 |
93 | mov edx,0x303030 |
94 | mov eax,13 |
94 | mov eax,13 |
95 | int 0x40 |
95 | int 0x40 |
96 | ;E:. |
96 | ;E:. |
97 | ;B+ Init parameters |
97 | ;B+ Init parameters |
98 | mov ecx,_input |
98 | mov ecx,_input |
99 | sub ecx,_nogo |
99 | sub ecx,_nogo |
100 | mov edi,_nogo |
100 | mov edi,_nogo |
101 | xor eax,eax |
101 | xor eax,eax |
102 | cld |
102 | cld |
103 | rep stosb |
103 | rep stosb |
104 | mov [_input],-1 |
104 | mov [_input],-1 |
105 | mov [_input2],-1 |
105 | mov [_input2],-1 |
106 | mov [_usexpr],1 |
106 | mov [_usexpr],1 |
107 | mov [_ccode],1 |
107 | mov [_ccode],1 |
108 | mov [_quote],34 |
108 | mov [_quote],34 |
109 | mov [test_outch.y_coord],60 |
109 | mov [test_outch.y_coord],60 |
110 | ;E:. |
110 | ;E:. |
111 | call init_osfunc |
111 | call init_osfunc |
112 | push dword 4 |
112 | push dword 4 |
113 | push args |
113 | push args |
114 | ;B+ Save exit ESP |
114 | ;B+ Save exit ESP |
115 | mov [exit_esp],esp |
115 | mov [exit_esp],esp |
116 | ;E:. |
116 | ;E:. |
117 | call _main |
117 | call _main |
118 | add esp,8 |
118 | add esp,8 |
119 | ; call end_osfunc |
119 | ; call end_osfunc |
120 | .no_run: |
120 | .no_run: |
121 | 121 | ||
122 | cmp ah,3 |
122 | cmp ah,3 |
123 | jne .no_path |
123 | jne .no_path |
124 | mov eax,inp_path |
124 | mov eax,inp_path |
125 | mov bx,27 |
125 | mov bx,27 |
126 | call read_string |
126 | call read_string |
127 | mov edx,[r_pos] |
127 | mov edx,[r_pos] |
128 | mov [p_len],edx |
128 | mov [p_len],edx |
129 | ; |
129 | ; |
130 | cmp ah,10 |
130 | cmp ah,10 |
131 | je still |
131 | je still |
132 | jmp still1 |
132 | jmp still1 |
133 | .no_path: |
133 | .no_path: |
134 | 134 | ||
135 | cmp ah,4 |
135 | cmp ah,4 |
136 | jne .no_file |
136 | jne .no_file |
137 | mov eax,inp_file |
137 | mov eax,inp_file |
138 | mov bx,42 |
138 | mov bx,42 |
139 | call read_string |
139 | call read_string |
140 | mov edx,[r_pos] |
140 | mov edx,[r_pos] |
141 | mov [f_len],edx |
141 | mov [f_len],edx |
142 | ; |
142 | ; |
143 | cmp ah,10 |
143 | cmp ah,10 |
144 | je still |
144 | je still |
145 | jmp still1 |
145 | jmp still1 |
146 | .no_file: |
146 | .no_file: |
147 | 147 | ||
148 | jmp still |
148 | jmp still |
149 | ;E:. |
149 | ;E:. |
150 | 150 | ||
151 | read_string: |
151 | read_string: |
152 | ;B+ Read string |
152 | ;B+ Read string |
153 | mov [c_place],eax |
153 | mov [c_place],eax |
154 | mov [r_pos],0 |
154 | mov [r_pos],0 |
155 | mov [rel_x],60 |
155 | mov [rel_x],60 |
156 | mov [rel_y],bx |
156 | mov [rel_y],bx |
157 | 157 | ||
158 | mov ebx,60 |
158 | mov ebx,60 |
159 | shl ebx,16 |
159 | shl ebx,16 |
160 | mov bx,6*26+1 |
160 | mov bx,6*26+1 |
161 | movzx ecx,[rel_y] |
161 | movzx ecx,[rel_y] |
162 | shl ecx,16 |
162 | shl ecx,16 |
163 | mov cx,10 |
163 | mov cx,10 |
164 | mov edx,0x000000 |
164 | mov edx,0x000000 |
165 | mov eax,13 |
165 | mov eax,13 |
166 | int 0x40 |
166 | int 0x40 |
167 | 167 | ||
168 | add ecx,11 shl 16 |
168 | add ecx,11 shl 16 |
169 | mov cx,2 |
169 | mov cx,2 |
170 | mov edx,0x999999 |
170 | mov edx,0x999999 |
171 | int 0x40 |
171 | int 0x40 |
172 | 172 | ||
173 | .next: |
173 | .next: |
174 | mov ebx,[rel_x] |
174 | mov ebx,[rel_x] |
175 | shl ebx,16 |
175 | shl ebx,16 |
176 | mov bx,7 |
176 | mov bx,7 |
177 | movzx ecx,[rel_y] |
177 | movzx ecx,[rel_y] |
178 | shl ecx,16 |
178 | shl ecx,16 |
179 | mov cx,10 |
179 | mov cx,10 |
180 | mov edx,0x000000 |
180 | mov edx,0x000000 |
181 | mov eax,13 |
181 | mov eax,13 |
182 | int 0x40 |
182 | int 0x40 |
183 | 183 | ||
184 | mov ebx,[c_place] |
184 | mov ebx,[c_place] |
185 | mov byte [ebx],0 |
185 | mov byte [ebx],0 |
186 | 186 | ||
187 | mov eax,10 |
187 | mov eax,10 |
188 | int 0x40 |
188 | int 0x40 |
189 | cmp eax,2 |
189 | cmp eax,2 |
190 | je .key |
190 | je .key |
191 | jmp .to_ret |
191 | jmp .to_ret |
192 | .key: |
192 | .key: |
193 | 193 | ||
194 | mov eax,2 |
194 | mov eax,2 |
195 | int 0x40 |
195 | int 0x40 |
196 | cmp ah,13 |
196 | cmp ah,13 |
197 | jne .no_enter |
197 | jne .no_enter |
198 | jmp .to_ret |
198 | jmp .to_ret |
199 | .no_enter: |
199 | .no_enter: |
200 | 200 | ||
201 | cmp ah,8 |
201 | cmp ah,8 |
202 | jne .no_back |
202 | jne .no_back |
203 | cmp [r_pos],0 |
203 | cmp [r_pos],0 |
204 | je .next |
204 | je .next |
205 | dec [r_pos] |
205 | dec [r_pos] |
206 | dec [c_place] |
206 | dec [c_place] |
207 | sub [rel_x],6 |
207 | sub [rel_x],6 |
208 | jmp .next |
208 | jmp .next |
209 | .no_back: |
209 | .no_back: |
210 | 210 | ||
211 | cmp [r_pos],25 |
211 | cmp [r_pos],25 |
212 | je .next |
212 | je .next |
213 | 213 | ||
214 | cmp ah,'a' |
214 | cmp ah,'a' |
215 | jb .no_sm_l |
215 | jb .no_sm_l |
216 | cmp ah,'z' |
216 | cmp ah,'z' |
217 | ja .no_sm_l |
217 | ja .no_sm_l |
218 | add ah,'A'-'a' |
218 | add ah,'A'-'a' |
219 | .no_sm_l: |
219 | .no_sm_l: |
220 | 220 | ||
221 | mov byte [ebx],ah |
221 | mov byte [ebx],ah |
222 | mov [char],ah |
222 | mov [char],ah |
223 | inc [c_place] |
223 | inc [c_place] |
224 | inc [r_pos] |
224 | inc [r_pos] |
225 | 225 | ||
226 | mov ebx,[rel_x] |
226 | mov ebx,[rel_x] |
227 | inc ebx |
227 | inc ebx |
228 | shl ebx,16 |
228 | shl ebx,16 |
229 | mov bx,[rel_y] |
229 | mov bx,[rel_y] |
230 | inc bx |
230 | inc bx |
231 | mov ecx,0x00ffff |
231 | mov ecx,0x00ffff |
232 | mov edx,char |
232 | mov edx,char |
233 | mov esi,1 |
233 | mov esi,1 |
234 | mov eax,4 |
234 | mov eax,4 |
235 | int 0x40 |
235 | int 0x40 |
236 | 236 | ||
237 | add [rel_x],6 |
237 | add [rel_x],6 |
238 | jmp .next |
238 | jmp .next |
239 | 239 | ||
240 | .to_ret: |
240 | .to_ret: |
241 | push eax |
241 | push eax |
242 | mov ebx,60 |
242 | mov ebx,60 |
243 | shl ebx,16 |
243 | shl ebx,16 |
244 | mov bx,6*26+1 |
244 | mov bx,6*26+1 |
245 | movzx ecx,[rel_y] |
245 | movzx ecx,[rel_y] |
246 | add ecx,11 |
246 | add ecx,11 |
247 | shl ecx,16 |
247 | shl ecx,16 |
248 | mov cx,2 |
248 | mov cx,2 |
249 | mov edx,0x000000 |
249 | mov edx,0x000000 |
250 | mov eax,13 |
250 | mov eax,13 |
251 | int 0x40 |
251 | int 0x40 |
252 | pop eax |
252 | pop eax |
253 | ret |
253 | ret |
254 | 254 | ||
255 | rel_x dd 60 |
255 | rel_x dd 60 |
256 | rel_y dw 0x0 |
256 | rel_y dw 0x0 |
257 | c_place dd 0x0 |
257 | c_place dd 0x0 |
258 | r_pos dd 0x0 |
258 | r_pos dd 0x0 |
259 | char db '?' |
259 | char db '?' |
260 | ;E:. |
260 | ;E:. |
261 | 261 | ||
262 | draw_window: |
262 | draw_window: |
263 | ;B+ Draw window |
263 | ;B+ Draw window |
264 | mov eax,12 |
264 | mov eax,12 |
265 | mov ebx,1 |
265 | mov ebx,1 |
266 | int 0x40 |
266 | int 0x40 |
267 | 267 | ||
268 | mov ebx,100*65536+320 |
268 | mov ebx,100*65536+320 |
269 | mov ecx,100*65536+320 |
269 | mov ecx,100*65536+320 |
270 | mov edx,0x035555DD |
270 | mov edx,0x035555DD |
271 | mov esi,0x805080d0 |
271 | mov esi,0x805080d0 |
272 | mov edi,0x005080d0 |
272 | mov edi,0x005080d0 |
273 | mov eax,0 |
273 | mov eax,0 |
274 | int 0x40 |
274 | int 0x40 |
275 | 275 | ||
276 | mov ebx,8*65536+8 |
276 | mov ebx,8*65536+8 |
277 | mov ecx,0x10ddeeff |
277 | mov ecx,0x10ddeeff |
278 | mov edx,caption |
278 | mov edx,caption |
279 | mov esi,caption_end-caption |
279 | mov esi,caption_end-caption |
280 | mov eax,4 |
280 | mov eax,4 |
281 | int 0x40 |
281 | int 0x40 |
282 | 282 | ||
283 | ;mov ebx,(300-19)*65536+12 |
283 | ;mov ebx,(300-19)*65536+12 |
284 | ;mov ecx,5*65536+12 |
284 | ;mov ecx,5*65536+12 |
285 | ;mov edx,1 |
285 | ;mov edx,1 |
286 | ;mov esi,0x6688dd |
286 | ;mov esi,0x6688dd |
287 | ;mov eax,8 |
287 | ;mov eax,8 |
288 | ;int 0x40 |
288 | ;int 0x40 |
289 | 289 | ||
290 | ;B+ Hot buttons |
290 | ;B+ Hot buttons |
291 | mov ebx,220 shl 16 + 70 |
291 | mov ebx,220 shl 16 + 70 |
292 | mov ecx,25 shl 16 + 29 |
292 | mov ecx,25 shl 16 + 29 |
293 | mov edx,2 ; compile |
293 | mov edx,2 ; compile |
294 | mov esi,0x6688dd |
294 | mov esi,0x6688dd |
295 | mov eax,8 |
295 | mov eax,8 |
296 | int 0x40 |
296 | int 0x40 |
297 | 297 | ||
298 | mov ebx,10 shl 16 + 47 |
298 | mov ebx,10 shl 16 + 47 |
299 | mov ecx,26 shl 16 + 12 |
299 | mov ecx,26 shl 16 + 12 |
300 | mov edx,3 ; path |
300 | mov edx,3 ; path |
301 | mov esi,0x6688dd |
301 | mov esi,0x6688dd |
302 | mov eax,8 |
302 | mov eax,8 |
303 | int 0x40 |
303 | int 0x40 |
304 | 304 | ||
305 | mov ebx,10 shl 16 + 47 |
305 | mov ebx,10 shl 16 + 47 |
306 | mov ecx,41 shl 16 + 12 |
306 | mov ecx,41 shl 16 + 12 |
307 | mov edx,4 ; file name |
307 | mov edx,4 ; file name |
308 | mov esi,0x6688dd |
308 | mov esi,0x6688dd |
309 | mov eax,8 |
309 | mov eax,8 |
310 | int 0x40 |
310 | int 0x40 |
311 | ;E:. |
311 | ;E:. |
312 | 312 | ||
313 | ;B+ Text in buttons |
313 | ;B+ Text in buttons |
314 | mov ebx,231 shl 16 + 36 |
314 | mov ebx,231 shl 16 + 36 |
315 | mov ecx,0x10ffffff |
315 | mov ecx,0x10ffffff |
316 | mov edx,txt_compile |
316 | mov edx,txt_compile |
317 | mov esi,txt_compile_end-txt_compile |
317 | mov esi,txt_compile_end-txt_compile |
318 | mov eax,4 |
318 | mov eax,4 |
319 | int 0x40 |
319 | int 0x40 |
320 | 320 | ||
321 | mov ebx,14 shl 16 + 28 |
321 | mov ebx,14 shl 16 + 28 |
322 | mov ecx,0xffffff |
322 | mov ecx,0xffffff |
323 | mov edx,txt_path |
323 | mov edx,txt_path |
324 | mov esi,txt_path_end-txt_path |
324 | mov esi,txt_path_end-txt_path |
325 | int 0x40 |
325 | int 0x40 |
326 | 326 | ||
327 | mov ebx,14 shl 16 + 43 |
327 | mov ebx,14 shl 16 + 43 |
328 | mov edx,txt_file |
328 | mov edx,txt_file |
329 | mov esi,txt_file_end-txt_file |
329 | mov esi,txt_file_end-txt_file |
330 | int 0x40 |
330 | int 0x40 |
331 | ;E:. |
331 | ;E:. |
332 | 332 | ||
333 | ;B+ Draw path / file name |
333 | ;B+ Draw path / file name |
334 | mov ebx,61 shl 16 + 28 |
334 | mov ebx,61 shl 16 + 28 |
335 | mov ecx,0x00ffff |
335 | mov ecx,0x00ffff |
336 | mov edx,inp_path |
336 | mov edx,inp_path |
337 | mov esi,[p_len] |
337 | mov esi,[p_len] |
338 | mov eax,4 |
338 | mov eax,4 |
339 | int 0x40 |
339 | int 0x40 |
340 | 340 | ||
341 | mov ebx,61 shl 16 + 43 |
341 | mov ebx,61 shl 16 + 43 |
342 | mov ecx,0x00ffff |
342 | mov ecx,0x00ffff |
343 | mov edx,inp_file |
343 | mov edx,inp_file |
344 | mov esi,[f_len] |
344 | mov esi,[f_len] |
345 | mov eax,4 |
345 | mov eax,4 |
346 | int 0x40 |
346 | int 0x40 |
347 | ;E:. |
347 | ;E:. |
348 | 348 | ||
349 | mov eax,12 |
349 | mov eax,12 |
350 | mov ebx,2 |
350 | mov ebx,2 |
351 | int 0x40 |
351 | int 0x40 |
352 | 352 | ||
353 | ret |
353 | ret |
354 | ;E:. |
354 | ;E:. |
355 | 355 | ||
356 | ;B+ Data area |
356 | ;B+ Data area |
357 | 357 | ||
358 | ;B+ Interface |
358 | ;B+ Interface |
359 | inp_path: times 100 db '/RD/1/',0 |
359 | inp_path: times 100 db '/SYS/',0 |
360 | p_len dd 6 |
360 | p_len dd 5 |
361 | inp_file: times 100 db 'EXAMPLE',0 |
361 | inp_file: times 100 db 'EXAMPLE',0 |
362 | f_len dd 7 |
362 | f_len dd 7 |
363 | 363 | ||
364 | txt_compile db 'Compile' |
364 | txt_compile db 'Compile' |
365 | txt_compile_end: |
365 | txt_compile_end: |
366 | txt_path db 'Path ->' |
366 | txt_path db 'Path ->' |
367 | txt_path_end: |
367 | txt_path_end: |
368 | txt_file db 'File ->' |
368 | txt_file db 'File ->' |
369 | txt_file_end: |
369 | txt_file_end: |
370 | ;E:. |
370 | ;E:. |
371 | 371 | ||
372 | ;B+ Main arguments |
372 | ;B+ Main arguments |
373 | args dd arg_str0,inp_file,arg_str2,arg_str3,arg_str4 |
373 | args dd arg_str0,inp_file,arg_str2,arg_str3,arg_str4 |
374 | 374 | ||
375 | arg_str0 db 'CC',0 |
375 | arg_str0 db 'CC',0 |
376 | arg_str1 db 'prog',0 |
376 | arg_str1 db 'prog',0 |
377 | arg_str2 db '-m',0 |
377 | arg_str2 db '-m',0 |
378 | arg_str3 db '-a',0 |
378 | arg_str3 db '-a',0 |
379 | arg_str4 db '-p',0 |
379 | arg_str4 db '-p',0 |
380 | ;E:. |
380 | ;E:. |
381 | 381 | ||
382 | ;B+ System parameters |
382 | ;B+ System parameters |
383 | exit_esp dd 0x0 |
383 | exit_esp dd 0x0 |
384 | ;E:. |
384 | ;E:. |
385 | 385 | ||
386 | caption db 'Small C compiler for KolibriOS v 0.5.3' |
386 | caption db 'Small C compiler for KolibriOS v 0.5.3' |
387 | caption_end: |
387 | caption_end: |
388 | 388 | ||
389 | times 8-($ mod 8) db 0 |
389 | times 8-($ mod 8) db 0 |
390 | ;E:. |
390 | ;E:. |
391 | 391 | ||
392 | I_END: |
392 | I_END: |