Zeal8bit / Zeal-8-bit-OS

An Operating System for Z80 computers, written in assembly
Apache License 2.0
574 stars 54 forks source link

RTC works in emulation, fails in real hardware #41

Closed Candid-Moe closed 3 weeks ago

Candid-Moe commented 3 weeks ago

I wrote this little Forth word that execute a SYSCALL 22 to get current time and date.

8 buffer: sys-date
: date ( -- )
    22 sys-date 0 0  ( HL DE BC A registers pushed into the stack )
    z80-syscall         ( do the syscall and put the registers in the stack HL DE BC A )
    ." Return code " . cr
    ." Date " sys-date 8 dump cr
    ;

The word works fine in emulation:

Screenshot at 2024-11-05 16-18-35

But in the real Zeal 8-bit board, it doesn't work:

Screenshot at 2024-11-05 16-21-24

The board has a CR2032 battery installed for the RTC (is that necessary) . The voltage is 2.97 v

The boot screen doesn't show an active timer:

Screenshot at 2024-11-05 15-57-23

How to test

You can test in emulation using https://github.com/Candid-Moe/Zorth/blob/main/prod/zorth.bin

For test in real hardware, use https://github.com/Candid-Moe/Zorth/blob/main/prod/os_with_romdisk.img

Zeal8bit commented 3 weeks ago

Hello @Candid-Moe !

What you did is correct, I suspect the RTC is stopped in your case. When you put in a CR battery, the RTC won't start automatically, it needs to be setup. The bit 7 of its register 00 needs to be cleared. This needs to be done every time the RTC battery runs out. The getdate syscall doesn't show this register 0's bit 7.

You have two solutions here, from easiest to hardest:

Candid-Moe commented 3 weeks ago

The "Test Hardware" fixed the problem. Now the clock is ticking but I can't change the date&time. Working on it.