Subversion Repositories Kolibri OS

Rev

Rev 3749 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3749 GerdtR 1
;
2
;   KolibriOS system mixer. Version 0.2
3
;
4
;   Author:         Asper
5
;   Date of issue:  15.08.2010
6
;   Compiler:       FASM
7
;   Target:         KolibriOS
8
;
9
 
10
use32
11
        org     0x0
12
 
13
        db      'MENUET01'      ; 8 byte id
14
        dd      38              ; required os
15
        dd      STARTAPP        ; program start
16
        dd      I_END           ; program image size
17
        dd      I_MEM           ; required amount of memory
18
        dd      I_MEM           ; stack heap
19
        dd      0x0, 0x0
20
 
5098 clevermous 21
include 'aspapi.INC'
3749 GerdtR 22
include '../../macros.inc'
23
;include 'string.inc'
24
 
25
 
26
;include 'debug.inc'
27
 
28
DEBUG    equ 0 ;1
29
 
30
SRV_GETVERSION        equ  0
31
DEV_PLAY              equ  1
32
DEV_STOP              equ  2
33
DEV_CALLBACK          equ  3
34
DEV_SET_BUFF          equ  4
35
DEV_NOTIFY            equ  5
36
DEV_SET_MASTERVOL     equ  6
37
DEV_GET_MASTERVOL     equ  7
38
DEV_GET_INFO          equ  8
39
 
40
 
41
;C_UNKNOWN     equ ?
42
C_BLACK        equ 0x000000
43
C_GREY         equ 0xB0B0B0    ; 0xC0C0C0
44
C_BLUE         equ 0x1070D0
45
C_GREEN        equ 0x70D010
46
C_RED          equ 0xD01010
47
C_ORANGE       equ 0xD07010
48
C_YELLOW       equ 0xE0E010
49
C_PURPLE       equ 0x7010D0
50
C_PINK         equ 0xFF00FF
51
;C_RESERVED     equ ?
52
C_WHITE        equ 0xFFFFFF
53
;C_OTHER        equ ?
54
 
55
 
56
C_KEYCOLOR1   equ 0x0050D250 ; Control button color 1
57
C_KEYCOLOR2   equ 0x00CBE1E1 ; Control button color 2
58
C_TEXTCOLOR   equ 0x80000000 ; Button caption color
59
BUT_W         equ 20
60
BUT_H         equ 20
61
;WIN_X         equ 30000 ; I hope nobody has screen
62
;WIN_Y         equ 30000 ; with such a big resolution :)
63
WIN_W         equ 250;390
64
WIN_H         equ 180
65
WIN_COLOR     equ 0x505050 ;0x0099BB
66
WIN_X_CENTER  equ WIN_W/2
67
 
68
FIRST_CTRL_BUTTON_ID  equ 7
69
MAX_CONTROLS_NUM equ 15 ;  Bad bounding :/
70
 
71
struc CONTROL
72
{
73
  .level dw ?
74
  .num_steps dw ?
75
}
76
 
77
; widget node for parsing
78
;struc HDA_GNODE
79
;{
80
;  .nid                dw ?    ;NID of this widget
81
;  .nconns             dw ?    ;number of input connections
82
;  .conn_list          dd ?
83
;  .slist              dw ?    ;temporay list
84
;                      dw ?
85
;
86
;  .wid_caps           dd ?    ;widget capabilities
87
;  .type               db ?    ;widget type
88
;  .pin_ctl            db ?    ;pin controls
89
;  .checked            db ?    ;the flag indicates that the node is already parsed
90
;  .pin_caps           dd ?    ;pin widget capabilities
91
;  .def_cfg            dd ?    ;default configuration
92
;  .amp_out_caps       dd ?    ;AMP out capabilities
93
;  .amp_in_caps        dd ?    ;AMP in capabilities
94
;  .next               dd ? ;        struct list_head list
95
;  .sizeof:
96
;}
97
 
98
;virtual at 0
99
;  HDA_GNODE  HDA_GNODE
100
;end virtual
101
 
102
STARTAPP:
103
        ; Initialize memory
104
;        mcall   68, 11
105
;        or      eax,eax
106
;        jz      close_app
107
 
108
 
109
        ; Load sound system driver
110
        mov     eax, 68
111
        mov     ebx, 16
112
        mov     ecx, drivername
113
        int     0x40
114
        mov     [hDriver], eax
115
        test    eax, eax
116
        jnz     @f
117
loaderr:
118
        if DEBUG
119
                print   "Can't load driver"
120
        end if
121
        jmp     close_app
122
  @@:
123
        mov     [is_hda], 1
124
        call    GetDriverVer
125
        mov     eax, [driver_ver]
126
        cmp     ax, 0x11DA
127
        je      @f
128
        mov     [is_hda], 0
129
  @@:
130
        cmp     [is_hda], 0
131
        je      .init_ac97_controls
132
        ; Init volume controls
133
        stdcall GetMasterVol, 0
134
        mov     ebx, eax
135
        mov     [LVolume.level], ax
136
        shr     eax, 16
137
        mov     [LVolume.num_steps], ax
138
        stdcall GetMasterVol, 1
139
        mov     [RVolume.level], ax
140
        shr     eax, 16
141
        mov     [RVolume.num_steps], ax
142
        jmp     .controls_init_complete
143
        ; Asper: temporary workaround on ac97 codecs [
144
  .init_ac97_controls:        ;jmp     @f
145
        mov     [is_hda], 0
146
        mov     [LVolume.num_steps], 31
147
        mov     [RVolume.num_steps], 31
148
        mov     ax, [LVolume.level]
149
        call    convert_ac97_volume_to_level
150
        mov     [LVolume.level], ax
151
        mov     [RVolume.level], ax
152
        ; Asper: temporary workaround on ac97 codecs ]
153
  .controls_init_complete:
154
        if DEBUG
155
                print   "Left level"
156
                movzx   eax, [LVolume.level]
157
                dph     eax
158
                newline
159
                print   "Left num_steps"
160
                movzx   eax, [LVolume.num_steps]
161
                dph     eax
162
                newline
163
                print   "Right level"
164
                movzx   eax, [RVolume.level]
165
                dph     eax
166
                newline
167
                print   "Right num_steps"
168
                movzx   eax, [RVolume.num_steps]
169
                dph     eax
170
                newline
171
        end if
172
 
173
        mcall   66, 1, 1  ; Set keyboard mode to get scancodes.
174
 
175
        mcall   37,0
176
        mov     cx,ax
177
        shl     ecx,16
178
        mov     cx,WIN_H
179
        mov     ebx,eax
180
        mov     bx,WIN_W
181
 
182
red:
183
        call    draw_window
184
 
185
still:
186
        mcall   10               ; Wait for an event in the queue.
187
 
188
        cmp     al,1                  ; redraw request ?
189
        jz      red
190
        cmp     al,2                  ; key in buffer ?
191
        jz      key
192
        cmp     al,3                  ; button in buffer ?
193
        jz      button
194
 
195
        jmp     still
196
 
197
key:
198
        mcall   2
199
 
200
        cmp     ah, 1 ;Esc
201
        je      close_app
202
 
203
;        cmp     ah, 5  ; '4'
204
;        jne     @f
205
;        stdcall GetMasterVol, 0
206
;        jmp     still
207
;       @@:
208
;
209
;        cmp     ah, 6  ; '5'
210
;        jne     @f
211
;        stdcall GetMasterVol, 1
212
;        jmp     still
213
;       @@:
214
 
215
;        cmp     ah, 8  ; '7'
216
;        jne     @f
217
;        call    GetDriverVer
218
;        jmp     still
219
;       @@:
220
 
221
        ;Left channel Up
222
        cmp     ah, 71  ; 'Home'
223
        jne     @f
224
        movzx   eax, [LVolume.level]
225
        inc     ax
226
        cmp     ax, [LVolume.num_steps]
227
        jg      still
228
        mov     [LVolume.level], ax
229
        call    convert_level_to_ac97_volume ;Asper: temporary workaround on ac97
230
        stdcall SetMasterVol, 0, eax
231
        jmp     red
232
       @@:
233
 
234
        ;Left channel Down
235
        cmp     ah, 79  ; 'End'
236
        jne     @f
237
        movzx   eax, [LVolume.level]
238
        dec     ax
239
        cmp     ax, 0
240
        jl      still
241
        mov     [LVolume.level], ax
242
        call    convert_level_to_ac97_volume ;Asper: temporary workaround on ac97
243
        stdcall SetMasterVol, 0, eax
244
        jmp     red
245
       @@:
246
 
247
        ;Right channel Up
248
        cmp     ah, 73  ; 'PageUp'
249
        jne     @f
250
        movzx   eax, [RVolume.level]
251
        inc     ax
252
        cmp     ax, [RVolume.num_steps]
253
        jg      still
254
        mov     [RVolume.level], ax
255
        call    convert_level_to_ac97_volume ;Asper: temporary workaround on ac97
256
        movzx   edx, [is_hda]
257
        stdcall SetMasterVol, edx, eax
258
        jmp     red
259
       @@:
260
 
261
        ;Right channel Down
262
        cmp     ah, 81  ; 'PageDown'
263
        jne     @f
264
        movzx   eax, [RVolume.level]
265
        dec     ax
266
        cmp     ax, 0
267
        jl      still
268
        mov     [RVolume.level], ax
269
        call    convert_level_to_ac97_volume ;Asper: temporary workaround on ac97
270
    .RVdown:
271
        movzx   edx, [is_hda]
272
        stdcall SetMasterVol, edx, eax
273
        jmp     red
274
       @@:
275
 
276
        jmp     still
277
 
278
button:
279
        mcall   17             ; Get pressed button code
280
        cmp     ah, 1               ; Test x button
281
        je      close_app
282
        jmp     still
283
 
284
 
285
draw_window:
286
        ;start_draw_window WIN_X,WIN_Y,WIN_W,WIN_H,WIN_COLOR,caption;, 12;labellen-labelt
287
        mcall   0,,,34000000h+WIN_COLOR,,caption
288
 
289
 
290
        stdcall draw_button,  WIN_X_CENTER-BUT_W-55, 30+BUT_H*0,BUT_W,BUT_H,2,C_PINK,aNoText,0,0
291
        stdcall draw_button,  WIN_X_CENTER-BUT_W-55, 30+BUT_H*1+10,BUT_W,BUT_H,3,C_GREEN,aNoText,0,0
292
        stdcall draw_button,  WIN_X_CENTER-BUT_W-55, 30+BUT_H*2+20,BUT_W,BUT_H,4,C_BLUE,aNoText,0,0
293
 
294
        stdcall draw_button,  WIN_X_CENTER-BUT_W/2+55, 30+BUT_H*0,BUT_W,BUT_H,5,C_GREY,aNoText,0,0
295
        stdcall draw_button,  WIN_X_CENTER-BUT_W/2+55, 30+BUT_H*1+10,BUT_W,BUT_H,6,C_BLACK,aNoText,0,0
296
        stdcall draw_button,  WIN_X_CENTER-BUT_W/2+55, 30+BUT_H*2+20,BUT_W,BUT_H,7,C_ORANGE,aNoText,0,0
297
 
298
        movzx   eax, [LVolume.level]
299
        movzx   edx, [LVolume.num_steps]
300
        stdcall draw_volume_control, WIN_X_CENTER-BUT_W-25, 20, 110, aLVolume, C_BLACK, eax, edx
301
        movzx   eax, [RVolume.level]
302
        movzx   edx, [RVolume.num_steps]
303
        stdcall draw_volume_control, WIN_X_CENTER+25, 20, 110, aRVolume, C_BLACK, eax, edx
304
 
305
        stdcall rectangle, WIN_X_CENTER-BUT_W-56, 29+BUT_H*0, BUT_W+2, BUT_H+2, C_BLACK
306
        stdcall rectangle, WIN_X_CENTER-BUT_W-56, 29+BUT_H*1+10, BUT_W+2, BUT_H+2, C_BLACK
307
        stdcall rectangle, WIN_X_CENTER-BUT_W-56, 29+BUT_H*2+20, BUT_W+2, BUT_H+2, C_BLACK
308
 
309
        stdcall rectangle, WIN_X_CENTER-BUT_W/2+54, 29+BUT_H*0, BUT_W+2, BUT_H+2, C_BLACK
310
        stdcall rectangle, WIN_X_CENTER-BUT_W/2+54, 29+BUT_H*1+10, BUT_W+2, BUT_H+2, C_GREEN
311
        stdcall rectangle, WIN_X_CENTER-BUT_W/2+54, 29+BUT_H*2+20, BUT_W+2, BUT_H+2, C_BLACK
312
 
313
        stdcall rectangle, WIN_X_CENTER-BUT_W-57, 28+BUT_H*0, BUT_W+4, BUT_H+4, C_PINK
314
        stdcall rectangle, WIN_X_CENTER-BUT_W-57, 28+BUT_H*1+10, BUT_W+4, BUT_H+4, C_GREEN
315
        stdcall rectangle, WIN_X_CENTER-BUT_W-57, 28+BUT_H*2+20, BUT_W+4, BUT_H+4, C_BLUE
316
 
317
        stdcall rectangle, WIN_X_CENTER-BUT_W/2+53, 28+BUT_H*0, BUT_W+4, BUT_H+4, C_GREY
318
        stdcall rectangle, WIN_X_CENTER-BUT_W/2+53, 28+BUT_H*1+10, BUT_W+4, BUT_H+4, C_BLACK;
319
        stdcall rectangle, WIN_X_CENTER-BUT_W/2+53, 28+BUT_H*2+20, BUT_W+4, BUT_H+4, C_ORANGE
320
 
321
 
322
        end_draw_window
323
ret
324
 
325
 
326
 
327
proc draw_volume_control stdcall, x:dword, y:dword, ysize:dword, name:dword, textcolor:dword, step:dword, max_steps:dword
328
        mov     ebx, [x]
329
        mov     edx, [y]
330
        mov     eax, [ysize]
331
        stdcall bar, ebx, edx, 10, eax, C_GREEN
332
        mov     ecx, [max_steps]
333
        cmp     ecx, [step]
334
        je      .l2
335
 
336
        push    eax  edx
337
        mov     cl,  byte [max_steps]
338
        test    cl, cl
339
        jnz     @f
340
        mov     ecx, [ysize]
341
        jmp     .l1
342
  @@:
343
        div     cl
344
        mov     cl,  byte [step]
345
        mul     cl
346
        mov     ecx, [ysize]
347
        sub     ecx, eax
348
  .l1:
349
        pop     edx  eax
350
        stdcall bar, ebx, edx, 10, ecx, C_RED
351
  .l2:
352
        dec     ebx
353
        dec     edx
354
        inc     eax
355
        stdcall rectangle, ebx, edx, 11, eax, C_BLACK
356
 
357
 
358
        add     edx, eax
359
        add     edx, 10
360
        sub     ebx, 8
361
        stdcall outtextxy, ebx, edx, [name], 0, C_GREEN or 0x80000000
362
        ret
363
endp
364
 
365
;____________________________________
366
GetDriverVer:
367
        push    ebx ecx
368
        mov     [ioctl_code], SRV_GETVERSION
369
        and     [inp_size], 0
370
        mov     [outp_size], 4
371
        mov     [output], driver_ver
372
        mcall   68,17,ioctl
373
        test    eax, eax
374
        jnz     loaderr
375
        if DEBUG
376
                push    eax
377
                dps     "1.) Driver version = "
378
                dph     [driver_ver]
379
                newline
380
                pop     eax
381
        end if
382
        pop     ecx ebx
383
ret
384
 
385
;____________________________________
386
Stop:
387
        and     [ioctl_code], DEV_STOP
388
        and     [inp_size], 4
389
        mov     [input], 0 ;? stream
390
        mov     [outp_size], 0
391
        mov     [output], 0
392
        mcall   68,17,ioctl
393
        test    eax, eax
394
        jnz     loaderr
395
        if DEBUG
396
                print   "Stop device"
397
        end if
398
ret
399
 
400
;____________________________________
401
proc GetMasterVol stdcall, channel:dword
402
        push    ebx ecx
403
        mov     [ioctl_code], DEV_GET_MASTERVOL
404
        mov     [inp_size], 1
405
        mov     eax, [channel]
406
        mov     [input], eax
407
        mov     [outp_size], 4
408
        mov     [output], master_vol
409
        mcall   68,17,ioctl
410
        if DEBUG
411
                push    eax
412
                dps     "Get Master volume = "
413
                dph     [master_vol]
414
                newline
415
                pop     eax
416
        end if
417
        mov     eax, [master_vol]
418
        pop     ecx ebx
419
ret
420
endp
421
;____________________________________
422
proc SetMasterVol stdcall, channel:dword, val:dword
423
        push    ebx ecx
424
        mov     [ioctl_code], DEV_SET_MASTERVOL
425
        mov     [inp_size], 4
426
        mov     eax, [channel]
427
        shl     eax, 24
428
        or      eax, [val]
429
        mov     [master_vol], eax
430
        mov     [input], master_vol
431
        mov     [outp_size], 0
432
        mcall   68,17,ioctl
433
        if DEBUG
434
                push    eax
435
                dps     "Set Master volume = "
436
                dph     [val]
437
                dps     "    ch = "
438
                dph     [channel]
439
                newline
440
                pop     eax
441
        end if
442
        pop     ecx ebx
443
ret
444
endp
445
 
446
;____________________________________
447
;GetDevInfo: ; Get pins configurations or controls
448
;        mov     [ioctl_code], DEV_GET_INFO
449
;        and     [inp_size], 0
450
;        mov     [outp_size], 9*4
451
;        mov     [output], ctrl_info
452
;        mcall   68,17,ioctl
453
;        if DEBUG
454
;                push    eax
455
;                print   "CTRL_INFO"
456
;                dps     ".pci_cmd = "
457
;                dph     [ctrl_info]
458
;                newline
459
;                dps     ".irq = "
460
;                dph     [ctrl_info+4]
461
;                newline
462
;                ;dps     ".glob_cntrl = "
463
;                dps     ".VIA_REG_OFFSET_CONTROL = "
464
;                dph     [ctrl_info+8]
465
;                newline
466
;                ;dps     ".glob_sta = "
467
;                dps     ".VIA_REG_OFFSET_STATUS = "
468
;                dph     [ctrl_info+12]
469
;                newline
470
;                ;dps     ".codec_io_base = "
471
;                dps     ".VIA_REG_OFFSET_TABLE_PTR = "
472
;                dph     [ctrl_info+16]
473
;                newline
474
;                dps     ".ctrl_io_base = "
475
;                dph     [ctrl_info+20]
476
;                newline
477
;                ;dps     ".codec_mem_base = "
478
;                dps     ".VIA_REG_OFFSET_STOP_IDX = "
479
;                dph     [ctrl_info+24]
480
;                newline
481
;                ;dps     ".ctrl_mem_base = "
482
;                dps     ".VIA_REG_OFFSET_CURR_COUNT = "
483
;                dph     [ctrl_info+28]
484
;                newline
485
;                dps     ".codec_id = "
486
;                dph     [ctrl_info+32]
487
;                newline
488
;                pop     eax
489
;        end if
490
;ret
491
 
492
 
493
convert_level_to_ac97_volume:
494
        push   ebx ecx edx
495
        cmp    [is_hda], 0
496
        jne    .not_ac97
497
 
498
        mov     [LVolume.level], ax
499
        mov     [RVolume.level], ax
500
 
501
        mov    bx, ax
502
        mov    ax, [LVolume.num_steps]
503
        sub    ax, bx
504
        mov    cx, 150
505
        mul    cx
506
        neg    eax
507
  .not_ac97:
508
        pop    edx ecx ebx
509
ret
510
 
511
 
512
convert_ac97_volume_to_level:
513
        push   ebx ecx edx
514
        cmp    [is_hda], 0
515
        jne    .not_ac97
516
 
517
        neg    eax
518
        mov    cx, 150
519
        div    cx
520
        mov    bx, ax
521
        mov    ax, [LVolume.num_steps]
522
        sub    ax, bx
523
  .not_ac97:
524
        pop    edx ecx ebx
525
ret
526
 
527
 
528
close_app:
529
        or      eax, -1
530
        int     0x40
531
;____________________________________
532
caption db 'Sound Mixer',0
533
drivername db 'SOUND',0
534
 
535
;aRamdisk db '/rd/1/',0
536
 
537
;aStartDriver db 'Start driver',0
538
;aStop        db 'Stop',0
539
;aGetMVol     db 'Get Master Volume',0
540
;aSetMVol    db 'Set Master Volume',0
541
;aGetDevInfo  db 'Get device info',0
542
aNoText      db 0
543
 
544
aLVolume     db 'Left',0
545
aRVolume     db 'Right',0
546
 
547
; Jack types
548
;aLineOut     db 'Line Out',0
549
;aSpeaker     db 'Speaker',0
550
;aHPOut       db 'HP Out',0
551
;aSideSpk     db '',0
552
;aCD          db 'CD',0
553
;aSPDIFOut    db 'SPDIF Out',0
554
;aDigitalOut  db 'Digital Out',0
555
;aModemLine   db 'Modem Line',0
556
;aModemHand   db 'Modem Hand',0
557
;aLineIn      db 'Line In',0
558
;aAUX         db 'AUX',0
559
;aMic         db 'Mic',0
560
;aTelephony   db 'Telephony',0
561
;aSPDIFIn     db 'SPDIF In',0
562
;aDigitalIn   db 'Digital In',0
563
;aReserved    db 'Reserved',0
564
;aOther       db 'Other',0
565
 
566
;Jack locations
567
;base
568
;aNA          db 'N/A',0
569
;aRear        db 'Rear',0
570
;aFront       db 'Front',0
571
;aLeft        db 'Left',0
572
;aRight       db 'Right',0
573
;aTop         db 'Top',0
574
;aBottom      db 'Bottom',0
575
;special
576
;aRearPanel   db 'Rear Panel',0
577
;aDriveBar    db 'Drive Bar',0
578
;aRiser       db 'Riser',0
579
;aHDMI        db 'HDMI',0
580
;aATAPI       db 'ATAPI',0
581
;aMobileIn    db 'Mobile-In',0
582
;aMobileOut   db 'Mobile-Out',0
583
 
584
 
585
I_END:
586
 
587
align 4
588
ioctl:
589
hDriver         rd 1
590
ioctl_code      rd 1
591
input           rd 1
592
inp_size        rd 1
593
output          rd 1
594
outp_size       rd 1
595
 
596
driver_ver      rd 1
597
master_vol      rd 1
598
 
599
;ctrl_info       rd 9
600
 
601
is_hda          rb 1
602
 
603
LVolume CONTROL
604
RVolume CONTROL
605
 
606
align 4
607
rb 2048 ; stack
608
I_MEM:
609