Subversion Repositories Kolibri OS

Rev

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

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