home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 7 / AU_CD7.iso / aujun99 / regulars / rtr / software / bassp1
Text File  |  1999-03-29  |  11KB  |  344 lines

  1.  ;MIDI Bass peddel
  2.  ;For an 8 MHz clock
  3.  ;A0 - MIDI out
  4.  ;16 keys clocked in through shift register
  5.       LIST P=16C84
  6.  ;      
  7.  ;
  8.  C       EQU     0
  9.  PCL     EQU     2
  10.  Z       EQU     2
  11.  PORTB   EQU     6
  12.  PORTA   EQU     5
  13.  TRISB   EQU     86H
  14.  TRISA   EQU     85H
  15.  EECON1  EQU     88H
  16.  EEDATA  EQU     8
  17.  EEADR   EQU     9
  18.  STATUS  EQU     3
  19.  RP0     EQU     5
  20.  INC     EQU     1
  21.  Mch     EQU     2      ;Midi transmit channel
  22.  H       EQU     80h    ;Hold drone note
  23.  Key     EQU    0ch
  24.  Note    EQU    0dh     ;MIDI note value
  25.  Sbuf    EQU    0eh
  26.  Scount  EQU    0fh
  27.  Cdown   EQU    10h
  28.  Drone   EQU    11h     ;Drone note indicator
  29.  Kbl     EQU    12h     ;Key debouncer inner
  30.  Kbh     EQU    13h     ;Key debouncer outer
  31.  KeyLim  EQU    14h     ;Key Limit for Nn routine
  32.  voice   EQU    15h     ;voice number store
  33.  bank    EQU    16h     ;bank number store
  34.  CC1     EQU    17h     ;Control Change data 1
  35.  CC2     EQU    18h     ;Control change data 2
  36.  PCd     EQU    19h     ;Programme change data
  37.  Lnote   EQU    1Ah     ;Last note sounded
  38. ;
  39.    ORG 0
  40.         GOTO    Start
  41. ;7 seg lookup table for diffrent notes
  42. Sseg
  43.         addwf   PCL,f
  44.         retlw   39h     ;C
  45.         retlw   0B9h    ;C#
  46.         retlw   05Eh    ;D
  47.         retlw   0DEh    ;D#
  48.         retlw   79h     ;E
  49.         retlw   71h     ;F
  50.         retlw   0F1h    ;F#
  51.         retlw   06Fh    ;G
  52.         retlw   0EFh    ;G#
  53.         retlw   77h     ;A
  54.         retlw   0F7h    ;A#
  55.         retlw   7Ch     ;B
  56.         retlw   58h     ;c
  57.         retlw   0       ;Unused switches
  58.         retlw   0
  59.         retlw   0
  60.         
  61.  
  62. ;Read the keys through the shift register        
  63. Kread   bcf     PORTA,2         ;Load shift low
  64.         clrf    Key             ;Clear the count
  65.         bsf     PORTA,2         ;Load shift high
  66. Kloop   btfss   PORTA,3         ;Look at data
  67.         goto    found           ;Jump out if find a zero
  68.         bcf     PORTA,1         ;Clock Low
  69.         nop
  70.         nop
  71.         nop
  72.         bsf     PORTA,1         ;Clock High
  73.         incf    Key,f           ;Counter
  74.         movf    Key,w           ;See if it's at the end
  75.         sublw   16
  76.         btfss   STATUS,Z
  77.         goto    Kloop
  78. found   return
  79.  
  80. Pres    CALL    Kread           ;Look at the peddles
  81.         MOVF    Key,w           ;Get key value
  82.         movf    Key,w           ;See if anything pressed
  83.         sublw   16
  84.         btfsc   STATUS,Z
  85.         goto    Pres            ;Look again if nothing pressed
  86.         return
  87.  
  88. Unpres 
  89.         CALL    Kread           ;Look at the peddles
  90.         MOVF    Key,w           ;Get key value
  91.         movf    Key,w           ;See if anything pressed
  92.         sublw   16
  93.         btfss   STATUS,Z
  94.         goto    Unpres          ;Look again until nothing pressed
  95.         return
  96.  
  97. ;Send a serial byte
  98. Send    movlw   9               ;Number of data bits to send
  99.         movwf   Scount
  100.         bcf     PORTA,0         ;Start bit
  101.         call    cDelay          ;Extra delay compensation
  102. Sloop   call    Delay
  103.         btfsc   Sbuf,0          ;Set the next bit
  104.         bsf     PORTA,0
  105.         btfss   Sbuf,0
  106.         bcf     PORTA,0
  107.         rrf     Sbuf,f          ;Shift for next time
  108.         decfsz  Scount,f
  109.         goto    Sloop           ;Round until finished
  110.         bsf     PORTA,0         ;Stop bit
  111.         call    cDelay          ;Extra delay compensation
  112.         call    Delay
  113.         call    Delay
  114.         call    cDelay          ;For good measure
  115.         return
  116.         
  117. Delay   movlw   17              ;Delay for serial send
  118.         movwf   Cdown
  119. Dloop   decfsz  Cdown,f
  120.         goto    Dloop
  121.         return
  122. cDelay  nop                     ;Extra delay for outside the loop
  123.         nop
  124.         nop
  125.         nop
  126.         nop
  127.         nop
  128.         nop
  129.         nop
  130.         nop
  131.         return
  132.         
  133. ProgC   movlw   0C0h            ;Program Change
  134.         iorlw   Mch             ;Mix in with MIDI channel number
  135.         movwf   Sbuf            ;Send buffer
  136.         call    Send            ;Send Program change message
  137.         movf    PCd,w           ;Data 1
  138.         movwf   Sbuf
  139.         call    Send
  140.         return
  141.         
  142. ContC   movlw   0B0h            ;Control Change
  143.         iorlw   Mch             ;Mix in with MIDI channel number
  144.         movwf   Sbuf            ;Send buffer
  145.         call    Send            ;Send control change message
  146.         movf    CC1,w           ;Data 1
  147.         movwf   Sbuf
  148.         call    Send
  149.         movf    CC2,w           ;Data 2
  150.         movwf   Sbuf
  151.         call    Send
  152.         return
  153.        
  154. NoteOn  movf    Key,w           ;Get key number
  155.         addlw   24              ;Make into MIDI note
  156.         movwf   Note            ;Save in Note (key = 0 note C)
  157.         movlw   90h             ;Note on
  158.         iorlw   Mch             ;Mix in with MIDI channel number
  159.         movwf   Sbuf            ;Send buffer
  160.         call    Send            ;Send note on
  161.         movf    Note,w          ;Get note number
  162.         movwf   Sbuf
  163.         call    Send            ;Send note number
  164.         movlw   100             ;Velocity
  165.         movwf   Sbuf
  166.         call    Send            ;Send Velocity
  167.         movf    Key,w           ;Display note
  168.         call    Sseg            ;Convert to 7 seg pattern
  169.         movwf   PORTB           ;Display it
  170.         return
  171.         
  172. NoteOff
  173.         movf    Note,w          ;Get last note
  174.         movwf   Lnote           ;Make a copy
  175.         movlw   80h             ;Note off
  176.         iorlw   Mch             ;Mix in with MIDI channel number
  177.         movwf   Sbuf            ;Send buffer
  178.         call    Send            ;Send note off
  179.         movf    Note,w          ;Get note number
  180.         movwf   Sbuf
  181.         call    Send            ;Send note number
  182.         movlw   0               ;Velocity
  183.         movwf   Sbuf
  184.         call    Send            ;Send Velocity
  185.         movlw   0               ;Blank display
  186.         movwf   PORTB
  187.         return
  188.  
  189. Nne     call    Unpres          ;If not valid key wate for unpressed
  190.         call    Bounce      
  191. Nn      call    Pres            ;Get just a note
  192.         call    Bounce
  193.         movf    KeyLim,w
  194.         subwf   Key,w           ;See if under the limit
  195.         btfsc   STATUS,C
  196.         goto    Nne             ;Look again if it is
  197.         return
  198.  
  199. Start
  200.         BSF     STATUS,RP0      ;SELECT REGISTER BANK 1
  201.         MOVLW   18h             ;Bits 4 & 3 inputs
  202.         MOVWF   TRISA^80H       ;SET PORT A TO ALL OUTPUTS
  203.         MOVLW   0               ;All port B to inputs
  204.         MOVWF   TRISB^80H
  205.         BCF     STATUS,RP0      ;SELECT REGISTER BANK 0
  206.         
  207.         BSF     PORTA,2         ;Shift / Load high
  208.         BSF     PORTA,0         ;Midi at Mark
  209.         BSF     PORTA,1         ;Clock high
  210.         clrf    Drone           ;Drone off
  211.         clrf    PORTB           ;Display off
  212.         clrf    Lnote           ;No note playing
  213.         
  214.  
  215. Main    
  216.         call    Pres            ;Hold until something pressed
  217.         
  218.         movlw   13              ;Test for a voice change
  219.         subwf   Key,w
  220.         btfsc   STATUS,Z
  221.         goto    Voice
  222.         
  223.         movlw   14              ;Test for a effects change
  224.         subwf   Key,w
  225.         btfsc   STATUS,Z
  226.         goto    Effects
  227.         
  228.         movlw   15              ;Test for spair input
  229.         subwf   Key,w
  230.         btfsc   STATUS,Z
  231.         goto    Main            ;Just back if it is
  232.           
  233.  
  234. ; Must be a note then :- Sound a note
  235.         call    NoteOff         ;Turn previous note off
  236.         movf    Key,w
  237.         addlw   24
  238.         subwf   Lnote,w         ;Is this the same note as last time
  239.         btfsc   STATUS,Z        ;If so skip playing
  240.         goto    nPlay
  241. Play    call    NoteOn          ;Turn new note on
  242. cPlay   call    Bounce
  243.         call    Unpres          ;Hold until key released
  244.         call    Bounce
  245.         btfss   Drone,0         ;Don't turn off if drone note
  246.         call    NoteOff         ;Turn previous note off
  247.  
  248.         goto    Main
  249. nPlay   btfss   Drone,0         ;If drone notes not on then play again
  250.         goto    Play
  251.         clrf    Lnote           ;Clear last note played
  252.         incf    Lnote,f         ;To make it diffrent from note
  253.         clrf    Note            ;Clear current note as we arn't going to play it
  254.         goto    cPlay
  255.        
  256. Voice   movlw   69h             ;Display an c underline
  257.         movwf   PORTB
  258.         call    Bounce          ;Remove voice change switch
  259.         call    Unpres
  260.         call    Bounce
  261.         
  262.         movlw   13              ;Limit key to return
  263.         movwf   KeyLim
  264.         call    Nn              ;Get voice change number
  265.         bcf     STATUS,C
  266.         rlf     Key,f           ;Multiply number by 2
  267.         movf    Key,w
  268.         movwf   EEADR           ;Look up voice parameters
  269.         BSF     STATUS,RP0      ;Select bank 1
  270.         bsf     EECON1^80h,0    ;initiate EPROM read
  271.         BCF     STATUS,RP0      ;Back to bank 0
  272.         movf    EEDATA,w        ;Get Voice number
  273.         movwf   voice
  274.         incf    EEADR,f         ;Get bank Number
  275.         BSF     STATUS,RP0      ;Select bank 1
  276.         bsf     EECON1^80h,0
  277.         BCF     STATUS,RP0      ;Back to bank 0
  278.         movf    EEDATA,w
  279.         movwf   bank
  280.         bcf     Drone,0         ;Clear out any drone
  281.         btfsc   bank,7          ;Test for Drone bit
  282.         bsf     Drone,0         ;Set if should be drone
  283.         movlw   32              ;Control change data 1
  284.         movwf   CC1
  285.         movf    bank,w          ;Control change data 2
  286.         andlw   7fh             ;Blank out any drone bit
  287.         movwf   CC2
  288.         call    ContC           ;Send first control change bank (LSB)
  289.         clrf    CC1
  290.         clrf    CC2
  291.         call    ContC           ;Send other bank (MSB)
  292.         movf    voice,w         ;Program change
  293.         movwf   PCd
  294.         call    ProgC
  295.         call    Unpres
  296.         call    Bounce
  297.         call    Bounce
  298.         clrf    PORTB           ;Blank out display
  299.         goto    Main
  300.          
  301. Effects
  302.         goto    Main            ;Not yet implemented
  303.         
  304. Bounce  movlw   36
  305.         movwf   Kbh             ;Outer loop
  306. B2      clrf    Kbl             ;inner loop 
  307. B1      decfsz  Kbl,f
  308.         goto    B1
  309.         decfsz  Kbh,f
  310.         goto    B2
  311.         return
  312.  
  313. ;Voice change data in EEPROM 
  314.  
  315.         org 2100h       ;Point at data memory
  316.         equb    81      ;Big Lead
  317.         equb    20+H
  318.         equb    81      ;Dir Lead
  319.         equb    41+H
  320.         equb    87      ;Big & Low
  321.         equb    16+H
  322.         equb    87      ;Fat & Porky
  323.         equb    64+H
  324.         equb    87      ;Bass Lead
  325.         equb    0+H
  326.         equb    88      ;Fantisy 2
  327.         equb    64
  328.         equb    95      ;Sweep
  329.         equb    0
  330.         equb    101     ;Goblins
  331.         equb    0+H
  332.         equb    96      ;Rain
  333.         equb    20
  334.         equb    91      ;CC
  335.         equb    67+H
  336.         equb    95      ;Celstia
  337.         equb    66+H
  338.         equb    95      ;Polar
  339.         equb    64+H
  340.         equb    95      ;Shimmer
  341.         equb    20+H        
  342.       
  343.         end                
  344.