******
** DIAL_1.ASM  (68HC11)
**
** Illustrates Direct Table Lookup.
**
** Dials tel number identified by toggle switches.  Uses 16
** bytes per tel number.  
**
** Thus address of tel number = TEL_BASE + 16 * SW
**
** P. H. Anderson, MSU, 12 April 93
*******

PSCT            EQU $C000
DSCT            EQU $D000
IDSCT           EQU $D300

REG_BASE        EQU $1000
STACK_TP        EQU $0045

PORTB   EQU $04
PORTC   EQU $03
DDRC    EQU $07

       ORG PSCT

       LDS #STACK_TP
       LDY #REG_BASE
       CLR DDRC,Y      * portc configured as input

       BCLR PORTB,Y %00000001  * release dial relay

       LDAA PORTC,Y
       STAA TEMP
       CLRA
       LDAB TEMP	* D now contains 00 SS where SS are switch values
       LSLD
       LSLD
       LSLD
       LSLD
       STD OFFSET       * OFFSET contains 16 times SW

       LDD #TEL_BASE
       ADDD OFFSET

       XGDX

       BSR DIAL     * address passed in X

       SWI

DIAL
* dial pulses tel number beginning at address pointed to by X.
* fetches each digit in turn and pulses it out with an interdigit pause.
* continues until terminating character $FF.
* returns with no registers disturbed.
       PSHX
       PSHB
       PSHA
TOP
       LDAA 00,X
       CMPA #$00	* if digit 0, add 10
       BNE AROUND_1
       ADDA #10
AROUND_1
       CMPA #$FF	* if terminating character, done
       BEQ DONE
       BSR PULSE        * digit passed in A
       BSR DELAY_LONG	* interdigit interval
       INX
       BRA TOP
DONE
       PULA
       PULB
       PULX
       RTS

PULSE
* Pulses Dial Pulse Relay number of times specified in A
       PSHA
P_TOP
       BSET PORTB,Y #%00000001
       BSR DELAY_SHORT	* operate for period of time
       BCLR PORTB,Y #%00000001
       BSR DELAY_SHORT	* release for period of time
       DECA
       BNE P_TOP
       PULA
       RTS

DELAY_LONG
       PSHX
       LDX #50000
D_L_TOP
       DEX
       BNE D_L_TOP
       PULX
       RTS

DELAY_SHORT
       PSHX
       LDX #10000
D_S_TOP
       DEX
       BNE D_L_TOP
       PULX
       RTS

       ORG DSCT

TEMP   RMB 1
OFFSET RMB 2

       ORG IDSCT
TEL_BASE
* 9 1 201 949 2007
       FCB 09, 01
       FCB 02, 00, 01
       FCB 09, 04, 09, 02, 00, 00, 07
       FCB $FF

       ORG IDSCT+$10
* 3911
       FCB 03, 09, 01, 01, $FF

       ORG IDSCT+$20
* 9 893 8762
       FCB 09, 08, 09, 03, 08, 09, 03, 08, 07, 06, 02
       FCB $FF


