	.TITLE	ROMSIM
/
/  12 JUL 78 (017; PDH) EXIT ON COMMAND '/*'
/   8 JUN 78 (016; PDH) ADD PROVISION FOR 20K MEMORY
/   8 DEC 77 (015; PDH) ESTABLISH OUTPUT FILE NAME FOR 'PP', IN CASE
/			OF FILE-ORIENTED OUTPUT; CHANGE 'LP' TO 6.
/   6 OCT 77 (014; PDH) MAKE SURE THAT A PATCH BEFORE THE LAST 'BLK'
/			DOES NOT CAUSE CLOBBER DATA IN THE PSEUDO-MEMORY
/   9 MAY 77 (013; PDH) ADD OPTIONS 'L', 'X'
/   9 MAY 77 (012; PDH) ALLOW UP TO 12K PSEUDO-MEMORY
/   4 MAY 77 (008; PDH) ADD CASE 10
/   3 MAY 77 (004; PDH) CONVERT TO XVM/RSX
/  21 OCT 75 (PDH) CHANGE ARROW FORMAT
/  17 OCT 75 (PDH) CORRECT CHECK FOR 'BLK'
/   6 OCT 75 - PAUL HENDERSON
/
	.EJECT
/  PROGRAM TO PRODUCE A PAPER TAPE FOR PROGRAMMING ROM'S,
/  FROM SPECIFICATIONS PROVIDED BY NCR, WATERLOO.
/
/  THIS IS NOW A BATCH PROGRAM, WITH COMMAND AND DATA INPUT VIA LUN 12.
/
/  THE COMMAND RECORD IMMEDIATELY PRECEDES THE DATA RECORDS, AND
/  IS OF THE FORM:
/
/	OPT_CASE
/
/  WHERE 'OPT' IS ONE OR MORE OF
/
/		N - INPUT NEW DECK
/		L - PRODUCE OUTPUT LISTING
/		X - DO NOT PRODUCE PUNCHED TAPE
/
/  AND 'CASE' IS A NUMERICAL FIELD, DEPENDENT ON TAPE SPECIFICATIONS.
/
/  DATA RECORDS ARE READ UNTIL AN END-OF-FILE ($EOF) IS ENCOUNTERED.
/  FOLLOWING THE END-OF-FILE, ANOTHER COMMAND IS EXPECTED.  IF	/(017)
/  THERE ARE NO MORE COMMANDS, A CARD BEGINNING			/(017)
/  '/*' MAY BE INSERTED.					/(017)
/
	.DEC
LP=6								/(015)
TTO=13
TTI=12
CD=12
PP=7
MEMSIZ=20480	/ 20K MEMORY SIZE (X'5000')			/(016)
	.OCT
X14=14
IDX=ISZ         / INDEX POINTER (SKIP NOT EXPECTED)
SET=ISZ	/ SET A FLAG NON-ZERO
ECLA=641000	/ EAE CLEAR AC INSTRUCTION
/
	.GLOBL	PACK,UNPACK,.IOERR
/
/
	.EJECT
ROMSIM	CAL	WRBL		/ BEGIN WITH A BLANK LINE
	CAL	WRHELO		/ 'ROMSIM V2A.  COMMAND  >'
	JMS	WTFOR
	EVTTO
	CAL	READCM		/ READ COMMAND LINE
	JMS	WTFOR
	EVTTI
	LAC	(ILINE+2
	DAC	UNPCM+1		/ SET UP POINTERS TO UNPACK COMMAND LINE
	LAC	(IMAGE
	DAC	UNPCM+2
UNPCM	JMS*	UNPACK		/ UNPACK COMMAND LINE
	0; 0
	SMA
	JMP	UNPCM
/
	DZM	LSTSW		/ DEFAULT OPTIONS ARE NO LISTING,
	DZM	NEWSW		/ DON'T READ IN A NEW DECK,
	SET	PCHSW		/ DO PRODUCE PUNCHED TAPE,
	DZM	CASES		/ AND CASE 0
	LAC	(200
	PAL			/ STOP AT END OF IMAGE BUFFER
	CLX
GETOPT	LAC	IMAGE,X		/ GET A CHARACTER
	SAD	(116		/ IS IT 'N'?
	SET	NEWSW
	SAD	(114		/ 'L'?
	SET	LSTSW
	SAD	(130		/ 'X'?
	DZM	PCHSW
	SAD	(137		/ '_' (UNDERSCORE OR BACK ARROW)
	JMP	GETCASE		/ END OF OPTIONS.
	SAD	(057		/ '/' ?				/(017)
	SKP							/(017)
	JMP	NXTCHR						/(017)
	LAC	IMAGE+1,X					/(017)
	SAD	(052		/ '*' ?				/(017)
	CAL	(10		/ '/*' MEANS EXIT TASK		/(017)
 
NXTCHR	AXS	1						/(017)
	JMP	GETOPT
/
BADCMD	CAL	WRINVC		/ 'INVALID COMMAND'
	JMS	WTFOR
	EVTTO
	JMP	ROMSIM
/
	.EJECT
GETCASE	AXR	1		/ INDEX TO CHARACTER AFTER THE '_'
GET1	LAC	IMAGE,X		/ SELECT A CHARACTER
	AND	(170
	SAD	(60		/ IS IT AN OCTAL DIGIT?
	SKP!CLL
	JMP	GET2		/ NO.  TERMINATE CASE ASSEMBLY.
	LAC	IMAGE,X		/ RETRIEVE ASCII DIGIT
	AND	(7		/ EXTRACT NUMERIC VALUE
	LMQ
	LAC	CASES
	ALS	3		/ MOVE TO MAKE ROOM FOR NEXT DIGIT
	OMQ			/ INSERT NEW DIGIT
	DAC	CASES		/ AND SAVE UPDATED VALUE
	AXS	1
	JMP	GET1		/ LOOP UNTIL NON-NUMERIC CHARACTER FOUND
/
GET2	LAC	CASES		/ DO WE HAVE A CASE?
	SNA
	JMP	BADCMD		/ NO CONTEST!
	LAC	NEWSW		/ SHOULD WE INPUT A NEW DECK?
	SNA
	JMP	CASE1		/ DO NOT INPUT NEW DECK
/
	.DEC
	LAC	(-MEMSIZ         / COMMAND CHAR IS 'N': INPUT NEW DECK
	.OCT
	DAC	COUNT
	LAW	-1
	TAD	PAGE0
	DAC*	(X14
CLRMEM	DZM*	X14		/ INITIALIZE PSEUDO-MEMORY TO ZERO
	ISZ	COUNT
	JMP	CLRMEM
/
	.EJECT
LOADER	CAL	ATTCD		/ ATTACH CARD READER		/(016)
	JMS	WTFOR		/ JUST FOR GOOD INSURANCE	/(016)
	EVCD							/(016)
	LAC	(PAGE0
	DAC	PAGPNT		/ START WITH PAGE 0
READ1	CAL	READCD		/ READ A CARD
/
WAITCD	LAC	(ILINE+2
	DAC	UNPCK+1         / POINTERS FOR 'UNPACK'
	LAC	(IMAGE
	DAC	UNPCK+2
	JMS	WTFOR		/ WAIT FOR CARD TO BE READ
	EVCD
	LAC	ILINE
	AND	(7
	SAD	(2		/ CHECK FOR IOPS ASCII DATA MODE
	SKP
	JMP	LOADED		/ GO TO OUTPUT SECTION WHEN NOT ASCII
	LAC	ILINE+2
	SAD	BLK		/ CHECK FOR 'BLK' CARD
	SKP
	JMP	UNPCK		/ UNPACK LINE WHEN NOT 'BLK' CARD
	LAC	ILINE+3
	SAD	BLK+1		/ MUST CHECK BOTH WORDS
	SKP
	JMP	UNPCK
	IDX	PAGPNT		/ WE HAVE A 'BLK' CARD.  INDEX TO
	LAW	-30		/ NEXT PAGE
	DAC	COUNT
	LAW	-1		/ BECAUSE OF THE POSSIBILITY OF
	TAD*	PAGPNT		/ SPECIFYING DATA PAST THE LOGICAL
	DAC*	(X14		/ END OF A MEMORY PAGE, IT IS
CLM2	DZM*	X14		/ PRUDENT TO CLEAR THE FIRST 24
	ISZ	COUNT		/ LOCATIONS OF THE NEW PAGE
	JMP	CLM2
	JMP	READ1		/ READ NEXT DATA CARD
/
	.EJECT
UNPCK	JMS*	UNPACK
	0; 0
	SMA
	JMP	UNPCK
	CAL	READCD		/ READ NEXT CARD AS SOON AS BUFFER FREE
	LAC	(IMAGE
	DAC*	(X14		/ IGNORE FIRST CHARACTER IN LINE
	JMS	UNHEX		/ CONVERT 3 CHARS FROM HEX TO BINARY
	JMP	ERR		/ WE DO NOT EXPECT A SPACE IN ADDRESS
	TAD*	PAGPNT		/ ADD DISPLACEMENT TO BASE ADDRESS
	DAC	ADDR
	LAW	-30		/ 24 DECIMAL
	DAC	COUNT
LOAD	JMS	UNHEX		/ DECODE THE DATA WORDS
	JMP	WAITCD		/ TERMINATE CARD WHEN SPACE ENCOUNTERED
	DAC*	ADDR		/ STORE DATA IN PSEUDO-MEMORY
	IDX	ADDR		/ POINT TO NEXT LOCATION
	ISZ	COUNT
	JMP	LOAD
	JMP	WAITCD		/ PROCESS NEXT CARD AT END OF DATA
/
	.EJECT
/  WE HAVE LOADED THE PSEUDO-MEMORY, AND MUST NOW PUNCH IT OUT IN THE
/ DESIRED FORMAT.  CHECK EACH OF THE POSSIBLE CASES:
/
/	 1 - FORMAT #1 ONLY
/	 2 - FORMAT #2 ONLY
/	 3 - BOTH FORMAT #1 AND FORMAT #2
/	 4 - FORMAT #3 ONLY
/	10 - SINGLE TAPE FOR 10K ROM (ADDRESSES X'0000' TO X'27FF')
/	20 - SECOND HALF OF  20K ROM (ADDRESSES X'2800' TO X'4FFF')
/	30 - CASE 10 FOLLOWED BY CASE 20
/
LOADED	LAC	LSTSW		/ DO WE WANT A LISTING?
	SNA
	JMP	CK4PCH		/ NO.				/(015)
	CAL	ATTLP		/ YES.  ATTACH LINE PRINTER
	JMS	WTFOR
	EVLP
	CAL	WRLPFF		/ ISSUE FORM FEED
/
CK4PCH	LAC	PCHSW		/ DO WE WANT PAPER TAPE?	/(015)
	SNA			/ 'PCHSW'=0 IF NO PAPER TAPE	/(015)
	JMP	CASE1		/ NO.				/(015)
	CAL	ATTPP		/ YES.  ATTACH PUNCH		/(015)
	JMS	WTFOR						/(015)
	EVPP							/(015)
/
CASE1	LAC	CASES
	RAR
	SNL			/ CASE 1?
	JMP	CASE2
	CAL	WRC1		/ 'CASE 1: FORMAT #1'
	LAC	PCHSW
	SZA			/ SKIP IF NO PUNCHED TAPE
	JMS	OPENPP		/ OPEN OUTPUT FILE ON PUNCH	/(015)
	LAW	-5
	DAC	SPCNT		/ 5 GROUPS OF ADDRESS SPACES (SEE SPEC)
	DZM	ADDR		/ BEGINNING AT LOCATION X'0'
	JMS	PUNCH
	JMS	WINDUP
/
	.EJECT
CASE2	LAC	CASES
	RTR
	SNL			/ CASE 2?
	JMP	CASE4
	CAL	WRC2		/ 'CASE 2: FORMAT #2'
	LAC	PCHSW
	SZA			/ SKIP IF NO PUNCHED TAPE REQUIRED
	JMS	OPENPP		/ OPEN OUTPUT FILE ON PUNCH	/(015)
	LAW	-5
	DAC	SPCNT		/ AGAIN 5 ADDRESS SPACES, BUT
	LAC	(2000		/ THIS TIME BEGINNING AT X'400'
	DAC	ADDR
	JMS	PUNCH
	JMS	WINDUP
/
	.EJECT
CASE4	LAC	CASES
	RAR; RTR
	SNL			/ CASE 4?
	JMP	CASE10
/
	CAL	WRC4		/ 'CASE 4: FORMAT #3'
	LAC	PCHSW
	SZA			/ SKIP IF NO PUNCHED TAPE REQUIRED
	JMS	OPENPP		/ OPEN OUTPUT FILE ON PUNCH	/(015)
	LAW	-3
	DAC	SPCNT		/ FIRST, 3 ADDRESS SPACES,
	DZM	ADDR		/ BEGINNING AT X'0'
	JMS	PUNCH
	LAW	-2
	DAC	SPCNT		/ THEN 2 MORE ADDRESS SPACES,
	LAC	(2000		/ BEGINNING AT X'400'
	DAC	ADDR
	JMS	PUNCH
	JMS	WINDUP
/
	.EJECT
CASE10	LAC	CASES
	AND	(10
	SNA
	JMP	CASE20		/ NOT CASE 10.  CHECK CASE 20.	/(016)
/
	CAL	WRC10		/ 'CASE 10: 10K IN SINGLE TAPE'
	LAC	PCHSW
	SZA			/ SKIP IF NO PUNCHED TAPE REQUIRED
	JMS	OPENPP						/(015)
	CLA			/ BEGINNING AT X'0000',
	JMS	PC10		/ PUNCH A SINGLE ADDRESS SPACE
	LAC	(2000		/ SUBSEQUENT ADDRESSES BEGIN AT X'0400'
	JMS	PC10
	LAC	(4000		/ X'0800'
	JMS	PC10
	LAC	(6000		/ X'0C00'
	JMS	PC10
	LAC	(10000		/ X'1000'
	JMS	PC10
	LAC	(12000		/ X'1400'
	JMS	PC10
	LAC	(14000		/ X'1800'
	JMS	PC10
	LAC	(16000		/ X'1C00'
	JMS	PC10
	LAC	(20000		/ X'2000'
	JMS	PC10
	LAC	(22000		/ X'2400'
	JMS	PC10
	JMS	WINDUP
	JMP	CASE20		/ CHECK NEXT CASE.		/(016)
/
/  SUBROUTINE TO OUTPUT A SINGLE ADDRESS SPACE, BEGINNING AT THE
/  ADDRESS CONTAINED IN THE AC AT ENTRY.
/
PC10	XX
	DAC	ADDR		/ INITIALIZE STARTING ADDRESS
	LAW	-1
	DAC	SPCNT		/ ONLY 1 ADDRESS SPACE
	JMS	PUNCH
	JMP*	PC10
/
	.EJECT
CASE20	LAC	CASES						/(016)
	AND	(20						/(016)
	SNA							/(016)
	JMP	CASE40		/ NOT CASE 20.  CHECK NEXT CASE	/(016)
/
	CAL	WRC20		/ 'CASE 20: 2ND 10K IN SINGLE TAPE' /(016)
	LAC	PCHSW						/(016)
	SZA							/(016)
	JMS	OPENPP		/ ONLY IF PUNCHED TAPE REQUIRED	/(016)
	LAC	(24000		/ FROM X'2800', OUTPUT		/(016)
	JMS	PC10		/ OUTPUT SINGLE ADDRESS SPACES	/(016)
	LAC	(26000		/ X'2C00'			/(016)
	JMS	PC10						/(016)
	LAC	(30000		/ X'3000'			/(016)
	JMS	PC10						/(016)
	LAC	(32000		/ X'3400'			/(016)
	JMS	PC10						/(016)
	LAC	(34000		/ X'3800'			/(016)
	JMS	PC10						/(016)
	LAC	(36000		/ X'3C00'			/(016)
	JMS	PC10						/(016)
	LAC	(40000		/ X'4000'			/(016)
	JMS	PC10						/(016)
	LAC	(42000		/ X'4400'			/(016)
	JMS	PC10						/(016)
	LAC	(44000		/ X'4800'			/(016)
	JMS	PC10						/(016)
	LAC	(46000		/ X'4C00'			/(016)
	JMS	PC10						/(016)
	JMS	WINDUP						/(016)
/
CASE40	JMP	ROMSIM		/ IN CASE ANOTHER CASE NEEDED	/(016)
/
	.EJECT
/  ENTER HERE WHEN WE ENCOUNTER AN INVALID CHARACTER IN INPUT DATA
/
ERR	CAL	WRILLC		/ 'ILLEGAL CHARACTER'
	CAL	WRBAD		/ OUTPUT PART OF OFFENDING LINE
	JMS	WTFOR
	EVTTO
	CAL	(10		/ ABORT WHEN ERROR DETECTED!!
/
/  SUBROUTINE TO PERFORM THE WINDUP FROM PUNCHING A SERIES OF
/  CASES ON THE PAPER PUNCH.
/
WINDUP	XX
	LAC	PCHSW
	SNA
	JMP*	WINDUP		/ NO WINDING REQUIRED IF NO TAPE
	JMS	WTFOR		/ WAIT FOR PUNCH TO STOP
	EVPP
	CAL	WRATSN		/ '@'
	CAL	CLOSPP		/ CLOSE PUNCH TO GENERATE BLANK TRAILER
	JMS	WTFOR
	EVPP
	JMP*	WINDUP
/
/  SUBROUTINE TO OPEN OUTPUT FILE NAME ON 'PP', IN CASE OUTPUT	/(015)
/  IS FILE-ORIENTED, THEN PUNCH SPECIAL NCR 'START' CODE.	/(015)
/
OPENPP	XX							/(015)
	IDX	PPNAME+1	/ MUST HAVE NEW NAME EACH TIME	/(015)
	CAL	ENTRPP		/ OPEN FILE			/(015)
	JMS	WTFOR		/ CHECK FOR I/O ERRORS		/(015)
	EVPP							/(015)
	CAL	WRARO		/ PUNCH OUT 'START' CODE	/(015)
	JMP*	OPENPP						/(015)
/
/  SUBROUTINE TO WAIT FOR SPECIFIED EVENT VARIABLE
/
WTFOR	XX
	LAC*	WTFOR		/ GET EVENT VARIABLE ADDRESS
	IDX	WTFOR
	DAC	WAITFR+1	/ PUT IN 'WAITFOR' CPB
	CAL	WAITFR
	LAC*	WAITFR+1	/ GET EVENT VARIABLE
	SMA
	JMP*	WTFOR		/ EV OK.  RETURN TO CALLING POINT
	SAD	(-6
	JMP*	WTFOR		/ IGNORE UNIMPLEMENTED FUNCTION
	JMS*	.IOERR		/ ANNOUNCE TERMINAL ERROR IF NOT OK
/
	.EJECT
/  SUBROUTINE TO CONVERT THE NEXT 3 CHARACTERS IN THE IMAGE BUFFER
/  TO BINARY.  'X14' POINTS TO THE FIRST CHARACTER.  IF A SPACE
/  IS ENCOUNTERED (1 OF THE 3 CHARS), THE 'RETURN ON SPACE' EXIT IS
/  TAKEN.  OTHERWISE, THE CHARACTERS ARE INTERPRETED AS HEXADECIMAL
/  DIGITS AND THE SUBROUTINE RETURNS WITH THE BINARY VALUE IN THE AC.
/
/  CALLING SEQUENCE:
/
/	JMS	UNHEX
/	(RETURN IF SPACE FOUND)
/	(NORMAL RETURN)	      / AC CONTAINS BINARY VALUE
/
UNHEX	XX
	LAW	-3		/ 3 HEX DIGITS PER WORD
	DAC	HCNT
	DZM	VALUE		/ INITIALIZE SOFTWARE ACCUMULATOR
UHLOOP	LAC*	X14		/ GET NEXT CHARACTER
	SAD	(40		/ CHECK FOR SPACE
	JMP*	UNHEX		/ TAKE 'SPACE' EXIT
	AAC	-60
	SPA
	JMP	ERR		/ CHAR < 60 (<'0')
	AAC	60-72
	SMA!SZA
	JMP	ALPHAS		/ CHAR IS LETTER (>'9' ANYWAY)
	AAC	72		/ RESTORE TO CORRECT ASCII
	AND	(17		/ KEEP ONLY NUMERIC PART OF DIGIT
	JMP	UNHEX1
/
ALPHAS	AAC	72-101
	SPA
	JMP	ERR		/ CHAR < 101 (<'A')
	AAC	101-106
	SMA!SZA
	JMP	ERR		/ CHAR > 106 (>'F')
	AAC	17		/ CHAR IS LEGAL LETTER.  CONVERT TO
UNHEX1	XOR	VALUE		/ APPROPRIATE VALUE AND
	ISZ	HCNT		/ ACCUMULATE THE DIGIT VALUE
	JMP	UNHEX2		/ HAVE NOT YET PROCESSED 3 CHARS
	IDX	UNHEX		/ INDEX TO NORMAL RETURN POINT
	JMP*	UNHEX
/
UNHEX2	ALSS	4
	DAC	VALUE		/ SAVE UPDATED VALUE FOR NEXT CHAR
	JMP	UHLOOP
/
	.EJECT
/  SUBROUTINE TO OUTPUT SPECIFIED GROUP OF ADDRESS SPACES.  ON ENTRY,
/  'ADDR' CONTAINS THE ABSOLUTE ADDRESS OF THE SPECIFIED ROM, AND
/  'SPCNT' CONTAINS THE 2'S COMPLEMENT OF THE NUMBER OF ADDRESS
/  SPACES TO OUTPUT.  AT THE END OF AN ADDRESS SPACE, X'400' IS ADDED
/  TO THE ADDRESS ('ADDR') TO SKIP PAST THE CURRENTLY UNWANTED
/  ADDRESS SPACE IN THE PARTICULAR CASE.
/
PUNCH	XX
PCH1	LAW	-2
	DAC	GPPG		/ 2 GROUPS PER PAGE
PCH2	LAW	-40
	DAC	LPG		/ 32 LINES PER GROUP
PCH3	LAW	-20
	DAC	WPL		/ 16 WORDS PER LINE
	LAC	ADDR		/ GET DESIRED ADDRESS IN ROM
	LMQ
	TAD	PAGE0		/ ADD ACTUAL CORE STARTING LOCATION TO
	DAC	RELADR		/ GENERATE RELOCATED ADDRESS OF DATA
	ECLA!LLSS 6		/ SHIFT PAGE DIGIT TO AC 14-17
	XOR	(60		/ IT WILL BE '0', '1', OR '2'
	DAC	IMAGE		/ PUT PAGE DIGIT IN COLUMN 1
	LAC	(IMAGE
	DAC*	(X14		/ INITIALIZE POINTER FOR THIS LINE
	LAC	ADDR
	JMS	HEX		/ PUT ROM ADDRESS IN IMAGE BUFFER
	LAW	54
	DAC	IMAGE+4         / ',' IN COLUMN 5
PCH4	LAC*	RELADR
	IDX	RELADR		/ POINT TO NEXT WORD
	JMS	HEX		/ PUT DATA WORD IN IMAGE BUFFER
	ISZ	WPL		/ END OF LINE YET?
	JMP	PCH4
	LAW	130
	DAC*	X14		/ PUT 'X' AT END OF LINE
	LAW	15
	DAC*	X14		/ FINISH WITH CARRIAGE RETURN
	LAC	ADDR
	TAD	(20		/ STEP PAST ADDRESSES OUTPUT THIS LINE
	DAC	ADDR
	LAC	(IMAGE
	DAC	PCK+1
	LAC	(OLINE+2        / ADDRESSES FOR PACK
	DAC	PCK+2
	JMS	WTFOR		/ WAIT FOR PREVIOUS LINE PRINTER OUTPUT
	EVLP
	JMS	WTFOR		/ WAIT FOR PREVIOUS PUNCHING
	EVPP
/
	.EJECT
PCK	JMS*	PACK
	0; 0
	SMA
	JMP	PCK
	LAC	PCHSW
	SZA			/ SKIP IF NO PUNCHED TAPE REQUIRED
	CAL	WROLINE
	LAC	LSTSW
	SZA			/ SKIP IF NO LISTING REQUIRED
	CAL	WRLIST
	ISZ	LPG		/ END OF GROUP OF 32 LINES?
	JMP	PCH3
	LAC	PCHSW
	SZA
	CAL	WRXTRA		/ OUTPUT EXTRA DUMMY LINE AFTER GROUP
	LAC	LSTSW
	SZA
	CAL	WRLPFF		/ FORM FEED ON LISTING AFTER GROUP
	ISZ	GPPG		/ END OF CURRENT ADDRESS SPACE
	JMP	PCH2
	LAC	ADDR
	TAD	(2000		/ ADD X'400' AT END OF CURRENT ADDRESSE
	DAC	ADDR
	ISZ	SPCNT		/ END OF REQUESTED ADDRESS SPACES?
	JMP	PCH1
	JMP*	PUNCH
/
/  SUBROUTINE TO CONVERT A WORD TO ITS HEXADECIMAL REPRESENTATION.  ONLY
/  THE LEAST SIGNIFICANT 3 DIGITS ARE OUTPUT.  AT ENTRY, THE WORD TO BE
/  CONVERTED IS IN THE AC, AND 'X14' POINTS TO THE IMAGE ASCII LINE
/  BUFFER WHERE THE GENERATED ASCII IS TO BE STORED.
/
HEX	XX
	LMQ
	LAW	-3		/ 3 HEX CHARACTERS/WORD
	DAC	HCNT
	LLSS	6		/ SHIFT OUT UNUSED BITS
/
HLOOP	ECLA!LLSS 4		/ SHIFT IN NEXT HEX DIGIT
	TAD	(LAC TABLE
	DAC	.+1
	XX			/ PICK UP CORRECT CHARACTER FROM TABLE
	DAC*	X14		/ STORE IN IMAGE BUFFER
	ISZ	HCNT
	JMP	HLOOP
	LAW	40		/ EACH WORD FOLLOWED BY A SPACE
	DAC*	X14
	JMP*	HEX
/
	.EJECT
/  MESSAGES, LINE BUFFERS, WORKING STORAGE
/
HELLO	HO-.*400+2; 0
	.ASCII	'ROMSIM V1A.  COMMAND  >'<175> ;HO=.
INVALC	IC-.*400+2; 0
	.ASCII	'INVALID COMMAND'<15> ;IC=.
C1	C01-.*400+2; 0
	.ASCII	'CASE 1: FORMAT #1'<15> ;C01=.
C2	C02-.*400+2; 0
	.ASCII	'CASE 2: FORMAT #2'<15> ;C02=.
C4	C04-.*400+2; 0
	.ASCII	'CASE 4: FORMAT #3'<15> ;C04=.
C10	C010-.*400+2; 0; .ASCII 'CASE 10: 10K ON SINGLE TAPE'<15> ;C010=.
C20	C020-.*400+2; 0						/(016)
	.ASCII	'CASE 20: 2ND 10K ON SINGLE TAPE'<15> ;C020=.	/(016)
ILLCHR	IL-.*400+2; 0
	.ASCII	'ILLEGAL INPUT CHARACTER'<15> ;IL=.
FF	2002; 0; .ASCII <14><15>
BLINE	2002; 0; .ASCII ' '<15>
EXTRA	XT-.*400+2; 0
	.ASCII	'.'<15> ;XT=.
ATSIGN	AS-.*400+2; 0
	.ASCII	'@'<15> ;AS=.
/
	.EJECT
ARROW	2002; 0; .ASCII <2><15>	/ <2> IS NCR 'START' CODE	/(015)
ILINE	.BLOCK	100
	44003			/ HEADER WORD FOR ILLEGAL CHARACTER
IMAGE	.BLOCK	200
OLINE	22002;	.BLOCK	77
/
BLK	.ASCII	'!BLK '
/
	.EJECT
/  TABLE FOR HEX TO ASCII CONVERSION
/
TABLE	60	/ '0'
	61	/ '1'
	62	/ '2'
	63	/ '3'
	64	/ '4'
	65	/ '5'
	66	/ '6'
	67	/ '7'
	70	/ '8'
	71	/ '9'
	101	/ 'A'
	102	/ 'B'
	103	/ 'C'
	104	/ 'D'
	105	/ 'E'
	106	/ 'F'
/
COUNT;HCNT;VALUE;CASES;LSTSW;NEWSW;PCHSW
PAGPNT	0
	.DEC
COMSIZ=MEMSIZ+50						/(016)
PAGE0	.CBD	PSMEM,COMSIZ	/ SIZE REQUIRED IS 20K (20480)	/(016)
PAGE1	.CBDR	4096		/ FOR PROGRAM TAPE +
PAGE2	.CBDR	8192		/ AT LEAST 24 IN CASE OF OVERFLOW
PAGE3	.CBDR	12288						/(016)
PAGE4	.CBDR	16384						/(016)
PAGE5	.CBDR	20480		/ DUMMY POINTER FOR LAST 'BLK' CARD /(016)
	.OCT
ADDR;RELADR
SPCNT;GPPG;LPG;WPL
/
	.EJECT
/  CAL PARAMETER BLOCKS FOR I/O
/
EVTTI;EVTTO;EVCD;EVPP 1;EVLP 1		/ EVENT VARIABLES
WAITFR	20;	EVPP
WRHELO	2700;	EVTTO;	TTO; 2; HELLO
READCM	2600;	EVTTI;	TTI; 2; ILINE; 64
WRINVC	2700;	EVTTO;	TTO; 2; INVALC
ATTCD	2400;	EVCD;	CD					/(016)
READCD	2600;	EVCD;	CD;  2; ILINE; 64
WRC1	2700;	0;	TTO; 2; C1
WRC2	2700;	0;	TTO; 2; C2
WRC4	2700;	0;	TTO; 2; C4
WRC10	2700;	0;	TTO; 2; C10
WRC20	2700;	0;	TTO; 2; C20
ATTPP	2400;	EVPP;	PP					/(015)
ENTRPP	3300;	EVPP;	PP;PPNAME .SIXBT 'NCRTP0SRC'		/(015)
WRARO	2700;	EVPP;	PP;  2; ARROW	/ CHANGE TO MODE 2	/(015)
WRATSN	2700;	0;	PP;  2; ATSIGN
CLOSPP	3400;	EVPP;	PP
ATTLP	2400;	EVLP;	LP
WRILLC	2700;	0;	TTO; 2; ILLCHR
WRBL	2700;	0;	TTO; 2; BLINE
WRBAD	2700;	EVTTO;	TTO; 3; IMAGE-1
WROLINE	2700;	EVPP;	PP;  2; OLINE
WRLIST	2700;	EVLP;	LP;  2; OLINE
WRLPFF	2700;	EVLP;	LP;  2; FF
WRXTRA	2700;	0;	PP;  2; EXTRA
	.END	ROMSIM
