#ifndef _TIME_H #define _TIME_H typedef long time_t; typedef unsigned long clock_t; typedef unsigned int size_t; #define CLOCKS_PER_SEC 60 // IIgs vsync tick (placeholder) struct tm { int tm_sec; // 0..60 (60 = leap second) int tm_min; // 0..59 int tm_hour; // 0..23 int tm_mday; // 1..31 int tm_mon; // 0..11 (Jan=0) int tm_year; // years since 1900 int tm_wday; // 0..6 (Sun=0) int tm_yday; // 0..365 (Jan 1 = 0) int tm_isdst; // > 0 = DST in effect, 0 = not, < 0 = unknown }; time_t time(time_t *t); clock_t clock(void); double difftime(time_t end, time_t start); // Calendar conversions. gmtime and localtime are identical here — // no timezone support; "local" is treated as UTC. // // ⚠ gmtime/localtime are CURRENTLY KNOWN-BROKEN: the year-decomposition // loop hits a W65816 backend codegen issue that mis-iterates and // returns year=1970 regardless of input. Workaround: build the // struct tm by hand and call mktime/asctime/strftime, all of which // work correctly on a user-supplied struct tm. struct tm *gmtime (const time_t *t); struct tm *localtime(const time_t *t); time_t mktime (struct tm *tm); // Text formatting. asctime returns "Sun Jan 1 00:00:00 1970\n" form. // Both functions return a pointer to a static buffer (overwritten on // each call — not thread-safe). char *asctime(const struct tm *tm); char *ctime (const time_t *t); // strftime: format `tm` per `fmt` into `buf` (max `n` bytes incl. // terminator). Supports a useful subset: %Y %m %d %H %M %S %j %w %a // %A %b %B %p %% — sufficient for log timestamps and date display. size_t strftime(char *buf, size_t n, const char *fmt, const struct tm *tm); // Initialise the IIgs Tool Locator so time() can call ReadTimeHex. // Call once before any time() use. Idempotent — repeated calls // are no-ops. clock() works regardless of whether this is called. void iigsToolboxInit(void); #endif