Page 1 of 1

Kernal RDTIM returns time wrong way

Posted: Thu Dec 07, 2023 7:08 pm
by Johan Kårlin
The function RDTIM in KERNAL R46 should be fully compatible with the C64 KERNAL RDTIM, but unfortunately, it isn't. According to the C64 Programmer's reference, three bytes are returned by the routine, with the accumulator containing the most significant byte, the X index register containing the next most significant byte, and the Y index register containing the least significant byte.

However, in the X16 KERNAL RDTIM, the most significant byte is returned in .Y, the next most significant byte in .X, and the least significant byte in .A. This is essentially in reverse order compared to the C64 KERNAL RDTIM.

It is uncertain if this is by design, but if so, the function should be documented in the X16 Programmer's guide. Currently, for all C64 KERNAL routines, users are referred to the C64 documentation.

Re: Kernal RDTIM returns time wrong way

Posted: Thu Dec 07, 2023 8:28 pm
by desertfish
Huh,t this is not true? X16 RDTIM does return the same order as on the C64...

This prog8 test program runs identically on the C64 and on X16

ubyte lo ubyte mid ubyte hi repeat { %asm {{ jsr cbm.RDTIM sta p8_lo stx p8_mid sty p8_hi }} txt.print_ubhex(hi, false) txt.print_ubhex(mid, false) txt.print_ubhex(lo, false) txt.nl() }

Re: Kernal RDTIM returns time wrong way

Posted: Thu Dec 07, 2023 9:22 pm
by Johan Kårlin
Ok, my bad, there is no bug. The problem lies in the C64 Programmer's Reference Guide, which contains an error. It says:
Three bytes are returned by the routine. The accumulator contains the most significant byte, the X index register contains the next most significant byte, and the Y index register contains the least significant byte.
On the other hand, Mapping the Commodore 64 says (what must be right):
The .Y register contains the most significant byte (from location 160 ($A0)), the .X register contains the middle byte (from location 161 ($A1)), and the Accumulator contains the least significant byte
It is still a small documentation issue, I guess. The C64 KERNAL routines are not documented in the X16 Programmer's Reference guide, which means that others may fall in the same trap as me.