Subversion Repositories Kolibri OS

Rev

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