        .TITLE  BOSS-15 SOURCE FILE    PREPROCESSOR (B.PRE)                     
/
/COPYRIGHT (C) 1975
/DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.
	.EJECT
/
/EDIT #20	1-20-72
/	021	SK	9-JAN-74	RK FTSTAT FIX
/	022	MJH	20-AUG-75	DISCLAIMER
/
/
/
/
/
/
/
	.EJECT
/B.PRE IS A RELOCATABLE PROGRAM.  IT'S PRIMARY FUNCTION                         
/IS TO PRE-PROCESS MACRO AND F4 SOURCE FILES FOR                                
/BOSS-15.  BUT IT CAN BE USED GENERALLY FOR ANY .ASCII                          
/FILE.  B.PRE IS CALLED BY BOSS-15 ANYTIME A $FOR OR $ASM                       
/CONTROL CARD APPEARS; IT WILL THEN DO THE FOLLOWING;                           
/       A.  IF NO DATA CARDS (I.E. CARDS WITHOUT A $-SIGN                       
/           IN COL.1) FOLLOW THE CONTROL CARD THAT CAUSED                       
/           B.PRE TO BE CALLED, EXIT WITHOUT HAVING DONE                        
/           ANYTHING                                                            
/       B.  IF DATA CARDS FOLLOW THE CONTROL CARD THAT CAUSED                   
                                                                                
/           B.PRE TO BE CALLED, ASSUME THOSE DATA CARDS ARE                     
/           SOURCE CARDS, READ EACH DATA CARD AND PREPARE                       
/           A .ASCII FILE WITH THEIR IMAGES.  THE FILE NAME                     
/           WILL BE READ FROM .DAT -2.                                          
/
/NOTE THAT B.PRE REQUIRES ONE LINE OF INPUT DATA ON .DAT -2,                    
/REGARDLESS OF WHETHER A. OR B. IS TRUE.  B.PRE ASSUMES THAT                    
/THE CORRECT UIC IS LOGGED IN AT THE TIME B.PRE IS CALLED.                      
/ALGORITHMS FOR B.PRE HAVE BEEN SELECTED WITH SPEED OF EXECUTION                
/AS THE PRIMARY CONSIDERATION.                                                  
/
SHAL=660000
IDX=ISZ
        .EJECT                                                                  
BEGIN=.
	.INIT -14,0,BEGIN
	.INIT -15,0,BEGIN
	.READ	-2,2,CDBUFF,48	/READ FILE NAME
	LAW	-6		/CLEAR OUT DEB'S
	DAC	TEMP
	LAC	(ENTER
	DAC	LENTER
LOOP.1	DZM*	LENTER
	IDX	LENTER
	ISZ	TEMP
	JMP	LOOP.1
	DZM	FLAG
	LAC	(ENTER
	DAC	LENTER
WAITM2  .WAIT   -2              /GET FILE NAME AND STORE                        
	LAC	(CDBUFF		/IT IN .ENTER BUFFER
	JMS	GT.FST
	SAD	CR
	JMP	RDSECN
        AND     (77                                                             
        JMS     RSHFT6                                                          
        RAR                                                                     
        DAC*    LENTER                                                          
	JMS	GT.CHR		/SECOND CHARACTER
	SAD	CR
	JMP	EXT.3
	SAD	BLANK
	JMP	EXT.1
        AND     (77                                                             
        JMS     LSHFT6                                                          
        XOR*    LENTER                                                          
        DAC*    LENTER                                                          
        JMS     GT.CHR          /THIRD CHARACTER                                
	SAD	CR
	JMP	EXT.3
	SAD	BLANK
	JMP	EXT.1
        AND     (77                                                             
        XOR*    LENTER                                                          
        DAC*    LENTER                                                          
        ISZ     LENTER                                                          
        JMS     GT.CHR          /FOURTH CHARACTER                               
	SAD	CR
	JMP	EXT.2
	SAD	BLANK
	JMP	EXT
        AND     (77                                                             
        JMS     RSHFT6                                                          
        RAR                                                                     
        DAC*    LENTER                                                          
        JMS     GT.CHR          /FIFTH CHARACTER                                
	SAD	CR
	JMP	EXT.2
	SAD	BLANK
	JMP	EXT
        AND     (77                                                             
        JMS     LSHFT6                                                          
	XOR*	LENTER
        DAC*    LENTER                                                          
	JMS	GT.CHR		/SIXTH CHARACTER
	SAD	CR
	JMP	EXT.2
	SAD	BLANK
	JMP	EXT
	AND	(77
        XOR*    LENTER                                                          
        DAC*    LENTER                                                          
EXT=.
	JMS	GT.CHR		/SKIP OVER BLANKS
	SAD	BLANK
	JMP	EXT
        ISZ     LENTER                                                          
        AND     (77                                                             
        SAD     (15                                                             
        JMP     NOEXT                                                           
        JMS     RSHFT6                                                          
        RAR                                                                     
        DAC*    LENTER                                                          
        JMS     GT.CHR          /SECOND CHARACTER                               
        AND     (77                                                             
        JMS     LSHFT6                                                          
        XOR*    LENTER                                                          
        DAC*    LENTER                                                          
	JMS	GT.CHR		/THIRD CHARACTER
	AND	(77
        XOR*    LENTER                                                          
        DAC*    LENTER                                                          
	JMP	RDSECN
EXT.3=.
	ISZ	LENTER
EXT.2=.
	ISZ	LENTER
NOEXT=.
        LAC     SRC             /NO EXTENSION TYPED IN, USE                     
        DAC*    LENTER          /'SRC' AS DEFAULT.                              
RDSECN  LAC     ENTERP                                                          
        SZA                                                                     
        JMP     CDREAD                                                          
	.READ	-2,2,CDBUFF,48
        LAC     (ENTERP                                                         
        DAC     LENTER                                                          
        JMP     WAITM2                                                          
EXT.1	ISZ	LENTER
	JMP	EXT
ERROR	.WRITE	6,2,ERRMSG,36
	.WAIT	6
	.EXIT
ERRMSG	007002
	0
	.ASCII	'NON-DISK I/O DEVICE'<15>
ERROR2	.WRITE	6,2,MSG1,36
	.WAIT	6
	.EXIT
MSG1	007002
	0
	.ASCII 'DIFFERENT DEVICES ASSIGNED TO .DAT-14&-15'<15>
ERROR3	.WRITE	6,2,MSG2,36
	.WAIT 6
	.EXIT
MSG2	007002
	0
	.ASCII 'DIFFERENT UIC ASSIGNED TO .DAT-14&-15'<15>
CDREAD=.
	.FSTAT	-14,ENTER
	LAC	.-1
	AND	(700000
	SAD	(100000		/IS IT DECTAPE?
	JMP	ERROR		/YES, PRINT ERROR MESSAGE
	DAC	DEV		/SAVE DEVICE TYPE
	.FSTAT	-15,ENTER
	LAC	.-1
	AND	(700000
	SAD	(100000		/IS IT DECTAPE?
	JMP	ERROR		/YES, PRINT ERROR MESSAGE
	SAD	DEV		/IS .DAT -15 THE SAME
	SKP			/AS .DAT -14?
	JMP	ERROR2		/NO-PRINT MESSAGE
	LAC*	(125		/YES-.SCOM+25
	AND	(77777
	TAD	(-15		/GET ADDRESS OF .DAT -15
	DAC	DEV		/SAVE IT
	LAC*	DEV		/UIC ASSIGNED TO .DAT -15
	DAC	UIC
	ISZ	DEV		/.DAT-14
	LAC*	DEV		/UIC ASSOCIATED WITH .DAT-14
	SAD	UIC		/IS UIC OF .DAT -15 + -14 THE SAME?
	SKP			/YES,CONTINUE
	JMP	ERROR3		/NO, PRINT MESSAGE
	.READ	5,2,CDBUFF,48
        .WAIT   5                                                               
        LAC     CDBUFF          /IS IT END-OF-FILE?                             
        AND     (17                                                             
        SAD     (5                                                              
        JMP     EOF             /YES.                                           
	SAD	(6
	JMP	EOF
	LAC	(CDBUFF		/EDIT CARDS?
	JMS	GT.FST
	SAD	(55
	JMP	LNEDIT		/YES, EDIT.
OPENF	.FSTAT	-14,TMPFIL	/DOES USER HAVE A FILE WITH SAME NAME AS
	SNA			/B.PRE'S TEMP FILE? YES, SKIP.
	JMP	OPEN.1		/NO, GO OPEN TEMP FILE.
	LAC	TMPFIL+1	/CHANGE B.PRE'S TEMP FILE NAME,AND
	IAC			/TRY AGAIN.
	DAC	TMPFIL+1
	JMP	OPENF
OPEN.1	.ENTER	-14,TMPFIL	/OPEN TEMPORARY FILE FOR OUTPUT.
        ISZ     FLAG            /SET FLAG                                       
CDWRIT=.                                                                        
       .READ   5,2,CPBUFF,48   /FILL-UP FIRST BUFFER                            
	.WRITE	-14,2,CDBUFF,48	/WRITE CARD
	.WAIT	-14
       .WAIT   5                                                                
       LAC     CPBUFF          /E.O.F.?                                         
       AND     (17                                                              
       SAD     (5                                                               
       JMP     EOF             /YES                                             
       SAD     (6                                                               
       JMP     EOF             /YES                                             
       .READ   5,2,CDBUFF,48   /FILL UP SECOND BUFFER                           
       .WRITE  -14,2,CPBUFF,48 /OUTPUT FIRST BUFFER                             
       .WAIT   -14                                                              
       .WAIT   5                                                                
       LAC     CDBUFF          /E.O.F.?                                         
       AND     (17                                                              
       SAD     (5                                                               
       JMP     EOF             /YES                                             
       SAD     (6                                                               
       JMP     EOF             /YES                                             
       JMP     CDWRIT          /NO,LOOP                                         
        .EJECT                                                                  
EOF=.
	LAC	FLAG		/FLAG=0?
        SNA                                                                     
        JMP     EXIT            /YES                                            
	.CLOSE	-14		/NO, CLOSE FILE
	.DLETE	-14,ENTERP	/DELETE NEW FILE IN CASE THERE WAS ONE ALREADY.
	JMS	MOVEP		/MOVE FILE NAME IN 'ENTER' BUFFER FOR RENAME
	.RENAM	-14,TMPFIL	/RENAME TEMP FILE TO NEW FILE NAME.
EXIT=.                                                                          
        .EXIT                                                                   
        .EJECT                                                                  
LNEDIT	.SEEK	-14,ENTERP	/START UP FILES
LNED.1	.FSTAT	-15,TMPFIL	/DOES USER HAVE FILE WITH SAME NAME AS
	SNA			/B.PRE'S TEMP FILE? YES, SKIP.
	JMP	LNED.2		/NO, GO OPEN TEMP FILE.
	LAC	TMPFIL+1	/CHANGE B.PRE'S TEMP FILE NAME,AND
	IAC			/TRY AGAIN.
	DAC	TMPFIL+1
	JMP	LNED.1
LNED.2	.ENTER	-15,TMPFIL	/OPEN TEMPORARY FILE FOR OUTPUT.
	DZM	LINCNT		/INITIALIZE POINTERS
EDIT	DZM	L1
        DZM     L2                                                              
        JMS     SCAN            /SCAN EDIT STATEMENT                            
        LAC     L2              /WHAT KIND OF OPERATION?                        
	SNA
	JMP	INSERT		/INSERT
	JMP	DELETE		/DELETE
/
MOREDT=.
	.READ	5,2,CDBUFF,48
	.WAIT	5
        LAC     CDBUFF                                                          
	AND	(17
	SAD	(6
	JMP	CLOSES
	SAD	(5
	JMP	CLOSES
	LAC	(CDBUFF
	JMS	GT.FST
	SAD	(55
	JMP	EDIT
	.WRITE	-15,2,CDBUFF,48
	.WAIT	-15
                                                                                
        JMP     MOREDT                                                          
/
INSERT	LAC	L1
	TCA
	TAD	LINCNT
	SNA
	JMP	MOREDT
	SMA
	JMP	OTSEQ
        ISZ     LINCNT                                                          
	.READ	-14,2,CDBUFF,48
	.WAIT	-14
	.WRITE	-15,2,CDBUFF,48
	.WAIT	-15
        JMP     INSERT                                                          
/
DELETE	LAC	L1
	TCA
	TAD	L2
	SPA
	JMP	OTSEQ
	LAW	-1
        TAD     L1                                                              
        DAC     L1                                                              
DEL.1	LAC	L1
	TCA
	TAD	LINCNT
	SNA
	JMP	DEL.2
	SMA
	JMP	OTSEQ
	ISZ	LINCNT
	.READ	-14,2,CDBUFF,48
	.WAIT	-14
	.WRITE	-15,2,CDBUFF,48
	.WAIT	-15
	JMP	DEL.1
DEL.2=.
	.READ	-14,2,CDBUFF,48
        ISZ     LINCNT                                                          
	LAC	LINCNT
	SAD	L2
        JMP     MOREDT                                                          
        JMP     DEL.2                                                           
SCAN	0
SCAN.1	JMS	GT.CHR		/GET NEXT CHARACTER
	JMS	CHECK		/WHAT IS IT?
	JMP	SCAN.2		/COMMA, START L2
        TAD     (-60            /NUMERIC                                        
        DAC     TEMP                                                            
        LAC     L1              /COMPUTE : L1=L1*10+TEMP                        
	MUL!SHAL
	12
	LACQ
	TAD	TEMP
        DAC     L1                                                              
	JMP	SCAN.1		/REPEAT
SCAN.2  JMS     GT.CHR                                                          
        JMS     CHECK                                                           
        JMP*    SCAN                                                            
	TAD	(-60
	DAC	TEMP
	LAC	L2
	MUL!SHAL
	12
	LACQ
	TAD	TEMP
        DAC     L2                                                              
        JMP     SCAN.2                                                          
CHECK	0
        DAC     TEMP                                                            
	SAD	(54
        JMP     CHK.R                                                           
        TAD     (-72                                                            
        SMA                                                                     
	JMP*	SCAN
	TAD	(12
        SPA                                                                     
	JMP*	SCAN
        ISZ     CHECK                                                           
CHK.R	LAC	TEMP
	JMP*	CHECK
TEMP	0
OTSEQ	.WRITE	6,2,SEQERR,60
	.WRITE	6,2,CDBUFF,80
	.WAIT	6
CLOSES=.
	.READ	-14,2,CDBUFF,48
	.WAIT	-14
	LAC	CDBUFF
	AND	(17
	SAD	(5
	JMP	CLOS.1
	.WRITE	-15,2,CDBUFF,48
	.WAIT	-15
	JMP	CLOSES
CLOS.1=.
	LAC	ENTER		/IS NEW OUTPUT FILE NAME SAME AS INPUT
	SNA			/FILE NAME? NO, SKIP
	JMS	MOVEP		/YES, MOVE INPUT FILE NAME IN 'ENTER' BUFFER.
	.CLOSE	-14
	.CLOSE	-15
	.DLETE	-14,ENTER	/DELETE NEW FILE IN CASE THERE WAS ONE ALREADY.
	.RENAM	-15,TMPFIL	/RENAME TEMP FILE TO NEW FILE NAME.
	.WAIT	-15
	JMP	EXIT
/
MOVEP	0
	LAC	ENTERP
	DAC	ENTER
	LAC	ENTERP+1
	DAC	ENTER+1
	LAC	ENTERP+2
	DAC	ENTER+2
	JMP*	MOVEP
/
/GDNERAL PURPOSE ROUTINES
/
/
/SUBROUTINE LSHFT6                                                              
/
/SHIFT AC LEFT SIX BITS
/CALLING SEQUENCE:
/       JMS     LSHFT6                                                          
/	(RETURN)
/LINK IS CLEARED                                                                
/
LSHFT6	0
        CLL!RTL                                                                 
        RTL                                                                     
	RTL
	JMP*	LSHFT6
/
/SUBROUTINE RSHFT6                                                              
/
/SHIFT6 AC RIGHT SIX BITS                                                       
/CALLING SEQUENCE:
/       JMS     RSHFT6                                                          
/       (RETURN)                                                                
/LINK IS CLEARED
/
RSHFT6	0
        CLL!RTR                                                                 
        RTR                                                                     
	RTR
        JMP*    RSHFT6                                                          
/
/SUBROUTINES GT.FST,GT.CHR
/
/GT.FST-INITIALIZE 51A .ASCII UNPACKING. ON ENTRY                               
/AC CONTAINS ADDRESS OF LINE BUFFER TO BE                                       
/UNPACKED.  ON RETURN AC CONTAINS FIRST CHARACTER                               
/OF LINE BUFFER.                                                                
/GT.CHR-AFTER 5/7 .ASCII UNPACKING HAS BEEN                                     
/INITIALIZED BY GT.FST, GT.CHR WILL RETURN  
/SUBSEQUENT CHARACTERS IN AC.                                                   
/
GT.FST	0
        TAD     (2              /BUFFER POINTER                                 
        DAC     GT.PTR                                                          
        LAW     -1              /CHARACTER COUNTER                              
        DAC     GT.5                                                            
        LAC     GT.FST          /FAKE 'JMS GT.CHR' TO                           
        DAC     GT.CHR          /GET FIRST CHARACTER                            
	JMP	GT.CHR+1
/
GT.CHR	0
        ISZ     GT.5                                                            
        JMP     GT.MOR          /WORD PAIR STARTED                              
        LAC*    GT.PTR          /NEED NEXT PAIR                                 
        ISZ     GT.PTR                                                          
        DAC     GT.WD1          /FIRST PART                                     
	LAC*	GT.PTR
        ISZ     GT.PTR                                                          
	DAC	GT.WD2		/SECOND PART
        LAW     17773           /RESET CHARACTER COUNTER                        
        DAC     GT.5                                                            
GT.MOR  LAW     17770           /SHIFT LOOP TO 7 1/2 TIMES                      
        DAC     GT.WD3                                                          
GT.LUP  LAC     GT.WD2                                                          
        RAL                                                                     
        ISZ     GT.WD3                                                          
        JMP     .+3                                                             
        AND     (177            /GOT CHARACTER                                  
        JMP*    GT.CHR          /EXIT                                           
        DAC     GT.WD2                                                          
        LAC     GT.WD1                                                          
        RAL                                                                     
        DAC     GT.WD1                                                          
	JMP	GT.LUP		/BACK TO LOOP
/
GT.PTR	0
GT.5    0                                                                       
GT.WD1  0                                                                       
GT.WD2	0
GT.WD3  0                                                                       
DEV	0
UIC	0
        .EJECT                                                                  
/
/DATA,BUFFERS,CONSTANTS                                                         
/
FLAG	0
TMPFIL	.SIXBT	'TEMPRATMP'
ENTER	.SIXBT	/TMPFILSRC/	/THESE "DEB'S" ARE CHANGED
ENTERP	.SIXBT	/TMPFILSRC/	/DEB'S ARE NON-ZERO SO WE 
				/DON'T GET IOPS73'S
LENTER  0                                                                       
BLANK	40
CR	15
SRC     .SIXBT  'SRC'                                                           
LINCNT  0                                                                       
L1      0                                                                       
L2      0                                                                       
CDBUFF	.BLOCK	60
CPBUFF .BLOCK  60                                                               
SEQERR	006002
	0
	.ASCII	'LINE NUMBERS OUT OF SEQUENCE'<15>
        .END    BEGIN                                                           
