Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2024. All rights reserved.    ;;
  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 ?
  24.         jne     .ret                            ; if no then return.
  25.  
  26.         cmp     byte [sound_flag], 0
  27.         jne     .ret
  28.  
  29.         movzx   eax, byte [countDelayNote]
  30.         or      al, al                          ; player is busy ?
  31.         jnz     .ret                            ; return counter delay Note
  32.  
  33.         mov     [memAdrNote], esi;edx
  34.         call    get_pid
  35.         mov     [pidProcessNote], eax
  36.         xor     eax, eax                        ; Ok!  EAX = 0
  37. .ret:
  38.         mov     [esp + SYSCALL_STACK.eax], eax  ; return value EAX for application
  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 ?
  57.         jz      .NotPlayNotes    ; if ESI = 0   -> ignore play pocedure
  58.         cmp     eax, [count_timer_Note]
  59.         jb      .NotPlayNotes
  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
  65.         jz      .NewLoadNote@Delay
  66.         cmp     al, 0xFF         ; this is first Note Play ?
  67.         jne     .NextDelayNote
  68.         ;This is FIRST Note, save counter channel 2 chip 8253
  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
  75.    .NewLoadNote@Delay:
  76.         cld
  77. ;      lodsb                      ; load AL - counter Delay
  78.         call    ReadNoteByte
  79.         or      al, al           ; THE END ?
  80.         jz      .EndPlayNote
  81.         cmp     al, 0x81
  82.         jnc     .NoteforOctave
  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
  89.         jmp     .pokeNote
  90.  
  91.    .EndPlayNote:                 ; THE END Play Notes!
  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
  102.    .NextDelayNote:
  103.         mov     [countDelayNote], al; save new counter delay Note
  104.         pop     eax
  105.    .NotPlayNotes:
  106.         ret
  107.  
  108.    .NoteforOctave:
  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 ?
  114.         jne     .packCode        ; no, this is PACK CODE
  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
  118.         jmp     .saveESI
  119.  
  120.    .packCode:
  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!
  130.    .pokeNote:
  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
  137.    .saveESI:
  138. ;      mov   [memAdrNote], esi    ; save new header control Delay-Note string
  139.         pop     eax
  140.         ret
  141.  
  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  -------------------
  167.