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