Skip to content

Retry the UDP read until the NTP reply arrives - #2

Open
JC-000 wants to merge 1 commit into
Pernotto:mainfrom
JC-000:retry-socket-read
Open

JC-000 wants to merge 1 commit into
Pernotto:mainfrom
JC-000:retry-socket-read

Conversation

@JC-000

@JC-000 JC-000 commented Nov 13, 2026

Copy link
Copy Markdown

Fixes #1

u-time.c sends the request and does a single uii_socketread(). An empty READ answers 02,NO DATA with count $FFFF, and CheckStatus() ends the program on it. So the program only works if the reply is already back when it reads. Firmware that waits 40 ms (3.12a to 3.15) gives a fast server that much time; firmware that answers an empty READ at once does not. From reading the firmware source, that is 3.0 to 3.11 (not tested), and it is the change proposed in GideonZ/1541ultimate#1087 (tested below).

Change

u-time.c only, +15/-2:

  • Read again while the status is 02, for up to 5 seconds measured with clock().
  • Any other non-00 status still stops the program as before.
  • On timeout, print "No reply from " and leave the clock alone.

clock() needs the KERNAL jiffy interrupt, which is running when the program starts from BASIC.

Testing

Built with cl65 -O -t c64 and cl65 -O -t c128 (cc65 2.18), no errors. The tracked target/ PRGs and D64 are not rebuilt in this PR.

For the tests I built the program with host in u-time.c (line 56) pointing at a local test server instead of pool.ntp.org; that change is not in the PR. I ran it on a C64 Ultimate (it reports itself as Ultimate 64-II) with each firmware loaded by JTAG (no flashing), and on an Ultimate 64 Elite with the no-wait firmware. The NTP server was a small script on the local network that answers every request after a set delay with a fixed time. A run counts as correct if the screen shows that time. Five runs per cell, correct runs out of five:

Server delay No-wait firmware, unchanged No-wait firmware, this PR 40 ms firmware, unchanged 40 ms firmware, this PR
0 ms 5/5 5/5 5/5 5/5
20 ms 0/5 5/5 5/5 5/5
100 ms 0/5 5/5 0/5 5/5
1000 ms 0/5 5/5 0/5 5/5

The Ultimate 64 Elite on the no-wait firmware gave the same result at 0, 100 and 1000 ms (unchanged 5/5, 0/5, 0/5; this PR 5/5 at all three). An unchanged program ends with "Status: 02,NO DATA: 11"; the changed one sets the clock.

Written with Claude Sonnet 5.5 in Claude Code.

The program sent its NTP request and then did a single socket READ.
That only works if the reply is already queued when the READ runs.
Newer Ultimate firmware answers an empty READ at once (status 02,
count -1), so the program stopped with no data. Ask again until data
arrives or 5 seconds have passed on clock(), and report "No reply"
on timeout.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

u-time stops with "Status: 02" when the NTP reply is not there yet

1 participant