;AY play midi note table2.bas ;THeff 6-30-12 #Picaxe 28X2 ;#No_Data ;#No_Table ;#Terminal 76800 ;****************** Constant Definitions ****************** symbol control = outpinsA ;control lines to the AY chip symbol BC1 = A.0 ;A.0 is BC1 on the AY chip symbol BDIR = A.1 ;A.1 is BDIR on the AY chip symbol bus = outpinsB ;data/address bus to AY chip symbol AYpulse = 4 ;2.5 uSec for pulsout ;AY-8910 control codes and register addresses symbol inactive = %00000000 symbol latchAddr = %00000011 symbol Reg7 = %00000111 ;Register 7 - data direction symbol Reg14 = %00001110 ;Register 14 - Port IOB symbol IOAOut = %11111110 ;enable IOA and tone A ;MIDI message bytes ;Symbol CHANNEL = 1 ' MIDI Channel = 1 To 16 ;Symbol CHANNEL_MINUS_1 = CHANNEL - 1 ' .--- Bytes in message ' |.-- Status byte ' ||_ ;Symbol NOTE_ON = $390 + CHANNEL_MINUS_1 ;Symbol NOTE_OFF = $380 + CHANNEL_MINUS_1 ;****************** Variable Definitions ****************** Symbol status = w0 ' b1:b0 Symbol statusByte = b0 Symbol statusCount = b1 Symbol argW = w1 ' b3:b2 Symbol arg2 = b2 Symbol arg1 = b3 symbol char = b4 ;ASCII character to be displayed symbol cmd = b4 ;an alias for the char byte symbol i = b5 ;loop variable symbol msg = b6 ;offset into message table symbol index = b7 ;pointer to current character symbol temp = b8 ;temporary LCD data byte built here symbol row = b9 ;current LCD row symbol col = b10 ;current LCD column symbol eelsb = b11 ;LSB data read symbol eemsb = b12 ;MSB data read symbol midival = b13 ;MIDI note & LSBvalue symbol midimsb = b14 ;MIDI MSB value symbol value = b15 ;register number (0-15) symbol register = b16 ;value to store in register ;*********************** Messages ************************* ;eeprom 0, ("Note On") ;0 ;eeprom 7, ("Note Off") ;1 ;********************** Main Program ********************** pgm: SetFreq EM64 ;64 MHz external resonator dirsA = %00001111 ;A.0-A.3 are outputs dirsB = %11111111 ;B.0-B.7 are outputs dirsC = %00000010 ;C.2-C.6 are inputs pwmout C.1, 7, 16 ;start AY clock at 2 MHz gosub init ;initialize AY and LCD display register = 8 ;make Tone A fixed on value = %00001111 gosub store MainLoop: for midival = 24 to 131 midimsb = midival + 120 readtable midival,eelsb readtable midimsb,eemsb SerTxd("Note # ",#midival,9,"MSB ",#eemsb,9,"LSB ",#eelsb, CR, LF) register = 0 ;frequency LSB value = eelsb gosub store register = 1 ;frequncy MSB value = eemsb gosub store pause 1600 next midival goto mainloop end ;************* Initialize AY on power-up ************* init: control = inactive ;clear BC1, BDIR ;set up the AY Port IOA for output control = latchAddr ;latch address to register 7 bus = Reg7 control = inactive bus = IOAOut ;enable IOA and Tone A pulsout BDIR,AYpulse control = latchAddr ;latch address to register 15 bus = Reg14 control = inactive bus = $FF ;turn all gates off pulsout BDIR,AYPulse return ;*************** Send Value to AY Register ************** ;Pass in register and value at entry store: control = inactive ;clear BC1, BDIR control = latchAddr ;latch address of register bus = register control = inactive bus = value ;get value and pulsout BDIR,AYPulse ;store it return ; msb offset is 120, e.g. the lsb is at midi_note and msb is at midi_note + 120 ;*********************** Note LSB Values ************************* table 12,(221) ;C0 table 13,(47) ;C#0 table 14,(154) ;D0 table 15,(28) ;D#0 table 16,(179) ;E0 table 17,(95) ;F0 table 18,(29) ;F#0 table 19,(238) ;G0 table 20,(208) ;G#0 table 21,(193) ;A0 table 22,(194) ;A#0 table 23,(210) ;B0 table 24,(238) ;C1 table 25,(24) ;C#1 table 26,(77) ;D1 table 27,(142) ;D#1 table 28,(218) ;E1 table 29,(47) ;F1 table 30,(143) ;F#1 table 31,(247) ;G1 table 32,(104) ;G#1 table 33,(225) ;A1 table 34,(97) ;A#1 table 35,(233) ;B1 table 36,(119) ;C2 table 37,(12) ;C#2 table 38,(167) ;D2 table 39,(71) ;D#2 table 40,(237) ;E2 table 41,(152) ;F2 table 42,(71) ;F#2 table 43,(252) ;G2 table 44,(180) ;G#2 table 45,(112) ;A2 table 46,(49) ;A#2 table 47,(244) ;B2 table 48,(188) ;C3 table 49,(134) ;C#3 table 50,(83) ;D3 table 51,(36) ;D#3 table 52,(246) ;E3 table 53,(204) ;F3 table 54,(164) ;F#3 table 55,(126) ;G3 table 56,(90) ;G#3 table 57,(56) ;A3 table 58,(24) ;A#3 table 59,(250) ;B3 table 60,(222) ;C4 table 61,(195) ;C#4 table 62,(170) ;D4 table 63,(146) ;D#4 table 64,(123) ;E4 table 65,(102) ;F4 table 66,(82) ;F#4 table 67,(63) ;G4 table 68,(45) ;G#4 table 69,(28) ;A4 table 70,(12) ;A#4 table 71,(253) ;B4 table 72,(239) ;C5 table 73,(225) ;C#5 table 74,(213) ;D5 table 75,(201) ;D#5 table 76,(190) ;E5 table 77,(179) ;F5 table 78,(169) ;F#5 table 79,(159) ;G5 table 80,(150) ;G#5 table 81,(142) ;A5 table 82,(134) ;A#5 table 83,(127) ;B5 table 84,(119) ;C6 table 85,(113) ;C#6 table 86,(106) ;D6 table 87,(100) ;D#6 table 88,(95) ;E6 table 89,(89) ;F6 table 90,(84) ;F#6 table 91,(80) ;G6 table 92,(75) ;G#6 table 93,(71) ;A6 table 94,(67) ;A#6 table 95,(63) ;B6 table 96,(60) ;C7 table 97,(56) ;C#7 table 98,(53) ;D7 table 99,(50) ;D#7 table 100,(47) ;E7 table 101,(45) ;F7 table 102,(42) ;F#7 table 103,(40) ;G7 table 104,(38) ;G#7 table 105,(36) ;A7 table 106,(34) ;A#7 table 107,(32) ;B7 table 108,(30) ;C8 table 109,(28) ;C#8 table 110,(27) ;D8 table 111,(25) ;D#8 table 112,(24) ;E8 table 113,(22) ;F8 table 114,(21) ;F#8 table 115,(20) ;G8 table 116,(19) ;G#8 table 117,(18) ;A8 table 118,(17) ;A#8 table 119,(16) ;B8 table 120,(15) ;C9 table 121,(14) ;C#9 table 122,(13) ;D9 table 123,(13) ;D#9 table 124,(12) ;E9 table 125,(11) ;F9 table 126,(11) ;F#9 table 127,(10) ;G9 table 128,(9) ;G#9 table 129,(9) ;A9 table 130,(8) ;A#9 table 131,(8) ;B9 ;*********************** Note MSB Values ************************* table 132, (29) ;C0 table 133, (28) ;C#0 table 134, (26) ;D0 table 135, (25) ;D#0 table 136, (23) ;E0 table 137, (22) ;F0 table 138, (21) ;F#0 table 139, (19) ;G0 table 140, (18) ;G#0 table 141, (17) ;A0 table 142, (16) ;A#0 table 143, (15) ;B0 table 144, (14) ;C1 table 145, (14) ;C#1 table 146, (13) ;D1 table 147, (12) ;D#1 table 148, (11) ;E1 table 149, (11) ;F1 table 150, (10) ;F#1 table 151, (9) ;G1 table 152, (9) ;G#1 table 153, (8) ;A1 table 154, (8) ;A#1 table 155, (7) ;B1 table 156, (7) ;C2 table 157, (7) ;C#2 table 158, (6) ;D2 table 159, (6) ;D#2 table 160, (5) ;E2 table 161, (5) ;F2 table 162, (5) ;F#2 table 163, (4) ;G2 table 164, (4) ;G#2 table 165, (4) ;A2 table 166, (4) ;A#2 table 167, (3) ;B2 table 168, (3) ;C3 table 169, (3) ;C#3 table 170, (3) ;D3 table 171, (3) ;D#3 table 172, (2) ;E3 table 173, (2) ;F3 table 174, (2) ;F#3 table 175, (2) ;G3 table 176, (2) ;G#3 table 177, (2) ;A3 table 178, (2) ;A#3 table 179, (1) ;B3 table 180, (1) ;C4 table 181, (1) ;C#4 table 182, (1) ;D4 table 183, (1) ;D#4 table 184, (1) ;E4 table 185, (1) ;F4 table 186, (1) ;F#4 table 187, (1) ;G4 table 188, (1) ;G#4 table 189, (1) ;A4 table 190, (1) ;A#4 table 191, (0) ;B4 table 192, (0) ;C5 table 193, (0) ;C#5 table 194, (0) ;D5 table 195, (0) ;D#5 table 196, (0) ;E5 table 197, (0) ;F5 table 198, (0) ;F#5 table 199, (0) ;G5 table 200, (0) ;G#5 table 201, (0) ;A5 table 202, (0) ;A#5 table 203, (0) ;B5 table 204, (0) ;C6 table 205, (0) ;C#6 table 206, (0) ;D6 table 207, (0) ;D#6 table 208, (0) ;E6 table 209, (0) ;F6 table 210, (0) ;F#6 table 211, (0) ;G6 table 212, (0) ;G#6 table 213, (0) ;A6 table 214, (0) ;A#6 table 215, (0) ;B6 table 216, (0) ;C7 table 217, (0) ;C#7 table 218, (0) ;D7 table 219, (0) ;D#7 table 220, (0) ;E7 table 221, (0) ;F7 table 222, (0) ;F#7 table 223, (0) ;G7 table 224, (0) ;G#7 table 225, (0) ;A7 table 226, (0) ;A#7 table 227, (0) ;B7 table 228, (0) ;C8 table 229, (0) ;C#8 table 230, (0) ;D8 table 231, (0) ;D#8 table 232, (0) ;E8 table 233, (0) ;F8 table 234, (0) ;F#8 table 235, (0) ;G8 table 236, (0) ;G#8 table 237, (0) ;A8 table 238, (0) ;A#8 table 239, (0) ;B8 table 240, (0) ;C9 table 241, (0) ;C#9 table 242, (0) ;D9 table 243, (0) ;D#9 table 244, (0) ;E9 table 245, (0) ;F9 table 246, (0) ;F#9 table 247, (0) ;G9 table 248, (0) ;G#9 table 249, (0) ;A9 table 250, (0) ;A#9 table 251, (0) ;B9