as12, an absolute assembler for Motorola MCU's, version 1.2e

                        ; Test.asm ---  Test program for the MiniDRAGON+ Rev. D board
                        ;               (c)2005, EVBplus.com, written By Wayne Chu
                        ;
                        ;     Function: This is the factory test program for checking on-board
                        ;		hardware. It checks the 2-pos DIP switches AN5-AN6,
                        ;		2 pushbuttons AN3-AN4 and the LCD display.
                        ;		It scans the switches and keypad. Shows their functions and
                        ;               displays the key number on the 7-segment LED display while
                        ;               playing a song. It allows to adjust the trimmer pot to change
                        ;               LED display's brightness.
                        ;
                        ; The switches are software de-bounced for better reliability
                        ;
                        ; Instructions:
                        ;       If you have a 4 x 4 keypad, connect it to the keypad header J22.
                        *       The middle 8 pins of the 10-pin keypad cable are keypad connections.
                        *       The pin 1 and pin 10 are not used.
                        *
                        ;	1. After running the test program, the 7-segment LED display will
                        ;	   count up from hex number 0 to F and the music will come out.
                        ;          LCD display shows:	" S1=UP, S2=DOWN "
                        ;                               "S3=FAST, S4=SLOW"
                        
                        ;	2. press the S1 pushbutton, the number counts up from hex 0 to F.
                        ;	   press the S2 pushbutton, the number counts down from hex F to 0.
                        ;
                        ;	3. Short the S3, the count speed is 250ms per count (fast).
                        ;	   Short the S4, the count speed is 750ms per count (slow).
                        ;
                        ;	4. Adjust the trimmer pot, the 7 segment LED display's brightness 
                        ;	   should change.
                        ;       5. Press the keypad, the 7-segment LED display will show key number.
                        
                        ;  LCD routines use 4-bit transfer via port M
                        ;  PM3 ------- RS ( register select, 0 = register transfer, 1 = data transfer).
                        ;  PM2 ------- Enable ( write pulse )
                        ;  PM4 ------- Data Bit 4 of LCD
                        ;  PM5 ------- Data Bit 5 of LCD
                        ;  PM6 ------- Data Bit 6 of LCD
                        ;  PM7 ------- Data Bit 7 of LCD
                        ;
                        ; Timing of 4-bit data transfer is shown on page 11 of the Seiko LCD
                        ; application note on the distribution CD. The file name is Seikolcd.pdf
                        ;
                        ; WARNING: Beware of pinouts of LCD modules. The pin 1 and pin 2 of some new
                        ;          modules are swapped. If you connect a wrong polarity LCD to the
                        ;          MiniDRAGON, it could be damaged.
                        ;
                        ; There are two different keypads have been used with Wytec development boards.
                        ; The following signal definitions only apply to Grayhill 4X4 keypad:
                        
                        ; PA0 connects ROW0 of the keypad via pin 1 of the 8-pin keypad header J29
                        ; PA1 connects ROW1 of the keypad via pin 2 of the 8-pin keypad header J29
                        ; PA2 connects ROW2 of the keypad via pin 3 of the 8-pin keypad header J29
                        ; PA3 connects ROW3 of the keypad via pin 4 of the 8-pin keypad header J29
                        
                        ; PA4 connects COL0 of the keypad via pin 5 of the 8-pin keypad header J29
                        ; PA5 connects COL1 of the keypad via pin 6 of the 8-pin keypad header J29
                        ; PA6 connects COL2 of the keypad via pin 7 of the 8-pin keypad header J29
                        ; PA7 connects COL3 of the keypad via pin 8 of the 8-pin keypad header J29
                        
                        ; The PA0-PA7 has a 100K pull-up resistor in each line.
                        
                        ; The following signal definitions only apply to Wytec 4X4 membrane keypad:
                        
                        ; PA0 connects COL0 of the keypad via pin 1 of the 8-pin keypad header J29
                        ; PA1 connects COL1 of the keypad via pin 2 of the 8-pin keypad header J29
                        ; PA2 connects COL2 of the keypad via pin 3 of the 8-pin keypad header J29
                        ; PA3 connects COL3 of the keypad via pin 4 of the 8-pin keypad header J29
                        
                        ; PA4 connects ROW0 of the keypad via pin 5 of the 8-pin keypad header J29
                        ; PA5 connects ROW1 of the keypad via pin 6 of the 8-pin keypad header J29
                        ; PA6 connects ROW2 of the keypad via pin 7 of the 8-pin keypad header J29
                        ; PA7 connects ROW3 of the keypad via pin 8 of the 8-pin keypad header J29
                        
                        ; The PA0-PA7 has an internal pull-up resistor in each line.
                        
                        ; To use the Grayhill keypad, remark the label Wytec_keypad and un-remark
                        ; the label Grayhill_keypad
                        
0001                    Wytec_keypad:		equ     1       ; use Wytec_keypad
                        ;Grayhill_keypad:        equ     1      ; not to use Grayhill_keypad
                        
                        
                        
0010                    SW1:	equ	$10		; AN4	
0008                    SW2:	equ	$08		; AN3	
0020                    SW3:	equ	$20		; AN5	
0040                    SW4:	equ	$40		; AN6	
                        ;
                        
0010                    MULTI_MODE:	equ	$10
0000                    SINGLE_MODE:	equ	0
0020                    SCAN_MODE:	equ	$20
0000                    NO_SCAN_MODE:	equ	0
0007                    CHANNEL_NUM:	equ	7		; reading input from AN07
                        
0001                    DB0:		equ	1
0002                    DB1:		equ	2
0004                    DB2:		equ   	4
0008                    DB3:		equ   	8
0010                    DB4:		equ	$10
0020                    DB5:		equ	$20
0040                    DB6:		equ	$40
0080                    DB7:		equ	$80
                        
0004                    OL5:		equ	DB2
0008                    OM5:		equ	DB3
                        
0fa0                    ONE_MS:		equ	4000		; 4000 x 250ns = 1 ms at 24 MHz bus speed
4e20                    FIVE_MS:	equ	20000
9c40                    TEN_MS:		equ	40000
00c8                    FIFTY_US:	equ	200
                        
0001                    COUNT_UP:	equ	1
0002                    COUNT_DOWN:	equ	2
00fa                    FAST:		equ	250		; 250 ms, fast counting speed
02ee                    SLOW:		equ	750		; 750 ms, slow counting speed
                        
5dc0                    TB1MS:		equ	24000		; 1ms time base of 24,000 instruction cycles
                        ;					; 24000 x 1/24MHz = 1ms at 24 MHz bus speed
0d65                    F3500HZ:	equ	3429
0000                    REGBLK:		equ	$0
                        #include        reg9s12.h		; include register equates
                        *
                        *
                        *  HC12 i/o register locations (9s12dp256)
                        *
                        *
0000                    porta:          equ 0   ;port a = address lines a8 - a15
0001                    portb:          equ 1   ;port b = address lines a0 - a7
0002                    ddra:           equ 2   ;port a direction register
0003                    ddrb:           equ 3   ;port a direction register
                        
0008                    porte:          equ 8   ;port e = mode,irqandcontrolsignals
0009                    ddre:           equ 9   ;port e direction register
000a                    pear:           equ $a  ;port e assignments
000b                    mode:           equ $b  ;mode register
000c                    pucr:           equ $c  ;port pull-up control register
000d                    rdriv:          equ $d  ;port reduced drive control register
000e                    ebictl:		equ $e  ;e stretch control
                        
0010                    initrm:         equ $10 ;ram location register
0011                    initrg:         equ $11 ;register location register
0012                    initee:         equ $12 ;eeprom location register
0013                    misc:           equ $13 ;miscellaneous mapping control
0014                    mtst0:          equ $14 ; reserved
0015                    itcr:           equ $15 ;interrupt test control register
0016                    itest:          equ $16 ;interrupt test register
0017                    mtst1:          equ $17 ; reserved
                        
001a                    partidh:	equ $1a ;part id high
001b                    partidl:	equ $1b ;part id low
001c                    memsiz0:	equ $1c ;memory size
001d                    memsiz1:	equ $1d ;memory size
001e                    intcr:          equ $1e ;interrupt control register
001f                    hprio:          equ $1f ;high priority reg
                        
0028                    bkpct0:         equ $28 ;break control register
0029                    bkpct1:         equ $29 ;break control register
002a                    bkp0x:          equ $2a ; break 0 index register
002b                    bkp0h:          equ $2b ; break 0 pointer high
002c                    brp0l:          equ $2c ; break 0 pointer low
002d                    bkp1x:          equ $2d ; break 1 index register
002e                    bkp1h:          equ $2e ; break 1 pointer high
002f                    brp1l:          equ $2f ; break 1 pointer low
0030                    ppage:		equ $30 ;program page register
                        
0032                    portk:		equ $32 ;port k data
0033                    ddrk:		equ $33 ;port k direction
0034                    synr:           equ $34 ; synthesizer / multiplier register
0035                    refdv:          equ $35 ; reference divider register
0036                    ctflg:          equ $36 ; reserved
0037                    crgflg:         equ $37 ; pll flags register
0038                    crgint:         equ $38 ; pll interrupt register
0039                    clksel:         equ $39 ; clock select register
003a                    pllctl:         equ $3a ; pll control register
003b                    rtictl:         equ $3b ;real time interrupt control
003c                    copctl:         equ $3c ;watchdog control
003d                    forbyp:         equ $3d ;
003e                    ctctl:          equ $3e ;
003f                    armcop:         equ $3f ;cop reset register
                        
0040                    tios:           equ $40 ;timer input/output select
0041                    cforc:          equ $41 ;timer compare force
0042                    oc7m:           equ $42 ;timer output compare 7 mask
0043                    oc7d:           equ $43 ;timer output compare 7 data
0044                    tcnt:           equ $44 ;timer counter register hi
                        *tcnt:          equ $45 ;timer counter register lo
0046                    tscr:           equ $46 ;timer system control register
0047                    ttov:           equ $47 ;reserved
0048                    tctl1:          equ $48 ;timer control register 1
0049                    tctl2:          equ $49 ;timer control register 2
004a                    tctl3:          equ $4a ;timer control register 3
004b                    tctl4:          equ $4b ;timer control register 4
004c                    tmsk1:          equ $4c ;timer interrupt mask 1
004d                    tmsk2:          equ $4d ;timer interrupt mask 2
004e                    tflg1:          equ $4e ;timer flags 1
004f                    tflg2:          equ $4f ;timer flags 2
0050                    tc0:            equ $50 ;timer capture/compare register 0
0052                    tc1:            equ $52 ;timer capture/compare register 1
0054                    tc2:            equ $54 ;timer capture/compare register 2
0056                    tc3:            equ $56 ;timer capture/compare register 3
0058                    tc4:            equ $58 ;timer capture/compare register 4
005a                    tc5:            equ $5a ;timer capture/compare register 5
005c                    tc6:            equ $5c ;timer capture/compare register 6
005e                    tc7:            equ $5e ;timer capture/compare register 7
0060                    pactl:          equ $60 ;pulse accumulator controls
0061                    paflg:          equ $61 ;pulse accumulator flags
0062                    pacn3:          equ $62 ;pulse accumulator counter 3
0063                    pacn2:          equ $63 ;pulse accumulator counter 2
0064                    pacn1:          equ $64 ;pulse accumulator counter 1
0065                    pacn0:          equ $65 ;pulse accumulator counter 0
0066                    mcctl:          equ $66 ;modulus down conunter control
0067                    mcflg:          equ $67 ;down counter flags
0068                    icpar:          equ $68 ;input pulse accumulator control
0069                    dlyct:          equ $69 ;delay count to down counter
006a                    icovw:          equ $6a ;input control overwrite register
006b                    icsys:          equ $6b ;input control system control
                        
006d                    timtst:         equ $6d ;timer test register
                        
0070                    pbctl:          equ $70 ; pulse accumulator b control
0071                    pbflg:          equ $71 ; pulse accumulator b flags
0072                    pa3h:           equ $72 ; pulse accumulator holding register 3
0073                    pa2h:           equ $73 ; pulse accumulator holding register 2
0074                    pa1h:           equ $74 ; pulse accumulator holding register 1
0075                    pa0h:           equ $75 ; pulse accumulator holding register 0
0076                    mccnt:          equ $76 ; modulus down counter register
                        *mccntl:        equ $77 ; low byte
0078                    tcoh:           equ $78 ; capture 0 holding register
007a                    tc1h:           equ $7a ; capture 1 holding register
007c                    tc2h:           equ $7c ; capture 2 holding register
007e                    tc3h:           equ $7e ; capture 3 holding register
                        
0080                    atd0ctl0:       equ $80 ;adc control 0 (reserved)
0081                    atd0ctl1:       equ $81 ;adc control 1 (reserved)
0082                    atd0ctl2:       equ $82 ;adc control 2
0083                    atd0ctl3:       equ $83 ;adc control 3
0084                    atd0ctl4:       equ $84 ;adc control 4
0085                    atd0ctl5:       equ $85 ;adc control 5
0086                    atd0stat:       equ $86 ;adc status register hi
                        *atd0stat       equ $87 ;adc status register lo
0088                    atd0test:       equ $88 ;adc test (reserved)
                        *atd0test       equ $89 ;
                        
008d                    atd0dien:	equ $8d ;
                        
008f                    portad0:         equ $8f ;port adc = input only
0090                    adr00h:         equ $90 ;adc result 0 register
0092                    adr01h:         equ $92 ;adc result 1 register
0094                    adr02h:         equ $94 ;adc result 2 register
0096                    adr03h:         equ $96 ;adc result 3 register
0098                    adr04h:         equ $98 ;adc result 4 register
009a                    adr05h:         equ $9a ;adc result 5 register
009c                    adr06h:         equ $9c ;adc result 6 register
009e                    adr07h:         equ $9e ;adc result 7 register
                        
00a0                    pwme:		equ $a0 ;pwm enable
00a1                    pwmpol:         equ $a1 ;pwm polarity
00a2                    pwmclk:         equ $a2 ;pwm clock select register
00a3                    pwmprclk:       equ $a3 ;pwm prescale clock select register
00a4                    pwmcae:         equ $a4 ;pwm center align select register
00a5                    pwmctl:         equ $a5 ;pwm control register
00a6                    pwmtst:         equ $a6 ;reserved
00a7                    pwmprsc:        equ $a7 ;reserved
00a8                    pwmscla:        equ $a8 ;pwm scale a
00a9                    pwmsclb:        equ $a9 ;pwm scale b
00aa                    pwmscnta:       equ $aa ;reserved
00ab                    pwmscntb:       equ $ab ;reserved
00ac                    pwmcnt0:        equ $ac ;pwm channel 0 counter
00ad                    pwmcnt1:        equ $ad ;pwm channel 1 counter
00ae                    pwmcnt2:        equ $ae ;pwm channel 2 counter
00af                    pwmcnt3:        equ $af ;pwm channel 3 counter
00b0                    pwmcnt4:        equ $b0 ;pwm channel 4 counter
00b1                    pwmcnt5:        equ $b1 ;pwm channel 5 counter
00b2                    pwmcnt6:        equ $b2 ;pwm channel 6 counter
00b3                    pwmcnt7:        equ $b3 ;pwm channel 7 counter
00b4                    pwmper0:        equ $b4 ;pwm channel 0 period
00b5                    pwmper1:        equ $b5 ;pwm channel 1 period
00b6                    pwmper2:        equ $b6 ;pwm channel 2 period
00b7                    pwmper3:        equ $b7 ;pwm channel 3 period
00b8                    pwmper4:        equ $b8 ;pwm channel 4 period
00b9                    pwmper5:        equ $b9 ;pwm channel 5 period
00ba                    pwmper6:        equ $ba ;pwm channel 6 period
00bb                    pwmper7:        equ $bb ;pwm channel 7 period
00bc                    pwmdty0:        equ $bc ;pwm channel 0 duty cycle
00bd                    pwmdty1:        equ $bd ;pwm channel 1 duty cycle
00be                    pwmdty2:        equ $be ;pwm channel 2 duty cycle
00bf                    pwmdty3:        equ $bf ;pwm channel 3 duty cycle
00c0                    pwmdty4:        equ $c0 ;pwm channel 0 duty cycle
00c1                    pwmdty5:        equ $c1 ;pwm channel 1 duty cycle
00c2                    pwmdty6:        equ $c2 ;pwm channel 2 duty cycle
00c3                    pwmdty7:        equ $c3 ;pwm channel 3 duty cycle
00c4                    pwmsdn:         equ $c4 ;pwm shutdown register
                        
00c8                    sc0bdh:         equ $c8 ;sci 0 baud reg hi byte
00c9                    sc0bdl:         equ $c9 ;sci 0 baud reg lo byte
00ca                    sc0cr1:         equ $ca ;sci 0 control1 reg
00cb                    sc0cr2:         equ $cb ;sci 0 control2 reg
00cc                    sc0sr1:         equ $cc ;sci 0 status reg 1
00cd                    sc0sr2:         equ $cd ;sci 0 status reg 2
00ce                    sc0drh:         equ $ce ;sci 0 data reg hi
00cf                    sc0drl:         equ $cf ;sci 0 data reg lo
00d0                    sc1bdh:         equ $d0 ;sci 1 baud reg hi byte
00d1                    sc1bdl:         equ $d1 ;sci 1 baud reg lo byte
00d2                    sc1cr1:         equ $d2 ;sci 1 control1 reg
00d3                    sc1cr2:         equ $d3 ;sci 1 control2 reg
00d4                    sc1sr1:         equ $d4 ;sci 1 status reg 1
00d5                    sc1sr2:         equ $d5 ;sci 1 status reg 2
00d6                    sc1drh:         equ $d6 ;sci 1 data reg hi
00d7                    sc1drl:         equ $d7 ;sci 1 data reg lo
00d8                    spi0cr1:        equ $d8 ;spi 0 control1 reg
00d9                    spi0cr2:        equ $d9 ;spi 0 control2 reg
00da                    spi0br:         equ $da ;spi 0 baud reg
00db                    spi0sr:         equ $db ;spi 0 status reg hi
                        
00dd                    sp0dr:          equ $dd ;spi 0 data reg
                        
00e0                    ibad:		equ $e0 ;i2c bus address register
00e1                    ibfd:		equ $e1 ;i2c bus frequency divider
00e2                    ibcr:		equ $e2 ;i2c bus control register
00e3                    ibsr:		equ $e3 ;i2c bus status register
00e4                    ibdr:		equ $e4 ;i2c bus message data register
                        
00e8                    dlcbcr1:	equ $e8 ;bdlc control regsiter 1
00e9                    dlcbsvr:	equ $e9 ;bdlc state vector register
00ea                    dlcbcr2:	equ $ea ;bdlc control register 2
00eb                    dlcbdr:		equ $eb ;bdlc data register
00ec                    dlcbard:	equ $ec ;bdlc analog delay register
00ed                    dlcbrsr:	equ $ed ;bdlc rate select register
00ee                    dlcscr:		equ $ee ;bdlc control register
00ef                    dlcbstat:	equ $ef ;bdlc status register
00f0                    spi1cr1:        equ $f0 ;spi 1 control1 reg
00f1                    spi1cr2:        equ $f1 ;spi 1 control2 reg
00f2                    spi1br:         equ $f2 ;spi 1 baud reg
00f3                    spi1sr:         equ $f3 ;spi 1 status reg hi
                        
00f5                    sp1dr:          equ $f5 ;spi 1 data reg
                        
00f8                    spi2cr1:        equ $f8 ;spi 2 control1 reg
00f9                    spi2cr2:        equ $f9 ;spi 2 control2 reg
00fa                    spi2br:         equ $fa ;spi 2 baud reg
00fb                    spi2sr:         equ $fb ;spi 2 status reg hi
                        
00fd                    sp2dr:          equ $fd ;spi 2 data reg
                        
0100                    fclkdiv:	equ $100 ;flash clock divider
0101                    fsec:		equ $101 ;flash security register
                        
0103                    fcnfg:		equ $103 ;flash configuration register
0104                    fprot:		equ $104 ;flash protection register
0105                    fstat:		equ $105 ;flash status register
0106                    fcmd:		equ $106 ;flash command register
                        
0110                    eclkdiv:	equ $110 ;eeprom clock divider
                        
0113                    ecnfg:		equ $113 ;eeprom configuration register
0114                    eprot:		equ $114 ;eeprom protection register
0115                    estat:		equ $115 ;eeprom status register
0116                    ecmd:		equ $116 ;eeprom command register
                        
0120                    atd1ctl0:       equ $120 ;adc1 control 0 (reserved)
0121                    atd1ctl1:       equ $121 ;adc1 control 1 (reserved)
0122                    atd1ctl2:       equ $122 ;adc1 control 2
0123                    atd1ctl3:       equ $123 ;adc1 control 3
0124                    atd1ctl4:       equ $124 ;adc1 control 4
0125                    atd1ctl5:       equ $125 ;adc1 control 5
0126                    atd1stat:       equ $126 ;adc1 status register hi
                        *atd1stat       equ $127 ;adc1 status register lo
0128                    atd1test:       equ $128 ;adc1 test (reserved)
                        *atd1test       equ $129 ;
                        
012d                    atd1dien:	equ $12d ;adc1 input enable register
                        
012f                    portad1:        equ $12f ;port adc1 = input only
0130                    adr10h:         equ $130 ;adc1 result 0 register
0132                    adr11h:         equ $132 ;adc1 result 1 register
0134                    adr12h:         equ $134 ;adc1 result 2 register
0136                    adr13h:         equ $136 ;adc1 result 3 register
0138                    adr14h:         equ $138 ;adc1 result 4 register
013a                    adr15h:         equ $13a ;adc1 result 5 register
013c                    adr16h:         equ $13c ;adc1 result 6 register
013e                    adr17h:         equ $13e ;adc1 result 7 register
0140                    can0ctl0:	equ $140 ;can0 control register 0
0141                    can0ctl1:	equ $141 ;can0 control register 1
0142                    can0btr0:	equ $142 ;can0 bus timing register 0
0143                    can0btr1:	equ $143 ;can0 bus timing register 1
0144                    can0rflg:	equ $144 ;can0 receiver flags
0145                    can0rier:	equ $145 ;can0 receiver interrupt enables
0146                    can0tflg:	equ $146 ;can0 transmit flags
0147                    can0tier:	equ $147 ;can0 transmit interrupt enables
0148                    can0tarq:	equ $148 ;can0 transmit message abort control
0149                    can0taak:	equ $149 ;can0 transmit message abort status
014a                    can0tbel:	equ $14a ;can0 transmit buffer select
014b                    can0idac:	equ $14b ;can0 identfier acceptance control
                        
014e                    can0rerr:	equ $14e ;can0 receive error counter
014f                    can0terr:	equ $14f ;can0 transmit error counter
0150                    can0ida0:	equ $150 ;can0 identifier acceptance register 0
0151                    can0ida1:	equ $151 ;can0 identifier acceptance register 1
0152                    can0ida2:	equ $152 ;can0 identifier acceptance register 2
0153                    can0ida3:	equ $153 ;can0 identifier acceptance register 3
0154                    can0idm0:	equ $154 ;can0 identifier mask register 0
0155                    can0idm1:	equ $155 ;can0 identifier mask register 1
0156                    can0idm2:	equ $156 ;can0 identifier mask register 2
0157                    can0idm3:	equ $157 ;can0 identifier mask register 3
0158                    can0ida4:	equ $158 ;can0 identifier acceptance register 4
0159                    can0ida5:	equ $159 ;can0 identifier acceptance register 5
015a                    can0ida6:	equ $15a ;can0 identifier acceptance register 6
015b                    can0ida7:	equ $15b ;can0 identifier acceptance register 7
015c                    can0idm4:	equ $15c ;can0 identifier mask register 4
015d                    can0idm5:	equ $15d ;can0 identifier mask register 5
015e                    can0idm6:	equ $15e ;can0 identifier mask register 6
015f                    can0idm7:	equ $15f ;can0 identifier mask register 7
0160                    can0rxfg:	equ $160 ;can0 rx foreground buffer thru +$16f
0170                    can0txfg:	equ $170 ;can0 tx foreground buffer thru +$17f
                        
0180                    can1ctl0:	equ $180 ;can1 control register 0
0181                    can1ctl1:	equ $181 ;can1 control register 1
0182                    can1btr0:	equ $182 ;can1 bus timing register 0
0183                    can1btr1:	equ $183 ;can1 bus timing register 1
0184                    can1rflg:	equ $184 ;can1 receiver flags
0185                    can1rier:	equ $185 ;can1 receiver interrupt enables
0186                    can1tflg:	equ $186 ;can1 transmit flags
0187                    can1tier:	equ $187 ;can1 transmit interrupt enables
0188                    can1tarq:	equ $188 ;can1 transmit message abort control
0189                    can1taak:	equ $189 ;can1 transmit message abort status
018a                    can1tbel:	equ $18a ;can1 transmit buffer select
018b                    can1idac:	equ $18b ;can1 identfier acceptance control
                        
018e                    can1rerr:	equ $18e ;can1 receive error counter
018f                    can1terr:	equ $18f ;can1 transmit error counter
0190                    can1ida0:	equ $190 ;can1 identifier acceptance register 0
0191                    can1ida1:	equ $191 ;can1 identifier acceptance register 1
0192                    can1ida2:	equ $192 ;can1 identifier acceptance register 2
0193                    can1ida3:	equ $193 ;can1 identifier acceptance register 3
0194                    can1idm0:	equ $194 ;can1 identifier mask register 0
0195                    can1idm1:	equ $195 ;can1 identifier mask register 1
0196                    can1idm2:	equ $196 ;can1 identifier mask register 2
0197                    can1idm3:	equ $197 ;can1 identifier mask register 3
0198                    can1ida4:	equ $198 ;can1 identifier acceptance register 4
0199                    can1ida5:	equ $199 ;can1 identifier acceptance register 5
019a                    can1ida6:	equ $19a ;can1 identifier acceptance register 6
019b                    can1ida7:	equ $19b ;can1 identifier acceptance register 7
019c                    can1idm4:	equ $19c ;can1 identifier mask register 4
019d                    can1idm5:	equ $19d ;can1 identifier mask register 5
019e                    can1idm6:	equ $19e ;can1 identifier mask register 6
019f                    can1idm7:	equ $19f ;can1 identifier mask register 7
01a0                    can1rxfg:	equ $1a0 ;can1 rx foreground buffer thru +$1af
01b0                    can1txfg:	equ $1b0 ;can1 tx foreground buffer thru +$1bf
                        
01c0                    can2ctl0:	equ $1c0 ;can2 control register 0
01c1                    can2ctl1:	equ $1c1 ;can2 control register 1
01c2                    can2btr0:	equ $1c2 ;can2 bus timing register 0
01c3                    can2btr1:	equ $1c3 ;can2 bus timing register 1
01c4                    can2rflg:	equ $1c4 ;can2 receiver flags
01c5                    can2rier:	equ $1c5 ;can2 receiver interrupt enables
01c6                    can2tflg:	equ $1c6 ;can2 transmit flags
01c7                    can2tier:	equ $1c7 ;can2 transmit interrupt enables
01c8                    can2tarq:	equ $1c8 ;can2 transmit message abort control
01c9                    can2taak:	equ $1c9 ;can2 transmit message abort status
01ca                    can2tbel:	equ $1ca ;can2 transmit buffer select
01cb                    can2idac:	equ $1cb ;can2 identfier acceptance control
                        
01ce                    can2rerr:	equ $1ce ;can2 receive error counter
01cf                    can2terr:	equ $1cf ;can2 transmit error counter
01d0                    can2ida0:	equ $1d0 ;can2 identifier acceptance register 0
01d1                    can2ida1:	equ $1d1 ;can2 identifier acceptance register 1
01d2                    can2ida2:	equ $1d2 ;can2 identifier acceptance register 2
01d3                    can2ida3:	equ $1d3 ;can2 identifier acceptance register 3
01d4                    can2idm0:	equ $1d4 ;can2 identifier mask register 0
01d5                    can2idm1:	equ $1d5 ;can2 identifier mask register 1
01d6                    can2idm2:	equ $1d6 ;can2 identifier mask register 2
01d7                    can2idm3:	equ $1d7 ;can2 identifier mask register 3
01d8                    can2ida4:	equ $1d8 ;can2 identifier acceptance register 4
01d9                    can2ida5:	equ $1d9 ;can2 identifier acceptance register 5
01da                    can2ida6:	equ $1da ;can2 identifier acceptance register 6
01db                    can2ida7:	equ $1db ;can2 identifier acceptance register 7
01dc                    can2idm4:	equ $1dc ;can2 identifier mask register 4
01dd                    can2idm5:	equ $1dd ;can2 identifier mask register 5
01de                    can2idm6:	equ $1de ;can2 identifier mask register 6
01df                    can2idm7:	equ $1df ;can2 identifier mask register 7
01e0                    can2rxfg:	equ $1e0 ;can2 rx foreground buffer thru +$1ef
01f0                    can2txfg:	equ $1f0 ;can2 tx foreground buffer thru +$1ff
                        
0200                    can3ctl0:	equ $200 ;can3 control register 0
0201                    can3ctl1:	equ $201 ;can3 control register 1
0202                    can3btr0:	equ $202 ;can3 bus timing register 0
0203                    can3btr1:	equ $203 ;can3 bus timing register 1
0204                    can3rflg:	equ $204 ;can3 receiver flags
0205                    can3rier:	equ $205 ;can3 receiver interrupt enables
0206                    can3tflg:	equ $206 ;can3 transmit flags
0207                    can3tier:	equ $207 ;can3 transmit interrupt enables
0208                    can3tarq:	equ $208 ;can3 transmit message abort control
0209                    can3taak:	equ $209 ;can3 transmit message abort status
020a                    can3tbel:	equ $20a ;can3 transmit buffer select
020b                    can3idac:	equ $20b ;can3 identfier acceptance control
                        
020e                    can3rerr:	equ $20e ;can3 receive error counter
020f                    can3terr:	equ $20f ;can3 transmit error counter
0210                    can3ida0:	equ $210 ;can3 identifier acceptance register 0
0211                    can3ida1:	equ $211 ;can3 identifier acceptance register 1
0212                    can3ida2:	equ $212 ;can3 identifier acceptance register 2
0213                    can3ida3:	equ $213 ;can3 identifier acceptance register 3
0214                    can3idm0:	equ $214 ;can3 identifier mask register 0
0215                    can3idm1:	equ $215 ;can3 identifier mask register 1
0216                    can3idm2:	equ $216 ;can3 identifier mask register 2
0217                    can3idm3:	equ $217 ;can3 identifier mask register 3
0218                    can3ida4:	equ $218 ;can3 identifier acceptance register 4
0219                    can3ida5:	equ $219 ;can3 identifier acceptance register 5
021a                    can3ida6:	equ $21a ;can3 identifier acceptance register 6
021b                    can3ida7:	equ $21b ;can3 identifier acceptance register 7
021c                    can3idm4:	equ $21c ;can3 identifier mask register 4
021d                    can3idm5:	equ $21d ;can3 identifier mask register 5
021e                    can3idm6:	equ $21e ;can3 identifier mask register 6
021f                    can3idm7:	equ $21f ;can3 identifier mask register 7
0220                    can3rxfg:	equ $220 ;can3 rx foreground buffer thru +$22f
0230                    can3txfg:	equ $230 ;can3 tx foreground buffer thru +$23f
                        
0240                    ptt:		equ $240 ;portt data register
0241                    ptit:		equ $241 ;portt input register
0242                    ddrt:		equ $242 ;portt direction register
0243                    rdrt:		equ $243 ;portt reduced drive register
0244                    pert:		equ $244 ;portt pull device enable
0245                    ppst:		equ $245 ;portt pull polarity select
                        
0248                    pts:		equ $248 ;ports data register
0249                    ptis:		equ $249 ;ports input register
024a                    ddrs:		equ $24a ;ports direction register
024b                    rdrs:		equ $24b ;ports reduced drive register
024c                    pers:		equ $24c ;ports pull device enable
024d                    ppss:		equ $24d ;ports pull polarity select
024e                    woms:		equ $24e ;ports wired or mode register
                        
0250                    ptm:		equ $250 ;portm data register
0251                    ptim:		equ $251 ;portm input register
0252                    ddrm:		equ $252 ;portm direction register
0253                    rdrm:		equ $253 ;portm reduced drive register
0254                    perm:		equ $254 ;portm pull device enable
0255                    ppsm:		equ $255 ;portm pull polarity select
0256                    womm:		equ $256 ;portm wired or mode register
0257                    modrr:		equ $257 ;portm module routing register
0258                    ptp:		equ $258 ;portp data register
0259                    ptip:		equ $259 ;portp input register
025a                    ddrp:		equ $25a ;portp direction register
025b                    rdrp:		equ $25b ;portp reduced drive register
025c                    perp:		equ $25c ;portp pull device enable
025d                    ppsp:		equ $25d ;portp pull polarity select
025e                    piep:		equ $25e ;portp interrupt enable register
025f                    pifp:		equ $25f ;portp interrupt flag register
0260                    pth:		equ $260 ;porth data register
0261                    ptih:		equ $261 ;porth input register
0262                    ddrh:		equ $262 ;porth direction register
0263                    rdrh:		equ $263 ;porth reduced drive register
0264                    perh:		equ $264 ;porth pull device enable
0265                    ppsh:		equ $265 ;porth pull polarity select
0266                    pieh:		equ $266 ;porth interrupt enable register
0267                    pifh:		equ $267 ;porth interrupt flag register
0268                    ptj:		equ $268 ;portp data register
0269                    ptij:		equ $269 ;portp input register
026a                    ddrj:		equ $26a ;portp direction register
026b                    rdrj:		equ $26b ;portp reduced drive register
026c                    perj:		equ $26c ;portp pull device enable
026d                    ppsj:		equ $26d ;portp pull polarity select
026e                    piej:		equ $26e ;portp interrupt enable register
026f                    pifj:		equ $26f ;portp interrupt flag register
                        
0280                    can4ctl0:	equ $280 ;can4 control register 0
0281                    can4ctl1:	equ $281 ;can4 control register 1
0282                    can4btr0:	equ $282 ;can4 bus timing register 0
0283                    can4btr1:	equ $283 ;can4 bus timing register 1
0284                    can4rflg:	equ $284 ;can4 receiver flags
0285                    can4rier:	equ $285 ;can4 receiver interrupt enables
0286                    can4tflg:	equ $286 ;can4 transmit flags
0287                    can4tier:	equ $287 ;can4 transmit interrupt enables
0288                    can4tarq:	equ $288 ;can4 transmit message abort control
0289                    can4taak:	equ $289 ;can4 transmit message abort status
028a                    can4tbel:	equ $28a ;can4 transmit buffer select
028b                    can4idac:	equ $28b ;can4 identfier acceptance control
                        
028e                    can4rerr:	equ $28e ;can4 receive error counter
028f                    can4terr:	equ $28f ;can4 transmit error counter
0290                    can4ida0:	equ $290 ;can4 identifier acceptance register 0
0291                    can4ida1:	equ $291 ;can4 identifier acceptance register 1
0292                    can4ida2:	equ $292 ;can4 identifier acceptance register 2
0293                    can4ida3:	equ $293 ;can4 identifier acceptance register 3
0294                    can4idm0:	equ $294 ;can4 identifier mask register 0
0295                    can4idm1:	equ $295 ;can4 identifier mask register 1
0296                    can4idm2:	equ $296 ;can4 identifier mask register 2
0297                    can4idm3:	equ $297 ;can4 identifier mask register 3
0298                    can4ida4:	equ $298 ;can4 identifier acceptance register 4
0299                    can4ida5:	equ $299 ;can4 identifier acceptance register 5
029a                    can4ida6:	equ $29a ;can4 identifier acceptance register 6
029b                    can4ida7:	equ $29b ;can4 identifier acceptance register 7
029c                    can4idm4:	equ $29c ;can4 identifier mask register 4
029d                    can4idm5:	equ $29d ;can4 identifier mask register 5
029e                    can4idm6:	equ $29e ;can4 identifier mask register 6
029f                    can4idm7:	equ $29f ;can4 identifier mask register 7
02a0                    can4rxfg:	equ $2a0 ;can4 rx foreground buffer thru +$2af
02b0                    can4txfg:	equ $2b0 ;can4 tx foreground buffer thru +$2bf
                        
                        * end registers
                        
                        
                        
1000                    	org	$1000
                        
1000                    ram:		rmb	1
1001                    temp:           rmb     1
1002                    spk_tone:	rmb	2
1004                    sound_dur:	rmb	1
1005                    xsound_save:	rmb	2
1007                    sound_repeat:	rmb	1
1008                    xsound_beg:	rmb	2
100a                    sound_start:	rmb	1
100b                    rest_note:	rmb	1
100c                    d1ms_flag:	rmb	1
100d                    xsave:		rmb	2
100f                    adctl_image:	rmb	1
1010                    brtness:	rmb	1
1011                    count_5ms:	rmb	1
1012                    count10:	rmb	1
1013                    disp_data:	rmb	1
1014                    loop_count:	rmb	2
1016                    direction:	rmb	1
1017                    speed:		rmb	2
1019                    switch_flag:	rmb	1
101a                    key_flag:       rmb     1
101b                    pmimg:		rmb	1
101c                    temp1:		rmb	1
101d                    ramend:		rmb	1
001d                    ALLRAM:		equ 	ramend-ram 	;total ram used
                        
0008                    REG_SEL:	equ	DB3		; 0=reg, 1=data
00f7                    NOT_REG_SEL:	equ	$F7     	; 11110111
0004                    ENABLE:		equ     DB2
00fb                    NOT_ENABLE:	equ     $FB             ; 11111011
                        
0250                    LCD:		equ	ptm
0250                    LCD_RS:		equ	ptm
0250                    LCD_EN:		equ	ptm
                        
101b                    LCDimg:		equ	pmimg
101b                    LCD_RSimg:	equ	pmimg
101b                    LCD_ENimg:	equ	pmimg
                        
2000                    STACK:		equ	$2000
                        ;
                        ; Segment conversion table:
                        
                        ; Binary number:	 	0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
                        ; Converted to 7-segment char: 	0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
                        ;
                        ; Binary number:		$10,$11,$12,$13,$14,$15,$16,$17
                        ; Converted to 7-segment char:   G   H   h   J   L   n   o   o
                        ;
                        ; Binary number:  		$18,$19,$1A,$1B,$1C,$1D,$1E,$1F,$20
                        ; Converted to 7-segment char:   P   r   t   U   u   y   _  --  Blank
                        
                        
                        ; for 24 MHz bus speed
                        ; 1200000 / 261.63 Hz = note count
                        ;
b32a                    c3	equ	45866		; 261.63 Hz at 24 MHz
a91d                    c3s	equ	43293		; 277.18 Hz at 24 MHz
9fa0                    d3	equ	40864		; 293.66 Hz at 24 MHz
96a9                    d3s	equ	38569		; 311.13 Hz at 24 MHz
8e34                    e3	equ	36404		; 329.63 Hz at 24 MHz
8639                    f3	equ	34361		; 349.23 Hz at 24 MHz
7eb1                    f3s	equ	32433		; 369.99 Hz at 24 MHz
7795                    g3	equ	30613		; 391.99 Hz at 24 MHz
70de                    g3s	equ	28894		; 415.31 Hz at 24 MHz
6a89                    a3	equ	27273		; 440.00 Hz at 24 MHz
648e                    a3s	equ	25742		; 466.16 Hz at 24 MHz
5ee9                    b3	equ	24297		; 493.88 Hz at 24 MHz
                        
5996                    c4	equ	22934		; 523.25 Hz at 24 MHz
548e                    c4s	equ	21646		; 554.37 Hz at 24 MHz
4fcf                    d4	equ	20431		; 587.33 Hz at 24 MHz
4b55                    d4s	equ	19285		; 622.25 Hz at 24 MHz
471a                    e4	equ	18202		; 659.26 Hz at 24 MHz
431d                    f4	equ	17181		; 698.46 Hz at 24 MHz
3f58                    f4s	equ	16216		; 739.99 Hz at 24 MHz
3bca                    g4	equ	15306		; 783.99 Hz at 24 MHz
386f                    g4s	equ	14447		; 830.61 Hz at 24 MHz
3544                    a4	equ	13636		; 880.00 Hz at 24 MHz
3247                    a4s	equ	12871		; 932.32 Hz at 24 MHz
2f75                    b4	equ	12149		; 987.77 Hz at 24 MHz
                        
2ccb                    c5	equ	11467		; 1046.50 Hz at 24 MHz
2a47                    c5s	equ	10823		; 1108.73 Hz at 24 MHz
27e8                    d5	equ	10216		; 1174.66 Hz at 24 MHz
25aa                    d5s	equ	9642		; 1244.51 Hz at 24 MHz
238d                    e5	equ	9101		; 1318.51 Hz at 24 MHz
218e                    f5	equ	8590		; 1396.91 Hz at 24 MHz
1fac                    f5s	equ	8108		; 1479.98 Hz at 24 MHz
1de5                    g5	equ	7653		; 1567.98 Hz at 24 MHz
1c39                    g5s	equ	7225		; 1661.22 Hz at 24 MHz
1aa2                    a5	equ	6818		; 1760.00 Hz at 24 MHz
1923                    a5s	equ	6435		; 1864.66 Hz at 24 MHz
17ba                    b5	equ	6074		; 1975.53 Hz at 24 MHz
                        
1665                    c6	equ	5733		; 2093.00 Hz at 24 MHz
1524                    c6s	equ	5412		; 2217.46 Hz at 24 MHz
13f5                    d6	equ	5109		; 2349.32 Hz at 24 MHz
12d5                    d6s	equ	4821		; 2489.02 Hz at 24 MHz
11c7                    e6	equ	4551		; 2637.02 Hz at 24 MHz
10c7                    f6	equ	4295		; 2793.83 Hz at 24 MHz
0fd6                    f6s	equ	4054		; 2959.96 Hz at 24 MHz
0ef3                    g6	equ	3827		; 3135.97 Hz at 24 MHz
0e1c                    g6s	equ	3612		; 3322.44 Hz at 24 MHz
0d51                    a6	equ	3409		; 3520.00 Hz at 24 MHz
0c92                    a6s	equ	3218		; 3729.31 Hz at 24 MHz
0bdd                    b6	equ	3037		; 3951.07 Hz at 24 MHz
                        
0b33                    c7	equ	2867		; 4186.01 Hz at 24 MHz
0a92                    c7s	equ	2706		; 4434.92 Hz at 24 MHz
09fa                    d7	equ	2554		; 4698.64 Hz at 24 MHz
096b                    d7s	equ	2411		; 4978.03 Hz at 24 MHz
08e3                    e7	equ	2275		; 5274.04 Hz at 24 MHz
0864                    f7	equ	2148		; 5587.66 Hz at 24 MHz
07eb                    f7s	equ	2027		; 5919.92 Hz at 24 MHz
0779                    g7	equ	1913		; 6271.93 Hz at 24 MHz
070e                    g7s	equ	1806		; 6644.88 Hz at 24 MHz
06a9                    a7	equ	1705		; 7040.00 Hz at 24 MHz
0649                    a7s	equ	1609		; 7458.63 Hz at 24 MHz
05ef                    b7	equ	1519		; 7902.13 Hz at 24 MHz
0001                    c8	equ	1		; for rest note
                        
0000                    note_c	equ	0
0001                    note_cs	equ	1
0002                    note_d	equ	2
0003                    note_ds	equ	3
0004                    note_e	equ	4
0005                    note_f	equ	5
0006                    note_fs	equ	6
0007                    note_g	equ	7
0008                    note_gs	equ	8
0009                    note_a	equ	9
000a                    note_as	equ	10
000b                    note_b	equ	11
                        
                        ; dur18= 1/8 note,  dur14= 1/4 note,  $fe= rest_note, $ff = end of song
                        	
0032                    dur18	equ	50
0064                    dur14	equ	100
                        	
                        
e000                    	org     $E000		; program code starts at flash memory address $E000
e000 06 e2 46           	jmp	start
                        ;
e003                    NOTE_TABLE:
e003 b3 2a a9 1d 9f a0  	fdb	c3,c3s,d3,d3s,e3,f3,f3s,g3,g3s,a3,a3s,b3
     96 a9 8e 34 86 39
     7e b1 77 95 70 de
     6a 89 64 8e 5e e9
e01b 00 00 00 00 00 00  	fdb	0,0,0,0		; dummy byte
     00 00
e023 59 96 54 8e 4f cf  	fdb	c4,c4s,d4,d4s,e4,f4,f4s,g4,g4s,a4,a4s,b4
     4b 55 47 1a 43 1d
     3f 58 3b ca 38 6f
     35 44 32 47 2f 75
e03b 00 00 00 00 00 00  	fdb	0,0,0,0		; dummy byte
     00 00
e043 2c cb 2a 47 27 e8  	fdb	c5,c5s,d5,d5s,e5,f5,f5s,g5,g5s,a5,a5s,b5
     25 aa 23 8d 21 8e
     1f ac 1d e5 1c 39
     1a a2 19 23 17 ba
e05b 00 00 00 00 00 00  	fdb	0,0,0,0		; dummy byte
     00 00
e063 16 65 15 24 13 f5  	fdb	c6,c6s,d6,d6s,e6,f6,f6s,g6,g6s,a6,a6s,b6
     12 d5 11 c7 10 c7
     0f d6 0e f3 0e 1c
     0d 51 0c 92 0b dd
e07b 00 00 00 00 00 00  	fdb	0,0,0,0		; dummy byte
     00 00
e083 0b 33 0a 92 09 fa  	fdb	c7,c7s,d7,d7s,e7,f7,f7s,g7,g7s,a7,a7s,b7
     09 6b 08 e3 08 64
     07 eb 07 79 07 0e
     06 a9 06 49 05 ef
e09b 00 00 00 00 00 00  	fdb	0,0,0,0		; dummy byte
     00 00
e0a3 00 01              	fdb	c8
                        ;
                        
e0a5                    segm_ptrn:						; segment pattern
e0a5 3f 06 5b 4f 66 6d  	fcb     $3f,$06,$5b,$4f,$66,$6d,$7d,$07		;0-7
     7d 07
                        ;		 0,  1,  2,  3,  4,  5,  6,  7
e0ad 7f 6f 77 7c 39 5e          fcb     $7f,$6f,$77,$7c,$39,$5e,$79,$71		;8-$0f
     79 71
                        ;		 8,  9,  A,  b,  C,  d,  E,  F
e0b5 3d 76 74 1e 38 54         	fcb     $3d,$76,$74,$1e,$38,$54,$63,$5c		;10-17
     63 5c
                        ;		 G,  H,  h,  J   L   n   o   o
e0bd 73 50 78 3e 1c 6e         	fcb     $73,$50,$78,$3e,$1c,$6e,$08,$40		;18-1f
     08 40
                        ;		 P,  r,  t,  U,  u   Y   -   -
e0c5 00 01 48 41 09 49         	fcb     $00,$01,$48,$41,$09,$49			;20-23
                        ;		blk, -,  =,  =,  =,  =
                        ;
e0cb                    seven_segment:
e0cb 34                 	pshx
e0cc 37                 	pshb
e0cd ce e0 a5           	ldx	#segm_ptrn
e0d0 36                 	psha
e0d1 84 3f              	anda	#$3f
e0d3 18 0e              	tab
e0d5 1a e5              	abx
e0d7 a6 00              	ldaa	0,x		; get segment
e0d9 33                 	pulb
e0da c4 80              	andb	#$80		; add DP
e0dc 18 06              	aba
e0de 33                 	pulb
e0df 30                 	pulx
e0e0 3d                 	rts
                        ;
                        #ifdef  Wytec_keypad
                        ; keypad scan for Wytec 4X4 membrane keypad (pin 1-4 = col 0-3, pin 5-8 = row 0-3)
                        ; at exit:  if a key is down, the carry bit =1 and the accumulator b
                        ;	    holds the key number
                        ;	    if no key is dwon the carry bit =0
                        
e0e1                    keypad:
                        ;	ldaa 	#00001111b
e0e1 86 0f              	ldaa 	#$0F		; pa0-pa3 are outputs, pa4-pa7 are inputs
e0e3 5a 02              	staa 	ddra
                        
e0e5 c6 0f              	ldab	#15
                        ;	ldaa	#11110111b
e0e7 86 f7              	ldaa	#$F7		; pa3=low, pa0-pa2=high
e0e9 7a 10 01           	staa	temp		; save it at temp
e0ec                    next_row:
e0ec 5a 00              	staa	porta
e0ee 86 0a              	ldaa	#10		; add delay before checking key down
e0f0 43                 k_dly:	deca
e0f1 26 fd              	bne	k_dly
                        
e0f3 96 00              	ldaa	porta
e0f5 84 f0              	anda	#$F0		; only read 4 MSBs pa4-pa7
e0f7 81 f0              	cmpa	#$F0
e0f9 26 11              	bne	keyin		; a key is pressed
e0fb 53                 	decb
e0fc c1 0b              	cmpb	#11
e0fe 27 09              	beq	no_keyin	; after 4 tests, accu B will be 11
                        
e100 76 10 01            	ror	temp
e103 b6 10 01           	ldaa	temp
e106 06 e0 ec           	jmp	next_row
                        
e109                    no_keyin:
e109 10 fe              	clc
e10b 3d                 	rts			; no key input
                        
e10c 45                 keyin:	rola
e10d 24 05               	bcc	key_ok
e10f c0 04               	subb    #4
e111 06 e1 0c            	jmp     keyin
e114 14 01              key_ok:	sec
e116 3d                 	rts
                        #endif
                        ;
                        
                        #ifdef  Grayhill_keypad
                        ;
                        ; keypad scan for Grayhill 4x4 keypad (pin 1-4 = row 0-3, pin 5-8 = col 0-3)
                        ; at exit:  if a key is down, the carry bit =1 and the accumulator b
                        ;	    holds the key number
                        ;	    if no key is dwon the carry bit =0
                        
                        keypad:
                        ;	ldaa 	#00001111b
                        	ldaa 	#$0F		; pa0-pa3 are outputs, pa4-pa7 are inputs
                        	staa 	ddra
                        
                        	ldab	#16
                        ;	ldaa	#11110111b
                        	ldaa	#$F7		; pa3=low, pa0-pa2=high
                        	staa	temp		; save it at temp
                        next_row:
                        	staa	porta
                        	ldaa	#10		; add delay before checking key down
                        k_dly:	deca
                        	bne	k_dly
                        
                        	ldaa	porta
                        	anda	#$F0		; only read 4 MSBs pa4-pa7
                        	cmpa	#$F0
                        	bne	keyin		; a key is pressed
                        	subb	#4
                        	beq	no_keyin	; after 4 tests, accu B will be 0
                        
                        	ror	temp
                        	ldaa	temp
                        	jmp	next_row
                        
                        no_keyin:
                        	clc
                        	rts			; no key input
                        
                        keyin:	decb
                        	rola
                        	bcs	keyin
                        	sec
                        	rts
                        #endif
                        
                        
                        
e117 20 53 31 3d 55 50  MSG1:   FCC     " S1=UP, S2=DOWN "
     2c 20 53 32 3d 44
     4f 57 4e 20
e127 53 33 3d 46 41 53  MSG2:   FCC     "S3=FAST, S4=SLOW"
     54 2c 20 53 34 3d
     53 4c 4f 57
e137                    lcd_ini:
e137 86 ff              	ldaa	#$ff
e139 7a 02 52           	staa	ddrm		; port M = output
e13c 87                 	clra
e13d 7a 10 1b           	staa	pmimg
e140 7a 02 50           	staa	ptm
                        
e143 ce e1 5b                  	ldx	#inidsp 	; point to init. codes.
e146 37                 	pshb            	; output instruction command.
e147 16 e1 70                  	jsr    	sel_inst
e14a e6 00                     	ldab   	0,x
e14c 08                        	inx
e14d a6 00              onext:	ldaa   	0,x
e14f 16 e1 9e                  	jsr    	wrt_nibble 	; initiate write pulse.
e152 08                        	inx
e153 16 e2 24           	jsr	delay_5ms       ; every nibble is delayed for 5ms
e156 53                        	decb                    ; in reset sequence to simplify coding
e157 26 f4                     	bne    	onext
e159 33                        	pulb
e15a 3d                        	rts
                        
e15b 0c                 inidsp: fcb	12		; number of high nibbles
                        *				; use high nibbles only, low nibbles are ignored
e15c 30                 	fcb	$30		; 1st reset code, must delay 4.1ms after sending
e15d 30                         fcb	$30		; 2nd reste code, must delay 100us after sending
                        
                        ; all following 10 nibbles must be delay 40us each after sending
e15e 30                 	fcb     $30             ; 3rd reset code,
e15f 20                 	fcb	$20		; 4th reste code,
e160 20                         fcb	$20   		; 4 bit mode, 2 line, 5X7 dot
e161 80                 	fcb	$80   		; 4 bit mode, 2 line, 5X7 dot
e162 00                         fcb	$00		; cursor increment, disable display shift
e163 60                 	fcb	$60		; cursor increment, disable display shift
e164 00                         fcb	$00		; display on, cursor off, no blinking
e165 c0                 	fcb	$C0		; display on, cursor off, no blinking
e166 00                 	fcb	$00		; clear display memory, set cursor to home pos
e167 10                 	fcb	$10		; clear display memory, set cursor to home pos
                        *
e168                    sel_data:
e168 36                 	psha
                        ;	bset	LCD_RSimg REG_SEL	; select instruction
e169 b6 10 1b           	ldaa	LCD_RSimg
e16c 8a 08              	oraa	#REG_SEL
e16e 20 06              	bra	sel_ins
e170                    sel_inst:
e170 36                 	psha
                        ;	bclr	LCD_RSimg REG_SEL	; select instruction
e171 b6 10 1b           	ldaa	LCD_RSimg
e174 84 f7              	anda	#NOT_REG_SEL
e176                    sel_ins:
e176 7a 10 1b           	staa	LCD_RSimg
e179 7a 02 50           	staa	LCD_RS
e17c 32                 	pula
e17d 3d                         rts
                        
e17e                    lcd_line1:
e17e 16 e1 70           	jsr    	sel_inst		; select instruction
e181 86 80                     	ldaa   	#$80     		; starting address for the line1
e183 20 05              	bra	line3
e185                    lcd_line2:
e185 16 e1 70           	jsr    	sel_inst
e188 86 c0                     	ldaa   	#$C0     		; starting address for the line2
e18a 16 e1 b5           line3: 	jsr    	wrt_byte
                        
e18d 16 e1 68                  	jsr    	sel_data
e190 16 e1 94           	jsr	msg_out
e193 3d                 	rts
                        ;
                        ; at entry, x must point to the begining of the message,
                        ;           b = number of the character to be sent out
                        
e194                    msg_out:
e194 a6 00              	ldaa   	0,x
e196 16 e1 b5                  	jsr    	wrt_byte
e199 08                        	inx
e19a 53                        	decb
e19b 26 f7                     	bne    	msg_out
e19d 3d                 	rts
                        
e19e                    wrt_nibble:
e19e 84 f0                     	anda   	#$f0     		; mask out 4 low bits
e1a0 7a 10 1c                  	staa   	temp1 			; save high nibble
e1a3 b6 10 1b                  	ldaa   	LCDimg    		; get LCD port image
e1a6 84 0c                     	anda   	#$0C     		; need DB2 and DB3
e1a8 ba 10 1c                  	oraa   	temp1    		; add it with high nibble
e1ab 7a 10 1b                   staa   	LCDimg    		; save it
e1ae 7a 02 50                   staa   	LCD    			; output data to LCD port
e1b1 16 e1 e9                   jsr	enable_pulse
e1b4 3d                  	rts
                        *
                        
                        ;       @ enter, a=data to output
                        ;
e1b5                    wrt_byte:
e1b5 34                 	pshx
e1b6 36                        	psha        			; save it tomporarily.
e1b7 84 f0                     	anda   #$f0     		; mask out 4 low bits.
e1b9 7a 10 1c                  	staa   temp1 			; save nibble value.
e1bc b6 10 1b                  	ldaa   LCDimg    		; get LCD port image.
e1bf 84 0c                     	anda   	#$0C     		; need DB2 and DB3
e1c1 ba 10 1c                  	oraa   temp1    		; add in low 4 bits.
e1c4 7a 10 1b                  	staa   LCDimg    		; save it
e1c7 7a 02 50                  	staa   LCD    			; output data
                        ;
e1ca 07 1d              	bsr	enable_pulse
e1cc 32                 	pula
e1cd 48                  	asla            		; move low bits over.
e1ce 48                 	asla
e1cf 48                 	asla
e1d0 48                 	asla
e1d1 7a 10 1c                  	staa   	temp1			; store temporarily.
                        ;
e1d4 b6 10 1b                  	ldaa   	LCDimg 			; get LCD port image.
e1d7 84 0c                     	anda   	#$0C     		; need DB2 and DB3
e1d9 ba 10 1c                   oraa   	temp1  			; add in loiw 4 bits.
e1dc 7a 10 1b                  	staa   	LCDimg    		; save it
e1df 7a 02 50                  	staa   	LCD    			; output data
                        ;
e1e2 07 05              	bsr	enable_pulse
e1e4 16 e2 2c           	jsr	delay_50us
e1e7 30                  	pulx
e1e8 3d                        	rts
                        ;
e1e9                    enable_pulse:
                        ;	bset	LCD_ENimg ENABLE	; ENABLE=high
e1e9 b6 10 1b           	ldaa	LCD_ENimg
e1ec 8a 04              	oraa	#ENABLE
e1ee 7a 10 1b           	staa	LCD_ENimg
e1f1 7a 02 50           	staa	LCD_EN
e1f4 03                 	dey                             ; time delay for ENABLE pulse
e1f5 02                 	iny
e1f6 03                 	dey
e1f7 02                 	iny
                        ;	bclr	LCD_ENimg ENABLE	; ENABLE=low
e1f8 b6 10 1b           	ldaa	LCD_ENimg
e1fb 84 fb              	anda	#NOT_ENABLE
e1fd 7a 10 1b           	staa	LCD_ENimg
e200 7a 02 50           	staa	LCD_EN
e203 3d                         rts
                        ;
                        ;
                        ; this routine will read adc input on the pin AN07 and store 4 consecutive 
                        ; 
e204                    adc_conv:
e204 8b 00              	adda	#SINGLE_MODE+NO_SCAN_MODE
                        ;
                        ; if you want to read multi-channel input, change above statement to
                        ;	adda	#MULTI_MODE+NO_SCAN_MODE
                        ;
e206 7a 10 0f           	staa	adctl_image
e209 ce 00 00           	ldx	#REGBLK
e20c 16 e2 10           	jsr	conv
e20f 3d                 	rts
                        	
e210 b6 10 0f           conv:	ldaa	adctl_image
e213 6a e0 85           	staa	atd0ctl5,x
e216                    not_ready:
e216 0f e0 86 80 fb     	brclr	atd0stat,x $80 not_ready
e21b 3d                 	rts
e21c                    delay_10ms:  
e21c 34                 	pshx
e21d ce 9c 40           	ldx     #TEN_MS
e220 07 12                	bsr	del1
e222 30                 	pulx
e223 3d                 	rts
e224                    delay_5ms:
e224 34                 	pshx
e225 ce 4e 20           	ldx     #FIVE_MS
e228 07 0a                	bsr	del1
e22a 30                 	pulx
e22b 3d                 	rts
e22c                    delay_50us:
e22c 34                 	pshx
e22d ce 00 c8           	ldx     #FIFTY_US
e230 07 02                	bsr	del1
e232 30                 	pulx
e233 3d                 	rts
                        ;
                        ; 250ns delay at 24MHz bus speed  (6 cycles x 41.67ns/cyl =250ns)
                        ;
e234 09                 del1:	dex				; 1 cycle
e235 08                 	inx				; 1 cycle
e236 09                 	dex				; 1 cycle
e237 26 fb              	bne	del1			; 3 cylces
e239 3d                 	rts
                        
                        
e23a 34                 clrall:	pshx
e23b ce 10 00           	ldx	#ram
e23e 69 00              clrr	clr	0,x
e240 08                 	inx
e241 43                 	deca
e242 26 fa              	bne	clrr
e244 30                 	pulx
e245 3d                 	rts
                        ;
e246 cf 20 00           start:	lds	#STACK
                        	
                        ;	The internal PLL clock lets us set the speed of the processor.
                        ;;      If you do not set the speed of the PLL as we are doing here, the
                        ;;      default bus speed speed will be 4 Mhz (half the OscFreq).
                        ;;
                        ;;      The math used to set the PLL frequency:
                        ;;        OscFreq = 8Mhz
                        ;;        initSYNR = 2      PLL multiplier
                        ;;        initREFDV = 0     PLL divider - 1
                        ;;        PLLCLK = 2 * OscFreq * (initSYNR+1) / (initREFDV+1)
                        ;;      Usually the OscFreq is 8Mhz, so we have PLLCLK = 2*8*3/1 = 48Mhz
                        ;;      The bus clock runs at half of the PLL speed:
                        ;;      Bus Clock = PLLCLK / 2 = 24 Mhz (for an OscFreq of 8 Mhz)
                        ;;
                        ;;      The effective cycle clock you should use for timing instructions is the
                        ;;      bus clock of 24 Mhz. This is currently the fastest speed this device
                        ;;      can safely use. Overclocking is not recommended.
                        ;;
                        ;;      If you set a slower speed, it will reduce power consumption. If low
                        ;;      power consumption is important (like for battery-powered circuits), you
                        ;;      should also put the processor to sleep as often as possible.
                        ;;
                        ;;      Set the PLL speed:
                        ;;
                        
                        ;********PLL code for 24MHz bus speed from a 4/8/16 crystal
e249 14 10              	sei
e24b ce 00 00           	ldx	#REGBLK
e24e 0d e0 39 80        	bclr	clksel,x,%10000000	; clear bit 7, clock derived from oscclk
e252 0c e0 3a 40        	bset	pllctl,x,%01000000	; Turn PLL on, bit 6 =1 PLL on, bit 6=0 PLL off
e256 86 05              	ldaa	#$05			; 5+1=6 multiplier 
e258 6a e0 34           	staa	synr,x
e25b 86 03              	ldaa	#$03			; 3+1=4 divisor, 6/4 * 16 = 24Mhz for 16 MHz crystal
                        ;	ldaa	#$01			; 1+1=2 divisor, 6/2 *  8 = 24Mhz for  8 MHz crystal
                        ;	ldaa	#$00			; 0+1=1 divisor, 6/1 *  4 = 24Mhz for  4 MHz crystal 
e25d 6a e0 35           	staa	refdv,x
e260                    wait_b3:
e260 0f e0 37 08 fb     	brclr	crgflg,x,%00001000,wait_b3 	; Wait until bit 3 = 1
e265 0c e0 39 80        	bset	clksel,x,%10000000
                        	
                        ;**********
                        	
e269 ce 00 00           	ldx	#REGBLK
e26c 86 ff              	ldaa	#$ff		
e26e 6a e2 02 62        	staa	ddrh,x		; porth = output
e272 69 e2 02 60        	clr	pth,x		; turn off LED display
e276 0c 0c 01            	bset	pucr,x,1	; enable pullup on portA
                        ;
e279 86 ff              	ldaa	#$ff		; enable the digital input buffer
e27b 6a e0 8d           	staa	atd0dien,x	; ATD0 port.
                        
e27e 86 80              	ldaa	#$80
e280 6a e0 46           	staa	tscr,x		; enable timer
e283 86 60              	ldaa	#DB5+DB6
e285 6a e0 40           	staa	tios,x		; select t6 as an output compare	 
e288 6a e0 4c           	staa	tmsk1,x
                        
e28b 0c e0 82 80        	bset 	atd0ctl2,x $80	; enable adc operation
e28f 0c e0 83 40        	bset	atd0ctl3,x $40	; 8 conversion needed for AN07
                        	
e293 ce 0d 65           	ldx	#F3500HZ	; 3.5kHz
e296 7e 10 02           	stx	spk_tone
e299 16 e3 c8           	jsr	spk_off
                        
e29c 86 1d              	ldaa	#ALLRAM
e29e 16 e2 3a           	jsr	clrall
                        ;
e2a1 16 e2 1c            	jsr	delay_10ms		; delay 20ms during power up
e2a4 16 e2 1c               	jsr	delay_10ms
                        
e2a7 16 e1 37               	jsr	lcd_ini			; initialize the LCD
                        
e2aa ce e1 17           	ldx    	#MSG1			; MSG1 for line1, x points to MSG1
e2ad c6 10                      ldab    #16                     ; send out 16 characters
e2af 16 e1 7e               	jsr	lcd_line1
                        
e2b2 ce e1 27               	ldx    	#MSG2			; MSG2 for line2, x points to MSG2
e2b5 c6 10                      ldab    #16                     ; send out 16 characters
e2b7 16 e1 85                	jsr	lcd_line2
                        
e2ba 10 ef              	cli
e2bc 16 e3 ba           	jsr	spk_on
e2bf 16 e4 69           	jsr	start_sound	; start sound
                        	
e2c2 86 01              	ldaa	#1
e2c4 7a 10 13           	staa	disp_data
e2c7 86 01              	ldaa	#COUNT_UP
e2c9 7a 10 16           	staa	direction
e2cc cd 02 ee           	ldy	#SLOW
e2cf 7d 10 17           	sty	speed
                        
e2d2 ce 00 00           	ldx	#REGBLK
e2d5 a6 e0 8f           begin:	ldaa	portad0,x		; get AD0 value.
e2d8 84 78              	anda	#SW1+SW2+SW3+SW4
e2da 81 78              	cmpa	#SW1+SW2+SW3+SW4
e2dc 27 53              	beq	no_switch			; no key down
e2de b6 10 19           	ldaa	switch_flag
e2e1 26 51              	bne	continue		; key was down
e2e3 16 e2 1c           	jsr	delay_10ms
e2e6 a6 e0 8f           	ldaa	portad0,x		; get AD0 value.
e2e9 84 78              	anda	#SW1+SW2+SW3+SW4
e2eb 81 78              	cmpa	#SW1+SW2+SW3+SW4
e2ed 27 42              	beq	no_switch			; no key is down < 10ms, it was noice
                        
                        ; key is down more than 10 ms, it's valid 
e2ef c6 01              	ldab	#1
e2f1 7b 10 19           	stab	switch_flag		; set key down flag
                        
e2f4 18 0e              	tab
e2f6 84 10              	anda	#SW1			; test Sw1
e2f8 27 15              	beq	sw1_down
                        		
e2fa 18 0f              	tba
e2fc 84 08              	anda	#SW2			; test Sw2
e2fe 27 17              	beq	sw2_down
                        		
e300 18 0f              	tba
e302 84 20              	anda	#SW3			; test Sw3
e304 27 19              	beq	sw3_down
                        	
e306 18 0f              	tba
e308 84 40              	anda	#SW4			; test Sw4
e30a 27 1c              	beq	sw4_down
e30c 06 e3 34           	jmp	continue
                        
e30f                    sw1_down:			
e30f 86 01              	ldaa	#COUNT_UP
e311 7a 10 16           	staa	direction
e314 06 e3 34           	jmp	continue
                        	
e317                    sw2_down:			
e317 86 02              	ldaa	#COUNT_DOWN
e319 7a 10 16           	staa	direction
e31c 06 e3 34           	jmp	continue
                        	
e31f                    sw3_down:			
e31f cd 00 fa           	ldy	#FAST
e322 7d 10 17           	sty	speed
e325 06 e3 34           	jmp	continue
                        	
e328                    sw4_down:			
e328 cd 02 ee           	ldy	#SLOW
e32b 7d 10 17           	sty	speed
e32e 06 e3 34           	jmp	continue
                        
e331                    no_switch:
e331 79 10 19           	clr 	switch_flag
e334                    continue:
e334 86 07              	ldaa	#CHANNEL_NUM	; set channel number before calling 
e336 16 e2 04           	jsr	adc_conv	
e339 96 9e              	ldaa	adr07h+REGBLK
e33b 7a 10 10           	staa	brtness
                        ;
e33e 16 e0 e1           	jsr     keypad
e341 24 17              	bcc	nokey
e343 b6 10 1a           	ldaa    Key_flag
e346 26 0d              	bne     key_down
e348 16 e2 1c              	jsr	delay_10ms
e34b 16 e0 e1           	jsr 	keypad
e34e 24 0a              	bcc	nokey
e350 86 01              	ldaa    #1
e352 7a 10 1a           	staa    key_flag
                        ; key down
e355                    key_down:
e355 18 0f              	tba
e357 06 e3 60           	jmp     key_out
                        	
e35a 79 10 1a           nokey:  clr	key_flag
e35d b6 10 13                   ldaa	disp_data
e360                    key_out:
e360 16 e0 cb           	jsr	seven_segment	; convert Accu A to segment pattern, no DP
e363 ce 00 00           	ldx	#REGBLK
e366 6a e2 02 60        	staa	pth,x
e36a b6 10 10           	ldaa	brtness		; was read from adc
e36d 27 0b              	beq	turn_off	; if =0, turn off display 
                        
e36f ce 00 0d           back:	ldx	#13		; make approx. 3.25 us delay per ADC count
e372 09                 back1:	dex			; 1 cycle
e373 08                 	inx			; 1 cycle
e374 09                 	dex			; 1 cycles
e375 26 fb              	bne	back1		; 3 cycles
e377 43                 	deca
e378 26 f5              	bne	back
                        
e37a                    turn_off:
e37a ce 00 00           	ldx	#REGBLK
e37d 69 e2 02 60        	clr	pth,x
                        ;
e381 f7 10 0c           wait:	tst	d1ms_flag
e384 27 fb              	beq	wait
e386 79 10 0c           	clr	d1ms_flag
e389 fd 10 14           	ldy	loop_count
e38c 02                 	iny
e38d 7d 10 14           	sty	loop_count
e390 bd 10 17           	cpy	speed
e393 2d 16              	blt	jmpbeg
e395 cd 00 00           	ldy	#0
e398 7d 10 14           	sty	loop_count
e39b f6 10 16           	ldab	direction
e39e c1 02              	cmpb	#COUNT_DOWN
e3a0 27 0c              	beq	check_down
e3a2 b6 10 13           	ldaa	disp_data
e3a5 42                 	inca
e3a6 84 0f              	anda	#$0f
e3a8 7a 10 13           	staa	disp_data
e3ab 06 e2 d5           jmpbeg:	jmp	begin
                        ;
e3ae                    check_down:
e3ae b6 10 13           	ldaa	disp_data
e3b1 43                 	deca
e3b2 84 0f              	anda	#$0f
e3b4 7a 10 13           	staa	disp_data
e3b7 06 e2 d5           	jmp	begin
                        ;
e3ba                    spk_on:	
e3ba 34                 	pshx
e3bb ce 00 00           	ldx	#REGBLK
e3be 0d e0 48 08        	bclr 	tctl1,x OM5
e3c2 0c e0 48 04        	bset 	tctl1,x OL5		; toggle speaker
e3c6 30                 	pulx
e3c7 3d                 	rts
e3c8                    spk_off:
e3c8 34                 	pshx
e3c9 ce 00 00           	ldx	#REGBLK
e3cc 0c e0 48 08        	bset 	tctl1,x OM5
e3d0 0d e0 48 04        	bclr 	tctl1,x OL5		; turn off speaker
e3d4 30                 	pulx
e3d5 3d                 	rts
                        
e3d6                    timer6:
e3d6 72 10 11           	inc	count_5ms
e3d9 b6 10 11           	ldaa	count_5ms
e3dc 81 05              	cmpa	#5
e3de 26 62              	bne	tmr3
e3e0 79 10 11           	clr	count_5ms
                        ;
                        ; processing every 5ms
e3e3 b6 10 0a           	ldaa	sound_start
e3e6 27 5a              	beq	tmr3
e3e8 b6 10 04           	ldaa	sound_dur		; duration
e3eb 43                 	deca
e3ec 7a 10 04           	staa	sound_dur
e3ef 26 51              	bne	tmr3
e3f1 fe 10 05           	ldx	xsound_save
e3f4 e6 00              repeat:	ldab	0,x
e3f6 c1 ff              	cmpb	#255
e3f8 27 31              	beq	sound_end
e3fa a6 01              	ldaa	1,x
e3fc 81 ff              	cmpa	#255
e3fe 27 2b              	beq	sound_end
e400 7a 10 04           	staa	sound_dur
e403 08                 	inx
e404 08                 	inx
e405 7e 10 05           	stx	xsound_save
e408 c1 fe              	cmpb	#$fe
e40a 26 0b              	bne	not_rest
e40c 86 01              	ldaa	#1
e40e 7a 10 0b           	staa	rest_note
e411 16 e3 c8           	jsr	spk_off
e414 06 e4 42           	jmp	tmr3
e417                    not_rest:
e417 79 10 0b           	clr	rest_note
e41a 16 e3 ba           	jsr	spk_on
e41d ce e0 03           	ldx	#NOTE_TABLE
e420 58                 	aslb
e421 1a e5              	abx
e423 ee 00              	ldx	0,x
e425 7e 10 02           	stx	spk_tone
e428 06 e4 42           	jmp	tmr3	
e42b                    sound_end:
e42b b6 10 07           	ldaa	sound_repeat
e42e 27 06              	beq	no_rep
e430 fe 10 08           	ldx	xsound_beg
e433 06 e3 f4           	jmp	repeat
                        
e436 ce 0d 65           no_rep:	ldx	#F3500HZ	; 3.5kHz
e439 7e 10 02           	stx	spk_tone
e43c 16 e3 c8           	jsr	spk_off
e43f 79 10 0a           	clr	sound_start
                        
e442 ce 00 00           tmr3:	ldx	#REGBLK		; in interrupt servicing routine
e445 72 10 0c           	inc	d1ms_flag
e448 cc 5d c0           	ldd	#TB1MS		; 1 ms time base
e44b e3 e0 5c           	addd	tc6,x
e44e 6c e0 5c           	std	tc6,x
e451 86 40              	ldaa	#DB6
e453 6a e0 4e           	staa	tflg1,x		; clear flag
e456 0b                 	rti
                        
e457                    timer5_spk:
e457 ce 00 00           	ldx	#REGBLK		; in interrupt servicing routine
e45a fc 10 02           	ldd	spk_tone
e45d e3 e0 5a           	addd	tc5,x
e460 6c e0 5a           	std	tc5,x
e463 86 20              	ldaa	#DB5
e465 6a e0 4e           	staa	tflg1,x		; clear flag
e468 0b                 	rti
                        
e469                    start_sound:
e469 ce e4 91           	ldx	#SONG
e46c 7e 10 08           	stx	xsound_beg
e46f 86 01              	ldaa	#1
e471 7a 10 07           	staa	sound_repeat
e474 e6 00              	ldab	0,x
e476 a6 01              	ldaa	1,x
e478 7a 10 04           	staa	sound_dur
e47b 08                 	inx
e47c 08                 	inx
e47d 7e 10 05           	stx	xsound_save
                        
e480 ce e0 03           	ldx	#NOTE_TABLE
e483 58                 	aslb
e484 1a e5              	abx
e486 ee 00              	ldx	0,x
e488 7e 10 02           	stx	spk_tone
e48b 86 01              	ldaa	#1
e48d 7a 10 0a           	staa	sound_start
e490 3d                 	rts
                        
e491 24 32              SONG:	fcb	$20+note_e,dur18
e493 23 32              	fcb	$20+note_ds,dur18
e495 24 32              	fcb	$20+note_e,dur18
e497 23 32              	fcb	$20+note_ds,dur18
e499 24 32              	fcb	$20+note_e,dur18
e49b 1b 32              	fcb	$10+note_b,dur18
e49d 22 32              	fcb	$20+note_d,dur18
e49f 20 32              	fcb	$20+note_c,dur18
e4a1 19 64              	fcb	$10+note_a,dur14
                        ;	fcb	$fe,dur18
                        ;	fcb	255,255
                        
e4a3 04 32              	fcb	$00+note_e,dur18
e4a5 09 32              	fcb	$00+note_a,dur18
e4a7 10 32              	fcb	$10+note_c,dur18
e4a9 14 32              	fcb	$10+note_e,dur18
e4ab 19 32              	fcb	$10+note_a,dur18
e4ad 1b 64              	fcb	$10+note_b,dur14
e4af 08 32              	fcb	$00+note_gs,dur18
e4b1 12 32              	fcb	$10+note_d,dur18
e4b3 14 32              	fcb	$10+note_e,dur18
e4b5 18 32              	fcb	$10+note_gs,dur18
e4b7 1b 32              	fcb	$10+note_b,dur18
e4b9 20 64              	fcb	$20+note_c,dur14
                        
e4bb 04 32              	fcb	$00+note_e,dur18
e4bd 09 32              	fcb	$00+note_a,dur18
e4bf 14 32              	fcb	$10+note_e,dur18
e4c1 fe 64              	fcb	$fe,dur14
e4c3 ff ff              	fcb	255,255
                        
                        ; See the secondary vector table addresses at page 38 of AN2153
efe2                    	org	$EFE2
efe2 e3 d6              	fdb	timer6
efe4                    	org	$EFE4
efe4 e4 57              	fdb	timer5_spk
effe                    	org	$EFFE
effe e2 46              	fdb	start
                        	end

Executed: Thu Dec 29 16:42:36 2005
Total cycles: 1209, Total bytes: 1227
Total errors: 0, Total warnings: 0
