Subversion Repositories Kolibri OS

Rev

Rev 1329 | Rev 2455 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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