Subversion Repositories Kolibri OS

Rev

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