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.
Kernal RDTIM returns time wrong way
-
- Posts: 292
- Joined: Wed Jun 03, 2020 11:33 am
- Location: Kalmar, Sweden
- desertfish
- Posts: 1098
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Re: Kernal RDTIM returns time wrong way
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() }
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() }
-
- Posts: 292
- Joined: Wed Jun 03, 2020 11:33 am
- Location: Kalmar, Sweden
Re: Kernal RDTIM returns time wrong way
Ok, my bad, there is no bug. The problem lies in the C64 Programmer's Reference Guide, which contains an error. It says:
On the other hand, Mapping the Commodore 64 says (what must be right):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.
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.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