**********
* PASS_STK (6811)
*
* Illustrates use of the stack in passing parameters to a subroutine.
* This is the convention used by C in passing parameters to functions.
*
* Read switches and causes LED 0 to pulse on and off number of times
* set by switches.  Also provides ability to vary the time.
*
* P. H. Anderson, MSU, 10 March 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	* load reg_base
	CLR DDRC,Y	* port c configured as 8-bit input

	CLR PORTB,Y	* zero the LEDs

	LDAA PORTC,Y	* get switches - times to wink
	PSHA			* place on stack
	LDAA #50		* some kind of time variable
	PSHA			* place on stack
	BSR WINK
	INS			* to adjust stack
	INS

	SWI

WINK
	TSX			* get top of stack
	LDAA 02,X		* get the parameters
	STAA W_TIME		* off the top of the stack
	LDAA 03,X
	STAA W_WINKS

PT_1
	BSET PORTB,Y %00000001	* turn on LED
	LDAA W_TIME		* delay
	PSHA
	JSR TIME
	INS			* to align stack

	BCLR PORTB,Y %00000001	* turn off and delay
	LDAA W_TIME
	PSHA
	JSR TIME
	INS

	DEC W_WINKS		* continue if more winks
	BNE PT_1
	RTS

TIME
	TSX			* get parameter off top of stack
	LDAA 00,X
	STAA T_TIME

	LDAA T_TIME
	LDAB #$FF
	MUL			* D = n * $FF
	XGDX			* interchange D and X
T1
	DEX			* standard time delay
	BNE T1

	RTS

	ORG DSCT

W_WINKS	RMB 1
W_TIME	RMB 1
T_TIME	RMB 1


