Subversion Repositories Kolibri OS

Rev

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

  1. ;******************************************************************************
  2. ;   MAIN MENU by lisovin@26.ru
  3. ;   Some parts of code rewritten by Ivan Poddubny <ivan-yar@bk.ru>
  4. ;
  5. ;   Compile with FASM for Menuet
  6. ;******************************************************************************
  7.   include "lang.inc"
  8.   include "..\..\..\macros.inc"
  9.  
  10.   BTN_HEIGHT  = 22
  11.   TXT_Y       = (BTN_HEIGHT)/2-5
  12.  
  13.   use32
  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
  22. ;******************************************************************************
  23. ;include "DEBUG.INC"             ; debug macros
  24. START:                 ; start of execution
  25.  
  26.      mov  eax, 48         ; load system colors
  27.      mov  ebx, 3
  28.      mov  ecx, sc
  29.      mov  edx, sizeof.system_colors
  30.      mcall
  31.  
  32.      mov  eax, 70         ; load MENU.DAT
  33.      mov  ebx, fileinfo
  34.      mcall
  35.      test eax, eax         ; error ?
  36.      jz  @f
  37.      cmp  eax,6
  38.      jnz  close
  39.   @@:
  40.      test ebx, ebx         ; length = 0 ?
  41.      jz   close
  42.      mov  ecx, ebx
  43.      mov  edi, mem_end
  44.   newsearch:
  45.      mov  al, '#'
  46.      cld
  47.      repne scasb
  48.      test ecx, ecx         ; if not found
  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
  57.      add  ebx, menu_data     ; pointer to process table
  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
  92.      mcall
  93.      sub  ax, 20
  94.      mov  [menu_data + y_end],      ax
  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:
  102.      mov  eax, [buffer]      ; identifier
  103.      shl  eax, 4
  104.      add  eax, menu_data
  105.      mov  edi, eax
  106.  
  107.      mov  eax, 40         ; set event mask
  108.      mov  ebx, 100111b         ; mouse + button + key + redraw
  109.      mcall
  110.  
  111.      call draw_window
  112.  
  113. still:
  114.     mov  eax, 23         ; wait here for event
  115.     mov  ebx, 5
  116.     mcall
  117.  
  118.     test [close_now], 1      ; is close flag set?
  119.     jnz  close
  120.  
  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
  129.  
  130.     cmp  edi, menu_data
  131.     je     still             ; if main process-ignored
  132.  
  133.   movzx  ebx, [edi + parent]     ; parent id
  134.     shl  ebx, 4
  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 :)
  138.     jne  close
  139.  
  140.     jmp  still
  141.  
  142.  
  143.   red:                 ; redraw
  144.     call draw_window
  145.     jmp  still
  146.  
  147.  
  148.   key:
  149. ;   mov  eax, 2
  150.     mcall
  151.  
  152.     mov  al,  [edi + rows]     ; number of buttons
  153.  
  154.     cmp  ah,  178         ; KEY_UP
  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:
  166.     cmp  ah, 177         ; KEY_DOWN
  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:
  178.     cmp  ah, 13          ; ENTER
  179.     jne  .noenter
  180.     mov  ah, [edi + cur_sel]
  181.     jmp  button1
  182.  
  183.   .noenter:
  184.     cmp  ah, 27          ; ESC
  185.     jne  still
  186.     jmp  close
  187.  
  188. ;           include "DEBUG.INC"
  189.  
  190.   button:             ; BUTTON HANDLER
  191.     mov  eax, 17         ; get id
  192.     mcall
  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 <ah> times; <ah> = 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
  221.     test ecx, ecx         ; if '/' not found
  222.     je     searchexit
  223.  
  224.     cmp  [edi], byte '@'     ; check for submenu
  225.     je     runthread
  226.  
  227.     dec  edi
  228.     push edi             ; pointer to start of filename
  229.     call searchstartstring   ; search for next string
  230.     sub  edi, 2          ; to last byte of string
  231.  
  232.     mov  ecx, edi
  233.     pop  esi
  234.     sub  ecx, esi
  235.     inc  ecx             ; length of filename
  236.     mov  edi, fileinfo_start.name
  237.     rep  movsb             ; copy string
  238.     mov  byte [edi], 0         ; store terminator
  239.     mov  eax, 70         ; start program
  240.     mov  ebx, fileinfo_start
  241.     mcall
  242. ;    mcall 5,100
  243.     or     [close_now], 1      ; set close flag
  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
  257.     call get_number          ; get number of this process
  258.     pop  eax
  259.  
  260.     test ebx, ebx          ; returned zero - main menu or not number
  261.     jz     searchexit
  262.  
  263.     mov  al, bl
  264.  
  265.     mov  ebx, [processes]
  266.     dec  bl
  267.     cmp  al, bl
  268.     ja     searchexit          ; such process doesnt exist
  269.     cmp  al, [esi + child]
  270.     je     searchexit          ; such process already exists
  271.  
  272.     mov  [esi + child], al    ; this is my child
  273.     mov  cx, [esi + x_start]
  274.     add  cx, 141          ; new x_start in cx
  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
  281.     sub  bl,  ah          ; number of btn from bottom
  282.   movzx  eax, al
  283.     mov  [buffer], eax          ; thread id in buffer
  284.   movzx  ebx, bl
  285.     push edx
  286.     mov  eax, BTN_HEIGHT
  287.     mul  ebx
  288.     sub  cx,  ax          ; new y_end for new thread
  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
  301.     mov  [thread_stack], 0xE000
  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]
  309.     mcall
  310.  
  311.     jmp  searchexit
  312.  
  313.  
  314.  mouse:               ; MOUSE EVENT HANDLER
  315.     mov  eax, 37
  316.     mov  ebx, 2
  317.     mcall
  318.     test eax, eax          ; check buttons state
  319.     jnz  click
  320.     mov  eax, 37
  321.     mov  ebx, 1
  322.     mcall
  323.     ror  eax, 16          ; eax = [ Y | X ] relative to window
  324.     cmp  ax,  140          ; pointer in window?
  325.     ja     noinwindow
  326. ;  in window 
  327.  
  328.     shr  eax, 16          ; eax = [ 0 | Y ]
  329.     xor  edx, edx
  330.     mov  ebx, BTN_HEIGHT
  331.     div  ebx
  332.     inc  eax              ; number of "button" in eax
  333.   movzx  ebx, [edi + rows]    ; total strings in ebx
  334.     cmp  eax, ebx
  335.     ja     noinwindow
  336.     cmp  [edi + cur_sel], al
  337.     je     noredrawbut
  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)
  359.     je     close
  360.     jmp  still
  361.  
  362.  
  363.   close:
  364.     or     eax, -1        ; close this thread
  365.     mov  [edi + child], al    ; my child is not mine
  366.     mcall
  367.  
  368.  
  369.   backconvert:            ; convert from pointer to process id
  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'
  390.     jb     .finish
  391.     cmp  al, '9'
  392.     ja     .finish
  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.  
  410.     mov  eax, 12           ; function 12:tell os about windowdraw
  411.     mov  ebx, 1            ; 1, start of draw
  412.     mcall
  413.  
  414.   movzx  ebx, [edi + rows]
  415.    imul  eax, ebx, BTN_HEIGHT       ; eax = height of window
  416.   movzx  ecx, [edi + y_end]
  417.     sub  ecx, eax           ; ecx = Y_START
  418.     shl  ecx, 16
  419.     add  ecx, eax           ; ecx = [ Y_START | Y_SIZE ]
  420.     dec  ecx
  421.   movzx  ebx, [edi + x_start]
  422.     shl  ebx, 16
  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
  427.     mcall
  428.  
  429.     call draw_all_buttons
  430.  
  431.     mov  eax,12
  432.     mov  ebx,2
  433.     mcall
  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]
  444.     jb     .new_button
  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
  471.     mov  esi, [sc.work]
  472.     cmp  esi, 0xdfdfdf
  473.     jb   nocorrect
  474.     sub  esi, 0x1b1b1b
  475.   nocorrect:
  476.     inc  dl
  477.     cmp  [edi + cur_sel], dl
  478.     jne  .nohighlight
  479.     add  esi, 0x1a1a1a
  480.   .nohighlight:
  481.     or     edx, 0x20000000
  482.     mcall
  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
  494.     je     .linefound
  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.  
  504.     mov  ecx, [sc.work_text]
  505.     mov  eax, 4
  506.     mov  esi, 21
  507.     mcall
  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.  
  525. thread_stack   dd   0xE000
  526. processes      dd   0
  527.  
  528. fileinfo:
  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
  534.  .name:
  535.      db   '/RD/1/MENU.DAT',0   ; ASCIIZ dir & filename
  536.  
  537. fileinfo_start:
  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
  543.  .name:
  544.    times 50 db ' '
  545.  
  546. I_END:
  547.  
  548. close_now      dd ?   ; close all processes immediately
  549. end_pointer    dd ?
  550. buffer           dd ?
  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
  560.   rows           db ?   ; +4    numer of strings
  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:
  571.