From fcfeee44cba8743189ea1b6bcab39bd6d68d3641 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Mon, 7 Sep 2026 17:38:37 -0700 Subject: [PATCH] Fixes c64 script. --- .rc.d/c64.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 9 deletions(-) diff --git a/.rc.d/c64.sh b/.rc.d/c64.sh index 3aee5e9..1f8d01d 100755 --- a/.rc.d/c64.sh +++ b/.rc.d/c64.sh @@ -1,9 +1,105 @@ -if [ -f "$HOME/Applications/KickAssembler/KickAss.jar" ]; then - # TODO: typeset may fail if CLASSPATH is already tied by another script. Handle this. - typeset -T CLASSPATH classpath - classpath+="$HOME/Applications/KickAssembler/KickAss.jar" - export CLASSPATH -fi -if [ -d "/Applications/VICE/bin" ]; then - path=(/Applications/VICE/bin $path) -fi +# Setup Commodore 64 development environment (KickAssembler & VICE) +_setup_c64() { + [ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob + + _add_to_path() { + [ -d "$1" ] || return 0 + case ":$PATH:" in + *":$1:"*) ;; + *) PATH="$1:$PATH"; export PATH ;; + esac + } + + _add_to_classpath() { + [ -f "$1" ] || return 0 + case ":$CLASSPATH:" in + *":$1:"*) ;; + *) CLASSPATH="${CLASSPATH:+$CLASSPATH:}$1"; export CLASSPATH ;; + esac + } + + # 1. KickAssembler search locations (macOS and Linux) + _kickass_candidates=( + "${KICKASS_JAR:-}" + "${KICKASS_HOME:-}/KickAss.jar" + "${KICKASSEMBLER_HOME:-}/KickAss.jar" + "$HOME/Applications/KickAssembler/KickAss.jar" + "$HOME/Applications/KickAssembler/kickass.jar" + "/Applications/KickAssembler/KickAss.jar" + "/Applications/KickAssembler/kickass.jar" + "$HOME/Applications/KickAss/KickAss.jar" + "/Applications/KickAss/KickAss.jar" + "/opt/homebrew/share/kickassembler/KickAss.jar" + "/usr/local/share/kickassembler/KickAss.jar" + "/opt/kickassembler/KickAss.jar" + "/usr/share/kickassembler/KickAss.jar" + "$HOME/.local/share/kickassembler/KickAss.jar" + "$HOME/kickassembler/KickAss.jar" + "$HOME/KickAssembler/KickAss.jar" + ) + + _found_kickass_jar="" + for _jar in "${_kickass_candidates[@]}"; do + if [ -n "$_jar" ] && [ -f "$_jar" ]; then + _found_kickass_jar="$_jar" + break + fi + done + + if [ -n "$_found_kickass_jar" ]; then + _add_to_classpath "$_found_kickass_jar" + _kickass_dir="$(dirname "$_found_kickass_jar")" + _add_to_path "$_kickass_dir" + export KICKASS_HOME="$_kickass_dir" + export KICKASS_JAR="$_found_kickass_jar" + + if ! command -v kickass >/dev/null 2>&1; then + kickass() { + java -jar "$KICKASS_JAR" "$@" + } + fi + fi + + # 2. VICE search locations (macOS and Linux) + _vice_candidates=( + "${VICE_HOME:-}/bin" + "${VICE_HOME:-}" + "$HOME/Applications/VICE/bin" + "/Applications/VICE/bin" + "$HOME/Applications/VICE.app/Contents/Resources/bin" + "/Applications/VICE.app/Contents/Resources/bin" + "$HOME/Applications/VICE.app/Contents/MacOS" + "/Applications/VICE.app/Contents/MacOS" + "/opt/homebrew/opt/vice/bin" + "/opt/homebrew/bin" + "/usr/local/opt/vice/bin" + "/usr/local/bin" + "/opt/vice/bin" + "/usr/bin" + ) + + _found_vice_bin="" + for _vdir in "${_vice_candidates[@]}"; do + if [ -n "$_vdir" ] && [ -d "$_vdir" ]; then + if [ -x "$_vdir/x64sc" ] || [ -x "$_vdir/x64" ] || [ -x "$_vdir/c1541" ] || [ -x "$_vdir/vice" ]; then + _found_vice_bin="$_vdir" + break + elif case "$_vdir" in *VICE*bin*|*vice*bin*) true ;; *) false ;; esac; then + _found_vice_bin="$_vdir" + break + fi + fi + done + + if [ -n "$_found_vice_bin" ]; then + _add_to_path "$_found_vice_bin" + if [ -z "$VICE_HOME" ]; then + case "$_found_vice_bin" in + */bin) export VICE_HOME="$(dirname "$_found_vice_bin")" ;; + *) export VICE_HOME="$_found_vice_bin" ;; + esac + fi + fi +} +_setup_c64 +unset -f _setup_c64 _add_to_path _add_to_classpath