89 lines
3.4 KiB
Bash
Executable file
89 lines
3.4 KiB
Bash
Executable file
#!/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-x68000-serial.sh - both-directions RS-232C gate for the X68000 port.
|
|
#
|
|
# Boots SERIAL.X under the patched MAME with SCC channel A wired to a null_modem
|
|
# on a TCP socket, sends a probe string in, and checks the example echoes it
|
|
# back. That exercises the full chain: elf2x68k -> .X -> xdftool image ->
|
|
# Human68k -> JoeyLib serial HAL -> IOCS -> SCC -> host.
|
|
#
|
|
# Requires: ./install.sh install x68000 -- the patched MAME
|
|
# (installer/patches/mame/0004-x68k-waitstates-rs232-mouse.patch)
|
|
# and the Human68k template image it copies.
|
|
set -uo pipefail
|
|
|
|
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
source "$repo/scripts/lib/joeyEnv.sh"
|
|
joeyNeed MAME mame
|
|
joeyNeed X68K_DIR x68kFirmware
|
|
joeyNeedFile "$X68K_DIR/roms/x68000/cgrom.dat" x68kCgrom
|
|
source "$repo/scripts/lib/x68kDisk.sh"
|
|
ROMS="$X68K_DIR/roms"
|
|
PORT="${X68K_SERIAL_PORT:-6800}"
|
|
# SERTEST (no jlInit, banner then echo) passes the same probe/echo test.
|
|
PROG="${X68K_SERIAL_PROG:-SERIAL}"
|
|
# The host end's line, "BAUD DATABITS PARITY STOPBITS" (e.g. "4800 7 E 1").
|
|
# Empty keeps MAME's null_modem default, 9600 8 N 1. A guest that did not
|
|
# apply its jlSerialConfigT would still be at the default, so running this
|
|
# with a program built for another line proves the settings reach the SCC.
|
|
# Build that program with the matching -DSERIAL_BAUD=... (and SERIAL_DATABITS,
|
|
# SERIAL_PARITY, SERIAL_STOPBITS; see examples/serial/serial.c) and pass its
|
|
# name in X68K_SERIAL_PROG. 19200 and 38400 need RSDRV.SYS, which the boot
|
|
# disk loads (scripts/lib/x68kDisk.sh).
|
|
LINE="${X68K_SERIAL_LINE:-}"
|
|
PROBE="${X68K_SERIAL_PROBE:-JOEYLIB-X68K}"
|
|
MAXWAIT="${X68K_SERIAL_TIMEOUT:-420}"
|
|
|
|
for f in "$MAME" "$X68K_SYSTEM_DISK"; do
|
|
[ -e "$f" ] || { echo "verify-x68000-serial: missing $f" >&2; exit 2; }
|
|
done
|
|
|
|
work=$(mktemp -d -t joey-x68ser.XXXXXX)
|
|
peer=""
|
|
mame=""
|
|
cleanup() {
|
|
joeyStop "$mame" "$peer"
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
# Autorun the program. No ECHO OFF so a load failure is visible in a screenshot.
|
|
x68kBootDisk "$work/serial.xdf" "A:\\$PROG.X" || exit 1
|
|
x68kXdf add "$work/serial.xdf" "$repo/build/x68000/bin/$PROG.X" "$PROG.X" >/dev/null || exit 1
|
|
|
|
# Host end of the link. MAME's null_modem socket form CONNECTS, so we listen.
|
|
python3 "$repo/scripts/x68kSerialPeer.py" \
|
|
--port "$PORT" --probe "$PROBE" --timeout "$MAXWAIT" \
|
|
> "$work/peer.out" 2>&1 &
|
|
peer=$!
|
|
sleep 2
|
|
|
|
# From the work dir, so MAME's cfg/ and nvram/ land there, not in the caller's
|
|
# cwd where the next run would read them back.
|
|
cd "$work" || exit 1
|
|
if [ -n "$LINE" ]; then
|
|
mkdir -p "$work/cfg"
|
|
python3 "$repo/scripts/lib/mameNullModemCfg.py" x68000 :rs232c:null_modem "$LINE" \
|
|
> "$work/cfg/x68000.cfg" || exit 2
|
|
fi
|
|
# MAME runs until the peer has its verdict and is then stopped by PID: waiting
|
|
# out a whole run once the probe has echoed cost minutes per gate. The peer's
|
|
# own deadline (MAXWAIT) bounds the run, and MAME is started directly rather
|
|
# than under timeout, so $! is MAME itself and stopping it orphans nothing.
|
|
"$MAME" x68000 \
|
|
-bios ipl10 -rompath "$ROMS" \
|
|
-flop1 "$work/serial.xdf" \
|
|
-rs232c null_modem -bitb "socket.127.0.0.1:$PORT" \
|
|
-video none -sound none -nothrottle </dev/null >/dev/null 2>&1 &
|
|
mame=$!
|
|
|
|
wait "$peer"
|
|
rc=$?
|
|
peer=""
|
|
joeyStop "$mame"
|
|
mame=""
|
|
cat "$work/peer.out"
|
|
exit $rc
|