Subversion Repositories Kolibri OS

Rev

Rev 526 | 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
51
   mov    al,' '
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:
128
 
174 heavyiron 129
    mov  ecx,5
31 halyavin 130
    mov  [ya],ecx
131
 
109 heavyiron 132
    cmp  ah,11	   ; Infile
174 heavyiron 133
    je   f1
109 heavyiron 134
    cmp  ah,12	   ; Outfile
174 heavyiron 135
    je   f2
109 heavyiron 136
    cmp  ah,13	   ; Path
174 heavyiron 137
    je   f3
31 halyavin 138
 
174 heavyiron 139
    jmp  still
31 halyavin 140
 
141
 
142
draw_window:
143
 
144
    pusha
145
 
146
    mcall  12,1 ; Start of draw
147
 
148
    get_sys_colors 1,0
149
 
220 heavyiron 150
    xor  eax,eax
174 heavyiron 151
    mov  ebx,50*65536+280
152
    mov  ecx,50*65536+250
153
    mov  edx,[sc.work]
154
    or   edx,0x33000000
485 heavyiron 155
    mov  edi,title             ; Draw Window Label Text
156
    mcall
31 halyavin 157
 
174 heavyiron 158
    mcall 9,PROCESSINFO,-1
31 halyavin 159
 
174 heavyiron 160
    mpack ecx,1,1
502 heavyiron 161
    mov   ebx,[pinfo.box.width]
174 heavyiron 162
    sub   ebx,10
31 halyavin 163
 
164
    push  ecx
370 heavyiron 165
    madd  ecx, 14*3+2, 14*3+2
31 halyavin 166
    mcall 38,,,[sc.work_graph]
167
    pop   ecx
168
 
169
    sub   ebx,MAGIC1+3
170
    mcall
370 heavyiron 171
    madd  ecx, 14, 14
31 halyavin 172
    mcall
370 heavyiron 173
    madd  ecx, 14, 14
31 halyavin 174
    mcall
370 heavyiron 175
    madd  ecx, 14, 14
31 halyavin 176
    mcall
177
    push  ebx
174 heavyiron 178
    mpack ebx,MAGIC1,MAGIC1
370 heavyiron 179
    sub   ecx, 14*3
31 halyavin 180
    mcall
181
    mov   ebx,[esp-2]
182
    pop   bx
183
    mcall
184
    add   esp,2
185
 
174 heavyiron 186
    mpack ebx,0,MAGIC1-1
370 heavyiron 187
    mpack ecx,1+1, 14-2
31 halyavin 188
    mcall 8,,,0x4000000B       ; Button: Enter Infile
370 heavyiron 189
    madd  ecx, 14,0
31 halyavin 190
    mcall  ,,,0x4000000C       ; Button: Enter Outfile
370 heavyiron 191
    madd  ecx, 14,0
31 halyavin 192
    mcall  ,,,0x4000000D       ; Button: Enter Path
193
 
502 heavyiron 194
    mpack ebx,[pinfo.box.width],MAGIC1
174 heavyiron 195
    msub  ebx,MAGIC1+10+1,0
370 heavyiron 196
    mpack ecx,0, 14*3/2-1
197
    madd  ecx,1,0
31 halyavin 198
    mcall  ,,,0x00000002,[sc.work_button]
370 heavyiron 199
    madd  ecx, 14*3/2+1,0
31 halyavin 200
    mcall  ,,,0x00000003
201
 
174 heavyiron 202
    mpack ebx,6,0    ; Draw Window Text
370 heavyiron 203
    add  ebx,1+ 14/2-3
31 halyavin 204
    mov  ecx,[sc.work_text]
205
    mov  edx,text
206
    mov  esi,text.line_size
207
    mov  eax,4
208
   newline:
485 heavyiron 209
    mcall
370 heavyiron 210
    add  ebx, 14
31 halyavin 211
    add  edx,text.line_size
212
    cmp  byte[edx],'x'
213
    jne  newline
214
 
502 heavyiron 215
    mov   ebx,[pinfo.box.width]
174 heavyiron 216
    sub   ebx,MAGIC1+10+1-9
31 halyavin 217
    shl   ebx,16
370 heavyiron 218
    add   ebx,1+( 14*3/2-1)/2-3
31 halyavin 219
    mcall  ,,[sc.work_button_text],s_compile,7
370 heavyiron 220
    add   ebx,14*3/2+1
31 halyavin 221
    mcall ,,,s_run
222
 
174 heavyiron 223
    mpack ebx,MAGIC1+6,0
370 heavyiron 224
    add   ebx,1+ 14/2-3+ 14*0
502 heavyiron 225
    mov   esi,[pinfo.box.width]
31 halyavin 226
    sub   esi,MAGIC1*2+5*2+6+3
227
    mov   eax,esi
228
    mov   cl,6
229
    div   cl
230
    cmp   al,MAX_PATH
231
    jbe   @f
232
    mov   al,MAX_PATH
233
@@: movzx esi,al
234
    mcall 4,,[sc.work_text],infile
370 heavyiron 235
    add   ebx,14
31 halyavin 236
    mcall ,,,outfile
370 heavyiron 237
    add   ebx,14
31 halyavin 238
    mcall ,,,path
239
 
240
    call  draw_messages
241
 
242
    mcall  12,2 ; End of Draw
243
 
244
    popa
245
    ret
246
 
247
bottom_right dd ?
248
 
249
draw_messages:
250
    mov    eax,13      ; clear work area
502 heavyiron 251
    mpack  ebx,7-2,[pinfo.box.width]
370 heavyiron 252
    sub    ebx,5*2+7*2-1-2*2
502 heavyiron 253
    mpack  ecx,0,[pinfo.box.height]
370 heavyiron 254
    madd   ecx, 14*3+1+7+1,-( 14*3+1+7*2+25)
31 halyavin 255
    mov    word[bottom_right+2],bx
256
    mov    word[bottom_right],cx
257
    msub   [bottom_right],7,11
370 heavyiron 258
    add    [bottom_right],7 shl 16 + 53
31 halyavin 259
    mov    edx,[sc.work]
485 heavyiron 260
    mcall
31 halyavin 261
_cy = 0
262
_sy = 2
263
_cx = 4
264
_sx = 6
265
    push   ebx ecx
370 heavyiron 266
    mpack  ebx,4,5
31 halyavin 267
    add    bx,[esp+_cx]
268
    mov    ecx,[esp+_sy-2]
269
    mov    cx,[esp+_sy]
270
    msub   ecx,1,1
271
    mcall  38,,,[sc.work_graph]
272
    mov    si,[esp+_cy]
273
    add    cx,si
274
    shl    esi,16
275
    add    ecx,esi
276
    madd   ecx,1,1
277
    mcall
370 heavyiron 278
    mpack  ebx,4,4
31 halyavin 279
    mov    esi,[esp+_sy-2]
280
    mov    si,cx
281
    mov    ecx,esi
282
    mcall
283
    mov    si,[esp+_cx]
284
    add    bx,si
285
    shl    esi,16
286
    add    ebx,esi
287
    madd   ebx,1,1
288
    mcall
289
    pop    ecx ebx
290
    ret
291
 
292
; read string
293
 
294
f1: mov  [addr],infile
370 heavyiron 295
    add  [ya], 14*0
31 halyavin 296
    jmp  rk
297
f2: mov  [addr],outfile
370 heavyiron 298
    add  [ya], 14*1
31 halyavin 299
    jmp  rk
300
f3: mov  [addr],path
370 heavyiron 301
    add  [ya], 14*2
31 halyavin 302
rk:
303
 
304
    mov  edi,[addr]
305
    mov  al,0
306
    mov  ecx,MAX_PATH
307
    add  edi,ecx
308
    dec  edi
309
    std
310
    repe scasb
311
    sub  ecx,MAX_PATH
312
    neg  ecx
313
    mov  al,$1C ; ''
314
    add  edi,2
315
    push  edi
316
    cld
317
    rep  stosb
318
    call print_text
319
    pop edi
320
f11:mcall  10
321
    cmp    eax,2
322
    jne read_done
323
    mcall; 2
324
    shr    eax,8
325
    cmp    al,13
109 heavyiron 326
    je	  read_done
31 halyavin 327
    cmp    al,8
328
    jne nobs
329
    cmp    edi,[addr]
109 heavyiron 330
    je	  f11
31 halyavin 331
    sub    edi,1
332
    mov    byte[edi],$1C ; '_'
333
    call   print_text
334
    jmp    f11
335
   nobs:
336
    movzx  ebx,al
337
    sub    ebx,$20
338
    jle    f11
339
    sub    al,[sub_table+ebx]
340
   keyok:
341
    mov    ecx,[addr]
342
    add    ecx,MAX_PATH
343
    cmp    edi,ecx
344
    jae    f11
345
    mov    [edi],al
346
 
347
    call   print_text
348
    inc    edi
349
    jmp f11
350
 
351
  read_done:
352
 
353
    mov    ecx,[addr]
354
    add    ecx,MAX_PATH
355
    sub    ecx,edi
356
    mov    al,0;' '
357
    cld
358
    rep    stosb
359
    call   print_text
360
 
361
    jmp    still
362
 
363
print_text:
364
 
502 heavyiron 365
    mpack ebx,MAGIC1+6,[pinfo.box.width]
370 heavyiron 366
    sub   ebx,MAGIC1*2+19
31 halyavin 367
    movzx esi,bx
368
    mov   ecx,[ya-2]
369
    mov   cx,8
370
    mcall 13,,,[sc.work]
371
 
174 heavyiron 372
    mpack ebx,MAGIC1+6,[ya]
31 halyavin 373
    mov   eax,esi
374
    mov   cl,6
375
    div   cl
376
    cmp   al,MAX_PATH
377
    jbe   @f
378
    mov   al,MAX_PATH
379
@@: movzx esi,al
380
    mcall 4,,[sc.work_text],[addr]
381
 
382
    ret
383
 
384
 
385
; DATA
386
 
387
text:
388
  db ' INFILE:'
389
.line_size = $-text
390
  db 'OUTFILE:'
391
  db '   PATH:'
392
  db 'x'
393
 
394
s_compile db 'COMPILE'
109 heavyiron 395
s_run	   db '  RUN  '
31 halyavin 396
 
205 heavyiron 397
infile	  db 'example.asm'
31 halyavin 398
  times MAX_PATH+$-infile  db 0
205 heavyiron 399
outfile db 'example'
31 halyavin 400
  times MAX_PATH+$-outfile db 0
539 spraid 401
path	db '/sys/'
31 halyavin 402
  times MAX_PATH+$-path    db 0
403
 
404
lf db 13,10,0
405
 
406
addr dd 0x0
407
ya   dd 0x0
408
zero db 0x0
409
 
410
mov_param_str:
411
  @@:
412
    mov    al,[esi]
413
    cmp    al,','
109 heavyiron 414
    je	     @f
31 halyavin 415
    cmp    al,0
109 heavyiron 416
    je	     @f
31 halyavin 417
    mov    [edi],al
418
    inc    esi
419
    inc    edi
420
    jmp    @b
421
  @@:
422
    mov    al,0
423
    stosb
424
ret
425
 
426
start:
427
    cmp    [_mode],NORMAL_MODE
428
    jne    @f
429
    call   draw_messages
174 heavyiron 430
    push   0
31 halyavin 431
    pop    [textxy]
370 heavyiron 432
    add    [textxy],7 shl 16 + 53
31 halyavin 433
@@:
434
    mov    esi,_logo
435
    call   display_string
436
 
437
 ;
438
 ;   Fasm native code
439
 ;
440
 
441
    mov    [input_file],infile
442
    mov    [output_file],outfile
443
 
444
    call   init_memory
445
 
446
    call   make_timestamp
447
    mov    [start_time],eax
448
 
449
    call   preprocessor
450
    call   parser
451
    call   assembler
452
    call   formatter
453
 
454
    call   display_user_messages
455
    movzx  eax,[current_pass]
456
    inc    eax
457
    call   display_number
458
    mov    esi,_passes_suffix
459
    call   display_string
460
    call   make_timestamp
461
    sub    eax,[start_time]
462
    xor    edx,edx
463
    mov    ebx,100
464
    div    ebx
109 heavyiron 465
    or	     eax,eax
466
    jz	     display_bytes_count
31 halyavin 467
    xor    edx,edx
468
    mov    ebx,10
469
    div    ebx
470
    push   edx
471
    call   display_number
472
    mov    dl,'.'
473
    call   display_character
474
    pop    eax
475
    call   display_number
476
    mov    esi,_seconds_suffix
477
    call   display_string
478
  display_bytes_count:
479
    mov    eax,[written_size]
480
    call   display_number
481
    mov    esi,_bytes_suffix
482
    call   display_string
483
    xor    al,al
484
 
485
    cmp    [_run_outfile],0
370 heavyiron 486
    je     @f
31 halyavin 487
    mov    edx,outfile
488
    call   make_fullpaths
174 heavyiron 489
    mov    eax,70
31 halyavin 490
    mov    ebx,file_info_start
491
    xor    ecx,ecx
485 heavyiron 492
    mcall
31 halyavin 493
@@:
494
    jmp    exit_program
495
 
496
 
497
include 'system.inc'
498
include 'version.inc'
499
include 'errors.inc'
500
include 'expressi.inc'
501
include 'preproce.inc'
502
include 'parser.inc'
503
include 'assemble.inc'
504
include 'formats.inc'
505
include 'x86_64.inc'
109 heavyiron 506
include 'tables.inc'
31 halyavin 507
 
485 heavyiron 508
title db appname,VERSION_STRING,0
196 heavyiron 509
 
31 halyavin 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
332 diamond 549
max_handles = 8
550
fileinfos rb (4+20+MAX_PATH)*max_handles
551
fileinfos_end:
31 halyavin 552
pinfo process_information