Subversion Repositories Kolibri OS

Rev

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