; last edited 3 Oct. 1982 12:24 pm PDT (Sunday) by GW & DP
;         SYSTEM    LCC
;         TITLE     'GNAT CONTROL PROGRAM ADAPTED FROM 2600 CONTROL PROGRAM'
;        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	KEYBOARDROW1			D0   
;D1	KEYBOARDROW2			D1   
;D2	KEYBOARDROW3			D2   
;D3	KEYBOARDROW4			D3   
;D4	PAPERTRAYSENSE		D4	MOTION SENSE 
;D5	ZapThermostat		D5	ZeroXing (Zero-crossing)
;D6					D6   
;D7					D7   
;
;
;  
;         
;        OUTPUT ADDRESSES
;  OUT0
; addr 03; 
; THE OUTPUTS TO THE SEVEN SEGMENT DISPLAY AND THE INDICATOR LEDS ARE STROBED
; BY SEPERATE ENABLES IN ADDR 04
; D0 LED SEGMENT A 
; D1 LED SEGMENT B
; D2 LED SEGMENT C OFFLINE LED
; D3 LED SEGMENT D ONLINE LED
; D4 LED SEGMENT E DIAGNOSTICS LED
; D5 LED SEGMENT F
; D6 LED SEGMENT G
; D7 ZeroXing mask  (Zero-crossing mask)
;  OUT1
; addr 04
; D0 ENABLE INDICATOR LEDS
; D1 SEVEN SEGMENT UNITS ENABLE
; D2 SEVEN SEGMENT TENS ENABLE
; D3
; D4
; D5 CHARGE ON 
; D6
; D7      
;	OUT2
; addr 05
; D0 Test1	--Generates the test pattern.
; D1 DEVELOPER BIAS ON
; D2
; D3
; D4
; D5
; D6
; D7      
;  OUT3
; addr 06
; D0
; D1 MAINDRIVE/DOCTOR BLADE
; D2 VACUUM FAN/ FUSER FAN
; D3 FUSER TRIAC
; D4 DEVELOPER CLUTCH
; D5 SCAN SOL
; D6 Billing Meter
; D7      
; addr 10
; KEYBOARD COLUMN 1
; addr 20
; KEYBOARD COLUMN 2
; addr 40
; KEYBOARD COLUMN 3
; addr 80
; KEYBOARD COLUMN 4
;        COUNTER/TIMER FUNCTIONS
;
;        M CNTR    L0 L1
;        MASTER COUNTER  CONTROLS GENERAL MACHINE TIMING.
;        ALSO USED TO ENTER DIAGNOSTIC MODE.
;
;        E CNTR    L2
;        STARTED AT MC = 280.  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. 
;
;        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.        Deleted.
;
;        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.
;
;        CHARGE SWITCHED ON AT 1.43 SECONDS(M86) AT ST121

;  STATE2--COPY CYCLE
;
;        SET SCAN SOLENOID AT M1
;
;        RESET SCAN SOLENOID AT M60
;
;        AT M280 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 RESET MC AND REPEAT STATE2

;  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 CHARGEON
;
;        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
;  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
;  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