;********************************************************************* ;* Title: code-timer-v00.asm ;********************************************************************* ;* Author: R. Allen Murphey ;* ;* License: Copyright (c) 2020-2022 R. Allen Murphey. All Rights Reserved. ;* ;* Description: VSYNC Timer Handler for Self-Destruct/Time Trial countdown ;* ;* Documentation: Color Computer Technical Reference Manual ;* ;* Include Files: none ;* ;* Assembler: lwasm 1.4.2 ;* ;* Revision History: ;* Rev # Date Who Comments ;* ----- ----------- ------ --------------------------------------- ;* 00 2020-2021 RAM Initial INITTMR and WAITSYNC ;********************************************************************* SECONDS: rmb 2 ; number of seconds to count down HZ rmb 1 ; number of video frames per second FRAMES: rmb 1 ; number of frames to count down to next second ; FIXME ADD PAL 50HZ SUPPORT INITTMR: ; INITIALIZE TIMER pshs D,CC ; save registers orcc #$50 ; stop interrupts lda PIA0BC ; get port B interrupt control ora #%00000011 ; Enable VSYNC interrupts RISING edge sta PIA0BC ; configure it andcc #$EF ; re-enable interrupts ldd #300 ; countdown 300 seconds std SECONDS ; whole seconds counter lda #60 ; NTSC sta HZ ; store in cycles per second sta FRAMES ; set the start frame countdown to HZ too puls D,CC,PC ; restore registers and return WAITSYNC: ; WAIT FOR VSYNC pshs A,CC ; save registers lda PIA0BD ; clear any pending VSYNC WAITSYNC2: lda PIA0BC ; read PIA 0 Port B Control for bit 7 VSYNC bpl WAITSYNC2 ; if bit 7 clear (positive number) then wait more lda PIA0BD ; acknowledge the interrupt with PIA0 Port B Data dec FRAMES ; decrement the frame countdown bne EXITSYNC ; has it been 60/50 frames? no, branch to exit dec SECONDS ; yes, count off a second lda HZ ; reload the VSYNC frame counter sta FRAMES ; set up next 60/50 frame countdown EXITSYNC: puls A,CC,PC ; done waiting in frame sync ;********************************************************************* ;* End of code-timer-v00.asm ;*********************************************************************