📄 timer8.asm
字号:
;
; ARGUMENTS: fastcall16 BYTE bPeriodValue (passed in A)
; RETURNS: Nothing
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
Timer8_WritePeriod:
_Timer8_WritePeriod:
RAM_PROLOGUE RAM_USE_CLASS_1
mov reg[Timer8_PERIOD_REG], A
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: Timer8_WriteCompareValue
;
; DESCRIPTION:
; Writes compare value into the Compare register (DR2).
;
; NOTE! The Timer user module must be STOPPED in order to write the
; Compare register. (Call Timer8_Stop to disable).
;-----------------------------------------------------------------------------
;
; ARGUMENTS: fastcall16 BYTE bCompareValue (passed in A)
; RETURNS: Nothing
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
Timer8_WriteCompareValue:
_Timer8_WriteCompareValue:
RAM_PROLOGUE RAM_USE_CLASS_1
mov reg[Timer8_COMPARE_REG], A
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: Timer8_bReadCompareValue
;
; DESCRIPTION:
; Reads the Compare register.
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
; RETURNS: fastcall16 BYTE bCompareValue (value of DR2 in the A register)
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
Timer8_bReadCompareValue:
_Timer8_bReadCompareValue:
bTimer8_ReadCompareValue: ; this name deprecated
_bTimer8_ReadCompareValue: ; this name deprecated
RAM_PROLOGUE RAM_USE_CLASS_1
mov A, reg[Timer8_COMPARE_REG]
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: Timer8_bReadTimerSaveCV
;
; DESCRIPTION:
; Returns the value in the Count register (DR0), preserving the
; value in the compare register (DR2).
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
; RETURNS: fastcall16 BYTE bCount (value of DR0 in the A register)
; SIDE EFFECTS:
; 1) May cause an interrupt, if interrupt on Compare is enabled.
; 2) If enabled, Global interrupts are momentarily disabled.
; 3) The user module is stopped momentarily while the compare value is
; restored. This may cause the Count register to miss one or more
; counts depending on the input clock speed.
; 4) The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; THEORY of OPERATION:
; 1) Read and save the Compare register.
; 2) Read the Count register, causing its data to be latched into
; the Compare register.
; 3) Read and save the Counter value, now in the Compare register,
; to the buffer.
; 4) Disable global interrupts
; 5) Halt the timer
; 6) Restore the Compare register values
; 7) Start the Timer again
; 8) Restore global interrupt state
;
Timer8_bReadTimerSaveCV:
_Timer8_bReadTimerSaveCV:
bTimer8_ReadTimerSaveCV: ; this name deprecated
_bTimer8_ReadTimerSaveCV: ; this name deprecated
bTimer8_ReadCounter: ; this name deprecated
_bTimer8_ReadCounter: ; this name deprecated
CpuFlags: equ 0
bCount: equ 1
RAM_PROLOGUE RAM_USE_CLASS_2
mov X, SP ; X <- stack frame pointer
add SP, 2 ; Reserve space for flags, count
mov A, reg[Timer8_CONTROL_REG] ; save the Control register
push A
mov A, reg[Timer8_COMPARE_REG] ; save the Compare register
push A
mov A, reg[Timer8_COUNTER_REG] ; synchronous copy DR2 <- DR0
; This may cause an interrupt!
mov A, reg[Timer8_COMPARE_REG] ; Now grab DR2 (DR0) and save
mov [X+bCount], A
mov A, 0 ; Guess the global interrupt state
tst reg[CPU_SCR0], CPU_SCR0_GIE_MASK ; Currently Disabled?
jz .SetupStatusFlag ; Yes, guess was correct
mov A, FLAG_GLOBAL_IE ; No, modify our guess
.SetupStatusFlag: ; and ...
mov [X+CpuFlags], A ; StackFrame[0] <- Flag Reg image
M8C_DisableGInt ; Disable interrupts globally
Timer8_Stop_M ; Stop the timer
pop A ; Restore the Compare register
mov reg[Timer8_COMPARE_REG], A
pop A ; restore start state of the timer
mov reg[Timer8_CONTROL_REG], A
pop A ; Return result stored in stack frame
RAM_EPILOGUE RAM_USE_CLASS_2
reti ; Flag Reg <- StackFrame[0]
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: Timer8_bReadTimer
;
; DESCRIPTION:
; Performs a software capture of the Count register. A synchronous
; read of the Count register is performed. The timer is NOT stopped.
;
; WARNING - this will cause loss of data in the Compare register.
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
; RETURNS: fastcall16 BYTE bCount, (value of DR0 in the A register)
; SIDE EFFECTS:
; May cause an interrupt.
;
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; THEORY of OPERATION:
; 1) Read the Count register - this causes the count value to be
; latched into the Compare register.
; 2) Read and return the Count register values from the Compare
; registers into the return buffer.
;
Timer8_bReadTimer:
_Timer8_bReadTimer:
bTimer8_ReadTimer: ; this name deprecated
_bTimer8_ReadTimer: ; this name deprecated
bTimer8_CaptureCounter: ; this name deprecated
_bTimer8_CaptureCounter: ; this name deprecated
RAM_PROLOGUE RAM_USE_CLASS_1
mov A, reg[Timer8_COUNTER_REG] ; synchronous copy DR2 <- DR0
; This may cause an interrupt!
mov A, reg[Timer8_COMPARE_REG] ; Return DR2 (actually DR0)
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
; End of File Timer8.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -