
; test for card swipe

;yellow -> PD5/SS*
;green -> PD4/SCK
;blue -> PD3/MOS1
;Red -> VCC
;Black -> Gnd


	org $2000
	jmp main

DDRD	equ	$1009       ;assign permanent value in addr 1009
SPCR	equ	$1028       ;assign permanent value in addr 1028
SPSR 	equ	$1029       ;assign permanent value in addr 1029
SPDR	equ	$102A       ;assign permanent value in addr 102A
PORTD	equ 	$1008       ;assign permanent value in addr 1008

out1bsp	equ	$FFBE       ;converts the binary byte at the addr in index
out1byte equ     $FFBB
outcrlf equ     $ffc4
outa    equ     $ffb8

;                            register x to two ASC11
buffalo	equ	$E000
INSIDE  fcb      0


data    rmb     30         ; variable data

TABLE   FCC      'X'
	FCC      '0'
	FCC      '8'
	FCC      'X'
	FCC      '4'
	FCC      'X'
	FCC      'X'
	FCC      '<'
	FCC      '2'
	FCC      'X'
	FCC      'X'
	FCC      ':'
	FCC      'X'
	FCC      '6'
	FCC      '>'
	FCC      'X'
	FCC      '1'
	FCC      'X'
	FCC      'X'
	FCC      '9'
	FCC      'X'
	FCC      '5'
	FCC      '='
	FCC      'X'
	FCC      'X'
	FCC      '3'
	FCC      ';'
	FCC      'X'
	FCC      '7'
	FCC      'X'
	FCC      'X'
	FCC      '?'


main	ldaa #$04          ; clears DDRD
	staa DDRD
	LDAA #$47          ; clears SPCR


	staa SPCR
	ldx #data           ;  use 16 bit register to load data
	
L1	LDAA PORTD          ; gives the pins to connect to the board
	anda #$20
	bne L1
	
poll	ldaa PORTD          ; load PORTD in 1008
	anda #$20           ; logical doing the high - low
	beq L2              ; looking for change from high to low
	jmp P_LOOP	    ; done reading the card

L2	LDAA SPSR          ; load SPSR in A loc 102A
	anda #$80          ; logical value in 80
	beq  poll          ; branch if equal to what's in poll

	ldaa SPDR         ;

	COMA              ;

	staa 0,x          ;

;	jsr out1bsp
	inx

	jmp poll
	
P_Loop	; jsr outcrlf       ;

LOOP    JSR LX             ; look for the start sentinel
	LDX #DATA
	LDAA 0,X
	ANDA #%11111000
	CMPA #%11010000
	BNE  LOOP
	
;	LDX #DATA            ; load data in X register
;	LDAB 0,X             ; load character in B
;	ANDB #%11111000      ; logincal AND in B
;	LSRB                 ; move data right 1 time
;	LSRB                 ; move data right 2nd time
;	LSRB                 ; move data right 3rd time

Number	jsr lx              ;
	jsr lx
	jsr lx
	jsr lx
	jsr lx

	LDX #DATA         ; look for the data and than shift to right
	LDAB 0,X
	ANDB #%11111000
	LSRB              ; this is where shift right 3x's
	LSRB
	LSRB

	LDX #TABLE        ; using 16bit load TABLE
	ABX

	ldaa 0,x
	cmpa #'?'
	beq  exit
	JSR outa
	JMP number
	
	
EXIT:   jsr outcrlf
	jmp main



SHIFT:
LX      PSHA                 ; test to shift data in card
	PSHX

	ldx #data

LX1     BRSET  1,X  #$80 LS

	LDAA 0,X              ; looks at the data
	LSLA                    ;compares it and shift
	STAA 0,X              ; once to left if > 0
	INX
	CPX  #DATA+30
	Bge  LX_EXIT
	JMP  LX1
	
LS      LDAA 0,X            ; looks at the data
	SEC                 ; store it until it
	ROLA                ; finds the sequence it's look for
	STAA 0,X
	INX
	CPX #DATA+30
	Bge LX_EXIT
	JMP LX1

LX_EXIT:
	PULx               ;
	PULa
	RTS

	LDAA INSIDE       ; the counter will compare unitl LX1
	STAA              ; finds the correct sequence
	CMPA
	JMP LX1
	


	

	





	

