	.TITLE	CDTEST
/
/  13 MAR 75 - PAUL HENDERSON
/
/  PROGRAM TO READ CARD DECK AND CHECK TO SEE IF THE CHARACTERS
/  READ ARE AS EXPECTED.  IF CHARACTER NOT SAME, THEN A PARTICULAR
/  ROW ON THE CARD HAS BEEN DROPPED, SINCE ONLY ONE PUNCH IS
/  PRESENT IN ANY ONE COLUMN.
/
TTO=-3
DK=-11
AUTO12=12
IDX=ISZ	/ INDEX, SKIP NOT EXPECTED
/
	.IODEV	DK,TTO
/
	.GLOBL	MAC89,M89CMD
/
MAC89	XX
	LAC	M89CMD+4
	LRSS	12		/ SHIFT CHARACTER INTO MQ
	RAR			/ CONVERT 7- TO 6-BIT
	LRSS	6		/ SHIFT 2ND CHARACTER INTO MQ
	LAW	15
	LRSS	6		/ MQ NOW CONTAINS 'MNN'
	LACQ
	DAC	NAME
	DZM	CRDCNT
	.INIT	DK,0,EOF
	.SEEK	DK,NAME
RESET	LAW	-14
	DAC	TBLCNT		/ 12 (DECIMAL) CHARACTERS IN TABLE
	LAC	(TBLE
	DAC	CHRPNT
/
READCD	.READ	DK,2,LINE,36	/ READ A CARD
	.WAIT	DK
	LAC	LINE
	AND	(7
	SAD	(2
	SKP
	JMP	EOF		/ RETURN ON END OF FILE
	IDX	CRDCNT		/ COUNT CARD READ
	LAC	(LINE+2
	DAC	UNP+1
	LAC	(IMAGE		/ POINTERS FOR UNPACK
	DAC	UNP+2
UNP	JMS	UNPACK
	0; 0
	SMA
	JMP	UNP
	LAC	(IMAGE-1
	DAC*	(AUTO12		/ CHECK CHARACTERS VIA AUTO-INDEX
	LAW	-120		/ 80 CHARACTERS PER CARD
	DAC	CHRCNT
	DZM	COLCNT		/ COLUMN COUNTER
	LAC*	CHRPNT		/ GET EXPECTED CHARACTER FROM TABLE
CHKCHR	IDX	COLCNT
	SAD*	AUTO12		/ CHECK AGAINST ACTUALLY READ
	JMP	CHROK
/
	DAC	ERRIMG+7	/ CHARACTER DOES NOT MATCH
	JMS	CARDS		/ TELL CARD COUNT TO DATE
	DZM	CRDCNT		/ RESET CARD COUNTER
	LAC	COLCNT		/ ANNOUNCE COLUMN IN ERROR & GOOD CHAR
	STL			/ CONVERT LEADING ZEROS TO SPACES
	JMS	OCTDEC
	ERRIMG
	LAC	(ERRIMG+4	/ PACK UP ONLY 2 DIGITS
	DAC	PCK+1
	LAC	(ERRBUF+2
	DAC	PCK+2
	.WAIT	TTO		/ IN CASE OF PREVIOUS ERROR ANNOUNCEMENT
PCK	JMS	PACK
	0; 0
	SMA			/ SHOULD ONLY BE ONE PAIR
	JMP	PCK
	.WRITE	TTO,2,ERRBUF,0	/ 'NN C' - COLUMN NUMBER & CHARACTER
	LAC*	CHRPNT		/ RETRIEVE CHHECK CHARACTER
/
CHROK	ISZ	CHRCNT
	JMP	CHKCHR		/ CHECK NEXT CHARACTER
	IDX	CHRPNT
	ISZ	TBLCNT
	JMP	READCD
	JMP	RESET		/ WE HAVE REACHED END OF TABLE.
/
EOF	.CLOSE	DK
	JMS	CARDS
	JMP*	MAC89		/ RETURN
/
CARDS	XX
	LAC	CRDCNT
	STL
	JMS	OCTDEC		/ ANNOUNCE HOW MANY CARDS SINCE LAST ERROR
	ERRIMG
	LAC	(ERRIMG+1	/ WANT ONLY 5 CHARACTERS
	DAC	PCK2+1
	LAC	(CRDS+2
	DAC	PCK2+2
	.WAIT	TTO
PCK2	JMS	PACK
	0; 0
	.WRITE	TTO,2,CRDS,0
	JMP*	CARDS
/
LINE	.BLOCK	44
IMAGE	.BLOCK	130
ERRBUF	3002
ERRIMG	.BLOCK	6
	40; 0; 15
TBLE	46; 55			/ '&','-'; ROWS 12 & 11 ON CARD
	60; 61; 62; 63; 64	/ '0'-'4'; ROWS 0-4 ON CARD
	65; 66; 67; 70; 71	/ '5'-'9'; ROWS 5-9 ON CARD
TBLCNT;CHRPNT;CHRCNT;COLCNT;CRDCNT
CRDS	CDS-.*400+2; 0
	.ASCII	'12345 CARDS SINCE LAST ERROR'<15> ;CDS=.
M89CMD	.BLOCK	6
NAME	.SIXBT	'M00@@@SRC'
	.TITLE ASCII PACK-UNPACK SUBROUTINE
/
/  CALLING SEQUENCE
/
/	JMS*	PACK (OR UNPACK)
/	.DSA	ADDRESS OF INPUT CHARACTERS
/	.DSA	ADDRESS OF OUTPUT CHARACTERS
/
/THE ADDRESSES ARE INCREMENTED BY THE PROPER AMOUNT TO POINT TO THE
/WORDS IN THE BUFFER.  WHEN CARRIAGE RETURN OR ALT MODE IS ENCOUNTERED,
/THE AC IS SET TO -1 (.TRUE.) ON EXIT FROM THE SUBROUTINE.  HENCE,
/NORMAL CALLING SEQUENCE WOULD BE:
/
/	JMS*	PACK (OR UNPACK)
/	.DSA	ADDRESS IN
/	.DSA	ADDRESS OUT
/	SMA
/	JMP	.-4
/
/
PACK	XX
	LAC*	PACK
	DAC	IN
	TAD	(5
	DAC*	PACK
	ISZ	PACK
	LAC*	PACK
	DAC	OUT
	TAD	(2
	DAC*	PACK
	ISZ	PACK	/POINT TO RETURN
	LAW	-5	/SET A COUNTER TO PROCESS
	DAC	COUNT	/5 CHARACTERS
	CLL		/CLEAR LINK TO PREVENT CONFUSION TO EAE
NEXT	LAC*	IN
	JMS	END	/CHECK FOR END OF LINE
	DAC	END	/HANDY PLACE TO STORE TEMPORARILY
	LAC	TWO
	LMQ
	LAC	ONE	/LOAD TWO WORDS
	LLS	7
	DAC	ONE	/STORE SHIFTED LEFT HALF
	LAC	END
	OMQ		/ADD IN NEW CHARACTER
	DAC	TWO	/STORE NEW RIGHT HALF
	ISZ	IN	/POINT TO NEXT CHARACTER
	ISZ	COUNT	/5 CHARACTERS YET?
	JMP	NEXT	/NO
	LAC	TWO	/YES
	RCL
	DAC	TWO	/MUST SHIFT EXTRA PLACE ON PACK
	LAC	ONE
	RAL
	DAC*	OUT	/RETURN PACKED PAIR TO USER
	ISZ	OUT
	LAC	TWO
	DAC*	OUT
	LAC	LNEND	/EXIT WITH END OF LINE FLAG
	DZM	LNEND	/IN AC
	JMP*	PACK
/
/
UNPACK	XX
	LAC*	UNPACK
	DAC	IN
	TAD	(2
	DAC*	UNPACK
	ISZ	UNPACK
	LAC*	UNPACK
	DAC	OUT
	TAD	(5
	DAC*	UNPACK
	ISZ	UNPACK
	LAW	-5	/PREPARE TO PROCESS 5
	DAC	COUNT	/CHARACTERS
	LAC*	IN
	DAC	ONE
	ISZ	IN
	LAC*	IN
	DAC	TWO
	CLL		/CLEAR LINK FOR EAE
NEXT2	LAC	ONE
	LRS	13	/GET 1ST CHARACTER RIGHT AWAY
	JMS	END
	DAC*	OUT	/RETURN IT TO USER
	ISZ	COUNT	/5 CHARACTERS YET?
	SKP
	JMP	PAST	/YES
	ISZ	OUT	/NO
	LAC	TWO	/ROTATE PAIR LEFT TO GET NEXT ONE
	LMQ
	LAC	ONE
	LLS	7
	DAC	ONE
	LACQ
	DAC	TWO
	JMP	NEXT2
PAST	LAC	LNEND	/EXIT WITH END-OF-LINE FLAG
	DZM	LNEND	/IN AC
	JMP*	UNPACK
/
IN;OUT;COUNT;LNEND
/
ONE;TWO
/
END	XX
	AND	(177
	SAD	(15	/CHECK FOR CARRIAGE RETURN
	SKP
	SAD	(175	/AND ALT MODE
	SKP
	JMP*	END	/GO AWAY IF NEITHER
	LMQ		/SAVE CHARACTER TEMPORARILY
	LAW	-1	/SET END-OF-LINE FLAG TO
	DAC	LNEND	/.TRUE. (-1) IF FOUND
	LACQ
	JMP*	END
	.TITLE	OCTDEC
/
/   4 DEC 74 (PDH) ADD '.DIGCT' FOR DIGITS CONVERTED COUNTER
/  21 FEB 73 - FIX UP PROBLEM WITH NUMBERS .GT. 377777
/		ALSO ADD TEST PROGRAM TO END OF FILE.
/  17 SEP 72 - PAUL HENDERSON
/
/  SUBROUTINE TO CONVERT A BINARY NUMBER TO DECIMAL AND STORE IT
/  AS SIX IMAGE ASCII CHARACTERS
/
/  CALLING SEQUENCE:
/
/	LINK
/	LAC	NUMBER
/	JMS	OCTDEC
/	.DSA	LINE	/ADDRESS OF IMAGE ASCII LINE
/	(RETURN)
/
/     WHERE LINK= ' STL' TO CONVERT LEADING ZEROS TO SPACES
/		= ' CLL' TO OUTPUT LEADING ZEROS
/
/  NOTE:  1) THE ADDRESS OF THE IMAGE ASCII LINE IS NOT INCREMENTED
/
/	 2) THE NUMBER OF DIGITS CONVERTED IS CONTAINED IN GLOBAL
/	    VARIABLE '.DIGCT'.  IF LEADING ZEROS ARE OUTPUT, '.DIGCT'
/	    WILL ALWAYS BE '6', OTHERWISE .DIGCT=(6 - # OF LEADING ZEROS)
/
/
/  IF IT IS DESIRED TO GENERATE A TEST PROGRAM TO TEST OUT ANY
/  FURTHER CHANGES TO 'OCTDEC', SIMPLY DEFINE THE SYMBOL
/
/TEST=0
/
/  AT ASSEMBLY TIME, AND THE RESULTING BINARY FILE CAN THEN
/  BE RUN.  OUTPUT IS VIA THE .DAT ASSOSIATED WITH THE
/  SYMBOL 'TT', WHICH, AT PRESENT, IS 4.
/
/
OCTDEC	XX
	DAC	DECPUT	/NUMBER TO BE CONVERTED IS IN AC
	DZM	.DIGCT		/ CLEAR # F DIGITS COUNTER
	CLA!RAR
	DAC	LEAD0		/SET OR CLEAR FLAG
	LAC*	OCTDEC
	ISZ	OCTDEC		/FETCH LINE POINTER
	DAC	OUTPNT
	LAW	-5
	DAC	DIGCNT	/CONVERT 5 CHARACTERS IN LOOP
	LAC	(FIVE-1
	DAC	TABLE	/POINTER TO CONVERSION TABLE
OK	ISZ	TABLE		/POINT TO CURRENT DIVISOR
	CLL			/FOR THE 'IDIV'
	LAC*	TABLE
	DAC	DIVSR		/MOVE DIVISOR TO CORRECT PLACE
	LAC	DECPUT
	IDIV
DIVSR	XX
	DAC	DECPUT		/STORE REMAINDER
	LACQ		/PICK UP COUNT FOR THIS DIGIT
	SZA
	JMP	STORE	/STORE IF NON-ZERO
	LAC	LEAD0	/IS THIS LEADING ZERO?
	SNA!CLA
	JMP	STORE	/NOT LEADING ZERO.  STORE AS '0'
	LAW	40
	JMP	PUT	/CONVERT LEADING ZERO TO SPACE
STORE	DZM	LEAD0	/FUTURE ZEROS ARE NOT LEADING.
	ISZ	.DIGCT		/ COUNT DIGITS CONVERTED
	XOR	(60	/CONVERT BINARY TO ASCII
PUT	DAC*	OUTPNT	/STORE IN IMAGE BUFFER
	ISZ	OUTPNT
	ISZ	DIGCNT	/COUNT UP TO 5 CHARACTERS
	JMP	OK
	LAC	DECPUT	/CONVERT FINAL BINARY DIGIT TO ASCII,
	XOR	(60	/EVEN IF LEADING ZERO
	DAC*	OUTPNT
	ISZ	.DIGCT		/ COUNT FINAL DIGIT
	JMP*	OCTDEC
/
FIVE	303240;	23420;	1750;	144;	12
TABLE;DECPUT;DIGCNT;LEAD0;OUTPNT;.DIGCT
	.END
