;----------------------------------------------------------- ; ; [Kawarazaki - 384 SW scan to MIDI] February 2007 ; ;----------------------------------------------------------- ;##### 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 paddr .equ h'0fffd1 padr .equ h'0fffd3 pbddr .equ h'0fffd4 pbdr .equ h'0fffd6 iprb .equ h'0ffff8 tstr .equ h'0fff60 tsnc .equ h'0fff61 tmdr .equ h'0fff62 tfcr .equ h'0fff63 toer .equ h'0fff90 tocr .equ h'0fff91 tcr0 .equ h'0fff64 tior0 .equ h'0fff65 tier0 .equ h'0fff66 tsr0 .equ h'0fff67 tcnt0 .equ h'0fff68 gra0 .equ h'0fff6a ;##### Vector Defines ##### .section vector,data,locate=h'000000 .data.l start .org h'000060 .data.l int_timer0 ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 tx_top .res.w 1 tx_end .res.w 1 div_d .res.w 1 div_t .res.w 1 tap_cnt .res.w 1 bank .res.b 64 phase .res.b 1 timer1 .res.b 1 timer2 .res.b 1 flag .res.b 1 plane .res.b 1 line .res.b 1 mask .res.b 1 buff .res.b 1 .org h'0ff400 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 mov.b #b'00100011,r0l mov.b r0l,@tcr0 ; Timer0 init : 2MHz clock bclr #0,@tsr0 ; Clear IMFA bset #0,@tier0 ; timer INT set mov.w #2000,r0 ; 1msec INT mov.w r0,@gra0 jsr @sci0_init ; SCI initialize mov.b #b'00000000,r0l mov.b r0l,@p2ddr ; set : Port[2] all input mov.b #b'11111111,r0l mov.b r0l,@paddr ; set : Port[A] all output mov.b r0l,@pbddr ; set : Port[B] all output mov.b r0l,@padr ; Port[A] all High - enable sig mov.b r0l,@pbdr ; Port[B] all High - Latch Pulse mov.b #b'00100000,r0l ; tx start ! mov.b r0l,@scr bset #0,@tstr ; timer start ! andc.b #b'01111111,ccr ; interrupt enable main_loop: jsr @timer_check jsr @tx_midi_check jmp @main_loop ;***** Main Routines ***** timer_check: mov.b @flag,r0l bne _timer_event rts _timer_event: mov.b #0,r0l mov.b r0l,@flag mov.b @timer2,r0l inc.b r0l mov.b r0l,@timer2 cmp.b #10,r0l beq _10msec rts _10msec: mov.b #0,r0l mov.b r0l,@timer2 mov.b @plane,r1h inc.b r1h cmp.b #6,r1h bne _sw_check mov.b #0,r1h _sw_check: mov.b r1h,@plane cmp.b #1,r1h beq plane_1 cmp.b #2,r1h beq plane_2 cmp.b #3,r1h beq plane_3 cmp.b #4,r1h beq plane_4 cmp.b #5,r1h beq plane_5 plane_0: mov.b #b'11111110,r0l bra plane_mix plane_1: mov.b #b'11111101,r0l bra plane_mix plane_2: mov.b #b'11111011,r0l bra plane_mix plane_3: mov.b #b'11110111,r0l bra plane_mix plane_4: mov.b #b'11101111,r0l bra plane_mix plane_5: mov.b #b'11011111,r0l plane_mix: mov.b r0l,@mask ; [mask] selected plane = 0 (bit) mov.b #0,r0l mov.b r0l,@line ; [line] counter 0 - 7 sw_loop: jsr @line_check mov.b @line,r0l inc.b r0l cmp.b #8,r0l beq _sw_loopend mov.b r0l,@line bra sw_loop _sw_loopend: rts line_check: mov.b #b'11111110,r3h ; 574 data line mask mov.b @line,r1l mov.b #0,r2l _mask_loop: cmp.b r2l,r1l beq _mask_fix inc.b r2l rotl.b r3h ; [R3H] : selected line = 0 (bit) bra _mask_loop _mask_fix: mov.b #b'11111111,r0l mov.b r3h,@padr ; 574 data mov.b @mask,r0h mov.b r0h,@pbdr nop mov.b r0l,@pbdr ; data bus open mov.b @p2dr,r1l xor.b #b'11111111,r1l mov.b r1l,@buff ; get SW data mov.b r0l,@padr mov.b r0h,@pbdr ; mask nop mov.b r0l,@pbdr ; data bus close mov.b @plane,r5l shll.b r5l shll.b r5l shll.b r5l mov.b @line,r0l add.b r0l,r5l mov.b #0,r5h mov.w #0,e5 mov.b @(bank,er5),r0h cmp.b r1l,r0h bne _bank_hit rts _bank_hit: mov.b r1l,@(bank,er5) mov.b @plane,r0h shll.b r0h add.b #h'b0,r0h mov.b r0h,r4h jsr @tx_fifo_set mov.b @line,r0h jsr @tx_fifo_set mov.b @buff,r0h and.b #b'01111111,r0h jsr @tx_fifo_set mov.b r4h,r0h inc.b r0h jsr @tx_fifo_set mov.b @line,r0h jsr @tx_fifo_set mov.b @buff,r0h shlr.b r0h and.b #b'01000000,r0h jsr @tx_fifo_set rts ;***** 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 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 int_timer0: push.w r0 mov.b #1,r0l mov.b r0l,@flag btst #0,@tsr0 bclr #0,@tsr0 ; Clear IMFA pop.w r0 rte .end