#!/usr/bin/env bash # Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License. # See LICENSE.md for license information. # SPDX-License-Identifier: MIT # # verify-win16-input.sh - Typed-character acceptance gate for the Win16 # port. Runs KEYS.EXE on Windows 3.11 under DOSBox # (scripts/lib/win16Gate.sh) at one window pixel per stage pixel # (JOEYLIB_SCALE=1, JOEYLIB_ASPECT=square), types the RetroNet # definition-of-done string with xdotool (X key events DOSBox turns into # the PC keyboard's, which Windows turns into WM_KEYDOWN/WM_CHAR), takes # DOSBox's own screenshot of the 800x600 screen, and decodes the example's # verification scanline (row 198) with scripts/lib/keysRow.py, wherever # Windows put the window. Then the named keys a second key gives # (scripts/lib/keysGate.sh): the keypad's arrows and Enter, and the right # Ctrl and Alt (the key messages' extended bit). A mapper file binds just # these keys and puts the screenshot on F11 (scripts/lib/dosboxKeys.sh): # DOSBox's Ctrl+F5 would hand Windows a Ctrl press. # # Usage: scripts/verify-win16-input.sh # Requires: Windows on DOSBox (install.sh install emulator:win16), Xvfb, # xdotool, python3 + PIL; build/win16/bin/KEYS.EXE (make win16). set -euo pipefail repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) source "$repo/scripts/lib/joeyEnv.sh" source "$repo/scripts/lib/win16Gate.sh" source "$repo/scripts/lib/dosboxKeys.sh" source "$repo/scripts/lib/keysGate.sh" label=verify-win16-input win16Need target="192.168.1.10:6510" program=$(joeyExampleProgram keys win16) [ -f "$program" ] || { echo "$label: build KEYS.EXE first (make win16)" >&2; exit 2; } # Windows' boot and KEYS reaching its poll loop. bootSeconds=10 work=$(mktemp -d -t joeylib-win16-input.XXXXXX) cleanup() { win16Stop rm -rf "$work" } trap cleanup EXIT mkdir -p "$work/program" "$work/shots" cp "$program" "$work/program/KEYS.EXE" win16Stage "$work" "$work/program" KEYS.EXE dosboxKeysMapper "$work/mapper.txt" "${DOSBOX_KEYS_TYPING[@]}" "${DOSBOX_KEYS_NAMED[@]}" WIN16_DOSBOX_ARGS=(--set "capture_dir=$work/shots" --set "mapperfile=$work/mapper.txt") win16Start "$work" JOEYLIB_SCALE=1 JOEYLIB_ASPECT=square sleep "$bootSeconds" win=$(win16Window) || { echo "$label: FAIL - DOSBox window not found" >&2; exit 1; } DISPLAY="$WIN16_DISPLAY" xdotool windowactivate --sync "$win" 2> /dev/null || true DISPLAY="$WIN16_DISPLAY" xdotool type --window "$win" --delay 150 -- "$target" sleep 2 png="$work/typed.png" dosboxShot "$WIN16_DISPLAY" "$win" "$work/shots" "$png" || { echo "$label: FAIL - DOSBox took no screenshot" >&2; exit 1; } found=$(python3 "$repo/scripts/lib/keysRow.py" "$png" "$target" --scale 1) || { echo "$found"; echo "$label: FAIL" >&2; exit 1; } echo "$found" [[ "$found" =~ row\ at\ \(([0-9]+),([0-9]+)\) ]] stageAt="${BASH_REMATCH[1]},$((BASH_REMATCH[2] - 198))" # X's names for the keys (scripts/lib/keysGate.sh's). declare -A xKey=([up]=Up [kp8]=KP_Up [kp2]=KP_Down [kp4]=KP_Left [kp6]=KP_Right [kpenter]=KP_Enter [rctrl]=Control_R [ralt]=Alt_R) KEYS_LABEL=$label keysPress() { DISPLAY="$WIN16_DISPLAY" xdotool keydown --window "$win" "${xKey[$1]}" } keysRelease() { DISPLAY="$WIN16_DISPLAY" xdotool keyup --window "$win" "${xKey[$1]}" } keysRead() { if dosboxShot "$WIN16_DISPLAY" "$win" "$work/shots" "$work/cells.png"; then python3 "$repo/scripts/lib/keysCells.py" "$work/cells.png" --at "$stageAt" else echo "no screenshot" fi } keysRunSteps kp8 kp2 kp4 kp6 kpenter rctrl ralt if [ -n "$KEYS_FAILS" ]; then echo "$label: FAIL - $KEYS_FAILS" >&2 exit 1 fi echo "$label: PASS (typed \"$target\", all ${#target} chars arrived via jlInputGetChar; $KEYS_STEPS named-key steps: the keypad's arrows and Enter, right Ctrl and Alt, Up held with its second key)"