Subversion Repositories Kolibri OS

Rev

Rev 7859 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7836 leency 1
 
2
; Copyright (c) 1999-2020, Tomasz Grysztar.
3
; All rights reserved.
4
5
 
6
7
 
8
appname equ 'flat assembler '
9
;-------------------------------------------------
10
; HEADER
11
;-------------------------------------------------
12
	db 'MENUET01'  ; 8 byte id
13
	dd 0x01  ; header version
14
	dd START	 ; program start
15
	dd program_end ; program image size
16
	dd stacktop	 ; required amount of memory
17
	dd stacktop	 ; stack
18
	dd params	 ; parameters
19
	dd cur_dir_path  ; icon
20
	if defined import.data
21
		dd import.data
22
	else
23
		dd 0
24
	end if
25
;-------------------------------------------------
26
; INCLUDES
27
;-------------------------------------------------
28
lang equ ru
29
include 'kolibria.inc'
30
include 'fasm.inc'
31
32
 
33
struc path name:?& {
34
        .:
35
	db name
36
	rb MAX_PATH-$+. }
37
;-------------------------------------------------
38
; CODE
39
;-------------------------------------------------
40
use32
41
include 'kolibri/osloader/osloader.inc'
42
;-------------------------------------------------
43
parse_params:
44
45
 
46
	jnz @f
47
	ret
48
@@:
49
	cmp	[params],0
50
	jnz	.chunk.console
51
	ret
52
      .chunk.console:
53
	mov	[_mode],CONSOLE_MODE
54
	mov	dword [esp], CUI_START ; force retaddr to CUI_START
55
56
 
57
	mov	esi, 10
58
	cld
59
	mov	ecx, esi
60
	mov	edi, infile
61
	rep stosd
62
	mov	ecx, esi
63
	mov	edi, outfile
64
	rep stosd
65
	mov	ecx, esi
66
	mov	edi, path
67
	rep stosd
68
69
 
70
	mov	edi, params
71
	mov	al, ' '
72
	repe scasb
73
	mov	esi, edi
74
	dec	esi
75
76
 
77
    @@: lodsb
78
	scasb
79
	jne	.NoOutDebugInfo
80
	cmp	byte[edi], 0
81
	jnz	@b
82
83
 
84
	jne	.NoOutDebugInfo
85
86
 
87
	mov	al,' '
88
	repe	scasb
89
	mov	esi,edi
90
	dec	esi
91
92
 
93
    @@: lodsb
94
	stosb
95
	test	al,al
96
	jnz	@b
97
98
 
99
100
 
101
 
102
	mov	[_mode],CONSOLE_MODE
103
	regcall mov_param_str,,,,,params,infile
104
	regcall mov_param_str,,,,,esi,outfile
105
	regcall mov_param_str,,,,,esi,path
106
	mov	eax, [esi-1]
107
	cmp	al,','
108
	jne	.locret
109
	cmp	eax, ',run'
110
	jne	.check_again
111
	mov	[_run_outfile],1
112
	jmp	.locret
113
      .check_again:
114
	cmp	eax, ',dbg'
115
	jne	.locret
116
	mov	[_run_outfile],2
117
      .locret:
118
	ret
119
;-------------------------------------------------
120
START:	    ; Start of execution
121
	mov	edi, fileinfos
122
	mov	ecx, (fileinfos_end-fileinfos)/4
123
	or	eax, -1
124
	rep	stosd
125
	mcall	SF_SYS_MISC,SSF_HEAP_INIT
126
127
 
128
	mcall	SF_SYS_MISC,SSF_MEM_ALLOC,$1000
129
	mov	[file_io_notify.flags],eax
130
131
 
132
133
 
134
	invoke	init_checkbox,ch1_dbg
135
	invoke	OpenDialog_Init,OpenDialog_data
136
137
 
138
still:
139
	sub	esp,4
140
	mcall	SF_WAIT_EVENT	   ; Wait here for event
141
	movzx	ecx,al
142
	jmp	[event_handlers+4*ecx]
143
event_handlers	dd 0,do_redraw,key,button,0,0,mouse
144
;-------------------------------------------------
145
key:		     ; Key
146
	mcall	SF_GET_KEY	 ; Read it and ignore
147
	invoke	edit_box_key, edit1
148
	invoke	edit_box_key, edit2
149
	invoke	edit_box_key, edit3
150
	ret
151
;-------------------------------------------------
152
button:    ; Button in Window
153
	mcall	SF_GET_BUTTON
154
	movzx	ecx,ah
155
	jmp	[button_handlers+4*ecx]
156
button_handlers dd 0,btn_close,CUI_START,btn_runout,btn_rundbg,fun_opn_dlg
157
;-------------------------------------------------
158
btn_close:
159
	mcall	SF_TERMINATE_PROCESS
160
;-------------------------------------------------
161
btn_runout:
162
	mov	edx,outfile
163
	call	make_fullpaths
164
	mcall	SF_FILE,file_io_start
165
	ret
166
;-------------------------------------------------
167
btn_rundbg:
168
	mov	edx,outfile
169
	call	make_fullpaths
170
	mcall	SF_FILE,file_io_debug
171
	ret
172
;-------------------------------------------------
173
mouse:
174
	invoke	edit_box_mouse, edit1
175
	invoke	edit_box_mouse, edit2
176
	invoke	edit_box_mouse, edit3
177
	invoke	check_box_mouse,ch1_dbg
178
	ret
179
;-------------------------------------------------
180
Edit_Update_Colors:
181
	mov	[edi+EDIT_BOX.focus_border_color], ebx
182
	mov	[edi+EDIT_BOX.blur_border_color], eax
183
	ret
184
;-------------------------------------------------
185
CheckBox_Update_Colors:
186
	or eax, 0x10000000
187
	mov	[edi+CHECK_BOX2.text_color], eax
188
	mov	[edi+CHECK_BOX2.border_color], ebx
189
	ret
190
;-------------------------------------------------
191
accept_systemcolors:
192
	mcall	SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors
193
	or	[sc.work], $3000000
194
	mov	esi, sc
195
	mov	edi, sc_prev
196
	mov	ecx, sizeof.system_colors/4
197
	repe cmpsd
198
	jne	.chunk.update_colors
199
	ret
200
      .chunk.update_colors:
201
	inc	ecx    ; move back
202
	sub	edi, 4 ; on first element
203
	sub	esi, 4 ; that not match
204
	rep movsd      ; copy only difference part
205
	mov	eax, [sc.work]
206
	mov	ebx, [sc.work_graph]
207
	shr	eax, 1
208
	shr	ebx, 1
209
	and	eax, $7F7F7F
210
	and	ebx, $7F7F7F
211
	add	eax, ebx
212
	regcall Edit_Update_Colors,eax, ebx,,,,edit1
213
	regcall Edit_Update_Colors,eax, ebx,,,,edit2
214
	regcall Edit_Update_Colors,eax, ebx,,,,edit3
215
	mov	eax, [sc.work_text]
216
	or	eax, $80000000
217
	mov	ebx, [sc.work_graph]
218
	regcall CheckBox_Update_Colors,eax, ebx,,,,ch1_dbg
219
	ret
220
;-------------------------------------------------
221
draw_window:
222
	cmp	dword[PROCESS_INFO.client_box.width],WIN_MIN_W
223
	jge	@f
224
	mcall   67,-1,-1,WIN_MIN_W+20,-1
225
	ret
226
@@:
227
	cmp	dword[PROCESS_INFO.client_box.height],WIN_MIN_H
228
	jge	@f
229
	mcall   67,-1,-1,-1,WIN_MIN_H+50
230
	ret
231
@@:
232
	mpack	ebx,[PROCESS_INFO.client_box.width],RIGHT_BTN_W
233
	msub	ebx,RIGHT_BTN_W+1,0
234
	mcall	SF_DEFINE_BUTTON,ebx,,ID_COMPILE_BTN,[sc.work_button]
235
	mcallb	SF_DEFINE_BUTTON,ebx,,ID_EXECUTE_BTN
236
	mcallb	SF_DEFINE_BUTTON,ebx,,ID_EXECDBG_BTN
237
238
 
239
240
 
241
	or	ecx, $10000000
242
	mcall	SF_DRAW_TEXT,<6,LINE_H*0+6>,,text+text.line_size*0,text.line_size	;InFile
243
	mcallb	SF_DRAW_TEXT,<6,LINE_H*1+6>,,text+text.line_size*1,esi	     ;OutFile
244
	mov	ecx, [sc.work_button_text]
245
	or	ecx, $10000000
246
	mcallb	SF_DRAW_TEXT,<0,LINE_H*2+6>,,text+text.line_size*2,esi	 ;Path
247
248
 
249
	sub	ebx,RIGHT_BTN_W-11
250
	shl	ebx,16
251
	add	ebx,LINE_H/2-6
252
	mov	ecx, [sc.work_button_text]
253
	or	ecx, $10000000
254
	mcallb	SF_DRAW_TEXT,ebx,ecx,s_compile,7
255
	add	ebx,LINE_H
256
	mcallb	SF_DRAW_TEXT,ebx,ecx,s_run
257
	add	ebx,LINE_H
258
	mcallb	SF_DRAW_TEXT,ebx,ecx,s_debug
259
260
 
261
	;mpack	ebx,MAGIC1+6,1+ 14/2-3+ 14*0
262
	;mov	esi,[PROCESS_INFO.client_box.width]
263
	;sub	esi,MAGIC1*2+6+3
264
	;mov	eax,esi
265
	;mov	cl,6
266
	;div	cl
267
	;cmp	al,MAX_PATH
268
	;jbe	@f
269
	;mov	al,MAX_PATH
270
;@@:
271
	movzx	esi,al
272
273
 
274
275
 
276
	sub	eax,[edit1.left]
277
	sub	eax,RIGHT_BTN_W+6
278
	mov	dword[edit1.width],eax
279
	mov	dword[edit2.width],eax
280
	mov	dword[edit3.width],eax
281
	invoke	edit_box_draw, edit1
282
	invoke	edit_box_draw, edit2
283
	invoke	edit_box_draw, edit3
284
	invoke	check_box_draw, ch1_dbg
285
	ret
286
;-------------------------------------------------
287
prepare_esp_and_redraw:
288
	mov	[processing_esp],esp
289
do_redraw:
290
	pusha
291
	mcall	SF_REDRAW,SSF_BEGIN_DRAW ; Start of draw
292
293
 
294
	mov	edx,[sc.work]
295
	or	edx,CW_CAPTION or CW_CLIENTRECTCOORDS or CW_SKINED;0x33000000
296
	mcall	SF_CREATE_WINDOW,<150,DEFAULT_WIN_W>,<150,DEFAULT_WIN_H>,edx,,title
297
	mcall	SF_THREAD_INFO,PROCESS_INFO,-1
298
299
 
300
	test	eax,100b
301
	jnz	.skip_draw_window
302
	call	draw_window
303
.skip_draw_window:
304
	mcall	SF_REDRAW,SSF_END_DRAW ; End of Draw
305
	popa
306
	ret
307
;---------------------------------------------------------------------
308
bottom_right dd ?
309
310
 
311
fun_opn_dlg:
312
	pushad
313
	mov	edx, open_dialog_name
314
	mov	edi, communication_area_default_path
315
	mov	esi, library_path
316
	call	@copy_path_wo_pdname
317
	mov	[OpenDialog_data.type], 0
318
319
 
320
	mov	edi, dword [edit3.text]
321
	mov	ecx, dword [edit3.max]
322
	cld
323
	repne	scasb
324
	cmp	byte[edi-2], '/'
325
	jne	@f
326
	mov	byte[edi-2], 0 ;if last symbol is slash cut it off
327
@@:
328
	invoke	OpenDialog_Start, OpenDialog_data
329
	cmp	[OpenDialog_data.status], 2
330
	je	@f
331
332
 
333
	mov	edi, dword [edit3.text]
334
	mov	ebx, edi ;copy text pointer
335
	mov	ecx, dword [edit3.max]
336
	cld
337
	repne	scasb
338
	cmp	byte[edi-2], '/'
339
	jne	.no_slash
340
341
 
342
.no_slash:
343
	mov	byte[edi-1], '/' ;add slash as last symbol
344
	mov	byte[edi], 0 ;cut off file name
345
	sub	edi, ebx ;edi = strlen(edit3.text)
346
	mov	[edit3.size], edi
347
	mov	[edit3.pos], edi
348
	invoke	edit_box_set_text, edit1, [OpenDialog_data.filename_area]
349
	invoke	edit_box_set_text, edit2, [OpenDialog_data.filename_area]
350
351
 
352
	xor	eax, eax
353
	cld
354
.cycle:
355
	lodsb
356
	test	eax, eax
357
	jnz	.cycle
358
359
 
360
	cmp	esi, [edit2.text]
361
	jle	.short_fn
362
363
 
364
	sub	dword [edit2.size], 4
365
	sub	dword [edit2.pos], 4
366
367
 
368
	invoke	edit_box_draw, edit1
369
	invoke	edit_box_draw, edit2
370
	invoke	edit_box_draw, edit3
371
@@:
372
	popad
373
	ret
374
;---------------------------------------------------------------------
375
draw_messages:
376
	mpack	ebx, 5,[PROCESS_INFO.client_box.width]
377
	sub	ebx, 9
378
	mpack	ecx, 0,[PROCESS_INFO.client_box.height]
379
	madd	ecx, LINE_H*4,-( LINE_H*4+5)
380
	mov	word[bottom_right+2], bx
381
	mov	word[bottom_right], cx
382
	msub	[bottom_right], 7,11
383
	add	[bottom_right], 7 shl 16 + 53
384
	mcall	SF_DRAW_RECT,,,0xFeFefe  ; clear work area
385
386
 
387
	push ecx
388
	mov cx,1
389
	mov edx,0xDADEDA
390
	mcall
391
392
 
393
	pop  ecx
394
	push ebx
395
	mov bx,1
396
	mcall
397
	pop  ebx
398
399
 
400
_sy = 2
401
_cx = 4
402
_sx = 6
403
	push	ebx ecx
404
	mpack	ebx, 4,5
405
	add	bx, [esp+_cx]
406
	mov	ecx, [esp+_sy-2]
407
	mov	cx, [esp+_sy]
408
	msub	ecx, 1,1
409
	mcall	SF_DRAW_LINE,,,[sc.work_graph]
410
	mov	si, [esp+_cy]
411
	add	cx, si
412
	shl	esi, 16
413
	add	ecx, esi
414
	madd	ecx, 1,1
415
	mcallb	SF_DRAW_LINE
416
	mpack	ebx, 4,4
417
	mov	esi, [esp+_sy-2]
418
	mov	si, cx
419
	mov	ecx, esi
420
	mcallb	SF_DRAW_LINE
421
	mov	si,[esp+_cx]
422
	add	bx,si
423
	shl	esi,16
424
	add	ebx,esi
425
	madd	ebx,1,1
426
	mcallb	SF_DRAW_LINE
427
	pop	ecx ebx
428
	ret
429
;---------------------------------------------------------------------
430
mov_param_str:
431
	cld
432
@@:
433
	lodsb
434
	cmp	al,','
435
	je	@f
436
	stosb
437
	test	al,al
438
	jnz	@b
439
@@:
440
	xor	al,al
441
	stosb
442
	ret
443
;---------------------------------------------------------------------
444
CUI_START:
445
	cmp	[_mode],NORMAL_MODE
446
	jne	@f
447
	call	draw_messages
448
	mov	[textxy],8 shl 16 + LINE_H*4+4
449
@@:
450
	mov	esi,_logo
451
	call	display_string
452
453
 
454
;   Fasm native code
455
;---------------------------------------------------------------------
456
	mov	[input_file],infile
457
	mov	[output_file],outfile
458
459
 
460
461
 
462
	mov	[start_time],eax
463
464
 
465
	call	parser
466
	call	assembler
467
	bt	dword[ch1_dbg.flags],1 ;cmp [bGenerateDebugInfo], 0
468
	jae	@f			  ;jz @f
469
	call	symbol_dump
470
@@:
471
	call	formatter
472
473
 
474
	movzx	eax,[current_pass]
475
	inc	eax
476
	call	display_number
477
	mov	esi,_passes_suffix
478
	call	display_string
479
	call	make_timestamp
480
	sub	eax,[start_time]
481
	xor	edx,edx
482
	mov	ebx,100
483
	div	ebx
484
	or	eax,eax
485
	jz	display_bytes_count
486
	xor	edx,edx
487
	mov	ebx,10
488
	div	ebx
489
	push	edx
490
	call	display_number
491
	mov	dl,'.'
492
	call	display_character
493
	pop	eax
494
	call	display_number
495
	mov	esi,_seconds_suffix
496
	call	display_string
497
display_bytes_count:
498
	mov	eax,[written_size]
499
	call	display_number
500
	mov	esi,_bytes_suffix
501
	call	display_string
502
	xor	al,al
503
504
 
505
	je	@f
506
	mov	edx,outfile
507
	call	make_fullpaths
508
	xor	ecx,ecx
509
510
 
511
	jne	run
512
	mcall	SF_FILE,file_io_debug
513
	jmp	@f
514
run:
515
	mcall	SF_FILE,file_io_start
516
@@:
517
	jmp	exit_program
518
519
 
520
include 'system.inc'
521
include 'core/version.inc'
522
include 'core/errors.inc'
523
include 'core/symbdump.inc'
524
include 'core/preproce.inc'
525
include 'core/parser.inc'
526
include 'core/exprpars.inc'
527
include 'core/assemble.inc'
528
include 'core/exprcalc.inc'
529
include 'core/formats.inc'
530
include 'core/x86_64.inc'
531
include 'core/avx.inc'
532
include 'core/tables.inc'
533
include 'core/messages.inc'
534
;---------------------------------------------------------------------
535
; IMPORT
536
;---------------------------------------------------------------------
537
  library box_lib,'box_lib.obj',\
538
	  proc_lib,'proc_lib.obj'
539
540
 
541
		 edit_box_key,'edit_box_key',\
542
		 edit_box_mouse,'edit_box_mouse',\
543
		 edit_box_set_text,'edit_box_set_text',\
544
		 version_ed,'version_ed',\
545
		 init_checkbox,'init_checkbox2',\
546
		 check_box_draw,'check_box_draw2',\
547
		 check_box_mouse,'check_box_mouse2',\
548
		 version_ch,'version_ch'
549
550
 
551
		  OpenDialog_Start,'OpenDialog_start'
552
;---------------------------------------------------------------------
553
; INITIALIZED DATA
554
;---------------------------------------------------------------------
555
;match =en,lang {include 'lang/en.inc'}
556
;match =ru,lang {include 'lang/ru.inc'}
557
558
 
559
560
 
561
edit2 EDIT_BOX 153, 72, LINE_H+3,   0xffffff, 0xA4C4E4, 0x80ff, 0, 0x10000000,(path-outfile-1), outfile, mouse_dd, 0, 7,7
562
edit3 EDIT_BOX 153, 72, LINE_H*2+3, 0xffffff, 0xA4C4E4, 0x80ff, 0, 0x10000000,(path_end-path-1), path, mouse_dd, 0, 6,6
563
editboxes_end:
564
ch1_dbg CHECK_BOX2 (5 shl 16)+15, ((LINE_H*3+3) shl 16)+15, 6, 0xffffff, 0x80ff, 0x10000000, s_dbgdescr,CB_FLAG_TOP
565
;---------------------------------------------------------------------
566
align 4
567
OpenDialog_data OPEN_DLG 0,PROCESS_INFO,communication_area_name,0,path,default_dir,library_path,do_redraw,0,path,filename_area,Filter,420,10,320,10
568
569
 
570
571
 
572
open_dialog_name	db 'opendial',0
573
communication_area_default_path db '/rd/1/File managers/',0
574
575
 
576
	dd Filter.end - Filter
577
      .1:
578
	db 'ASM',0
579
      .end:
580
	db 0
581
582
 
583
 
584
mouse_dd dd 0 ;needed for Shift in editbox
585
;---------------------------------------------------------------------
586
infile	path 'example.asm',0
587
outfile path 'example',0
588
path	path '/rd/1//',0
589
path_end:
590
crlf	db $D,$A,0
591
title	db appname,VERSION_STRING,0
592
593
 
594
595
 
596
_seconds_suffix db ' seconds, ',0
597
_bytes_suffix	db ' bytes.',$D,$A,0
598
599
 
600
601
 
602
603
 
604
_run_outfile	dd 0
605
606
 
607
608
 
609
610
 
611
dc	 db 0
612
filesize dd 0
613
614
 
615
 
616
error_suffix		db '.',0
617
line_data_start 	db ':'
618
line_number_start	db ' [',0
619
620
 
621
file_io_notify		FILEIO SSF_START_APP
622
file_io_notify.path	db 0
623
file_io_notify.lppath	dd notify_path
624
notify_path		db '/rd/1/@notify',0
625
626
 
627
file_io_start.path	path
628
629
 
630
file_io_debug.path	db '/SYS/DEVELOP/MTDBG',0
631
_ramdisk		db '/rd/1/'
632
filepos 		dd 0
633
634
 
635
times $41 db $00
636
times $1A db $20
637
times $25 db $00
638
times $10 db $20
639
times $30 db $00
640
times $10 db $50
641
times $04 db $00,$01
642
times $08 db $00
643
program_end:
644
;---------------------------------------------------------------------
645
; UNINITIALIZED DATA
646
;---------------------------------------------------------------------
647
params		rb $1000
648
cur_dir_path	rb $1000
649
library_path	rb $1000
650
filename_area	rb $100
651
652
 
653
654
 
655
656
 
657
658
 
659
buffer_address	dd ?
660
memory_setting	dd ?
661
start_time	dd ?
662
memblock	dd ?
663
664
 
665
666
 
667
668
 
669
fullpath_write	path
670
dbgfilename	rb MAX_PATH+4
671
672
 
673
sc_prev 	system_colors
674
max_handles = 8
675
fileinfos	rb (4+20+MAX_PATH)*max_handles
676
fileinfos_end:
677
PROCESS_INFO	process_information
678
679
 
680
displayed_count dd ?
681
last_displayed	rb 2
682
processing_esp dd ?
683
684
 
685
;---------------------------------------------------------------------
686
; STACK
687
;---------------------------------------------------------------------
688
		rb $1000
689
stacktop:
690