Subversion Repositories Kolibri OS

Rev

Rev 5432 | Rev 5458 | 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
5446 eAndrew 235
    cmpe    ah, 177, toggle_mute ; v
236
    cmpe    ah, 181, toggle_mute ; End
5432 eAndrew 237
 
238
    jmp     _update
239
 
240
 ;----------------------------
241
 
242
 _mouse:
243
    mcall   37, 7
244
    cmpe    eax, 0, _update
245
 
246
    mov     esi, eax
247
    mcall   37, 1
248
    movzx   ebx, ax
249
    shr     eax, 16
250
    cmpg    eax, WIN_SIZE, _update
251
    cmpg    ebx, WIN_SIZE, _update
252
 
253
    cmpe    si, 1,  dec_volume
254
    jne     inc_volume
255
 
256
 ;----------------------------
257
 
258
 dec_volume:
259
    cmpe    dword[volume], 0, _update
260
    dec     dword[volume]
261
    jmp     unmute_volume
262
 
263
 inc_volume:
264
    cmpe    dword[volume], 10, _update
265
    inc     dword[volume]
5446 eAndrew 266
    jmp     unmute_volume
5432 eAndrew 267
 
268
 toggle_mute:
269
    mov     eax, 1
270
    sub     eax, [mute]
271
    mov     [mute], eax
272
    jmp     @f
273
 
5446 eAndrew 274
 unmute_volume:
275
    mov     dword[mute], 0
5432 eAndrew 276
 
277
 set_sound:
278
  @@:
5446 eAndrew 279
    call    set_sound_proc
280
    mov     dword[timer], TIMER
281
    call    draw_icon
282
    call    draw_bar
283
    jmp     _update
284
 
285
 set_sound_proc:
5432 eAndrew 286
    mov     [snd_driver.command], 6
287
    mov     [snd_driver.inputsz], 4
288
    mov     [snd_driver.output], 0
289
    mov     [snd_driver.outputsz], 0
290
    mov     [snd_driver.input], buffer
291
    mov     edi, 10
292
    cmpe    [mute], 1, .set_sound
293
    sub     edi, [volume]
294
  .set_sound:
295
    imul    edi, 479
296
    neg     edi
297
    mov     dword[buffer], edi
298
    mcall   68, 17, snd_driver
5446 eAndrew 299
    ret
5432 eAndrew 300
 
301
 ;----------------------------
302
 
303
 _redraw:
304
    call    draw_window
305
    call    draw_icon
306
    call    draw_bar
307
 
308
    jmp     _update
309
 
310
 ;----------------------------
311
 
312
 draw_window:
313
    mcall   0, <[win.x], WIN_SIZE + 1>, <[win.y], WIN_SIZE + 1>, 0x61000000
314
 
315
    mcall   13, <0, WIN_SIZE>, <1, WIN_SIZE - 2>, 0x3D3D3D
316
    mcall     , <1, WIN_SIZE - 2>, <0, 1>
317
    mcall     , 		 , 
318
 
319
    mcall   8, <0, WIN_SIZE>, <0, WIN_SIZE>, 0x60000002
320
    mcall    , <20, 80>, <22, 60>, 0x60000003
321
 
322
    ret
323
 
324
 ;----------------------------
325
 
326
 draw_icon:
327
    mcall   7, image, <30, 45>, <31, 30>
328
 
329
    cmpe    dword[mute], 0, @f
330
    mov     ebx, 30 * 45 * 3 * 5 + image
331
    jmp     .draw
332
  @@:
333
    cmpne   dword[volume], 0, @f
334
    mov     ebx, 30 * 45 * 3 * 1 + image
335
    jmp     .draw
336
  @@:
337
    cmpge  dword[volume], 5, @f
338
    mov     ebx, 30 * 45 * 3 * 2 + image
339
    jmp     .draw
340
  @@:
341
    cmpge  dword[volume], 9, @f
342
    mov     ebx, 30 * 45 * 3 * 3 + image
343
    jmp     .draw
344
  @@:
345
    mov     ebx, 30 * 45 * 3 * 4 + image
346
 .draw:
347
    mcall    ,	    ,	      , <61, 30>
348
 
349
    ret
350
 
351
 ;----------------------------
352
 
353
 draw_bar:
354
 ;; draw shadow
355
    mov     eax, 13
356
    mov     ebx, 11 shl 16 + 9
357
    mov     ecx, 100 shl 16 + 1
358
    mov     edx, 0x252525
359
    mov     esi, 10
360
  @@:
361
    cmpe    esi, 0, @f
362
    mcall
363
    add     ebx, 10 shl 16
364
    dec     esi
365
    jmp     @b
366
  @@:
367
 
368
 ;; draw active
369
    mov     ebx, 11 shl 16 + 9
370
    mov     ecx, 96 shl 16 + 4
371
    mov     edx, 0xE5E5E5
372
    mov     esi, [volume]
373
  @@:
374
    cmpe    esi, 0, @f
375
    mcall
376
    add     ebx, 10 shl 16
377
    dec     esi
378
    jmp     @b
379
  @@:
380
 
381
 ;; draw inactive
382
    mov     ebx, 11 shl 16 + 9
383
    mov     edx, 0x737373
384
    mov     esi, 10
385
    sub     esi, [volume]
386
    imul    edi, [volume], 10
387
    shl     edi, 16
388
    add     ebx, edi
389
  @@:
390
    cmpe    esi, 0, @f
391
    mcall
392
    add     ebx, 10 shl 16
393
    dec     esi
394
    jmp     @b
395
  @@:
396
 
397
    ret
398
 
399
 ;----------------------------
400
 
401
 @imports:
402
    library img, "libimg.obj"
403
    import  img, \
404
	img.init,    "lib_init", \
405
	img.to_rgb,  "img_to_rgb2", \
406
	img.decode,  "img_decode", \
407
	img.destroy, "img_destroy"
408
 
409
 ;----------------------------
410
 
411
 volume_dat db "/sys/settings/volume.dat", 0
412
 
413
 is_save:
414
	    dd 2
415
	    dd 0
416
	    dd 0
417
	    dd 8
418
	    dd volume
419
	    db 0
420
	    dd volume_dat
421
 
422
 is_load:
423
	    dd 0
424
	    dd 0
425
	    dd 0
426
	    dd 8
427
	    dd volume
428
	    db 0
429
	    dd volume_dat
430
 
431
 icons	    file "icon.png"
432
  .size     = $-icons
433
 snd_driver.name:
434
	    db "SOUND", 0
435
 shm_name   db "volume-man", 0
436
 
437
 @end:
438
 
439
;=====================================================================
440
 
441
 win:
442
  .x	    rd 1
443
  .y	    rd 1
444
  .pid	    rd 1
445
 
446
 image	    rb 45 * 30 * 6 * 3
447
  .data     rd 1
448
 
449
 shm	    rd 1
450
 volume     rd 1
451
 timer	    rd 1
452
 mute	    rd 1
453
 command    rd 1
454
 buffer     rb 1024
455
 snd_driver rd 1
456
  .command  rd 1
457
  .input    rd 1
458
  .inputsz  rd 1
459
  .output   rd 1
460
  .outputsz rd 1
461
 
462
;=====================================================================
463
	    rb 2048
464
 _stack:
465
	    rb 2048
466
 @stack:
467
 @params    rb 256
468
 
469
 @memory: