ASMB,Z,L
			NAM	'MGEN for HP 5420B'
*
*-------------------------------------------------------------------------------------------------
*			MGEN for HP 5420B
*-------------------------------------------------------------------------------------------------
*
*		Filename:		MGEN5420B.asm
*		Project Name:		HP 5420A/5423A Restoration Project
*		Project Purpose:	Restoration to full operation the HP 5420A Digital Signal
*					Analyzer and the HP 5423A Digital Structural Analyzer.
*
*		Target CPU:		HP 21MX
*		Date:			24 Dec 2014
*		Verson:			1.0.0
*		Author:			Peter D O'Neill
*		Source:			HP 5420B/HPIB MASTER CONTROL TAPE 05420-60029?
*		
*		File Purpose:		This file is to take control of the system boot process
*					after the Internal Binary Loader (IBL) has loaded this
*					code from the Control Tape. The IBL passes control to
*					MGEN once it has been sucessfully loaded then MGEN prerforms
*					the second light test which indicates to the operator that
*					it has loaded and then the LEDS in the illuminated measurement 
*					buttons on thee 5441A front panel will provide a binary 
*					count of the records sucessfilly loaded as the main control
*					software is loaded into memory. When the loading is complete
*					then control is transferred to the main program.
*
*-------------------------------------------------------------------------------------------------
*		LABELS USED
*-------------------------------------------------------------------------------------------------
*
*		I've tried use labels that are descriptive as well as keeping the use of a "."
*		separater as used in HP documentation of the time. 
*
*		Subroutines will have names like READY.INDICATOR then any further labels in the
*		in the subroutine may have the last word truncated and will have number added eg
*
*		READY.IND.1
*		READY.IND.2
*		etc
*
*		Time Constants will be NAME.TC
*		Lights will be NAME.LIGHT
*		Keys will be NAME.KEY
*		Control Word for an MIOB device is NAME.CW this used where the status of the
*		device is being toggled.
*
*		So the control word for the ready light would be READY.LIGHT.CW
*
*		If on the other hand the decive is just going to be turned ON only or OFF only
*		then NAME.ON or NAME.OFF is used.
*
*		Where a bit pattern is stored but not overwritten and it is loaded into register
*		or is used with CP(A/B), IOR, XOR, AND instructions then it is being used for  bit
*		setting or clearing then we will call it a mask eg NAME.MASK.
*
*		Temporary storage will be NAME.TS and if the location is only used by one subroutine
*		then it is local temporary storage so it would be SUBROUTINENAME.LTS
*
*		If I'm unsure of an appropriate label then my best guess will be NAME.???
*
*		Constants that are used for comparison should have a name that discribes
*		the comparison
*
*			Conditional Assembly
*
*			For items specifically related to the 5420 set condition assembly to 'Z'
*			For items specifically related to the 5423 set condition assembly to 'N'
*
*-------------------------------------------------------------------------------------------------
*
*			ASMB,Z			; This must be on the first line
*
*-------------------------------------------------------------------------------------------------
*			Regiseter Equates
*-------------------------------------------------------------------------------------------------
*
A			EQU	0		; A-register equate
B			EQU	1		; B-register equate
*
*-------------------------------------------------------------------------------------------------
*			Equates for Front Panel
*-------------------------------------------------------------------------------------------------
*
FRONT.PANEL.21MX	EQU	1B		; Check this
*
*-------------------------------------------------------------------------------------------------
*			Equates for MIOB
*-------------------------------------------------------------------------------------------------
*
MIOB.SELECT		EQU	10B		; I/O Select address for MIOB
KEYBOARD.DEVICE		EQU	20000B		; 0010	5443A Kyboard/Control -- Keyboard
TAPE.DEVICE		EQU	30000B		; 0011	5441A Display -- A9 Cartridge Interface
*
*-------------------------------------------------------------------------------------------------
*			Equates for Keys
*-------------------------------------------------------------------------------------------------
*
KBD.ENABLE		EQU	000067B		; Keyboard enable, this is an output control
*						; word to be set up as through it is a light. 
KEY.ON.5441A		EQU	000100B		; Key is on 5441A
FIRST.PRESS		EQU	000200B		; First time key is pressed
KPUP.BIT		EQU	001000B		; Reset the key scanning
*
*-------------------------------------------------------------------------------------------------
*			Equates for Keys with same name and position on 5420 and 5423
*		        Keys located on 5443A front panel
*-------------------------------------------------------------------------------------------------
*
COMMA.KEY		EQU	000005B		; COMMA key status
DOT.KEY			EQU	000006B		; DOT (FULL STOP) key status
N0.KEY			EQU	000007B		; NUMERIC 0 key status
N3.KEY			EQU	000015B		; NUMERIC 3 key status
N2.KEY			EQU	000016B		; NUMERIC 2 key status
N1.KEY			EQU	000017B		; NUMERIC 1 key status
PAUSE/COUNT.KEY		EQU	000022B		; PAUSE/COUNT key status
HZ/mSEC/dB.KEY		EQU	000023B		; HZ/mSEC/dB key status
N6.KEY			EQU	000025B		; NUMERIC 6 key status
N5.KEY			EQU	000026B		; NUMERIC 5 key status
N4.KEY			EQU	000027B		; NUMERIC 4 key status
START.KEY		EQU	000032B		; START key status
kHZ/SEC/V.KEY		EQU	000033B		; kKHZ/SEC/V key status
CURSOR.VALUE.KEY	EQU	000034B		; CURSOR VALUE key status
N9.KEY			EQU	000035B		; NUMERIC 9 key status
N8.KEY			EQU	000036B		; NUMERIC 8 key status
N7.KEY			EQU	000037B		; NUMERIC 7 key status
DSP.EXP.KEY		EQU	000051B		; DISPLAY EXPAND key status
DSP.CNT.KEY		EQU	000052B		; DISPLAY CONTRACT key status
TOP/RIGHT.KEY		EQU	000061B		; TOP/RIGHT key status
BOT/LEFT.KEY		EQU	000062B		; BOTTOM/LEFT key status
X.KEY			EQU	000071B		; X key status
Y.KEY			EQU	000072B		; Y key status
TRIG.KEY		EQU	000073B		; TRIG key status
SGNL.KEY		EQU	000074B		; SGNL key status
AVG.KEY			EQU	000075B		; AVG key status
FREQ.KEY		EQU	000076B		; FREQ key status
TIME.KEY		EQU	000077B		; TIME key status
*
*-------------------------------------------------------------------------------------------------
*			Equates for keys specific to the 5420A 
*			Keys located on 5443A front panel
*-------------------------------------------------------------------------------------------------
*
			IFZ
*
SELF.TEST.KEY		EQU	000001B		; SELF TEST key status
RESET.KEY		EQU	000002B		; RESET key status
BACKSP.KEY		EQU	000003B		; BACKSPC key status
DASH.KEY		EQU	000004B		; DASH key status
MAX.RATE.KEY		EQU	000011B		; MAX RATE key status
VIEW.INPUT.KEY		EQU	000012B		; VIEW INPUT key status
mHZ/uSEC.KEY		EQU	000013B		; mHZ/uSEC key status
EEX.KEY			EQU	000014B		; EEX key status
BLANK.KEY		EQU	000024B		; <BLANK> key status
RESTORE.KEY		EQU	000043B		; RESTORE key status
VIEW.KEY		EQU	000045B		; VIEW key status
STORE.KEY		EQU	000047B		; STORE key status
T.KEY			EQU	000053B		; T key status
BW.KEY			EQU	000054B		; BW key status
CENT.FREQ.KEY		EQU	000055B		; CENT FREQ key status
UP.KEY			EQU	000056B		; UP ARROW key status
DOWN.KEY		EQU	000057B		; DOWN ARROW key status
CAL.KEY			EQU	000063B		; CAL key status
DELAY.KEY		EQU	000064B		; DELAY key status
AC/DC.KEY		EQU	000065B		; AC/DC key status
RANGE.KEY		EQU	000066B		; RANGE key status
CHAN#.KEY		EQU	000067B		; CHAN# key status
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for keys specific to the 5423A 
*			Keys located on 5443A front panel
*-------------------------------------------------------------------------------------------------
*
			IFN
*
RESET.KEY		EQU	000001B		; RESET key status
ALPHA.KEY		EQU	000002B		; ALPHA key status
EEX.KEY			EQU	000003B		; EEX key status
BACKSP.KEY		EQU	000004B		; BACKSPC key status
SELF.TEST.KEY		EQU	000011B		; SELF TEST key status
AUTO.SEQ.KEY		EQU	000012B		; AUTO SEQ key status
CPM/uSEC.KEY		EQU	000013B		; CPM/uSEC key status
DASH.KEY		EQU	000014B		; DASH key status
EDIT.KEY		EQU	000024B		; EDIT key status
RECALL.KEY		EQU	000043B		; RECALL key status
SAVE.KEY		EQU	000044B		; SAVE key status
STATE.KEY		EQU	000045B		; STATE key status
UP.KEY			EQU	000046B		; UP ARROW key status
DOWN.KEY		EQU	000047B		; DOWN ARROW key status
CAL.KEY			EQU	000053B		; CAL key status
DELAY.KEY		EQU	000054B		; DELAY key status
AC/DC.KEY		EQU	000055B		; AC/DC key status
RANGE.KEY		EQU	000056B		; RANGE key status
CHAN#.KEY		EQU	000057B		; CHAN# key status
BW.KEY			EQU	000063B		; BW key status
CENT.FREQ.KEY		EQU	000064B		; CENT FREQ key status
T.KEY			EQU	000065B		; T key status
EXT.SMPL.KEY		EQU	000066B		; EXT SMPL key status
ID.KEY			EQU	000067B		; ID key status
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for Keys with same name and position on 5420 and 5423
*		        Keys located on 5441A front panel
*-------------------------------------------------------------------------------------------------
*
CROSS.KEY		EQU	000034B		; CROSS key status
AUTO.KEY		EQU	000035B		; AUTO key status 
COHER.KEY		EQU	000036B		; COHER key status
TRANS.KEY		EQU	000037B		; TRANS key status
LG/MG.KEY		EQU	000046B		; LG/MG key status
IM/RE.KEY		EQU	000047B		; IM/RE key status
IMAG.KEY		EQU	000056B		; IMAG key status
REAL.KEY		EQU	000057B		; REAL key status
PLUS.KEY		EQU	000062B		; PLUS key status
MINUS.KEY		EQU	000063B		; MINUS key status
XLOGX.KEY		EQU	000066B		; XLOGX key status
LOG.MAG.KEY		EQU	000067B		; LOG MAG key status
EXPAND.KEY		EQU	000073B		; EXPAND key status
FORMAT.KEY		EQU	000074B		; FORMAT key status
TRACE.KEY		EQU	000075B		; TRACE key status
PHASE.KEY		EQU	000076B		; PHASE key status
MAG.KEY			EQU	000077B		; MAG key status
*
*-------------------------------------------------------------------------------------------------
*			Equates for keys specific to the 5420A 
*			Keys located on 5441A front panel
*-------------------------------------------------------------------------------------------------
*
			IFZ
*
LINEAR.KEY		EQU	000032B		; LINEAR key status
HIST.KEY		EQU	000033B		; HIST key status
SAVE.KEY		EQU	000042B		; SAVE key status
PLOT.KEY		EQU	000043B		; PLOT key status
POWER.KEY		EQU	000052B		; POWER key status
PEAK.KEY		EQU	000053B		; PEAK key status
GOLD.KEY		EQU	000072B		; GOLD key status
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for keys specific to the 5423A 
*			Keys located on 5441A front panel
*-------------------------------------------------------------------------------------------------
*
			IFN
*
INPUT.KEY		EQU	000032B		; INPUT key status
LINEAR.KEY		EQU	000033B		; LINEAR key status
PLOT.KEY		EQU	000042B		; PLOT key status
POWER.KEY		EQU	000043B		; POWER key status
SQUARED.KEY		EQU	000052B		; SQUARED key status
INTEGRAL.KEY		EQU	000053B		; INTEGRAL key status
SHIFT.KEY		EQU	000072B		; SHIFT key status
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for LIGHT control bits with same name and position on 5420 and 5423
*		        Lights located on 5443A front panel
*-------------------------------------------------------------------------------------------------
*
X.LIGHT			EQU	000053B		; Select X light
Y.LIGHT			EQU	000054B		; Select Y light
REMOTE.LIGHT		EQU	000056B		; Select REMOTE light
READY.LIGHT		EQU	000064B		; Select READY light
OFF			EQU	000000B		; Light OFF flag
ON			EQU	000100B		; Light ON flag	
*
*-------------------------------------------------------------------------------------------------
*			Equates for lights specific to the 5420A 
*			lights located on 5443A front panel
*-------------------------------------------------------------------------------------------------
*
			IFZ
*
INPUT.LIGHT		EQU	000057B		; Select INPUT light
VIEW.LIGHT		EQU	000060B		; Select VIEW light
RATE.LIGHT		EQU	000061B		; Select RATE light
MAX.LIGHT		EQU	000062B		; Select MAX light
RUN.LIGHT		EQU	000066B		; Select RUN light
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for lights specific to the 5423A 
*			lights located on 5443A front panel
*-------------------------------------------------------------------------------------------------
*
			IFN
*
ALPHA.LIGHT		EQU	000057B		; Select ALPHA light
SHIFT.LIGHT		EQU	000060B		; Select SHIFT light
MAX.LIGHT		EQU	000061B		; Select MAX light
VIEW.LIGHT		EQU	000062B		; Select VIEW light
MEAS.LIGHT		EQU	000066B		; Select MEAS light
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for LIGHT control bits with same name and position on 5420 and 5423
*		        Lights located on 5441A front panel
*-------------------------------------------------------------------------------------------------
*
PRT/BK.LIGHT		EQU	000032B		; Select PRT/BK light
UNLABELED.LIGHT		EQU	000033B		; Light works but front panel is blackedout
UPR/LWR.LIGHT		EQU	000034B		; Select UPR/LWR light
B.LIGHT			EQU	000035B		; Select B light
FULL.LIGHT		EQU	000036B		; Select FULL light
A.LIGHT			EQU	000037B		; Select A light
CROSS.LIGHT		EQU	000434B		; Select CROSS light
AUTO.LIGHT		EQU	000435B		; Select AUTO light
COHER.LIGHT		EQU	000436B		; Select COHER light
TRANS.LIGHT		EQU	000437B		; Select TRANS light
*
*-------------------------------------------------------------------------------------------------
*			Equates for lights specific to the 5420A 
*			lights located on 5441A front panel
*-------------------------------------------------------------------------------------------------
*
			IFZ
*
LINEAR.LIGHT		EQU	000432B		; Select LINEAR light
HIST.LIGHT		EQU	000433B		; Select HIST light
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for lights specific to the 5423A 
*			lights located on 5441A front panel
*-------------------------------------------------------------------------------------------------
*
			IFN
*
INPUT.LIGHT		EQU	000432B		; Select INPUT light
LINEAR.LIGHT		EQU	000433B		; Select LINEAR light
*
			XIF
*
*-------------------------------------------------------------------------------------------------
*			Equates for TAPE CARTRIDGE control bits
*-------------------------------------------------------------------------------------------------
*
FRONT			EQU	001000B		; Front cartridge on
REAR			EQU	000400B		; Rear cartridge on
CARTOFF			EQU	001400B		; Turn both Cartridges off
SELECT			EQU	006000B		; Cartride select code
BIT			EQU	000400B		; Bit data mode / 0 = Word data mode
READ			EQU	002000B		; Read from tape control bit
WRITE			EQU	004000B		; Write TO tape control bit
RUN			EQU	000100B		; Run tape control bit
LITE			EQU	000040B		; Cartridge activity light
TRACKB			EQU	000020B		; Selects track B, Zeroing this bit selects track A
REVERSE			EQU	000010B		; Sets tape motion to reverse, Zeroing this bit Sets 
*						; tape motion to forward
FAST			EQU	000004B		; Sets tape motion to 88IPS, Zeroing this bit Sets
*						; the tape speed to 22ips
MOD			EQU	000002B		; Sets the VDAC read threshold 
*
*-------------------------------------------------------------------------------------------------
*			Equates for TAPE CARTRIDGE Status bits
*-------------------------------------------------------------------------------------------------
*
DATA.ERROR		EQU	004000B		; Set if 5443A is too slow on read or write
IRG			EQU	002000B		; Set if Inter-Record Gap (IRG)
1STWORD			EQU	001000B		; Set if First word of data
ERROR			EQU	000400B		; Set if EOT, Motor Error, or 10mS time-out
TTACH			EQU	002000B		; Set if 2000 tach pulses per rev
MVG			EQU	004000B		; Set if Low tape speed < 2ips
MERR			EQU	000040B		; Set if Motor Error or EOT
CEOT			EQU	000020B		; Set if End Of Tape (EOT) detected
CWEN			EQU	000010B		; Set if the cartridge RECORD tab allows writing 
COUT			EQU	000004B		; Set if when no cartridge is in the selected drive
*
*-------------------------------------------------------------------------------------------------
*			Equates for external references
*-------------------------------------------------------------------------------------------------
*
PAGE.ZERO.LOC.2		EQU	2B		; This is supposed to be the entry point
*						; where the system software starts the SETUP
*						; STATE display on screen
PAGE.ZERO.LOC.3		EQU	3B
PAGE.ZERO.LOC.4		EQU	4B		; But this appear to be the entry point
*						; possibly changed for the 5420B
PAGE.ZERO.LOC.5		EQU	5B
*
*-------------------------------------------------------------------------------------------------
*			Equates for Hook Addresses in IBL
*-------------------------------------------------------------------------------------------------
*
Z000300			EQU	300B
*
*-------------------------------------------------------------------------------------------------
*			Origin At 024000B
*-------------------------------------------------------------------------------------------------
*
			ORG	24000B			; 24002B

INSTRUCTION.DEST.1      ABS	0B                      ; This code could possibly be a warm start
INSTRUCTION.DEST.2      ABS	0B                      ; routine which doesn't include a light
INSTRUCTION.DEST.3      ABS	0B                      ; test.
INSTRUCTION.DEST.4      ABS	0B 
*
*-------------------------------------------------------------------------------------------------
*			Entry Point at 024004B, This the transfer address used by the IBL
*-------------------------------------------------------------------------------------------------
*
MGEN_ENTRY		EQU	*
INSTRUCTION.SOURCE.1    JSB     SET.UP.FOR.READ.MODE	; On entry (A REG) = 32000B       
INSTRUCTION.SOURCE.2    CLA                      
INSTRUCTION.SOURCE.3    STA     READY.LIGHT.SETUP	; return address of READY.LIGHT.SETUP set to zero 
               		JMP     LOAD.CONTROL.SOFTWARE	; Go and load the system control software
          
               		LDA     TAPE.REVERSE.MASK	; Initialise the MOIB I/O Address          
               		LDB     TAPE.REVERSE.MASK       ; TAPE.REVERSE.MASK is the same value as   
               		STB     MIOB.ADDR               ; the MIOB address
               		JSB     S024431          
               		JSB     DO.LIGHT.TEST          
               		JSB     FLASH.READY.FAST          
INSTRUCTION.SOURCE.4    JMP     AUTO.REWIND.TAPE          
*
*-------------------------------------------------------------------------------------------------
*			Exit to Ready, This will display the "SETUP STATE" page on the CRT
*-------------------------------------------------------------------------------------------------
*
EXIT.TO.READY        	JSB     DO.LIGHT.TEST		; Perform a light test          
               		JSB     KB.EN.&.DRIVE.SEL	; enable keyboard, and select tape drive          
               		LDA     DMS.16K.SEGMENT.LENGTH  ; Restore the addressable memory (40000 to        
               		STA     DMS.B0.SEG.PAGE.NUMBER  ; 77777) to physical memory in the range       
               		JSB     SET.DMS			; 40000 to 77777 
*							; memory into address space          
               		STC     4B			; re-initialises the power fail logic and 
*							; restores the interrupt system					               
               		JMP     PAGE.ZERO.LOC.4		; this is transfer of control to 
*							; main system software
          
TEMP.INSTRUCTION.1      ABS	124003B			; JMP     PAGE.ZERO.LOC.3,I        
TEMP.INSTRUCTION.2      ABS	056337B			; CPB     C024337          
TEMP.INSTRUCTION.3      ABS	114017B			; JSB     S000017,I        
JUMP.INDEXED.ADR.3      ABS	124003B			; JMP     PAGE.ZERO.LOC.3,I        
ADDRESS.OF.LIGHT.TEST   ABS	LIGHT.TEST.LOOP.ADDRESS	; used by a JMP ,I
*
*-------------------------------------------------------------------------------------------------
*		This is the main loop for generating a CONTROL TAPE
*
*		It is also a bit confusing as there a multiple entry points
*		some of which are subroutine entries and the execution of some
*		of the code is such that the subroutines can be executed without
*		a JSB instruction. Having said that there are also parts of the
*		code that place NOPs in the subroutine return address location
*		so that the execution flow can just fall into a subroutine
*		without trying to execute and unexpected instruction.
*-------------------------------------------------------------------------------------------------
*          
DUPLICATE.LOOP 		JSB     DO.LIGHT.TEST          
               		JSB     KB.EN.&.DRIVE.SEL          
               		LDA     RUN.LIGHT.ON		; turn on the "RUN" light          
               		JSB     MIOB.CONTROL          
               		JSB     FORWARD.FIXED.AMOUNT          
               		JSB     FORWARD.FIXED.AMOUNT          
               		JSB     FORWARD.FIXED.AMOUNT          
               		JSB     REWIND.WITH.IRG.DISPLAY          
MODIFIED.CODE.1        	RSS                      
               		JMP     DUPLICATE.LOOP.2          
               		JMP     DUPLICATE.LOOP.3          
DUPLICATE.LOOP.2        JSB     SKIP.NEXT.INSTRUCTION          
               		JMP     DUPLICATE.LOOP.8          
               		LDA     CONSTANT.ZERO          
               		STA     DMS.B0.SEG.PAGE.NUMBER          
               		JSB     WRITE.A.RECORD.TO.TAPE          
DUPLICATE.LOOP.3        LDA     DMS.A0.REGISTER		; (A-reg) <-- 0B, which selects track A    
               		STA     TAPE.TRACK.SELECT 	; now save to tape track storage        
               		JSB     TABLE.INITIALISER	; initialise table          
               		JMP     J024123
          
DUPLICATE.LOOP.4        JSB     SKIP.NEXT.INSTRUCTION          
               		JSB     FLASH.RDY.SLOW.IOFF 
         
               		LDA     PAGE.MASK          
               		STA     RECORD.NUMBER.STORE.WR	; Save Record Number (duplication mode)          
               		JSB     WRITE.FOUR.DATA.RECORDS	; return address is next instruction + 1          
               		JMP     PAGE.ZERO.LOC.4		; this is an exit point          
DUPLICATE.LOOP.5        JSB     DMS.TABLE.UPDATE          
               		ADA     READ.THRESHOLD.MASK          
               		CPA     READ.THRESHOLD.MASK          
               		RSS                      
               		LDA     CONSTANT.16384          
               		JSB     WRITE.A.RECORD.TO.TAPE          
               		LDA     DMS.B0.SEG.PAGE.NUMBER	;           
               		INA                      
               		CPA     CONSTANT.64          
               		RSS                      
C024077        		CPA     CONSTANT.64.2          
               		RSS                      
               		JMP     DUPLICATE.LOOP.5          
               		JSB     WRITE.FOUR.DATA.RECORDS ; return address is next instruction + 1          
               		JMP     A                
               		JSB     SKIP.NEXT.INSTRUCTION          
               		JMP     DUPLICATE.LOOP.8          
DUPLICATE.LOOP.7        JSB     WRITE.FOUR.DATA.RECORDS	; return address is next instruction + 1           
               		JMP     A                
               		JMP     DUPLICATE.LOOP.7          
DUPLICATE.LOOP.8        JSB     REWIND.WITH.IRG.DISPLAY          
               		LDA     TAPE.TRACK.SELECT 	; get the cuurent tape track selection         
               		CPA     DMS.A0.REGISTER		; if track B isn't selected then skip          
               		RSS                      	; skip and process track B
               		JMP     DUPLICATE.LOOP.4          		; jump to process track A
               		LDA     RECORD.NUMBER.STORE.WR	; Get Record Number (duplication mode)          
               		JSB     DISPLAY.RECORD.NUMBER	; Display the record number          
               		JSB     CHECK.FOR.SELF.TEST          
               		JMP     DUPLICATE.LOOP 
*
*-------------------------------------------------------------------------------------------------
*		Storage for the Record number while we are making a duplicate control tape			
*-------------------------------------------------------------------------------------------------
*
RECORD.NUMBER.STORE.WR	ABS	1777B
*         
J024123        		JSB     CHKS.TABLE.INIT          
               		JMP     DMS.TABLE.UPDATE.1
          
AUTO.REWIND.TAPE        JSB     REWIND.WITH.IRG.DISPLAY
*
*-------------------------------------------------------------------------------------------------
*		Entry point for loading the control tape into memory			
*-------------------------------------------------------------------------------------------------
*
LOAD.CONTROL.SOFTWARE 	JSB     DO.LIGHT.TEST 		; Perform a light test         
LOAD.CONTROL.SOFTWARE.1 JSB     READ.DATA.RECORD          
               		LDA     READY.LIGHT.SETUP 	; test the return address for READY.LIGHT.SETUP         
               		SZA,RSS				; if A-reg = 0 then execute the next instruction                  
               		JMP     LOAD.CONTROL.SOFTWARE.2	; Else, skip this instruction          
               		JSB     CHECK.FOR.SELF.TEST     ; Did the operator press the "SELF TEST" key     
               		JMP     LOAD.CONTROL.SOFTWARE.1          
LOAD.CONTROL.SOFTWARE.2	JSB     REWIND.WITH.IRG.DISPLAY          
               		LDA     MENU.ACTIVE		; Test if menu is active          
               		SZA,RSS				; skip if non-zero                  
C024140        		JMP     EXIT.TO.READY		; here if the menu was not entered          
               		LDA     TAPE.SELECT.FRONT       ; else. here if we are waiting for the user   
               		STA     TAPE.SELECT.FRONT.CW    ; to press a menu key      
               		JSB     FLASH.READY.FAST          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, FLASH.READY.SLOW
*
*		Set flash rate for "READY" light (twice per second?)			
*-------------------------------------------------------------------------------------------------
*
FLASH.READY.SLOW        NOP                      
               		LDA     CONSTANT.MINUS.32768	; A reg <-- -32768        
               		JMP     FLASH.READY.FAST.1          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, FLASH.READY.FAST
*
*		Set flash rate for "READY" light (16 times per second?)	
*-------------------------------------------------------------------------------------------------
*
FLASH.READY.FAST        ABS	024144B          
               		LDA     CONSTANT.MINUS.4096     ; A reg <-- -4096 
               		JMP     FLASH.READY.FAST.1          
               		NOP                      
               		LDA     CONSTANT.176000B        ; A reg <-- 176000B  
FLASH.READY.FAST.1	LDB     READY.LIGHT.OFF          
               		JSB     READY.LIGHT.SETUP 	; READY.LIGHT.SETUP return may be being altered         
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, CHECK.FOR.SELF.TEST
*
*		Check if the operator pressed the "SELF TEST" key			
*-------------------------------------------------------------------------------------------------
*
CHECK.FOR.SELF.TEST     ABS	024402B         
               		LDA     SAVED.KEY.CODE 		; Get the last key pressed         
               		CPA     SELF.TEST.PRESSED	; Was it the "SELF TEST" key?         
               		JMP     CHECK.FOR.SELF.TEST,I	; Yes then return to caller 
               		JSB     FLASH.READY.FAST          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, FLASH.RDY.SLOW.IOFF
*
*		Set flash rate for "READY" light, turn INPUT light off.	
*-------------------------------------------------------------------------------------------------
*
FLASH.RDY.SLOW.IOFF	ABS	024526B          
               		LDA     CONSTANT.MINUS.32768	; A reg <-- -32768        
               		JMP     FLASH.RDY.FAST.IOFF.1          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, FLASH.RDY.FAST.IOFF
*
*		Flash the "READY" light fast, turn INPUT light off, and go an test for
*		keyboard entry. Don't know how the subroutine returns to the caller, can't see 
*		where the return address is read!!!			
*-------------------------------------------------------------------------------------------------
*
FLASH.RDY.FAST.IOFF	ABS     024630B          
               		LDA     CONSTANT.MINUS.4096	; A reg <-- -4096            
FLASH.RDY.FAST.IOFF.1	LDB     INPUT.LIGHT.OFF		; "INPUT" light off control word          
               		JSB     READY.LIGHT.SETUP	; READY.LIGHT.SETUP return may be being altered 
*
*	I think that you only return from the above subroutine if there is an error
*	as the following routine appears to loop continuously while performing a light test.
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, Flash the "READY" light
*			This may infact be a light test but there are differing delays on entry			
*-------------------------------------------------------------------------------------------------
*
LIGHT.TEST.LOOP.ADDRESS	EQU	*
LIGHT.TEST.LOOP        	LDA     READY.LIGHT.CW		; Turn on the "READY" light
*							         
LIGHT.TEST.LOOP.1       JSB     MIOB.CONTROL          
               		XOR     LIGHT.ON.OFF            
               		INA                             
               		CPA     END.OF.LIGHT.TEST 	; Skip if A-reg not equal to 027600B         
               		LDA     KEYBOARD.ADDRESS        ; else, reset the device address back
               		LDB     CONSTANT.MINUS.257	; This is short delay of 712uS          
LIGHT.TEST.LOOP.2   	ISZ     B                
               		JMP     LIGHT.TEST.LOOP.2          
               		JMP     LIGHT.TEST.LOOP.1          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, WAS.GOLD.KEY.PRESSED
*
*		Test if the last key pressed was the "GOLD" key
*		On entry (A reg) is the current record number			
*-------------------------------------------------------------------------------------------------
*
WAS.GOLD.KEY.PRESSED	ABS	0B                      
               		LDB     SAVED.KEY.CODE		; Get the most recent key pressed          
               		CPB     GOLD.KEY.TEST          	; was it the "GOLD" key?
               		RSS				; skip if the "GOLD" key was pressed                      
               		JMP     WAS.GOLD.KEY.PRESSED,I	; Return to caller if "GOLD" key wasn't pressed

        		JSB     DISPLAY.RECORD.NUMBER	; display the record number          
               		JSB     FLASH.READY.SLOW          
*
*-------------------------------------------------------------------------------------------------
*		Initialisation of "READY" light state and flash time constant
*
*		This is called as a subroutine but it appears not to return
*		normally using the return address as if it did the program
*		flow would crash.
*		On entry (A reg) is the new READY LIGHT time constant
*			 (B reg) is the READY LIGHT CONTROL WORD			
*-------------------------------------------------------------------------------------------------
*
READY.LIGHT.SETUP       ABS     024156B			; READY.LIGHT.SETUP return may be being altered           
               		STA     READY.LIGHT.TC		; save the "READY" light time constant		          
               		STB     READY.LIGHT.CW		; save the "READY" lighy control word          
               		JSB     KB.EN.&.DRIVE.SEL	; enable keyboard, and select tape drive          
DONT.MASK.IR.ERR0R.MVG	CLA,CLE				; Reset the key press counter
*							; content of this location is also used
*							; to test for IRG, ERROR, and MVG flags                  
               		STA     KEY.PRESS.COUNT		; update the counter storage          
J024221        		LDA     CONSTANT.MINUS.30          
               		STA     LOOP.COUNTER.1          
               		JMP     READY.IND.1
*
*-------------------------------------------------------------------------------------------------
*		Control of "READY" light 			
*-------------------------------------------------------------------------------------------------
*          
READY.INDICATOR        	LDA     READY.INDICATOR.LTS	; Get the READY LIGHT STATUS          
               		CMA 				; Toggle it                     
               		STA     READY.INDICATOR.LTS	; and save it          
               		LDA     READY.LIGHT.CW		; Get the READY LIGHT OFF CONTROL WORD          
               		XOR     LIGHT.ON.OFF		; Toggle the light on/off control bit          
               		STA     READY.LIGHT.CW		; save the control word          
               		JSB     MIOB.CONTROL 		; issue the MIOB control word
READY.IND.1       	LDA     READY.INDICATOR.LTS	; get the READY LIGHT STATUS          
               		SSA				; skip if status is positive                      
READY.IND.2        	JMP     READY.IND.5          
READY.IND.3        	CLF     MIOB.SELECT		; Clear Flag              
READY.IND.4        	SFC     MIOB.SELECT		; Switch MIOB to Control Mode             
READY.IND.5        	STC     MIOB.SELECT,C		; Issue a COMMC           
*
*-------------------------------------------------------------------------------------------------
*		Outer delay loop (approx 100mS), READY LIGHT flash rate 0.2S
*-------------------------------------------------------------------------------------------------
*
               		LDA     READY.LIGHT.TC		; Load READY LIGHT flash time constant
*
*-------------------------------------------------------------------------------------------------
*		Inner delay loop (13.8uS), Waiting for MIOB ready
*-------------------------------------------------------------------------------------------------
*         
READY.IND.6        	LDB     MIOB.TEST.TC		; load the loop delay count (5)       
READY.IND.7        	ISZ     B                	; loop delay 2.765uS
               		JMP     READY.IND.7		; total loop delay 13.8uS          
READY.IND.8        	SFS     MIOB.SELECT 		; Skip MIOB is ready             
               		RSS				; skip if no data 
               		JMP     READY.IND.9          	; eles, go and read the MIOB
               		ISZ     A 			; Dec READY LIGHT flash time constant              
               		JMP     READY.IND.6		; count no zero yet, loop again          
               		JMP     READY.INDICATOR		; else, count zero update READY LIGHT          
READY.IND.9        	LIA     MIOB.SELECT 		; read the data from MIOB             
               		STA     KEY.READ          	; save it for later processing
               		AND     DEVICE.ADDRESS.MASK	; Mask all but device addresses          
               		CPA     KEYBOARD.ADDRESS          
               		JMP     READY.IND.10          
               		CPA     TAPE.ADDRESS          
               		JMP     J024331          
               		JMP     J024354
          
READY.INDICATOR.LTS	ABS	177777B 		; Initially set negative (flag toggled pos/neg)       
CONSTANT.MINUS.32768    ABS     100000B          
CONSTANT.MINUS.4096     ABS     170000B              
CONSTANT.176000B        ABS     176000B			             
READY.LIGHT.TC		ABS     170000B			; Time Constant for READY LIGHT             
KEY.READ        	ABS     020035B
*
*-------------------------------------------------------------------------------------------------
*					
*-------------------------------------------------------------------------------------------------
*          
READY.IND.10        	LDA     KEY.READ          
               		LDB     READY.LIGHT.CW          
               		SLB,RSS                  
               		JMP     TEST.FOR.MENU.KEYS
          
               		CPA     GOLD.PRESSED		; Test for the "GOLD" key          
               		JMP     ENTER.MENU          	; here if the "GOLD" key was pressed
               		JMP     READY.IND.1 		; loop back from here "GOLD" key not pressed
*
*-------------------------------------------------------------------------------------------------
*		Test if any of the function keys have been pressed					
*-------------------------------------------------------------------------------------------------
*                   
TEST.FOR.MENU.KEYS	CPA     DOT.PRESSED		; Change read threshold?          
               		JMP     CHANGE.READ.THRESHOLD          
               		CPA     N0.PRESSED		; Exit?          
               		JMP     EXIT.TO.READY          
               		CPA     N1.PRESSED		; Wind tape back?          
               		JMP     MOVE.TAPE.BACK          
               		CPA     N2.PRESSED 		; Select other tape drive?         
               		JMP     SELECT.OTHER.DRIVE          
               		CPA     N3.PRESSED 		; Wind tape forward?         
               		JMP     MOVE.TAPE.FORWARD          
               		CPA     N4.PRESSED		; Rewind tape (start index hole)?          
               		JMP     REWIND.TAPE          
               		CPA     N5.PRESSED		; Certify a test tape?          
               		JMP     CERTIFY.TEST.TAPE          
               		CPA     N6.PRESSED		; Make a test tape?          
               		JMP     GENERATE.TEST.TAPE 	         
               		CPA     N7.PRESSED 		; Load a tape?         
               		JMP     LOAD.SELECTED.TAPE          
               		CPA     N8.PRESSED		; verify a control tape?          
               		JMP     VERIFY.CONTROL.TAPE          
               		CPA     N9.PRESSED		; Make a control tape?        
               		JMP     DUPLICATE.CONTROL.TAPE          
               		CPA     GOLD.PRESSED          
               		JMP     ENTER.MENU          
               		JMP     READY.INDICATOR          
J024331        		LDA     KEY.READ          
               		AND     DMS.16K.SEGMENT.LENGTH  ; 20B mask, Test for eot
               		SZA                      
               		JSB     FIX.UP.AFTER.EOT          
               		ISZ     LOOP.COUNTER.1          
               		NOP                      
        		LDA     LOOP.COUNTER.1		;          
               		SSA,RSS                  
               		JSB     KB.EN.&.DRIVE.SEL	; enable keyboard, and select tape drive 
*							; this subroutine is called once every
*							; 30 times past this point         
               		LDA     KEY.READ          
               		AND     MIOB.CONTROL.2          
               		SZA                      
        		LDA     REMOTE.LIGHT.OFF	; Turn off the "REMOTE" light (C024345)          
               		SZA,RSS                  
               		LDA     REMOTE.LIGHT.ON          
               		JSB     MIOB.CONTROL          
               		JMP     READY.IND.2          
*
LOOP.COUNTER.1        	ABS	177742B			;        
CONSTANT.MINUS.30	ABS	-30			; 177742B			;
        
J024354        		JSB     FLASH.RDY.FAST.IOFF
          
*
*-------------------------------------------------------------------------------------------------
*		Generate a "TEST TAPE"			
*-------------------------------------------------------------------------------------------------
*
GENERATE.TEST.TAPE	CLA,RSS				; Clear A reg and skip the next instruction                  
*
*-------------------------------------------------------------------------------------------------
*		Generate a "CONTROL TAPE"	
*-------------------------------------------------------------------------------------------------
*
DUPLICATE.CONTROL.TAPE	LDA     GET.RSS.INSTRUCTION          
               		STA     MODIFIED.CODE.1          
               		JMP     DUPLICATE.LOOP
*
*-------------------------------------------------------------------------------------------------
*		Load memory image from a tape			
*-------------------------------------------------------------------------------------------------
*
LOAD.SELECTED.TAPE	JSB     SET.READ.MODE          
               		JMP     LOAD.CONTROL.SOFTWARE	; Go and load the system control software          
*
*-------------------------------------------------------------------------------------------------
*		Certify a "TEST TAPE"			
*-------------------------------------------------------------------------------------------------
*
CERTIFY.TEST.TAPE	CLA,RSS				; Clear A reg and skip the next instruction               
*
*-------------------------------------------------------------------------------------------------
*		Verify a "CONTROL TAPE"			
*-------------------------------------------------------------------------------------------------
*
VERIFY.CONTROL.TAPE	LDA     GET.RSS.INSTRUCTION          
               		STA     RSS.STORAGE          
               		CLA	                      
               		STA     RECORD.NUMBER.STORAGE          
               		JSB     DO.LIGHT.TEST          
VERIFY.TAPE.1		JSB     SET.READ.MODE          
               		LDA     RSS.STORAGE          
               		STA     NOT.RSS.RD.EXTRA.WORD          
               		LDA     GET.RSS.INSTRUCTION          
               		STA     READ.VERIFY.FUNC.SW	; Saves RSS when verifying tape          
               		JSB     READ.DATA.RECORD          
               		LDA     RECORD.NUMBER.STORAGE          
               		JSB     DISPLAY.RECORD.NUMBER          
               		JSB     CHECK.FOR.SELF.TEST          
               		JMP     VERIFY.TAPE.1
*          
RSS.STORAGE		RSS                      
RECORD.NUMBER.STORAGE   ABS	0B                      
*
*-------------------------------------------------------------------------------------------------
*		Wind tape forward			
*-------------------------------------------------------------------------------------------------
*
MOVE.TAPE.FORWARD	LDA     TAPE.FORWARD		; Set tape control bits for forward motion          
               		RSS                      	; skip next instruction
*
*-------------------------------------------------------------------------------------------------
*		Wind tape back	
*-------------------------------------------------------------------------------------------------
*
MOVE.TAPE.BACK		LDA     TAPE.REVERSE            ; Set tape control bits for reverse motion 
               		JSB     MOVE.TAPE          
               		JMP     J024221
*
*-------------------------------------------------------------------------------------------------
*		Rewind to the start of the tape			
*-------------------------------------------------------------------------------------------------
*
REWIND.TAPE        	JSB     REWIND.WITH.IRG.DISPLAY          
               		JSB     FLASH.READY.FAST
*
*-------------------------------------------------------------------------------------------------*
*		Change the READ threshold (VDAC, this is a combination of FAST & MOD bits)			
*-------------------------------------------------------------------------------------------------
*
CHANGE.READ.THRESHOLD	LDA     READ.THRESHOLD		; Get the read threshold data          
               		XOR     READ.THRESHOLD.MASK	; toggle the threshold          
               		STA     READ.THRESHOLD		; and save the data           
               		JMP     SELECT.TAPE.DRIVE	; no go and select the tape drive
*
*-------------------------------------------------------------------------------------------------
*		Select other drive so if FRONT is selected change to REAR						
*-------------------------------------------------------------------------------------------------
*
SELECT.OTHER.DRIVE	LDA     TAPE.SELECT.FRONT.CW	; get the drive select control word          
               		XOR     TOGGLE.DRIVE		; Toggle the drive select between FRONT/REAR          
               		IOR     TOGGLE.LITE 		; turn on the drive activity light         
               		STA     TAPE.SELECT.FRONT.CW    ; save the new drive select control word      
SELECT.TAPE.DRIVE	LDA     TAPE.SELECT.FRONT.CW          
               		JSB     MOVE.TAPE          
               		JSB     FLASH.READY.FAST          
ENTER.MENU        	JSB     DO.LIGHT.TEST          
               		JSB     FLASH.READY.FAST          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, S024431
*
*
*-------------------------------------------------------------------------------------------------
*
S024431        		ABS	24465B			; On entry there should be an I/O address
*							; normally only the I/O address of MIOB          
               		AND     IO.MASK			; mask off all but the I/O address          
               		IOR     TEMPLATE.STC          	; add on the STC instruction template
               		STA     MIOB.STS.1          	; and save it into the MIOB.STATUS subroutine
               		STA     MIOB.CONTROL.4		; and into the MIOB.CONTROL subroutine          
               		STA     READY.IND.5          
               		XOR     INSTRUCTION.MASK.1         
               		STA     MIOB.CONTROL.5          
               		XOR     INSTRUCTION.MASK.2          
               		STA     MIOB.STS.4          
               		STA     READY.IND.8          
               		XOR     LIGHT.ON.OFF          
               		STA     MIOB.CONTROL.1          
               		STA     READY.IND.4          
               		XOR     MASK.BITS.6.7.8		; this is 700B, bit 7 (200B) will cause an MPUP
*							; I'm guessing this part of the second light test          
               		STA     MIOB.STS.5          
               		STA     READY.IND.9          
               		XOR     MASK.BITS.6.7		; this is 300B, bit 7 (200B) will cause an MPUP          
               		STA     MIOB.CONTROL.3          
               		STA     SET.CTRL.BIT.INS	; I think this changes an OTA to an STC instruction          
               		XOR     MASK.BITS.6.7.8.9          
               		STA     READY.IND.3          
               		JMP     S024431,I        
*
*-------------------------------------------------------------------------------------------------
*		Storage	for the MIOB I/O Address		
*-------------------------------------------------------------------------------------------------
*
MIOB.ADDR		ABS	MIOB.SELECT		; MIOB Address number                     
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, SET.UP.FOR.READ.MODE
*
*		Prepare for a READ from tape			
*-------------------------------------------------------------------------------------------------
*
SET.UP.FOR.READ.MODE	ABS	024005B          
               		STA     TAPE.SELECT.FRONT.CW  	; initially (A REG) = 32000B
*							; to select the front cartridge drive        
               		LDA     MIOB.ADDR		; Get the MIOB address      
               		JSB     S024431          
               		JSB     SET.READ.MODE          
               		LDA     DMS.A0.REGISTER		; The DMS A Latch does not change and is 0          
               		STA     READ.THRESHOLD		; set the read threashold for normal reading                        		
			JMP     SET.UP.FOR.READ.MODE,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, SET.READ.MODE
*
*		Initialise flags for READ MODE, then a change of the 
*		READ.VERIFY.FUNC.SW, can change between READ and VERIFY			
*-------------------------------------------------------------------------------------------------
*
SET.READ.MODE		ABS	024466B          
               		LDA     GET.RSS.INSTRUCTION          
               		STA     MODIFIED.CODE.1          
               		STA     NOT.RSS.RD.EXTRA.WORD          
KEYBOARD.ADDRESS        XOR     A			; This instruction is also used as
*							; comparison data to test for the keyboard
*							; device address                
               		STA     READ.VERIFY.FUNC.SW     ; zero when reading, RSS Ins when verifying
               		STA     MENU.ACTIVE		          
               		STA     KEY.PRESS.COUNT          
               		JMP     SET.READ.MODE,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, DO.LIGHT.TEST
*
*		Performs a light test and hardware reset			
*-------------------------------------------------------------------------------------------------
*
DO.LIGHT.TEST        	ABS	024034B          
               		CLF     0B			; Disable the interrupt system               
               		CLF     5B               	; Clear the parity flag
               		JSB     WAIT.180.MS 		; wait a while         
               		LDA     TAPE.SELECT.FRONT.CW    ; select       
DO.LIGHT.TEST.1		JSB     MIOB.CONTROL          
               		INA                      
               		CPA     END.OF.LIGHT.TEST          
GET.RSS.INSTRUCTION	RSS                      
               		JMP     DO.LIGHT.TEST.1        
               		JSB     MIOB.CONTROL          
               		CLA                      
               		STA     C024635          
               		JMP     DO.LIGHT.TEST,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, KB.EN.&.DRIVE.SEL
*
*		Enable Keyboard and Drive select with delay		
*-------------------------------------------------------------------------------------------------
*
KB.EN.&.DRIVE.SEL       ABS	024565B			          
               		LDA     KEYBOARD.ENABLE.CW      ;     
               		JSB     MIOB.CONTROL          
               		JSB     DRIVE.SELECT.DELAY          
               		JSB     SKIP.NEXT.INSTRUCTION          
               		JSB     FLASH.RDY.SLOW.IOFF          
               		JMP     KB.EN.&.DRIVE.SEL,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, SET.DMS
*
*		This is simple DMS set up routine			
*-------------------------------------------------------------------------------------------------
*
SET.DMS			ABS	025631B          
               		STA     DMS.STORE.1          	
               		AND     PAGE.MASK          
               		CMA,INA				; 2's complement                  
               		ADA     MIOB.CONTROL.2  	; Set flags? as MIOB.CONTROL.2 = 0        
               		STA     DMS.STORE.3          
               		LDA     DMS.16K.SEGMENT.LENGTH  ; (A-reg) <-- 20B, 16k segment length       
               		CMA,INA				; 2's complement, make it -20B                   
               		ADA     DMS.B0.SEG.PAGE.NUMBER  ; now subtract AL from B0        
               		STA     DMS.B0_AL.REGISTER      ; and save the result 
*							; Update the DMS registers   
               		LDA     DMS.A0.POINTER          
               		ABS     105573B			; Set the A and C DMS latches          
               		LDA     DMS.B0_AL.POINTER          
               		ABS     105574B			; Set the B DMS latch          
               		JMP     SET.DMS,I		; Return to caller 
*
*-------------------------------------------------------------------------------------------------
*		Data Storage for simple DMS		
*-------------------------------------------------------------------------------------------------
*
DMS.STORE.1        	ABS	MGEN_ENTRY  		; MGEN start address        
DMS.STORE.2        	ABS	042000B              
DMS.STORE.3        	ABS	1774B         
DMS.A0.POINTER		DEF	*+1          
DMS.A0.REGISTER        	ABS	0B                      
DMS.AL.REGISTER		ABS	20B 			                  
DMS.B0_AL.POINTER	DEF	*+1         
DMS.B0_AL.REGISTER      ABS	177357B        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, REWIND.WITH.IRG.DISPLAY
*
*		REWIND TAPE and display presence/absence of IRG by the state
*		of the REMOTE LIGHT, LIGHT OFF means IRG, LIGHT ON means DATA RECORD			
*-------------------------------------------------------------------------------------------------
*
REWIND.WITH.IRG.DISPLAY	ABS	024043B         
               		ISZ     C024635          
               		LDA     C024635          
               		JSB     DISPLAY.RECORD.NUMBER          
               		LDA     TAPE.REWIND          
REWIND.WITH.IRG.DISP.1	STA     TAPE.REWIND.CW          
               		JSB     KB.EN.&.DRIVE.SEL          
               		JSB     SKIP.NEXT.INSTRUCTION          
               		JMP     REWIND.WITH.IRG.DISPLAY,I 
               		LDA     TAPE.REWIND.CW          ; Rewind the tape
               		JSB     MOVE.TAPE          
               		LDA     TAPE.TRACK.SELECT       ; Get the current tape track selection   
               		XOR     DMS.16K.SEGMENT.LENGTH	; toggle it to the other track          
               		STA     TAPE.TRACK.SELECT	; save the new trackselection data          
REWIND.WITH.IRG.DISP.2	JSB     OP.INPUT.WITH.TAPE          
               		AND     MIOB.CONTROL.2		; Mask for IRG
*							; Zero => REMOTE.LIGHT.OFF
*   							; NON Zero => REMOTE.LIGHT.ON          
               		SZA				                     
               		LDA     REMOTE.LIGHT.ON		; REMOTE light on means, dats record present          
               		SZA,RSS				                   
               		LDA     REMOTE.LIGHT.OFF        ; REMOTE light off means, IRG   
               		JSB     MIOB.CONTROL		; Update the state of the "REMOTE" light          
               		LDA     MIOB.RETURN.STATUS          
               		AND     EOT.OR.MOTOR.ERROR.MASK	; Mask off all but Motor and EOT errors           
               		SZA,RSS				; skip if A-reg not equal to 0                  
               		JMP     REWIND.WITH.IRG.DISP.2          
               		LDA     TAPE.REVERSE		; any errors, then reduce winding speed          
               		JMP     REWIND.WITH.IRG.DISP.1          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, FORWARD.FIXED.AMOUNT
*
*		This moves the tape forward by a fixed distance haven't calculated
*		the distance yet but the tape duplication routine calls this subroutine three
*		times so I would think that this total distance on the tape will be from the
*		EOT hole to the start of data		
*-------------------------------------------------------------------------------------------------
*
FORWARD.FIXED.AMOUNT    ABS	024042B			          
               		JSB     KB.EN.&.DRIVE.SEL	; enable keyboard, and select tape drive          
               		LDA     RUN.LIGHT.ON          
               		JSB     MIOB.CONTROL          
               		LDX     CONSTANT.MINUS.10	; (X-reg) <-- -10         
FORWARD.FIXED.AMOUNT.1  LDB     CONSTANT.MINUS.1000     ; (B-reg) <-- -1000     
FORWARD.FIXED.AMOUNT.2  LDA     TAPE.FORWARD          
               		JSB     MOVE.TAPE          
               		ISZ     B                
               		JMP     FORWARD.FIXED.AMOUNT.2          
               		JSB     OP.INPUT.WITH.TAPE	; check for operator input          
               		AND     TAPE.REVERSE.MASK       ; same as write enable bit   
               		SZA,RSS                  
               		JSB     FLASH.RDY.FAST.IOFF          
               		ISX				; Increment X and skip if zero                      
               		JMP     FORWARD.FIXED.AMOUNT.1          
               		JMP     FORWARD.FIXED.AMOUNT,I 	; Return to caller         

CONSTANT.MINUS.1000     ABS	-1000			; 176030B			
CONSTANT.MINUS.10      	ABS	-10			; 177766B			        
C024635        		ABS     1B               
*
*-------------------------------------------------------------------------------------------------
*		subroutine, OP.INPUT.WITH.TAPE
*
*		Operator Input, while tape is running, This has an interesting
*		mode change mechanism. In the calling routine or the last time
*		the SKIP.NEXT.INSTRUCTION subroutine was called the return address
*		for the caller was saved. In this routine tests are made of the
*		MIOB status if tape status was returned
			
*-------------------------------------------------------------------------------------------------
*
OP.INPUT.WITH.TAPE    	ABS	025722B         
               		STB     OP.INPUT.WITH.TAPE.LTS          
OP.INPUT.2        	JSB     MIOB.STATUS          
               		STA     MIOB.RETURN.STATUS          
               		AND     DEVICE.ADDRESS.MASK          
               		CPA     TAPE.ADDRESS 		; skip if not tape address         
               		JMP     OP.INPUT.CHECK.TAPE	; else, got a tape address          
               		CPA     KEYBOARD.ADDRESS	; skip if not a keyboard address          
               		RSS                      
               		JSB     FLASH.RDY.FAST.IOFF          
               		LDA     MIOB.RETURN.STATUS	; here if keyboard          
               		CPA     GOLD.PRESSED		; GOLD key pressed?          
               		JMP     OP.INPUT.GOLD.KEY			; yes          
               		STA     SAVED.KEY.CODE			; no, save the key         
               		CPA     N9.PRESSED		; 9 key pressed?          
               		RSS                      
               		JMP     OP.INPUT.2		; go and get the status again          
               		LDA     KEY.PRESS.COUNT		; here if it was the 9 key          
               		SZA,RSS                  
               		JMP     OP.INPUT.2		; go and get the status again          
               		STA     MENU.ACTIVE		; flag that menu has been entered          
               		LDA     READY.LIGHT.ON          
               		JSB     MIOB.CONTROL          
               		JMP     OP.INPUT.2		; go and get the status again          
OP.INPUT.GOLD.KEY       ISZ     KEY.PRESS.COUNT          
               		LDA     KEY.PRESS.COUNT          
               		CPA     THREE.PRESSES		; Check for three presses of the GOLD key          
               		JSB     FLASH.READY.FAST          
               		JMP     OP.INPUT.2		; go and get the status again          
OP.INPUT.CHECK.TAPE     LDA     MIOB.RETURN.STATUS          
               		AND     DMS.16K.SEGMENT.LENGTH	; 20B mask          
               		SZA                      	; skip if not EOT, End Of Tape
               		JSB     FIX.UP.AFTER.EOT          
               		LDA     MIOB.RETURN.STATUS          
               		LDB     OP.INPUT.WITH.TAPE.LTS          
               		JMP     OP.INPUT.WITH.TAPE,I 	; Return to caller 
        
MIOB.RETURN.STATUS      ABS	030012B        
OP.INPUT.WITH.TAPE.LTS	ABS	177403B        
THREE.PRESSES	        ABS     3B               
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, SKIP.NEXT.INSTRUCTION
*
*		Skip the next instruction
*
*			The purpose of this subroutine is twofold.
*
*			1.	Initially when called this subroutine will return to P-reg + 2 
*			        rather than P-reg + 1 as with a normal return from subroutine.
*				Effectively the instruction immediately following the calling JSB
*				is skipped.
*			2.	The normal return address of this subroutine is available for
*				use up until a different JSB calls this subroutine. Consequently,
*				this return address can be used as a mode change at some point
*				by returning to the instruction that was originally skipped.	
*-------------------------------------------------------------------------------------------------
*
SKIP.NEXT.INSTRUCTION   ABS	024060B				        
               		LDA     SKIP.NEXT.INSTRUCTION   ; Get the return address
               		INA                      	; increment the return address
               		JMP     A,I              	; jump to the return address
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, FIX.UP.AFTER.EOT
*
*		Fix up tape position after an EOT			
*-------------------------------------------------------------------------------------------------
*
FIX.UP.AFTER.EOT        ABS	024677B				          
               		LDA     TAPE.MOTION.CW          
               		STA     TEMP.TAPE.CW          	; save the control word
               		JSB     DRIVE.SELECT.DELAY     	; stop the drive     
               		LDA     TEMP.TAPE.CW          
               		STA     TAPE.MOTION.CW          
               		LDA     CONSTANT.MINUS.8000     ; Have done a quick timing check and 8000     
               		STA     TEMP.TAPE.CW          	; loops here should be 123mS which for the
FIX.UP.AFTER.EOT.1	LDA     TAPE.MOTION.CW		; tape running at 22ips, that's a distance of          
               		JSB     MIOB.CONTROL          	; 2.7" that tape is moved forward past the
               		ISZ     TEMP.TAPE.CW          	; EOT hole, as the tape would not have 
               		JMP     FIX.UP.AFTER.EOT.1      ; stopped at EOT but a bit beyond it the
*							; hole should be 1" to 1.5" past the sensor
*							; this is close to what actually happens 
               		JSB     DRIVE.SELECT.DELAY      ; stop the drive       
               		LDB     SKIP.NEXT.INSTRUCTION   ; get the last return address from
*       						; SKIP.NEXT.INSTRUCTION 
               		JSB     SKIP.NEXT.INSTRUCTION	; skip the next instruction, and save return
*							; address          
               		JSB     FLASH.RDY.SLOW.IOFF          
               		JMP     B,I			; and return to last caller, usind (B-reg) 						
              
CONSTANT.MINUS.8000	ABS	-8000			; 160300B	      
TEMP.TAPE.CW 		NOP                      
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, MIOB.STATUS
*
*		This routine can be modified prior being called			
*-------------------------------------------------------------------------------------------------
*
MIOB.STATUS		ABS	25730B          
MIOB.STS.1		STC     MIOB.SELECT,C		; Issue a COMMC        
MIOB.STS.2		CLA                      
MIOB.STS.3        	INA,SZA,RSS              
               		JSB     FLASH.RDY.FAST.IOFF          
MIOB.STS.4        	SFS     MIOB.SELECT              
               		JMP     MIOB.STS.3          
MIOB.STS.5        	LIA     MIOB.SELECT  		; Toggles between LIA and SOC            
               		JMP     MIOB.STATUS,I		; Return to caller        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, READ.DATA.RECORD
*
*		This reads a data record from the tape READ or VERIFY			
*-------------------------------------------------------------------------------------------------
*
READ.DATA.RECORD        ABS	024130B			; JMP	J000130          
               		JSB     KB.EN.&.DRIVE.SEL	; enable keyboard, and select tape drive          
               		JSB     TABLE.INITIALISER          
               		JMP     READ.DATA.RECORD.18          
               		LDA     INPUT.LIGHT.ON		; Turn off the "VIEW" ("SHIFT") light           
               		JSB     MIOB.CONTROL          
               		LDA     READ.VERIFY.FUNC.SW	; test for read or verify          
               		SZA                      
               		JMP     READ.DATA.RECORD.1	; here if verify 
*							; here for read          
               		LDA     JUMP.INDEXED.ADR.3	; In memory location 000002 place JMP 3,I         
               		STA     PAGE.ZERO.LOC.2		;           
               		LDA     ADDRESS.OF.LIGHT.TEST   ; The address for the above indirect jump       
               		STA     PAGE.ZERO.LOC.3 	; is the Light test function         
               		LDA     IBL.LOADER.INSTRUCTION	; and in location 000004 the IBL Loader Instruction         
               		STA     PAGE.ZERO.LOC.4         ; 105577B is stored 
READ.DATA.RECORD.1	JSB     DMS.TABLE.UPDATE          
               		STA     C025574          
READ.DATA.RECORD.2	LDA     C025574          
               		LDB     SAVED.KEY.CODE          
               		CPB     SELF.TEST.PRESSED         
               		LDA     RECORD.NUMBER.STORAGE          
               		JSB     DISPLAY.RECORD.NUMBER          
               		LDB     C025574          
               		CMB                      
               		ADB     CONSTANT.64          
               		LDA     DMS.A0.REGISTER 	; (A-reg) <-- 0B, select Track A       
               		SSB     			; skip (B-reg) is a positive number                 
               		LDA     DMS.16K.SEGMENT.LENGTH	; (A-reg) <-- 20B, select Track B         
               		LDB     CONSTANT.64          
               		CPB     CONSTANT.64.2		; skip if not equal          
               		RSS           			; if equal then skip track select update           
               		STA     TAPE.TRACK.SELECT	; save the new track selection data          
               		LDA     READ.DATA.CW		; prepare to read from the tape         
               		JSB     MOVE.TAPE          	; update the tape control 
READ.DATA.RECORD.3	LDA     VIEW.LIGHT.OFF		; Turn off the "VIEW" ("SHIFT") light            
               		JSB     MIOB.CONTROL            ; ready for record checksum test
READ.DATA.RECORD.4	JSB     READ.A.DATA.WORD          
               		LDA     MIOB.RETURN.STATUS          
               		AND     DONT.MASK.IR.ERR0R.MVG          
               		CPA     MIOB.STS.2 		; 2400B          
               		RSS                      	; skip if no error
               		JMP     READ.DATA.RECORD.4      ; loop if there was an MVG error    
               		LDA     REMOTE.LIGHT.OFF	; Turn off the "REMOTE" light          
               		JSB     MIOB.CONTROL          
READ.DATA.RECORD.5	JSB     READ.A.DATA.WORD          
               		LDA     MIOB.RETURN.STATUS          
               		AND     MIOB.CONTROL.2          
               		SZA                      
               		JMP     READ.DATA.RECORD.5          
               		LDA     REMOTE.LIGHT.ON		; Turn on the "REMOTE" light                    
               		JSB     MIOB.CONTROL          
               		LDA     DATA.WORD.TAPE.RD.WR          
               		STA     C025564          
               		STA     B                
               		OTA     FRONT.PANEL.21MX	; This data is seen only if the 21MX 
*							; front panel is connected              
NOT.RSS.RD.EXTRA.WORD	RSS                      
               		JMP     READ.DATA.RECORD.6          
               		JMP     READ.DATA.RECORD.7
*          
READ.DATA.RECORD.6	JSB     READ.A.DATA.WORD	; read a word from the tape          
C025040        		LDA     DATA.WORD.TAPE.RD.WR    ; Place the data in A-reg
               		CPA     CONSTANT.ZERO           ; is the word = 0
               		JMP     READ.DATA.RECORD.6       ; Yes, then read another word   
               		OTA     FRONT.PANEL.21MX	; Else send data to 21MX front panel
*							; panel is not normally connected              
               		ISZ     RECORD.NUMBER.STORAGE   ; increment the record number       
               		LDA     RECORD.NUMBER.STORAGE          
               		JSB     WAS.GOLD.KEY.PRESSED 	; Was the "GOLD" key pressed?         
               		JSB     DISPLAY.RECORD.NUMBER 	; Show the Record Number         
               		JMP     READ.DATA.RECORD.6 
*         
READ.DATA.RECORD.7	JSB     READ.A.DATA.WORD          
               		STA     C025565          
               		JSB     SET.DMS			; Set the DMS latches to shift higher
*							; memory into address space          
               		JSB     READ.A.DATA.WORD          
               		STA     C025566          
               		CMA                      
               		STA     LOCAL.WORD.COUNTER          
               		STB     C025570          
               		JSB     READ.A.DATA.WORD          
               		STA     C025567          
               		LDA     MIOB.RETURN.STATUS          
               		AND     MIOB.CONTROL.2          
               		SZA                      
               		JSB     S025206          
               		LDA     DATA.WORD.TAPE.RD.WR          
               		CPA     C025570          
               		JMP     READ.DATA.RECORD.8          
               		LDA     C025454          
               		SSA                      
               		JMP     READ.DATA.RECORD.2          
               		JSB     S025206          		
READ.DATA.RECORD.8	LDA     VIEW.LIGHT.ON		; Turn on the "VIEW" (5420)/"SHIFT" (5423) light       
               		JSB     MIOB.CONTROL          
               		LDA     C025564          
               		CPA     C025574          
               		JMP     READ.DATA.RECORD.16          
               		CPA     C025455          
               		RSS                      
               		JMP     READ.DATA.RECORD.9          
               		LDA     C025574          
               		JSB     S025433          
               		JSB     DMS.TABLE.UPDATE          
               		STA     C025574          
               		JMP     READ.DATA.RECORD.16          
READ.DATA.RECORD.9	CPA     CONSTANT.MINUS.257          
               		RSS                      
               		JMP     READ.DATA.RECORD.2          
               		LDA     C025565          
               		CPA     CONSTANT.24000B          
               		JSB     REWIND.WITH.IRG.DISPLAY          
               		JMP     READ.DATA.RECORD.2          
READ.DATA.RECORD.10	LDA     READ.VERIFY.FUNC.SW          
               		SZA                      
               		JMP     READ.DATA.RECORD.14	; here for verify          
               		LDA     DMS.STORE.1		; here for read          
               		CPA     DMS.STORE.2          
               		JSB     S025206          
               		CPA     READ.THRESHOLD.MASK	; is function code = 2?          
               		JMP     READ.DATA.RECORD.11          
               		CPA     CONSTANT.3		; is function code = 3?          
               		JMP     READ.DATA.RECORD.12          
               		CPA     CONSTANT.4		; is function code = 4?          
               		JMP     READ.DATA.RECORD.13          
               		JMP     READ.DATA.RECORD.14 
         
READ.DATA.RECORD.11	JSB     READ.A.DATA.WORD          
               		STA     TEMP.INSTRUCTION.1          
               		JMP     READ.DATA.RECORD.15          
READ.DATA.RECORD.12	JSB     READ.A.DATA.WORD          
               		STA     TEMP.INSTRUCTION.2          
               		JMP     READ.DATA.RECORD.15
          
READ.DATA.RECORD.13	JSB     READ.A.DATA.WORD          
               		STA     TEMP.INSTRUCTION.3          
               		JMP     READ.DATA.RECORD.15
          
READ.DATA.RECORD.14	LDA     DMS.STORE.1,I        
               		CMA                      
               		STA     DMS.STORE.1,I        
               		LDA     DMS.STORE.1,I        
               		CMA                      
               		STA     DMS.STORE.1,I        
               		JSB     READ.A.DATA.WORD          
READ.VERIFY.FUNC.SW     NOP				; if verify, an RSS is here 
*			 				; to skip the STA                   
               		STA     DMS.STORE.1,I        
               		CPA     DMS.STORE.1,I        
               		RSS                      
               		JMP     READ.DATA.RECORD.17          
READ.DATA.RECORD.15	LDA     MIOB.RETURN.STATUS          
               		AND     DONT.MASK.IR.ERR0R.MVG          
               		SZA				; skip of no error or IRG                      
               		JMP     READ.DATA.RECORD.3          
               		ISZ	DMS.STORE.1          
READ.DATA.RECORD.16	ISZ     LOCAL.WORD.COUNTER          
               		JMP     READ.DATA.RECORD.10          
               		STB     CHECKSUM.STORAGE          
               		JSB     READ.A.DATA.WORD          
               		LDB     CHECKSUM.STORAGE          
               		CPA     B                
               		RSS                      
               		JSB     S025206          
               		JSB     READ.A.DATA.WORD          
               		LDB     CONSTANT.100000B          
               		CPA     B                
               		JMP     READ.DATA.RECORD.1          
               		JSB     S025206          
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, S025206
*
*			
*-------------------------------------------------------------------------------------------------
*
S025206        		NOP                      
               		LDA     C025574          
               		LDB     READ.VERIFY.FUNC.SW	; Were we READing or VERIFYing?          
               		SZB,RSS				; skip if VERIFY                  
               		JSB     S025433          	; here if were in READ mode
               		CCA				; Set all of the record number bits				;                       
               		JSB     DISPLAY.RECORD.NUMBER	; display the record number          
               		LDA     S025206          
               		JSB     WAS.GOLD.KEY.PRESSED 	; Was the "GOLD" key pressed?            
               		JMP     READ.DATA.RECORD.1
          
READ.DATA.RECORD.17	LDA     READ.VERIFY.FUNC.SW          
               		ISZ     RECORD.NUMBER.STORAGE          
               		SZA                      
               		JSB     S025206          
               		JMP     LIGHT.TEST.LOOP		; Exit to a light test          
READ.DATA.RECORD.18	LDA     READ.VERIFY.FUNC.SW          
               		SZA                      
               		JMP     READ.DATA.RECORD,I 
       
               		LDA     TEMP.INSTRUCTION.1          
               		STA     PAGE.ZERO.LOC.2 	;          
               		LDA     TEMP.INSTRUCTION.2          
               		STA     PAGE.ZERO.LOC.3          
               		LDA     TEMP.INSTRUCTION.3          
               		STA     PAGE.ZERO.LOC.4          
               		JMP     READ.DATA.RECORD,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, READ.A.DATA.WORD
*
*		Read a data word routine with the checksum held in B-reg, the data word is in 
*		A-reg and saved to DATA.WORD.TAPE.RD.WR		
*-------------------------------------------------------------------------------------------------
*
READ.A.DATA.WORD        ABS	025202B       
               		JSB     OP.INPUT.WITH.TAPE          
               		AND     EOT.OR.MOTOR.ERROR.MASK	; EOT & Motor Error mask used but
*							; this must check if the operator keys
*							; are enabled, if so "READY" light flashes          
               		SZA				; Skip if A-reg is zero                      
               		JSB     FLASH.RDY.FAST.IOFF        ; Else, flash the "READY" light  
			JSB     MIOB.STATUS		; Get MIOB status / data          
               		STA     DATA.WORD.TAPE.RD.WR          
               		ADB     A			; update the checksum                
               		JMP     READ.A.DATA.WORD,I 	; Return to caller               
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, MIOB.CONTROL
*
*		Send MIOB Control Word, on entry control word is in A-reg	
*-------------------------------------------------------------------------------------------------
*
*		Looks like this routine potentially is modified before it is called
*
MIOB.CONTROL		ABS	025301B      
MIOB.CONTROL.1		SFC     MIOB.SELECT     	; Switch MIOB to Control Mode         
MIOB.CONTROL.2		ABS	2000B                      
MIOB.CONTROL.3		OTA	MIOB.SELECT  		; Send the command            
MIOB.CONTROL.4		STC	MIOB.SELECT,C        	; Issue a COMMC       
MIOB.CONTROL.5		CLC	MIOB.SELECT          	; Set DATA Mode    
			JMP	MIOB.CONTROL,I		; Return to caller        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, MOVE.TAPE
*
*		On entry the base control word is on A-reg and this routine adds on
*		both the track selection, and threshold bits before issuing the CW 
*		Then a new control word is set up ready to reverse the tape direction
*		but depending on the (A-reg) on next entry may or may not be used.
*		Next the track select data is used to update the "A" and "B" lights, so
*		for track A "A" light is on and for track B "B" light is on. 			
*		Finally, check the READ THRESHOLD status and use it to update the 
*		"UPR/LWR" light. 			
*-------------------------------------------------------------------------------------------------
*
MOVE.TAPE        	ABS	025651B			         
               		IOR     TAPE.TRACK.SELECT       ; add on the track selection bit   
               		IOR     READ.THRESHOLD       	; add on the read threshold bit   
               		JSB     MIOB.CONTROL          	; send the control word
               		AND     TAPE.REVERSE.MASK	; Mask off all but tape reverse bit          
               		XOR     TAPE.REVERSE.MASK 	; Toggle the reverse bit         
               		IOR     TAPE.FORWARD		; add on all of the other control bis          
               		STA     TAPE.MOTION.CW          
               		LDA     TAPE.TRACK.SELECT 	; Get the tape track select bit         
               		RAL,RAL           		; shift left twice, makes light on/off bit       
               		IOR     B.LIGHT.CW          	; add on the base "B" light control word
               		JSB     MIOB.CONTROL            ; update the "B" light
               		XOR     A.LIGHT.TOGGLE          ; This changes the control word from
*							; "B" to "A" light and toggles the light
               		JSB     MIOB.CONTROL		; update the "B" "A" light          
			LDA     READ.THRESHOLD          ; Get the current READ THRESHOLD status
               		ALF,RAL                  	; shift it to light on/off bit position
               		IOR     UPR/LWR.LIGHT.CW 	; add on the "UPR/LWR" light control word         
               		JSB     MIOB.CONTROL            ; update the "UPR/LWR" light
               		JMP     MOVE.TAPE,I		; Return to caller        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, DRIVE.SELECT.DELAY
*
*		Wait for 180mS, then select the FRONT tape drive and update the track
*		and read threshold lights, then wait a further 180mS		
*-------------------------------------------------------------------------------------------------
*
DRIVE.SELECT.DELAY      ABS	024726B				        
               		JSB     WAIT.180.MS			; Wait for 180mS          
               		LDA     TAPE.SELECT.FRONT.CW          
               		JSB     MOVE.TAPE          
               		LDA     TAPE.SELECT.FRONT.CW          
               		STA     TAPE.MOTION.CW          
               		JSB     WAIT.180.MS 			; Wait for 180mS         
               		JMP     DRIVE.SELECT.DELAY,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, WAIT.180.MS
*
*		Wait 180mS (2.765uS * 65536 = 181.2mS)			
*-------------------------------------------------------------------------------------------------
*
WAIT.180.MS		ABS	025311B          
               		CLB					; clear B-reg                      
WAIT.180.MS.2        	ISZ     B                		; increment B-reg and skip if zero
               		JMP     WAIT.180.MS.2        		; else loop till done
               		JMP     WAIT.180.MS,I			; Return to caller        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, DISPLAY.RECORD.NUMBER
*
*		Display Record Number (sucessfully loaded)		
*-------------------------------------------------------------------------------------------------
*
DISPLAY.RECORD.NUMBER	ABS	025637B          
               		STA     RECORD.NUMBER.TS		; save the current record number
               		JSB     UPDATE.DATA.BIT			; Update LINEAR LIGHT
			ABS	KEYBOARD.DEVICE+LINEAR.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update HIST LIGHT
			ABS	KEYBOARD.DEVICE+HIST.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update CROSS LIGHT
			ABS	KEYBOARD.DEVICE+CROSS.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update AUTO LIGHT
			ABS	KEYBOARD.DEVICE+AUTO.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update COHER LIGHT
			ABS	KEYBOARD.DEVICE+COHER.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update TRANS LIGHT
			ABS	KEYBOARD.DEVICE+TRANS.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update X LIGHT
			ABS	KEYBOARD.DEVICE+X.LIGHT
               		JSB     UPDATE.DATA.BIT			; Update Y LIGHT
			ABS	KEYBOARD.DEVICE+Y.LIGHT
               		JMP     DISPLAY.RECORD.NUMBER,I 	; Return to caller       
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, UPDATE.DATA.BIT
*
* 		Update data bit (measurement lights for record count and X / Y for errors)			
*-------------------------------------------------------------------------------------------------
*
UPDATE.DATA.BIT		ABS	025341B         
               		LDB     RECORD.NUMBER.TS		; Place the record number data in B reg          
               		LDA     UPDATE.DATA.BIT,I		; return address points to MIOB Control 
*								; word for the light being updated        
               		SLB,RBR					; test for light on, the rotate next bit
*								; into bit 0. If light to be off 
*								; skip next       
               		XOR     LIGHT.ON.OFF			; else toggle the light control bit to on          
               		STB     RECORD.NUMBER.TS		; save the data          
               		JSB     MIOB.CONTROL			; send out the control word to the MIOB          
               		ISZ     UPDATE.DATA.BIT			; Increment the return address          
               		JMP     UPDATE.DATA.BIT,I        	; and return to caller
*
RECORD.NUMBER.TS	ABS	177403B				; record number temporary storage       
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, CHKS.TABLE.INIT
*
*		This is an initialisation routine, I'm not 100% sure what this
*		does, but I suspect that initialises a table where the checksum status
*		of the records that been read is stored. 		
*-------------------------------------------------------------------------------------------------
*
CHKS.TABLE.INIT        	ABS	025377B				;         
               		LDA     CONSTANT.64.2			; A-reg <-- 64          
               		CMA,INA 				; A-reg <-- -64                 
C025357        		STA     C025454 			; (C025454) <-- A-reg         
               		LDA     CONSTANT.0			; A-reg <-- 0          
               		STA     C025455				; (C025455) <-- A-reg          
               		LDA     TABLE.START          		; A-reg <-- 025762B
               		ALF,ALF  				; Shift left six times                
               		RAR,RAR					; A-reg <-- 176212B                  
               		AND     IO.MASK				; A-reg <-- 000012B <-- A-reg AND 000077B				          
               		STA     C025457				; (C025457) <-- A-reg          
               		LDA     TABLE.START          		; A-reg <-- 025762B
               		STA     CHKS.TABLE.POINTER		; (CHKS.TABLE.POINTER) <-- A-reg          
               		STA     DMS.TABLE.POINTER		; (DMS.TABLE.POINTER) <-- A-reg          
               		CLA 					; A-reg <-- 0                      
               		STA     TABLE.COUNTER			; (TABLE.COUNTER) <-- A-reg          
               		JMP     CHKS.TABLE.INIT,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, TABLE.INITIALISER
*
*		I think this Initialises a table which has pointers to the record numbers
*		or pointers to record numbers for records where the checksum did not verify
*		apart from calling a table initialise routine this routine has the
*		same type operation as SKIP.NEXT.INSTRUCTION, see that subroutine for
*		an explanation of its operation.
*-------------------------------------------------------------------------------------------------
*
TABLE.INITIALISER       ABS	024056B				  
               		JSB     CHKS.TABLE.INIT          
C025377        		LDA     TABLE.INITIALISER		; get the return address          
               		INA 					; increment it                     
               		JMP     A,I				; and return to caller
*								; return address + 1              
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, DMS.TABLE.UPDATE
*
*		I think this accesses a table which has pointers to the DMS
*		values required to save to and read from memory the data in each record		
*-------------------------------------------------------------------------------------------------
*
DMS.TABLE.UPDATE	ABS	024765B				; JMP     J000765          
DMS.TABLE.UPDATE.1	LDA     C025454          
               		SSA,INA,RSS				; skip if A-reg is negative then inc A-reg              
               		JMP     DMS.TABLE.UPDATE.2		; here if A-reg is positive          
               		STA     C025454				; save A-reg          
               		LDA     C025455          
               		ISZ     C025455          
               		JMP     DMS.TABLE.UPDATE.3          
DMS.TABLE.UPDATE.2	LDA     DMS.TABLE.POINTER,I        
               		STA     DMS.B0.SEG.PAGE.NUMBER          
               		ISZ     DMS.TABLE.POINTER          
               		LDA     DMS.TABLE.POINTER          
               		CPA     TABLE.END          
               		LDA     TABLE.START          
               		STA     DMS.TABLE.POINTER          
               		LDA     TABLE.COUNTER			; A-reg <-- TABLE.COUNTER          
               		SZA,RSS					; test for A-reg = 0 and skip if non-zero                 
               		JMP     TABLE.INITIALISER,I
        
               		ADA     CONSTANT.MINUS.1		; decrement A-reg          
               		STA     TABLE.COUNTER  			; TABLE.COUNTER <-- A-reg        
               		LDA     DMS.B0.SEG.PAGE.NUMBER          
DMS.TABLE.UPDATE.3	STA     DMS.B0.SEG.PAGE.NUMBER          
               		CPA     C025457          
               		JMP     DMS.TABLE.UPDATE.1          
               		JMP     DMS.TABLE.UPDATE,I        
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, S025433
*
*		I think this Initialises a table which holds the record numbers or
*		pointers to record numbers for records where the checksum did not verify
*		and these records are re-read till the checksum is good.
*-------------------------------------------------------------------------------------------------
*
S025433        		ABS	0B                      
               		STA     CHKS.TABLE.POINTER,I		; store A to memory pointed to by (C02446)       
               		ISZ     CHKS.TABLE.POINTER		; increment the pointer (C02446)          
               		LDA     CHKS.TABLE.POINTER		; A-reg <-- pointer (C02446)          	
               		CPA     TABLE.END			; is the pointer = 25776B          
               		LDA     TABLE.START			; yes, the A-reg <-- 25762B          
               		STA     CHKS.TABLE.POINTER          	; save the pointer
               		ISZ     TABLE.COUNTER			; increment the counter          
               		CPA     CONSTANT.14B		;           
               		JSB     FLASH.READY.SLOW          
               		JMP     S025433,I        
*
*-------------------------------------------------------------------------------------------------
*		Data Storage Area
*-------------------------------------------------------------------------------------------------
*
CHKS.TABLE.POINTER	ABS	025762B		         
DMS.TABLE.POINTER	ABS	025762B		          
TABLE.START		ABS	025762B		         
TABLE.END		ABS	025776B		        
TABLE.COUNTER		ABS	0B		; NOP                      
CONSTANT.14B        	ABS	14B
                     
C025454       		ABS	177700B      
C025455        		ABS	0B		; NOP                      
CONSTANT.0        	ABS	0B		; NOP                      
C025457        		ABS	12B                      
END.OF.LIGHT.TEST       ABS	027600B          
REMOTE.LIGHT.ON		ABS	KEYBOARD.DEVICE+REMOTE.LIGHT+ON
REMOTE.LIGHT.OFF        ABS	KEYBOARD.DEVICE+REMOTE.LIGHT+OFF
RUN.LIGHT.ON        	ABS	KEYBOARD.DEVICE+RUN.LIGHT+ON
INPUT.LIGHT.ON		ABS	KEYBOARD.DEVICE+INPUT.LIGHT+ON
INPUT.LIGHT.OFF		ABS	KEYBOARD.DEVICE+INPUT.LIGHT+OFF
READY.LIGHT.CW		ABS	KEYBOARD.DEVICE+READY.LIGHT+OFF
VIEW.LIGHT.ON		ABS	KEYBOARD.DEVICE+VIEW.LIGHT+ON
VIEW.LIGHT.OFF		ABS	KEYBOARD.DEVICE+VIEW.LIGHT+OFF
READY.LIGHT.ON		ABS	KEYBOARD.DEVICE+READY.LIGHT+ON
READY.LIGHT.OFF         ABS	KEYBOARD.DEVICE+READY.LIGHT+OFF
               		ABS	020136B          
B.LIGHT.CW		ABS	KEYBOARD.DEVICE+B.LIGHT          
UPR/LWR.LIGHT.CW	ABS	KEYBOARD.DEVICE+UPR/LWR.LIGHT       
KEYBOARD.ENABLE.CW      ABS	KEYBOARD.DEVICE+ON+KBD.ENABLE	; Enable keyboard      
DOT.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+DOT.KEY
N0.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N0.KEY
N1.PRESSED		ABS	KEYBOARD.DEVICE+N1.KEY    
N2.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N2.KEY
N3.PRESSED		ABS	KEYBOARD.DEVICE+N3.KEY         
N4.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N4.KEY       
N5.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N5.KEY      
N6.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N6.KEY
N7.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N7.KEY
N8.PRESSED		ABS	KEYBOARD.DEVICE+FIRST.PRESS+N8.KEY        
N9.PRESSED        	ABS	KEYBOARD.DEVICE+N9.KEY

			IFZ          
GOLD.PRESSED        	ABS	KEYBOARD.DEVICE+FIRST.PRESS+KEY.ON.5441A+GOLD.KEY
			XIF

			IFN
GOLD.PRESSED        	ABS	KEYBOARD.DEVICE+FIRST.PRESS+KEY.ON.5441A+SHIFT.KEY
			XIF
       
SELF.TEST.PRESSED       ABS	KEYBOARD.DEVICE+SELF.TEST.KEY	; 020001B                
GOLD.KEY.TEST        	ABS	KEYBOARD.DEVICE+GOLD.KEY	; 020072B         
SAVED.KEY.CODE        	ABS	KEYBOARD.DEVICE+AUTO.KEY	; 020035B          
MENU.ACTIVE        	ABS     1B               
KEY.PRESS.COUNT        	ABS	0B                      
TAPE.SELECT.FRONT	ABS	TAPE.DEVICE+SELECT+FRONT+LITE           
TAPE.SELECT.FRONT.CW	ABS	TAPE.DEVICE+SELECT+FRONT+LITE         
TAPE.REWIND		ABS	TAPE.DEVICE+BIT+RUN+LITE+REVERSE+FAST        
TAPE.REWIND.CW		ABS	TAPE.DEVICE+BIT+RUN+LITE+REVERSE+FAST
TAPE.REVERSE        	ABS	TAPE.DEVICE+BIT+RUN+LITE+REVERSE
TAPE.FORWARD		ABS	TAPE.DEVICE+BIT+RUN+LITE       
TAPE.MOTION.CW        	ABS	TAPE.DEVICE+BIT+RUN+LITE+REVERSE          
READ.DATA.CW      	ABS	TAPE.DEVICE+READ+RUN+LITE       ; Read Data Control Word
WRITE.IRG.CW        	ABS	TAPE.DEVICE+WRITE+BIT+RUN+LITE	; Write IRG Control Word          
WRITE.DATA.CW        	ABS	TAPE.DEVICE+WRITE+RUN+LITE	; Write Data Control Word          
DMS.16K.SEGMENT.LENGTH	ABS	20B				; DMS 16k comparison point                      
TAPE.TRACK.SELECT	ABS	0B                      
READ.THRESHOLD        	ABS	0B                      
EOT.OR.MOTOR.ERROR.MASK ABS	MERR+CEOT                 
TAPE.REVERSE.MASK	ABS	REVERSE                     
LIGHT.ON.OFF        	ABS	ON                       
TAPE.ADDRESS        	ABS	TAPE.DEVICE              
CONSTANT.16384        	ABS	16384				; 040000B                
TEMPLATE.STC        	STC     0B,C				; template code for STC              
DEVICE.ADDRESS.MASK	ABS	170000B				; this mask removes all but the 
*								; MIOB device addresses               
CONSTANT.MINUS.1        ABS	-1       
READ.THRESHOLD.MASK     ABS     MOD				; VDAC READ THRESHOLD               
CONSTANT.3        	ABS     3B               
CONSTANT.4        	ABS     4B               
               		ABS	14B                      
TOGGLE.LITE		ABS	LITE                     
IO.MASK        		ABS	77B				; I/O address mask           
A.LIGHT.TOGGLE		ABS	102B                                 
MASK.BITS.6.7 		ABS	300B                                
MASK.BITS.6.7.8		ABS	700B                                 
TOGGLE.DRIVE		ABS	CARTOFF                      
MASK.BITS.6.7.8.9       ABS	1700B                      
PAGE.MASK        	ABS	1777B				; MASK to maximum number of 1024 
*								; word pages allowed         
INSTRUCTION.MASK.2	ABS	4400B                                 
INSTRUCTION.MASK.1	ABS	5000B                      
MIOB.TEST.TC        	ABS	177773B       
C025564       		ABS	77B             
C025565        		ABS	040000B                
C025566        		ABS	2000B				; Work like a NOP                      
C025567        		ABS     042077B          
C025570        		ABS     042077B          
CHECKSUM.STORAGE        ABS	057011B        
LOCAL.WORD.COUNTER	ABS	177572B        
WRITE.DATA.MEMORY.PTR   ABS	025573B         
C025574        		ABS	77B              
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, WRITE.FOUR.DATA.RECORDS
*
*		Write four data records to tape, these blocks of four records are separated 
*		by an IRG of four times	the length of the IRG which separates individual 
*		records within a block. 
*-------------------------------------------------------------------------------------------------
*
WRITE.FOUR.DATA.RECORDS	ABS	024064B	          
               		LDA     IRG.LONG.TC          
               		STA     IRG.COUNT          
J025600        		LDA     INSTRUCTION.SOURCE.1	; Make a copy of four instrictions and          
               		STA     INSTRUCTION.DEST.1	; place them in the first four memory
		        LDA     INSTRUCTION.SOURCE.2	; locations of the page used by MGEN         
               		STA     INSTRUCTION.DEST.2			             
               		LDA     INSTRUCTION.SOURCE.3          
               		STA     INSTRUCTION.DEST.3          
               		LDA     INSTRUCTION.SOURCE.4          
               		STA     INSTRUCTION.DEST.4          
               		LDA     CONSTANT.MINUS.257          
               		STA     DMS.B0.SEG.PAGE.NUMBER          
               		LDA     WRITE.FOUR.DATA.RECORDS,I        
               		JSB     WRITE.A.RECORD.TO.TAPE          
               		ISZ     RECORD.NUMBER.STORE.WR	; Increment Record Number
               		JSB     WRITE.A.RECORD.TO.TAPE          
               		ISZ     RECORD.NUMBER.STORE.WR	; Increment Record Number 
               		JSB     WRITE.A.RECORD.TO.TAPE          
               		ISZ     RECORD.NUMBER.STORE.WR  ; Increment Record Number
               		JSB     WRITE.A.RECORD.TO.TAPE          
               		ISZ     RECORD.NUMBER.STORE.WR	; Increment Record Number 
               		LDA     IRG.LONG.TC          
               		STA     IRG.COUNT          
               		ISZ     WRITE.FOUR.DATA.RECORDS          
               		JMP     WRITE.FOUR.DATA.RECORDS,I ; Return to caller         
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, WRITE.A.RECORD.TO.TAPE
*
*		Write a record to tape (control tape duplication process)
*
*		Data format of a record is:
*
*		Word #1		000000
*		Word #2		000000
*		Word #3		000001
*		Word #4		RRRRRR	Record identifier -257 for MGEN, other values to set DMS
*		Word #5		SSSSSS  Start address
*		Word #6         CCCCCC  Word Count (Number of data words)
*		Word #7		XXXXXX  Header Checksum
*		Word #8		DDDDDD  1st data word
*		  |                |
*		Word #8+n-1     DDDDDD  nth data word
*		Word #8+n	XXXXXX  Data Checksum
*		Word #8+n+1	100000
*		Word #8+n+2	000000
*-------------------------------------------------------------------------------------------------
*
WRITE.A.RECORD.TO.TAPE  ABS	025614B          
               		JSB     SET.DMS			; Set the DMS latches to shift higher 
*							; memory into address space          
               		LDA     MODIFIED.CODE.1		; For normal operation an RSS instruction          
               		STA     WRITE.A.REC.TO.TAPE.3	; is saved when a NOP is saved then we are 
*							; writing a test tape          
               		LDA     DMS.B0.SEG.PAGE.NUMBER          
               		SSA				; skip if (A-reg) is positive                      
               		LDA     RECORD.NUMBER.STORE.WR	; Get Record Number (duplication mode)          
               		JSB     DISPLAY.RECORD.NUMBER	; Display the next record number          
               		JSB     WRITE.IRG          	; write the inter-record gep
               		LDA     REMOTE.LIGHT.ON 	; IRG complete, turn on the "REMOTE" light         
               		JSB     MIOB.CONTROL            ; send the MIOB control word
               		LDA     DMS.B0.SEG.PAGE.NUMBER          
               		AND     LIGHT.ON.OFF		; Mask all but the light on/off bit          
               		XOR     LIGHT.ON.OFF            ; toggle the light on/off bit
               		IOR     VIEW.LIGHT.OFF          ; add the "VIEW"/"SHIFT" light control bits
               		JSB     MIOB.CONTROL            ; send the MIOB control word
               		LDA     WRITE.DATA.CW		; Set up to write data          
               		JSB     MOVE.TAPE          
               		CLA 				                     
               		JSB     WRITE.DATA.TO.TAPE	; Write 000000B          
               		JSB     WRITE.DATA.TO.TAPE      ; write 000000B    
               		LDA     CONSTANT.1B          
               		JSB     WRITE.DATA.TO.TAPE 	; Write 000001B         
WRITE.A.REC.TO.TAPE.2   LDA     DMS.B0.SEG.PAGE.NUMBER          
               		JSB     WRITE.DATA.TO.TAPE 	; first time through (A-reg) = -257 MGEN 
*							; record type       
               		STA     CHECKSUM.STORAGE          
WRITE.A.REC.TO.TAPE.3   RSS				; when changed to a NOP then a countinuous
*							; write the data in DMS.B0.SEG.PAGE.NUMBER 
*							; will occur, this is when a test tape is 
*							; generated                   
               		JMP     WRITE.A.REC.TO.TAPE.2          
               		LDA     DMS.STORE.1          
               		JSB     WRITE.DATA.TO.TAPE 	; Write  (start address)        
               		LDA     DMS.STORE.3          
               		JSB     WRITE.DATA.TO.TAPE 	; Write  (word count)        
               		LDA     CHECKSUM.STORAGE          
               		JSB     WRITE.DATA.TO.TAPE 	; Write the header Checksum to tape      
               		LDA     DMS.STORE.3          
               		CMA,INA,SZA,RSS			; If word count <> 0 then skip          
               		JMP     WRITE.A.REC.TO.TAPE.5 	; else, don't write data to the tape         
               		STA     LOCAL.WORD.COUNTER	; save the word count          
               		LDA     DMS.STORE.1          
               		STA     WRITE.DATA.MEMORY.PTR	; (WRITE.DATA.MEMORY.PTR) <-- Memory pointer
*
*-------------------------------------------------------------------------------------------------
*		Write data to tape here
*-------------------------------------------------------------------------------------------------
*         
WRITE.A.REC.TO.TAPE.4	LDA     WRITE.DATA.MEMORY.PTR,I	; (A-reg) <-- (Memory)        
        		JSB     WRITE.DATA.TO.TAPE	; Write a data word  (C025700)        
               		ISZ     WRITE.DATA.MEMORY.PTR	; increment          
               		ISZ     LOCAL.WORD.COUNTER	; increment the word count          
               		JMP     WRITE.A.REC.TO.TAPE.4          
WRITE.A.REC.TO.TAPE.5	LDA     CHECKSUM.STORAGE          
               		JSB     WRITE.DATA.TO.TAPE      ; Write the checksum on data to tape      
               		LDA     CONSTANT.100000B	        
              		JSB     WRITE.DATA.TO.TAPE      ; Write 100000B      
               		CLA                      
               		JSB     WRITE.DATA.TO.TAPE	; Write 000000B          
               		JSB     WRITE.IRG          
               		LDA     DMS.STORE.1          
               		JMP     WRITE.A.RECORD.TO.TAPE,I ; Return to caller         
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, WRITE.DATA.TO.TAPE
*
*		Write a data word to tape
*
*		On Entry, the word to be written is in A-reg			
*-------------------------------------------------------------------------------------------------
*
WRITE.DATA.TO.TAPE	ABS	025701B			;          
               		STA     DATA.WORD.TAPE.RD.WR    ; save the data      
               		ADA     CHECKSUM.STORAGE	; Add it to current checksum value         
               		STA     CHECKSUM.STORAGE        ; and save the checksum 
               		JSB     OP.INPUT.WITH.TAPE          
               		AND     TAPE.REVERSE.MASK          
               		SZA,RSS                  	; skip "READY" light does not need updating
               		JSB     FLASH.RDY.FAST.IOFF	; else, flash the "READY" light  
               		LDA     DATA.WORD.TAPE.RD.WR    ; restore the orgininal data      
SET.CTRL.BIT.INS	OTA     MIOB.SELECT        	; Send the word      
               		JSB     MIOB.STATUS             ; check MIOB status
               		LDA     DATA.WORD.TAPE.RD.WR    ; restore the data once again      
               		JMP     WRITE.DATA.TO.TAPE,I 	; Return to caller         
*
*-------------------------------------------------------------------------------------------------
*		Subroutine, WRITE.IRG
*
*		Indicate we are writing an inter-record gap (IRG)			
*-------------------------------------------------------------------------------------------------
*
WRITE.IRG        	ABS	025640B			          
               		LDA     REMOTE.LIGHT.OFF	; turn off "REMOTE" light          
               		JSB     MIOB.CONTROL          
               		LDA     VIEW.LIGHT.OFF		; Turn off "VIEW" / "SHIFT" light          
               		JSB     MIOB.CONTROL          
               		LDA     WRITE.IRG.CW		; Get write IRG control word          
               		JSB     MOVE.TAPE          	; Write tape control reg
WRITE.IRG.1        	JSB     MIOB.STATUS          
	       		ISZ     IRG.COUNT		; increment the IRG Count, skip if zero          
               		JMP     WRITE.IRG.1          	; else, loop back to check the tape status
               		LDA     IRG.STANDARD.TC		; initalise the IRG length for next time          
               		STA     IRG.COUNT          	
               		JMP     WRITE.IRG,I 		; Return to caller 
*
*-------------------------------------------------------------------------------------------------
*		Data Storage Area
*-------------------------------------------------------------------------------------------------
*
IRG.LONG.TC        	ABS	-3182			; Time constant for the long IRG       
IRG.STANDARD.TC        	ABS	-795			; Time constant for the standard IRG      
IRG.COUNT        	ABS	176345B			; This is storage for IRG length counter        
DATA.WORD.TAPE.RD.WR    ABS	176345B			;        
CONSTANT.MINUS.257      ABS	-257			; 177377B       
CONSTANT.ZERO        	ABS	0B				                      
DMS.B0.SEG.PAGE.NUMBER  ABS	177377B			;      
CONSTANT.24000B        	ABS	024000B			;                 
CONSTANT.1B        	ABS     1B               
CONSTANT.100000B        ABS     100000B          
IBL.LOADER.INSTRUCTION	ABS     105577B			; This is the IBL Loader instruction          
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                     
C025766        		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
C025773       		ABS	0B			; NOP                     
               		ABS	0B			; NOP                      
               		ABS	0B			; NOP                      
CONSTANT.64		ABS	100B                                 
CONSTANT.64.2		ABS	100B
*
			END
                                 
