Subversion Repositories Kolibri OS

Rev

Rev 9439 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;******************************************************************************
2211 mario79 2
;   MAIN MENU
3
;******************************************************************************
2618 mario79 4
; last update:  17/04/2012
5
; changed by:   Marat Zakiyanov aka Mario79, aka Mario
6
; changes:      Support for boot parameters.
7
;------------------------------------------------------------------------------
2488 mario79 8
; last update:  22/03/2012
9
; changed by:   Marat Zakiyanov aka Mario79, aka Mario
10
; changes:      Global optimization! The program uses
11
;               only 32 KB of memory instead of 128 kb is now.
12
;------------------------------------------------------------------------------
2211 mario79 13
; last update:  19/09/2011
14
; changed by:   Marat Zakiyanov aka Mario79, aka Mario
15
; changes:      Checking for program exist to memory
16
;               Added processing of keys: left and right arrow
2488 mario79 17
;------------------------------------------------------------------------------
31 halyavin 18
;   MAIN MENU by lisovin@26.ru
19
;   Some parts of code rewritten by Ivan Poddubny 
20
;
8489 maxcodehac 21
;   Compile with FASM for Kolibri
31 halyavin 22
;******************************************************************************
8489 maxcodehac 23
  BTN_HEIGHT         = 26
9436 leency 24
  BTN_WIDTH          = 198 ; 178 for a small font
8762 leency 25
  TXT_Y              = (BTN_HEIGHT)/2-7
8489 maxcodehac 26
  FONT_TYPE          = 0x90000000
31 halyavin 27
 
8484 leency 28
  PANEL_HEIGHT       = 20
29
  MENU_BOTTON_X_POS  = 10
30
  MENU_BOTTON_X_SIZE = 50
2488 mario79 31
;------------------------------------------------------------------------------
2211 mario79 32
	use32
33
	org 0x0
2488 mario79 34
 
8484 leency 35
	db 'MENUET01'  ; 8 byte id
36
	dd 0x01        ; header version
37
	dd START       ; start of code
38
	dd IM_END      ; size of image
39
	dd mem_end     ; memory for app
40
	dd stack_area  ; esp
41
	dd bootparam   ; boot parameters
42
	dd 0x0         ; path
2488 mario79 43
;------------------------------------------------------------------------------
2618 mario79 44
include "..\..\..\macros.inc"
7786 leency 45
include "..\..\..\gui_patterns.inc"
9433 rgimad 46
; Formatted debug output:
47
include "..\..\..\debug-fdo.inc"
48
__DEBUG__       = 1             ; 0 - disable debug output / 1 - enable debug output
49
__DEBUG_LEVEL__ = DBG_ERR      ; set the debug level
50
DBG_ALL       = 0  ; all messages
51
DBG_INFO      = 1  ; info and errors
52
DBG_ERR       = 2  ; only errors
2488 mario79 53
;------------------------------------------------------------------------------
54
align 4
2618 mario79 55
conversion_ASCII_to_HEX:
56
	xor	ebx,ebx
57
	cld
58
	lodsd
59
	mov	ecx,4
60
;--------------------------------------
61
align 4
62
.loop:
63
	cmp	al,0x60	; check for ABCDEF
64
	ja	@f
65
	sub	al,0x30 ; 0-9
66
	jmp	.store
67
;--------------------------------------
68
align 4
69
@@:
70
	sub	al,0x57 ; A-F
71
;--------------------------------------
72
align 4
73
.store:
74
	and	al,0xf
75
	rol	ebx,4
76
	add	bl,al
77
	ror	eax,8
78
	dec	ecx
79
	jnz	.loop
80
 
81
	ret
82
;------------------------------------------------------------------------------
83
align 4
97 mario79 84
START:		       ; start of execution
2488 mario79 85
	mcall	68,11
8484 leency 86
 
87
	mcall 30, 1, default_dir
2618 mario79 88
 
9433 rgimad 89
	; DEBUGF DBG_INFO, "MENU START! sc.work = %x\n", [sc.work]
90
 
2618 mario79 91
	mov	esi,bootparam
92
	cmp	[esi],byte 0
93
	je	.no_boot_parameters
94
; boot params - hex
95
; db '9999'	; +0	Menu button X
96
; db '9999'	; +4	Menu button X size
97
; db '9999'	; +8	Menu button Y
98
; db '9999'	; +12	Menu button Y size
99
; db '9999'	; +16	Panel height
100
; db '1000'	; +20	Panel attachment
101
 
102
;	mov	edx,bootparam
103
;	call	debug_outstr
104
;	newline
105
 
106
	call	conversion_ASCII_to_HEX
107
	mov	[menu_button_x.start],ebx
108
 
109
;	dps	"menu_button_x.start: "
110
;	dpd	ebx
111
;	newline
112
 
113
	call	conversion_ASCII_to_HEX
114
	mov	[menu_button_x.size],ebx
115
 
116
;	dps	"menu_button_x.size: "
117
;	dpd	ebx
118
;	newline
119
 
120
	call	conversion_ASCII_to_HEX
121
	mov	[menu_button_y.start],ebx
122
 
123
;	dps	"menu_button_y.start: "
124
;	dpd	ebx
125
;	newline
126
 
127
	call	conversion_ASCII_to_HEX
128
	mov	[menu_button_y.size],ebx
129
 
130
;	dps	"menu_button_y.size: "
131
;	dpd	ebx
132
;	newline
133
 
134
	call	conversion_ASCII_to_HEX
135
	mov	[panel_height],ebx
136
 
137
;	dps	"panel_height: "
138
;	dpd	ebx
139
;	newline
140
 
141
	call	conversion_ASCII_to_HEX
142
	mov	[panel_attachment],ebx
143
 
144
;	dps	"panel_attachment: "
145
;	dpd	ebx
146
;	newline
147
;--------------------------------------
148
align 4
149
.no_boot_parameters:
2211 mario79 150
	call	program_exist
151
	mcall	14
152
	mov	[screen_size],eax
153
 
154
	mcall	48,3,sc,sizeof.system_colors	; load system colors
9433 rgimad 155
 
156
	; DEBUGF  DBG_INFO, "sc.work = %x\n", [sc.work]
157
 
9527 rgimad 158
	mov esi, [sc.work]
159
	add esi, 0x1a1a1a
160
	mov ebx, esi
161
	and ebx, 0xFF000000
162
	test ebx, ebx
163
	jz @f
164
	mov esi, 0x00FFFFFF
165
@@:
166
	mov [active_color], esi
167
 
168
	mov  esi, [sc.work]
169
	cmp  esi, 0xdfdfdf
170
	jb   @f
171
	sub  esi, 0x1b1b1b
172
@@:
173
	mov [work_color], esi
174
 
9433 rgimad 175
	mov eax, 68
176
	mov ebx, 22
177
	mov ecx, icons_resname
178
	mov esi, 0 ; SHM_READ
179
	mcall
180
	test eax, eax
181
	jnz @f
182
	mov [no_shared_resources], 1
183
	DEBUGF DBG_ERR, "Failed to get ICONS18W from @RESHARE.\nTry rerun @RESHARE.\n"
184
	jmp .no_res
185
@@:
186
	mov [shared_icons_size], edx
9527 rgimad 187
	; copy shared icons
9433 rgimad 188
	mov esi, eax
189
	mov ecx, edx
190
	mcall 68, 12, edx
191
	mov edi, eax
9527 rgimad 192
	mov [shared_icons_ptr], eax
193
	shr ecx, 2 ; /= 4; ecx = how many dwords in shared icons
194
	cld
195
	rep movsd
196
 
197
	; copy shared icons to active icons
198
	mov esi, [shared_icons_ptr]
199
	mov ecx, edx
200
	mcall 68, 12, edx
201
	mov edi, eax
9433 rgimad 202
	mov [shared_icons_active_ptr], eax
203
	shr ecx, 2 ; /= 4; ecx = how many dwords in shared icons
204
	cld
205
	rep movsd
9527 rgimad 206
 
207
	; fix colors:
9433 rgimad 208
	mov esi, [shared_icons_active_ptr]
9527 rgimad 209
	mov edi, [shared_icons_ptr]
9433 rgimad 210
	xor ecx, ecx
211
.for1:
212
	cmp ecx, [shared_icons_size]
213
	jae .end_for1
214
 
215
	mov eax, esi
216
	add eax, ecx
217
	mov edx, [eax]
218
	cmp edx, [sc.work]
219
	; DEBUGF DBG_INFO, "eax = %x, sc.work = %x\n", eax, [sc.work]
220
	jne @f
9527 rgimad 221
	mov ebx, [active_color]
9433 rgimad 222
	mov [eax], ebx
223
@@:
9527 rgimad 224
 
225
	mov eax, edi
226
	add eax, ecx
227
	mov edx, [eax]
228
	cmp edx, [sc.work]
229
	jne @f
230
	mov ebx, [work_color]
231
	mov [eax], ebx
232
@@:
233
 
9433 rgimad 234
	add ecx, 4
235
	jmp .for1
236
.end_for1:
237
.no_res:
2488 mario79 238
 
239
; get size of file MENU.DAT
240
	mcall	70,fileinfo
241
	test	eax,eax
2211 mario79 242
	jnz	close
2488 mario79 243
; get memory for MENU.DAT
244
	mov	ecx,[procinfo+32]
245
	mov	[fileinfo.size],ecx
246
	mcall	68,12
247
	mov	[fileinfo.return],eax
248
	mcall	68
249
	mov	[menu_data],eax
250
; load MENU.DAT
251
	mov	[fileinfo],dword 0
252
	mcall	70,fileinfo
253
	test	eax,eax
254
	jnz	close
255
 
2211 mario79 256
	test	ebx,ebx	   ; length = 0 ?
257
	jz	close
258
	mov	ecx,ebx
2488 mario79 259
	mov	edi,[fileinfo.return]	;mem_end
260
;--------------------------------------
261
align 4
9433 rgimad 262
newsearch: ; search for next submenu in MENU.DAT
2211 mario79 263
	mov	al,'#'
264
	cld
265
	repne	scasb
266
	test	ecx,ecx	   ; if not found
267
	jz	close
9433 rgimad 268
	call	get_number ; get submenu number from char at edi position to ebx
2211 mario79 269
	test	ebx,ebx
270
	jnz	.number
271
	cmp	al,'#'
272
	je	search_end
2488 mario79 273
;--------------------------------------
274
align 4
2211 mario79 275
.number:
9433 rgimad 276
	shl	ebx,4 ; *= 16 . 16 is size of process table (see virtual at 0 ... stuff in the end of file)
2488 mario79 277
	add	ebx,[menu_data]     ; pointer to process table
9433 rgimad 278
	mov	[ebx],edi ; process_table->pointer = edi
2211 mario79 279
	inc	[processes]
280
	jmp	newsearch
2488 mario79 281
;--------------------------------------
282
align 4
2211 mario79 283
search_end:
284
	mov	[end_pointer],edi
285
	mov	ebx,[processes]
286
	dec	ebx
287
	shl	ebx,4
2488 mario79 288
	add	ebx,[menu_data]
289
;--------------------------------------
290
align 4
2211 mario79 291
newprocess:
292
	xor	edx,edx
293
	mov	ecx,edi
294
	sub	ecx,[ebx]
295
	mov	al,10
2488 mario79 296
;--------------------------------------
297
align 4
2211 mario79 298
newsearch1:
299
	std
300
	repne	scasb
301
	test	ecx,ecx
302
	je	endprocess
303
	cmp	[edi],byte 13
304
	jne	newsearch1
305
	inc	edx
306
	jmp	newsearch1
2488 mario79 307
;--------------------------------------
308
align 4
2211 mario79 309
endprocess:
310
	mov	esi,ebx
311
	add	esi,4
312
	dec	edx
313
	mov	[esi],dl
2488 mario79 314
	cmp	ebx,[menu_data]
2211 mario79 315
	jbe	search_end1
316
	sub	ebx,16
317
	jmp	newprocess
2488 mario79 318
;--------------------------------------
319
align 4
2211 mario79 320
search_end1:
321
	mcall	14
2618 mario79 322
	cmp	[panel_attachment],byte 1
323
	je	@f
324
	xor	ax,ax
325
	jmp	.store
326
;--------------------------------------
327
align 4
328
@@:
329
	sub	ax,[panel_height]	;20
330
.store:
2488 mario79 331
	mov	ebx,[menu_data]
332
	mov	[ebx + y_end],ax
333
	mov	[ebx + x_start],5
334
	mov	al,[ebx + rows]
335
	mov	[ebx + cur_sel],al	 ; clear selection
336
	mov	[ebx + prev_sel],al
2211 mario79 337
	mov	[buffer],0
2488 mario79 338
;------------------------------------------------------------------------------
339
align 4
9433 rgimad 340
thread: ; starts new thread. called when opening each menu
341
	DEBUGF DBG_INFO, "start new THREAD\n"
2488 mario79 342
	mov	ebp,esp
343
	sub	ebp,0x1000
344
	cmp	ebp,0x2000 ; if this is first started thread
345
	ja	@f
346
	xor	ebp,ebp ; not free area
347
;--------------------------------------
348
align 4
349
@@:
2211 mario79 350
	mov	eax,[buffer]      ; identifier
351
	shl	eax,4
2488 mario79 352
	add	eax,[menu_data]
2211 mario79 353
	mov	edi,eax
354
	mcall	40,100111b	; mouse + button + key + redraw
2488 mario79 355
;------------------------------------------------------------------------------
356
align 4
2211 mario79 357
red:
358
	call	draw_window	; redraw
2488 mario79 359
;------------------------------------------------------------------------------
360
align 4
9433 rgimad 361
still: ; event loop
2488 mario79 362
	call	free_area_if_set_mutex
363
 
2211 mario79 364
	mcall	23,5	; wait here for event
365
	test	[close_now],1      ; is close flag set?
366
	jnz	close
367
 
368
	cmp	eax,1	; redraw request ?
369
	je	red
370
	cmp	eax,2	; key pressed ?
371
	je	key
372
	cmp	eax,3	; button in buffer ?
373
	je	button
374
	cmp	eax,6	; mouse event ?
375
	je	mouse
2488 mario79 376
	cmp	edi,[menu_data]
2211 mario79 377
	je	still	     ; if main process-ignored
378
 
379
	movzx	ebx,[edi + parent]	 ; parent id
380
	shl	ebx,4
2488 mario79 381
	add	ebx,[menu_data]      ; ebx = base of parent info
2211 mario79 382
	call	backconvert	     ; get my id in al
383
	cmp	al,[ebx + child]    ; if I'm not child of my parent, I shall die :)
384
	jne	close
385
 
386
	jmp	still
2488 mario79 387
;------------------------------------------------------------------------------
388
align 4
2211 mario79 389
key:
2488 mario79 390
	mcall	2
2211 mario79 391
	mov	[last_key],ah
392
	mov	al,[edi + rows]     ; number of buttons
393
	cmp	ah,178	  ; KEY_UP
394
	jne	.noup
395
 
396
	mov	ah,[edi+cur_sel]
397
	mov	[edi+prev_sel],ah
398
	dec	byte [edi+cur_sel]
399
	jnz	redrawbut
400
	mov	[edi+cur_sel],al
401
	jmp	redrawbut
2488 mario79 402
;--------------------------------------
403
align 4
2211 mario79 404
.noup:
405
	cmp	ah,177	 ; KEY_DOWN
406
	jne	.nodn
407
 
408
	mov	ah,[edi + cur_sel]
409
	mov	[edi + prev_sel],ah
410
	inc	[edi + cur_sel]
411
	cmp	[edi + cur_sel],al
412
	jna	redrawbut
413
	mov	[edi + cur_sel],1
414
	jmp	redrawbut
2488 mario79 415
;--------------------------------------
416
align 4
2211 mario79 417
.nodn:
418
	cmp	ah,179 	 ; KEY_LEFT
419
	je	@f
420
	cmp	ah,13 	 ; ENTER
421
	jne	.noenter
422
@@:
423
	mov	ah,[edi + cur_sel]
424
	jmp	button1
2488 mario79 425
;--------------------------------------
426
align 4
2211 mario79 427
.noenter:
428
	cmp	ah,176 	 ; KEY_RIGHT
429
	je	@f
430
	cmp	ah,27 	 ; ESC
431
	jne	still
432
	jmp	close
2488 mario79 433
;--------------------------------------
434
align 4
2211 mario79 435
@@:
436
	call	get_process_ID
437
	cmp	[main_process_ID],ecx
438
	jne	close
439
	jmp	still
2488 mario79 440
;------------------------------------------------------------------------------
441
align 4
2211 mario79 442
button:	; BUTTON HANDLER
443
	mcall	17	; get id
444
				; dunkaist[
5452 leency 445
	test	eax,0xfffffe00	; is it system close button? (close signal from @taskbar)
2211 mario79 446
	setz	byte[close_now]	; set (or not set) close_recursive flag
447
	jz	close		; if so,close all menus
448
				; dunkaist]
2488 mario79 449
;--------------------------------------
450
align 4
2211 mario79 451
button1:
452
	mov	esi,edi
453
	push	edi
454
	mov	edi,[edi + pointer]
31 halyavin 455
; print "hello"
2211 mario79 456
	mov	al,[esi + cur_sel]
457
	mov	[esi + prev_sel],al
458
	mov	[esi + cur_sel],ah
459
 
460
	pushad
461
	mov	edi,esi
462
; dph eax
463
	call	draw_only_needed_buttons
464
	popad
9433 rgimad 465
; look (.next_string) for the next line in MENU.DAT  times;  = button_id
2211 mario79 466
	push	eax
2488 mario79 467
;--------------------------------------
468
align 4
2211 mario79 469
.next_string:
9433 rgimad 470
	; DEBUGF DBG_INFO, ".next_string called\n"
2211 mario79 471
	call	searchstartstring
472
	dec	ah
473
	jnz	.next_string
474
	pop	eax
475
 
476
	mov	ecx,40
8484 leency 477
	mov	al,'|'
2211 mario79 478
	cld
479
	repne	scasb
8484 leency 480
	test	ecx,ecx	  ; if '|' not found
2211 mario79 481
	je	searchexit
482
 
483
	cmp	[edi],byte '@'     ; check for submenu
484
	je	runthread
485
 
486
	cmp	[last_key],179
487
	je	searchexit
488
 
8484 leency 489
	;dec	edi
2211 mario79 490
	push	edi			; pointer to start of filename
491
	call	searchstartstring	; search for next string
492
	sub	edi,2		; to last byte of string
493
 
494
	mov	ecx,edi
495
	pop	esi
496
	sub	ecx,esi
497
	inc	ecx		 ; length of filename
498
	mov	edi, fileinfo_start.name
499
	rep	movsb		   ; copy string
500
	mov	[edi],byte 0	       ; store terminator
501
	mcall	70,fileinfo_start	; start program
9439 leency 502
	pop	edi
2211 mario79 503
	or	[close_now],1      ; set close flag
504
	mov	[mousemask],0
9439 leency 505
	; if program run failed then start /sys/@open with param
506
	test	eax,eax
507
	jns	close
508
	mov	eax, fileinfo_start.name
509
	mov [file_open.params], eax
510
	mcall	70,file_open
2211 mario79 511
	jmp	close
2488 mario79 512
;--------------------------------------
513
align 4
2211 mario79 514
searchexit:
515
	pop	edi
516
	jmp	still
2488 mario79 517
;------------------------------------------------------------------------------
518
align 4
2211 mario79 519
runthread:
520
	inc	edi
521
 
522
	push	eax
523
	call	get_number	     ; get number of this process
524
	pop	eax
525
 
526
	test	ebx,ebx	   ; returned zero - main menu or not number
527
	jz	searchexit
528
 
529
	mov	al,bl
530
 
531
	mov	ebx,[processes]
532
	dec	bl
533
	cmp	al,bl
534
	ja	searchexit	       ; such process doesnt exist
535
	cmp	al,[esi + child]
536
	je	searchexit	       ; such process already exists
537
 
538
	mov	[esi + child],al    ; this is my child
539
	mov	cx,[esi + x_start]
8484 leency 540
	add	cx,BTN_WIDTH+1	  ; new x_start in cx
2211 mario79 541
	movzx	edx,al
542
	shl	edx,4
2488 mario79 543
	add	edx,[menu_data]       ; edx points to child's base address
2211 mario79 544
	mov	[edx + x_start],cx  ; xstart for new thread
545
	mov	cx,[esi + y_end]   ; y_end in cx
546
	mov	bl,[esi + rows]    ; number of buttons in bl
547
	sub	bl,ah	  ; number of btn from bottom
7848 leency 548
 
549
	; Leency: store vars for case when attachement=top
550
	pusha
551
	mov [prior_thread_selected_y_end], bl
552
	mcall	9,procinfo,-1
553
	m2m     [prior_thread_y], dword[procinfo+38]
554
	m2m     [prior_thread_h], dword[procinfo+46]
555
	popa
556
 
2211 mario79 557
	movzx	eax,al
558
	mov	[buffer],eax		; thread id in buffer
559
	movzx	ebx,bl
560
	push	edx
561
	mov	eax,BTN_HEIGHT
562
	mul	ebx
563
	sub	cx,ax	  ; new y_end for new thread
564
	pop	edx
565
	mov	[edx + y_end],cx    ; store y_end
566
	mov	edi,esi
567
	call	backconvert	      ; get number of this process (al)
568
	mov	[edx + parent],al   ; store number of parent process
7848 leency 569
 
2211 mario79 570
	mov	al,[edx + rows]
571
	mov	[edx + cur_sel],al  ; clear current selected element
572
	mov	[edx + prev_sel],al ; clear previous selected element
573
	mov	[edx + child],0
574
 
2488 mario79 575
	mcall	68,12,0x1000	; stack of each thread is allocated 4 KB
576
	add	eax,0x1000	; set the stack pointer to the desired position
577
	mov	edx,eax
578
	mcall	51,1,thread	; Go ahead!
2211 mario79 579
	jmp	searchexit
2488 mario79 580
;------------------------------------------------------------------------------
581
align 4
2211 mario79 582
mouse: 	      ; MOUSE EVENT HANDLER
583
	mcall	37,0
584
	mov	[screen_mouse_position],eax ; eax = [ Y | X ] relative to screen
31 halyavin 585
 
2211 mario79 586
	mcall	37,2
587
	test	eax,eax	   ; check buttons state
588
	jnz	click
589
	mcall	37,1
590
	ror	eax,16	  ; eax = [ Y | X ] relative to window
7786 leency 591
	cmp	ax,BTN_WIDTH	   ; pointer in window?
2211 mario79 592
	ja	noinwindow
593
; *** in window ***
594
	shr	eax,16	  ; eax = [ 0 | Y ]
595
	xor	edx,edx
596
	mov	ebx,BTN_HEIGHT
597
	div	ebx
598
	inc	eax		  ; number of "button" in eax
599
	movzx	ebx,[edi + rows]    ; total strings in ebx
600
	cmp	eax,ebx
601
	ja	noinwindow
602
	cmp	[edi + cur_sel],al
603
	je	noredrawbut
604
	mov	bl,[edi + cur_sel]
605
;;;;;;
606
	cmp	[edi + child],0
607
	jne	noredrawbut
608
;;;;;;
609
	mov	[edi + cur_sel],al
610
	mov	[edi + prev_sel],bl
2488 mario79 611
;--------------------------------------
612
align 4
2211 mario79 613
redrawbut:
614
	call	draw_only_needed_buttons
2488 mario79 615
;--------------------------------------
616
align 4
2211 mario79 617
noredrawbut:
618
	call	backconvert
619
	bts	[mousemask],eax
620
	jmp	still
2488 mario79 621
;--------------------------------------
622
align 4
2211 mario79 623
noinwindow:
624
	call	backconvert
625
	btr	[mousemask],eax
626
	jmp	still
2488 mario79 627
;------------------------------------------------------------------------------
628
align 4
2211 mario79 629
click:
630
	cmp	[mousemask],0  ; not in a window (i.e. menu)
631
	jne	still
632
; checking for pressing 'MENU' on the taskbar
633
	mov	eax,[screen_mouse_position]
2618 mario79 634
 
635
	cmp	[panel_attachment],byte 1
636
	je	@f
637
 
638
	xor	ebx,ebx
639
	jmp	.check_y
640
;--------------------------------------
641
align 4
642
@@:
2211 mario79 643
	mov	ebx,[screen_size]
2618 mario79 644
	sub	bx,word [panel_height]	;PANEL_HEIGHT
645
;--------------------------------------
646
align 4
647
.check_y:
648
	add	bx,word [menu_button_y.start]
2211 mario79 649
	cmp	bx,ax
650
	ja	close
2618 mario79 651
 
652
	add	bx,word [menu_button_y.size]
653
	cmp	bx,ax
654
	jb	close
655
 
2211 mario79 656
	shr	eax,16
2618 mario79 657
 
658
	mov	ebx,[menu_button_x.start]
659
	cmp	bx,ax	; MENU_BOTTON_X_SIZE
2211 mario79 660
	ja	close
2618 mario79 661
 
662
	add	bx,[menu_button_x.size]
663
	cmp	bx,ax	; MENU_BOTTON_X_POS
2211 mario79 664
	ja	still
2488 mario79 665
;------------------------------------------------------------------------------
666
align 4
2211 mario79 667
close:
668
 
669
	movzx	ebx,[edi+parent]       ; parent id
670
	shl	ebx,4
2488 mario79 671
	add	ebx,[menu_data]          ; ebx = base of parent info
2211 mario79 672
	call	backconvert
673
	cmp	[ebx + child],al       ; if i am the child of my parent...
674
	jnz	@f
675
	mov	[ebx + child],-1       ; ...my parent now has no children
2488 mario79 676
;--------------------------------------
677
align 4
728 diamond 678
@@:
2211 mario79 679
	or	eax,-1                 ; close this thread
680
	mov	[edi + child],al       ; my child is not mine
2488 mario79 681
 
682
	call	free_area_if_set_mutex
683
	call	set_mutex_for_free_area
684
 
2211 mario79 685
	mcall
2488 mario79 686
;--------------------------------------
687
align 4
2211 mario79 688
backconvert:		  ; convert from pointer to process id
689
	mov	eax,edi
2488 mario79 690
	sub	eax,[menu_data]
2211 mario79 691
	shr	eax,4
692
	ret
2488 mario79 693
;------------------------------------------------------------------------------
694
align 4
695
set_mutex_for_free_area:
696
; set mutex for free thread stack area
697
	push	eax ebx
698
;--------------------------------------
699
align 4
700
.wait_lock:
701
        cmp     [free_my_area_lock], 0
702
        je      .get_lock
703
	mcall	68,1
704
        jmp     .wait_lock
705
;--------------------------------------
706
align 4
707
.get_lock:
708
        mov     eax, 1
709
        xchg    eax, [free_my_area_lock]
710
        test    eax, eax
711
        jnz     .wait_lock
712
	mov	[free_my_area],ebp
713
	pop	ebx eax
714
	ret
715
;------------------------------------------------------------------------------
716
align 4
717
free_area_if_set_mutex:
718
	cmp	[free_my_area_lock],0
719
	je	.end
720
 
721
	push	eax ebx ecx
722
	mov	ecx,[free_my_area]
723
 
724
	test	ecx,ecx
725
	jz	@f
726
	mcall	68,13
727
;--------------------------------------
728
align 4
729
@@:
730
	xor	eax,eax
731
	mov	[free_my_area_lock],eax
732
	pop	ecx ebx eax
733
;--------------------------------------
734
align 4
735
.end:
736
	ret
737
;------------------------------------------------------------------------------
31 halyavin 738
;==================================
739
; get_number
740
;    load number from [edi] to ebx
741
;==================================
2488 mario79 742
align 4
2211 mario79 743
get_number:
744
	push	edi
745
	xor	eax,eax
746
	xor	ebx,ebx
2488 mario79 747
;--------------------------------------
748
align 4
2211 mario79 749
.get_next_char:
750
	mov	al,[edi]
751
	inc	edi
752
	cmp	al, '0'
753
	jb	.finish
754
	cmp	al, '9'
755
	ja	.finish
756
	sub	al, '0'
757
	imul	ebx,10
758
	add	ebx,eax
759
	jmp	.get_next_char
760
;-------------------------------------
2488 mario79 761
align 4
2211 mario79 762
.finish:
763
	pop	edi
764
	ret
2488 mario79 765
;------------------------------------------------------------------------------
766
align 4
2211 mario79 767
get_process_ID:
768
	mcall	9,procinfo,-1
769
	mov	edx,eax
770
	mov	ecx,[ebx+30]	; PID
771
	ret
2488 mario79 772
;------------------------------------------------------------------------------
773
align 4
2211 mario79 774
program_exist:
775
	call	get_process_ID
776
	mov	[main_process_ID],ecx
777
	mcall	18,21
778
	mov	[active_process],eax	; WINDOW SLOT
779
	mov	ecx,edx
780
	xor	edx,edx
781
;-----------------------------------------
2488 mario79 782
align 4
2211 mario79 783
.loop:
784
	push	ecx
785
	mcall	9,procinfo
786
	mov	eax,[menu_mame]
787
	cmp	[ebx+10],eax
788
	jne	@f
8484 leency 789
	; temporary to fit into 3 IMG sectors
790
	;mov	ax,[menu_mame+4]
791
	;cmp	[ebx+14],ax
792
	;jne	@f
2211 mario79 793
	cmp	ecx,[active_process]
794
	je	@f
795
; dph ecx
796
	mcall	18,2
797
	mov	edx,1
2488 mario79 798
;--------------------------------------
799
align 4
2211 mario79 800
@@:
801
	pop	ecx
802
	loop	.loop
2488 mario79 803
 
2211 mario79 804
	test	edx,edx
805
	jz	@f
806
	mcall	-1
2488 mario79 807
;--------------------------------------
808
align 4
2211 mario79 809
@@:
810
	ret
2488 mario79 811
;------------------------------------------------------------------------------
31 halyavin 812
;   *********************************************
813
;   *******  WINDOW DEFINITIONS AND DRAW ********
814
;   *********************************************
2488 mario79 815
align 4
31 halyavin 816
draw_window:
9433 rgimad 817
	mcall	48,5 ; get working area
2618 mario79 818
	mov	[x_working_area],eax
819
	mov	[y_working_area],ebx
820
 
2211 mario79 821
	mcall	12,1	; 1,start of draw
822
	movzx	ebx,[edi + rows]
823
	imul	eax,ebx,BTN_HEIGHT	    ; eax = height of window
824
	movzx	ecx,[edi + y_end]
2618 mario79 825
	cmp	[panel_attachment],byte 1
826
	je	@f
7848 leency 827
 
828
 
829
	;cmp	ebp,0x000 ; if this is first started thread
830
	;je .1            ; then show it at the very top
831
 
832
	push  ebx eax
833
	; if attachement=top
834
	; then NEW_WIN_Y = PRIOR_WIN_Y + PRIOR_WIN_H - ITEM_H + 1 - SEL_ITEM_Y
835
 
836
	mov ecx, [prior_thread_y]
837
	add ecx, [prior_thread_h]
838
	sub ecx, BTN_HEIGHT
839
	inc ecx
840
 
841
	xor eax, eax
842
	mov al, [prior_thread_selected_y_end]
843
	mov ebx, BTN_HEIGHT
844
	mul ebx
845
 
846
	sub ecx, eax
847
 
848
	mov	[edi + cur_sel],1 ;if attachement=top then set item=1 selected
849
 
850
	pop eax ebx
851
 
2618 mario79 852
	jmp	.1
853
;--------------------------------------
854
align 4
855
@@:
2211 mario79 856
	sub	ecx,eax	    ; ecx = Y_START
2618 mario79 857
;--------------------------------------
858
align 4
859
.1:
2211 mario79 860
	shl	ecx,16
861
	add	ecx,eax	    ; ecx = [ Y_START | Y_SIZE ]
7786 leency 862
	dec ecx
7548 leency 863
 
2211 mario79 864
	movzx	ebx,[edi + x_start]
865
	shl	ebx,16
7786 leency 866
	mov	bx,BTN_WIDTH	    ; ebx = [ X_START | X_SIZE ]
2211 mario79 867
	mov	edx,0x01000000       ; color of work area RRGGBB,8->color gl
868
	mov	esi,edx	    ; unmovable window
2618 mario79 869
 
870
	mov	eax,[y_working_area]
871
	shr	eax,16
872
	ror	ecx,16
873
	test	cx,0x8000
874
	jz	@f
875
	mov	cx,ax
876
;--------------------------------------
877
align 4
878
@@:
879
	cmp	cx,ax
880
	ja	@f
881
	mov	cx,ax
882
;--------------------------------------
883
align 4
884
@@:
885
	rol	ecx,16
2211 mario79 886
	xor	eax,eax	    ; function 0 : define and draw window
887
	mcall
888
 
2618 mario79 889
;	dps	"[ Y_START | Y_SIZE ] : "
890
;	dph	ecx
891
;	newline
892
 
893
;	dps	"[ X_START | X_SIZE ] : "
894
;	dph	ebx
895
;	newline
896
 
2211 mario79 897
	call	draw_all_buttons
898
	mcall	12,2
899
	ret
2488 mario79 900
;------------------------------------------------------------------------------
901
align 4
2211 mario79 902
draw_all_buttons:
903
	xor	edx,edx
2488 mario79 904
;--------------------------------------
905
align 4
2211 mario79 906
.new_button:
907
	call	draw_one_button
908
	inc	edx
909
	cmp	dl,[edi + rows]
910
	jb	.new_button
911
	ret
2488 mario79 912
;------------------------------------------------------------------------------
913
align 4
2211 mario79 914
draw_only_needed_buttons:
915
	xor	edx,edx
916
	mov	dl,[edi + cur_sel]
917
	dec	dl
918
	call	draw_one_button
919
	mov	dl,[edi + prev_sel]
920
	dec	dl
921
	call	draw_one_button
922
	ret
2488 mario79 923
;------------------------------------------------------------------------------
924
align 4
2211 mario79 925
draw_one_button:
926
; receives number of button in dl
927
	push	edx
928
	mov	eax,8
7786 leency 929
	mov	ebx,BTN_WIDTH
2211 mario79 930
	movzx	ecx,dl
931
	imul	ecx,BTN_HEIGHT
7786 leency 932
	mov [draw_y], ecx
2211 mario79 933
	shl	ecx,16
6258 leency 934
	add	ecx,BTN_HEIGHT
2211 mario79 935
; edx = button identifier
9527 rgimad 936
	mov	esi, [work_color]
937
 
9433 rgimad 938
	mov [is_icon_active], 0
2211 mario79 939
	inc	dl
940
	cmp	[edi + cur_sel],dl
941
	jne	.nohighlight
9433 rgimad 942
	mov [is_icon_active], 1
9527 rgimad 943
 
944
	mov	esi, [active_color]
2488 mario79 945
;--------------------------------------
946
align 4
2211 mario79 947
.nohighlight:
7786 leency 948
	or	edx,BT_NOFRAME + BT_HIDE
2211 mario79 949
				; dunkaist[
950
	add	edx,0xd1ff00	; This makes first menu buttons differ
951
				; from system close button with 0x000001 id
952
				; dunkaist]
953
	mcall
8484 leency 954
	push edx
7786 leency 955
 
956
	mov edx, esi
9433 rgimad 957
	mcall 13 ; draw rect
7786 leency 958
 
8484 leency 959
	mcall , BTN_WIDTH,<[draw_y],1>,[sc.work_light]
960
	add     ecx, BTN_HEIGHT-1
961
	mcall , 1
962
	inc     ecx
963
	mcall , , , [sc.work_dark]
964
	add     [draw_y], BTN_HEIGHT-1
965
	mcall , BTN_WIDTH,<[draw_y],1>
7786 leency 966
 
8484 leency 967
	pop edx
2211 mario79 968
	movzx	edx,dl
969
	dec	dl
970
	imul	ebx,edx,BTN_HEIGHT
9433 rgimad 971
	add	ebx,((4 + 18) shl 16) + TXT_Y ; added + 18 (icon size)
2211 mario79 972
	movzx	ecx,dl
973
	inc	ecx
974
	mov	edx,[edi + pointer]
2488 mario79 975
;--------------------------------------
976
align 4
2211 mario79 977
.findline:
9433 rgimad 978
	cmp	byte [edx],13 ; if \r encountered => line found
2211 mario79 979
	je	.linefound
9433 rgimad 980
	inc	edx ; go to next char
2211 mario79 981
	jmp	.findline
2488 mario79 982
;------------------------------------------------------------------------------
983
align 4
2211 mario79 984
.linefound:
9433 rgimad 985
	inc	edx ; go to next char after \r
986
	cmp	byte [edx],10 ; if it is not \n then again findline
2211 mario79 987
	jne	.findline
9433 rgimad 988
	dec	ecx ; TODO what in ecx? button number?
2211 mario79 989
	jnz	.findline
990
 
8489 maxcodehac 991
	mov ecx, [sc.work_text]
992
	add ecx, FONT_TYPE
9433 rgimad 993
 
994
	push ecx esi edi ebp
995
	push ebx ; preserve ebx, it stores coordinates
996
	mov [tmp], edx
997
	mov [has_icon], 1
998
	xor ebx, ebx
999
@@: ; parse icon number
1000
	inc	edx
1001
	mov	al,[edx]
1002
	; DEBUGF DBG_INFO, "(%u)\n", al
1003
	cmp	al, '0'
1004
	jb	@f
1005
	cmp	al, '9'
1006
	ja	@f
1007
	sub	al, '0'
1008
	imul	ebx,10
1009
	add	ebx,eax
1010
	jmp @b
1011
@@:
1012
	; DEBUGF DBG_INFO, "icon_number = %x al = %u\n", ebx, al
1013
	mov [icon_number], ebx
1014
	cmp al, ' '
1015
	je @f
1016
	; if no space after number then consider that number is a part of caption
1017
	mov edx, [tmp] ; restore edx
1018
	mov [has_icon], 0 ; no icon
1019
@@:
1020
	pop ebx
1021
 
1022
	mcall	4,,,,21 ; draw menu element caption
1023
 
1024
	cmp [no_shared_resources], 1
1025
	je @f
1026
	cmp [has_icon], 1
1027
	jne @f
1028
	; draw icon:
1029
	mov eax, ebx
1030
	shr eax, 16
1031
	sub eax, 18 ; 18 - icon width
1032
	movzx ebx, bx
1033
 
1034
	sub ebx, 2
1035
	shl eax, 16
1036
	add eax, ebx
9436 leency 1037
	add eax, 1 shl 16
9433 rgimad 1038
	mov [tmp], eax
1039
	mov ebx, [icon_number]
1040
	imul ebx, 18*18*4
1041
 
1042
	mov ecx, [shared_icons_ptr]
1043
	; DEBUGF DBG_INFO, "is_icon_active = %x\n", [is_icon_active]
1044
 	cmp [is_icon_active], 1
1045
 	jne .not_active_icon
1046
 	mov ecx, [shared_icons_active_ptr]
1047
.not_active_icon:
1048
	add ebx, ecx
9436 leency 1049
	mcall 65, ebx, <18,18>, [tmp], 32, 0, 0
9433 rgimad 1050
 
9435 rgimad 1051
@@:
9433 rgimad 1052
	pop ebp edi esi ecx
9435 rgimad 1053
 
2211 mario79 1054
	pop	edx
1055
	ret
2488 mario79 1056
;------------------------------------------------------------------------------
1057
align 4
2211 mario79 1058
searchstartstring:
1059
	mov	ecx,40
1060
	mov	al,13
1061
	cld
1062
	repne	scasb
1063
	cmp	byte [edi],10
1064
	jne	searchstartstring
1065
	ret
2488 mario79 1066
;------------------------------------------------------------------------------
31 halyavin 1067
;*** DATA AREA ****************************************************************
8484 leency 1068
menu_mame:   db '@MENU',0
1069
default_dir: db '/sys',0
31 halyavin 1070
 
2488 mario79 1071
align 4
1072
free_my_area_lock	dd 0
1073
free_my_area	dd 0
1074
 
2211 mario79 1075
processes      dd 0
2488 mario79 1076
;--------------------------------------
2618 mario79 1077
menu_button_x:
1078
.start:	dd MENU_BOTTON_X_POS
1079
.size:	dd MENU_BOTTON_X_SIZE
1080
;--------------------------------------
1081
menu_button_y:
1082
.start:	dd 2
1083
.size:	dd 18
1084
;--------------------------------------
1085
panel_height:		dd PANEL_HEIGHT
1086
panel_attachment:	dd 1
1087
;--------------------------------------
2488 mario79 1088
align 4
31 halyavin 1089
fileinfo:
2488 mario79 1090
 .subfunction	 dd 5		; 5 - file info; 0 - file read
1091
 .start 	 dd 0		; start byte
1092
 .size_high	 dd 0		; rezerved
1093
 .size		 dd 0		; bytes to read
1094
 .return	 dd procinfo	; return data pointer
31 halyavin 1095
 .name:
8484 leency 1096
     db   'SETTINGS/MENU.DAT',0   ; ASCIIZ dir & filename
2488 mario79 1097
;--------------------------------------
1098
align 4
31 halyavin 1099
fileinfo_start:
2488 mario79 1100
 .subfunction	dd 7	; 7=START APPLICATION
1101
 .flags		dd 0	; flags
1102
 .params	dd 0x0	; nop
1103
 .rezerved	dd 0x0	; nop
1104
 .rezerved_1	dd 0x0	; nop
31 halyavin 1105
 .name:
1106
   times 50 db ' '
9439 leency 1107
;--------------------------------------
1108
align 4
1109
file_open:
1110
 .subfunction	dd 7	; 7=START /SYS/@OPEN APP WITH PARAM
1111
 .flags		dd 0	; flags
1112
 .params	dd 0x0	; nop
1113
 .rezerved	dd 0x0	; nop
1114
 .rezerved_1	dd 0x0	; nop
1115
 .name:
1116
   db   '/SYS/@OPEN',0
2488 mario79 1117
;------------------------------------------------------------------------------
1118
IM_END:
1119
;------------------------------------------------------------------------------
1120
align 4
2211 mario79 1121
close_now	dd ?   ; close all processes immediately
1122
end_pointer	dd ?
1123
buffer		dd ?
1124
mousemask	dd ?   ; mask for mouse pointer location
31 halyavin 1125
 
2211 mario79 1126
active_process	dd ?
1127
main_process_ID	dd ?
2488 mario79 1128
;--------------------------------------
2211 mario79 1129
screen_mouse_position:
1130
.y	dw ?
1131
.x	dw ?
2488 mario79 1132
;--------------------------------------
2211 mario79 1133
screen_size:
1134
.y	dw ?
1135
.x	dw ?
2488 mario79 1136
;--------------------------------------
7786 leency 1137
draw_y dd ?
1138
;--------------------------------------
2618 mario79 1139
x_working_area:
1140
.right:		dw ?
1141
.left:		dw ?
1142
y_working_area:
1143
.bottom:	dw ?
1144
.top:		dw ?
1145
;--------------------------------------
31 halyavin 1146
sc system_colors
2488 mario79 1147
;--------------------------------------
1148
last_key	db ?
7848 leency 1149
prior_thread_y dd ?
1150
prior_thread_h dd ?
1151
prior_thread_selected_y_end db ?
2488 mario79 1152
;------------------------------------------------------------------------------
1153
align 4
8484 leency 1154
menu_data   dd ?
2488 mario79 1155
;--------------------------------------
8484 leency 1156
virtual     at 0       ; PROCESSES TABLE (located at menu_data)
1157
  pointer   dd ?   ; +0    pointer in file
1158
  rows      db ?   ; +4    numer of strings
1159
  x_start   dw ?   ; +5    x start
1160
  y_end     dw ?   ; +7    y end
1161
  child     db ?   ; +9    id of child menu
1162
  parent    db ?   ; +10   id of parent menu
1163
  cur_sel   db ?   ; +11   current selection
1164
  prev_sel  db ?   ; +12   previous selection
1165
  rb        16-$+1 ; [16 bytes per element]
31 halyavin 1166
end virtual
9433 rgimad 1167
 
1168
include_debug_strings ; for debug-fdo
1169
 
1170
icons_resname db 'ICONS18W', 0
1171
shared_icons_ptr dd ?
1172
shared_icons_active_ptr dd ?
1173
shared_icons_size dd ?
1174
has_icon db ?
1175
icon_number dd ?
1176
is_icon_active dd ?
1177
no_shared_resources dd 0
1178
tmp dd ?
9527 rgimad 1179
active_color dd ?
1180
work_color dd ?
2488 mario79 1181
;------------------------------------------------------------------------------
2211 mario79 1182
align 4
2618 mario79 1183
bootparam:
2211 mario79 1184
procinfo:
1185
	rb 1024
2488 mario79 1186
;------------------------------------------------------------------------------
1187
align 4
1188
	rb 0x1000
1189
stack_area:
1190
;------------------------------------------------------------------------------
31 halyavin 1191
mem_end:
3013 dunkaist 1192
;------------------------------------------------------------------------------