'Any registers used here are preserved in the poke statement (next line+5)
Interrupt:If TOFlag = True then
'Timer event has occurred
Inc wGlobalTick 'Runs continually (100mS counter)
'
Poke rIntStack, bTimerStatus 'Preserve variable - whatever happened to be in the reg at the time
Peek rTimersStatus, bTimerStatus 'Fetch status for all software timers
'
Dec bMainTimer 'Main Timer runs continuously
If bMainTimer = 0 Then 'If just expired...
tMainTimer = True
bMainTimer = cMainTimerVal 'Reinitiate timer
EndIf
'
If bDelayTimer <> cNotRunning Then 'Delay Timer runs on demand (non blocking)
Dec bDelayTimer ' and is running
If bDelayTimer = 0 Then 'If just expired...
tDelayTimer = True
'SerTxd("++++")
EndIf 'Note: next Timer Event will set bDelayTimer to cNotRunning
EndIf
If bEventTimer <> cNotRunning Then 'Event Timer runs on demand (blocks other events)
Dec bEventTimer ' and is running
If bEventTimer = 0 Then 'If just expired...
tEventTimer = True
EndIf 'Note: next Timer Event will set bEventTimer to cNotRunning
EndIf
If bKeyTimer <> cKeyTimerDisabled Then'Keypad key is currently held
Inc bKeyTimer
EndIf
Poke rTimersStatus, bTimerStatus 'Save status for all software timers
Peek rIntStack, bTimerStatus 'Preserve variable(s)
'
Timer = tmrIntOn1stTick 'Sequence changed v3.03
TOFlag = False
SetIntFlags flgBGTimerOnly, mskBGTimerOnly 'Set timer 0 to interrupt (Slot 0)
EndIf
'Both Timer and hInt interrupts can occur during the same instruction cycle: must check both
If hIntFlag = True Then 'was If hInt1Flag = True Or hInt2Flag = True Then
'Hardware Interrupt has occurred: Keyboard event has occurred
'Note that bLCount (b18) is a global variable that is clocking data out
' the 74LS164 keypad driver via sub ShiftRegOut:
hIntFlag = False 'Must clear hIntFlags to
hInt1Flag = False ' ensure that execution does not
hInt2Flag = False ' reenter here on timer interrupts
Poke rIntStack, bKBDStatus, bKBDValue 'Preserve any previous values in variable(s)
Peek rKeyStatus, bKBDStatus 'Get the keyboard status (byte)
Peek rKeyStore, bKBDValue 'Get any existing key value (byte)
If bKBDStatus = 0 Then 'Fresh new keypress
tKeyUnreslvd = True 'That's bit 5 of b0
bKeyTimer = cTimerStart 'Start the long-held-key timer
ElseIf tKeyUnreslvd = True Then '(Bit 6) Resolve the key. (2nd interrupt for this keypress)
tKeyUnreslvd = False 'Clear 'Unresolved' bit. KeyShift may have been set already.
bKBDStatus = bKBDStatus Or cKeyDown 'KeyDown: key is identified but still held.
bKBDValue = bLCount 'bLCount (b18) must not be used locally
ElseIf tKeyTimeOut = True Then '(bit 5) Key-held timeout has occurred
bKBDValue = bLCount + 9 'Key-held gives range 10-17 ((1 to 8) + 9) (9&18 handled sep'rtly)
bKBDStatus = cKeyDown 'KeyDown: key is identified as <shifted> but still held
EndIf
Poke rKeyStatus, bKBDStatus 'Store Key status
Poke rKeyStore, bKBDValue 'Store Key value
Peek rIntStack, bKBDStatus, bKBDValue 'Restore variables
'Note: Interrupts are not reenabled here! (Done in Sub ResolveKeys (also Sub ResetKBD))
EndIf
Return