*********
* Program ILLOP_1 (6811)
*
* Illustrates the use of the illegal op code trap to implement a function.
*
* Uses opcode 18 00 to wink an LED on and off one time.
* Note that 18 is a double opcode, and 18 00 is not defined in the Motorola
* 68HC11 instruction set.
*
* P. H. Anderson, 15 Oct 90, 22 Feb 91; 15 Jan 93
*********

PSCT		EQU $C000
DSCT		EQU $D000
IDSCT		EQU $D300

STACKTP         EQU $0045
REG_BASE	EQU $1000
ILLOP_VECT      EQU $00F7

DDRC    EQU $07
PORTB   EQU $04       * output
PORTC   EQU $03       * input

        ORG PSCT

        LDS #STACKTP
	LDY #REG_BASE

        CLR DDRC,Y
        BCLR PORTB,Y,#%10000000	     * zero LED 7
        LDAA PORTC,Y		     * fetch sw
        STAA TIMES_LEFT
AGN
        FDB $1800       * illegal opcode - wink the LED
        DEC TIMES_LEFT
        BNE AGN

        SWI

WINK
	STY PTR1
	STX PTR2
        TSX             * load X with SP+1
        LDY 07,X        * adjust the program counter to point
        INY             * to instruction after 18 00 on return from
        INY             * interrupt
        STY 07,X
	LDY PTR1
	LDX PTR2

        BSET PORTB,Y,#%10000000       * wink LED 7
        BSR TIME
        BCLR PORTB,Y,#%10000000
        BSR TIME

        RTI

TIME
        PSHX
        LDX #50000
L1
        DEX
        BNE L1
        PULX
        RTS

        ORG ILLOP_VECT

        JMP WINK

        ORG DSCT

TIMES_LEFT      RMB 1
PTR1		RMB 2
PTR2		RMB 3

