IRClock

Post Reply
User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

IRClock

Post by JimmyDansbo »

IRClock shows a digital watch at the top right of the screen in 80x60 mode.
The program relocates it self to golden memory ($400) when run to make room for normal BASIC development.
The program reads the current time from the RTC but afterwards the RTC is not used to keep the time.
The time can be set by poke'ing values into $400 = hours, $401 = minutes and $402 = seconds.

Now you have a handy time-keeper while you program away on your most recent BASIC game.
irclock.png
irclock.png (27.46 KiB) Viewed 6771 times

Try It Now!

Download the program here:
IRCLOCK.PRG
(314 Bytes) Downloaded 537 times
If you really want to see the source, you can go to https://github.com/jimmydansbo/cx16stuff and look for irclock.asm

#R45
Attachments
irclock.zip
(649 Bytes) Downloaded 669 times
Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Re: IRClock

Post by grml »

User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

Re: IRClock

Post by JimmyDansbo »

Because this was written before the system had a working RTC ;)
I may update it in the future, but you are welcome to grab a copy of the code and modify it your self. :D
Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
TomXP411
Posts: 1802
Joined: Tue May 19, 2020 8:49 pm

Re: IRClock

Post by TomXP411 »

Thanks, Jimmy. Does this use interrupts to print the clock?

With the RTC change, this would be a great tutorial for the use of interrupt-driven routines. It's not just a neat example, but it's actually useful, too!
User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

Re: IRClock

Post by JimmyDansbo »

It does use interrupt to draw the clock and my main goal with the program was to have a small working example on how to install an interrupt handler.
Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

Re: IRClock

Post by JimmyDansbo »

Now updated to read startup time from RTC
Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
Xiphod
Posts: 568
Joined: Thu Apr 15, 2021 8:05 am

Re: IRClock

Post by Xiphod »

Thanks for sharing these notes about the RTC and interrupt. I understand how this is working (using an IRQ to basically "simulate" the old Commodore jiffies count of 60?)

I tried the following in cc65:
__asm__("jsr $ff50"); // lock_get_date_time
__asm__("sta %v", reg_a);
__asm__("stx %v", reg_x);
__asm__("sty %v", reg_y);

And only reg_a is getting populated with the SECONDS count (where I defined reg_a, _x, _y as unsigned char).

Is there really no easier way to get sub-second precision besides something like the IRClock example?

Even if it's not super "atomic clock" like precision, sub-second timing is also useful for animation and movements (like waiting 15 or 30 jiffies) or having priorities (like checking for certain conditions at a high rate vs a slower rate).
Ender
Posts: 220
Joined: Sat May 09, 2020 9:32 pm

Re: IRClock

Post by Ender »

voidstar wrote: Tue May 02, 2023 5:27 pm Thanks for sharing these notes about the RTC and interrupt. I understand how this is working (using an IRQ to basically "simulate" the old Commodore jiffies count of 60?)

I tried the following in cc65:
__asm__("jsr $ff50"); // lock_get_date_time
__asm__("sta %v", reg_a);
__asm__("stx %v", reg_x);
__asm__("sty %v", reg_y);

And only reg_a is getting populated with the SECONDS count (where I defined reg_a, _x, _y as unsigned char).

Is there really no easier way to get sub-second precision besides something like the IRClock example?

Even if it's not super "atomic clock" like precision, sub-second timing is also useful for animation and movements (like waiting 15 or 30 jiffies) or having priorities (like checking for certain conditions at a high rate vs a slower rate).
You could use STTIM and RDTIM, at $FFDB and $FFDE respectively. Those set a timer with jiffie resolution that you can set and get. It uses A as the MSB, X as the middle byte, and Y as the LSB.

Code: Select all

;SET THE CLOCK TO 10 MINUTES = 3600 JIFFIES
     LDA #0               ;MOST SIGNIFICANT
     LDX #>3600
     LDY #<3600           ;LEAST SIGNIFICANT
     JSR $FFDB

Code: Select all

     JSR $FFDE
     STY TIME
     STX TIME+1
     STA TIME+2
Xiphod
Posts: 568
Joined: Thu Apr 15, 2021 8:05 am

Re: IRClock

Post by Xiphod »

That works for me (r42), thanks!
Post Reply