NMI TOD clock alarm interrupt #335
Replies: 5 comments 8 replies
-
Cool! There was a hardware bug at midnight IIRC... |
Beta Was this translation helpful? Give feedback.
-
An easy way to show this working is: include tod
settod
setalarm
: go ptod recurse ;
go
|
Beta Was this translation helpful? Give feedback.
-
You'll notice when warp mode in VICE is active, unlike the jiffy clock, TOD isn't sped up. |
Beta Was this translation helpful? Give feedback.
-
I rewrote your code to help myself understand it. It uses Johan's nice decimal \ marker -tod- : vv -tod- v ;
\ time of day ( dsec sec min hour )
: >b 10 /mod 4 lshift or ; \ bcd
: am >r 0 -rot r> >b swap >b rot >b ;
: pm am $80 or ;
\ e.g. 4 30 57 pm -- 0 $57 $30 $84
\ print:
: 00. s>d <# # # #> type ;
: a/p $80 and if 'p' else 'a' then ;
: tod. dup >r $1f and base @ >r hex
00. ':' emit 00. ':' emit 00. drop
r> base ! r> a/p emit ." m " ;
\ fetch/store tod registers:
: c@+ dup c@ swap 1+ ;
: c!- tuck c! 1- ;
: tod@ $dd08 c@+ c@+ c@+ c@ ;
: tod! $dd0b c!- c!- c!- c! ;
\ alarm interrupt & register mode:
: alset! if $84 else 4 then $dd0d c! ;
: almode! if $80 else 0 then $dd0f c! ;
: alarm! 1 almode! tod! 0 almode! ;
\ user interface:
: setalarm 1 alset! alarm! ;
: clalarm 0 alset! ;
: ptod tod@ tod. ;
: lcsr 0 do $9d emit loop ;
: poll key? if key else 0 then ;
: clock begin ptod 11 lcsr poll until ;
\ e.g. 1 23 45 pm tod! page clock
\ benching: e.g. ' slow timed
: slow $a000 dump n n n ;
: timed 0 0 0 0 tod! execute ptod cr ;
: in> source >in @ /string dup >in +! ;
: time in> ['] evaluate timed refill ; Some history of this comment, check edits for full details:
Here's the removed input words in case they might be useful elsewhere: : keyin key dup emit ;
: bcdin chrin '0' - chrin '0' -
dup 9 u> if drop exit then
swap 4 lshift or ; |
Beta Was this translation helpful? Give feedback.
-
restore_handler in interpreter.asm is mostly a copy of the kernal's NMI handler. restore_handler
pha ; save a
txa ; copy x
pha ; save x
tya ; copy y
pha ; save y
lda #$7f ; disable all CIA 2 interrupts
sta $dd0d ;
ldy $dd0d ; save CIA 2 interrupt control register for kernal_nmi
bpl brk_handler ; CIA 2 is not the NMI source if the most significant bit is not set.
kernal_nmi
jmp $fe72 ; all CIA 2 NMI's fall through to the Kernals' RS-232 routines
brk_handler ; all non-CIA NMI (RESTORE key) and brk instructions- via IRQ vector end up here.
pla ; drop y -the return stack will be reset by QUIT anyway
pla ; pull x
tax ; restore parameter stack pointer for QUIT
jmp QUIT ; already under sei from NMI stub in Kernal or from IRQ to brk_handler such as this, as yet, untested: code rsthandler
pha, txa, pha, tya, pha,
$7f lda,# $ddod dup sta, ldy,
0 @: bpl,
tya, 4 and,# 1 @: bne,
$fe72 jmp, 0 @@
pla, pla, tax, ' quit jmp,
1 @@ ' mycode jsr, \ mind yr, $fe72 requires it.
$fe72 jmp, \ let the Kernal deal with the stack
;code
We have the NMI code. Now we want to signal an alarm without causing issues with the console, or another running program. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is a number of applications to exploit the TOD clock.
The alarm, as it is a NMI,
calls QUIT, so it could be used as a watchdog timer.The alarm NMI now only gets cleared by the NMI routine as per Kernal.
Now
ptod
with colons!Leverage the power of your c64 as a clock.
Beta Was this translation helpful? Give feedback.
All reactions