;----------------------------------------------------------- ; ; Box/SW scan --> MIDI, MIDI --> 8 LEDs : July 2012 ; ; for Installation "Color Orchestra" ; ;----------------------------------------------------------- ;##### Port Defines ##### smr .equ h'0fffb0 brr .equ h'0fffb1 scr .equ h'0fffb2 tdr .equ h'0fffb3 ssr .equ h'0fffb4 rdr .equ h'0fffb5 p3ddr .equ h'0fffc4 p3dr .equ h'0fffc6 p4ddr .equ h'0fffc5 p4dr .equ h'0fffc7 paddr .equ h'0fffd1 padr .equ h'0fffd3 pbddr .equ h'0fffd4 pbdr .equ h'0fffd6 iprb .equ h'0ffff8 ;##### Vector Defines ##### .section vector,data,locate=h'000000 .data.l start .org h'0000d0 .data.l int_rx_error .data.l int_rx_full ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 timer1 .res.w 1 timer2 .res.w 1 tx_top .res.w 1 tx_end .res.w 1 rx_top .res.w 1 rx_end .res.w 1 rsb .res.b 1 channel .res.b 1 dcb .res.b 1 keyno .res.b 1 data .res.b 1 sw_old .res.b 1 sw_new .res.b 1 box_dt .res.b 1 box_no .res.b 1 box_old .res.b 44 .org h'0ff400 rx_fifo .res.b 1024 .org h'0ff800 tx_fifo .res.b 1024 ;***** Reset --> Initialize --> Main Loop ***** .section program,code,locate=h'001000 start: mov.l #h'0fff0f,er7 ; stack pointer set mov.l #h'0fef10,er2 mov.w #h'0fe0,r1 mov.b #0,r0l _ram_clear: mov.b r0l,@er2 inc.l #1,er2 dec.w #1,r1 bne _ram_clear jsr @sci0_init ; SCI initialize mov.b #b'00000000,r0l mov.b r0l,@p3ddr ; set : Port[3] all input mov.b r0l,@p4ddr ; set : Port[4] all input mov.b #b'11111111,r0l mov.b r0l,@pbddr ; set : Port[B] all output mov.b r0l,@paddr ; set : Port[A] all output mov.b #b'11111111,r0l mov.b r0l,@pbdr ; LED all OFF ! mov.b #b'00000000,r0l mov.b r0l,@padr mov.b r0l,@sw_old mov.b r0l,@box_no mov.w #0,e2 mov.w #0,r2 mov.b #b'11111111,r0l _box_clr: mov.b r0l,@(box_old,er2) inc.b r2l cmp.b #44,r2l bne _box_clr jsr @wait_500msec mov.b #b'01110000,r0l ; tx/rx start ! mov.b r0l,@scr andc.b #b'01111111,ccr ; interrupt enable loop: jsr @timer_check jsr @tx_midi_check jsr @rx_midi_check bra loop ;***** Common Sub-Routines ***** sci0_init: mov.b #b'00000000,r0l mov.b r0l,@scr mov.b #b'00000000,r0l mov.b r0l,@smr mov.b #15,r0l mov.b r0l,@brr mov.w #500,r0 _sci0_wait: dec.w #1,r0 bne _sci0_wait mov.b @ssr,r0l ; (dummy read) mov.b #0,r0l mov.b r0l,@ssr mov.b #b'00001000,r0l mov.b r0l,@iprb ; SCI0-int priority UP ! rts int_rx_error: bclr #5,@ssr bclr #4,@ssr rte int_rx_full: push.w r0 push.l er5 btst #6,@ssr bclr #6,@ssr mov.w @rx_top,r5 mov.w #0,e5 mov.b @rdr,r0l mov.b r0l,@(rx_fifo,er5) inc.w #1,r5 bclr #2,r5h mov.w r5,@rx_top pop.l er5 pop.w r0 rte tx_midi_check: mov.w @tx_top,r1 mov.w @tx_end,r6 cmp.w r1,r6 bne _tx_exist rts _tx_exist: btst #7,@ssr ; test TRDE bne _tx_seq rts _tx_seq: mov.w #0,e6 mov.b @(tx_fifo,er6),r0l mov.b r0l,@tdr bclr #7,@ssr ; Transmit ! inc.w #1,r6 bclr #2,r6h mov.w r6,@tx_end rts tx_fifo_set: mov.w @tx_top,r6 mov.w #0,e6 mov.b r0h,@(tx_fifo,er6) ; transmit data = [r0h] inc.w #1,r6 bclr #2,r6h mov.w r6,@tx_top rts wait_500msec: mov.l #1000,er1 _wait_1: jsr @wait_1msec sub.l #1,er1 bne _wait_1 rts wait_1msec: mov.l #2048,er2 _wait_2: sub.l #1,er2 bne _wait_2 rts ;***** Switch scan routine ***** timer_check: mov.w @timer1,r1 inc.w #1,r1 mov.w r1,@timer1 cmp.w #500,r1 beq _timer00_1 rts _timer00_1: mov.w #0,r1 mov.w r1,@timer1 jsr @sw_scan_00 jsr @box_scan rts sw_scan_00: mov.w @timer2,r1 inc.w #1,r1 mov.w r1,@timer2 cmp.w #50,r1 beq _timer00_2 rts _timer00_2: mov.w #0,r1 mov.w r1,@timer2 jsr @sw_scan_go rts sw_scan_go: mov.b @p3dr,r3l xor.b #b'11111111,r3l mov.b r3l,@sw_new mov.b @sw_old,r3h xor.b r3l,r3h ; [R3H] event bit = 1 cmp.b #0,r3h bne sw_scan_01 rts sw_scan_01: mov.b #b'00000001,r2l ; [R2L] bit mask mov.b #b'00000000,r2h ; [R2H] counter (0-7) sw_scan_02: mov.b r3h,r3l and.b r2l,r3l cmp.b #0,r3l beq sw_scan_03 mov.b @sw_new,r3l and.b r2l,r3l cmp.b #0,r3l beq sw_scan_03 mov.b #h'cf,r0h jsr @tx_fifo_set mov.b r2h,r0h jsr @tx_fifo_set sw_scan_03: shll.b r2l inc.b r2h cmp.b #8,r2h bne sw_scan_02 mov.b @sw_new,r3l mov.b r3l,@sw_old rts ;***** MIDI Receive Routine ***** rx_midi_check: mov.w @rx_top,r1 mov.w @rx_end,r5 cmp.w r1,r5 bne _rx_exist rts _rx_exist: mov.w #0,e5 mov.b @(rx_fifo,er5),r0h ; received data = [r0h] inc.w #1,r5 bclr #2,r5h mov.w r5,@rx_end btst #7,r0h beq running mov.b r0h,r0l and.b #b'11111000,r0l cmp.b #b'11111000,r0l bne _lower_f8 rts _lower_f8: and.b #b'11110000,r0l cmp.b #b'11110000,r0l bne _lower_f0 mov.b #0,r0l mov.b r0l,@rsb rts _lower_f0 mov.b r0h,r0l and.b #b'00001111,r0l mov.b r0l,@channel mov.b r0h,r0l and.b #b'11110000,r0l mov.b r0l,@rsb mov.b #0,r0l mov.b r0l,@dcb rts running: mov.b @rsb,r0l bne _normal rts _normal: cmp.b #b'11000000,r0l beq _2byte cmp.b #b'11010000,r0l beq _2byte mov.b @dcb,r1l bne _3byte inc.b r1l mov.b r1l,@dcb mov.b r0h,@keyno rts _3byte: rts _2byte: mov.b #0,r1h mov.b r1h,@dcb mov.b r0h,@data mov.b @rsb,r0l mov.b @channel,r0h or.b r0h,r0l cmp.b #h'CF,r0l ; CF ? beq _hit_01 rts _hit_01: mov.b @data,r0h cmp.b #0,r0h beq _led_0 cmp.b #1,r0h beq _led_1 cmp.b #2,r0h beq _led_2 cmp.b #3,r0h beq _led_3 cmp.b #4,r0h beq _led_4 cmp.b #5,r0h beq _led_5 cmp.b #6,r0h beq _led_6 cmp.b #7,r0h beq _led_7 cmp.b #127,r0h beq _led_127 bra _led_off rts _led_0: mov.b #b'00000001,r1h bra _led_send _led_1: mov.b #b'00000010,r1h bra _led_send _led_2: mov.b #b'00000100,r1h bra _led_send _led_3: mov.b #b'00001000,r1h bra _led_send _led_4: mov.b #b'00010000,r1h bra _led_send _led_5: mov.b #b'00100000,r1h bra _led_send _led_6 mov.b #b'01000000,r1h bra _led_send _led_7: mov.b #b'10000000,r1h bra _led_send _led_127: mov.b #b'11111111,r1h bra _led_send _led_off: mov.b #b'00000000,r1h _led_send: xor.b #b'11111111,r1h mov.b r1h,@pbdr rts ;***** BOX scan routine ***** box_scan: mov.b @p4dr,r4h ; [R4H] scanned new data for box NO. xor.b #h'FF,r4h mov.w #0,e2 mov.b #0,r2h mov.b @box_no,r2l mov.b @(box_old,er2),r3l cmp.b r4h,r3l beq _box_next mov.b r4h,@(box_old,er2) cmp.b #b'00000000,r4h beq _box_8 cmp.b #b'00000001,r4h beq _box_0 cmp.b #b'00000010,r4h beq _box_1 cmp.b #b'00000100,r4h beq _box_2 cmp.b #b'00001000,r4h beq _box_3 cmp.b #b'00010000,r4h beq _box_4 cmp.b #b'00100000,r4h beq _box_5 cmp.b #b'01000000,r4h beq _box_6 cmp.b #b'10000000,r4h beq _box_7 mov.b #9,r3l bra _box_send _box_8: mov.b #8,r3l bra _box_send _box_0: mov.b #0,r3l bra _box_send _box_1: mov.b #1,r3l bra _box_send _box_2: mov.b #2,r3l bra _box_send _box_3: mov.b #3,r3l bra _box_send _box_4: mov.b #4,r3l bra _box_send _box_5: mov.b #5,r3l bra _box_send _box_6: mov.b #6,r3l bra _box_send _box_7: mov.b #7,r3l _box_send: mov.b r3l,@box_dt mov.b #h'bf,r0h jsr @tx_fifo_set mov.b @box_no,r0h jsr @tx_fifo_set mov.b @box_dt,r0h jsr @tx_fifo_set _box_next: mov.b @box_no,r0l inc.b r0l cmp.b #44,r0l bne _box_exit mov.b #0,r0l _box_exit: ; mov.b #26,r0l ; ###################### mov.b r0l,@box_no mov.b r0l,@padr rts .end