#make_COM#

; COM file is loaded at CS:0100h
; (the value of CS is set by Operating System)
ORG 100h


	lea bx,buff	;initialize
	mov cl,00h
	mov ch,00h

	mov al,0ffh	;set Parallel Port D0-D7 high
	mov dx,0378h	;to power card reader
	out dx,al

	mov dx,0ffffh	;pause to allow card reader time
l4:	call pause	;to power up
	dec dx	
	jnz l4

l9:	mov dx,0379h	;wait for card detect
	in al,dx
	and al,08h
	jnz l9

l1:	mov dx,0379h
	in al,dx	;get new input
	mov new,al
	and al,08h	;if card detect is high (no
	jz l8		;card) display card number
	jmp display
l8:	mov al,new	
	and al,20h	;check clock bit is low
	jnz l1		;if not loop to l1
	
	mov al,new	;get last input
	and al,10h	;check data bit
	clc		;clear carry for shift
	shr cl,1	;shift in from 32 bit
	add cl,al	;add new bit
	
	inc ch		;if 5 bits then
	
	cmp ch,05h
	jnz l7

	not cl			;not it 
	and cl,0fh		;strip parity bit
	mov [bx],cl		;store
	mov ch,0		;clear count
	mov cl,0		;clear value
	inc bx			;inc memory loc to store to
	
l7:	mov dx,0379h	;wait for clock to go high
	in al,dx
	and al,20h
	jz l7
	
	jmp l1		;get next bit of data
	

display:
	lea bx,buff
	mov si,5
	mov cl,0ah
la:	mov al,[bx+si]
	add al,30h
	mov ah,0eh
	int 10h
	inc si
	dec cl
	jnz la
	ret
	
pause:	push dx		;pause routine
	mov dx,0100h
l3:	dec dx
	jnz l3
	pop dx
	ret

new	db 	0
buff	db 	0 DUP(38)