Rev 109 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; flat assembler source ;; |
||
109 | heavyiron | 4 | ;; Copyright (c) 1999-2006, Tomasz Grysztar ;; |
31 | halyavin | 5 | ;; All rights reserved. ;; |
6 | ;; ;; |
||
7 | ;; Menuet port by VT ;; |
||
8 | ;; ;; |
||
9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
10 | |||
11 | NORMAL_MODE = 8 |
||
12 | CONSOLE_MODE = 32 |
||
13 | |||
174 | heavyiron | 14 | MAGIC1 = 6*(text.line_size-1)+14 |
15 | MAGIC2 = 14 |
||
16 | MAGIC3 = 1 |
||
17 | MAGIC4 = 7 |
||
18 | OUTPUTXY = 7 shl 16 + 53 |
||
19 | MAX_PATH = 100 |
||
31 | halyavin | 20 | |
174 | heavyiron | 21 | APP_MEMORY = 0x00800000 |
31 | halyavin | 22 | |
23 | ;; Menuet header |
||
24 | |||
174 | heavyiron | 25 | appname equ "FASM " |
26 | version equ "1.67.11" |
||
27 | |||
31 | halyavin | 28 | use32 |
29 | |||
30 | org 0x0 |
||
31 | db 'MENUET01' ; 8 byte id |
||
174 | heavyiron | 32 | dd 0x01 ; header version |
33 | dd START ; program start |
||
31 | halyavin | 34 | dd program_end ; program image size |
35 | dd APP_MEMORY ; required amount of memory |
||
174 | heavyiron | 36 | dd 0xDFFF0 ; stack |
31 | halyavin | 37 | dd params,0x0 ; parameters,icon |
38 | |||
39 | include 'lang.inc' |
||
40 | include 'fasm.inc' |
||
41 | |||
42 | center fix true |
||
43 | |||
109 | heavyiron | 44 | START: ; Start of execution |
31 | halyavin | 45 | |
174 | heavyiron | 46 | cmp [params],0 |
47 | jz red |
||
31 | halyavin | 48 | |
174 | heavyiron | 49 | mov ecx,10 |
50 | mov al,' ' |
||
51 | mov edi,infile |
||
52 | push ecx |
||
31 | halyavin | 53 | cld |
174 | heavyiron | 54 | rep stosd |
55 | mov ecx,[esp] |
||
56 | mov edi,outfile |
||
57 | rep stosd |
||
58 | pop ecx |
||
59 | mov edi,path |
||
60 | rep stosd |
||
31 | halyavin | 61 | |
174 | heavyiron | 62 | mov esi,params |
31 | halyavin | 63 | ; DEBUGF "params: %s\n",esi |
174 | heavyiron | 64 | mov edi,infile |
31 | halyavin | 65 | call mov_param_str |
66 | ; mov edi,infile |
||
67 | ; DEBUGF " input: %s\n",edi |
||
174 | heavyiron | 68 | inc esi |
69 | mov edi,outfile |
||
31 | halyavin | 70 | call mov_param_str |
71 | ; mov edi,outfile |
||
72 | ; DEBUGF "output: %s\n",edi |
||
174 | heavyiron | 73 | inc esi |
74 | mov edi,path |
||
31 | halyavin | 75 | call mov_param_str |
76 | ; mov edi,path |
||
77 | ; DEBUGF " path: %s\n",edi |
||
78 | |||
174 | heavyiron | 79 | cmp [esi], dword ',run' |
80 | jne @f |
||
81 | mov [_run_outfile],1 |
||
31 | halyavin | 82 | @@: |
83 | |||
174 | heavyiron | 84 | mov [_mode],CONSOLE_MODE |
85 | jmp start |
||
31 | halyavin | 86 | |
87 | |||
174 | heavyiron | 88 | red: ; Redraw |
31 | halyavin | 89 | call draw_window |
90 | |||
174 | heavyiron | 91 | still: |
92 | push 10 ; Wait here for event |
||
93 | pop eax |
||
94 | int 40h |
||
95 | dec eax |
||
96 | je red ; Redraw request |
||
97 | dec eax |
||
98 | jne button ; Button in buffer |
||
31 | halyavin | 99 | |
174 | heavyiron | 100 | key: ; Key |
101 | mov al,2 ; Read it and ignore |
||
102 | int 0x40 |
||
31 | halyavin | 103 | jmp still |
104 | |||
174 | heavyiron | 105 | button: ; Button in Window |
31 | halyavin | 106 | |
174 | heavyiron | 107 | mov al,17 |
108 | int 0x40 |
||
31 | halyavin | 109 | |
174 | heavyiron | 110 | cmp ah,1 |
111 | jne noclose |
||
112 | or eax,-1 |
||
113 | int 0x40 |
||
31 | halyavin | 114 | |
174 | heavyiron | 115 | noclose: |
116 | cmp ah,2 ; Start compiling |
||
117 | je start |
||
118 | cmp ah,3 ; Start compiled file |
||
31 | halyavin | 119 | jnz norunout |
120 | |||
121 | mov edx,outfile |
||
122 | call make_fullpaths |
||
174 | heavyiron | 123 | mcall 70,file_info_start |
31 | halyavin | 124 | ; xor ecx,ecx |
125 | jmp still |
||
126 | norunout: |
||
127 | |||
174 | heavyiron | 128 | mov ecx,5 |
31 | halyavin | 129 | mov [ya],ecx |
130 | |||
109 | heavyiron | 131 | cmp ah,11 ; Infile |
174 | heavyiron | 132 | je f1 |
109 | heavyiron | 133 | cmp ah,12 ; Outfile |
174 | heavyiron | 134 | je f2 |
109 | heavyiron | 135 | cmp ah,13 ; Path |
174 | heavyiron | 136 | je f3 |
31 | halyavin | 137 | |
174 | heavyiron | 138 | jmp still |
31 | halyavin | 139 | |
140 | |||
141 | draw_window: |
||
142 | |||
143 | pusha |
||
144 | |||
145 | mcall 12,1 ; Start of draw |
||
146 | |||
147 | get_sys_colors 1,0 |
||
148 | |||
174 | heavyiron | 149 | mov eax,0 |
150 | mov ebx,50*65536+280 |
||
151 | mov ecx,50*65536+250 |
||
152 | mov edx,[sc.work] |
||
153 | or edx,0x33000000 |
||
154 | mov edi,header ; Draw Window Label Text |
||
155 | int 0x40 |
||
31 | halyavin | 156 | |
174 | heavyiron | 157 | mcall 9,PROCESSINFO,-1 |
31 | halyavin | 158 | |
174 | heavyiron | 159 | mpack ecx,1,1 |
31 | halyavin | 160 | mov ebx,[pinfo.x_size] |
174 | heavyiron | 161 | sub ebx,10 |
31 | halyavin | 162 | |
163 | push ecx |
||
164 | madd ecx,MAGIC2*3+2,MAGIC2*3+2 |
||
165 | mcall 38,,,[sc.work_graph] |
||
166 | pop ecx |
||
167 | |||
168 | sub ebx,MAGIC1+3 |
||
169 | mcall |
||
170 | madd ecx,MAGIC2,MAGIC2 |
||
171 | mcall |
||
172 | madd ecx,MAGIC2,MAGIC2 |
||
173 | mcall |
||
174 | madd ecx,MAGIC2,MAGIC2 |
||
175 | mcall |
||
176 | push ebx |
||
174 | heavyiron | 177 | mpack ebx,MAGIC1,MAGIC1 |
178 | sub ecx,MAGIC2*3 |
||
31 | halyavin | 179 | mcall |
180 | mov ebx,[esp-2] |
||
181 | pop bx |
||
182 | mcall |
||
183 | add esp,2 |
||
184 | |||
174 | heavyiron | 185 | mpack ebx,0,MAGIC1-1 |
186 | mpack ecx,MAGIC3+1,MAGIC2-2 |
||
31 | halyavin | 187 | mcall 8,,,0x4000000B ; Button: Enter Infile |
188 | madd ecx,MAGIC2,0 |
||
189 | mcall ,,,0x4000000C ; Button: Enter Outfile |
||
190 | madd ecx,MAGIC2,0 |
||
191 | mcall ,,,0x4000000D ; Button: Enter Path |
||
192 | |||
193 | mpack ebx,[pinfo.x_size],MAGIC1 |
||
174 | heavyiron | 194 | msub ebx,MAGIC1+10+1,0 |
195 | mpack ecx,0,MAGIC2*3/2-1 |
||
31 | halyavin | 196 | madd ecx,MAGIC3,0 |
197 | mcall ,,,0x00000002,[sc.work_button] |
||
198 | madd ecx,MAGIC2*3/2+1,0 |
||
199 | mcall ,,,0x00000003 |
||
200 | |||
174 | heavyiron | 201 | mpack ebx,6,0 ; Draw Window Text |
202 | add ebx,MAGIC3+MAGIC2/2-3 |
||
31 | halyavin | 203 | mov ecx,[sc.work_text] |
204 | mov edx,text |
||
205 | mov esi,text.line_size |
||
206 | mov eax,4 |
||
207 | newline: |
||
174 | heavyiron | 208 | int 0x40 |
31 | halyavin | 209 | add ebx,MAGIC2 |
210 | add edx,text.line_size |
||
211 | cmp byte[edx],'x' |
||
212 | jne newline |
||
213 | |||
214 | mov ebx,[pinfo.x_size] |
||
174 | heavyiron | 215 | sub ebx,MAGIC1+10+1-9 |
31 | halyavin | 216 | shl ebx,16 |
174 | heavyiron | 217 | add ebx,MAGIC3+(MAGIC2*3/2-1)/2-3 |
31 | halyavin | 218 | mcall ,,[sc.work_button_text],s_compile,7 |
219 | add ebx,MAGIC2*3/2+1 |
||
220 | mcall ,,,s_run |
||
221 | |||
174 | heavyiron | 222 | mpack ebx,MAGIC1+6,0 |
31 | halyavin | 223 | add ebx,MAGIC3+MAGIC2/2-3+MAGIC2*0 |
224 | mov esi,[pinfo.x_size] |
||
225 | sub esi,MAGIC1*2+5*2+6+3 |
||
226 | mov eax,esi |
||
227 | mov cl,6 |
||
228 | div cl |
||
229 | cmp al,MAX_PATH |
||
230 | jbe @f |
||
231 | mov al,MAX_PATH |
||
232 | @@: movzx esi,al |
||
233 | mcall 4,,[sc.work_text],infile |
||
234 | add ebx,MAGIC2 |
||
235 | mcall ,,,outfile |
||
236 | add ebx,MAGIC2 |
||
237 | mcall ,,,path |
||
238 | |||
239 | call draw_messages |
||
240 | |||
241 | mcall 12,2 ; End of Draw |
||
242 | |||
243 | popa |
||
244 | ret |
||
245 | |||
246 | bottom_right dd ? |
||
247 | |||
248 | draw_messages: |
||
249 | mov eax,13 ; clear work area |
||
174 | heavyiron | 250 | mpack ebx,MAGIC4-2,[pinfo.x_size] |
31 | halyavin | 251 | sub ebx,5*2+MAGIC4*2-1-2*2 |
174 | heavyiron | 252 | mpack ecx,0,[pinfo.y_size] |
253 | madd ecx,MAGIC2*3+MAGIC3+MAGIC4+1,-(MAGIC2*3+MAGIC3+MAGIC4*2+25) |
||
31 | halyavin | 254 | mov word[bottom_right+2],bx |
255 | mov word[bottom_right],cx |
||
256 | msub [bottom_right],7,11 |
||
257 | add [bottom_right],OUTPUTXY |
||
258 | mov edx,[sc.work] |
||
259 | int 0x40 |
||
260 | _cy = 0 |
||
261 | _sy = 2 |
||
262 | _cx = 4 |
||
263 | _sx = 6 |
||
264 | push ebx ecx |
||
174 | heavyiron | 265 | mpack ebx,MAGIC4-3,MAGIC4-2 |
31 | halyavin | 266 | add bx,[esp+_cx] |
267 | mov ecx,[esp+_sy-2] |
||
268 | mov cx,[esp+_sy] |
||
269 | msub ecx,1,1 |
||
270 | mcall 38,,,[sc.work_graph] |
||
271 | mov si,[esp+_cy] |
||
272 | add cx,si |
||
273 | shl esi,16 |
||
274 | add ecx,esi |
||
275 | madd ecx,1,1 |
||
276 | mcall |
||
174 | heavyiron | 277 | mpack ebx,MAGIC4-3,MAGIC4-3 |
31 | halyavin | 278 | mov esi,[esp+_sy-2] |
279 | mov si,cx |
||
280 | mov ecx,esi |
||
281 | mcall |
||
282 | mov si,[esp+_cx] |
||
283 | add bx,si |
||
284 | shl esi,16 |
||
285 | add ebx,esi |
||
286 | madd ebx,1,1 |
||
287 | mcall |
||
288 | pop ecx ebx |
||
289 | ret |
||
290 | |||
291 | ; read string |
||
292 | |||
293 | f1: mov [addr],infile |
||
294 | add [ya],MAGIC2*0 |
||
295 | jmp rk |
||
296 | f2: mov [addr],outfile |
||
297 | add [ya],MAGIC2*1 |
||
298 | jmp rk |
||
299 | f3: mov [addr],path |
||
300 | add [ya],MAGIC2*2 |
||
301 | rk: |
||
302 | |||
303 | mov edi,[addr] |
||
304 | mov al,0 |
||
305 | mov ecx,MAX_PATH |
||
306 | add edi,ecx |
||
307 | dec edi |
||
308 | std |
||
309 | repe scasb |
||
310 | sub ecx,MAX_PATH |
||
311 | neg ecx |
||
312 | mov al,$1C ; '' |
||
313 | add edi,2 |
||
314 | push edi |
||
315 | cld |
||
316 | rep stosb |
||
317 | call print_text |
||
318 | pop edi |
||
319 | f11:mcall 10 |
||
320 | cmp eax,2 |
||
321 | jne read_done |
||
322 | mcall; 2 |
||
323 | shr eax,8 |
||
324 | cmp al,13 |
||
109 | heavyiron | 325 | je read_done |
31 | halyavin | 326 | cmp al,8 |
327 | jne nobs |
||
328 | cmp edi,[addr] |
||
109 | heavyiron | 329 | je f11 |
31 | halyavin | 330 | sub edi,1 |
331 | mov byte[edi],$1C ; '_' |
||
332 | call print_text |
||
333 | jmp f11 |
||
334 | nobs: |
||
335 | movzx ebx,al |
||
336 | sub ebx,$20 |
||
337 | jle f11 |
||
338 | sub al,[sub_table+ebx] |
||
339 | keyok: |
||
340 | mov ecx,[addr] |
||
341 | add ecx,MAX_PATH |
||
342 | cmp edi,ecx |
||
343 | jae f11 |
||
344 | mov [edi],al |
||
345 | |||
346 | call print_text |
||
347 | inc edi |
||
348 | jmp f11 |
||
349 | |||
350 | read_done: |
||
351 | |||
352 | mov ecx,[addr] |
||
353 | add ecx,MAX_PATH |
||
354 | sub ecx,edi |
||
355 | mov al,0;' ' |
||
356 | cld |
||
357 | rep stosb |
||
358 | call print_text |
||
359 | |||
360 | jmp still |
||
361 | |||
362 | print_text: |
||
363 | |||
174 | heavyiron | 364 | mpack ebx,MAGIC1+6,[pinfo.x_size] |
31 | halyavin | 365 | sub ebx,MAGIC1*2+5*2+6+3 |
366 | movzx esi,bx |
||
367 | mov ecx,[ya-2] |
||
368 | mov cx,8 |
||
369 | mcall 13,,,[sc.work] |
||
370 | |||
174 | heavyiron | 371 | mpack ebx,MAGIC1+6,[ya] |
31 | halyavin | 372 | mov eax,esi |
373 | mov cl,6 |
||
374 | div cl |
||
375 | cmp al,MAX_PATH |
||
376 | jbe @f |
||
377 | mov al,MAX_PATH |
||
378 | @@: movzx esi,al |
||
379 | mcall 4,,[sc.work_text],[addr] |
||
380 | |||
381 | ret |
||
382 | |||
383 | |||
384 | ; DATA |
||
385 | |||
174 | heavyiron | 386 | header db appname,version,0 |
31 | halyavin | 387 | |
388 | text: |
||
389 | db ' INFILE:' |
||
390 | .line_size = $-text |
||
391 | db 'OUTFILE:' |
||
392 | db ' PATH:' |
||
393 | db 'x' |
||
394 | |||
395 | s_compile db 'COMPILE' |
||
109 | heavyiron | 396 | s_run db ' RUN ' |
31 | halyavin | 397 | |
109 | heavyiron | 398 | infile db 'EXAMPLE.ASM' |
31 | halyavin | 399 | times MAX_PATH+$-infile db 0 |
400 | outfile db 'EXAMPLE' |
||
401 | times MAX_PATH+$-outfile db 0 |
||
109 | heavyiron | 402 | path db '/RD/1/' |
31 | halyavin | 403 | times MAX_PATH+$-path db 0 |
404 | |||
405 | lf db 13,10,0 |
||
406 | |||
407 | addr dd 0x0 |
||
408 | ya dd 0x0 |
||
409 | zero db 0x0 |
||
410 | |||
411 | mov_param_str: |
||
412 | @@: |
||
413 | mov al,[esi] |
||
414 | cmp al,',' |
||
109 | heavyiron | 415 | je @f |
31 | halyavin | 416 | cmp al,0 |
109 | heavyiron | 417 | je @f |
31 | halyavin | 418 | mov [edi],al |
419 | inc esi |
||
420 | inc edi |
||
421 | jmp @b |
||
422 | @@: |
||
423 | mov al,0 |
||
424 | stosb |
||
425 | ret |
||
426 | |||
427 | start: |
||
428 | cmp [_mode],NORMAL_MODE |
||
429 | jne @f |
||
430 | call draw_messages |
||
174 | heavyiron | 431 | push 0 |
31 | halyavin | 432 | pop [textxy] |
433 | add [textxy],OUTPUTXY |
||
434 | @@: |
||
435 | mov esi,_logo |
||
436 | call display_string |
||
437 | |||
438 | ; |
||
439 | ; Fasm native code |
||
440 | ; |
||
441 | |||
442 | mov [input_file],infile |
||
443 | mov [output_file],outfile |
||
444 | |||
445 | call init_memory |
||
446 | |||
447 | call make_timestamp |
||
448 | mov [start_time],eax |
||
449 | |||
450 | call preprocessor |
||
451 | call parser |
||
452 | call assembler |
||
453 | call formatter |
||
454 | |||
455 | call display_user_messages |
||
456 | movzx eax,[current_pass] |
||
457 | inc eax |
||
458 | call display_number |
||
459 | mov esi,_passes_suffix |
||
460 | call display_string |
||
461 | call make_timestamp |
||
462 | sub eax,[start_time] |
||
463 | xor edx,edx |
||
464 | mov ebx,100 |
||
465 | div ebx |
||
109 | heavyiron | 466 | or eax,eax |
467 | jz display_bytes_count |
||
31 | halyavin | 468 | xor edx,edx |
469 | mov ebx,10 |
||
470 | div ebx |
||
471 | push edx |
||
472 | call display_number |
||
473 | mov dl,'.' |
||
474 | call display_character |
||
475 | pop eax |
||
476 | call display_number |
||
477 | mov esi,_seconds_suffix |
||
478 | call display_string |
||
479 | display_bytes_count: |
||
480 | mov eax,[written_size] |
||
481 | call display_number |
||
482 | mov esi,_bytes_suffix |
||
483 | call display_string |
||
484 | xor al,al |
||
485 | |||
486 | cmp [_run_outfile],0 |
||
109 | heavyiron | 487 | je @f |
31 | halyavin | 488 | mov edx,outfile |
489 | call make_fullpaths |
||
174 | heavyiron | 490 | mov eax,70 |
31 | halyavin | 491 | mov ebx,file_info_start |
492 | xor ecx,ecx |
||
493 | int 0x40 |
||
494 | @@: |
||
495 | jmp exit_program |
||
496 | |||
497 | |||
498 | include 'system.inc' |
||
499 | |||
500 | include 'version.inc' |
||
501 | include 'errors.inc' |
||
502 | include 'expressi.inc' |
||
503 | include 'preproce.inc' |
||
504 | include 'parser.inc' |
||
505 | include 'assemble.inc' |
||
506 | include 'formats.inc' |
||
507 | include 'x86_64.inc' |
||
109 | heavyiron | 508 | include 'tables.inc' |
31 | halyavin | 509 | |
510 | _logo db 'flat assembler version ',VERSION_STRING,13,10,0 |
||
511 | |||
512 | _passes_suffix db ' passes, ',0 |
||
513 | _seconds_suffix db ' seconds, ',0 |
||
514 | _bytes_suffix db ' bytes.',13,10,0 |
||
515 | |||
516 | _include db 'INCLUDE',0 |
||
517 | |||
518 | _counter db 4,'0000' |
||
519 | |||
109 | heavyiron | 520 | _mode dd NORMAL_MODE |
31 | halyavin | 521 | _run_outfile dd 0 |
522 | |||
523 | sub_table: |
||
524 | times $41 db $00 |
||
525 | times $1A db $20 |
||
526 | times $25 db $00 |
||
527 | times $10 db $20 |
||
528 | times $30 db $00 |
||
529 | times $10 db $50 |
||
530 | times $04 db $00,$01 |
||
531 | times $08 db $00 |
||
532 | |||
533 | ;include_debug_strings |
||
534 | |||
535 | params db 0 ; 'TINYPAD.ASM,TINYPAD,/HD/1/TPAD4/', |
||
536 | program_end: |
||
537 | rb 1000h |
||
538 | |||
539 | align 4 |
||
540 | |||
541 | include 'variable.inc' |
||
542 | |||
543 | program_base dd ? |
||
544 | buffer_address dd ? |
||
545 | memory_setting dd ? |
||
546 | start_time dd ? |
||
547 | |||
548 | sc system_colors |
||
549 | pinfo process_information |