joeylib2/scripts/verify-iigs-icon.sh

95 lines
3.9 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-iigs-icon.sh - IIgs programs' icons as the Finder shows them.
#
# make bakes every IIgs program a Finder icon file (make/iigs.mk:
# tools/iconBake iigs, type $CA: an icon record for a GS/OS application of
# the program's name, black and white), and make-iigs-disk.sh puts it in the
# JOEYLIB volume's Icons folder, which the Finder reads when it starts. GS/OS
# boots under MAME into its Finder with joey.2mg mounted; the gate opens the
# JOEYLIB window as verify-iigs.sh does (J, then Command-O) and at READ_FRAME
# reads the Super Hi-Res screen out of emulated memory -- the pixels, the
# scan line control bytes and the palettes -- and draws it as it shows in 640
# mode. The window must show the baked icon: every pixel its mask leaves
# opaque, as the two screen pixels QuickDraw draws a 4-bit icon pixel as in
# 640 mode, the first its high two bits and the second its low two. The
# screen's own 2-bit values are compared, so the check does not lean on the
# palette; the icon's colours are the Finder's palette's (tools/iconBake).
#
# Usage: scripts/verify-iigs-icon.sh
# Env: IIGS_ICON_KEEP keep the screen as build/iigs/iigs-icon.png
# MAME_READ_FRAME the frame the screen is read at (default 5400)
# Exit: 0 PASS, 1 FAIL, 2 SKIP (MAME or the IIgs firmware not installed,
# or joey.2mg not built)
# Requires: ./install.sh install emulator:iigs;
# build/iigs/bin/joey.2mg (make iigs-disk).
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
joeyNeed MAME mame
joeyNeed IIGS_ROMPATH iigsFirmware
joeyNeed GSOS_SYSTEM_DISK iigsFirmware
label=verify-iigs-icon
data_disk=$repo/build/iigs/bin/joey.2mg
icon=$repo/build/iigs/icon/DRAW/finder.icons
readFrame="${MAME_READ_FRAME:-5400}"
[ -f "$data_disk" ] && [ -f "$icon" ] || { echo "$label: build the disk first (make iigs-disk)" >&2; exit 2; }
work=$(mktemp -d -t joeylib-iigs-icon.XXXXXX)
trap 'rm -rf "$work"' EXIT
cp "$GSOS_SYSTEM_DISK" "$work/boot.po"
cp "$data_disk" "$work/joey.2mg"
# The Finder keystrokes verify-iigs.sh calibrated: select the JOEYLIB volume
# (J), Command-O to open its window. At readFrame the SHR block, $E1/2000 to
# $E1/9FFF (pixels, scan line control bytes, palettes), goes to shr.bin.
cat > "$work/icon.lua" <<LUA
local mem = manager.machine.devices[":maincpu"].spaces["program"]
local nat = manager.machine.natkeyboard
local frame = 0
local idx = 1
local cmd = manager.machine.ioport.ports[":macadb:KEY3"].fields["Command / Open Apple"]
local function dump()
local out = io.open("$work/shr.bin", "wb")
local chunk = {}
for i = 0, 0x7FFF do
chunk[#chunk + 1] = string.char(mem:read_u8(0xE12000 + i))
if #chunk == 256 then
out:write(table.concat(chunk))
chunk = {}
end
end
out:close()
end
local steps = {
{3000, function() nat:post("J") end},
{3120, function() cmd:set_value(1) end},
{3126, function() nat:post("o") end},
{3180, function() cmd:set_value(0) end},
{$readFrame, function() dump(); manager.machine:exit() end},
}
emu.register_frame_done(function()
frame = frame + 1
while idx <= #steps and frame >= steps[idx][1] do
steps[idx][2]()
idx = idx + 1
end
end)
LUA
(cd "$work" && QT_QPA_PLATFORM=offscreen SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
timeout 300 "$MAME" apple2gs -rompath "$IIGS_ROMPATH" \
-flop3 "$work/boot.po" -flop4 "$work/joey.2mg" \
-video none -sound none -nothrottle \
-autoboot_script "$work/icon.lua" < /dev/null > "$work/mame.log" 2>&1) || true
[ -s "$work/shr.bin" ] || { echo "$label: FAIL - MAME never reached frame $readFrame" >&2; tail -5 "$work/mame.log" >&2; exit 1; }
"$(joeyTool iigsIcon)" "$work/shr.bin" "$icon" "$label" "${IIGS_ICON_KEEP:+$repo/build/iigs/iigs-icon.png}"