Classic Computer Magazine Archive PROGRAM LISTING: 82-10/ACLOCK.SRC


;"ACCURATE" CLOCK MODULE
;Copyright Pete Goodeve, 1982
;=========================
;
;occupies cassette buffer
;
;Atari OS references:
SETVBV	EQU	$E45C		; set-vector entry
SYSVBV	EQU	$E45F		; OS VBLANK service
VVBLKI	EQU	$222		; immed. VBLANK vector
CRITIC	EQU	$42		; critical section flag
CASINI	EQU	$2		; "cassette" init vector
BOOTF	EQU	9		; boot mode flag for init
;
;
	ORG	$400		; cass. buffer(1024 dec)
;
TIMLOK	DB	$FF
SECS	DB	0
MIN	DB	0
HRS	DB	0
DAYS	DB	0
;
CNT60	DB	60		; VBLANK ticks
CSECS	DB	0		; contin. count
ASECS	DB	13		; adjustment count
;
;
INITON	DS	1
;Comes this way on RESET Button
;via "Cassette Init" vector:
RESET
	JSR	NUTHIN		; -- filled before use
SETINT
	LDX	#<CLOCK
	LDY	#>CLOCK
	LDA	#6		; "immediate VBLANK" code
	JSR	SETVBV		; set up interr# vect,
NUTHIN
	RTS
;
;
;Immed VBLANK interrupt service
;comes through here first:
;
CLOCK
	DEC	CNT60		; count 60 ticks
	BNE	XIT		; before doing anything
	INC	CSECS		; keep track of seconds
	LDX	#60		; (kept around for later)
	STX	CNT60		; reset count
	LDA	CRITIC		; check if critical
	ORA	TIMLOK		; or if locked by user
	BNE	XIT		; gotta stop here
; continue on if not critical
; or locked ...:
; repeats if seconds were missed
CLKLP
	DEC	ASECS		; 13 second count down
	BNE	TICK
	LDA	#13
	STA	ASECS		; reset 13-sec count
	DEC	CNT60		; and skip one tick
TICK
	INC	SECS		; user's time
	CPX	SECS		; reached 60 yet!
	BNE	TOK		; nops
	LDY	#0
	STY	SECS		; reset seconds
	INC	MIN		; and bump minutes
	CPX	MIN		; over the hour?
	BNE	TOK		; not yet
	STY	MIN		; and so on
	INC	HRS
	LDA	#24
	CMP	HRS
	BNE	TOK
	STY	HRS
	INC	DAYS
;...etc. if needed
TOK
	DEC	CSECS		; were any missed?
	BNE	CLKLP		; round again if so
VVON	DS	1
;continue with VBLANK chain:
XIT
	JMP	SYSVBV		; altered at setup
;
;
;
;*** INITIAL ENTRY HERE
;gets overwritten by BASIC
WINDIT
	LDX	CASINI+1	; Cassette Init vect
	BEQ	NOINI		; zero if not used
	LDY	CASINI		; rest of current vect
SETON
	STX	INITON+1	; set up JSR address
	STY	INITON		; so stuff gets done
	LDA	#<RESET		; plug in our own
	STA	CASINI+1	; reset sequence
	LDA	#>RESET
	STA	CASINI
	LDA	VVBLKI		; current immed VBLANK
	STA	VVON		; will be done after us
	LDA	VVBLKI+1
	STA	VVON+1
	LDA	BOOTF		; bootstrap mode flag
	ORA	#2		; must include "cassette.'
	STA	BOOTF
	JMP	SETINT		; go set VBLANK vector
;
NOINI
	LDY	#>NUTHIN	; dummy for JSR
	LDX	#<NUTHIN
	BNE	SETON
;
;
;Autostart addr.
	ORG	$2E2		; "init" vector
	DW	WINDIT
;
***	.END


Back to previous page