;-----------------------------------------------------------------------------------------------; ; Program: **tbd** ; ; Developed by David J. Brown ; ; Copyright (c) April 13, 2004 David J. Brown ; ; Email: davebr@earthlink.net ; ; Web site: http://modularsynthesis.com ; ;-----------------------------------------------------------------------------------------------; ; LICENSE AGREEMENT: ; ; This program is free software. You can redistribute it and/or modify it. ; ; ; ; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, ; ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ; ;-----------------------------------------------------------------------------------------------; ; ; Description: ; This program **tbd** ; ; Inputs: ; Start = not used ; Stop = not used ; In-1 = not used ; In-2 = not used ; In-3 = not used ; In-4 = not used ; In-5 = not used ; In-6 = not used ; In-7 = not used ; In-8 = not used ; Aux = not used ; Midi-In = not used ; ; Outputs: ; Out-1 = not used ; Out-2 = not used ; Out-3 = not used ; Out-4 = not used ; Out-5 = not used ; Out-6 = not used ; Out-7 = not used ; Out-8 = not used ; Aux = not used ; Midi-Out= not used ; Speakjet= not used ; ; Display = not used ; Run led = toggles @ 0.5 S (timer interrupts enabled) ; Stop led= not used ; ; Revision: 0.0S2 ; Date Month Day, Year ; History: 0.0S2 initial release of program ; Written: Month Day, Year ; ;-----------------------------------------------------------------------------------------------; ; Conditionals ; ;-----------------------------------------------------------------------------------------------; ; ;---------PSIM, CVS, OR CVS-4 CONDITIONAL COMPILE OPTION----------------------------------------; ; ; ; UNCOMMENT ONE OF NEXT THREE LINES TO SELECT TARGET MODULE ; cvs con 1 ;define for CVS module ; ;cvs4 con 1 ;define for 4 channel CVS module ; ;psim con 1 ;define for PSIM module ; ;-----------------------------------------------------------------------------------------------; ;---------ENABLE AUX_IN RISING EDGE INTERRUPT CONDITIONAL COMPILE OPTION------------------------; ; ; ; COMMENT OUT NEXT LINE TO DISABLE AUX INPUT RISING EDGE INTERRUPTS ; aux_int_en con 1 ;define to enable aux_in rising edge interrupts ; ; ;comment to disable aux_in rising edge interrupts ; ;-----------------------------------------------------------------------------------------------; ;---------ENABLE TIMER INTERRUPT CONDITIONAL COMPILE OPTION-------------------------------------; ; Notes: run led will blink to verify timer operation ; ; ; ; COMMENT OUT NEXT LINE TO DISABLE TIMER INTERRUPTS ; timer_int_en con 1 ;define to enable timer interrupts ; ; ;comment to disable timer interrupts ; ; ; ; ;------ENABLE AVERAGED ANALOG-IN IN TIMER INTERRUPT CONDITIONAL COMPILE OPTION------------; ; ; ; Note: requires timer_int_en to be defined ; ; ; ; ; ; ; ; COMMENT OUT NEXT LINE TO DISABLE ANALOG-IN ON TIMER INTERRUPTS/ENABLE POLLED ANALOG-IN ; ; input_int_en con 1 ;define to enable input interrupt mode ; ; ; ; ;comment to set polled input mode ; ; ; ;-----------------------------------------------------------------------------------------; ; ; ; ; ;------ENABLE RISING EDGE DETECT IN TIMER INTERRUPT CONDITIONAL COMPILE OPTION------------; ; ; ; Note: requires timer_int_en to be defined ; ; ; ; pulse must be > 1 mS and > 8 mS period (7 timer clocks low / 1 timer clock high) ; ; ; ; ; ; ; ; COMMENT OUT NEXT LINE TO DISABLE RISING EDGE DETECT IN TIMER INTERRUPTS ; ; ; edge_int_en con 1 ;define to enable rising edge detect mode ; ; ; ; ;comment to disable rising edge detect mode ; ; ; ; UNCOMMENT ONE OF NEXT THREE LINES TO SELECT INPUT FOR RISING EDGE DETECT ; ; ; edge_in var in4 ;use start jack for rising edge detect input ; ; ; edge_in var in5 ;use stop jack for rising edge detect input ; ; ; edge_in var in8 ;use aux jack for rising edge detect input ; ; ; ;-----------------------------------------------------------------------------------------; ; ;-----------------------------------------------------------------------------------------------; ; ;-----------------------------------------------------------------------------------------------; ; Include Files (locate one level above the program directory) ; ;-----------------------------------------------------------------------------------------------; ; #include "..\support.djb.bas" ;support declarations and subroutines ; ;-----------------------------------------------------------------------------------------------; ; Program Declarations ; ;-----------------------------------------------------------------------------------------------; ;**tbd** ;-----------------------------------------------------------------------------------------------; ; MIDI Declarations ; ;-----------------------------------------------------------------------------------------------; allup con $7b ;midi all notes-off command keyup con $80 ;midi note-off command keydn con $90 ;midi note-on command conctrl con $b0 ;midi continuous controller command pgmchg con $c0 ;midi program change command chnprs con $d0 ;midi channel pressure command pitchb con $e0 ;midi pitch bend command midi_chan var nib ;midi channel: send_note_on, send_note_off, send_cc, send_prog_change midi_note var byte ;midi note value: send_note_on, send_note_off midi_vel var byte ;midi velocity value: send_note_on, send_note_off midi_pgm var byte ;midi program change value: send_prog_change midi_cc var byte ;midi continuous controller number: send_cc trans_chan var byte ;midi in channel transpose (added to midi channel) trans_note var byte ;midi in note tranpose (added to note value) last_cmd var byte ;last midi command for running status midi_cmd var byte ;branch address for running status sys_cmd var byte ;branch address for system commands midi_data var byte ;variable: send_midi, get_rcx_bfr, send_note_on, send_note_off rcx_data_flg var bit ;received data flag (1=data, 0=no data): get_rcx_bfr ;-----------------------------------------------------------------------------------------------; ; Table Declarations ; ;-----------------------------------------------------------------------------------------------; patch_tbl bytetable | ;GM instrument patch names "AcouGrnd", | ; 1 "BrightAc", | ; 2 "ElecGrnd", | ; 3 "HonkyTnk", | ; 4 "ElPiano1", | ; 5 "ElPiano2", | ; 6 "Harpscrd", | ; 7 "Clavinet", | ; 8 "Celesta ", | ; 9 "Glcknspl", | ;10 "MusicBox", | ;11 "Vibraphn", | ;12 "Marimba ", | ;13 "Xylophon", | ;14 "TubBells", | ;15 "Dulcimer", | ;16 "Drawbar ", | ;17 "Perc Org", | ;18 "Rock Org", | ;19 "Church ", | ;20 "Reed Org", | ;21 "Acordian", | ;22 "Harmnica", | ;23 "TangoAcc", | ;24 "NylonGtr", | ;25 "SteelGtr", | ;26 "Jazz Gtr", | ;27 "CleanGtr", | ;28 "MutedGtr", | ;29 "OverDriv", | ;30 "Distortn", | ;31 "Harmonic", | ;32 "AcouBass", | ;33 "FingerAc", | ;34 "PickBass", | ;35 "Fretless", | ;36 "Slp1Bass", | ;37 "Slp2Bass", | ;38 "SynBass1", | ;39 "SynBass2", | ;40 "Violin ", | ;41 "Viola ", | ;42 "Cello ", | ;43 "Contra ", | ;44 "Trem Str", | ;45 "Pizicato", | ;46 "Orchestl", | ;47 "Timpani ", | ;48 "StrEnsm1", | ;49 "StrEnsm2", | ;50 "SynStr1 ", | ;51 "SynStr2 ", | ;52 "ChoirAhs", | ;53 "VoiceOhs", | ;54 "SynthVoc", | ;55 "OrchHits", | ;56 "Trumpet ", | ;57 "Trombone", | ;58 "Tuba ", | ;59 "MuteTrmp", | ;60 "FrnchHrn", | ;61 "BrassSec", | ;62 "SynBrss1", | ;63 "SynBrss2", | ;64 "SoprnSax", | ;65 "Alto Sax", | ;66 "TenorSax", | ;67 "Baritone", | ;68 "Oboe ", | ;69 "English ", | ;70 "Bassoon ", | ;71 "Clarinet", | ;72 "Piccolo ", | ;73 "Flute ", | ;74 "Recorder", | ;75 "PanFlute", | ;76 "BlownBtl", | ;77 "Shakuhac", | ;78 "Whistle ", | ;79 "Ocarina ", | ;80 "SquareWv", | ;81 "Sawtooth", | ;82 "Calliope", | ;83 "Chiff Ld", | ;84 "Charang ", | ;85 "Voice Ld", | ;86 "5thsLead", | ;87 "BassLead", | ;88 "New Age ", | ;89 "Warm Syn", | ;90 "Poly Syn", | ;91 "ChoirPad", | ;92 "BowedPad", | ;93 "Metallic", | ;94 "Halo Pad", | ;95 "SweepPad", | ;96 "Rain Fx ", | ;97 "Soundtrk", | ;98 "Crystal ", | ;99 "Atmosphr", | ;100 "Britness", | ;101 "Goblins ", | ;102 "EchoesFx", | ;103 "SciFi Fx", | ;104 "Sitar ", | ;105 "Banjo ", | ;106 "Shamisen", | ;107 "Koto ", | ;108 "Kalimba ", | ;109 "Bag Pipe", | ;110 "Fiddle ", | ;111 "Shanai ", | ;112 "TinklBel", | ;113 "Agogo ", | ;114 "SteelDrm", | ;115 "Woodblok", | ;116 "TaikoDrm", | ;117 "Melodic ", | ;118 "Syn Drum", | ;119 "RevCymbl", | ;120 "Gtr Fret", | ;121 "Breath ", | ;122 "Seashore", | ;123 "BrdTweet", | ;124 "Tel Ring", | ;125 "Helicptr", | ;126 "Applause", | ;127 "Gunshot " ;128 ;-----------------------------------------------------------------------------------------------; ; Initialization ; ;-----------------------------------------------------------------------------------------------; ; initialize: ;program specific initialization starts here ;initialize midi variables ; let midi_chan=0 ;set midi channel ; let midi_note=0 ;set midi note let midi_vel=64 ;set default velocity let midi_cmd=$0f ;set last midi command to invalid ; let trans_note=0 ;set transpose note to none ; let trans_chan=0 ;set transpose channel to none gosub send_all_off ;turn off any stuck notes #ifdef psim pause 250 ;let display initialize hserout [$f0,$7d,$0a,$18,"0123456789ABCDEF",$f7] ;clear, overwrite, name #else hserout [$f0,$7d,$0a,$18,"0123456789ABCDEFFEDCBA9876543210",$f7] ;clear, overwrite, name #endif ;speak program name #ifdef psim i2cout i2c_data,i2c_clk,($48<<1),["i am rev 1.0",$02,"i was written by Dave Brown",$03,"ready",$0d] #endif ; ;-----------------------------------------------------------------------------------------------; ; Main Program ; ;-----------------------------------------------------------------------------------------------; ; ;sample program ; loop In1-4 to Out1-4 ; flash Stop led on Aux rising edge ; loop Midi In to Midi Out ;written by David J. Brown sample: if aux_cnt<>0 then ;flash stop led for each trigger on aux_in high stop_led disable let aux_cnt=0 ;reset aux count let turn_off=time_count+15 ;set flash time enable endif let out_j1=in_j1*15/4 ;pass in's to out's let out_j2=in_j2*15/4 let out_j3=in_j3*15/4 let out_j4=in_j4*15/4 let out_j5=in_j5*15/4 let out_j6=in_j6*15/4 let out_j7=in_j7*15/4 let out_j8=in_j8*15/4 gosub load_outputs gosub proc_midi ;pass midi in to out goto sample ; ;-----------------------------------------------------------------------------------------------; ; Subroutines ; ;-----------------------------------------------------------------------------------------------; ; ;**tbd** ; ;-----------------------------------------------------------------------------------------------; ; MIDI Subroutines ; ;-----------------------------------------------------------------------------------------------; ; Revision: 1.1S2 ; Date: Sept 28, 2010 ; History: 1.1S2 modified serial syntax for Studio 2.0 ; 1.0S adapted from PSIM-CVS-CVS4 Template V1.6S ; Written: April 13, 2004 ; ; Description ; This is a MIDI template for the PSIM, CVS or CVS4 which provides: ; MIDI output functions ; MIDI protocol processing ; GM instrument name table ; ;send midi note-on command ;midi_chan is channel ;midi_note is note ;midi_vel is velocity send_note_on: hserout [keydn|midi_chan,midi_note,midi_vel] return ; ;send midi note-off command ;midi_chan is channel ;midi_note is note send_note_off: hserout [keyup|midi_chan,midi_note,0] return ; ;send midi all notes off command on all channels send_all_off: for tempb=0 to 15 ;send on all channels hserout [conctrl|tempb,allup,0] ;send all notes off next return ; ;send midi program change command ;midi_chan is channel ;midi_pgm is program change send_prog_change: hserout [pgmchg|midi_chan,midi_pgm] return ; ;send midi continuous controller command ;midi_cc is controller number ;midi_data is controller data send_cc: hserout [conctrl|midi_chan,midi_cc,midi_data] return ; ;get midi_data from buffer ;rcx_data_flg=1 if successful, rcx_data_flg=0 if no data in buffer get_rcx_bfr: let rcx_data_flg=0 ;set empty flag get_rcx_bfr1: hserin get_rcx_bfr2,0,[midi_data] if midi_data=$fe then get_rcx_bfr1 ;ignore active status let rcx_data_flg=1 ;set data returned flag get_rcx_bfr2: return ; ;send midi_data send_midi: hserout [midi_data] ;put data in transmit buffer return ; ;process midi in commands ;transposes note to midi note+trans_note ;transposes channel to midi channel+trans_chan ;written by David J. Brown proc_midi: hserin proc_none,0,[midi_data] if midi_data=$fe then proc_midi ;ignore active status high stop_led #ifdef timer_int_en disable timerwint_imiea let turn_off=time_count+20 ;set led time enable timerwint_imiea #endif if midi_data>$f7 then real_time ;check for real time if midi_data.bit7=0 then running ;check to see if running status let last_cmd=midi_data ;save command to expand running let midi_cmd=(midi_data>>4)&$07 ;strip midi channel for branch branch midi_cmd,[mkey_up,mkey_dn,key_prs,ctrl_chg,prgm_chg,chan_prs,ptch_bnd,sys_com] ; proc_none: return ; ;running status running: let tempb=(last_cmd&$f0)|((last_cmd+trans_chan)&$0f) ;expand to non-running and transpose midi channel hserout [tempb] branch midi_cmd,[mkey_upr,mkey_dnr,key_prsr,ctrl_chgr,prgm_chgr,chan_prsr,ptch_bndr,proc_none] ; ;note off command mkey_up: let midi_data=keyup|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer mkey_upr: let midi_data=midi_data+trans_note ;transpose midi note hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;note on command mkey_dn: let midi_data=keydn|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer mkey_dnr: let midi_data=midi_data+trans_note ;transpose midi note hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;key pressure command key_prs: let midi_data=chnprs|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer key_prsr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;control change command ctrl_chg: let midi_data=conctrl|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer ctrl_chgr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;program change command prgm_chg: let midi_data=pgmchg|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer prgm_chgr: hserout [midi_data] return ; ;channel pressure command chan_prs: let midi_data=chnprs|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer chan_prsr: hserout [midi_data] return ; ;pitch bend command ptch_bnd: let midi_data=pitchb|((midi_data+trans_chan)&$0f) ;transpose midi channel hserout [midi_data] gosub get_next_byte ;get data from received buffer ptch_bndr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;system common command sys_com: let sys_cmd=midi_data&$07 ;get system common command branch sys_cmd,[sys_ex,proc_none,song_ptr,song_sel,proc_none,proc_none,tune_req,proc_none] ; ;system exclusive sys_ex: hserout [midi_data] sys_ex2: gosub get_next_byte ;get data from received buffer hserout [midi_data] ;send it if midi_data<$80 then sys_ex2 ;check for end of string return ; ;song pointer command song_ptr: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;song select command song_sel: hserout [midi_data] gosub get_next_byte ;get data from received buffer hserout [midi_data] return ; ;tune_request command tune_req: hserout [midi_data] return ; ;real time commands real_time: let sys_cmd=midi_data&$07 ;strip high bits for branch branch sys_cmd,[time_clk,proc_none,start_cmd,cont_cmd,stop_cmd,proc_none,proc_none,reset_cmd] return ; ;timing clock command time_clk: hserout [midi_data] return ; ;start command start_cmd: hserout [midi_data] return ; ;continue command cont_cmd: hserout [midi_data] return ; ;stop command stop_cmd: hserout [midi_data] return ; ;reset command reset_cmd: hserout [midi_data] return ; ;wait for data and check for real time data get_next_byte: hserin get_next_byte,0,[midi_data] if midi_data=$fe then get_next_byte ;ignore active status if midi_data>$f7 then ;check for real time gosub real_time goto get_next_byte endif return ; ;-----------------------------------------------------------------------------------------------; ; Interrupt Service Routines ; ;-----------------------------------------------------------------------------------------------; ; #ifdef aux_int_en ;interrupt service routine for aux input rising edge aux_isr: let aux_cnt=aux_cnt+1 ;count number of aux interrupts resume ;ignore overflow #endif ; ; #ifdef timer_int_en ;interrupt service routine for timer ;increments time_count value ;turn off stop led at turn_off value ;toggle run led at 512 mS intervals ;written by David J. Brown tm_isr: let time_count=time_count+1 ;increment real time count if time_count=turn_off then ;value to turn off stop led low stop_led endif let run_led_out=time_count.bit9 ;toggle run led at 512 mS intervals ; #ifdef edge_int_en ;check for trigger rising edge ;pulse width must be > 1 ms timer let edge_state=edge_state<<1 ;shift previous state left let edge_state.bit0=edge_in ;set low bit to current input state if edge_state=$01 then ;edge detect requires 7 previous lows and current high let edge_flg=1 ;set edge flag endif #endif ; #ifndef input_int_en resume ;resume if input polled mode #else ;sample in-1 - in-4 at specific intervals ;injx is input averaged over last 4 samples (0 - 1023) ;injx_bfr(0) & injx_bfr(1) are last 4 word samples ;written by David J. Brown let isr_cnt=isr_cnt+1 #ifdef cvs ;change the following table to modify the scan rate for each CVS input ;175 uS execution time so maximum of one sample and average per interrupt ;currently set for: in-1 to 8 @ 8 mS branch isr_cnt, [avg1,avg2,avg3,avg4,avg5,avg6,avg7,avg8,avg1,avg2,avg3,avg4,avg5,avg6,avg7,avg8] #else ;change the following table to modify the scan rate for each PSIM input ;175 uS execution time so maximum of one sample and average per interrupt ;currently set for: in-1 @ 2 mS, in-2 @ 4 mS, in-3 @ 8 mS, in-4 @ 8 mS branch isr_cnt, [avg1,avg2,avg1,avg3,avg1,avg2,avg1,avg4,avg1,avg2,avg1,avg3,avg1,avg2,avg1,avg4] #endif #endif #endif ;-----------------------------------------------------------------------------------------------; ; End Of Program ; ;-----------------------------------------------------------------------------------------------;