;----------------------------------------------------------- ; ; 10 * 10 Relay ON/OFF Control : December 2006 ; ; for Yamaguchi ; ;----------------------------------------------------------- ;##### 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 p2ddr .equ h'0fffc1 p2dr .equ h'0fffc3 p3ddr .equ h'0fffc4 p3dr .equ h'0fffc6 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 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 led .res.b 1 p3_data .res.b 13 .org h'0ff400 rx_fifo .res.b 1024 ;***** Constant Table Defines ***** .section rom,data,locate=h'001000 table_1: .data.b 0,0,0,0,0,0,0,0 .data.b 1,1,1,1,1,1,1,1 .data.b 2,2,2,2,2,2,2,2 .data.b 3,3,3,3,3,3,3,3 .data.b 4,4,4,4,4,4,4,4 .data.b 5,5,5,5,5,5,5,5 .data.b 6,6,6,6,6,6,6,6 .data.b 7,7,7,7,7,7,7,7 .data.b 8,8,8,8,8,8,8,8 .data.b 9,9,9,9,9,9,9,9 .data.b 10,10,10,10,10,10,10,10 .data.b 11,11,11,11,11,11,11,11 .data.b 12,12,12,12 table_2: .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8,16,32,64,128 .data.b 1,2,4,8 table_3: .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 1,1,1,1,1,1,1,1 .data.b 0,0,0,0,0,0,0,0 .data.b 0,0,0,0,0,0,0,0 .data.b 0,0,0,0,0,0,0,0 .data.b 0,0,0,0,0,0,0,0 .data.b 0,0,0,0 table_4: .data.b 1,1,1,1,1,1,1,1 .data.b 2,2,2,2,2,2,2,2 .data.b 4,4,4,4,4,4,4,4 .data.b 8,8,8,8,8,8,8,8 .data.b 16,16,16,16,16,16,16,16 .data.b 32,32,32,32,32,32,32,32 .data.b 64,64,64,64,64,64,64,64 .data.b 128,128,128,128,128,128,128,128 .data.b 1,1,1,1,1,1,1,1 .data.b 2,2,2,2,2,2,2,2 .data.b 4,4,4,4,4,4,4,4 .data.b 8,8,8,8,8,8,8,8 .data.b 16,16,16,16 ;***** Reset --> Initialize --> Main Loop ***** .section program,code,locate=h'002000 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'11111111,r0l mov.b r0l,@p2ddr ; set : Port[2] all output mov.b r0l,@p3ddr ; set : Port[3] all output mov.b r0l,@paddr ; set : Port[A] all output mov.b r0l,@pbddr ; set : Port[B] all output mov.b #b'00000000,r0l mov.b r0l,@p2dr ; all L mov.b r0l,@p3dr ; all L mov.b #b'11111111,r0l mov.b r0l,@padr ; all H mov.b r0l,@pbdr ; all H mov.b #b'00000000,r0l mov.b r0l,@padr ; all L mov.b r0l,@pbdr ; all L nop nop mov.b #b'11111111,r0l mov.b r0l,@padr ; all H mov.b r0l,@pbdr ; all H 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 @rx_midi_check jmp @loop ;***** SCI init / MIDI Transmit 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 ;***** Timer / Counter Routines ***** wait_500msec: mov.l #500,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 timer_check: mov.w @timer1,r0 inc.w #1,r0 mov.w r0,@timer1 cmp.w #1000,r0 beq t_1 rts t_1: mov.w #0,r0 mov.w r0,@timer1 mov.w @timer2,r0 inc.w #1,r0 mov.w r0,@timer2 cmp.w #200,r0 beq t_2 rts t_2: mov.w #0,r0 mov.w r0,@timer2 mov.b @led,r0l mov.b r0l,r1l and.b #b'01111111,r0l xor.b #b'10000000,r1l and.b #b'10000000,r1l or.b r1l,r0l mov.b r0l,@led jsr @led_display rts led_display; mov.b @led,r0l xor.b #b'11111111,r0l mov.b r0l,@p2dr rts ;***** Rx Interrupt / MIDI Receive Routines ***** 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 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 _2byte: rts _3byte: mov.b #0,r1h mov.b r1h,@dcb mov.b r0h,@data ; velocity data ! mov.b @rsb,r0l cmp.b #h'90,r0l ; 9* event ? beq _hit_01 cmp.b #h'80,r0l ; 8* event ? beq _hit_01 rts _hit_01: mov.b #0,r0l mov.b @channel,r1l cmp.b r1l,r0l beq _hit_02 ; MIDI 1ch ? rts _hit_02: mov.b @rsb,r0l cmp.b #h'90,r0l ; 9* event ? beq _hit_03 mov.b #0,r0h mov.b r0h,@data ; velocity=0 _hit_03: mov.b @keyno,r1l mov.b @led,r0l and.b #b'10000000,r0l or.b r1l,r0l mov.b r0l,@led jsr @led_display mov.b r1l,r0l mov.b #0,r0h mov.w #0,e0 mov.l #table_1,er1 add.l er0,er1 mov.b @er1,r2h ; table_1 --> r2h : 574 NO.(0-12) mov.l #table_2,er1 add.l er0,er1 mov.b @er1,r2l ; table_2 --> r2l : bit mask mov.l #table_3,er1 add.l er0,er1 mov.b @er1,r3h ; table_3 --> r3h : 1=PA 0=PB mov.l #table_4,er1 add.l er0,er1 mov.b @er1,r3l ; table_4 --> r3l : CK mask mov.b r2h,r1l mov.b #0,r1h mov.w #0,e1 mov.b @(p3_data,er1),r4l ; to 574 data (old) mov.b r2l,r4h xor.b #b'11111111,r4h ; inv bitmask and.b r4h,r4l ; other bits mov.b @data,r0l cmp.b #0,r0l ; Note ON/Off ? beq off_event on_event: or.b r2l,r4l off_event: mov.b r4l,@(p3_data,er1) ; to 574 data (new) mov.b r4l,@p3dr mov.b #b'11111111,r1h xor.b #b'11111111,r3l cmp.b #0,r3h beq pb_write pa_write: mov.b r1h,@padr mov.b r3l,@padr nop nop mov.b r1h,@padr rts pb_write: mov.b r1h,@pbdr mov.b r3l,@pbdr nop nop mov.b r1h,@pbdr rts .end