MIDI Xpander code


REM To be *EXECed into BASIC
AUTO
REM **********************************
REM *  MIDI to AMPLE Interface Code  *
REM *  Copyright Scott Mackie 1988   *
REM **********************************
REM
REM Another Underwhelming Project From
REM The Awfully Nice Software Company!
REM
REM Copies of this code may be made on
REM condition that no profit is made
REM
REM Published by AMPLINEX
REM September 1988
REM
buffer=&A00:table=&96:in=&90:out=&91
splitarray=&C80:ssplit=&BFF
esplit=&C07
REM Change the following addresses to
REM suit your own interface. These are
REM the locations of the ETI port A.
status=&FCF0:data=&FCF1
FOR opt%=0 TO 7 STEP 7
O%=&4000
P%=&0900
REM Rather misleadingly titled gnote!
REM Foreground data output routine
[OPT opt%
.gnote lda out     \ Get Outputpointer
CMP in             \ Any data?
BEQ gnote          \ Nope? Check again
LDY out
LDA buffer,Y       \ Get buffer data
INC out            \ Update pointer
RTS
\ This is the main loop of the code
\ Calls the various routines needed
\ having analysed the data. Any extra
\ checking should go in after the
\ patchchange check.
.code JSR gnote    \ Get data
CMP #&90           \ Is it a Noteon?
BEQ noteon         \ Yip
CMP #&80           \ Noteoff?
BEQ noteoff        \ Yup
CMP #&E0           \ Pitchbend?
BEQ pitchb         \ Yip
CMP #&C0           \ Patchchange?
BEQ patchc         \ Yup
JMP code           \ Start again....
\ This routine handles Noteons. It
\ Also handles Noteoffs if sent as a
\ Noteon with zero velocity. See later
\ text about this point.
.noteon LDA #0     \ Set ID byte to 0
STA &92            \  in header
JSR gnote          \ Get note data
TAX                \ Save for later
SEC
SBC #&3C           \ Convert for AMPLE
STA &93            \ Store in header
JSR gnote          \ Get velocity byte
STA &94            \ Store in header
CMP #0             \ Noteoff?
BEQ dalloc         \ Looks like it!
LDY splitarray,X   \ Get zone number
LDX ssplit,Y       \ Get initial voice
.loop1 INX
LDA table,X        \ Get voice table
CMP #128           \ Voice unused?
BNE loop1          \ No!
TXA
CMP esplit,Y       \ Over voice limit?
BCC foundslot      \ No...phew...
LDX ssplit,Y       \ Boo....overflow
INX
.foundslot STX &95 \ Store in header
LDA &93            \ Get note pressed
STA table,X        \ Store it in table
RTS
\ Noteoff provides handling for those
\ keyboards that actually use a
\ Noteoff instead of a zero velocity
\ Noteon. I haven't checked this as I
\ don't have a "Noteoff" keyboard, but
\ it should work... comments please...
.noteoff LDA #0    \ Set ID byte to 0
STA &92            \  in header
JSR gnote          \ Get note data
SEC
SBC #&3C           \ Convert for AMPLE
STA &93            \ Store in header
JSR gnote          \ Waste velocity
LDA #0
STA &94            \ Store in header
.dalloc LDY #0     \ Reset pointer
.loop2 INY
CPY table          \ We overflowed?
BEQ notfound       \ Uh Huh...
LDA table,Y        \ Get note here
CMP &93            \ Same as Noteoff?
BNE loop2          \ No....
LDA #128           \ Get reset byte
STA table,Y        \ Free the voice
.notfound STY &95  \ Store voice freed
RTS
\ This routine handles the pitchbend
\ data arriving. Has an ID of 1.
.pitchb LDA #1     \ Set ID byte
STA &92            \ Store in header
JSR gnote          \ Get LSB and waste
JSR gnote          \ Get MSB of data
STA &93            \ Store in header
RTS
\ This routine handles the patch
\ changes...basically just reads the
\ data...very boring actually...
.patchc LDA #2     \ Set ID byte
STA &92            \ Store in header
JSR gnote          \ Get patch number
STA &93            \ Store it...
RTS                \ Bye bye
]
P%=&D00
REM This is the NMI code, positioned
REM at &D00. It provides circular
REM buffer handling for the buffer at
REM &A00
[
OPT opt%          
PHA:TYA:PHA
.wait LDA status   \ Get 6850 status
AND #1             \ Mask data bit
CMP #1             \ Check it
BNE wait           \ Nothing yet
LDA data           \ Get the data
LDY in             \ Get the pointer
STA buffer,Y       \ Store data
STA data           \ MIDI Out "Echo"
INC in             \ Update pointer
PLA:TAY:PLA:RTI    \ Exit NMI
]
NEXT
REM Press Escape and then RUN

Published in AMPLINEX 007, September 1988