; last edited March 19, 1981  4:41 PM
;         SYSTEM    LCC
;         TITLE     '2600  CONTROL PROGRAM 29JUN79'
;        B3 ROM SOURCE FILE.
;        INCLUDES TIMING CHANGES FOR THE MOHAWK POWER SUPPLY.
;        REGISTER ASSIGNMENTS
;
;L0  MASTER COUNTER LSB             L8 MOTION SENSOR CTR
;L1  MASTER COUNTER MSB             L9   FLAGS
;L2  E COUNTER                      L10 X CTR
;L3  LF COUNTER                     L11  TEMPORARY REG (STATE 6)
;L4  PROGRAM COUNTER                L12 FUSER CNTR
;L5  WATCHDOG TIMER                 L13  INPUT BYTE
;L6  STATE COUNTER                  L14  INPUT BYTE
;L7  COUNTER INSTRUCTIONS  & FLAGS  L15  OUTPUT BYTE
;
;
;L7  COUNTER INSTRUCTIONS & FLAGS
;    COUNTER INSTRUCTIONS:   1=INCREMENT
;                            0=DISABLE
;      BIT
;        0  M COUNTER INCREMENT FLAG
;        1  E COUNTER INCREMENT FLAG
;        2  COIN FLAG
;        3  START PRINT FLAG
;        4  LF FLAG
;        5  MOTION SENSOR ENABLE FLAG
;        6  MOTION SENSOR DELAY (D) FLAG
;        7  PWRUP FLAG
;
;
;L9   FLAGS(FLG2)
;       BIT
;        0  X CNTR ENABLE FLAG
;        1  F CNTR ENABLE FLAG
;        2  DIAGNOSTIC FLAG
;        3  1 SHOT FLAG
;        4
;        5
;        6
;        7
;
;        INPUT ADDRESSES
;  IN1(L13)                         IN2(L14)
;  ADDR 0                           ADDR 1
;
;D0  SELECTOR SW U1              D0  NPRINTSW  0 WHEN ACTUATED
;D1  SELECTOR SW U2              D1  HOME SW  1 IF HOME; 0 IF NOT HOME
;D2  SELECTOR SW U4              D2  '0' CROSSING  0 WHEN CROSSING
;D3  SELECTOR SW U8              D3  PAPER MOTION
;D4  SELECTOR SW T1              D4  NZAP (ACTIVE LOW)
;D5  SELECTOR SW T2              D5  50-60HZ SELECT  1=60HZ
;D6  SPARE                       D6  SPARE
;D7  SPARE                       D7  SPARE
;
;
;  SELECTOR SWITCH ENCODES BCD               ENCODES 1'S
;
         
;        OUTPUT ADDRESSES
;  OUTS(L15)
;  ADDR 0
;D0  CHARGEOFF     CHARGE IS ON WHEN LOGICAL 0
;D1  SCANSOL
;D2  BILLING
;D3  JAMLED
;D4  FANS
;D5  EXPOSE
;D6  DRIVES
;D7  FUSER
;
         
;        COUNTER/TIMER FUNCTIONS
;
;        M CNTR    L0 L1
;        MASTER COUNTER  CONTROLS GENERAL MACHINE TIMING.
;        ALSO USED TO ENTER DIAGNOSTIC MODE.
;
;        E CNTR    L2
;        STARTED AT THE ELECTRICAL END OF SCAN  CONTROLS
;        MOTION SENSOR ENABLE/DISABLE AND BILLING. TERMINAL
;        COUNT OF 255 CAUSES E CNTR TO BE DISABLED AND
;        ENABLES THE F CNTR. CHARGE TURNOFF IS ALSO
;        CONTROLLED BY THE E CNTR.
;
;        F CNTR    L12
;        FUSER TIME OUT COUNTER  STARTS AT E CNTR=255  BUT HELD
;        CLEAR IF THE E CNTR IS ENABLED.
;
;        P CNTR    L4
;        PROGRAM COUNTER  INCREMENTED FOR EVERY COPY CYCLE 
;        COUNTS COPIES MADE. P CNTR IS INITIALIZED=1.
;
;        WATCHDOG TIMER    L5
;        BIT 0 IS THE WDT FLAG WHICH IS SET UPON RECIEPT OF AN
;        INTERUPT AND ALLOWS ENTRY INTO THE LF ROUTINE WHERE IT IS
;        RESET. COUNTER IS INCREMENTED(BY 2) EVERY PASS THROUGH
;        THE PROGRAM AND IF A CARRY OCCURS INDICATING A LOSS OF
;        INTERUPT SIGNAL  PROGRAM JUMPS TO THE JAM ROUTINE.
;
;        STATE CNTR  L6
;        THE STATE COUNTER KEEPS TRACK OF MACHINE STATES AND
;        ALLOWS ENTRY INTO A STATE WHEN APPROPRIATE.
;
;        MS CNTR   L8
;        MOTION SENSOR COUNTER  INCREMENTED IF ENABLED 
;        CLEARED ON NEGATIVE EDGES OF MOTION SENSOR INPUT 
;        PROGRAM BRANCHES TO THE JAM ROUTINE IF VALUE OF
;        10 IS REACHED.
;
;        X CNTR    L10
;        X COUNTER IS USED IN STATE 1 TO ACHIEVE A 5.25 SECOND
;        TIME CHECK FOR OFF HOME CONDITION DURING STARTUP.
;        X COUNTER IS ALSO USED IN STATE 5 TO CONTROL FLASH
;        RATE OF THE JAMLED WHILE IN THE ZAP MODE.
;
;
         
;
;        TIMING CHANGES FOR B3 NECISITATED BY
;        INCLUSION OF THE MOHAWK HIGH VOLTAGE POWER
;        SUPPLY.
;
;        1.        KEEP THE EXPOSURE LAMP ON AS LONG
;                  THE DRIVES ARE ON.
;
;        2.        PREVENT THE COROTRONS FROM GOING OFF
;                  IF THE PRINT SWITCH IS MADE PRIOR TO
;                  THE NORMAL COROTRON TURN-OFF TIME
;                  DURING CYCLE OUT.
;
;        3.        IF THE PRINT SW IS MADE AFTER COROTRON
;                  TURN-OFF AND BEFORE 7.5 SEC. HAVE PASSED
;                  SINCE THE END OF SCAN  TURN ON THE
;                  COROTRONS AT 7.5 SEC. AND START A SCAN
;                  AT 8.0 SEC.
;
;        4.        IF THE PRINT SW IS MADE BETWEEN 7.5SEC.AND
;                  CYCLE OUT  TURN ON COROTRONS AT 10.1 SEC.
;                  AND START A SCAN AT 10.6 SEC.
;
;                                  J. R.
;                                  18JUN79
;
;
;        ALSO REQUIRED;
;        SENSE JAM RECOVERY( POWER ON RESET) AND TURN CHARGE
;        ON WITH DRIVES FOR COPY FOLLOWING A JAM TO AVOID THE
;        BACKGROUND STREAK. THIS WILL ALSO OCCUR ANY TIME THAT
;        POWER IS BROKEN AND RESTORED AND WILL RESULT IN SOME
;        ADDITIONAL TONER CONSUMPTION  BUT IS ACCEPTABLE
;        TO THE PROGRAM.
;                                  JC
;                                  27JUN79
         
;        STATE DESCRIPTIONS:
;
;
;  STATE1--CYCLE UP
;
;        SET FANS  EXPOSURE AND DRIVES AT M1.
;
;        OFF HOME JAM CHECK AT ST12 ALLOWS 5.25 SECONDS FOR
;        SCAN CARRIAGE TO RETURN HOME  ELSE JAM.
;
;        CHARGE SWITCHED ON AT 1.43 SECONDS(M86) AT ST121
;
;        SELECTOR SWITCH 00 (STOP PRINT) TESTED AT 1.7SECONDS
;        (M102) AND PROCEED TO STATE2 IF NOT 00
;
;
;
;  STATE2--COPY CYCLE
;
;        SET SCAN SOLENOID AT M1
;
;        RESET SCAN SOLENOID AT "NOT HOME SWITCH" OR "HOME
;        SWITCH AND M60"
;
;        ON HOME JAM CHECK AT ST22 ALLOWS 2 SECONDS (M120) FOR
;        SCAN CARRIAGE TO LEAVE HOME  ELSE JAM
;
;        AT M280 (END OF SCAN)  SET FUSER AND ENABLE EC  TEST
;        FOR PC GREATER OR EQUAL TO SELECTOR SWITCH AND SET
;        COIN FLAG IF TRUE
;
;        AT M316  TEST COIN FLAG AND ADVANCE TO STATE3 IF TRUE
;        ELSE TEST HOME SWITCH
;
;        IF HOME SWITCH IS TRUE  RESET MC AND REPEAT STATE2
;
;        IF "NOT HOME SWITCH AND M376"  JAM
;
;        AT ST24D  IF IN DIAGNOSTIC MODE  WHEN SCAN CARRIAGE
;        RETURNS HOME  IF EC IS 21 OR GREATER  SET THE JAMLED
;        TO INDICATE SLOW SCAN RETURN
;
;
         ;page
;  STATE3--CYCLE DOWN
;
;        RESET EXPOSURE AT M140
;
;        RESET FANS AND DRIVES AT M515
;
;        ADVANCE TO STATE4 AT M575
;
;        TEST PRINT FLAG WHILE IN STATE3 AND JUMP TO INITIAL1
;        TO INITIATE ANOTHER COPY CYCLE IF TRUE
;
;
;
;  STATE4--STANDBY
;
;        RESET MC AND CHARGEOFF
;
;        TEST ZAP THERMOSTAT INPUT  ADVANCE TO STATE5 IF 0
;
;        TEST DIAGNOSTIC FLAG AND ADVANCE TO STATE6 IF TRUE
;        (WILL OCCUR ONLY IN DIAGNOSTIC CODE 15 FLYBACK TIME
;        TEST)
;
;        TEST PRINT FLAG  ADVANCE TO STATE1 IF TRUE
;
;
;
;
;  STATE5--FUSER AND EXPOSURE LAMP PREHEAT
;
;        RESET PRINT FLAG AND SET FUSER
;
;        DELAY 3 SECONDS AND SET EXPOSURE
;
;        FLASH JAMLED AT 2HZ RATE
;
;        RESET EXPOSURE AFTER 4MINUTES AND 3 SECONDS
;        IF STILL IN ZAP MODE
;
;        RESET FUSER AND EXPOSURE AND ADVANCE TO STATE4 WHEN
;        ZAP THERMOSTAT INPUT= 1
;
;
;
         ;page
;  STATE6--DIAGNOSTICS MODE
;
;        SELECTOR SWITCH=00  MONITOR BIT 3 OF THE LF COUNTER
;
;        SELECTOR SWITCH=01  MONITOR PRINT SWITCH INPUT
;
;        SELECTOR SWITCH=03  PREPARE BILLING OUTPUT
;
;        SELECTOR SWITCH=04  PREPARE FUSER AND FANS OUTPUTS
;
;        SELECTOR SWITCH=05  MONITOR ZAP INPUT
;                            PREPARE FANS OUTPUT
;
;        SELECTOR SWITCH=06  MONITOR 50/60 HZ SELECT INPUT
;                            PREPARE EXPOSURE OUTPUT
;
;        SELECTOR SWITCH=07  PREPARE CHARGE FANS DRIVES OUTPUTS
;
;        SELECTOR SWITCH=08  MONITOR MOTION SENSOR INPUT
;                            PREPARE CHARGE  FANS  DRIVES 
;                            AND EXPOSURE OUTPUTS
;
;        SELECTOR SWITCH=09  MONITOR HOME SWITCH INPUT
;                            PREPARE SCAN SOLENOID OUTPUT
;
;        SELECTOR SWITCH=15  PREPARE TO SET STATE CNTR=1 
;                            SET THE DIAG FLAG  AND JUMP
;                            TO INITIAL FOR FLYBACK TIMING
;                            TEST
;
;
;        INPUT TESTS:
;        THE INPUT SELECTED IS MONITORED  AND ITS STATUS IS
;        INDICATED ON THE JAMLED:
;                  IF LOGICAL "1" JAMLED ON
;                  IF LOGICAL "0" JAMLED OFF
;
;
;
;        OUTPUT TESTS:
;        THE OUTPUT(S) SELECTED WILL BE SWITCHED ON WHEN THE
;        PRINT SWITCH IS ACTUATED
;        IN THE CASE OF CODE 15  THE PROGRAM INITIATES A 15
;        COPY CYCLE AND THE JAMLED IS SWITCHED ON MOMENTARILY
;        IF THE FLYBACK TIME EXCEEDS .33 SECONDS
;
;
;
         ;page
;  MISC ROUTINES:
;
;        ENABLE INTERUPT IF "0" CROSSING INPUT= 1
;
;        DECODE E CNTR TO:
;                  START AND STOP MOTION SENSING
;                  SET AND RESET BILLING COUNTER
;                  ENABLE F CNTR
;
;        DECODE F CNTR TO RESET FUSER
;
;        MONITOR MOTION SENSOR INPUT AND CONDITION THE
;        PAPER MOTION D FLAG
;
;        MONITOR THE MOTION SENSOR CNTR AND JAM IF VALUE
;        OF 10 IS REACHED
;
;        INPUT TO IN1 AND MASK BITS 6 AND 7 OF SELECTOR SWITCH
;        BYTE; INPUT TO IN2 THE REMAINDER OF INPUTS
;
;        INCREMENT WATCH DOG TIMER AND TEST FOR CARRY:
;        IF CARRY  JAM
;
;  LF (LINE FREQUENCY) ROUTINES:
;
;        THE WDT FLAG IS SET AT THE INTERUPT SERVICE
;        ROUTINE AT 120HZ AND WILL ALLOW ENTRY TO LF
;        IF TRUE. THE WDT FLAG IS RESET AND THE LF
;        CNTR IS INCREMENTED. IF THE LF CNTR INDICATES
;        DIVIDE BY 2  PASSAGE THROUGH LF IS ALLOWED.
;
;        THE LF ROUTINE ACCOMPLISHES:
;
;                  50/60 HZ TIMING CONVERSION
;
;                  MC INCREMENT IF ENABLED
;
;                  EC INCREMENT IF ENABLED
;
;                  FC INCREMENT IF ENABLED
;
;                  XC INCREMENT IF ENABLED
;
;                  PC INCREMENT IF "STATE2 AND M279"
;
;                  MSC INCREMENT IF ENABLED
;****newstuff
;		uart intialization has been added at init
;		added command and status processor at interrupt
;		ADDED PAGE SYNC STATUS AT STATE 2
			.predefine "XLCCPREDEFS.SR"
          .RDX  16
;        SYSTEM EQUATES
		MCL      =       00             ; M CNTR LOW BYTE
		MCH      =       01             ; M CNTR HIGH BYTE
		EC       =       02             ; E CNTR
		LFC      =       03             ; LF CNTR
		PC       =       04             ; PROG CNTR
		WDT      =       05           ;   WATCH DOG CNTR
		SC       =       06             ; STATE CNTR
		FLG1     =       07            ;  FLAG REG 1
		MSC      =       08             ; MOTION SENSE CNTR
		FLG2     =       09             ; FLAG REG 2
		XC       =       0A            ; EXTENDER CNTR
		TEMP     =       0B          ;   TEMP REG
		FC       =       0C            ; FUSER CNTR
		IN1      =       0D            ; INPUT BYTE 1
		IN2      =       0E            ; INPUT BYTE 2
		OUTS     =       0F           ;  OUTPUT BYTE
;page 2 register assignments
		uartcom =        00             ; uart command register
		uartstat  =        01             ; uart status register
		IFLAG   =        02             ; interupt polling register
		UFLAG  =        03             ; uart  status flags register
		sav1      =        04             ;storage for T during interupt
		sav2      =        05             ;storage for STATUS during
                                          ;interupt
		TEMP2 = 06
       uflag2  =07
       testcounter = 08
       OUT2 = 09
		inp3    = 0A
; uart constants
		cmdUart =        09       ; uart control addr
		dataUart =        08             ; uart send and receive data addr
		intflags  =        10             ; interupting device polling addr
		combit  =         00             ; command received from server
		statbit   =         01 ; status needs to be sent to server
		prntbit  =         02 ;print request from server i.e. make 1 print
		multibit=          03 ; delay cycle down more prints coming
		PFBIT   =         04 ;PAGE FLOP PSEUDO FLAG
		PSBIT   =         05 ;Flag that is set when print is started
      PARBIT =         06             ;parity status holding bit
      BADCMDBIT =   07
;uflag2 assignment
      pagedelbit     =    00
      patternbit  =  01 ;true when we're generating test patterns.
;OUT2 oriented stuff
      altosync = 00
      rosflag = 07
		rosconstant = 12. ; number of 8ms ticks to leave ros on for test
;INTFLAGS
      PRNTREQ = 02
;STATUS RESPONSES TO SERVER
		warmup =        40         ;machine is warming up
		ready    =        41         ;ready to feed (not running)
		jamb    =        44         ;machine is jammed
		fusercold =      49         ;fuser has gotten cold while printing
		rntredy   =      4a         ;printing not ready for new feed command
		rnredy    =      4b         ;printing ready to feed
		comrejp  =      4d         ;command rejected bad parity
		comrejun =     4e         ; don't recognize command
		comrejil  =      4f         ; illegal command sequence
		pgsync   =      52         ;page sync
		pgdel     =      53         ;page delivered to output tray
; COMMANDS TO PRINTER
		FEEDBOT=     40         ;PRINT COMMAND
      READSTAT =  20         ;READ STATUS COMMAND
      FEEDTOP = 50
      ISTACK = 21
      FEEDTOPSK = 51
      FEEDBOTSK = 41
      
;UART constants
      PARITY = 03.
;intflags bit assignments
;	d0 - uart interupt flag (active high)
;   d1 - 120hz interupt (active low)
         .loc    0
;
;
; INITIALIZATION ROUTINE - THIS ROUTINE INITIALIZE REGISTERS , FLAGS &USART

         MVI       SC 04          ; SET STATE CNTR eq 4
         MVI       FLG1  80      ; SET PWRUP FLAG
inituart:
			mvi TEMP 5Ax		;load a temp register with 5Ax 
			out TEMP cmdUart	;store to Uart mode reg
			mvi TEMP 35x		;load temp with 35x
			out TEMP cmdUart	;store to Uart command reg
			inp TEMP dataUart	;make a dummy read of Uart datareg
			CLR 
			stp                         ;set page flop
			movt   uartcom          ;clr command reg
			movt   uartstat          ;clr status reg
			movt   IFLAG            ;clr IFLAG
			movt   UFLAG           ;clr UFLAG
			movt   UFLAG2           ;clr UFLAG2
			movt   temp2           ;clr temp2
        MOVT   INP3            ;CLR ALTOPRINTREQ
			MVI   OUT2  80         ;turn off laser
			clp
INIT0:    CLR
         movt       OUTS          ;RESET OUTPUTS
         movt       LFC            ;CLEAR LF CNTR
         movt       WDT           ;CLEAR WATCH DOG CNTR
         movt       FLG2           ;RESET XC AND FC
INITIAL:  CLR                      ;ENABLE FLAGS
         movt       EC              ;CLEAR E CNTR
         movt       FC              ;CLEAR F CNTR
         movt       MSC            ;CLEAR MOTION SENSOR CNTR
         STB        07              ;RESET FLG1 EXCEPT PWRUP
         AND       FLG1          ;FLAG IF IT IS ON.
INITIAL1:  CAL      RESETMC  ;CLEAR M CNTR
INITIAL2: STB       0             ;ENABLE M CNTR
         IOR       FLG1
         CLR
         movt       XC             ;CLEAR X CNTR
         CLB       0
         AND       FLG2          ;RESET X CNTR ENABLE FLAG
         MVI       PC 1            ;SET PROG CNTReq1
;
;
; STATE 1 ROUTINE - STATE COUNTER IS CHECKED  IF ITS NOT EQUAL TO 1
;                   THE PROGRAM IS VECTORED TO STATE 2.
;                   THIS ROUTINE ACCOMPLISHES CYCLE UP & PREPARES
;                   MACHINE FOR COPY CYCLING.
;
;
STATE1:   lcj       SC 1 STATE2 ; IF: SC EQ 1
         MVIT        77              ;RESET PWRUP AND PRINT FLAGS
         AND       FLG1            ;ENDIF
;
ST101:    lcj       MCL 0 ST12    ;IF: MC EQ 0
         MVIT        70              ;SET FANS 
         IOR       OUTS             ;DRVS & EXPO
         stp                            ; enable ros output
         mvi out2 00
         clp
ST12:  ;movr        IN2
         ;CPL                          ;ELSE:
         ;bt 1 ST13                       ;**bypass home sw bt 1 ST13 IF: HOME SW
         STB       0                   ;ENAB. M CTR
         IOR       FLG1              ;& DISABLE X CNTR
         CLB       0                   ;ENDIF
         AND       FLG2             ;ENDIF
ST121:    lcj       MCL 86. ST122
ST123:    CLB       0                ;IF: MC EQ 86
         AND       OUTS            ;RESET CHARGEOFF
         CLB       2                   ;AND
         AND       FLG1             ;COIN FLAG
;                                   ELSE:
ST122:  lcj       MCL 102. STATE2       ;IF: MC EQ 102
         lcj       IN1 0 ST102             ;IF: SEL SW EQ 0
         JMP       ST11                   ;JMP TO ST11
;                                         ELSE:
ST102:    CAL       RESETMC                    ;    RESET MC & SET
         MVI       SC 2                         ;  STATE COUNTER eq 2
         JMP       STATE2                     ;    JMP TO STATE2
;                                           ENDIF
;                                        ENDIF
;                                   ENDIF
ST11:     MVI       SC 3            ; SET STATE CTReq3
         CAL       RESETMC        ;  CLEAR MC
         STB       0
         IOR       FLG1          ; ENABLE MC
         IOR       OUTS          ; SET CHARGEOFF
         JMP       STATE2          ; JMP TO STATE2
ST13:     lcj       MCL 60. STATE2
         CLB       0               ; IF: MC EQ 60
         AND       FLG1              ;  DISABLE MC &
         STB       0                    ; ENABLE X CNTR
         IOR       FLG2          ; ENDIF
         lcj       XC 255. STATE2
         JMP       JAM             ; IF: X CNTR EQ 255 - JMP JAM
;                                   ENDIF
;
; STATE 2 ROUTINE - STATE COUNTER IS CHECKED IF THE COUNT IS NOT 2 
;                   THE PROGRAM IS VECTORED TO STATE 3 ROUTINE.
;                   THIS ROUTINE CONTAINS MULTI COPY CYCLING PROCESS.
;
STATE2:   lcj       SC 2 STATE3     ; IF: SC EQ 2
         CLB       3                 ; RESET PRINT FLAG
         AND       FLG1          ; ENDIF
         lcj       MCH 0 ST21
         lcj       MCL 1 ST21      ; IF: MC EQ 1
         stp
         movr UFLAG
         bt prntbit pagesync
sync:	   clp
         STB       1                      ; SET SCAN SOL
         IOR       OUTS
ST21:   LCJ mch 0 ST270              ; read counter for sol reset
         LCJ mcl 15 ST270
         MVIT        0F5
         AND       OUTS                ;  RESET SCAN SOL & JAM LED
;                                       ENDIF
;                                   ENDIF
ST270:           ;this value must be at least one greater than the value of st27


         LCJ mch 1 ST27				; read counter 
         LCJ mcl 59. ST27          ;
         stp
         clb psbit                    ;watch for extra pagesync's
         and uflag                   ;clear page sync 1 shot
         movr uflag                 ;test if multicopy if so 
         bt multibit more          ;then clear the multibit
         clb prntbit                 ;otherwise clear the printbit
         and uflag
         clp
         jmp ST27
more:   clb multibit
         and uflag
         clp
ST27:   lcj       MCH 1 ST24D
         lcj       MCL 24. ST24D    ; IF: MC EQ 280 (256+24)
         STB       7
         IOR       OUTS              ;  SET FUSER
         STB       1
         IOR       FLG1                ; ENABLE E CNTR
         STB       3
         IOR       FLG2                ; SET 1SHOT FLAG
;                                   ENDIF
ST23:     movr        IN1
         CPL
         movt       IN1 ;            MCH3eqCOMPLEMENT OF SELSW
         stp 
         clb altosync                ;turn off alto pagesync 
         and out2
         movr uflag
         bt multibit ST24
         bt prntbit setcoin
         clp
         movr        PC
         ADD       IN1             ; PC>eqSELSW
         bt nc       ST24            ; IF: PC GE SEL SW
setcoin:
         clp
         STB       2
         IOR       FLG1               ; SET COIN FLAG
;                                   ENDIF
ST24D:    ;movr        IN2
         ;CPL
         ;bt 1       ST24            ; IF: HOME SW ON
         movr        FLG2
         CPL
         bt 3       ST24            ; ORIF: 1SHOT FLAG SET
         bt 2       ST24            ; ORIF: DIAG FLAG SET
         CLB       3
         AND       FLG2               ; RESET 1SHOT FLAG
         MVIT        20.
         CMP       EC                    ; COMPARE E CNTR WITH 20
         bt nz      ST24                  ; IF: E CNTR GT 20
         STB       3                        ;  SET JAM LED TO IND.
         IOR       OUTS                  ;   SLOW FLYBACK IN DIAG.
;                                         ENDIF
;                                   ENDIF
ST24:   clp
         lcj       MCH 1 STATE3    ; IF: MC EQ 256
         MVIT        59.
         CMP       MCL 
         bt nz      STATE3          ; ORIF: MC GT 315 (256+59)
         movr        FLG1
         bt 2       ST25                ; IF: COIN FLAG CLEAR
         jmp ST26                      ;bypass home sw stuff
;
;                                           ENDIF
;                                       ENDIF
;                                   ENDIF
ST25:     MVI       SC 3            ; SET STATE CTReq3
ST26:     CAL       RESETMC      ;    RESET MC
         JMP       STATE3          ; JMP TO STATE3
pagesync:
			stp                     ;make sure its reg bank 2
          movr uflag
          bt psbit sync
          mvi uartstat pgsync  ;put page sync stat in stat reg
			stb statbit             ;set send status flag
			IOR UFLAG          
          stb altosync
          ior out2
          stb psbit              ;set the page sync 1shot flag
          ior uflag
			clp                     ;reset page flop
			jmp sync
;                                   ELSE:  JMP TO ST27
;                                   ENDIF
;
;
; STATE 3 ROUTINE - STATE COUNTER IS DECODED IF ITS NOT 3 THE PROGRAM
;                   IS VECTORED TO STATE4 ROUTINE.
;                   STATE 3 IS FOR CYCLE OUT.
;
STATE3:   JMP       state333
         .loc    0FF
;
;
; INTERUPT LOCATION  WDT FLAGeq1 ALLOWS ENTRY TO THE LF ROUTINE
;
;
      CAL INTHANDLE
      RFS

state333:  lcj       SC 3 STATE4    ; SCeq3
         movr        OUTS         ; IF MAIN DRIVE OFF 
         CPL
         bt 6       ST37             ; JMP TO ST37
         movr        FLG1
         bt 3       ST31           ; JMP IF PRINT FLAG
ST37:     lcj       MCH 2. STATE4
         lcj       MCL 3. ST36     ; MCeq512+3eq515
         stp
         clb patternbit
         and uflag2
         movr uflag2
         cpl
         bt pagedelbit ST371
         mvi uartstat ready
         stb statbit
         ior uflag
         clb pagedelbit
         and uflag2
ST371:
         clp
         MVIT        08F        ; RESET DRIVES FANS EXPOSE
         AND       OUTS
         stp                       ;disable ros output
         mvi out2 80
         clp
ST36:     LCJ       MCL 33. STATE4  ; MCeq512+33eq545
         MVI       SC 4             ; SET STATE CNTReq4
         JMP       STATE4
ST31:     movr        OUTS
         bt 0       ST32           ; JMP IF CHARGE IS OFF
         MVI       SC 1           ; ELSE SET SCeq1
         CLB       2               ;  AND RESET COIN FLAG
         AND       FLG1
         JMP       INITIAL1
ST32:     CLR
         CMP       MCH            ; TEST MCHeq0 (LESS THAN 256)
         bt z       ST35
         STB       0.               ;TEST MCH GRTR 256
         CMP       MCH 
         bt n      ST33           ; JMP IF GRTR 256
         MVIT        156.
         CMP       MCL 
         bt n      ST33            ;JMP IF MC GRTR 256+156eq412
ST35:     LCJ       MCH 1. STATE4
         LCJ       MCL 155. STATE4 ; IF MCeq256+155eq411  RESTART
ST34:     MVI       MCL 72.         ; SET MCeq72
         MVI       MCH 0.
         MVI       SC 1.           ; SET SCeq1
         CLB       0               ;TURN ON CHARGE
         AND       OUTS
         CLB       2              ; RESET COIN FLAG
         AND       FLG1
         JMP       INITIAL2
ST33:     LCJ       MCH 2. STATE4
         LCJ       MCL 55. STATE4
         JMP       ST34           ; IF MCeq567  JMP ST34
;
;
; STATE 4 ROUTINE - STATE COUNTER IS DECODED IF ITS NOT 4 PROGRAM
;                   IS VECTORED TO STATE 5 ROUTINE.THIS ROUTINE
;                   CONTAINS THE STANDBY STATE.
;
STATE4:   lcj       SC 4 STATE5     ; IF: SC EQ 4
         CAL       RESETMC             ; CLEAR MC
         CLB       0                 ; RESET CHARGEOFF
         AND       OUTS         ;  ENDIF
         movr        IN2
         bt 4       ST41D           ; IF: ZAP MODE
         MVI       SC 5.               ; SET SC eq 5
         JMP       INIT0             ;  & JMP TO INIT0
;                                   ENDIF
ST41D:    movr        FLG2
         CPL
         bt 2       ST41            ; IF: DIAG FLAG SET
         MVI       SC 6             ;    SET SC eq 6
;
ST41:     movr        FLG1          ; ELSE:
         CPL                            ; IF: PRINT FLAG SET
         bt 3       STATE5                   ; SET CHARGEOFF SET SCeq1
         MVI       SC 1                     ; & JMP TO INITIAL
         movr        FLG1         ; TEST PWRUP FLAG
         bt 7       ST42            ;  IF SET  DONT SET CHARGEOFF
         STB       0.                  ;   ENDIF
         IOR       OUTS          ; ENDIF
ST42:     JMP       INITIAL        ;  ENDIF
;
;
; STATE 5 ROUTINE - STATE COUNTER IS DECODED IF COUNT IS NOT 5
;                   THE PROGRAM IS VECTORED TO STATE 6. THIS
;                   ROUTINE CONSISTS OF FUSER & EXPOSURE PREHEAT(ZAP).
;
STATE5:   lcj       SC 5 STATE6     ; IF: SC EQ 5
         movr        IN2              ; IF: IN ZAP MODE
         bt 4       ST51
         cal wrmup
wrmup2:
         CLB       3.                      ; RESET PRINT FLAG
         AND       FLG1
         STB       0
         IOR       FLG2                 ; ENABLE X CNTR
         STB       7.
         IOR       OUTS                 ; SET FUSER
         lcj       XC 1 ST52              ; IF: X CNTR EQ 1
         STB       3.                          ; SET JAM LED
         IOR       OUTS                 ; ENDIF
;                                      ENDIF
;                                   ENDIF
ST52:     lcj       XC 30. ST53      ; IF: X CNTR EQ 30
         CLB       3.                  ; RESET JAM LED
         AND       OUTS         ;  ENDIF
;
ST53:     lcj       XC 60. ST54      ; IF: X CNTR EQ 60
         MVI       XC 0.              ;   SET X CNTR eq 0
;                                   ENDIF
ST54:     movr        OUTS
         bt 5       ST55            ; IF: EXPOSURE OFF
         lcj       MCH 0. ST55
         lcj       MCL 180. ST55    ; ANDIF: MC EQ 180
         STB       5                  ;    SET EXPO.&
         IOR       OUTS
         CAL       RESETMC        ;        RESET MC.
;                                   ENDIF
ST55:     lcj       MCH  038  ST56  ; IF: MC EQ 14400
         lcj       MCL  040  ST56
         CLB       5                  ; RESET EXPO.
         AND       OUTS           ;   & DISABLE MC
         CLB       0
         AND       FLG1          ; ELSE:
ST56:     JMP       STATE6             ;  JMP TO STATE6
;                                   ENDIF
;                                   IF: NOT IN ZAP MODE
ST51:     CLB       0                   ; DISABLE X CNTR
         AND       FLG2             ;  RESET JAM LED 
         MVIT         057              ; FUSER & EXPOSURE
         AND       OUTS
         MVI       SC 4                ; SET SCeq4
         JMP       STATE6
;                                   ENDIF
;
;
; STATE 6 ROUTINE - STATE COUNTER IS DECODED IF NOT 6 PROGRAM
;                   IS VECTORED TO MISC ROUTINE.THIS ROUTINE CONTAINS
;                   THE MACHINE DIAGNOSTICS.
;                   IN STATE 6; TEMP IS USED AS A TEMPORARY REGISTER 
;                   IN WHICH OUTPUT CONDITIONS ARE SET UP. AT ST693 
;                   TEMP IS MASKED IF PRINT BUTTON IS NOT ACTIVATED 
;                   ELSE TEMP IS MOVED TO OUTS FOR OUTPUT.
;
;
         .loc       1FF
 STATE6:   lcj       SC 6 GMISC      ; IF: SC EQ 6
         MVI       TEMP  08          ; SET JAM LED
;                                   ENDIF
         lcj       IN1  00  ST601 ; IF: SEL SW EQ 00
         movr        LFC             ; IF: NOT 15 HZ
         bt 3       ST601                ; RESET JAM LED
         CLB       3                 ; ENDIF
         AND       TEMP
ST601:    lcj       IN1  001  ST61  ; ELSEIF: SEL SW EQ 01
         movr        IN2              ; IF: PRINT SW ON
         bt 0       ST61               ;     RESET JAM LED
         CLB       3                  ; ENDIF
         AND       TEMP
ST61:     lcj       IN1  09  ST63  ; ELSEIF: SEL SW EQ 09
         movr        IN2
         bt 1       ST62              ; IF: HOME SW OFF
         CLB       3                   ;  RESET JAM LED
         AND       TEMP
ST62:     STB       1                  ;ELSE:
         IOR       TEMP               ; SET SCAN SOL
;                                     ENDIF
ST63:     lcj       IN1  03  ST65  ; ELSEIF: SEL SW EQ 03
ST64:     STB       2                   ; SET BILLING
         IOR       TEMP
ST65:     lcj       IN1  04  ST66  ; ELSEIF: SEL SW EQ 04
         MVIT         90                  ; SET FUSER &
         IOR       TEMP                 ;  FANS.
ST66:     lcj       IN1  05  ST68  ; ELSEIF: SEL SW EQ 05
         movr        IN2                ; IF: ZAP EQ 0
         bt 4       ST67
         CLB       3                        ; RESET JAM LED
         AND       TEMP               ; ELSE:
ST67:     STB       4                       ;  SET FANS
         IOR       TEMP               ; ENDIF
ST68:     lcj       IN1  06  ST690
         movr        IN2           ; ELSEIF: SEL SW EQ 06
         bt 5       ST69                  ; IF: 50HZ SELECTED
         CLB       3                        ;  RESET JAM LED
         AND       TEMP                ; ELSE:
ST69:     STB       5                         ; SET EXPOSURE
         IOR       TEMP                ; ENDIF
ST690:    lcj       IN1  07  ST691 ; ELSEIF: SEL SW EQ 07
         MVIT         50                  ; TURN ON CHARGE
         IOR       TEMP                  ; DRIVES & FANS
ST691:    lcj       IN1  08  ST692  ;ELSEIF: SEL SW EQ 08
         MVIT         70                  ; TURN ON DRVS
         IOR       TEMP                  ; FANS EXPO.& CHG.
         movr        IN2
         bt 3       ST692                  ; IF: MOTION SENSE OFF
         CLB       3                         ; RESET JAM LED
         AND       TEMP                 ; ENDIF
ST692:    lcj       IN1  15  ST693 ; ELSEIF: SEL SW EQ 15
         movr        IN2
         bt 0       ST693                   ; IF: PRINT SW ON
         MVI       SC 1                       ;  SET SC eq 1
         STB       2                           ; SET DIAG FLAG
         IOR       FLG2                      ; AND THEN
         JMP       INITIAL                     ; JMP TO INITIAL
GMISC:    JMP       MISC
;                                               FOR FLYBACK CHK.
;                                           ENDIF
ST693:    movr        IN2
         CPL
         bt 0       ST694           ; ELSEIF: PRINT SW OFF
         STB       3                  ; RESET ALL OUTPUTS EXCEPT JAM LED
         AND       TEMP          ; ELSE:
ST694:    movr        TEMP                ; PUT TEMP IN OUT REG.
         movt       OUTS ;           ENDIF
;
;
; MISC ROUTINE
;
MISC:     CAL       INPUT           ; REFRESH INPUTS
         movr        IN2
         CPL
         bt 2       MISC12           ;IF: ZERO CROSSING TRUE
         STI                           ; SET INTERRUPT ENABLE
         CAL CHKPRNT             ; CHECK FOR PRINT COMMAND
         STP    
         INPT INTFLAGS      ;READ THE PRINTER INPUT BYTE 
         MOVT TEMP2
        CMP INP3
        BT Z NOPRNTREQ  ; TEST TO SEE IF SLOT CARD PRINT
										; REQUEST HAS BEEN MADE IF SO
										;THEN SET THE PRNTBIT ELSE NEVERMIND
        MOVR INP3 
        BT prntreq NOPRNTREQ
        stb PRNTBIT
        IOR UFLAG
NOPRNTREQ:
        MOVR TEMP2
        MOVT INP3
         MOVR UFLAG
         BT PRNTBIT MISC101
         CLP
MISC12:   movr        IN2
         bt 0       MISC11          ; ELSEIF: PRINT SW ON
MISC101:
         movr uflag
         cpl
         bt prntbit MISC101A
         stb pagedelbit           ;remember to send page delivered
         ior uflag2
MISC101A:
         CLP
         STB       3
         IOR       FLG1               ; SET PRINT FLAG
         stp
         movr uflag
         bt prntbit misc11
         stb patternbit
         ior uflag2
MISC11:
         clp
         STB       1
         ADD       WDT                  ; INCREMENT WD TIMER BY 2
         bt nc       MISC13          ; ELSEIF: CARRY IS SET
         JMP       JAM                ;  JMP TO JAM
MISC13:   lcj       EC 117. MISC14   ; ELSEIF: E CNTR EQ 117
         STB       5                   ; ENABLE MOT SEN
         IOR       FLG1
MISC14:   movr        FLG1
         CPL                       ; ELSEIF: COIN FLAG SET
         bt 2       MISC141               ; IF: EC EQ 140
         lcj       EC 140. MISC141
         STB       0                        ; SET CHARGEOFF
         IOR       OUTS                ; ENDIF
MISC141:  lcj       EC 247. MISC15   ; ELSEIF: EC EQ 247
         CLB       5
         AND       FLG1               ; DISABLE MOT SENS
         STB       2
         IOR       OUTS               ; SET BILLING
;
;
MISC15:   lcj       EC 255. MISC16   ; ELSEIF: EC EQ 255
         CLB       2
         AND       OUTS               ; RESET BILLING
         stp
         movr uflag2
         bt pagedelbit delivered         ; test deliver flag send delivered
misc151:
         clp
         CLB       1
         AND       FLG1               ; DISABLE EC
         MVI       EC 0                 ; RESET EC
         STB       1
         IOR       FLG2               ; ENABLE FC
MISC16:   movr        FLG1
         CPL
         bt 1       MISC17          ; ELSEIF: EC INCR FLAG SET
         MVI       FC 0                ; RESET FC
MISC17:   lcj       FC 176. MISC18   ; ELSEIF: EC EQ 176
         CLB       7                    ; RESET FUSER
         AND       OUTS
MISC18:   movr        FLG1
         CPL
         bt 5       MISC21          ; ELSEIF: MOT SEN ENABLE
         movr        IN2
         bt 3       MISC19               ; IF: PAP IN MOTION
         movr        FLG1                 ;  SET D FLAG @ MISC19
         bt 6       MISC20               ; ELSEIF: MOT SEN EQ 0
;                                           RESET MOT  D  FLAG
;                                        ENDIF
MISC22:   lcj       MSC 10. LF       ; ELSEIF: MOT SEN EQ 10
;;;         JMP       JAM                 ;  JMP TO JAM
;patched out above instruction to see if we can get large format to work on
;the Hornet

delivered: 
         mvi uartstat pgdel
         stb statbit
         ior uflag
        jmp misc151
;                                   ELSE: JMP TO LINE FREQ ROUT
;                                   ENDIF
MISC19:   STB       6
         IOR       FLG1          ; SET MOTION D FLAG
         JMP       MISC22
MISC20:   CLB       6
         AND       FLG1          ; RESET MOTION D FLAG
MISC21:   MVI       MSC 0          ;  RESET MOT SEN CTR
         JMP       LF
;
;
; LINE FREQ ROUTINE - WATCH DOG TIMER FLAG IS CHECKED IF ITS CLEAR
;                     THE PROGRAM IS VECTORED TOSTATE 1 ROUTINE.
;
         .loc       2FF
LF:       movr        WDT
         CPL
         bt 0       LFEND           ; IF: WDT FLAG IS SET
         CLB       0                   ; RESET WDT FLAG
         AND       WDT
         STB       0
         ADD       LFC                ;  INCR LF CNTR
         movr        IN2           ; ENDIF
         CPL
         bt 5       LF1             ; IF: 60 HZ MODE
LF11:     movr        LFC
         bt 0       LFEND           ; ANDIF: LSB OF LFC NE 1 (DEVIDE BY 2)
LF2:      movr        FLG1
         CPL
         bt 0       LF3             ; ANDIF: MC ENABLED
         STB       0
         ADD       MCL                  ; INCR LSB OF MC
         bt nc       LF3                   ; IF: CARRY IS SET
         ADD       MCH                  ;    INCR MSB OF MC
;                                         ENDIF
;                                   ENDIF
LF3:      movr        FLG1
         CPL
         bt 1       LF31            ; IF: EC ENABLED
         STB       0
         ADD       EC                 ; INCR EC
LF31:     movr        FLG2          ; ELSE:
         CPL
         bt 1       LF35                ; IF: FC ENABLED
         STB       0
         ADD       FC                     ; INCR FC
LF35:     movr        FLG2
         CPL                           ; ELSE:
         bt 0       LF311                   ; IF: XC ENABLED
         STB       0
         ADD       XC                         ; INCR XC &
         JMP       LF4                        ; JMP TO LF4
LF311:    CLR                               ; ELSE:
         movt       XC ;                         RESET XC
;                                           ENDIF
;                                       ENDIF
;                                   ENDIF
LF4:      lcj       SC 2. LF47       ; IF: SC EQ 2
         lcj       MCH 1. LF47      ; ANDIF: MC EQ 279
         lcj       MCL 23. LF47
;
;
; PROGRAM COUNTER IS INCREMENTED TO BE COMPATABLE WITH BCD INPUT
; FROM SELECTOR SWITCH.
         MVIT        7
         ADD       PC                   ; INCR PC BY 7
         bt ci       LF47                 ; IF: CI IS CLEAR
         MVIT        0FA					; FF - 6
         ADD       PC                      ; DEC. PC BY 6
;                                        ENDIF
;                                   ENDIF
LF47:     movr        FLG1
         CPL
         bt 5       LFEND            ;IF: MOT SEN ENABLED
         STB       0
         ADD       MSC                 ;INCR MOT SEN CNTR
;                                   ELSE:
LFEND:    JMP       STATE1               ; JMP TO STATE1
;                                   ENDIF
LF1:      lcj       LFC 4 LF11      ; IF: LFC EQ 4
         MVI       LFC  0FF            ;SET LFC TO 255
         JMP       LF2                 ;& JMP TO LF2
;                                   ELSE: JMP TO LF11
;                                   ENDIF
; SUBROUTINES
;
RESETMC:  CLR
         movt       MCL ;            RESET MC LSB
         movt       MCH ;            RESET MC MSB
         RFS                        ;RETURN
         NOP
;
;
; JAM ROUTINE HAS ONLY ONE NORMAL EXIT  THAT IS POWER UP RESET.
; THE DIAGNOSTICS ROUTINE IS ACESSED VIA THE JAM ROUTINE.
;
JAM:    stp
          movr uflag2
          bt pagedelbit sendjam
          clb statbit
          and uflag
          clp
jammed:
         clp
         MVI       OUTS  008       ; CLEAR OUTS  SET JAMLED
         OUT  OUTS  0        ; OUTPUT HERE IN CASE OF JAM:
         stp
         clb patternbit
         and uflag2
         MVI out2 80           ;turn off laser
         clp
;                                   DUE TO INTERUPT FAILURE
;                                   (WATCH DOG TIMER OVERFLOW)
         CAL       INPUT           ; INPUT AND MASK SELSW TO
;                                   IN1  INPUT TO IN2
         movr        IN2
         bt 2       j21           ;IF: ZERO CROSSING TRUE
         STI                           ; SET INTERRUPT ENABLE
j21:
         bt 0       J2              ; IF: PRINT SW OFF - JMP J2
         movr        MCL
         CMP       IN1             ; ELSE:
         bt z       J3                  ; IF: SEL SW EQ MC (LSB)
         MVIT        0F0                 ; DECR MC BY  010 
         ADD       MCL                 ; ELSE:
J3:       lcj       MCL  0F8  JAM           ; IF: MC EQ  0F8 
         lcj       IN1  000  JAM           ; ANDIF: SEL SW EQ 00
         MVI       SC 6                         ;SET SC eq 6 &
         JMP       INIT0                       ; JMP TO STATE 6
;                                           ELSE:
;                                                JMP TO JAM
;                                           ENDIF
;                                       ENDIF
;                                   ENDIF
;THIS IS ONE OF THE PLACES WE SEND STATUS. WE RESPOND
;TO READ STATUS REQUESTS HERE, AND ALSO SEND 'JAMMED'
;IN RESPONSE TO 'FEED' COMMANDS.
; WE DON'T CARE IF THERE WAS A RESPONSE PENDING WHEN 
;THE JAM OCCURRED -- IT IS STEPPED ON. 
J2:       MVI       MCL  038        ; SET LSB OF MC eq  038 
          stp
          movr uflag
          cpl
          bt combit jammed          ; if combit is 
          mvit readstat
          cmp uartcom
          bt z sendjam
           mvit feedbot
          cmp uartcom
          bt z sendjam
          clp
        JMP       jammed             ; JMP TO jammed
sendjam:
         stp
         mvi uartstat jamb
         out uartstat datauart
         clb prntbit
         and uflag
         clb combit
         and uflag
         clp
         jmp jammed
;
;
;        SUBROUTINE "INPUT" INPUTS THE SELECTOR SWITCH AND
;        MASKS THE UNUSED BITS 6&7; SELSW VALUE THEN
;        STORED IN IN1. MACHINE INPUTS THEN STORED IN
;        IN2.
;
;
INPUT:    INP       IN1 0           ; INPUT  SEL SW TO MCH3
         MVIT         03F 
         AND       IN1           ; MASK UNUSED BITS 6 & 7
         INP       IN2 1           ; INPUT MACH INPUTS TO MCH4
         RFS                       ; RETURN
wrmup:
         stp
         movr UFLAG
         bt prntbit sendwrmup
         clp
         RFS
sendwrmup:
         mvi uartstat warmup
         stb statbit
         ior uflag
         clb prntbit
         and uflag
         clp
         RFS
.LOC 400
INTHANDLE:
		BT PF   SETPGF     ;TEST THE PAGE FLOP
		stp                    ;set register page flip flop
		movt sav1            ;save contents of T register
		svs                    ; move status to T
		movt sav2            ;save status register
      movr uflag
      bt prntbit save ;if online printing, forget test.
      movr uflag2
      cpl
      bt patternbit save      ;test the copier print flag
      stp               ; output test pattern by leaving ros on for
      stb 0             ;   'rosconstant' number of cycles
      add testcounter
      mvit rosconstant
      cmp testcounter
      bt n toggle ;go to 'toggle' if the counter has gone negative

save:
       stp
		inp IFLAG intflags  ;input the interupt register
		movr IFLAG         ; T←interupt flags
		cpl
		bt 1 lineint          ;if not lineint
		movr IFLAG         ;restore IFLAG to T
		bt 0 ruart             ;if not uart restore state then RFS
		MOVR UFLAG
		BT PFBIT RESETFLAG
		JMP RESTORE

TOGGLE:
       movr OUT2
       bt rosflag complement
       stb rosflag
       ior OUT2
toggle1:
       clr
       movt testcounter
       jmp save

complement:
       clb rosflag
       and OUT2
       jmp toggle1
RESTORE:
		movr sav2            ;saved status to T
		rss                     ;restore status from T
		movr sav1            ;restore T register
		clp                    ; reset page flop
      CLI
		RFS
SETPGF:
		STP                   ;SET PAGE FLOP
		movt sav1            ;save contents of T register
		svs                    ; move status to T
		movt sav2            ;save status register
		STB PFBIT      ;SET PG FLOP FLAG
		IOR  UFLAG
		JMP SAVE
ruart:
		inp uartcom datauart  ;read uart data and store in uart com reg
      INPT CMDUART
      BT PARITY PARERR
		
      jmp filterCmds         ;returns to filterCmdsRet


filterCmdsRet:
		IOR uflag
		MOVR UFLAG
		BT PFBIT RESETFLAG
		JMP RESTORE
RESETFLAG:
		CLB PFBIT                ;CLEAR THE PAGE FLOP FLAG
		AND UFLAG
		movr sav2            ;saved status to T
		rss                     ;restore status from T
		movr sav1            ;restore T register
       CLI
		RFS
		
filterCmds:
       clb 07
       and uartcom
       mvit FEEDBOT
       cmp uartcom
       bt z filterCmds1
       stb  combit
       jmp filterCmdsRet
filterCmds1:
       mvit READSTAT
       cmp uartcom
       bt z filterCmds2
       stb  combit
       jmp filterCmdsRet
filterCmds2:

       mvit FEEDTOP
       cmp uartcom
       bt z filterCmds3
       jmp filterCmdsRet
filterCmds3:
       mvit ISTACK
       cmp uartcom
       bt z filterCmds4
       jmp filterCmdsRet
filterCmds4:
       mvit FEEDTOPSK
       cmp uartcom
       bt z filterCmds5
       jmp filterCmdsRet
filterCmds5:
       mvit FEEDBOTSK
       cmp uartcom
       bt z filterCmds6
       jmp filterCmdsRet
filterCmds6:
       MVIT 0F0
       AND UARTCOM
       MVIT 30
       CMP UARTCOM
       BT Z FILTERCMDSRET
       STB BADCMDBIT
       IOR UFLAG
       JMP FILTERCMDSRET


lineint:
		clp
         MVI WDT 01       ;SET WDT FLAG UPON INTERUPT 
                               ;RESET WATCH DOG TIMER.
         OUT  OUTS 0     ;OUTPUT OCCURS AT 0 CROSSING.
		stp                     ;set page flop
		OUT OUT2 16.
movr IFLAG          ;get the interupt polling flags
		bt 0 ruart             ;test if uart called as well
		movr uflag
		bt statbit suart
       bt parbit cont
       bt badcmdbit badcmd
       movr uflag
		BT PFBIT RESETFLAG
		JMP RESTORE
suart:
		out uartstat datauart ;send status to uart
		clb statbit            ; clear status bit of uart flag
		and uflag
		MOVR UFLAG
  		BT PFBIT RESETFLAG
		JMP RESTORE
badcmd:
      mvi uartstat comrejun
      CLB BADCMDBIT
      AND UFLAG
      jmp suart

PARERR:
       bt statbit setpar
      inpt datauart               ;reinit uart and send parity error
      mvi temp2 40
      out temp2 cmduart
      mvi temp2 5a
      out temp2 cmduart
      mvi temp2 35
      out temp2 cmduart
       mvi uartstat comrejp
       stb statbit
       ior uflag
       movr uflag 
       bt pfbit resetflag
       jmp restore
setpar:
       stb parbit
       ior uflag
       movr uflag
       bt pfbit resetflag
       jmp restore 
cont: 
      mvi uartstat comrejp
      inpt datauart
      mvi temp2 40            ;reinit uart and send parity error
      out temp2 cmduart
      mvi temp2 5a
      out temp2 cmduart
      mvi temp2 35
      out temp2 cmduart
      out uartstat datauart
      movr uflag
      bt pfbit resetflag
      jmp restore
.loc 500
CHKPRNT:
         STP
         MOVR UFLAG              ;GET UART FLAGS
         BT COMBIT CHKCOM     ; TEST COM FLAG
         CLP                          ;IF TRUE THEN GO CHKCOM
         RFS                          ;ELSE RFS
CHKCOM:
         CLB 07                      ;
         AND UARTCOM
         MVIT FEEDBOT           ;TEST PRINT COMMAND
         CMP UARTCOM
         BT Z SETPRNT            ;TRUE , GO SETPRNT
         MVIT READSTAT
         CMP UARTCOM
         BT Z SENDSTAT
         CLP                          ;ELSE RFS
         RFS
SENDSTAT:
         clp
         movr IN2
         cpl
         bt 04 SENDWARMUP ;testing for warmup
         movr flg1
         bt 03 SENDPRINTING ;JUST MEANS 'COPIER' IS printing
         stp
         mvi uartstat ready
         stb statbit
         ior uflag
         jmp clrcomb ; enough with the commands

SENDWARMUP:
         stp
         mvi uartstat WARMUP
         stb statbit
         ior uflag
         jmp clrcomb ; enough with the commands


SENDPRINTING:     ;here if in test mode or printing a file
         stp
         mvi uartstat rntredy  ;not ready for another feed command!
         stb statbit
         ior uflag
         jmp clrcomb ; enough with the commands

SETPRNT:
         movr uflag
         bt prntbit onmulti
         STB PRNTBIT            ;SET PRNTBIT FLAG
         IOR UFLAG               ;
clrcomb:
         CLB COMBIT            ;CLEAR COM FLAG
         AND UFLAG
         CLP
         RFS
ONMULTI: 
         stb multibit
         ior uflag
         jmp clrcomb
              .END