*********
* Program PARITY_1 (6811)
*
* Reads switchs.  Ouput char O or E depending on parity of
* switch settings.
*
* Equipment configuration:  See attached figure.
*
* Theory:  Uses shift technique to count number of ones.
*          Then determines if number of ones is even or odd.
*
* P. H. Anderson, 12 Sept 91; Checked 12 Sept 91; 15 Jan 93
**********

PSCT    EQU $C000
DSCT    EQU $D000
IDSCT	EQU $D300

REG_BASE	EQU $1000

PORTB   EQU $04
PORTC   EQU $03
DDRC    EQU $07

        ORG PSCT

	LDY #REG_BASE
        CLR DDRC,Y      * portc configured as input
TOP
	CLR NUM_ONES	* zero number of ones

	LDAA #$08	* 8 bits to examine
	STAA BITS_LEFT

        LDAA PORTC,Y    * get the switches

L1	
	LSRA
	BCC AROUND

	INC NUM_ONES	* bit was a one

AROUND	
	DEC BITS_LEFT
	BNE L1

* at this point all 8 bits have been examined.

	LDAA NUM_ONES
	ANDA #$01	* examine lsb to determine if even or odd
	BEQ EVEN_PAR
	BNE ODD_PAR

EVEN_PAR
        LDAA EVEN
        STAA PORTB,Y	* output the character E
        BRA TOP

ODD_PAR
        LDAA ODD
        STAA PORTB,Y	* output the character O
        BRA TOP

        ORG DSCT

NUM_ONES  RMB 1
BITS_LEFT RMB 1

	ORG IDSCT

EVEN FCB $18	* to display character 'E'
ODD  FCB $02	* to display character 'O'


