Subversion Repositories Kolibri OS

Rev

Rev 2211 | Rev 2836 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2211 Rev 2488
1
;******************************************************************************
1
;******************************************************************************
2
;   MAIN MENU
2
;   MAIN MENU
3
;******************************************************************************
3
;******************************************************************************
-
 
4
; last update:  22/03/2012
-
 
5
; changed by:   Marat Zakiyanov aka Mario79, aka Mario
-
 
6
; changes:      Global optimization! The program uses
-
 
7
;               only 32 KB of memory instead of 128 kb is now.
-
 
8
;------------------------------------------------------------------------------
4
; last update:  19/09/2011
9
; last update:  19/09/2011
5
; changed by:   Marat Zakiyanov aka Mario79, aka Mario
10
; changed by:   Marat Zakiyanov aka Mario79, aka Mario
6
; changes:      Checking for program exist to memory
11
; changes:      Checking for program exist to memory
7
;               Added processing of keys: left and right arrow
12
;               Added processing of keys: left and right arrow
8
;---------------------------------------------------------------------
13
;------------------------------------------------------------------------------
9
;   MAIN MENU by lisovin@26.ru
14
;   MAIN MENU by lisovin@26.ru
10
;   Some parts of code rewritten by Ivan Poddubny 
15
;   Some parts of code rewritten by Ivan Poddubny 
11
;
16
;
12
;   Compile with FASM for Menuet
17
;   Compile with FASM for Menuet
13
;******************************************************************************
18
;******************************************************************************
14
  include "lang.inc"
19
  include "lang.inc"
15
  include "..\..\..\macros.inc"
20
  include "..\..\..\macros.inc"
16
 
21
 
17
  BTN_HEIGHT  = 22
22
  BTN_HEIGHT  = 22
18
  TXT_Y       = (BTN_HEIGHT)/2-5
23
  TXT_Y       = (BTN_HEIGHT)/2-5
19
 
24
 
20
  PANEL_HEIGHT	= 20
25
  PANEL_HEIGHT	= 20
21
  MENU_BOTTON_X_POS	= 10
26
  MENU_BOTTON_X_POS	= 10
22
  MENU_BOTTON_X_SIZE	= 60
27
  MENU_BOTTON_X_SIZE	= 60
23
  
-
 
-
 
28
;------------------------------------------------------------------------------
24
	use32
29
	use32
25
	org 0x0
30
	org 0x0
-
 
31
 
26
	db 'MENUET01'	; 8 byte id
32
	db 'MENUET01'	; 8 byte id
27
	dd 0x01		; header version
33
	dd 0x01		; header version
28
	dd START	; start of code
34
	dd START	; start of code
29
	dd I_END	; size of image
35
	dd IM_END	; size of image
30
	dd 0x20000	; memory for app
36
	dd mem_end	; memory for app
31
	dd 0x20000	; esp
37
	dd stack_area	; esp
32
	dd 0x0,0x0	; I_Param , I_Icon
38
	dd 0x0		; boot parameters
-
 
39
	dd 0x0		; path
33
;******************************************************************************
40
;------------------------------------------------------------------------------
34
;include "DEBUG.INC"             ; debug macros
41
;include "DEBUG.INC"             ; debug macros
-
 
42
;------------------------------------------------------------------------------
-
 
43
align 4
35
START:		       ; start of execution
44
START:		       ; start of execution
-
 
45
	mcall	68,11
36
	call	program_exist
46
	call	program_exist
37
	mcall	14
47
	mcall	14
38
	mov	[screen_size],eax
48
	mov	[screen_size],eax
39
	
49
	
40
	mcall	48,3,sc,sizeof.system_colors	; load system colors
50
	mcall	48,3,sc,sizeof.system_colors	; load system colors
-
 
51
	
41
	mcall	70,fileinfo	; load MENU.DAT
52
; get size of file MENU.DAT
42
	test	eax,eax	   ; error ?
53
	mcall	70,fileinfo
43
	jz	@f
-
 
44
	cmp	eax,6
54
	test	eax,eax
45
	jnz	close
55
	jnz	close
-
 
56
; get memory for MENU.DAT
-
 
57
	mov	ecx,[procinfo+32]
-
 
58
	mov	[fileinfo.size],ecx
-
 
59
	mcall	68,12
-
 
60
	mov	[fileinfo.return],eax
-
 
61
	mcall	68
-
 
62
	mov	[menu_data],eax
-
 
63
; load MENU.DAT
-
 
64
	mov	[fileinfo],dword 0
-
 
65
	mcall	70,fileinfo
-
 
66
	test	eax,eax
-
 
67
	jnz	close
46
@@:
68
 
47
	test	ebx,ebx	   ; length = 0 ?
69
	test	ebx,ebx	   ; length = 0 ?
48
	jz	close
70
	jz	close
49
	mov	ecx,ebx
71
	mov	ecx,ebx
50
	mov	edi,mem_end
72
	mov	edi,[fileinfo.return]	;mem_end
-
 
73
;--------------------------------------
-
 
74
align 4
51
newsearch:
75
newsearch:
52
	mov	al,'#'
76
	mov	al,'#'
53
	cld
77
	cld
54
	repne	scasb
78
	repne	scasb
55
	test	ecx,ecx	   ; if not found
79
	test	ecx,ecx	   ; if not found
56
	jz	close
80
	jz	close
57
	call	get_number
81
	call	get_number
58
	test	ebx,ebx
82
	test	ebx,ebx
59
	jnz	.number
83
	jnz	.number
60
	cmp	al,'#'
84
	cmp	al,'#'
61
	je	search_end
85
	je	search_end
-
 
86
;--------------------------------------
-
 
87
align 4
62
.number:
88
.number:
63
	shl	ebx,4
89
	shl	ebx,4
64
	add	ebx,menu_data     ; pointer to process table
90
	add	ebx,[menu_data]     ; pointer to process table
65
	mov	[ebx],edi
91
	mov	[ebx],edi
66
	inc	[processes]
92
	inc	[processes]
67
	jmp	newsearch
93
	jmp	newsearch
68
;---------------------------------------------------------------------
94
;--------------------------------------
-
 
95
align 4
69
search_end:
96
search_end:
70
	mov	[end_pointer],edi
97
	mov	[end_pointer],edi
71
	mov	ebx,[processes]
98
	mov	ebx,[processes]
72
	dec	ebx
99
	dec	ebx
73
	shl	ebx,4
100
	shl	ebx,4
74
	add	ebx,menu_data
101
	add	ebx,[menu_data]
-
 
102
;--------------------------------------
-
 
103
align 4
75
newprocess:
104
newprocess:
76
	xor	edx,edx
105
	xor	edx,edx
77
	mov	ecx,edi
106
	mov	ecx,edi
78
	sub	ecx,[ebx]
107
	sub	ecx,[ebx]
79
	mov	al,10
108
	mov	al,10
-
 
109
;--------------------------------------
-
 
110
align 4
80
newsearch1:
111
newsearch1:
81
	std
112
	std
82
	repne	scasb
113
	repne	scasb
83
	test	ecx,ecx
114
	test	ecx,ecx
84
	je	endprocess
115
	je	endprocess
85
	cmp	[edi],byte 13
116
	cmp	[edi],byte 13
86
	jne	newsearch1
117
	jne	newsearch1
87
	inc	edx
118
	inc	edx
88
	jmp	newsearch1
119
	jmp	newsearch1
89
;---------------------------------------------------------------------
120
;--------------------------------------
-
 
121
align 4
90
endprocess:
122
endprocess:
91
	mov	esi,ebx
123
	mov	esi,ebx
92
	add	esi,4
124
	add	esi,4
93
	dec	edx
125
	dec	edx
94
	mov	[esi],dl
126
	mov	[esi],dl
95
	cmp	ebx,menu_data
127
	cmp	ebx,[menu_data]
96
	jbe	search_end1
128
	jbe	search_end1
97
	sub	ebx,16
129
	sub	ebx,16
98
	jmp	newprocess
130
	jmp	newprocess
99
;---------------------------------------------------------------------
131
;--------------------------------------
-
 
132
align 4
100
search_end1:
133
search_end1:
101
	mcall	14
134
	mcall	14
102
	sub	ax,20
135
	sub	ax,20
-
 
136
	mov	ebx,[menu_data]
103
	mov	[menu_data + y_end],ax
137
	mov	[ebx + y_end],ax
104
	mov	[menu_data + x_start],5
138
	mov	[ebx + x_start],5
105
	mov	al,[menu_data + rows]
139
	mov	al,[ebx + rows]
106
	mov	[menu_data + cur_sel],al	 ; clear selection
140
	mov	[ebx + cur_sel],al	 ; clear selection
107
	mov	[menu_data + prev_sel],al
141
	mov	[ebx + prev_sel],al
108
	mov	[buffer],0
142
	mov	[buffer],0
-
 
143
;------------------------------------------------------------------------------
-
 
144
align 4
109
thread:
145
thread:
-
 
146
	mov	ebp,esp
-
 
147
	sub	ebp,0x1000
-
 
148
	cmp	ebp,0x2000 ; if this is first started thread
-
 
149
	ja	@f
-
 
150
	xor	ebp,ebp ; not free area
-
 
151
;--------------------------------------
-
 
152
align 4
-
 
153
@@:
110
	mov	eax,[buffer]      ; identifier
154
	mov	eax,[buffer]      ; identifier
111
	shl	eax,4
155
	shl	eax,4
112
	add	eax,menu_data
156
	add	eax,[menu_data]
113
	mov	edi,eax
157
	mov	edi,eax
114
	mcall	40,100111b	; mouse + button + key + redraw
158
	mcall	40,100111b	; mouse + button + key + redraw
-
 
159
;------------------------------------------------------------------------------
-
 
160
align 4
115
red:	
161
red:	
116
	call	draw_window	; redraw
162
	call	draw_window	; redraw
-
 
163
;------------------------------------------------------------------------------
-
 
164
align 4
117
still:
165
still:
-
 
166
	call	free_area_if_set_mutex
-
 
167
 
118
	mcall	23,5	; wait here for event
168
	mcall	23,5	; wait here for event
119
	test	[close_now],1      ; is close flag set?
169
	test	[close_now],1      ; is close flag set?
120
	jnz	close
170
	jnz	close
121
	
171
	
122
	cmp	eax,1	; redraw request ?
172
	cmp	eax,1	; redraw request ?
123
	je	red
173
	je	red
124
	cmp	eax,2	; key pressed ?
174
	cmp	eax,2	; key pressed ?
125
	je	key
175
	je	key
126
	cmp	eax,3	; button in buffer ?
176
	cmp	eax,3	; button in buffer ?
127
	je	button
177
	je	button
128
	cmp	eax,6	; mouse event ?
178
	cmp	eax,6	; mouse event ?
129
	je	mouse
179
	je	mouse
130
	cmp	edi,menu_data
180
	cmp	edi,[menu_data]
131
	je	still	     ; if main process-ignored
181
	je	still	     ; if main process-ignored
132
	
182
	
133
	movzx	ebx,[edi + parent]	 ; parent id
183
	movzx	ebx,[edi + parent]	 ; parent id
134
	shl	ebx,4
184
	shl	ebx,4
135
	add	ebx,menu_data      ; ebx = base of parent info
185
	add	ebx,[menu_data]      ; ebx = base of parent info
136
	call	backconvert	     ; get my id in al
186
	call	backconvert	     ; get my id in al
137
	cmp	al,[ebx + child]    ; if I'm not child of my parent, I shall die :)
187
	cmp	al,[ebx + child]    ; if I'm not child of my parent, I shall die :)
138
	jne	close
188
	jne	close
139
	
189
	
140
	jmp	still
190
	jmp	still
141
;---------------------------------------------------------------------
191
;------------------------------------------------------------------------------
-
 
192
align 4
142
key:
193
key:
143
;	mov	eax,2
-
 
144
	mcall
194
	mcall	2
145
	mov	[last_key],ah
195
	mov	[last_key],ah
146
	mov	al,[edi + rows]     ; number of buttons
196
	mov	al,[edi + rows]     ; number of buttons
147
	cmp	ah,178	  ; KEY_UP
197
	cmp	ah,178	  ; KEY_UP
148
	jne	.noup
198
	jne	.noup
149
	
199
	
150
	mov	ah,[edi+cur_sel]
200
	mov	ah,[edi+cur_sel]
151
	mov	[edi+prev_sel],ah
201
	mov	[edi+prev_sel],ah
152
	dec	byte [edi+cur_sel]
202
	dec	byte [edi+cur_sel]
153
	jnz	redrawbut
203
	jnz	redrawbut
154
	mov	[edi+cur_sel],al
204
	mov	[edi+cur_sel],al
155
	jmp	redrawbut
205
	jmp	redrawbut
156
;---------------------------------------------------------------------
206
;--------------------------------------
-
 
207
align 4
157
.noup:
208
.noup:
158
	cmp	ah,177	 ; KEY_DOWN
209
	cmp	ah,177	 ; KEY_DOWN
159
	jne	.nodn
210
	jne	.nodn
160
	
211
	
161
	mov	ah,[edi + cur_sel]
212
	mov	ah,[edi + cur_sel]
162
	mov	[edi + prev_sel],ah
213
	mov	[edi + prev_sel],ah
163
	inc	[edi + cur_sel]
214
	inc	[edi + cur_sel]
164
	cmp	[edi + cur_sel],al
215
	cmp	[edi + cur_sel],al
165
	jna	redrawbut
216
	jna	redrawbut
166
	mov	[edi + cur_sel],1
217
	mov	[edi + cur_sel],1
167
	jmp	redrawbut
218
	jmp	redrawbut
168
;---------------------------------------------------------------------
219
;--------------------------------------
-
 
220
align 4
169
.nodn:
221
.nodn:
170
	cmp	ah,179 	 ; KEY_LEFT
222
	cmp	ah,179 	 ; KEY_LEFT
171
	je	@f
223
	je	@f
172
	cmp	ah,13 	 ; ENTER
224
	cmp	ah,13 	 ; ENTER
173
	jne	.noenter
225
	jne	.noenter
174
@@:
226
@@:
175
	mov	ah,[edi + cur_sel]
227
	mov	ah,[edi + cur_sel]
176
	jmp	button1
228
	jmp	button1
177
;---------------------------------------------------------------------
229
;--------------------------------------
-
 
230
align 4
178
.noenter:
231
.noenter:
179
	cmp	ah,176 	 ; KEY_RIGHT
232
	cmp	ah,176 	 ; KEY_RIGHT
180
	je	@f
233
	je	@f
181
	cmp	ah,27 	 ; ESC
234
	cmp	ah,27 	 ; ESC
182
	jne	still
235
	jne	still
183
	jmp	close
236
	jmp	close
-
 
237
;--------------------------------------
-
 
238
align 4
184
@@:
239
@@:
185
	call	get_process_ID
240
	call	get_process_ID
186
	cmp	[main_process_ID],ecx
241
	cmp	[main_process_ID],ecx
187
	jne	close
242
	jne	close
188
	jmp	still
243
	jmp	still
189
;---------------------------------------------------------------------
244
;------------------------------------------------------------------------------
190
; include "DEBUG.INC"
245
align 4
191
button:	; BUTTON HANDLER
246
button:	; BUTTON HANDLER
192
	mcall	17	; get id
247
	mcall	17	; get id
193
				; dunkaist[
248
				; dunkaist[
194
	test	eax,0xfffffe00	; is it system close button? (close signal from @panel)
249
	test	eax,0xfffffe00	; is it system close button? (close signal from @panel)
195
	setz	byte[close_now]	; set (or not set) close_recursive flag
250
	setz	byte[close_now]	; set (or not set) close_recursive flag
196
	jz	close		; if so,close all menus
251
	jz	close		; if so,close all menus
197
				; dunkaist]
252
				; dunkaist]
-
 
253
;--------------------------------------
-
 
254
align 4
198
button1:
255
button1:
199
	mov	esi,edi
256
	mov	esi,edi
200
	push	edi
257
	push	edi
201
	mov	edi,[edi + pointer]
258
	mov	edi,[edi + pointer]
202
; print "hello"
259
; print "hello"
203
	mov	al,[esi + cur_sel]
260
	mov	al,[esi + cur_sel]
204
	mov	[esi + prev_sel],al
261
	mov	[esi + prev_sel],al
205
	mov	[esi + cur_sel],ah
262
	mov	[esi + cur_sel],ah
206
	
263
	
207
	pushad
264
	pushad
208
	mov	edi,esi
265
	mov	edi,esi
209
; dph eax
266
; dph eax
210
	call	draw_only_needed_buttons
267
	call	draw_only_needed_buttons
211
	popad
268
	popad
212
; look for the next line  times;  = button_id
269
; look for the next line  times;  = button_id
213
	push	eax
270
	push	eax
-
 
271
;--------------------------------------
-
 
272
align 4
214
.next_string:
273
.next_string:
215
	call	searchstartstring
274
	call	searchstartstring
216
	dec	ah
275
	dec	ah
217
	jnz	.next_string
276
	jnz	.next_string
218
	pop	eax
277
	pop	eax
219
	
278
	
220
	mov	ecx,40
279
	mov	ecx,40
221
	mov	al,'/'
280
	mov	al,'/'
222
	cld
281
	cld
223
	repne	scasb
282
	repne	scasb
224
	test	ecx,ecx	  ; if '/' not found
283
	test	ecx,ecx	  ; if '/' not found
225
	je	searchexit
284
	je	searchexit
226
	
285
	
227
	cmp	[edi],byte '@'     ; check for submenu
286
	cmp	[edi],byte '@'     ; check for submenu
228
	je	runthread
287
	je	runthread
229
	
288
	
230
	cmp	[last_key],179
289
	cmp	[last_key],179
231
	je	searchexit
290
	je	searchexit
232
	
291
	
233
	dec	edi
292
	dec	edi
234
	push	edi			; pointer to start of filename
293
	push	edi			; pointer to start of filename
235
	call	searchstartstring	; search for next string
294
	call	searchstartstring	; search for next string
236
	sub	edi,2		; to last byte of string
295
	sub	edi,2		; to last byte of string
237
	
296
	
238
	mov	ecx,edi
297
	mov	ecx,edi
239
	pop	esi
298
	pop	esi
240
	sub	ecx,esi
299
	sub	ecx,esi
241
	inc	ecx		 ; length of filename
300
	inc	ecx		 ; length of filename
242
	mov	edi, fileinfo_start.name
301
	mov	edi, fileinfo_start.name
243
	rep	movsb		   ; copy string
302
	rep	movsb		   ; copy string
244
	mov	[edi],byte 0	       ; store terminator
303
	mov	[edi],byte 0	       ; store terminator
245
	mcall	70,fileinfo_start	; start program
304
	mcall	70,fileinfo_start	; start program
246
	or	[close_now],1      ; set close flag
305
	or	[close_now],1      ; set close flag
247
	pop	edi
306
	pop	edi
248
	mov	[mousemask],0
307
	mov	[mousemask],0
249
	jmp	close
308
	jmp	close
250
;---------------------------------------------------------------------
309
;--------------------------------------
-
 
310
align 4
251
searchexit:
311
searchexit:
252
	pop	edi
312
	pop	edi
253
	jmp	still
313
	jmp	still
254
;---------------------------------------------------------------------
314
;------------------------------------------------------------------------------
-
 
315
align 4
255
runthread:
316
runthread:
256
	inc	edi
317
	inc	edi
257
	
318
	
258
	push	eax
319
	push	eax
259
	call	get_number	     ; get number of this process
320
	call	get_number	     ; get number of this process
260
	pop	eax
321
	pop	eax
261
	
322
	
262
	test	ebx,ebx	   ; returned zero - main menu or not number
323
	test	ebx,ebx	   ; returned zero - main menu or not number
263
	jz	searchexit
324
	jz	searchexit
264
	
325
	
265
	mov	al,bl
326
	mov	al,bl
266
	
327
	
267
	mov	ebx,[processes]
328
	mov	ebx,[processes]
268
	dec	bl
329
	dec	bl
269
	cmp	al,bl
330
	cmp	al,bl
270
	ja	searchexit	       ; such process doesnt exist
331
	ja	searchexit	       ; such process doesnt exist
271
	cmp	al,[esi + child]
332
	cmp	al,[esi + child]
272
	je	searchexit	       ; such process already exists
333
	je	searchexit	       ; such process already exists
273
	
334
	
274
	mov	[esi + child],al    ; this is my child
335
	mov	[esi + child],al    ; this is my child
275
	mov	cx,[esi + x_start]
336
	mov	cx,[esi + x_start]
276
	add	cx,141	  ; new x_start in cx
337
	add	cx,141	  ; new x_start in cx
277
	movzx	edx,al
338
	movzx	edx,al
278
	shl	edx,4
339
	shl	edx,4
279
	add	edx,menu_data       ; edx points to child's base address
340
	add	edx,[menu_data]       ; edx points to child's base address
280
	mov	[edx + x_start],cx  ; xstart for new thread
341
	mov	[edx + x_start],cx  ; xstart for new thread
281
	mov	cx,[esi + y_end]   ; y_end in cx
342
	mov	cx,[esi + y_end]   ; y_end in cx
282
	mov	bl,[esi + rows]    ; number of buttons in bl
343
	mov	bl,[esi + rows]    ; number of buttons in bl
283
	sub	bl,ah	  ; number of btn from bottom
344
	sub	bl,ah	  ; number of btn from bottom
284
	movzx	eax,al
345
	movzx	eax,al
285
	mov	[buffer],eax		; thread id in buffer
346
	mov	[buffer],eax		; thread id in buffer
286
	movzx	ebx,bl
347
	movzx	ebx,bl
287
	push	edx
348
	push	edx
288
	mov	eax,BTN_HEIGHT
349
	mov	eax,BTN_HEIGHT
289
	mul	ebx
350
	mul	ebx
290
	sub	cx,ax	  ; new y_end for new thread
351
	sub	cx,ax	  ; new y_end for new thread
291
	pop	edx
352
	pop	edx
292
	mov	[edx + y_end],cx    ; store y_end
353
	mov	[edx + y_end],cx    ; store y_end
293
	mov	edi,esi
354
	mov	edi,esi
294
	call	backconvert	      ; get number of this process (al)
355
	call	backconvert	      ; get number of this process (al)
295
	mov	[edx + parent],al   ; store number of parent process
356
	mov	[edx + parent],al   ; store number of parent process
296
	mov	al,[edx + rows]
357
	mov	al,[edx + rows]
297
	mov	[edx + cur_sel],al  ; clear current selected element
358
	mov	[edx + cur_sel],al  ; clear current selected element
298
	mov	[edx + prev_sel],al ; clear previous selected element
359
	mov	[edx + prev_sel],al ; clear previous selected element
299
	mov	[edx + child],0
360
	mov	[edx + child],0
300
	
361
	
301
	cmp	[thread_stack],0x1e000
362
	mcall	68,12,0x1000	; stack of each thread is allocated 4 KB
302
	jne	thread_stack_not_full
363
	add	eax,0x1000	; set the stack pointer to the desired position
303
	mov	[thread_stack],0xE000
-
 
304
thread_stack_not_full:
-
 
305
	add	[thread_stack],0x2000 ; start new thread
364
	mov	edx,eax
306
	mcall	51,1,thread,[thread_stack]
365
	mcall	51,1,thread	; Go ahead!
307
	jmp	searchexit
366
	jmp	searchexit
-
 
367
;------------------------------------------------------------------------------
308
;---------------------------------------------------------------------
368
align 4
309
mouse: 	      ; MOUSE EVENT HANDLER
369
mouse: 	      ; MOUSE EVENT HANDLER
310
	mcall	37,0
370
	mcall	37,0
311
	mov	[screen_mouse_position],eax ; eax = [ Y | X ] relative to screen
371
	mov	[screen_mouse_position],eax ; eax = [ Y | X ] relative to screen
312
 
372
 
313
	mcall	37,2
373
	mcall	37,2
314
	test	eax,eax	   ; check buttons state
374
	test	eax,eax	   ; check buttons state
315
	jnz	click
375
	jnz	click
316
	mcall	37,1
376
	mcall	37,1
317
	ror	eax,16	  ; eax = [ Y | X ] relative to window
377
	ror	eax,16	  ; eax = [ Y | X ] relative to window
318
	cmp	ax,140	   ; pointer in window?
378
	cmp	ax,140	   ; pointer in window?
319
	ja	noinwindow
379
	ja	noinwindow
320
; *** in window ***
380
; *** in window ***
321
	shr	eax,16	  ; eax = [ 0 | Y ]
381
	shr	eax,16	  ; eax = [ 0 | Y ]
322
	xor	edx,edx
382
	xor	edx,edx
323
	mov	ebx,BTN_HEIGHT
383
	mov	ebx,BTN_HEIGHT
324
	div	ebx
384
	div	ebx
325
	inc	eax		  ; number of "button" in eax
385
	inc	eax		  ; number of "button" in eax
326
	movzx	ebx,[edi + rows]    ; total strings in ebx
386
	movzx	ebx,[edi + rows]    ; total strings in ebx
327
	cmp	eax,ebx
387
	cmp	eax,ebx
328
	ja	noinwindow
388
	ja	noinwindow
329
	cmp	[edi + cur_sel],al
389
	cmp	[edi + cur_sel],al
330
	je	noredrawbut
390
	je	noredrawbut
331
	mov	bl,[edi + cur_sel]
391
	mov	bl,[edi + cur_sel]
332
;;;;;;
392
;;;;;;
333
	cmp	[edi + child],0
393
	cmp	[edi + child],0
334
	jne	noredrawbut
394
	jne	noredrawbut
335
;;;;;;
395
;;;;;;
336
	mov	[edi + cur_sel],al
396
	mov	[edi + cur_sel],al
337
	mov	[edi + prev_sel],bl
397
	mov	[edi + prev_sel],bl
-
 
398
;--------------------------------------
-
 
399
align 4
338
redrawbut:
400
redrawbut:
339
	call	draw_only_needed_buttons
401
	call	draw_only_needed_buttons
-
 
402
;--------------------------------------
-
 
403
align 4
340
noredrawbut:
404
noredrawbut:
341
	call	backconvert
405
	call	backconvert
342
	bts	[mousemask],eax
406
	bts	[mousemask],eax
343
	jmp	still
407
	jmp	still
344
;---------------------------------------------------------------------
408
;--------------------------------------
-
 
409
align 4
345
noinwindow:
410
noinwindow:
346
	call	backconvert
411
	call	backconvert
347
	btr	[mousemask],eax
412
	btr	[mousemask],eax
348
	jmp	still
413
	jmp	still
349
;---------------------------------------------------------------------
414
;------------------------------------------------------------------------------
-
 
415
align 4
350
click:
416
click:
351
	cmp	[mousemask],0  ; not in a window (i.e. menu)
417
	cmp	[mousemask],0  ; not in a window (i.e. menu)
352
	jne	still
418
	jne	still
353
; checking for pressing 'MENU' on the taskbar	
419
; checking for pressing 'MENU' on the taskbar	
354
	mov	eax,[screen_mouse_position]
420
	mov	eax,[screen_mouse_position]
355
	mov	ebx,[screen_size]
421
	mov	ebx,[screen_size]
356
	sub	bx,PANEL_HEIGHT
422
	sub	bx,PANEL_HEIGHT
357
	cmp	bx,ax
423
	cmp	bx,ax
358
	ja	close
424
	ja	close
359
	shr	eax,16
425
	shr	eax,16
360
	cmp	ax,MENU_BOTTON_X_SIZE
426
	cmp	ax,MENU_BOTTON_X_SIZE
361
	ja	close
427
	ja	close
362
	cmp	ax,MENU_BOTTON_X_POS
428
	cmp	ax,MENU_BOTTON_X_POS
363
	ja	still
429
	ja	still
364
;---------------------------------------------------------------------
430
;------------------------------------------------------------------------------
-
 
431
align 4
365
close:
432
close:
366
	
433
	
367
	movzx	ebx,[edi+parent]       ; parent id
434
	movzx	ebx,[edi+parent]       ; parent id
368
	shl	ebx,4
435
	shl	ebx,4
369
	add	ebx,menu_data          ; ebx = base of parent info
436
	add	ebx,[menu_data]          ; ebx = base of parent info
370
	call	backconvert
437
	call	backconvert
371
	cmp	[ebx + child],al       ; if i am the child of my parent...
438
	cmp	[ebx + child],al       ; if i am the child of my parent...
372
	jnz	@f
439
	jnz	@f
373
	mov	[ebx + child],-1       ; ...my parent now has no children
440
	mov	[ebx + child],-1       ; ...my parent now has no children
-
 
441
;--------------------------------------
-
 
442
align 4
374
@@:
443
@@:
375
	or	eax,-1                 ; close this thread
444
	or	eax,-1                 ; close this thread
376
	mov	[edi + child],al       ; my child is not mine
445
	mov	[edi + child],al       ; my child is not mine
-
 
446
	
-
 
447
	call	free_area_if_set_mutex
-
 
448
	call	set_mutex_for_free_area
-
 
449
	
377
	mcall
450
	mcall
-
 
451
;--------------------------------------
-
 
452
align 4
378
backconvert:		  ; convert from pointer to process id
453
backconvert:		  ; convert from pointer to process id
379
	mov	eax,edi
454
	mov	eax,edi
380
	sub	eax,menu_data
455
	sub	eax,[menu_data]
381
	shr	eax,4
456
	shr	eax,4
382
	ret
457
	ret
-
 
458
;------------------------------------------------------------------------------
-
 
459
align 4
-
 
460
set_mutex_for_free_area:
-
 
461
; set mutex for free thread stack area	
-
 
462
	push	eax ebx
-
 
463
;--------------------------------------
-
 
464
align 4
-
 
465
.wait_lock:
-
 
466
        cmp     [free_my_area_lock], 0
-
 
467
        je      .get_lock
-
 
468
	mcall	68,1
-
 
469
        jmp     .wait_lock
-
 
470
;--------------------------------------
-
 
471
align 4
-
 
472
.get_lock:
-
 
473
        mov     eax, 1
-
 
474
        xchg    eax, [free_my_area_lock]
-
 
475
        test    eax, eax
-
 
476
        jnz     .wait_lock
-
 
477
	mov	[free_my_area],ebp
-
 
478
	pop	ebx eax
-
 
479
	ret
-
 
480
;------------------------------------------------------------------------------
-
 
481
align 4
-
 
482
free_area_if_set_mutex:
-
 
483
	cmp	[free_my_area_lock],0
-
 
484
	je	.end
-
 
485
 
-
 
486
	push	eax ebx ecx
-
 
487
	mov	ecx,[free_my_area]
-
 
488
 
-
 
489
	test	ecx,ecx
-
 
490
	jz	@f
-
 
491
	mcall	68,13
-
 
492
;--------------------------------------
-
 
493
align 4
-
 
494
@@:
-
 
495
	xor	eax,eax
-
 
496
	mov	[free_my_area_lock],eax
-
 
497
	pop	ecx ebx eax
-
 
498
;--------------------------------------
-
 
499
align 4
-
 
500
.end:	
-
 
501
	ret
383
;---------------------------------------------------------------------
502
;------------------------------------------------------------------------------
384
;==================================
503
;==================================
385
; get_number
504
; get_number
386
;    load number from [edi] to ebx
505
;    load number from [edi] to ebx
387
;==================================
506
;==================================
-
 
507
align 4
388
get_number:
508
get_number:
389
	push	edi
509
	push	edi
390
	xor	eax,eax
510
	xor	eax,eax
391
	xor	ebx,ebx
511
	xor	ebx,ebx
-
 
512
;--------------------------------------
-
 
513
align 4
392
.get_next_char:
514
.get_next_char:
393
	mov	al,[edi]
515
	mov	al,[edi]
394
	inc	edi
516
	inc	edi
395
	cmp	al, '0'
517
	cmp	al, '0'
396
	jb	.finish
518
	jb	.finish
397
	cmp	al, '9'
519
	cmp	al, '9'
398
	ja	.finish
520
	ja	.finish
399
	sub	al, '0'
521
	sub	al, '0'
400
	imul	ebx,10
522
	imul	ebx,10
401
	add	ebx,eax
523
	add	ebx,eax
402
	jmp	.get_next_char
524
	jmp	.get_next_char
403
;-------------------------------------
525
;-------------------------------------
-
 
526
align 4
404
.finish:
527
.finish:
405
	pop	edi
528
	pop	edi
406
	ret
529
	ret
407
;---------------------------------------------------------------------
530
;------------------------------------------------------------------------------
-
 
531
align 4
408
get_process_ID:
532
get_process_ID:
409
	mcall	9,procinfo,-1
533
	mcall	9,procinfo,-1
410
	mov	edx,eax
534
	mov	edx,eax
411
	mov	ecx,[ebx+30]	; PID
535
	mov	ecx,[ebx+30]	; PID
412
	ret
536
	ret
413
;---------------------------------------------------------------------
537
;------------------------------------------------------------------------------
-
 
538
align 4
414
program_exist:
539
program_exist:
415
	call	get_process_ID
540
	call	get_process_ID
416
	mov	[main_process_ID],ecx
541
	mov	[main_process_ID],ecx
417
	mcall	18,21
542
	mcall	18,21
418
	mov	[active_process],eax	; WINDOW SLOT
543
	mov	[active_process],eax	; WINDOW SLOT
419
	mov	ecx,edx
544
	mov	ecx,edx
420
	xor	edx,edx
545
	xor	edx,edx
421
;-----------------------------------------
546
;-----------------------------------------
-
 
547
align 4
422
.loop:
548
.loop:
423
	push	ecx
549
	push	ecx
424
	mcall	9,procinfo
550
	mcall	9,procinfo
425
	mov	eax,[menu_mame]
551
	mov	eax,[menu_mame]
426
	cmp	[ebx+10],eax
552
	cmp	[ebx+10],eax
427
	jne	@f
553
	jne	@f
428
	mov	ax,[menu_mame+4]
554
	mov	ax,[menu_mame+4]
429
	cmp	[ebx+14],ax
555
	cmp	[ebx+14],ax
430
	jne	@f
556
	jne	@f
431
	cmp	ecx,[active_process]
557
	cmp	ecx,[active_process]
432
	je	@f
558
	je	@f
433
; dph ecx
559
; dph ecx
434
	mcall	18,2
560
	mcall	18,2
435
	mov	edx,1
561
	mov	edx,1
-
 
562
;--------------------------------------
-
 
563
align 4
436
@@:
564
@@:
437
	pop	ecx
565
	pop	ecx
438
	loop	.loop
566
	loop	.loop
439
;-----------------------------------------	
-
 
-
 
567
 
440
	test	edx,edx
568
	test	edx,edx
441
	jz	@f
569
	jz	@f
442
	mcall	-1
570
	mcall	-1
-
 
571
;--------------------------------------
-
 
572
align 4
443
@@:
573
@@:
444
	ret
574
	ret
445
;---------------------------------------------------------------------
575
;------------------------------------------------------------------------------
446
;   *********************************************
576
;   *********************************************
447
;   *******  WINDOW DEFINITIONS AND DRAW ********
577
;   *******  WINDOW DEFINITIONS AND DRAW ********
448
;   *********************************************
578
;   *********************************************
-
 
579
align 4
449
draw_window:
580
draw_window:
450
	mcall	12,1	; 1,start of draw
581
	mcall	12,1	; 1,start of draw
451
	movzx	ebx,[edi + rows]
582
	movzx	ebx,[edi + rows]
452
	imul	eax,ebx,BTN_HEIGHT	    ; eax = height of window
583
	imul	eax,ebx,BTN_HEIGHT	    ; eax = height of window
453
	movzx	ecx,[edi + y_end]
584
	movzx	ecx,[edi + y_end]
454
	sub	ecx,eax	    ; ecx = Y_START
585
	sub	ecx,eax	    ; ecx = Y_START
455
	shl	ecx,16
586
	shl	ecx,16
456
	add	ecx,eax	    ; ecx = [ Y_START | Y_SIZE ]
587
	add	ecx,eax	    ; ecx = [ Y_START | Y_SIZE ]
457
	dec	ecx
588
	dec	ecx
458
	movzx	ebx,[edi + x_start]
589
	movzx	ebx,[edi + x_start]
459
	shl	ebx,16
590
	shl	ebx,16
460
	mov	bx,140	    ; ebx = [ X_START | X_SIZE ]
591
	mov	bx,140	    ; ebx = [ X_START | X_SIZE ]
461
	mov	edx,0x01000000       ; color of work area RRGGBB,8->color gl
592
	mov	edx,0x01000000       ; color of work area RRGGBB,8->color gl
462
	mov	esi,edx	    ; unmovable window
593
	mov	esi,edx	    ; unmovable window
463
	xor	eax,eax	    ; function 0 : define and draw window
594
	xor	eax,eax	    ; function 0 : define and draw window
464
	mcall
595
	mcall
465
	
596
	
466
	call	draw_all_buttons
597
	call	draw_all_buttons
467
	mcall	12,2
598
	mcall	12,2
468
	ret
599
	ret
469
;---------------------------------------------------------------------
600
;------------------------------------------------------------------------------
-
 
601
align 4
470
draw_all_buttons:
602
draw_all_buttons:
471
	xor	edx,edx
603
	xor	edx,edx
-
 
604
;--------------------------------------
-
 
605
align 4
472
.new_button:
606
.new_button:
473
	call	draw_one_button
607
	call	draw_one_button
474
	inc	edx
608
	inc	edx
475
	cmp	dl,[edi + rows]
609
	cmp	dl,[edi + rows]
476
	jb	.new_button
610
	jb	.new_button
477
	ret
611
	ret
478
;---------------------------------------------------------------------
612
;------------------------------------------------------------------------------
-
 
613
align 4
479
draw_only_needed_buttons:
614
draw_only_needed_buttons:
480
	xor	edx,edx
615
	xor	edx,edx
481
	mov	dl,[edi + cur_sel]
616
	mov	dl,[edi + cur_sel]
482
	dec	dl
617
	dec	dl
483
	call	draw_one_button
618
	call	draw_one_button
484
	mov	dl,[edi + prev_sel]
619
	mov	dl,[edi + prev_sel]
485
	dec	dl
620
	dec	dl
486
	call	draw_one_button
621
	call	draw_one_button
487
	ret
622
	ret
488
;---------------------------------------------------------------------
623
;------------------------------------------------------------------------------
-
 
624
align 4
489
draw_one_button:
625
draw_one_button:
490
; receives number of button in dl
626
; receives number of button in dl
491
	push	edx
627
	push	edx
492
	mov	eax,8
628
	mov	eax,8
493
	mov	ebx,140
629
	mov	ebx,140
494
	movzx	ecx,dl
630
	movzx	ecx,dl
495
	imul	ecx,BTN_HEIGHT
631
	imul	ecx,BTN_HEIGHT
496
	shl	ecx,16
632
	shl	ecx,16
497
	add	ecx,BTN_HEIGHT-1
633
	add	ecx,BTN_HEIGHT-1
498
; edx = button identifier
634
; edx = button identifier
499
	mov	esi,[sc.work]
635
	mov	esi,[sc.work]
500
	cmp	esi,0xdfdfdf
636
	cmp	esi,0xdfdfdf
501
	jb	nocorrect
637
	jb	nocorrect
502
	sub	esi,0x1b1b1b
638
	sub	esi,0x1b1b1b
-
 
639
;--------------------------------------
-
 
640
align 4
503
nocorrect: 
641
nocorrect: 
504
	inc	dl
642
	inc	dl
505
	cmp	[edi + cur_sel],dl
643
	cmp	[edi + cur_sel],dl
506
	jne	.nohighlight
644
	jne	.nohighlight
507
	add	esi,0x1a1a1a
645
	add	esi,0x1a1a1a
-
 
646
;--------------------------------------
-
 
647
align 4
508
.nohighlight:
648
.nohighlight:
509
	or	edx,0x20000000
649
	or	edx,0x20000000
510
				; dunkaist[
650
				; dunkaist[
511
	add	edx,0xd1ff00	; This makes first menu buttons differ
651
	add	edx,0xd1ff00	; This makes first menu buttons differ
512
				; from system close button with 0x000001 id
652
				; from system close button with 0x000001 id
513
				; dunkaist]
653
				; dunkaist]
514
	mcall
654
	mcall
515
	movzx	edx,dl
655
	movzx	edx,dl
516
	dec	dl
656
	dec	dl
517
	imul	ebx,edx,BTN_HEIGHT
657
	imul	ebx,edx,BTN_HEIGHT
518
	add	ebx,(4 shl 16) + TXT_Y
658
	add	ebx,(4 shl 16) + TXT_Y
519
	movzx	ecx,dl
659
	movzx	ecx,dl
520
	inc	ecx
660
	inc	ecx
521
	mov	edx,[edi + pointer]
661
	mov	edx,[edi + pointer]
-
 
662
;--------------------------------------
-
 
663
align 4
522
.findline:
664
.findline:
523
	cmp	byte [edx],13
665
	cmp	byte [edx],13
524
	je	.linefound
666
	je	.linefound
525
	inc	edx
667
	inc	edx
526
	jmp	.findline
668
	jmp	.findline
527
;---------------------------------------------------------------------
669
;------------------------------------------------------------------------------
-
 
670
align 4
528
.linefound:
671
.linefound:
529
	inc	edx
672
	inc	edx
530
	cmp	byte [edx],10
673
	cmp	byte [edx],10
531
	jne	.findline
674
	jne	.findline
532
	dec	ecx
675
	dec	ecx
533
	jnz	.findline
676
	jnz	.findline
534
	
677
	
535
	mcall	4,,[sc.work_text],,21
678
	mcall	4,,[sc.work_text],,21
536
	pop	edx
679
	pop	edx
537
	ret
680
	ret
538
;---------------------------------------------------------------------
681
;------------------------------------------------------------------------------
-
 
682
align 4
539
searchstartstring:
683
searchstartstring:
540
	mov	ecx,40
684
	mov	ecx,40
541
	mov	al,13
685
	mov	al,13
542
	cld
686
	cld
543
	repne	scasb
687
	repne	scasb
544
	cmp	byte [edi],10
688
	cmp	byte [edi],10
545
	jne	searchstartstring
689
	jne	searchstartstring
546
	ret
690
	ret
547
;---------------------------------------------------------------------
691
;------------------------------------------------------------------------------
548
;*** DATA AREA ****************************************************************
692
;*** DATA AREA ****************************************************************
549
menu_mame:
693
menu_mame:
550
	db '@MENU',0
694
	db '@MENU',0
-
 
695
 
551
 
696
align 4
552
thread_stack   dd 0xE000
697
free_my_area_lock	dd 0
-
 
698
free_my_area	dd 0
-
 
699
 
-
 
700
processes      dd 0
553
processes      dd 0
701
;--------------------------------------
554
 
702
align 4
555
fileinfo:
703
fileinfo:
556
 .subfunction	 dd 0 	      ; 0=READ
704
 .subfunction	 dd 5		; 5 - file info; 0 - file read
557
 .start 	 dd 0 	      ; start byte
705
 .start 	 dd 0		; start byte
558
 .size_high	 dd 0 	      ; rezerved
706
 .size_high	 dd 0		; rezerved
559
 .size		 dd 0x10000-mem_end ; blocks to read
707
 .size		 dd 0		; bytes to read
560
 .return	 dd mem_end	      ; return data pointer
708
 .return	 dd procinfo	; return data pointer
-
 
709
 .name:
561
 .name:
710
     db   '/sys/MENU.DAT',0   ; ASCIIZ dir & filename
562
     db   '/sys/MENU.DAT',0   ; ASCIIZ dir & filename
711
;--------------------------------------
563
 
712
align 4
564
fileinfo_start:
713
fileinfo_start:
565
 .subfunction	dd 7 	 ; 7=START APPLICATION
714
 .subfunction	dd 7	; 7=START APPLICATION
566
 .flags		dd 0 	 ; flags
715
 .flags		dd 0	; flags
567
 .params	dd 0x0	 ; nop
716
 .params	dd 0x0	; nop
568
 .rezerved	dd 0x0	 ; nop
717
 .rezerved	dd 0x0	; nop
569
 .rezerved_1	dd 0x0	 ; nop
718
 .rezerved_1	dd 0x0	; nop
570
 .name:
719
 .name:
571
   times 50 db ' '
720
   times 50 db ' '
572
;---------------------------------------------------------------------
721
;------------------------------------------------------------------------------
573
I_END:
722
IM_END:
574
;---------------------------------------------------------------------
723
;------------------------------------------------------------------------------
-
 
724
align 4
575
close_now	dd ?   ; close all processes immediately
725
close_now	dd ?   ; close all processes immediately
576
end_pointer	dd ?
726
end_pointer	dd ?
577
buffer		dd ?
727
buffer		dd ?
578
mousemask	dd ?   ; mask for mouse pointer location
728
mousemask	dd ?   ; mask for mouse pointer location
579
 
729
 
580
active_process	dd ?
730
active_process	dd ?
581
main_process_ID	dd ?
731
main_process_ID	dd ?
582
 
-
 
-
 
732
;--------------------------------------
583
screen_mouse_position:
733
screen_mouse_position:
584
.y	dw ?
734
.y	dw ?
585
.x	dw ?
735
.x	dw ?
586
 
-
 
-
 
736
;--------------------------------------
587
screen_size:
737
screen_size:
588
.y	dw ?
738
.y	dw ?
589
.x	dw ?
739
.x	dw ?
590
 
-
 
591
 
-
 
-
 
740
;--------------------------------------
592
sc system_colors
741
sc system_colors
-
 
742
;--------------------------------------
-
 
743
last_key	db ?
-
 
744
;------------------------------------------------------------------------------
593
 
745
align 4
594
menu_data:
746
menu_data	dd ?
595
	rb 0x4000  ;x10000
747
;--------------------------------------
596
 
-
 
597
virtual at 0	      ; PROCESSES TABLE (located at menu_data)
748
virtual at 0	      ; PROCESSES TABLE (located at menu_data)
598
  pointer	dd ?   ; +0    pointer in file
749
  pointer	dd ?   ; +0    pointer in file
599
  rows		db ?	; +4    numer of strings
750
  rows		db ?	; +4    numer of strings
600
  x_start	dw ?   ; +5    x start
751
  x_start	dw ?   ; +5    x start
601
  y_end		dw ?   ; +7    y end
752
  y_end		dw ?   ; +7    y end
602
  child		db ?   ; +9    id of child menu
753
  child		db ?   ; +9    id of child menu
603
  parent	db ?   ; +10   id of parent menu
754
  parent	db ?   ; +10   id of parent menu
604
  cur_sel	db ?   ; +11   current selection
755
  cur_sel	db ?   ; +11   current selection
605
  prev_sel	db ?   ; +12   previous selection
756
  prev_sel	db ?   ; +12   previous selection
606
  rb		16-$+1 ; [16 bytes per element]
757
  rb		16-$+1 ; [16 bytes per element]
607
end virtual
758
end virtual
608
 
-
 
609
last_key	db ?
-
 
610
;---------------------------------------------------------------------
759
;------------------------------------------------------------------------------
611
align 4
760
align 4
612
procinfo:
761
procinfo:
613
	rb 1024
762
	rb 1024
614
;---------------------------------------------------------------------
763
;------------------------------------------------------------------------------
-
 
764
align 4
-
 
765
	rb 0x1000
-
 
766
stack_area:
-
 
767
;------------------------------------------------------------------------------
615
mem_end:
768
mem_end:
616
;---------------------------------------------------------------------
-
 
617
769
;------------------------------------------------------------------------------
-
 
770
618
771