Subversion Repositories Kolibri OS

Rev

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

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