Subversion Repositories Kolibri OS

Rev

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

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