Subversion Repositories Kolibri OS

Rev

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