* RTC TEST PROGAM
* TEST INTERRUPT AND CLOCK MECHANISM
* THE RTC OF THE SIMULATOR IS SYNCHRONIZED WITH THE CLOCK OF THE PC
* THAT RUNS THE SIMULATOR. THIS TEST PROGRAM PRINTS THE WALL TIME AS
* DERIVED FROM THE SIMULATOR CLOCK SO ITS ACCURACY CAN BE CHECKED.
* 
*
 IDENT TSTRTC
 AORG /1000
RTC EQU /3F DEVICE ADDRESS REAL TIME CLOCK
ASR EQU /10 DEVICE ADDRESS TTY
IRTC EQU /44 INTERRUPT ADDRESS CLOCK
S\EQU\1 START
H\EQU\0 HALT
*
ST EQU * START ADDRESS
 INH
 LDKL A14,LSK SET LINK STACK PPOINTER
 LDKL A1,INTCLK ADDRESS CLOCK INTERRUPT ROUTINE
 ST A1,IRTC TO CLOCK INTERRUPT ADDRESS
 LDKL A1,-10 GRID = 1 SECOND (10HZ CLOCK => 10 PULSES IS 1 SEC)
 ST A1,TIME RESET TIME
 LDK A1,0
 ST A1,SEC RESET WALL TIME COUNTERS
 ST A1,MINUTE
 ST A1,HOUR
 CIO A1,S,RTC START CLOCK
 LDKL A1,/FFFF
 WIM A1 DISABLE ALL COMMON LINE INTERRUPTS
*
* READ INITIAL CLOCK VALUES (HOUR/MINUTE) TO SET WALL TIME
RC1 LDK A6,/20 READ HOUR, NUMBER < 24
 CF A14,ASCOUT
 LDK A6,/48
 CF A14,ASCOUT
 CF A14,ASCOUT HH
 CF A14,ASCIN
 SUK A6,/30 1ST DIGIT
MT1 LDR A8,A6
 SLA A6,2 *4
 ADR A8,A6 *5
 ADR A8,A8 *10
 CF A14,ASCIN
 SUK A6,/30 2ND DIGIT
ME1 ADR A8,A6
 CWK A8,24
 RB(6) RC1 AGAIN
 ST A8,HOUR STORE HOUR
*
RC2 LDK A6,/20 READ MINUTE, NUMBER < 60
 CF A14,ASCOUT
 LDK A6,/4D
 CF A14,ASCOUT
 CF A14,ASCOUT MM
 CF A14,ASCIN
 SUK A6,/30 1ST DIGIT
MT2 LDR A8,A6
 SLA A6,2 *4
 ADR A8,A6 *5
 ADR A8,A8 *10
 CF A14,ASCIN
 SUK A6,/30 2ND DIGIT
ME2 ADR A8,A6
 CWK A8,60
 RB(6) RC1 AGAIN
 ST A8,MINUTE STORE MINUTE
 LDK A6,/D
 CF A14,ASCOUT
 LDK A6,/A
 CF A14,ASCOUT
 ENB
*
* LOOP; 1) PRINTS EACH SECOND A *
*       2) PRINTS EACH MINUTE THE WALL TIME
LOOPM LD A6,MINUTE
 ST A6,CHKM
LOOPS LD A6,SEC
 ST A6,CHKS
*
CL0 LD A6,SEC
 CW A6,CHKS
 RB(0) CL0
 LDK A6,/2A * SECOND OVER
 CF A14,ASCOUT
 LD A6,MINUTE
 CW A6,CHKM
 RB(0) LOOPS
 LDK A6,/D MINUTE OVER
 CF A14,ASCOUT
 LDK A6,/A
 CF A14,ASCOUT
*
* PRINT WALL TIME IN DECIMAL
 INH
 LDK A1,0
 LD A2,HOUR
 DVK 10
 LDR A6,A2
 LDR A8,A1 SAVE REMAINDER
 ENB
 ADK A6,/30
 CF A14,ASCOUT
 LDR A6,A8
 ADK A6,/30
 CF A14,ASCOUT
 LDK A6,/3A
 CF A14,ASCOUT
 INH
 LDK A1,0
 LD A2,MINUTE
 DVK 10
 LDR A6,A2
 LDR A8,A1 SAVE REMAINDER
 ENB
 ADK A6,/30
 CF A14,ASCOUT
 LDR A6,A8
 ADK A6,/30
 CF A14,ASCOUT
 RB LOOPM
*
CHKM DATA 0
CHKS DATA 0
* CLOCK DATA
TIME DATA 0
SEC DATA 0
MINUTE DATA 0
HOUR DATA 0
*
* SUBR LINK STACK
 RES 6
LSK EQU *-2
*
* CLOCK INTERRUPT ROUTINE
INTCLK EQU *
 RIT /1B RESET CLOCK INTERRUPT
 IM TIME
 RF(0) KLOK
 RTN A15
*
* GRID OVERFLOW (AFTER 10 PULSES)
KLOK EQU *
 LDKL A1,-10
 ST A1,TIME RESET GRID COUNTER
 LDK A1,0
 LDK A2,1
 LD A3,SEC
 ADR A3,A2
 CWK A3,60
 RF(0) M
 ST A3,SEC
 RTN A15
* SECOND OVERFLOW
M ST A1,SEC
 LD A3,MINUTE
 ADR A3,A2
 CWK A3,60
 RF(0) U
 ST A3,MINUTE
 RTN A15
* MINUTE OVERFLOW
U ST A1,MINUTE
 LD A3,HOUR
 ADR A3,A2
 ST A3,HOUR
 RTN A15
*
* PRINT CHARACTER ON TTY
ASCIN LDK A7,1 INPUT MODE
 CIO A7,S,ASR
 RB(4) *-2
 INR A6,0,ASR
 RB(4) *-2
 ANK A6,/7F MASK 7 BITS
 CIO A7,H,ASR
 SST A7,ASR
 RB(4) *-2
 RTN A14
*
* READ CHARACTER FROM TTY
ASCOUT LDK A7,0 OUTPUT MODE
 CIO A7,S,ASR
 RB(4) *-2
 OTR A6,0,ASR
 RB(4) *-2
 CIO A7,H,ASR
 SST A7,ASR
 RB(4) *-2
 RTN A14
 END

