Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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