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