Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved.    ;;
431 serge 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
1 ha 6
;;  PLAYNOTE.INC                    version 1.1  22 November 2003  ;;
7
;;                                                                 ;;
8
;;  Player Notes for Speaker PC                                    ;;
9
;;         subfunction #55 from function #55  Menuet OS            ;;
10
;;                                                                 ;;
11
;;                 Copyright 2003  VaStaNi                         ;;
12
;;                     vastani@ukr.net                             ;;
13
;;           >>>- SIMPLY - QUICKLY - SHORTLY -<<<                  ;;
14
;;                                                                 ;;
15
;;  Note: playnote.txt                                             ;;
16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18
 
593 mikedld 19
$Revision: 2465 $
20
 
802 serge 21
align 4
22
sound_interface:
593 mikedld 23
 
2434 Serge 24
        cmp     eax, ebx                        ; this is subfunction #55 ?
25
        jne     retFunc55                       ; if no then return.
1 ha 26
 
2434 Serge 27
        cmp     byte [sound_flag], 0
28
        jne     retFunc55
802 serge 29
 
2434 Serge 30
        movzx   eax, byte [countDelayNote]
31
        or      al, al                          ; player is busy ?
32
        jnz     retFunc55                       ; return counter delay Note
802 serge 33
 
2434 Serge 34
        mov     [memAdrNote], esi;edx
35
        call    get_pid
36
        mov     [pidProcessNote], eax
37
        xor     eax, eax                       ; Ok!  EAX = 0
802 serge 38
 retFunc55:
2434 Serge 39
        mov     [esp+32], eax                  ; return value EAX for application
40
        ret
802 serge 41
 
42
iglobal
43
align 4
44
  kontrOctave      dw  0x4742, 0x4342, 0x3F7C, 0x3BEC, 0x388F, 0x3562
45
                   dw  0x3264, 0x2F8F, 0x2CE4, 0x2A5F, 0x2802, 0x25BF
46
  memAdrNote       dd  0
47
  pidProcessNote   dd  0
48
  slotProcessNote  dd  0
49
  count_timer_Note dd  1
50
  mem8253r42       dw  0
51
  countDelayNote   db  0
52
endg
53
 
1 ha 54
playNote:
55
;      jmp   NotPlayNotes
2434 Serge 56
        mov     esi, [memAdrNote]
57
        or      esi, esi         ; ESI = 0 ?  - OFF Notes Play ?
58
        jz      NotPlayNotes     ; if ESI = 0   -> ignore play pocedure
59
        cmp     eax, [count_timer_Note]
60
        jb      NotPlayNotes
61
        push    eax
62
        inc     eax
63
        mov     [count_timer_Note], eax
64
        mov     al, [countDelayNote]
65
        dec     al               ; decrement counter Delay for Playing Note
66
        jz      NewLoadNote@Delay
67
        cmp     al, 0xFF         ; this is first Note Play ?
68
        jne     NextDelayNote
1 ha 69
      ;This is FIRST Note, save counter channel 2 chip 8253
2434 Serge 70
        mov     al, 0xB6         ; control byte to timer chip 8253
71
        out     0x43, al         ; Send it to the control port chip 8253
72
        in      al, 0x42         ; Read Lower byte counter channel 2 chip 8253
73
        mov     ah, al           ; AH = Lower byte counter channel 2
74
        in      al, 0x42         ; Read Upper byte counter channel 2 chip 8253
75
        mov     [mem8253r42], ax ; Save counter channel 2 timer chip 8253
1 ha 76
   NewLoadNote@Delay:
2434 Serge 77
        cld
1 ha 78
;      lodsb                      ; load AL - counter Delay
2434 Serge 79
        call    ReadNoteByte
80
        or      al, al           ; THE END ?
81
        jz      EndPlayNote
82
        cmp     al, 0x81
83
        jnc     NoteforOctave
84
        mov     [countDelayNote], al
1 ha 85
;      lodsw                      ; load AX - counter for Note!
2434 Serge 86
        call    ReadNoteByte
87
        mov     ah, al
88
        call    ReadNoteByte
89
        xchg    al, ah
90
        jmp     pokeNote
1 ha 91
 
92
   EndPlayNote:                  ; THE END Play Notes!
2434 Serge 93
        in      al, 0x61         ; Get contents of system port B chip 8255
94
        and     al, 0xFC         ; Turn OFF timer and speaker
95
        out     0x61, al         ; Send out new values to port B chip 8255
96
        mov     ax, [mem8253r42] ; memorize counter channel 2 timer chip 8253
97
        xchg    al, ah           ; reverse byte in word
98
        out     0x42, al         ; restore Lower byte counter channel 2
99
        mov     al, ah           ; AL = Upper byte counter channel 2
100
        out     0x42, al         ; restore Upper byte channel 2
101
        xor     eax, eax         ; EAX = 0
102
        mov     [memAdrNote], eax; clear header control Delay-Note string
1 ha 103
   NextDelayNote:
2434 Serge 104
        mov     [countDelayNote], al; save new counter delay Note
105
        pop     eax
1 ha 106
   NotPlayNotes:
107
        RET
108
 
109
   NoteforOctave:
2434 Serge 110
        sub     al, 0x81         ; correction value for delay Note
111
        mov     [countDelayNote], al; save counter delay this new Note
1 ha 112
;      lodsb                      ; load pack control code
2434 Serge 113
        call    ReadNoteByte
114
        cmp     al, 0xFF         ; this is PAUSE ?
115
        jne     packCode         ; no, this is PACK CODE
116
        in      al, 0x61         ; Get contents of system port B chip 8255
117
        and     al, 0xFC         ; Turn OFF timer and speaker
118
        out     0x61, al         ; Send out new values to port B chip 8255
119
        jmp     saveESI
1 ha 120
 
121
   packCode:
2434 Serge 122
        mov     cl, al           ; save code
123
        and     al, 0xF          ; clear upper bits
124
        dec     al               ; correction
125
        add     al, al           ; transform number to offset constant
126
        movsx   eax, al          ; EAX - offset
127
        add     eax, dword kontrOctave; EAX - address from constant
128
        mov     ax, [eax]        ; read constant
129
        shr     cl, 4            ; transform for number Octave
130
        shr     ax, cl           ; calculate from Note this Octave!
1 ha 131
   pokeNote:
2434 Serge 132
        out     0x42, al         ; Lower byte Out to channel 2 timer chip 8253
133
        mov     al, ah
134
        out     0x42, al         ; Upper byte Out to channel 2 timer chip 8253
135
        in      al, 0x61         ; Get contents of system port B chip 8255
136
        or      al, 3            ; Turn ON timer and speaker
137
        out     0x61, al         ; Send out new values to port B chip 8255
1 ha 138
   saveESI:
139
;      mov   [memAdrNote], esi    ; save new header control Delay-Note string
2434 Serge 140
        pop     eax
1 ha 141
        RET
142
ReadNoteByte:
143
;result:
144
;  al - note
2434 Serge 145
        push    eax
146
        push    ecx
147
        push    edx
148
        push    esi
1329 Lrz 149
 
2434 Serge 150
        mov     eax, [pidProcessNote]
151
        call    pid_to_slot
152
        test    eax, eax
153
        jz      .failed
154
        lea     ecx, [esp+12]
155
        mov     edx, 1
156
        mov     esi, [memAdrNote]
157
        inc     [memAdrNote]
1329 Lrz 158
 
2434 Serge 159
        call    read_process_memory
431 serge 160
.failed:
2434 Serge 161
        pop     esi
162
        pop     edx
163
        pop     ecx
164
        pop     eax
165
        ret
1 ha 166
;-------------------  END CODE  -------------------