Subversion Repositories Kolibri OS

Rev

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

  1.  WIN_SIZE equ 120
  2.  TIMER equ 60
  3.  
  4.     use32
  5.     org     0
  6.     db      'MENUET01'
  7.     dd      1, @entry, @end, @memory, @stack, @params, 0
  8.  
  9.     include "../../macros.inc"
  10.     include "../../proc32.inc"
  11.     include "../../dll.inc"
  12. ;    include "../../debug.inc"
  13.     include "macros.inc"
  14.  
  15. ;=====================================================================
  16.  
  17.  @entry:
  18.     mcall   68, 11
  19.     mcall   68, 22, shm_name, 512, 5
  20.     mov     [shm], eax
  21.  
  22.     mcall   9, buffer, -1
  23.     mov     esi, dword[buffer + 30]
  24.     mov     edi, eax
  25.  
  26.   @@:
  27.     mcall   9, buffer, edi
  28.     cmpe    dword[buffer + 30], esi, .next
  29.     cmpe    dword[buffer + 10], dword "@Vol", @open_1
  30.     cmpe    dword[buffer + 10], dword "@VOL", @open_1
  31.     cmpe    dword[buffer + 10], dword "@vol", @open_1
  32.  .next:
  33.     dec     edi
  34.     jnz     @b
  35.  
  36.     mov     eax, [shm]
  37.     mov     [eax], dword 0
  38.     mcall   40, 10b
  39.     mcall   66, 1, 1
  40.     ;mcall   66, 4, 16, 0x110
  41.     mcall   66, 4, 77, 0x110
  42.     mcall   66, 4, 75, 0x110
  43.     mcall   66, 4, 80, 0x110
  44.  
  45.     stdcall dll.Load, @imports
  46.     stdcall dword[img.decode], icons, icons.size, 0
  47.     mov     dword[image.data], eax
  48.     stdcall dword[img.to_rgb], dword[image.data], image
  49.     stdcall dword[img.destroy], dword[image.data]
  50.  
  51.  ; load driver
  52.     mcall   68, 16, snd_driver.name
  53.     mov     [snd_driver], eax
  54.     cmpe    eax, 0, exit
  55.  
  56.  @update:
  57.     mcall   23, 5
  58.     cmpe    al, EV_KEY, @key
  59.     mov     eax, [shm]
  60.     cmpne   [eax], dword 0, @open_2
  61.     jmp     @update
  62.  
  63.  @open_1:
  64.     mov     ebx, 1
  65.     cmpne   [@params], byte '+', @f
  66.     mov     ebx, 2
  67.   @@:
  68.     cmpne   [@params], byte '-', @f
  69.     mov     ebx, 3
  70.   @@:
  71.     cmpne   [@params], byte 'm', @f
  72.     mov     ebx, 4
  73.   @@:
  74.     cmpne   [@params], byte 's', @f
  75.     mov     ebx, 5
  76.   @@:
  77.     mov     eax, [shm]
  78.     mov     [eax], ebx
  79.     jmp     @exit
  80.  
  81.  @open_2:
  82.     mov     eax, [shm]
  83.     mov     ebx, [eax]
  84.     mov     [command], ebx
  85.     mov     [eax], dword 0
  86.     cmpne   [win.pid], dword 0, @update
  87.     mcall   51, 1, _entry, _stack
  88.     jmp     @update
  89.  
  90.  @key:
  91.     mcall   2
  92.     ;cmpe    ah, 16, @exit
  93.     mov     edx, [shm]
  94.     cmpne   ah, 77, @f
  95.  .cm_1:
  96.     cmpne   [win.pid], 0, .else_1
  97.     mov     [edx], dword 2
  98.     jmp     @open_2
  99.  .else_1:
  100.     mov     [command], 2
  101.   @@:
  102.     cmpne   ah, 75, @f
  103.  .cm_2:
  104.     cmpne   [win.pid], 0, .else_2
  105.     mov     [edx], dword 3
  106.     jmp     @open_2
  107.  .else_2:
  108.     mov     [command], 3
  109.   @@:
  110.     cmpne   ah, 80, @f
  111.  .cm_3:
  112.     mov     [edx], dword 4
  113.     jmp     @open_2
  114.   @@:
  115.     jmp     @update
  116.  
  117.  @exit:
  118.     mcall   -1
  119.  
  120. ;=====================================================================
  121.  
  122.  _entry:
  123.     mcall   40, 100111b
  124.  
  125.     mcall   9, buffer, -1
  126.     mov     ecx, eax
  127.     mov     edx, dword [buffer + 30]
  128.     mov     [win.pid], edx
  129.  
  130.     mcall   14
  131.     movzx   ebx, ax
  132.     shr     eax, 17
  133.     shr     ebx, 1
  134.     sub     eax, WIN_SIZE / 2
  135.     sub     ebx, WIN_SIZE / 2
  136.     mov     [win.x], eax
  137.     mov     [win.y], ebx
  138.  
  139.     mcall   70, is_load
  140.     cmpe    eax, 0, @f
  141.     mov     dword[volume], 5
  142.   @@:
  143.     mov     dword[timer], TIMER
  144.  
  145.     jmp     set_sound
  146.  
  147.  ;----------------------------
  148.  
  149.  _update:
  150.     mcall   23, 5
  151.     cmpe    al, EV_REDRAW, _redraw
  152.     cmpe    al, EV_KEY, _key
  153.     cmpe    al, EV_BUTTON, _button
  154.     cmpe    al, EV_MOUSE, _mouse
  155.  
  156.     cmpne   [command], 2, @f
  157.     mov     [mute], 0
  158.     cmpe    [volume], dword 10, @f
  159.     inc     dword[volume]
  160.     jmp     .apply
  161.   @@:
  162.     cmpne   [command], 3, @f
  163.     mov     [mute], 0
  164.     cmpe    [volume], dword 0, @f
  165.     dec     dword[volume]
  166.     jmp     .apply
  167.   @@:
  168.     cmpne   [command], 4, @f
  169.     mov     [mute], 1
  170.     jmp     .apply
  171.   @@:
  172.     cmpne   [command], 5, @f
  173.     mov     [mute], 0
  174.     jmp     .apply
  175.  
  176.  .apply:
  177.     mov     [command], 0
  178.     jmp     set_sound
  179.   @@:
  180.  
  181.     mcall   18, 7
  182.     mov     ecx, eax
  183.     mcall   9, buffer
  184.     mov     eax, dword[buffer + 30]
  185.     cmpne   [win.pid], eax, exit
  186.  
  187.     dec     dword[timer]
  188.     jnz     _update
  189.  
  190.  ;----------------------------
  191.  
  192.  exit:
  193.     mov     [win.pid], 0
  194.     mcall   70, is_save
  195.     mcall   -1
  196.  
  197.  ;----------------------------
  198.  
  199.  _button:
  200.     mcall   17
  201.     cmpe    ah, 1, exit
  202.     cmpe    ah, 3, toggle_mute
  203.     jmp     _update
  204.  
  205.  ;----------------------------
  206.  
  207.  _key:
  208.     mcall   2
  209.     cmpe    ah, 027, exit
  210.     cmpe    ah, 176, dec_volume ; <-
  211.     cmpe    ah, 183, dec_volume ; PgDown
  212.     cmpe    ah, 179, inc_volume ; ->
  213.     cmpe    ah, 184, inc_volume ; PgUp
  214.     cmpe    ah, 178, unmute_volume ; ^
  215.     cmpe    ah, 180, unmute_volume ; Home
  216.     cmpe    ah, 177, mute_volume ; v
  217.     cmpe    ah, 181, mute_volume ; End
  218.  
  219.     jmp     _update
  220.  
  221.  ;----------------------------
  222.  
  223.  _mouse:
  224.     mcall   37, 7
  225.     cmpe    eax, 0, _update
  226.  
  227.     mov     esi, eax
  228.     mcall   37, 1
  229.     movzx   ebx, ax
  230.     shr     eax, 16
  231.     cmpg    eax, WIN_SIZE, _update
  232.     cmpg    ebx, WIN_SIZE, _update
  233.  
  234.     cmpe    si, 1,  dec_volume
  235.     jne     inc_volume
  236.  
  237.  ;----------------------------
  238.  
  239.  dec_volume:
  240.     cmpe    dword[volume], 0, _update
  241.     dec     dword[volume]
  242.     jmp     unmute_volume
  243.  
  244.  inc_volume:
  245.     cmpe    dword[volume], 10, _update
  246.     inc     dword[volume]
  247.  
  248.  unmute_volume:
  249.     mov     [mute], 0
  250.     jmp     @f
  251.  
  252.  toggle_mute:
  253.     mov     eax, 1
  254.     sub     eax, [mute]
  255.     mov     [mute], eax
  256.     jmp     @f
  257.  
  258.  mute_volume:
  259.     mov     [mute], 1
  260.  
  261.  set_sound:
  262.   @@:
  263.     mov     [snd_driver.command], 6
  264.     mov     [snd_driver.inputsz], 4
  265.     mov     [snd_driver.output], 0
  266.     mov     [snd_driver.outputsz], 0
  267.     mov     [snd_driver.input], buffer
  268.     mov     edi, 10
  269.     cmpe    [mute], 1, .set_sound
  270.     sub     edi, [volume]
  271.   .set_sound:
  272.     imul    edi, 479
  273.     neg     edi
  274.     mov     dword[buffer], edi
  275.     mcall   68, 17, snd_driver
  276.  
  277.     mov     dword[timer], TIMER
  278.     call    draw_icon
  279.     call    draw_bar
  280.     jmp     _update
  281.  
  282.  ;----------------------------
  283.  
  284.  _redraw:
  285.     call    draw_window
  286.     call    draw_icon
  287.     call    draw_bar
  288.  
  289.     jmp     _update
  290.  
  291.  ;----------------------------
  292.  
  293.  draw_window:
  294.     mcall   0, <[win.x], WIN_SIZE + 1>, <[win.y], WIN_SIZE + 1>, 0x61000000
  295.  
  296.     mcall   13, <0, WIN_SIZE>, <1, WIN_SIZE - 2>, 0x3D3D3D
  297.     mcall     , <1, WIN_SIZE - 2>, <0, 1>
  298.     mcall     ,                  , <WIN_SIZE - 1, 1>
  299.  
  300.     mcall   8, <0, WIN_SIZE>, <0, WIN_SIZE>, 0x60000002
  301.     mcall    , <20, 80>, <22, 60>, 0x60000003
  302.  
  303.     ret
  304.  
  305.  ;----------------------------
  306.  
  307.  draw_icon:
  308.     mcall   7, image, <30, 45>, <31, 30>
  309.  
  310.     cmpe    dword[mute], 0, @f
  311.     mov     ebx, 30 * 45 * 3 * 5 + image
  312.     jmp     .draw
  313.   @@:
  314.     cmpne   dword[volume], 0, @f
  315.     mov     ebx, 30 * 45 * 3 * 1 + image
  316.     jmp     .draw
  317.   @@:
  318.     cmpge  dword[volume], 5, @f
  319.     mov     ebx, 30 * 45 * 3 * 2 + image
  320.     jmp     .draw
  321.   @@:
  322.     cmpge  dword[volume], 9, @f
  323.     mov     ebx, 30 * 45 * 3 * 3 + image
  324.     jmp     .draw
  325.   @@:
  326.     mov     ebx, 30 * 45 * 3 * 4 + image
  327.  .draw:
  328.     mcall    ,      ,         , <61, 30>
  329.  
  330.     ret
  331.  
  332.  ;----------------------------
  333.  
  334.  draw_bar:
  335.  ;; draw shadow
  336.     mov     eax, 13
  337.     mov     ebx, 11 shl 16 + 9
  338.     mov     ecx, 100 shl 16 + 1
  339.     mov     edx, 0x252525
  340.     mov     esi, 10
  341.   @@:
  342.     cmpe    esi, 0, @f
  343.     mcall
  344.     add     ebx, 10 shl 16
  345.     dec     esi
  346.     jmp     @b
  347.   @@:
  348.  
  349.  ;; draw active
  350.     mov     ebx, 11 shl 16 + 9
  351.     mov     ecx, 96 shl 16 + 4
  352.     mov     edx, 0xE5E5E5
  353.     mov     esi, [volume]
  354.   @@:
  355.     cmpe    esi, 0, @f
  356.     mcall
  357.     add     ebx, 10 shl 16
  358.     dec     esi
  359.     jmp     @b
  360.   @@:
  361.  
  362.  ;; draw inactive
  363.     mov     ebx, 11 shl 16 + 9
  364.     mov     edx, 0x737373
  365.     mov     esi, 10
  366.     sub     esi, [volume]
  367.     imul    edi, [volume], 10
  368.     shl     edi, 16
  369.     add     ebx, edi
  370.   @@:
  371.     cmpe    esi, 0, @f
  372.     mcall
  373.     add     ebx, 10 shl 16
  374.     dec     esi
  375.     jmp     @b
  376.   @@:
  377.  
  378.     ret
  379.  
  380.  ;----------------------------
  381.  
  382.  @imports:
  383.     library img, "libimg.obj"
  384.     import  img, \
  385.         img.init,    "lib_init", \
  386.         img.to_rgb,  "img_to_rgb2", \
  387.         img.decode,  "img_decode", \
  388.         img.destroy, "img_destroy"
  389.  
  390.  ;----------------------------
  391.  
  392.  volume_dat db "/sys/settings/volume.dat", 0
  393.  
  394.  is_save:
  395.             dd 2
  396.             dd 0
  397.             dd 0
  398.             dd 8
  399.             dd volume
  400.             db 0
  401.             dd volume_dat
  402.  
  403.  is_load:
  404.             dd 0
  405.             dd 0
  406.             dd 0
  407.             dd 8
  408.             dd volume
  409.             db 0
  410.             dd volume_dat
  411.  
  412.  icons      file "icon.png"
  413.   .size     = $-icons
  414.  snd_driver.name:
  415.             db "SOUND", 0
  416.  shm_name   db "volume-man", 0
  417.  
  418.  @end:
  419.  
  420. ;=====================================================================
  421.  
  422.  win:
  423.   .x        rd 1
  424.   .y        rd 1
  425.   .pid      rd 1
  426.  
  427.  image      rb 45 * 30 * 6 * 3
  428.   .data     rd 1
  429.  
  430.  shm        rd 1
  431.  volume     rd 1
  432.  timer      rd 1
  433.  mute       rd 1
  434.  command    rd 1
  435.  buffer     rb 1024
  436.  snd_driver rd 1
  437.   .command  rd 1
  438.   .input    rd 1
  439.   .inputsz  rd 1
  440.   .output   rd 1
  441.   .outputsz rd 1
  442.  
  443. ;=====================================================================
  444.             rb 2048
  445.  _stack:
  446.             rb 2048
  447.  @stack:
  448.  @params    rb 256
  449.  
  450.  @memory:
  451.