Amendments on August 21, 2023

Initial amendment

After a few afternoons of hacking, I now have a barely working
proof-of-concept NTP client that works on System 6.
(I added _UDPRcv() to tcp.{c,h})
Most of the rest were lifted from jcs's wikipedia Amend repo, and I
wrote main.c that implements the actual client.
My aim is to iron out bugs in this, and then turn it into an INIT
that syncs the clock in my Mac Plus at bootup.
vkoskiv made amendment 1 8 months ago

Amendments on August 22, 2023

Add signed int8_t type

vkoskiv made amendment 2 8 months ago

Few fixes:

- Clean up comments
- Switch precision to signed integer type
- Check ntp_packet size before doing TCPInit()
- Comment udp_buf_size weirdness
vkoskiv made amendment 3 8 months ago

More tidying up around main

- Removed a bunch of unneeded variables
- Add a few more comments to remind later me
vkoskiv made amendment 4 8 months ago

Dump ntp payload in main() instead of io handler & verify origin_ts

We now just store the received payload into the main request, or an
error otherwise. We can then check for errors and continue in main(),
which makes this a bit easier to read.
We're effectively just faking a synchronous _UDPRcv() here, I still
have no idea why doing it synchronously gives me an empty rcvBuff from
vkoskiv made amendment 5 8 months ago

Hack ntp_req_free() to not crash and use it

I have no idea why xfree() crashes the program when I'm freeing
xalloc'd pointers. I'll just put in stack buffers in there instead.
vkoskiv made amendment 6 8 months ago

Yeet calls to xmalloc() and xfree()

I only had two buffers I was allocating anyway, so I just stuck them
on the stack instead. No idea what the stack size is on a machine
this old, and if that changes in different contexts. We'll see.
vkoskiv made amendment 7 8 months ago


I explain how to set up a development environment in Think C, since
it may not be obvious to beginners.
vkoskiv made amendment 8 8 months ago

Actually update system clock :^)

Surprisingly easy, OSUtils provides a simple SetDateTime() that
takes seconds.
Still need to figure out how to configure UTC offset. Will likely
have to be a cdev panel to configure manually, I doubt people worried
about timezone switching in 1991 much.
vkoskiv made amendment 9 8 months ago

Amendments on August 24, 2023

Gate debug prints behind #define and add more prints

These prints are by far the slowest part of the running program, but
quite useful for debugging.
There is now a SLOW_DEBUG_PRINTF define that can be commented out to
disable these prints. In that case, no window opens, MacNTP just does
its thing and exits.
I also added printouts to show the old and new system time, if it was
vkoskiv made amendment 10 8 months ago

Amendments on September 7, 2023

Large rewrite, restructure the project into an INIT

* Moved NTP client to MacNTP.{c,h}
* Rewrite main to work as an INIT
* Load NTP url and utc offset from resourcs
* Fix many bugs
* Add many new bugs
* Remove all ANSI dependencies, it's a big library
* Remove util.{c,h}
* Add basic debugging, uncomment DEBUGGING define in main.c to enable
vkoskiv made amendment 11 7 months ago

Add copyright headers

MIT license. Also copied in the one in tcp.c from upstream.
vkoskiv made amendment 12 7 months ago

Small NTP corrections

* Send actual transmit timestamp and verify it matches
* Use server transmit timestamp to set system clock instead of
the reference timestamp
* Clean up debugging gunk
vkoskiv made amendment 13 7 months ago

Amendments on September 8, 2023

Show icon on startup and remove InitGraf trap

Earlier, I thought that I had to run the NTP querying code in a trap
instead of the main INIT invocation, but I now found that not to be
true. This simplifies main.c quite a bit.
I also fetched a copy of ShowInitIcon, fixed it up a bit, and now we
show the MacNTP icon on startup.
The icon has 3 variants: Pending, Success and Failure.
We initially show the pending variant, and then swap to one of the
other two depending on the result of the NTP query.
vkoskiv made amendment 14 7 months ago

Amendments on September 9, 2023

Purge resources when done to save 8K of system heap

We now no longer need to persist our resources in the system heap for
later trap access, so we now let the system purge them after MacNTP
has run. This saves 8K of system heap.
If MacNTP did end up updating the clock, it sets up the MacTCP driver,
which stays resident in the system heap until the next reboot, bloating
the system heap by 16K. Nothing we can do about that, AFAIK.
I also yanked out two globals we no longer need.
vkoskiv made amendment 15 7 months ago

Amendments on September 13, 2023

Implement a very rough first-pass control panel + fallback option

I honestly thought that the cdev would be the easy part, but the API
is quite weird, and I've had tons of issues just getting text boxes
to work as expected.
It now works just enough to edit the STR resources we use to store
settings. There is no validation yet, that will come later.
There are now two NTP urls, the fallback URL will be tried if the
primary one returns a DNS resolve error.
vkoskiv made amendment 16 7 months ago

Amendments on September 17, 2023

Store UTC offset as string and change some rsrc IDs

Moved the STR resource IDs to the range recommended in literature for
use with cdevs, and stuck them in a header to share between the cdev
and INIT.
We now also store the UTC offset as a full string, rather than just
the minutes as a string. The cdev validates before saving, and the
INIT also checks it before using it.
The cdev now also computes an offset and updates the system clock when
setting the UTC offset, since we don't check it again until reboot,
and even then only if the clock is obviously wrong.
vkoskiv made amendment 17 7 months ago

Amendments on September 20, 2023

Haphazard hacking to try fixing bizarre bugs

I honestly don't know why some of these bugs exist. I've read the
docs several times, and I still have no idea.
The cdev now mostly works. editText boxes still render weird, the
text shifts up and down by 1 or 2 pixels when you edit it.
I don't know where to even begin looking for a solution.
I'm also now handling macDev messages and checking that MacTCP is
present, but System 6 refuses to send the macDev message, despite
the mach resource being correct, according to Inside Macintosh.
- Fixed the bug where a letter appears if you hit CMD+X or similar.
- Hooked up cutDev, copyDev and pasteDev
- Tweaked DITL to be a bit more symmetric.
- The INIT also checks to see if MacTCP is present, and bails out if
if it isn't.
vkoskiv made amendment 18 7 months ago

Display MacNTP errors in cdev

It now shows what went wrong at INIT time if it displayed the X
icon during boot. Error gets cleared when a successful run happens.
If no error, the space is just blank.
Also fixed HideDItem call IDs in closeDev, they were outdated.
vkoskiv made amendment 19 7 months ago