Subversion Repositories Kolibri OS

Rev

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