#!/usr/bin/env bash
# check-millis.sh - Host-cc harness for the generic millisecond clock
# (jlpGenericMillisElapsed, the IIgs/Amiga path). Compiles genericPort.c
# with mocked jlpFrameCount/jlpFrameHz (tests/host/millisHost.c) and runs
# frame sequences including the 16-bit wrap.
#
# EXPECTED TO FAIL until the Phase 1 #23 fix lands (the clock runs
# backward at the 65536-frame wrap); after that it must PASS and becomes
# the regression gate. See PERF-AUDIT-PLAN.md Phase 0/Phase 1.
set -euo pipefail

repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cc=${CC:-cc}
work=$(mktemp -d -t joeylib-millis.XXXXXX)
trap 'rm -rf "$work"' EXIT

cd "$repo"
# The BLANK platform block already registers JL_HAS_FRAME_COUNT and
# JL_HAS_FRAME_HZ (blank.c normally supplies them); millisHost.c provides
# the mocks here instead, so no extra -D flags are needed.
"$cc" -DJOEYLIB_PLATFORM_BLANK \
    -Iinclude -Iinclude/joey -Isrc/core -Wall \
    src/generic/genericPort.c tests/host/millisHost.c \
    -o "$work/millisHost"

"$work/millisHost"
