;MIDI PROGRAM   PATCH BANKER    4/16/87 
;           CZ.PB   version 3.5c.nolist
;            --use menu.block1.1
;MODIFIED 2/16/91 to create CRUNCH0.0
;  --puts two midi bytes into H/L format
;  --splits H/L byte into 2 midi bytes  
;  --a self contained subroutine
;  --main program must have wait.to.get and wait.to.send midi i/o routines

cr.temp1:   .byte $00  

; Get 2 midi bytes and put them together
; NOTE: crunch returns with byte in .A
; Carry flag will be set if f7 is rec'd
; If 1st byte was F7, .A contains F7
; If 2nd byte was F7, .A contains data
crunch:         jsr wait.to.get
                lda dr
                cmp #$f7
                beq f7.received1
                sta cr.temp1
                jsr wait.to.get
                lda dr
                cmp #$f7
                beq f7.received2
                and #$0f
                asl a
                asl a
                asl a
                asl a
                ora cr.temp1
                lda cr.temp1
                clc
                rts
f7.received2:   lda cr.temp1 ; .A = data
f7.received1:   sec ;.A contains f7
                rts

; Take byte and send out 2 midi bytes
;NOTE: byte should be in .A
uncrunch:       sta cr.temp1
                jsr wait.to.send
                lda cr.temp1
                and #$0f
                sta dw
                jsr wait.to.send
                lda cr.temp1
                lsr a
                lsr a
                lsr a
                lsr a
                and #$0f
                sta dw
                rts

