Subversion Repositories Kolibri OS

Rev

Rev 370 | 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'
31 halyavin 36
include 'fasm.inc'
37
 
38
center fix true
39
 
109 heavyiron 40
START:	    ; Start of execution
332 diamond 41
        mov     edi, fileinfos
42
        mov     ecx, (fileinfos_end-fileinfos)/4
43
        or      eax, -1
44
        rep     stosd
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
485 heavyiron 94
    mcall
174 heavyiron 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
485 heavyiron 102
    mcall
31 halyavin 103
    jmp  still
104
 
174 heavyiron 105
button:    ; Button in Window
31 halyavin 106
 
174 heavyiron 107
    mov  al,17
485 heavyiron 108
    mcall
31 halyavin 109
 
174 heavyiron 110
    cmp     ah,1
111
    jne     noclose
112
    or      eax,-1
485 heavyiron 113
    mcall
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
 
220 heavyiron 149
    xor  eax,eax
174 heavyiron 150
    mov  ebx,50*65536+280
151
    mov  ecx,50*65536+250
152
    mov  edx,[sc.work]
153
    or   edx,0x33000000
485 heavyiron 154
    mov  edi,title             ; Draw Window Label Text
155
    mcall
31 halyavin 156
 
174 heavyiron 157
    mcall 9,PROCESSINFO,-1
31 halyavin 158
 
174 heavyiron 159
    mpack ecx,1,1
485 heavyiron 160
    mov   ebx,[pinfo.box.left]
174 heavyiron 161
    sub   ebx,10
31 halyavin 162
 
163
    push  ecx
370 heavyiron 164
    madd  ecx, 14*3+2, 14*3+2
31 halyavin 165
    mcall 38,,,[sc.work_graph]
166
    pop   ecx
167
 
168
    sub   ebx,MAGIC1+3
169
    mcall
370 heavyiron 170
    madd  ecx, 14, 14
31 halyavin 171
    mcall
370 heavyiron 172
    madd  ecx, 14, 14
31 halyavin 173
    mcall
370 heavyiron 174
    madd  ecx, 14, 14
31 halyavin 175
    mcall
176
    push  ebx
174 heavyiron 177
    mpack ebx,MAGIC1,MAGIC1
370 heavyiron 178
    sub   ecx, 14*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
370 heavyiron 186
    mpack ecx,1+1, 14-2
31 halyavin 187
    mcall 8,,,0x4000000B       ; Button: Enter Infile
370 heavyiron 188
    madd  ecx, 14,0
31 halyavin 189
    mcall  ,,,0x4000000C       ; Button: Enter Outfile
370 heavyiron 190
    madd  ecx, 14,0
31 halyavin 191
    mcall  ,,,0x4000000D       ; Button: Enter Path
192
 
485 heavyiron 193
    mpack ebx,[pinfo.box.left],MAGIC1
174 heavyiron 194
    msub  ebx,MAGIC1+10+1,0
370 heavyiron 195
    mpack ecx,0, 14*3/2-1
196
    madd  ecx,1,0
31 halyavin 197
    mcall  ,,,0x00000002,[sc.work_button]
370 heavyiron 198
    madd  ecx, 14*3/2+1,0
31 halyavin 199
    mcall  ,,,0x00000003
200
 
174 heavyiron 201
    mpack ebx,6,0    ; Draw Window Text
370 heavyiron 202
    add  ebx,1+ 14/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:
485 heavyiron 208
    mcall
370 heavyiron 209
    add  ebx, 14
31 halyavin 210
    add  edx,text.line_size
211
    cmp  byte[edx],'x'
212
    jne  newline
213
 
485 heavyiron 214
    mov   ebx,[pinfo.box.left]
174 heavyiron 215
    sub   ebx,MAGIC1+10+1-9
31 halyavin 216
    shl   ebx,16
370 heavyiron 217
    add   ebx,1+( 14*3/2-1)/2-3
31 halyavin 218
    mcall  ,,[sc.work_button_text],s_compile,7
370 heavyiron 219
    add   ebx,14*3/2+1
31 halyavin 220
    mcall ,,,s_run
221
 
174 heavyiron 222
    mpack ebx,MAGIC1+6,0
370 heavyiron 223
    add   ebx,1+ 14/2-3+ 14*0
485 heavyiron 224
    mov   esi,[pinfo.box.left]
31 halyavin 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
370 heavyiron 234
    add   ebx,14
31 halyavin 235
    mcall ,,,outfile
370 heavyiron 236
    add   ebx,14
31 halyavin 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
485 heavyiron 250
    mpack  ebx,7-2,[pinfo.box.left]
370 heavyiron 251
    sub    ebx,5*2+7*2-1-2*2
485 heavyiron 252
    mpack  ecx,0,[pinfo.box.top]
370 heavyiron 253
    madd   ecx, 14*3+1+7+1,-( 14*3+1+7*2+25)
31 halyavin 254
    mov    word[bottom_right+2],bx
255
    mov    word[bottom_right],cx
256
    msub   [bottom_right],7,11
370 heavyiron 257
    add    [bottom_right],7 shl 16 + 53
31 halyavin 258
    mov    edx,[sc.work]
485 heavyiron 259
    mcall
31 halyavin 260
_cy = 0
261
_sy = 2
262
_cx = 4
263
_sx = 6
264
    push   ebx ecx
370 heavyiron 265
    mpack  ebx,4,5
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
370 heavyiron 277
    mpack  ebx,4,4
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
370 heavyiron 294
    add  [ya], 14*0
31 halyavin 295
    jmp  rk
296
f2: mov  [addr],outfile
370 heavyiron 297
    add  [ya], 14*1
31 halyavin 298
    jmp  rk
299
f3: mov  [addr],path
370 heavyiron 300
    add  [ya], 14*2
31 halyavin 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
 
485 heavyiron 364
    mpack ebx,MAGIC1+6,[pinfo.box.left]
370 heavyiron 365
    sub   ebx,MAGIC1*2+19
31 halyavin 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
 
386
text:
387
  db ' INFILE:'
388
.line_size = $-text
389
  db 'OUTFILE:'
390
  db '   PATH:'
391
  db 'x'
392
 
393
s_compile db 'COMPILE'
109 heavyiron 394
s_run	   db '  RUN  '
31 halyavin 395
 
205 heavyiron 396
infile	  db 'example.asm'
31 halyavin 397
  times MAX_PATH+$-infile  db 0
205 heavyiron 398
outfile db 'example'
31 halyavin 399
  times MAX_PATH+$-outfile db 0
205 heavyiron 400
path	db '/rd/1/'
31 halyavin 401
  times MAX_PATH+$-path    db 0
402
 
403
lf db 13,10,0
404
 
405
addr dd 0x0
406
ya   dd 0x0
407
zero db 0x0
408
 
409
mov_param_str:
410
  @@:
411
    mov    al,[esi]
412
    cmp    al,','
109 heavyiron 413
    je	     @f
31 halyavin 414
    cmp    al,0
109 heavyiron 415
    je	     @f
31 halyavin 416
    mov    [edi],al
417
    inc    esi
418
    inc    edi
419
    jmp    @b
420
  @@:
421
    mov    al,0
422
    stosb
423
ret
424
 
425
start:
426
    cmp    [_mode],NORMAL_MODE
427
    jne    @f
428
    call   draw_messages
174 heavyiron 429
    push   0
31 halyavin 430
    pop    [textxy]
370 heavyiron 431
    add    [textxy],7 shl 16 + 53
31 halyavin 432
@@:
433
    mov    esi,_logo
434
    call   display_string
435
 
436
 ;
437
 ;   Fasm native code
438
 ;
439
 
440
    mov    [input_file],infile
441
    mov    [output_file],outfile
442
 
443
    call   init_memory
444
 
445
    call   make_timestamp
446
    mov    [start_time],eax
447
 
448
    call   preprocessor
449
    call   parser
450
    call   assembler
451
    call   formatter
452
 
453
    call   display_user_messages
454
    movzx  eax,[current_pass]
455
    inc    eax
456
    call   display_number
457
    mov    esi,_passes_suffix
458
    call   display_string
459
    call   make_timestamp
460
    sub    eax,[start_time]
461
    xor    edx,edx
462
    mov    ebx,100
463
    div    ebx
109 heavyiron 464
    or	     eax,eax
465
    jz	     display_bytes_count
31 halyavin 466
    xor    edx,edx
467
    mov    ebx,10
468
    div    ebx
469
    push   edx
470
    call   display_number
471
    mov    dl,'.'
472
    call   display_character
473
    pop    eax
474
    call   display_number
475
    mov    esi,_seconds_suffix
476
    call   display_string
477
  display_bytes_count:
478
    mov    eax,[written_size]
479
    call   display_number
480
    mov    esi,_bytes_suffix
481
    call   display_string
482
    xor    al,al
483
 
484
    cmp    [_run_outfile],0
370 heavyiron 485
    je     @f
31 halyavin 486
    mov    edx,outfile
487
    call   make_fullpaths
174 heavyiron 488
    mov    eax,70
31 halyavin 489
    mov    ebx,file_info_start
490
    xor    ecx,ecx
485 heavyiron 491
    mcall
31 halyavin 492
@@:
493
    jmp    exit_program
494
 
495
 
496
include 'system.inc'
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
 
485 heavyiron 507
title db appname,VERSION_STRING,0
196 heavyiron 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
332 diamond 548
max_handles = 8
549
fileinfos rb (4+20+MAX_PATH)*max_handles
550
fileinfos_end:
31 halyavin 551
pinfo process_information