;----------------------------------------------------------- ; ; [Roll Piano to MIDI] July 2004 ; ;----------------------------------------------------------- ;##### 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 p6ddr .equ h'0fffc9 p6dr .equ h'0fffcb 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 old0 .res.b 8 old1 .res.b 8 led .res.b 1 offset .res.b 1 note .res.b 1 phase .res.b 1 .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'11111111,r0l mov.b r0l,@p1ddr ; set : Port[1] all output mov.b r0l,@p6ddr ; set : Port[6] all output mov.b r0l,@p1dr mov.b #b'00000000,r0l mov.b r0l,@p2ddr ; set : Port[2] all input jsr @wait_500msec mov.b #b'01110000,r0l ; tx/rx start ! mov.b r0l,@scr main_loop: jsr @timer_check jsr @tx_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 ;***** MIDI / Timer / Counter Routines ***** 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 #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.w @timer1,r0 inc.w #1,r0 mov.w r0,@timer1 cmp.w #100,r0 beq _timer_hit1 rts _timer_hit1: mov.w #0,r0 mov.w r0,@timer1 jsr @event_check mov.w @timer2,r0 inc.w #1,r0 mov.w r0,@timer2 cmp.w #1500,r0 beq _timer_hit2 rts _timer_hit2: mov.w #0,r0 mov.w r0,@timer2 mov.b @led,r0l xor.b #b'11111111,r0l mov.b r0l,@led mov.b r0l,@p6dr rts event_check: bra _timer_pass ; max scan speed mov.w @timer3,r0 inc.w #1,r0 mov.w r0,@timer3 cmp.w #10,r0 beq _timer_hit3 rts _timer_hit3: mov.w #0,r0 mov.w r0,@timer3 _timer_pass: mov.b @phase,r5l mov.b r5l,r4l ; [R5L] current phase inc.b r4l cmp.b #7,r4l bne _hit4 mov.b #0,r4l _hit4: mov.b r4l,@phase ; next check phase mov.b #0,r5h mov.w #0,e5 mov.b @(table_2,er5),r0l mov.b r0l,@p1dr mov.b @p2dr,r0h _scan1: nop nop mov.b @p2dr,r0l cmp.b r0h,r0l beq _scan2 mov.b r0l,r0h bra _scan1 _scan2: xor.b #b'11111111,r0l mov.b r0l,r3l ; [R3L] current data mov.b #b'11111111,r0l mov.b r0l,@p1dr mov.b @(old0,er5),r2l ; [R2L] old data cmp.b r3l,r2l beq _ok_data mov.b r3l,@(old0,er5) ; [R3L] current data set rts _ok_data: mov.b @(old1,er5),r2l ; [R2L] very old data cmp.b r3l,r2l bne _hit5 rts _hit5: mov.b r3l,@(old1,er5) ; very old data set xor.b r3l,r2l ; [R2L] event bits mov.b @(table_1,er5),r0l mov.b r0l,@offset mov.b #0,r2h ; loop counter mov.b #b'00000001,r1h ; bit mask _hit6: mov.b r2l,r4l and.b r1h,r4l cmp.b #0,r4l beq _hit7 ; non event mov.b @offset,r0l add.b r2h,r0l mov.b r0l,@note mov.b r3l,r3h and.b r1h,r3h beq _off_eve _on_eve: mov.b @note,r0l ; Chattering Filter ! cmp.b #44,r0l ; bmi _hit7 ; cmp.b #76,r0l ; bpl _hit7 ; Chattering Filter ! mov.b #h'90,r0h jsr @tx_fifo_set mov.b @note,r0h jsr @tx_fifo_set mov.b #h'7f,r0h jsr @tx_fifo_set bra _hit7 _off_eve: mov.b @note,r0l ; Chattering Filter ! cmp.b #44,r0l ; bmi _hit7 ; cmp.b #76,r0l bpl _hit7 ; Chattering Filter ! mov.b #h'90,r0h jsr @tx_fifo_set mov.b @note,r0h jsr @tx_fifo_set mov.b #h'00,r0h jsr @tx_fifo_set _hit7: cmp.b #6,r5l bne _hit8 rts _hit8: shll.b r1h inc.b r2h cmp.b #8,r2h bne _hit6 rts table_1: .data.b 36,44,52,60,68,76,84,0 ; key offset table_2: .data.b 255-1,255-2,255-4,255-8,255-16,255-32,255-64,255 ; 573 OC .end