Subversion Repositories Kolibri OS

Rev

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