Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
9910 Doczom 3
;; Copyright (C) KolibriOS team 2004-2023. 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
$Revision: 9910 $
20
 
21
align 4
22
sound_interface:
23
 
24
        cmp     eax, ebx                        ; this is subfunction #55 ?
9910 Doczom 25
        jne     .ret                            ; if no then return.
2288 clevermous 26
 
27
        cmp     byte [sound_flag], 0
9910 Doczom 28
        jne     .ret
2288 clevermous 29
 
30
        movzx   eax, byte [countDelayNote]
31
        or      al, al                          ; player is busy ?
9910 Doczom 32
        jnz     .ret                            ; return counter delay Note
2288 clevermous 33
 
34
        mov     [memAdrNote], esi;edx
35
        call    get_pid
36
        mov     [pidProcessNote], eax
9910 Doczom 37
        xor     eax, eax                        ; Ok!  EAX = 0
38
.ret:
39
        mov     [esp + SYSCALL_STACK.eax], eax  ; return value EAX for application
2288 clevermous 40
        ret
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
 
54
playNote:
55
;      jmp   NotPlayNotes
56
        mov     esi, [memAdrNote]
57
        or      esi, esi         ; ESI = 0 ?  - OFF Notes Play ?
9910 Doczom 58
        jz      .NotPlayNotes    ; if ESI = 0   -> ignore play pocedure
2288 clevermous 59
        cmp     eax, [count_timer_Note]
9910 Doczom 60
        jb      .NotPlayNotes
2288 clevermous 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
9910 Doczom 66
        jz      .NewLoadNote@Delay
2288 clevermous 67
        cmp     al, 0xFF         ; this is first Note Play ?
9910 Doczom 68
        jne     .NextDelayNote
69
        ;This is FIRST Note, save counter channel 2 chip 8253
2288 clevermous 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
9910 Doczom 76
   .NewLoadNote@Delay:
2288 clevermous 77
        cld
78
;      lodsb                      ; load AL - counter Delay
79
        call    ReadNoteByte
80
        or      al, al           ; THE END ?
9910 Doczom 81
        jz      .EndPlayNote
2288 clevermous 82
        cmp     al, 0x81
9910 Doczom 83
        jnc     .NoteforOctave
2288 clevermous 84
        mov     [countDelayNote], al
85
;      lodsw                      ; load AX - counter for Note!
86
        call    ReadNoteByte
87
        mov     ah, al
88
        call    ReadNoteByte
89
        xchg    al, ah
9910 Doczom 90
        jmp     .pokeNote
2288 clevermous 91
 
9910 Doczom 92
   .EndPlayNote:                 ; THE END Play Notes!
2288 clevermous 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
9910 Doczom 103
   .NextDelayNote:
2288 clevermous 104
        mov     [countDelayNote], al; save new counter delay Note
105
        pop     eax
9910 Doczom 106
   .NotPlayNotes:
107
        ret
2288 clevermous 108
 
9910 Doczom 109
   .NoteforOctave:
2288 clevermous 110
        sub     al, 0x81         ; correction value for delay Note
111
        mov     [countDelayNote], al; save counter delay this new Note
112
;      lodsb                      ; load pack control code
113
        call    ReadNoteByte
114
        cmp     al, 0xFF         ; this is PAUSE ?
9910 Doczom 115
        jne     .packCode        ; no, this is PACK CODE
2288 clevermous 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
9910 Doczom 119
        jmp     .saveESI
2288 clevermous 120
 
9910 Doczom 121
   .packCode:
2288 clevermous 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!
9910 Doczom 131
   .pokeNote:
2288 clevermous 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
9910 Doczom 138
   .saveESI:
2288 clevermous 139
;      mov   [memAdrNote], esi    ; save new header control Delay-Note string
140
        pop     eax
9910 Doczom 141
        ret
142
 
2288 clevermous 143
ReadNoteByte:
144
;result:
145
;  al - note
146
        push    eax
147
        push    ecx
148
        push    edx
149
        push    esi
150
 
151
        mov     eax, [pidProcessNote]
152
        call    pid_to_slot
153
        test    eax, eax
154
        jz      .failed
155
        lea     ecx, [esp+12]
156
        mov     edx, 1
157
        mov     esi, [memAdrNote]
158
        inc     [memAdrNote]
159
 
160
        call    read_process_memory
161
.failed:
162
        pop     esi
163
        pop     edx
164
        pop     ecx
165
        pop     eax
166
        ret
167
;-------------------  END CODE  -------------------