;----------------------------------------------------------- ; ; [Meisou_LED-3] February 2002 ; ;----------------------------------------------------------- ;##### 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 p1ddr .equ h'0fffc0 p1dr .equ h'0fffc2 p2ddr .equ h'0fffc1 p2dr .equ h'0fffc3 p3ddr .equ h'0fffc4 p3dr .equ h'0fffc6 p4ddr .equ h'0fffc5 p4dr .equ h'0fffc7 p5ddr .equ h'0fffc8 p5dr .equ h'0fffca p6ddr .equ h'0fffc9 p6dr .equ h'0fffcb p8ddr .equ h'0fffcd p8dr .equ h'0fffcf 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 rx_top .res.w 1 rx_end .res.w 1 pdata .res.b 8 rsb .res.b 1 channel .res.b 1 dcb .res.b 1 keyno .res.b 1 data .res.b 1 ctr .res.b 1 .org h'0ff300 setd .res.b 64 dat .res.b 64 .org h'0ff400 rx_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'11111111,r0l mov.b r0l,@pbddr ; set : Port[B] all output mov.b r0l,@paddr ; set : Port[A] all output mov.b r0l,@p8ddr ; set : Port[8] all output mov.b r0l,@p6ddr ; set : Port[6] all output mov.b r0l,@p5ddr ; set : Port[5] all output mov.b r0l,@p4ddr ; set : Port[4] all output mov.b r0l,@p3ddr ; set : Port[3] all output mov.b r0l,@p2ddr ; set : Port[2] all output mov.b r0l,@p1ddr ; set : Port[1] all output mov.b #b'11111111,r0l mov.b r0l,@pbdr mov.b r0l,@padr mov.b r0l,@p8dr mov.b r0l,@p6dr mov.b r0l,@p5dr mov.b r0l,@p4dr mov.b r0l,@p3dr mov.b r0l,@p2dr mov.b r0l,@p1dr jsr @wait_500msec mov.b #b'01010000,r0l ; tx/rx start ! mov.b r0l,@scr andc.b #b'01111111,ccr ; interrupt enable main_loop: jsr @job_timer jsr @rx_midi_check jmp @main_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,er5 _wait_2: sub.l #1,er5 bne _wait_2 rts timer_check: mov.b @timer1,r0l inc.b r0l mov.b r0l,@timer1 cmp.b #10,r0l beq _timer_hit rts _timer_hit: mov.b #0,r0l mov.b r0l,@timer1 jsr @job_timer 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 mov.b @rsb,r0l cmp.b #h'a0,r0l ; A* event ? beq _hit_01 rts _hit_01: mov.b @channel,r0l cmp.b #h'0f,r0l beq _hit_02 rts _hit_02: mov.l #setd,er4 mov.b @keyno,r4l mov.b @data,r0l mov.b r0l,@er4 rts ;***** Software Timer Routine ***** job_timer: mov.b @ctr,r5h dec.b r5h mov.b r5h,@ctr bne _job_1 mov.b #128,r0l mov.b r0l,@ctr _job_1: mov.l #dat+0,er6 mov.l #setd+0,er4 jsr @led_sub ; 0 - 7 mov.b r1h,@p1dr jsr @led_sub ; 8 - 15 mov.b r1h,@p2dr jsr @led_sub ; 16 - 23 mov.b r1h,@p3dr jsr @led_sub ; 24 - 31 mov.b r1h,@p4dr jsr @led_sub ; 32 - 39 mov.b r1h,r5l and.b #b'00011111,r1h mov.b r1h,@p8dr and.b #b'11100000,r5l rotl.b r5l rotl.b r5l rotl.b r5l jsr @led_sub ; 40 - 47 mov.b r1h,r1l and.b #b'00001111,r1h mov.b r1h,@p5dr and.b #b'11110000,r1l shlr.b r1l or.b r1l,r5l mov.b r5l,@p6dr jsr @led_sub ; 48 - 55 mov.b r1h,@padr jsr @led_sub ; 56 - 63 mov.b r1h,@pbdr rts led_sub: mov.b #8,r3h ; loop counter mov.b #b'00000001,r2h ; bit mask mov.b #0,r1h ; bit buffer _loop01: mov.b @er6,r0l beq _loop02 or.b r2h,r1h ; ON ! dec.b r0l mov.b r0l,@er6 _loop02: shal.b r2h cmp.b #0,r5h bne _loop03 mov.b @er4,r0l mov.b r0l,@er6 _loop03: inc.b r4l inc.b r6l dec.b r3h bne _loop01 xor.b #b'11111111,r1h rts .end