Subversion Repositories Kolibri OS

Rev

Rev 318 | Rev 529 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;******************************************************************************
2
;   MAIN MENU by lisovin@26.ru
3
;   Some parts of code rewritten by Ivan Poddubny 
4
;
5
;   Compile with FASM for Menuet
6
;******************************************************************************
7
  include "lang.inc"
485 heavyiron 8
  include "..\..\..\macros.inc"
31 halyavin 9
 
10
  BTN_HEIGHT  = 22
11
  TXT_Y       = (BTN_HEIGHT)/2-5
12
 
13
  use32
97 mario79 14
  org	  0x0
15
  db	 'MENUET01'	    ; 8 byte id
16
  dd	 0x01		  ; header version
17
  dd	 START		   ; start of code
18
  dd	 I_END		   ; size of image
19
  dd	 0x20000	 ; memory for app
20
  dd	 0x20000-1	     ; esp
21
  dd	 0x0 , 0x0	   ; I_Param , I_Icon
31 halyavin 22
;******************************************************************************
23
;include "DEBUG.INC"             ; debug macros
97 mario79 24
START:		       ; start of execution
31 halyavin 25
 
97 mario79 26
     mov  eax, 48	  ; load system colors
31 halyavin 27
     mov  ebx, 3
28
     mov  ecx, sc
29
     mov  edx, sizeof.system_colors
485 heavyiron 30
     mcall
31 halyavin 31
 
97 mario79 32
     mov  eax, 70	  ; load MENU.DAT
31 halyavin 33
     mov  ebx, fileinfo
485 heavyiron 34
     mcall
97 mario79 35
     test eax, eax	   ; error ?
36
     jz  @f
37
     cmp  eax,6
31 halyavin 38
     jnz  close
97 mario79 39
  @@:
40
     test ebx, ebx	   ; length = 0 ?
31 halyavin 41
     jz   close
42
     mov  ecx, ebx
43
     mov  edi, mem_end
44
  newsearch:
45
     mov  al, '#'
46
     cld
47
     repne scasb
97 mario79 48
     test ecx, ecx	   ; if not found
31 halyavin 49
     jz   close
50
     call get_number
51
     test ebx, ebx
52
     jnz  .number
53
     cmp  al, '#'
54
     je   search_end
55
   .number:
56
     shl  ebx, 4
97 mario79 57
     add  ebx, menu_data     ; pointer to process table
31 halyavin 58
     mov  [ebx], edi
59
     inc  [processes]
60
     jmp  newsearch
61
  search_end:
62
     mov  [end_pointer], edi
63
     mov  ebx, [processes]
64
     dec  ebx
65
     shl  ebx, 4
66
     add  ebx, menu_data
67
  newprocess:
68
     xor  edx, edx
69
     mov  ecx, edi
70
     sub  ecx, [ebx]
71
     mov  al, 10
72
  newsearch1:
73
     std
74
     repne scasb
75
     test ecx, ecx
76
     je   endprocess
77
     cmp  [edi], byte 13
78
     jne  newsearch1
79
     inc  edx
80
     jmp  newsearch1
81
  endprocess:
82
     mov  esi, ebx
83
     add  esi, 4
84
     dec  edx
85
     mov  [esi], dl
86
     cmp  ebx, menu_data
87
     jbe  search_end1
88
     sub  ebx, 16
89
     jmp  newprocess
90
  search_end1:
91
     mov  eax, 14
485 heavyiron 92
     mcall
31 halyavin 93
     sub  ax, 20
97 mario79 94
     mov  [menu_data + y_end],	    ax
31 halyavin 95
     mov  [menu_data + x_start],  5
96
     mov  al, [menu_data + rows]
97
     mov  [menu_data + cur_sel],  al	 ; clear selection
98
     mov  [menu_data + prev_sel], al
99
 
100
     mov  [buffer], 0
101
  thread:
97 mario79 102
     mov  eax, [buffer]      ; identifier
31 halyavin 103
     shl  eax, 4
104
     add  eax, menu_data
105
     mov  edi, eax
106
 
97 mario79 107
     mov  eax, 40	  ; set event mask
108
     mov  ebx, 100111b	       ; mouse + button + key + redraw
485 heavyiron 109
     mcall
31 halyavin 110
 
111
     call draw_window
112
 
113
still:
97 mario79 114
    mov  eax, 23	 ; wait here for event
31 halyavin 115
    mov  ebx, 5
485 heavyiron 116
    mcall
31 halyavin 117
 
97 mario79 118
    test [close_now], 1      ; is close flag set?
31 halyavin 119
    jnz  close
120
 
97 mario79 121
    cmp  eax, 1 	 ; redraw request ?
122
    je	   red
123
    cmp  eax, 2 	 ; key pressed ?
124
    je	   key
125
    cmp  eax, 3 	 ; button in buffer ?
126
    je	   button
127
    cmp  eax, 6 	 ; mouse event ?
128
    je	   mouse
31 halyavin 129
 
130
    cmp  edi, menu_data
97 mario79 131
    je	   still	     ; if main process-ignored
31 halyavin 132
 
133
  movzx  ebx, [edi + parent]	 ; parent id
134
    shl  ebx, 4
97 mario79 135
    add  ebx, menu_data      ; ebx = base of parent info
136
    call backconvert	     ; get my id in al
137
    cmp  al, [ebx + child]    ; if I'm not child of my parent, I shall die :)
31 halyavin 138
    jne  close
139
 
140
    jmp  still
141
 
142
 
97 mario79 143
  red:		       ; redraw
31 halyavin 144
    call draw_window
145
    jmp  still
146
 
147
 
148
  key:
149
;   mov  eax, 2
485 heavyiron 150
    mcall
31 halyavin 151
 
97 mario79 152
    mov  al,  [edi + rows]     ; number of buttons
31 halyavin 153
 
97 mario79 154
    cmp  ah,  178	  ; KEY_UP
31 halyavin 155
    jne  .noup
156
 
157
    mov  ah,  [edi+cur_sel]
158
    mov  [edi+prev_sel], ah
159
    dec  byte [edi+cur_sel]
160
    jnz  redrawbut
161
    mov  [edi+cur_sel], al
162
    jmp  redrawbut
163
 
164
 
165
  .noup:
97 mario79 166
    cmp  ah, 177	 ; KEY_DOWN
31 halyavin 167
    jne  .nodn
168
 
169
    mov  ah, [edi + cur_sel]
170
    mov  [edi + prev_sel], ah
171
    inc  [edi + cur_sel]
172
    cmp  [edi + cur_sel], al
173
    jna  redrawbut
174
    mov  [edi + cur_sel], 1
175
    jmp  redrawbut
176
 
177
  .nodn:
97 mario79 178
    cmp  ah, 13 	 ; ENTER
31 halyavin 179
    jne  .noenter
180
    mov  ah, [edi + cur_sel]
181
    jmp  button1
182
 
183
  .noenter:
97 mario79 184
    cmp  ah, 27 	 ; ESC
31 halyavin 185
    jne  still
186
    jmp  close
187
 
188
;           include "DEBUG.INC"
189
 
97 mario79 190
  button:	      ; BUTTON HANDLER
191
    mov  eax, 17	 ; get id
485 heavyiron 192
    mcall
31 halyavin 193
 
194
  button1:
195
    mov  esi, edi
196
    push edi
197
    mov  edi, [edi + pointer]
198
 
199
; print "hello"
200
    mov  al, [esi + cur_sel]
201
    mov  [esi + prev_sel], al
202
    mov  [esi + cur_sel], ah
203
    pushad
204
    mov edi, esi
205
;    dph eax
206
    call draw_only_needed_buttons
207
    popad
208
 
209
    ; look for the next line  times;  = button_id
210
    push eax
211
  .next_string:
212
    call searchstartstring
213
    dec  ah
214
    jnz  .next_string
215
    pop  eax
216
 
217
    mov  ecx, 40
218
    mov  al, '/'
219
    cld
220
  repne  scasb
97 mario79 221
    test ecx, ecx	  ; if '/' not found
222
    je	   searchexit
31 halyavin 223
 
224
    cmp  [edi], byte '@'     ; check for submenu
97 mario79 225
    je	   runthread
31 halyavin 226
 
227
    dec  edi
97 mario79 228
    push edi		 ; pointer to start of filename
31 halyavin 229
    call searchstartstring   ; search for next string
97 mario79 230
    sub  edi, 2 	 ; to last byte of string
31 halyavin 231
 
232
    mov  ecx, edi
233
    pop  esi
234
    sub  ecx, esi
97 mario79 235
    inc  ecx		 ; length of filename
31 halyavin 236
    mov  edi, fileinfo_start.name
97 mario79 237
    rep  movsb		   ; copy string
238
    mov  byte [edi], 0	       ; store terminator
239
    mov  eax, 70	 ; start program
31 halyavin 240
    mov  ebx, fileinfo_start
485 heavyiron 241
    mcall
97 mario79 242
;    mcall 5,100
243
    or	   [close_now], 1      ; set close flag
31 halyavin 244
    pop  edi
245
    mov  [mousemask], 0
246
    jmp  close
247
 
248
  searchexit:
249
    pop  edi
250
    jmp  still
251
 
252
 
253
  runthread:
254
    inc  edi
255
 
256
    push eax
97 mario79 257
    call get_number	     ; get number of this process
31 halyavin 258
    pop  eax
259
 
97 mario79 260
    test ebx, ebx	   ; returned zero - main menu or not number
261
    jz	   searchexit
31 halyavin 262
 
263
    mov  al, bl
264
 
265
    mov  ebx, [processes]
266
    dec  bl
267
    cmp  al, bl
97 mario79 268
    ja	   searchexit	       ; such process doesnt exist
31 halyavin 269
    cmp  al, [esi + child]
97 mario79 270
    je	   searchexit	       ; such process already exists
31 halyavin 271
 
272
    mov  [esi + child], al    ; this is my child
273
    mov  cx, [esi + x_start]
97 mario79 274
    add  cx, 141	  ; new x_start in cx
31 halyavin 275
  movzx  edx, al
276
    shl  edx, 4
277
    add  edx, menu_data       ; edx points to child's base address
278
    mov  [edx + x_start], cx  ; xstart for new thread
279
    mov  cx,  [esi + y_end]   ; y_end in cx
280
    mov  bl,  [esi + rows]    ; number of buttons in bl
97 mario79 281
    sub  bl,  ah	  ; number of btn from bottom
31 halyavin 282
  movzx  eax, al
97 mario79 283
    mov  [buffer], eax		; thread id in buffer
31 halyavin 284
  movzx  ebx, bl
285
    push edx
286
    mov  eax, BTN_HEIGHT
287
    mul  ebx
97 mario79 288
    sub  cx,  ax	  ; new y_end for new thread
31 halyavin 289
    pop  edx
290
    mov  [edx + y_end], cx    ; store y_end
291
    mov  edi, esi
292
    call backconvert	      ; get number of this process (al)
293
    mov  [edx + parent], al   ; store number of parent process
294
    mov  al, [edx + rows]
295
    mov  [edx + cur_sel], al  ; clear current selected element
296
    mov  [edx + prev_sel], al ; clear previous selected element
297
    mov  [edx + child], 0
298
 
299
    cmp  [thread_stack], 0x1e000
300
    jne  thread_stack_not_full
97 mario79 301
    mov  [thread_stack], 0xE000
31 halyavin 302
 
303
thread_stack_not_full:
304
    add  [thread_stack], 0x2000 ; start new thread
305
    mov  eax, 51
306
    mov  ebx, 1
307
    mov  ecx, thread
308
    mov  edx, [thread_stack]
485 heavyiron 309
    mcall
31 halyavin 310
 
311
    jmp  searchexit
312
 
313
 
97 mario79 314
 mouse: 	      ; MOUSE EVENT HANDLER
31 halyavin 315
    mov  eax, 37
316
    mov  ebx, 2
485 heavyiron 317
    mcall
97 mario79 318
    test eax, eax	   ; check buttons state
31 halyavin 319
    jnz  click
320
    mov  eax, 37
321
    mov  ebx, 1
485 heavyiron 322
    mcall
97 mario79 323
    ror  eax, 16	  ; eax = [ Y | X ] relative to window
324
    cmp  ax,  140	   ; pointer in window?
325
    ja	   noinwindow
31 halyavin 326
;  in window 
327
 
97 mario79 328
    shr  eax, 16	  ; eax = [ 0 | Y ]
31 halyavin 329
    xor  edx, edx
330
    mov  ebx, BTN_HEIGHT
331
    div  ebx
97 mario79 332
    inc  eax		  ; number of "button" in eax
31 halyavin 333
  movzx  ebx, [edi + rows]    ; total strings in ebx
334
    cmp  eax, ebx
97 mario79 335
    ja	   noinwindow
31 halyavin 336
    cmp  [edi + cur_sel], al
97 mario79 337
    je	   noredrawbut
31 halyavin 338
    mov  bl, [edi + cur_sel]
339
 
340
   ;;;;;;
341
    cmp  [edi + child], 0
342
    jne  noredrawbut
343
   ;;;;;;
344
 
345
    mov  [edi + cur_sel], al
346
    mov  [edi + prev_sel], bl
347
  redrawbut:
348
    call draw_only_needed_buttons
349
  noredrawbut:
350
    call backconvert
351
    bts  [mousemask], eax
352
    jmp  still
353
  noinwindow:
354
    call backconvert
355
    btr  [mousemask], eax
356
    jmp  still
357
  click:
358
    cmp  [mousemask], 0  ; not in a window (i.e. menu)
97 mario79 359
    je	   close
31 halyavin 360
    jmp  still
361
 
362
 
363
  close:
97 mario79 364
    or	   eax, -1	  ; close this thread
365
    mov  [edi + child], al    ; my child is not mine
485 heavyiron 366
    mcall
31 halyavin 367
 
368
 
97 mario79 369
  backconvert:		  ; convert from pointer to process id
31 halyavin 370
    mov  eax, edi
371
    sub  eax, menu_data
372
    shr  eax, 4
373
    ret
374
 
375
 
376
;==================================
377
; get_number
378
;    load number from [edi] to ebx
379
;==================================
380
  get_number:
381
    push edi
382
 
383
    xor  eax, eax
384
    xor  ebx, ebx
385
 
386
   .get_next_char:
387
    mov  al, [edi]
388
    inc  edi
389
    cmp  al, '0'
97 mario79 390
    jb	   .finish
31 halyavin 391
    cmp  al, '9'
97 mario79 392
    ja	   .finish
31 halyavin 393
    sub  al, '0'
394
    imul ebx, 10
395
    add  ebx, eax
396
    jmp  .get_next_char
397
 
398
   .finish:
399
    pop  edi
400
    ret
401
 
402
 
403
;   *********************************************
404
;   *******  WINDOW DEFINITIONS AND DRAW ********
405
;   *********************************************
406
 
407
 
408
draw_window:
409
 
97 mario79 410
    mov  eax, 12	   ; function 12:tell os about windowdraw
411
    mov  ebx, 1 	   ; 1, start of draw
485 heavyiron 412
    mcall
31 halyavin 413
 
414
  movzx  ebx, [edi + rows]
97 mario79 415
   imul  eax, ebx, BTN_HEIGHT	    ; eax = height of window
31 halyavin 416
  movzx  ecx, [edi + y_end]
97 mario79 417
    sub  ecx, eax	    ; ecx = Y_START
31 halyavin 418
    shl  ecx, 16
97 mario79 419
    add  ecx, eax	    ; ecx = [ Y_START | Y_SIZE ]
31 halyavin 420
    dec  ecx
421
  movzx  ebx, [edi + x_start]
422
    shl  ebx, 16
97 mario79 423
    mov  bx,  140	    ; ebx = [ X_START | X_SIZE ]
424
    xor  eax, eax	    ; function 0 : define and draw window
425
    mov  edx, 0x01000000       ; color of work area RRGGBB,8->color gl
426
    mov  esi, edx	    ; unmovable window
485 heavyiron 427
    mcall
31 halyavin 428
 
429
    call draw_all_buttons
430
 
431
    mov  eax,12
432
    mov  ebx,2
485 heavyiron 433
    mcall
31 halyavin 434
 
435
    ret
436
 
437
 
438
 draw_all_buttons:
439
    xor  edx, edx
440
  .new_button:
441
    call draw_one_button
442
    inc  edx
443
    cmp  dl, [edi + rows]
97 mario79 444
    jb	   .new_button
31 halyavin 445
 
446
    ret
447
 
448
 
449
 draw_only_needed_buttons:
450
    xor  edx, edx
451
    mov  dl, [edi + cur_sel]
452
    dec  dl
453
    call draw_one_button
454
    mov  dl, [edi + prev_sel]
455
    dec  dl
456
    call draw_one_button
457
    ret
458
 
459
 
460
 draw_one_button:
461
 ; receives number of button in dl
462
    push edx;ad
463
 
464
    mov  eax, 8
465
    mov  ebx, 140
466
  movzx  ecx, dl
467
    imul ecx, BTN_HEIGHT
468
    shl  ecx, 16
469
    add  ecx, BTN_HEIGHT-1
470
;   edx = button identifier
195 heavyiron 471
    mov  esi, [sc.work]
318 heavyiron 472
    cmp  esi, 0xdfdfdf
473
    jb   nocorrect
474
    sub  esi, 0x1b1b1b
475
  nocorrect:
31 halyavin 476
    inc  dl
477
    cmp  [edi + cur_sel], dl
478
    jne  .nohighlight
318 heavyiron 479
    add  esi, 0x1a1a1a
31 halyavin 480
  .nohighlight:
97 mario79 481
    or	   edx, 0x20000000
485 heavyiron 482
    mcall
31 halyavin 483
    movzx edx, dl
484
 
485
    dec  dl
486
    imul ebx, edx, BTN_HEIGHT
487
    add  ebx, (4 shl 16) + TXT_Y
488
 
489
  movzx  ecx, dl
490
    inc  ecx
491
    mov  edx, [edi + pointer]
492
  .findline:
493
    cmp  byte [edx], 13
97 mario79 494
    je	   .linefound
31 halyavin 495
    inc  edx
496
    jmp  .findline
497
  .linefound:
498
    inc  edx
499
    cmp  byte [edx], 10
500
    jne  .findline
501
    dec  ecx
502
    jnz  .findline
503
 
195 heavyiron 504
    mov  ecx, [sc.work_text]
31 halyavin 505
    mov  eax, 4
506
    mov  esi, 21
485 heavyiron 507
    mcall
31 halyavin 508
 
509
    pop  edx;ad
510
    ret
511
 
512
 
513
 searchstartstring:
514
    mov  ecx, 40
515
    mov  al, 13
516
    cld
517
  repne  scasb
518
    cmp  byte [edi], 10
519
    jne  searchstartstring
520
    ret
521
 
522
 
523
;*** DATA AREA ****************************************************************
524
 
97 mario79 525
thread_stack   dd   0xE000
31 halyavin 526
processes      dd   0
527
 
528
fileinfo:
97 mario79 529
 .subfunction	 dd   0 	      ; 0=READ
530
 .start 	 dd   0 	      ; start byte
531
 .size_high	 dd   0 	      ; rezerved
532
 .size		 dd   0x10000-mem_end ; blocks to read
533
 .return	 dd   mem_end	      ; return data pointer
31 halyavin 534
 .name:
535
     db   '/RD/1/MENU.DAT',0   ; ASCIIZ dir & filename
536
 
537
fileinfo_start:
97 mario79 538
 .subfunction	 dd   7 	 ; 7=START APPLICATION
539
 .flags 	 dd   0 	 ; flags
540
 .params	 dd   0x0	 ; nop
541
 .rezerved	 dd   0x0	 ; nop
542
 .rezerved_1	 dd   0x0	 ; nop
31 halyavin 543
 .name:
544
   times 50 db ' '
545
 
546
I_END:
547
 
548
close_now      dd ?   ; close all processes immediately
549
end_pointer    dd ?
97 mario79 550
buffer		 dd ?
31 halyavin 551
mousemask      dd ?   ; mask for mouse pointer location
552
 
553
sc system_colors
554
 
555
menu_data:
556
  rb 0x4000  ;x10000
557
 
558
virtual at 0	      ; PROCESSES TABLE (located at menu_data)
559
  pointer      dd ?   ; +0    pointer in file
97 mario79 560
  rows		 db ?	; +4    numer of strings
31 halyavin 561
  x_start      dw ?   ; +5    x start
562
  y_end        dw ?   ; +7    y end
563
  child        db ?   ; +9    id of child menu
564
  parent       db ?   ; +10   id of parent menu
565
  cur_sel      db ?   ; +11   current selection
566
  prev_sel     db ?   ; +12   previous selection
567
  rb	       16-$+1 ; [16 bytes per element]
568
end virtual
569
 
570
mem_end: