	NAM	INTCLK

* CLOCK PROGRAM FOR MP-T INTERRUPT TIMER
* DISPLAYS TIME IN 12 HOUR FORMAT 12:24.56
*
* UPDATED VERSION BY MIKE DOUGLAS 2/10/2023
* BASED ON THE ORIGINAL INTCLK SOURCE CODE

TIMER	EQU	$8010		ADDRESS OF MP-T BOARD
INEEE	EQU	$E1AC
PDATA1	EQU	$E07E
OUTEEE	EQU	$E1D1
IRQVEC	EQU	$A000

CR	EQU	$0D
LF	EQU	$0A
EOT	EQU	$04
SPACE	EQU	$20

	ORG	$0100
	SEI
	LDX	#MHEAD		DISPLAY HEADING
	JSR	PDATA1
	LDX	#MTIME		AND TIME PROMPT
	JSR	PDATA1
	
	LDX	#MTIME+1	INIT TO INPUT TIME
	LDAA	#CR
	JSR	OUTEEE

LOOP1	JSR	INEEE		INPUT START TIME
	STAA	0,X
	INX
	CPX	#TIMEEND
	BNE	LOOP1

	LDX	#TIMER		POINT TO MP-T BOARD
	LDAA	#$FF		PORT B AS OUTPUT
	STAA	2,X
	LDAA	#$3D		ACCESS DATA REGISTER
	STAA	3,X
	LDAA	#$80		RESET TIMER
	STAA	2,X
	LDAA	#$06		1 SEC TIC
	STAA	2,X
	
	LDX	#TMRINT		POINT SWTBUG TO TIMER ISR
	STX	IRQVEC
	CLI

LOOP2	NOP
	BRA	LOOP2

* INTERRUPT ROUTINE

TMRINT	LDAA	TIMER+2		CLEAR INTERRUPT		
	LDX	#MTIME		INCREMENT TIME
	INC	8,X		SECONDS
	LDAA	8,X
	CMPA	#'9
	BLS	DISPLAY
	LDAB	#'0		WRAP TO 0
	STAB	8,X
	
	INC	7,X		10 SECS
	LDAA	7,X
	CMPA	#'5
	BLS	DISPLAY
	STAB	7,X		WRAP TO 0
	
	INC	5,X		MINUTES
	LDAA	5,X
	CMPA	#'9
	BLS	DISPLAY
	STAB	5,X		WRAP TO 0
	
	INC	4,X		10 MINS
	LDAA	4,X
	CMPA	#'5
	BLS	DISPLAY
	STAB	4,X		WRAP TO 0
	
	INC	2,X		HOURS
	LDAA	2,X
	CMPA	#'2
	BLS	DISPLAY		ONES IS 0,1,2
	
	LDAB	#'1		10 OR GREATER?
	CMPB	1,X
	BEQ	HOURS10		YES
	
	CMPA	#'9
	BLS	DISPLAY
	STAB	1,X		9:59 TO 10:00
	DECB
	STAB	2,X		
	BRA	DISPLAY

HOURS10	STAB	2,X		12:59 TO 1:00
	LDAB	#SPACE
	STAB	1,X

DISPLAY	LDX	#MTIME
	JSR	PDATA1
	RTI

MHEAD	FCB	CR,LF,LF
	FCC	'SWTPC 6800 COMPUTER SYSTEM TIME:'
	FCB	CR,LF,EOT

MTIME	FCB	CR
	FCC	'HH:MM.SS' 
TIMEEND	FCB	EOT
	
	ORG	$A048
	FDB	$0100

	END
