; last edited June 30, 1982 11:19 AM
; 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 0ADDR 1
;
;D0
KEYBOARDROW1D0
;D1
KEYBOARDROW2D1
;D2
KEYBOARDROW3D2
;D3
KEYBOARDROW4D3
;D4
PAPERTRAYSENSED4MOTION SENSE
;D5
ZapThermostatD5ZeroXing (Zero-crossing)
;D6
D6
;D7
D7
;
;
;
;
; OUTPUT ADDRESSES
; OUT3
; 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)
; OUT4
; addr 04
; D0 ENABLE INDICATOR LEDS
; D1 SEVEN SEGMENT UNITS ENABLE
; D2 SEVEN SEGMENT TENS ENABLE
; D3
; D4
; D5 CHARGE ON
; D6
; D7
;
OUT5
; addr 05
; D0 Test1
--Generates the test pattern.
; D1 DEVELOPER BIAS ON
; D2
; D3
; D4
; D5
; D6
; D7
; OUT6
; 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 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 "ADMPredefs.SR"
.RDX 16
;
SYSTEM EQUATES
;Bank 0 registers
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
;Bank 1 Registers
uartcom=00; uart command register
uartstat=01; uart status register
IFLAG=02; interupt polling register
UFLAG=03; uart status flags register
TEMP2=06
uflag2=07
testcounter=08
OUT3=09; OUTPUT HOLDING REGISTERS
OUT4=0A
OUT5=0B
OUT6=0C
;These registers are for use in bank 2
ROW=00
COL=01
DSP=02
KBDREG=03
CPYSEL=04;

DSPTENS=05;
DSPONES=06;
TEMP4=07;
TEMP5=08;
TEMP6=09;
ZEROFLG=0A;
ROUT0=0B;
ROUT1=0C;MUST BE IN[8..F]
WDTtimeout=0D;
FLAG2=0E;One bit in this keeps WDT state

;Bank 3 registers
SAVET=048.;
SavetRel=00;
SR=049.;
SaverRel=01;
;Bits
TENENT=01;
ONEENT=00;
OFFLINE=02;
ONLINE=03;
BLANK=00;
ZCROSSING=05;
EXTF=0C;External interrupt mask
LEDRTN =0
LEDONE =1
LEDTEN =2
WatchDT=Bit7;

;Some Locations
DATARW=08; THE UART
INPUT1=01;INTERRUPT STATUS
OUT0=03;
OUT1=04;
OUT3=06;

;how about some constants, too?
Bit0=00
Bit1=01
Bit2=02
Bit3=03
Bit4=04
Bit5=05
Bit6=06
Bit7=07
AllOnes=0FF;
ZERO=00;


;I/O constants
;
OUTPUTS:
ledenable=00
unitseable=01
tensenable=02
chargeon=05
devbias=01
maindrve=01
vacuum=02
fuser=03
devclutch=04
scansol=05
ROShold=05
ROSpullin=06
Billing=06
Test1=00;when set, we’re generating test pattern

;
INPUTS:
zaptherm=05
ZeroXing=05
OutOfPaper=04
MotionSense=04
KbdRow1=00
KbdRow2=01
KbdRow3=02
KbdRow4=03

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

;random constants
rosconstant=12.; Number of 8ms ticks to leave ros on for test;
laserBeam=01;

; (determines stripe width for test).

;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
RESTART:
JMP STARTUP;POWER ON RESET
JMP INTHANDLE;external interrupt vector
JMP TimerInterrupt;This is the timer interrupt loc: forget it

;
INITIALIZATION ROUTINE - THIS ROUTINE INITIALIZE REGISTERS , FLAGS &USART
STARTUP:
DIF;in case we need to initialize some variables.
DTI
LPI02
STBWatchDT
MOVT FLAG2;save wdt’s state here
MVI WDTtimeout 00; for watch dog timer hack
MVIROUT0 084;turn on the "OFF LINE" led
MVIT 084
OUTT OUT0
STBLEDRTN;set up to strobe the leds
OUTTOUT1;

MVIKBDREG 0C0; enable keyboard

Lpi0;set the reg bank to 0
MVISC 04; SET STATE CNTR eq 4
MVIFLG1 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
Lpi 1;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
MVI OUT3 00;CLEAR ALL THE OUTPUT REGISTERS
MVI OUT4 00
MVI OUT5 00
MVI OUT6 00
Lpi 0
INIT0:
CLR
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:
lcjSC 1 STATE2;IF: SC EQ 1
MVIT77;RESET PWRUP AND PRINT FLAGS
ANDFLG1;ENDIF

ST101:
lcjMCL 0 ST12;IF: MC EQ 0
Lpi1; SET MAIN DRIVE
stbMAINDRVE;SET FANS
IOROUT6
stbVACUUM
IOROUT6
Lpi0
ST12:
STB0;ENAB. M CTR
IORFLG1;& DISABLE X CNTR
CLB0;ENDIF
ANDFLG2;ENDIF
ST121:
lcjMCL 86. ST122
ST123:
Lpi1
CLBchargeon;IF: MC EQ 86
ANDOUT4;RESET CHARGEOFF
Lpi0
CLB2;AND
ANDFLG1;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
stb chargeon
Lpi 1
IOR OUT4 ; SET CHARGEOFF
Lpi 0
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
Lpi 1
movr UFLAG
bt prntbit pagesync
sync:
Lpi 0
STB scansol ; SET SCAN SOL
Lpi 1
IOR OUT6
Lpi 0
ST21:
LCJ mch 0 ST270 ; read counter for sol reset
LCJ mcl 15 ST270
clb scansol
Lpi 1
AND OUT6 ; RESET SCAN SOL & JAM LED
Lpi 0
; 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
Lpi 1
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
Lpi 0
jmp ST27

more:
clb multibit
and uflag
Lpi 0
ST27:
lcj MCH 1 ST24D
lcj MCL 24. ST24D ; IF: MC EQ 280 (256+24)
STB fuser
Lpi 1
IOR OUT6 ; SET FUSER
Lpi 0
STB 1
IOR FLG1 ; ENABLE E CNTR
STB 3
IOR FLG2 ; SET 1SHOT FLAG
; ENDIF
ST23:
movr IN1
CPL
movt IN1 ; MCH3eqCOMPLEMENT OF SELSW
Lpi 1
movr uflag
bt multibit ST24
bt prntbit setcoin
Lpi 0
movr PC
ADD IN1 ; PC>eqSELSW
bt nc ST24 ; IF: PC GE SEL SW

setcoin:
Lpi 0
STB 2
IOR FLG1 ; SET COIN FLAG
; ENDIF
ST24D:
ST24:
Lpi 0
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:
Lpi 1;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 psbit;set the page sync 1shot flag
ior uflag
Lpi 0;reset page flop
jmp sync
;
; 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:

state333:
lcjSC 3 STATE4 ; SCeq3
Lpi1
movrout6;IF MAIN DRIVE OFF
CPL
lpi 0
bt mainDrve ST37 ; JMP TO ST37
movr FLG1
bt 3 ST31 ; JMP IF PRINT FLAG
ST37:
lcj MCH 2. STATE4
lcj MCL 3. ST36 ; MCeq512+3eq515
Lpi 1
clb patternbit
and uflag2
movr uflag2
cpl
bt pagedelbit ST371
mvi uartstat ready
stb statbit
ior uflag
clb pagedelbit
and uflag2

ST371:
Lpi1
MVITmaindrve; RESET DRIVES FANS EXPOSE
ANDOUT6
mvitvacuum
andout6
Lpi0

ST36:
LCJMCL 33. STATE4; MCeq512+33eq545
MVISC 4; SET STATE CNTReq4
JMPSTATE4

ST31:
Lpi1
movrOUT6
btchargeon ST32; JMP IF CHARGE IS OFF
Lpi0
MVISC 1; ELSE SET SCeq1
CLB2; AND RESET COIN FLAG
ANDFLG1
JMPINITIAL1

ST32:
Lpi 0
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 chargeon;TURN ON CHARGE
Lpi 1
AND OUT6
Lpi 0
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 chargeon ; RESET CHARGEOFF
Lpi 1
AND OUT6 ; ENDIF
Lpi 0
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 chargeon ; ENDIF
Lpi 1
IOR OUT6 ; ENDIF
Lpi 0
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:
lcjSC 5 STATE6; IF: SC EQ 5
movrIN2; IF: IN ZAP MODE
bt 4ST51
calwrmup

wrmup2:
CLB3.; RESET PRINT FLAG
ANDFLG1
STB0
IORFLG2; ENABLE X CNTR
STBfuser
Lpi1
IOROUT6; SET FUSER
Lpi0

ST53:
lcjXC 60. ST54; IF: X CNTR EQ 60
MVIXC 0.; SET X CNTR eq 0

ST54:
ST55:
lcjMCH 038 ST56 ; IF: MC EQ 14400
lcjMCL 040 ST56
CLB0
ANDFLG1 ; ELSE:
ST56:
JMPSTATE6; JMP TO STATE6
; IF: NOT IN ZAP MODE

ST51:
CLB0 ; DISABLE X CNTR
ANDFLG2 ; RESET JAM LED
MVITfuser ; FUSER & EXPOSURE
Lpi1
ANDOUT6
Lpi0
MVISC 4 ; SET SCeq4
JMPSTATE6
; 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
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:
movrIN2
CPL
bt 0ST694 ; ELSEIF: PRINT SW OFF
STB3 ; RESET ALL OUTPUTS EXCEPT JAM LED
ANDTEMP ; ELSE:
ST694:
movr TEMP ; PUT TEMP IN OUT REG.
;Since the Gnat doesn’t have a jam led, and the print switch has different
; semantics than that on the 2600, this will need to be fixed.
;;;;; movt OUTS ; commented out to assemble.
;
;
; MISC ROUTINE
;
MISC:
CAL INPUT ; REFRESH INPUTS
movrIN2
bt ZCROSSING MISC12 ;IF: ZERO CROSSING TRUE
EIF ; SET INTERRUPT ENABLE
CAL CHKPRNT ; CHECK FOR PRINT COMMAND
Lpi 1
MOVR UFLAG
BT PRNTBIT MISC101
Lpi 0
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:
Lpi 0
STB 3
IOR FLG1 ; SET PRINT FLAG
Lpi 1
movr uflag
bt prntbit misc11
stb patternbit
ior uflag2
MISC11:
Lpi 0
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:
movrFLG1
CPL ; ELSEIF: COIN FLAG SET
bt2MISC141 ; IF: EC EQ 140
lcjEC 140. MISC141
lpi1
STBchargeon; SET CHARGEOFF
IOROUT4; ENDIF
lpi0
MISC141:
lcjEC 247. MISC15 ; ELSEIF: EC EQ 247
CLB5
ANDFLG1 ; DISABLE MOT SENS
lpi1
STBbilling
IOROUT6 ; SET BILLING
lpi 0

;
;
MISC15:
lcj EC 255. MISC16 ; ELSEIF: EC EQ 255
lpi1
CLB billing
AND OUT6 ; RESET BILLING
movr uflag2
bt pagedelbit delivered ; test deliver flag send delivered
misc151:
Lpi 0
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
lpi1
CLB fuser ; RESET FUSER
AND OUT6
lpi 0
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
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 TO STATE 1 ROUTINE.
;
.loc
2FF
LF:
movrWDT
CPL
bt 0LFEND ; IF: WDT FLAG IS SET
CLB0 ; RESET WDT FLAG
ANDWDT
STB0
ADDLFC ; INCR LF CNTR
movrIN2 ; ENDIF
CPL
bt 5LF1 ; IF: 60 HZ MODE
LF11:
movrLFC
bt 0LFEND ; ANDIF: LSB OF LFC NE 1 (DIVIDE 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: Lpi 1
movr uflag2
bt pagedelbit sendjam
clb statbit
and uflag
Lpi 0
jammed:
Lpi 0
;;; MVI OUTS 008 ; CLEAR OUTS SET JAMLED
;;; OUT OUTS 0 ; OUTPUT HERE IN CASE OF JAM:
; we need to notify the keyboard on this machine

Lpi 1
clb patternbit
and uflag2
MVI Out5 laserBeam ;turn off laser
Lpi 0
; 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:
MVIMCL038;SET LSB OF MC eq 038
Lpi1
movruflag
cpl
btcombit jammed;if combit is
mvitreadstat
cmpuartcom
btzsendjam
mvitfeedbot
cmpuartcom
bt z sendjam
Lpi0
JMPjammed; JMP TO jammed

sendjam:
Lpi 1
mvi uartstat jamb
out uartstat datauart
clb prntbit
and uflag
clb combit
and uflag
Lpi 0
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:
INPIN1 0; INPUT SEL SW TO MCH3
MVIT03F
ANDIN1; MASK UNUSED BITS 6 & 7
INPIN2 INPUT1; INPUT MACH INPUTS TO MCH4
RFS; RETURN

wrmup:
Lpi 1
movr UFLAG
bt prntbit sendwrmup
Lpi 0
RFS

sendwrmup:
mvi uartstat warmup
stb statbit
ior uflag
clb prntbit
and uflag
Lpi 0
RFS

.LOC 400
INTHANDLE:
DIF
MVDRTSAVET;SAVE T REG
MOVST;MOVE STATUS REG TO T
MVDRTSR;MOVE T TO SR SAVE REG
LPI2
MVIT 01
ADD WDTtimeout
LCJ WDTtimeout 4 DoChores

MVI WDTtimeout 00
MOVR FLAG2
BT WatchDT zeroWDT
STB WatchDT
movt FLAG2
OUTFLAG2 OUT3; watch dog timer
JMP DoChores

zeroWDT:
MVI FLAG2 Zero
OUTFLAG2 OUT3; watch dog timer
JMP DoChores;


DoChores:
MOVRROUT1
MVIROUT1 0F8;TURN OFF ALL OUTPUT STROBES
ANDROUT1;TO AVOID SHADOWING
OUTROUT1 OUT1
BT0 DO1S;CASE
BT1 DOTENS;THIRD BIT SET
DOLEDS:
STBLEDRTN;SET THE FIRST STROBE BIT
IORROUT1
MOVRROUT0;GET LED INFO INTO T REG
JMPPUTOUTS
DO1S:
STBLEDONE;FIRST BIT SET:
IOR ROUT1; SET THE SECOND STROBE BIT
MOVRDSPONES; ELSE: GET TENS DISPLAY INFO
JMPPUTOUTS
DOTENS:
STBLEDTEN;SECOND BIT SET:
IORROUT1; SET THE THIRD STROBE BIT
MOVRDSPTENS; ELSE: GET TENS DISPLAY INFO

PUTOUTS:
OUTTOUT0;OUTPUT THE NEW DISPLAY INFO
OUTROUT1 OUT1;THEN OUTPUT STROBE TO CHANNEL
;;;
OUTROUT2 OUT2;IN ORIGINAL CODE, NOT HERE

CALKEYBRD
JMP CheckOthers

INCOL4: NOP
INPT 080
RFS
;
INCOL3: NOP
INPT 040
RFS
;
INCOL2: NOP
INPT 020
RFS
;
INCOL1: NOP
INPT 010
RFS

;*********************************************
;
; KEYBOARD READ ROUTINE
;
;*********************************************
;
;
ROW -- ROW INPUT
;
COL -- COLUMN INPUT
;
DSP -- DISPLACEMENT IN KEYBOARD TABLE
;
KBDREG -- DEBOUNCE COUNTER AND ENABLE/DISABLE BITS
;
KEYBRD:
LPI2
LCJKBDREG 0FF READ;KBDREG = FF MEANS
RFS;KEYBOARD IS DISABLED
;
; COLUMN 1
READ:
MVIDSP 0;SET DISPLACEMENT FOR COLUMN 1
CALINCOL1;READ ADDRESS OF COLUMN 1
CALMSBMSK;MASK OFF MSB
JCC NZDECODE;IF NO ENTRY RECOGNIZED
;
PROCEED TO COLUMN 2
; COLUMN 2
MVIDSP 4;SET DISPLACEMENT FOR COLUMN 2
CALINCOL2;READ ADDRESS OF COLUMN 2
CALMSBMSK;MASK OFF MSB
JCC NZDECODE;IF NO ENTRY RECOGNIZED
;PROCEED TO COLUMN 3
; COLUMN 3
MVIDSP 8;SET DISPLACEMENT FOR COLUMN 3
CALINCOL3;READ ADDRESS OF COLUMN 3
CALMSBMSK;MASK OFF MSB
JCC NZDECODE;IF NO ENTRY RECOGNIZED
;PROCEED TO COLUMN 4
; COLUMN 4
MVIDSP 12;SET DISPLACEMENT FOR COLUMN 4
CALINCOL4;;READ ADDRESS OF COLUMN 4
CALMSBMSK;MASK OFF MSB
JCC NZDECODE;IF NO ENTRY RECOGNIZED

; NO ENTRY MADE
MVIT 03F;CLEAR DEBOUNCE BITS 6 & 7
ANDKBDREG;TO SHOW KEY HAS BEEN RELEASED
NOTCLR: RFS;
RETURN (NO ENTRIES MADE)

;*********************************************
;
; DECODE INPUTTED COLUMN;
;
;*********************************************

DECODE:
MOVR KBDREG;MAKE SURE KEY FROM LAST
;ENTRY HAS BEEN RELEASED
BT Bit7 NOTCLR;IF DEBOUNCE BITS ARE NOT CLEAR
;WAIT FOR KEY TO BE RELEASED
; DETERMINE ROW
MOVR COL;PUT INPUTTED COLUMN IN COL
MVIROW 0;SET UP FOR ROW 1
BTBIT0 ROWFND;
MVIROW 1;SET UP FOR ROW 2
BTBIT1 ROWFND
MVIROW 2;SET UP FOR ROW 3
BTBIT2 ROWFND
MVIROW 3;SET UP FOR ROW 4
BTBIT3 ROWFND
;
; SHOULD NOT GET HERE
RFS
;

ROWFND: MOVR ROW
ADDDSP;ADD ROW TO COLUMN DISPLACEMENT
MVIT (KBDtblLoc&0FF)
ADDDSP;ADD KEYBOARD TABLE ADDRESS TO DSP
MOVR DSP
MPM (HiAddr↑-8);LOAD ADDRESS OF ENTRY (OR ADDRESS)
MOVTDSP;AND STORE IT IN DSP

; DEBOUNCE
STBBIT6;SET T TO 40 (BIT 6 OF T)
ADDKBDREG;BITS 6 & 7 ARE USED FOR DEBOUNCE
MOVR KBDREG
BT BIT7 RECENT;DEBOUNCE IS COMPLETE if BIT7 is set
RFS;otherwise wait for another round

;*******************************************
;
; KEYBOARD ENTRY RECOGNIZED
;
;*******************************************
;
RECENT: LPI
2
;;;
MVIT 10
MVIT 9
CMPDSP
JCC N TabDispatch;IF DISPLACEMENT IS >= 10
;
ENTRY IS A FUNCTION
;;;
JGENUMBER;IF DISPLACEMENT IS >= 10
;
ENTRY IS A FUNCTION
JMP NUMBER;
TabDispatch: JMP RealDispatch
;*********************************************
;
; NUMBER ENTRY RECOGNIZED
;
;*********************************************
;
; CHECK FOR FIRST NUMBER ENTERED
;
.LOC 0100;

NUMBER: MOVR KBDREG
BTTENENT NOENT
BTONEENT TRYTENS;IF ONES ENTRY ALREADY MADE
STBONEENT;TRY FOR TENS ENTRY
IORKBDREG;ELSE
CALENTER0;SET ONES ENTRY FLAG
MVIT 0F0;SET IST ZERO ENTRY FLAG
ANDCPYSEL;SEND KEY INFO TO SERVER
JMPDSPNUM;IF OFF LINE
;DISPLAY KEY ENTRY
; SECOND NUMBER
TRYTENS: STB
ONEENT;DISABLE ONES ENTRY
IORKBDREG
CALENTER0;SET 2ND ZERO ENTRY FLAG
MOVR CPYSEL
ADDCPYSEL
MOVR CPYSEL;START SHIFTING ONES ENTRY
ADDCPYSEL;TO TENS
MOVR CPYSEL
ADDCPYSEL
MOVR CPYSEL
ADDCPYSEL
DSPNUM: MOVR DSP
IORCPYSEL;DISPLAY KEY ENTRY
CALKEYCODE;SEND KEY INFO TO SERVER
CALSELDSP;DISPLAY IT TOO
NOENT: RFS

MSBMSK: CPL;
RETURNED IN T (0 = ON)
MVICOL 00F;
ANDCOL;MASK OFF BITS 4 THRU 7
RFS

;*************************************************************
; MACHINE FUNCTIONS JUMPED TO FROM KEYBOARD
; SCAN IF THE RESPECTIVE FUNCTION SWITCH IS MADE
; NOTE THAT ALL KYBD FUNCTION LABELS MUST START
; AFTER ADDRESS 0180 AS THIS DISTINGUISHES
; FROM NUMERIC KEYS.
;*************************************************************
;
;
;
.LOC 0200
RealDispatch:
MOVR DSP;ACTIVATE FUNCTION KEY
JIT

HiAddr = .
;***************************
; OFF LINE FUNCTION
; SUBROUTINE
;***************************
OffLineRoutine:
STB OFFLINE;set the off-line led
IORROUT0
CLBONLINE;deactivate the on-line led
ANDROUT0
RFS


;************************************
;
; FUNCTION SWITCH FOUND
;
;************************************

;************************************
;
; NO ACTION FUNCTION KEY
;
;************************************

NOACTN:
RFS
Clear:
RFS;
OnLineRoutine:
RFS;
TEST:
RFS;
STOP: RFS;
;*****************************************************
; KEYBOARD DECODE TABLE
; FUNCTIONS ARE ADDRESS INFORMATION, AND DIGITS ARE
; SEGMENT INFORMATION.
;*****************************************************
KBDtblLoc = .
KBDTBL:
01;ONE
04;FOUR
07;SEVEN
OffLineRoutine-HiAddr;OFFLINE - SPARE
02;TWO
05;FIVE
08;EIGHT
00;ZERO
03;THREE
06;SIX
09;NINE
Clear-HiAddr;CLEAR
OffLineRoutine-HiAddr;OFF LINE
OffLineRoutine-HiAddr;OFF LINE
OffLineRoutine-HiAddr;OFF LINE
OffLineRoutine-HiAddr;OFF LINE

;extra entries for screwed-up keyboard
OffLineRoutine-HiAddr;OFF LINE
OffLineRoutine-HiAddr;OFF LINE
Stop-HiAddr;STOP
OffLineRoutine-HiAddr;OFF LINE
TEST-HiAddr;;TEST

DspTblLoc = .
DSPTBL:
3F;DIGIT 0
06;DIGIT 1
5B;DIGIT 2
4F;DIGIT 3
66;DIGIT 4
6D;DIGIT 5
7D;DIGIT 6
07;DIGIT 7
7F;DIGIT 8
67;DIGIT 9
9E;DIGIT J
38;DIGIT L
39;DIGIT C
5E;DIGIT D
79;DIGIT E
71;DIGIT F

;***********************************
; Start a new story here
;***********************************
;************************************
;
; KEYBOARD ENTRY IS DECODED *
; HERE FOR KEY STATUS TRANS- *
; MISSION TO SERVER. *
; *
;************************************
KEYCODE:
;;;
LPI1
MOVRROUT0
BTOFFLINE KEYRET;IF ON-LINE MODE
;;;;
LPI00
MVICPYSEL 00;DO NOT STORE KEY INFO
MOVRDSP
LPI2
MVITEMP6 030;DECODE KEY INFO
IORTEMP6
MOVRTEMP6
;;
OUTTDATARW; &TRANSMIT IT TO SERVER
KEYRET:;;;;
LPI0
RETN:
RFS;ELSE

;*************************************
;
; SUBROUTINE FOR DISPLAYING
; NUMERIC KEY ENTRY DURING
; OFF LINE TEST 1 MODE
;*************************************
;
SELDSP: ;;;;;
LPI1
MOVRROUT0
BTONLINE RETN
;;;;;
LPI0;IF OFF LINE ACTIVE
MOVR CPYSEL;DISPLAY KEY ENTRY

DSPLY:
LPI2
MOVTTEMP4 ;SAVE CHARACTERS
MOVTTEMP5

MVIT00F ;ISOLATE LOW ORDER CHARACTER
AND TEMP4
MVIT 0F0
AND TEMP5
;T wants the within-256-byte displacement within the "page"
MVIT (DspTblLoc&0FF);GET SEGMENT PATTERN FOR
ADD TEMP4;LOW ORDER CHARACTER
MOVR TEMP4;i.e., T←Temp4
MPM(HIADDR↑-8);the "page number" of code
MOVT DSPONES

SF0:
MOVR TEMP5;(we understand this better)
CPL;move high nibble of Temp5 to
BT Bit7 TryBit6; the low nibble
StbBit3
IOR TEMP5
TryBit6:
MOVR TEMP5
CPL
BT Bit6 TryBit5
StbBit2
IOR TEMP5
TryBit5:
MOVR TEMP5
CPL
BT Bit5 TryBit4
StbBit1
IOR TEMP5
TryBit4:
MOVR TEMP5
CPL
BT Bit4 MskTmp
StbBit0
IOR TEMP5
MskTmp:
MVIT 0f
AND TEMP5


SF1:
MVIT (DspTblLoc&0FF)
ADD TEMP5
MOVR TEMP5;GET SEGMENT PATTERN
MPM(HIADDR↑-8);FOR 10S DIGIT
MOVT DSPTENS

MVIT 03F;SURPRESS LEADING 0S
CMPDSPTENS
JCC NZ OK
MOVR ZEROFLG
BT1 OK
MVIDSPTENSBLANK
OK:
RFS

ENTER0:
MOVRZEROFLG ;SET 1ST & 2ND ZERO ENTRY FLAGS
BT0SECOND0 ;IF FIRST BIT SET,
STB0
IORZEROFLG
RFS
SECOND0:
STB1 ;SET THE SECOND BIT
IORZEROFLG
RFS
;******************************************************
;** END OF INTERRUPT CODE ***
;******************************************************
CHeckOthers:
movr uflag
bt prntbit save;if online printing, forget test.
movr uflag2
cpl
bt patternbit save;test the copier print flag
Lpi 1; 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:
Lpi1
inp IFLAG intflags;input the interupt register
movr IFLAG; T←interupt flags
cpl
bt 1 lineint;if not, go to 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 OUT5
bt Test1 complement
stb Test1
ior OUT5

toggle1:
clr
movt testcounter
jmp save

complement:
clb Test1
and OUT5
jmp toggle1

RESTORE:
IntReturn:
LPI03;this will be overridden with the MOVRS
MOVRSavetRel
MOVRSSaverRel;MOVE REGISTER TO STATUS REGISTER
EXI;enable external interrupts
RFS;enable interrupts in background


SETPGF:
Lpi 1;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:
Lpi 0
MVI WDT 01;SET WDT FLAG UPON INTERUPT
;RESET WATCH DOG TIMER.
Lpi 1;set page flop
OUT OUT3 03;out the output bytes
OUT OUT4 04;
OUT OUT5 05
OUT OUT6 06
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:
Lpi 1
MOVR UFLAG;GET UART FLAGS
BT COMBIT CHKCOM; TEST COM FLAG
Lpi 0;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
Lpi 0;ELSE RFS
RFS

SENDSTAT:
Lpi 0
movr IN2
cpl
bt 04 SENDWARMUP;testing for warmup
movr flg1
bt 03 SENDPRINTING;JUST MEANS ’COPIER’ IS printing
Lpi 1
mvi uartstat ready
stb statbit
ior uflag
jmp clrcomb;enough with the commands

SENDWARMUP:
Lpi 1
mvi uartstat WARMUP
stb statbit
ior uflag
jmp clrcomb

;here if in test mode or printing a file
SENDPRINTING:
Lpi 1
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
Lpi 0
RFS

ONMULTI:
stb multibit
ior uflag
jmp clrcomb
TimerInterrupt:
RFI;

.END;