;----------------------------------------------------------- ; ; 64 switches to MIDI : July 2002 ; ; for MAF2002 WAKABA ; ;----------------------------------------------------------- ;##### 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 p7dr .equ h'0fffce 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 ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 timer1 .res.w 1 timer2 .res.w 1 timer3 .res.w 1 tx_top .res.w 1 tx_end .res.w 1 data .res.b 1 counter .res.b 1 led .res.b 1 group .res.b 1 new .res.b 9 old .res.b 9 eve .res.b 4 .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,@p1ddr ; set : Port[1] all input mov.b r0l,@p2ddr ; set : Port[2] all input mov.b r0l,@p3ddr ; set : Port[3] all input mov.b r0l,@p4ddr ; set : Port[4] all input mov.b r0l,@p6ddr ; set : Port[6] all input mov.b r0l,@paddr ; set : Port[A] all input mov.b r0l,@pbddr ; set : Port[B] all input mov.b #b'00000010,r0l mov.b r0l,@p5ddr ; set : Port[5] out/in jsr @wait_500msec mov.b #b'00100000,r0l ; tx/rx start ! mov.b r0l,@scr loop: jsr @timer_check jsr @tx_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 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 ;***** 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,r1 inc.w #1,r1 mov.w r1,@timer1 cmp.w #2000,r1 beq _timer_1 rts _timer_1: mov.w #0,r1 mov.w r1,@timer1 jsr @sw_scan mov.w @timer2,r1 inc.w #1,r1 mov.w r1,@timer2 cmp.w #50,r1 beq _timer_2 rts _timer_2: mov.w #0,r1 mov.w r1,@timer2 mov.b @counter,r0l inc.b r0l and.b #b'01111111,r0l mov.b r0l,@counter mov.b @led,r0l bnot #1,r0l mov.b r0l,@led mov.b r0l,@p5dr ; write to Port[5] rts ;********************* sw_scan: mov.b @group,r0l inc.b r0l and.b #b'00000111,r0l mov.b r0l,@group cmp.b #0,r0l beq sw_1 cmp.b #1,r0l beq sw_2 cmp.b #2,r0l beq sw_3 cmp.b #3,r0l beq sw_4 cmp.b #4,r0l beq sw_5 cmp.b #5,r0l beq sw_6 cmp.b #6,r0l beq sw_7 bra sw_8 sw_1: mov.b @p1dr,r0l xor.b #b'11111111,r0l mov.b r0l,@new+0 mov.b @old+0,r1l cmp.b r0l,r1l bne _sw_e_1 rts _sw_e_1: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #1,r0l mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+0,r0l mov.b r0l,@old+0 rts sw_2: mov.b @p2dr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+1 ; mov.b @old+1,r1l ; cmp.b r0l,r1l bne _sw_e_2 ; rts _sw_e_2: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #9,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+1,r0l ; mov.b r0l,@old+1 ; rts sw_3: mov.b @p3dr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+2 ; mov.b @old+2,r1l ; cmp.b r0l,r1l bne _sw_e_3 ; rts _sw_e_3: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #17,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+2,r0l ; mov.b r0l,@old+2 ; rts sw_4: mov.b @p4dr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+3 ; mov.b @old+3,r1l ; cmp.b r0l,r1l bne _sw_e_4 ; rts _sw_e_4: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #25,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+3,r0l ; mov.b r0l,@old+3 ; rts sw_5: mov.b @p7dr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+4 ; mov.b @old+4,r1l ; cmp.b r0l,r1l bne _sw_e_5 ; rts _sw_e_5: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #33,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+4,r0l ; mov.b r0l,@old+4 ; rts sw_6: mov.b @padr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+5 ; mov.b @old+5,r1l ; cmp.b r0l,r1l bne _sw_e_6 ; rts _sw_e_6: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #41,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+5,r0l ; mov.b r0l,@old+5 ; rts sw_7: mov.b @pbdr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+6 ; mov.b @old+6,r1l ; cmp.b r0l,r1l bne _sw_e_7 ; rts _sw_e_7: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #49,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check mov.b @new+6,r0l ; mov.b r0l,@old+6 ; rts sw_8: mov.b @p6dr,r0l ; xor.b #b'11111111,r0l mov.b r0l,@new+7 ; mov.b @old+7,r1l ; cmp.b r0l,r1l bne _sw_e_8 ; bra sw_9 _sw_e_8: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #57,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check2 mov.b @new+7,r0l ; mov.b r0l,@old+7 ; sw_9: mov.b @p5dr,r0l ; xor.b #b'11111111,r0l and.b #b'00000001,r0l mov.b r0l,@new+8 ; mov.b @old+8,r1l ; cmp.b r0l,r1l bne _sw_e_9 ; rts _sw_e_9: mov.b r0l,@eve+0 ; [+0] new status mov.b r1l,@eve+1 ; [+1] old status xor.b r0l,r1l mov.b r1l,@eve+2 ; [+2] event bit = 1 mov.b #64,r0l ; mov.b r0l,@eve+3 ; [+3] Offset ! jsr @sw_check3 mov.b @new+8,r0l ; mov.b r0l,@old+8 ; rts sw_check: mov.b #0,r4h ; Loop Counter mov.b #1,r4l ; Bit Mask _sw_loop: mov.b @eve+2,r0l and.b r4l,r0l bne _sw_eve1 shll.b r4l inc.b r4h cmp.b #8,r4h bne _sw_loop rts _sw_eve1: mov.b #h'90,r0h jsr @tx_fifo_set mov.b r4h,r3l mov.b @eve+3,r0h add.b r3l,r0h ; Key Number jsr @tx_fifo_set mov.b @eve+0,r0l and.b r4l,r0l beq _sw_off _sw_on: mov.b #127,r0h jsr @tx_fifo_set rts _sw_off: mov.b #0,r0h jsr @tx_fifo_set rts sw_check2: mov.b #0,r4h ; Loop Counter mov.b #1,r4l ; Bit Mask _sw_loop2: mov.b @eve+2,r0l and.b r4l,r0l bne _sw_eve2 shll.b r4l inc.b r4h cmp.b #7,r4h bne _sw_loop2 rts _sw_eve2: mov.b #h'90,r0h jsr @tx_fifo_set mov.b r4h,r3l mov.b @eve+3,r0h add.b r3l,r0h ; Key Number jsr @tx_fifo_set mov.b @eve+0,r0l and.b r4l,r0l beq _sw_off2 _sw_on2: mov.b #127,r0h jsr @tx_fifo_set rts _sw_off2: mov.b #0,r0h jsr @tx_fifo_set rts sw_check3: mov.b #1,r4l ; Bit Mask mov.b @eve+2,r0l and.b r4l,r0l bne _sw_eve3 rts _sw_eve3: mov.b #h'90,r0h jsr @tx_fifo_set mov.b @eve+3,r0h jsr @tx_fifo_set mov.b @eve+0,r0l and.b r4l,r0l beq _sw_off3 _sw_on3: mov.b #127,r0h jsr @tx_fifo_set rts _sw_off3: mov.b #0,r0h jsr @tx_fifo_set rts .end