;------------------------------------------------- ; ; AKI-H8 VCA module : November 1998 ; ;------------------------------------------------- ;##### 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 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 grb0 .equ h'0fff6c dadr0 .equ h'0fffdc dadr1 .equ h'0fffdd dacr .equ h'0fffde dastcr .equ h'0fff5c addra .equ h'0fffe0 adcsr .equ h'0fffe8 adcr .equ h'0fffe9 ;##### Vector Defines ##### .section vector,data,locate=h'000000 .data.l start .org h'000060 .data.l int_timer0 .org h'0000d0 .data.l int_rx_error .data.l int_rx_full ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 env .res.w 1 rx_top .res.w 1 rx_end .res.w 1 old .res.w 1 oldold .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 flag .res.b 1 remain .res.b 1 bank .res.b 1 speed .res.b 1 depth .res.b 1 decay .res.b 1 read .res.b 1 timer1 .res.b 1 timer2 .res.b 1 .org h'0ff400 rx_fifo .res.b 1024 ;***** Constant Table Defines ***** .section rom,data,locate=h'001000 ;## data(0) sine wave .data.b h'80,h'83,h'86,h'89,h'8c,h'8f,h'92,h'95 .data.b h'98,h'9c,h'9f,h'a2,h'a5,h'a8,h'ab,h'ae .data.b h'b0,h'b3,h'b6,h'b9,h'bc,h'bf,h'c1,h'c4 .data.b h'c7,h'c9,h'cc,h'ce,h'd1,h'd3,h'd5,h'd8 .data.b h'da,h'dc,h'de,h'e0,h'e2,h'e4,h'e6,h'e8 .data.b h'ea,h'ec,h'ed,h'ef,h'f0,h'f2,h'f3,h'f5 .data.b h'f6,h'f7,h'f8,h'f9,h'fa,h'fb,h'fc,h'fc .data.b h'fd,h'fe,h'fe,h'ff,h'ff,h'ff,h'ff,h'ff .data.b h'ff,h'ff,h'ff,h'ff,h'ff,h'ff,h'fe,h'fe .data.b h'fd,h'fc,h'fc,h'fb,h'fa,h'f9,h'f8,h'f7 .data.b h'f6,h'f5,h'f3,h'f2,h'f0,h'ef,h'ed,h'ec .data.b h'ea,h'e8,h'e6,h'e4,h'e2,h'e0,h'de,h'dc .data.b h'da,h'd8,h'd5,h'd3,h'd1,h'ce,h'cc,h'c9 .data.b h'c7,h'c4,h'c1,h'bf,h'bc,h'b9,h'b6,h'b3 .data.b h'b0,h'ae,h'ab,h'a8,h'a5,h'a2,h'9f,h'9c .data.b h'98,h'95,h'92,h'8f,h'8c,h'89,h'86,h'83 .data.b h'80,h'7c,h'79,h'76,h'73,h'70,h'6d,h'6a .data.b h'67,h'63,h'60,h'5d,h'5a,h'57,h'54,h'51 .data.b h'4f,h'4c,h'49,h'46,h'43,h'40,h'3e,h'3b .data.b h'38,h'36,h'33,h'31,h'2e,h'2c,h'2a,h'27 .data.b h'25,h'23,h'21,h'1f,h'1d,h'1b,h'19,h'17 .data.b h'15,h'13,h'12,h'10,h'0f,h'0d,h'0c,h'0a .data.b h'09,h'08,h'07,h'06,h'05,h'04,h'03,h'03 .data.b h'02,h'01,h'01,h'00,h'00,h'00,h'00,h'00 .data.b h'00,h'00,h'00,h'00,h'00,h'00,h'01,h'01 .data.b h'02,h'03,h'03,h'04,h'05,h'06,h'07,h'08 .data.b h'09,h'0a,h'0c,h'0d,h'0f,h'10,h'12,h'13 .data.b h'15,h'17,h'19,h'1b,h'1d,h'1f,h'21,h'23 .data.b h'25,h'27,h'2a,h'2c,h'2e,h'31,h'33,h'36 .data.b h'38,h'3b,h'3e,h'40,h'43,h'46,h'49,h'4c .data.b h'4f,h'51,h'54,h'57,h'5a,h'5d,h'60,h'63 .data.b h'67,h'6a,h'6d,h'70,h'73,h'76,h'79,h'7c ;## data(1) triangle .data.b h'80,h'82,h'84,h'86,h'88,h'8a,h'8c,h'8e .data.b h'90,h'92,h'94,h'96,h'98,h'9a,h'9c,h'9e .data.b h'a0,h'a2,h'a4,h'a6,h'a8,h'aa,h'ac,h'ae .data.b h'b0,h'b2,h'b4,h'b6,h'b8,h'ba,h'bc,h'be .data.b h'c0,h'c2,h'c4,h'c6,h'c8,h'ca,h'cc,h'ce .data.b h'd0,h'd2,h'd4,h'd6,h'd8,h'da,h'dc,h'de .data.b h'e0,h'e2,h'e4,h'e6,h'e8,h'ea,h'ec,h'ee .data.b h'f0,h'f2,h'f4,h'f6,h'f8,h'fa,h'fc,h'fe .data.b h'ff,h'fd,h'fb,h'f9,h'f7,h'f5,h'f3,h'f1 .data.b h'ef,h'ed,h'eb,h'e9,h'e7,h'e5,h'e3,h'e1 .data.b h'df,h'dd,h'db,h'd9,h'd7,h'd5,h'd3,h'd1 .data.b h'cf,h'cd,h'cb,h'c9,h'c7,h'c5,h'c3,h'c1 .data.b h'bf,h'bd,h'bb,h'b9,h'b7,h'b5,h'b3,h'b1 .data.b h'af,h'ad,h'ab,h'a9,h'a7,h'a5,h'a3,h'a1 .data.b h'9f,h'9d,h'9b,h'99,h'97,h'95,h'93,h'91 .data.b h'8f,h'8d,h'8b,h'89,h'87,h'85,h'83,h'81 .data.b h'7f,h'7d,h'7b,h'79,h'77,h'75,h'73,h'71 .data.b h'6f,h'6d,h'6b,h'69,h'67,h'65,h'63,h'61 .data.b h'5f,h'5d,h'5b,h'59,h'57,h'55,h'53,h'51 .data.b h'4f,h'4d,h'4b,h'49,h'47,h'45,h'43,h'41 .data.b h'3f,h'3d,h'3b,h'39,h'37,h'35,h'33,h'31 .data.b h'2f,h'2d,h'2b,h'29,h'27,h'25,h'23,h'21 .data.b h'1f,h'1d,h'1b,h'19,h'17,h'15,h'13,h'11 .data.b h'0f,h'0d,h'0b,h'09,h'07,h'05,h'03,h'01 .data.b h'00,h'02,h'04,h'06,h'08,h'0a,h'0c,h'0e .data.b h'10,h'12,h'14,h'16,h'18,h'1a,h'1c,h'1e .data.b h'20,h'22,h'24,h'26,h'28,h'2a,h'2c,h'2e .data.b h'30,h'32,h'34,h'36,h'38,h'3a,h'3c,h'3e .data.b h'40,h'42,h'44,h'46,h'48,h'4a,h'4c,h'4e .data.b h'50,h'52,h'54,h'56,h'58,h'5a,h'5c,h'5e .data.b h'60,h'62,h'64,h'66,h'68,h'6a,h'6c,h'6e .data.b h'70,h'72,h'74,h'76,h'78,h'7a,h'7c,h'7e ;## data(2) saw-a .data.b h'00,h'01,h'02,h'03,h'04,h'05,h'06,h'07 .data.b h'08,h'09,h'0a,h'0b,h'0c,h'0d,h'0e,h'0f .data.b h'10,h'11,h'12,h'13,h'14,h'15,h'16,h'17 .data.b h'18,h'19,h'1a,h'1b,h'1c,h'1d,h'1e,h'1f .data.b h'20,h'21,h'22,h'23,h'24,h'25,h'26,h'27 .data.b h'28,h'29,h'2a,h'2b,h'2c,h'2d,h'2e,h'2f .data.b h'30,h'31,h'32,h'33,h'34,h'35,h'36,h'37 .data.b h'38,h'39,h'3a,h'3b,h'3c,h'3d,h'3e,h'3f .data.b h'40,h'41,h'42,h'43,h'44,h'45,h'46,h'47 .data.b h'48,h'49,h'4a,h'4b,h'4c,h'4d,h'4e,h'4f .data.b h'50,h'51,h'52,h'53,h'54,h'55,h'56,h'57 .data.b h'58,h'59,h'5a,h'5b,h'5c,h'5d,h'5e,h'5f .data.b h'60,h'61,h'62,h'63,h'64,h'65,h'66,h'67 .data.b h'68,h'69,h'6a,h'6b,h'6c,h'6d,h'6e,h'6f .data.b h'70,h'71,h'72,h'73,h'74,h'75,h'76,h'77 .data.b h'78,h'79,h'7a,h'7b,h'7c,h'7d,h'7e,h'7f .data.b h'80,h'81,h'82,h'83,h'84,h'85,h'86,h'87 .data.b h'88,h'89,h'8a,h'8b,h'8c,h'8d,h'8e,h'8f .data.b h'90,h'91,h'92,h'93,h'94,h'95,h'96,h'97 .data.b h'98,h'99,h'9a,h'9b,h'9c,h'9d,h'9e,h'9f .data.b h'a0,h'a1,h'a2,h'a3,h'a4,h'a5,h'a6,h'a7 .data.b h'a8,h'a9,h'aa,h'ab,h'ac,h'ad,h'ae,h'af .data.b h'b0,h'b1,h'b2,h'b3,h'b4,h'b5,h'b6,h'b7 .data.b h'b8,h'b9,h'ba,h'bb,h'bc,h'bd,h'be,h'bf .data.b h'c0,h'c1,h'c2,h'c3,h'c4,h'c5,h'c6,h'c7 .data.b h'c8,h'c9,h'ca,h'cb,h'cc,h'cd,h'ce,h'cf .data.b h'd0,h'd1,h'd2,h'd3,h'd4,h'd5,h'd6,h'd7 .data.b h'd8,h'd9,h'da,h'db,h'dc,h'dd,h'de,h'df .data.b h'e0,h'e1,h'e2,h'e3,h'e4,h'e5,h'e6,h'e7 .data.b h'e8,h'e9,h'ea,h'eb,h'ec,h'ed,h'ee,h'ef .data.b h'f0,h'f1,h'f2,h'f3,h'f4,h'f5,h'f6,h'f7 .data.b h'f8,h'f9,h'fa,h'fb,h'fc,h'fd,h'fe,h'ff ;## data(3) saw-b .data.b h'ff,h'fe,h'fd,h'fc,h'fb,h'fa,h'f9,h'f8 .data.b h'f7,h'f6,h'f5,h'f4,h'f3,h'f2,h'f1,h'f0 .data.b h'ef,h'ee,h'ed,h'ec,h'eb,h'ea,h'e9,h'e8 .data.b h'e7,h'e6,h'e5,h'e4,h'e3,h'e2,h'e1,h'e0 .data.b h'df,h'de,h'dd,h'dc,h'db,h'da,h'd9,h'd8 .data.b h'd7,h'd6,h'd5,h'd4,h'd3,h'd2,h'd1,h'd0 .data.b h'cf,h'ce,h'cd,h'cc,h'cb,h'ca,h'c9,h'c8 .data.b h'c7,h'c6,h'c5,h'c4,h'c3,h'c2,h'c1,h'c0 .data.b h'bf,h'be,h'bd,h'bc,h'bb,h'ba,h'b9,h'b8 .data.b h'b7,h'b6,h'b5,h'b4,h'b3,h'b2,h'b1,h'b0 .data.b h'af,h'ae,h'ad,h'ac,h'ab,h'aa,h'a9,h'a8 .data.b h'a7,h'a6,h'a5,h'a4,h'a3,h'a2,h'a1,h'a0 .data.b h'9f,h'9e,h'9d,h'9c,h'9b,h'9a,h'99,h'98 .data.b h'97,h'96,h'95,h'94,h'93,h'92,h'91,h'90 .data.b h'8f,h'8e,h'8d,h'8c,h'8b,h'8a,h'89,h'88 .data.b h'87,h'86,h'85,h'84,h'83,h'82,h'81,h'80 .data.b h'7f,h'7e,h'7d,h'7c,h'7b,h'7a,h'79,h'78 .data.b h'77,h'76,h'75,h'74,h'73,h'72,h'71,h'70 .data.b h'6f,h'6e,h'6d,h'6c,h'6b,h'6a,h'69,h'68 .data.b h'67,h'66,h'65,h'64,h'63,h'62,h'61,h'60 .data.b h'5f,h'5e,h'5d,h'5c,h'5b,h'5a,h'59,h'58 .data.b h'57,h'56,h'55,h'54,h'53,h'52,h'51,h'50 .data.b h'4f,h'4e,h'4d,h'4c,h'4b,h'4a,h'49,h'48 .data.b h'47,h'46,h'45,h'44,h'43,h'42,h'41,h'40 .data.b h'3f,h'3e,h'3d,h'3c,h'3b,h'3a,h'39,h'38 .data.b h'37,h'36,h'35,h'34,h'33,h'32,h'31,h'30 .data.b h'2f,h'2e,h'2d,h'2c,h'2b,h'2a,h'29,h'28 .data.b h'27,h'26,h'25,h'24,h'23,h'22,h'21,h'20 .data.b h'1f,h'1e,h'1d,h'1c,h'1b,h'1a,h'19,h'18 .data.b h'17,h'16,h'15,h'14,h'13,h'12,h'11,h'10 .data.b h'0f,h'0e,h'0d,h'0c,h'0b,h'0a,h'09,h'08 .data.b h'07,h'06,h'05,h'04,h'03,h'02,h'01,h'00 ;***** 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'00100011,r0l mov.b r0l,@tcr0 ; Timer0 init : 2MHz clock bclr #0,@tsr0 ; Clear IMFA bset #0,@tier0 ; timer INT set mov.w #99,r0 ; 50usec INT mov.w r0,@gra0 mov.b #b'11111111,r0l mov.b r0l,@pbddr ; set : Port[B] all output mov.b #b'01100000,r0l mov.b r0l,@dacr ; D/A 0 enable ! mov.b #b'00000000,r0l mov.b r0l,@adcsr ; A/D port0 bclr.b #7,@adcr ; non trigger jsr @wait_500msec mov.b #b'01110000,r0l ; tx/rx start ! mov.b r0l,@scr bset #0,@tstr ; timer start ! bset.b #5,@adcsr ; A/D Start ! andc.b #b'01111111,ccr ; interrupt enable mov.b #0,r0l mov.b r0l,@remain mov.b #h'10,r0l mov.b r0l,@bank mov.b #40,r0l mov.b r0l,@speed mov.b #105,r0l mov.b r0l,@decay mov.b #20,r0l mov.b r0l,@depth mov.w #h'7fff,r0 mov.w r0,@env 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 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 timer_check: mov.b @flag,r0l cmp.b #0,r0l bne _timer_event rts _timer_event: mov.b #0,r0l mov.b r0l,@flag btst.b #7,@adcsr ; dummy mov.w @addra,r0 ; now input bclr.b #7,@adcsr bset.b #5,@adcsr ; next A/D Start ! xor.b #b'10000000,r0h ; -> 2's comp. mov.b @read,r1l mov.b @bank,r1h mov.w #0,e1 mov.b @er1,r2h ; mod wave data (abs) mov.b #0,r2l mov.b @depth,r3h mov.b #0,r3l mulxu.w r3,er2 ; wave * depth shlr.w e2 mov.w #h'7fff,r1 sub.w e2,r1 mulxs.w r0,er1 ; input * mod add.w e1,e1 mov.w @env,r3 mulxs.w e1,er3 ; * env mov.w e3,r0 add.w r0,r0 xor.b #b'10000000,r0h ; -> abs mov.b r0h,@dadr0 ; output D/A ! jsr @tremoro jsr @trigger rts trigger: mov.b @timer1,r0l inc.b r0l mov.b r0l,@timer1 mov.b @decay,r1h cmp.b r0l,r1h beq _tim1_hit rts _tim1_hit: mov.b #0,r0l mov.b r0l,@timer1 mov.w @env,r0 mov.w #h'7f77,r1 mulxs.w r1,er0 shll.w e0 mov.w e0,@env mov.w e0,r1 mov.b r1h,@pbdr ; write to Port[B] rts tremoro: mov.b @timer2,r0l inc.b r0l mov.b r0l,@timer2 mov.b @speed,r0h cmp.b r0h,r0l beq _tim2_hit rts _tim2_hit: mov.b #0,r0l mov.b r0l,@timer2 mov.b @read,r0l inc.b r0l mov.b r0l,@read 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 @channel,r1l or.b r1l,r0l cmp.b #h'90,r0l ; 90 note event ? beq _3_hit cmp.b #h'80,r0l ; 80 note event ? beq _3_off cmp.b #h'a0,r0l ; A0 parameters ? beq _3_para rts _3_hit: cmp.b #0,r0h ; velociry > 0 ? bne _3_cont _3_off: mov.b @remain,r0l dec.b r0l mov.b r0l,@remain rts _3_pass: rts _3_cont: mov.b @keyno,r0l cmp.b #24,r0l bmi _3_pass cmp.b #97,r0l bpl _3_pass mov.b @keyno,r0l mov.b r0l,@pbdr ; write to Port[B] mov.b @remain,r0l inc.b r0l mov.b r0l,@remain cmp.b #1,r0l bne _3_pass mov.w #h'7fff,r0 mov.w r0,@env rts _3_para: mov.b @keyno,r0l cmp.b #0,r0l beq _set_decay cmp.b #1,r0l beq _set_depth cmp.b #2,r0l beq _set_speed cmp.b #3,r0l beq _set_wave rts _set_decay: mov.b @data,r0l add.b #5,r0l mov.b r0l,@decay rts _set_depth: mov.b @data,r0l shal.b r0l mov.b r0l,@depth rts _set_speed: mov.b @data,r0l mov.b #135,r0h sub.b r0l,r0h mov.b r0h,@speed rts _set_wave: mov.b @data,r0l and.b #b'00000011,r0l bset.b #4,r0l mov.b r0l,@bank rts .end