*************************************************
*						*
*     Program:	Port E Switch I/O		*
*						*
*     Name   :	porte.src			*
*						*
*     Date   :	22 Jan 1999			*
*						*
*     By     :	Steven J. Dombrowski		*
*						*
*						*
*     This program reads all 8 switches on	*
* the M68HC11EVB and continuously updates all	*
* readings.					*
*						*
* Since PE0 is also used to select the Buffalo	*
* monitor or EEPROM upon reset, you should put	*
* 7E E0 0A at EEPROM location $B600 using the	*
* MM command.  Then move jumper J4 from pins 1-2*
* to 2-3.  Pressing the reset button will put	*
* you into the Buffalo monitor. 		*
*						*
*     To execute this program type G 6000 <CR>	*
*						*
*************************************************
*			      *
*  program origin and equates *
*			      *
*******************************
	 org $6000
outcrlf  equ $ffc4
outstrg0 equ $ffca
outa	 equ $ffb8
porte    equ $100a
swmsg1	 equ $c000
swmsg2	 equ $c100
	ldx #swmsg1
	ldy #table1
	ldab #$29
loop1	ldaa 0,y
	staa 0,x
	inx
	iny
	decb
	cmpb #0
	bne loop1
	ldx #swmsg2
	ldy #table2
	ldab #$29
loop2	ldaa 0,y
	staa 0,x
	inx
	iny
	decb
	cmpb #0
	bne loop2
************************
*		       *
* Introductory message *
*		       *
************************
	ldaa #$1a		* clear screen
	jsr outa
	ldab #04		* skips 4 lines on
	jsr lines		*   the screen
	ldaa #26		* skips 26 spaces on
	jsr spaces		*    the screen
	ldx #line1		* prints program title
	jsr outstrg0		* message
	ldab #2 		* skips 2 lines on
	jsr lines		* the screen
	ldaa #29		* skips 29 spaces on
	jsr spaces		* the screen
	ldx #line2		* prints program
	jsr outstrg0		* message
	ldab #2 		* skips 2 lines on
	jsr lines		* the screen
	ldaa #27		* skips 27 spaces on
	jsr spaces		* the screen
	ldx #line3		* prints program
	jsr outstrg0		* message
	ldab #2 		* skips 2 lines on
	jsr lines		* the screen
	ldaa #24		* skips 24 spaces on
	jsr spaces		* the screen
	ldx #line4		* prints location
	jsr outstrg0		* message
	ldab #6 		* skips 6 lines on
	jsr lines		* the screen
************************
*		       *
* Main part of program *
*		       *
************************
start	ldaa porte
	anda #1
	jsr  rh 	
	staa swmsg1+13	* output to screen
	ldaa porte
	anda #2
	lsra
	jsr  rh 	
	staa swmsg1+21	* output to screen
	ldaa porte
	anda #4
	lsra
	lsra
	jsr rh
	staa swmsg1+29	* output to screen
	ldaa porte
	anda #8
	lsra
	lsra
	lsra
	jsr  rh 	
	staa swmsg1+37	* output to screen
	ldaa porte
	anda #$10
	lsra
	lsra
	lsra
	lsra
	jsr rh
	staa swmsg2+13	* output to screen
	ldaa porte
	anda #$20
	lsra
	lsra
	lsra
	lsra
	lsra
	jsr  rh 	* convert right nibble to ascii
	staa swmsg2+21	* output to screen
	ldaa porte
	anda #$40
	lsra
	lsra
	lsra
	lsra
	lsra
	lsra
	jsr rh
	staa swmsg2+29	* output to screen
	ldaa porte
	anda #$80
	lsra
	lsra
	lsra
	lsra
	lsra
	lsra
	lsra
	jsr  rh 	* convert right nibble to ascii
	staa swmsg2+37	* output to screen
	ldaa #20	* indent 20 spaces
	jsr spaces
	ldx #swmsg1	* display sw1-4
	jsr outstrg0
	jsr bkspc	* update switch readings
	jsr outcrlf
	jsr outcrlf
	ldaa #20	* indent 20 spaces
	jsr spaces
	ldx #swmsg2	* display sw5-8
	jsr outstrg0
	jsr bkspc	* update switch readings
	ldaa #$0b	* go up 2 lines to ch1-4
	jsr outa
	jsr outa
	jmp start	* continue program
***********************************
*				  *
*  Subroutine to backspace cursor *
*				  *
***********************************
bkspc	ldy #$40
bkspc1 ldaa #$08
	jsr outa
	dey
	cpy #0
	bne bkspc1
	rts
*******************************
*			      *
* Subroutine to convert right *
* half of binary byte in acca *
* to an ascii character       *
*			      *
*******************************
rh	asla
	asla
	asla
	asla
	lsra
	lsra
	lsra
	lsra
	anda #$0f
	adda #$30
	cmpa #$39
	ble out1
	adda #$07
out1	rts
******************************************
*					 *
* Subroutine to skip lines on the screen *
*					 *
******************************************
lines	  jsr outcrlf
	  decb
	  cmpb #0
	  bne lines
	  rts
*******************************************
*					  *
* Subroutine to skip spaces on the screen *
*					  *
*******************************************
spaces	  tab
	  ldaa #$20
spaces2   jsr outa
	  decb
	  cmpb #0
	  bne spaces2
	  rts
******************************************************
*						     *
*		   Screen messages		     *
*						     *
******************************************************
table1 fcc 'reading sw0:    sw1:    sw2:    sw3:    '
       fcb 4
table2 fcc 'reading sw4:    sw5:    sw6:    sw7:    '
       fcb 4
line1  fcc 'Port E Switch I/O Program'
       fcb 4
line2  fcc 'using the M68HC11EVB'
       fcb 4
line3  fcc 'by Steven J. Dombrowski'
       fcb 4
line4  fcc 'Rensselaer Polytechnic Institute'
       fcb 4
