#!/usr/bin/env bash # Build the phase-3 player in WSL around a C1V1 stream: # # wsl -e bash player32x/build_c1.sh out32/c1v_0 -> out32/c1v_0/player.32x # # Like build_hello.sh: marsdev's 32x-skeleton is copied from the pinned source at build # time (Sega's security bytes stay out of this repo); our files replace m_main.c, # s_main.c and the demo images; the 68000 side loses its backdrop colour cycle. set -euo pipefail HERE="$(cd "$(dirname "$0")/.." && pwd)" MARSDEV="${MARSDEV:-/mnt/d/dev/tools/marsdev/mars}" SKEL="${MARSDEV_SRC:-/mnt/d/dev/tools/_dl/marsdev-src}/examples/32x-skeleton" DATA="$(cd "$1" && pwd)" BUILD="$DATA/build" [ -f "$DATA/stream.c1v" ] || { echo "no $DATA/stream.c1v" >&2; exit 1; } [ "$(git -C "$SKEL/../.." rev-parse HEAD)" = 3318d3f39823154b24ce48bfa5d8fe6e3f6cde3f ] || { echo "marsdev source is not at the pinned revision" >&2; exit 1; } mkdir -p "$BUILD" find "$BUILD" -mindepth 1 -delete # empty it (a Windows handle can pin the directory itself) cp -r "$SKEL"/. "$BUILD"/ rm -f "$BUILD/sh_src/images.c" "$BUILD/sh_src/images.h" cp "$HERE"/player32x/c1/{m_main.c,s_main.c,stream.s,c1asm.s,c1bfly.s,c1_k16.inc,c1dec.c,c1dec.h,c1_tables.h,c1job.h} "$BUILD/sh_src/" sed -i '/vdp_color(0, color_cycle\[col\]);/d' "$BUILD/md_src/md_main.c" # C1_WIDTH=288: a narrower stored picture with black borders (must match the stream). W="${C1_WIDTH:-320}" printf '! Generated by build_c1.sh\n\t.set\tC1_W, %s\n' "$W" > "$BUILD/sh_src/c1_geom.inc" sed -i "s/^SHCCFLAGS = -m2/SHCCFLAGS = -DC1_WIDTH=$W -m2/" "$BUILD/Makefile" # Executable code copied to SDRAM with .data: its own section, so its padding is NOPs. sed -i "s/*(.data .data.*)/*(.data .data.*) *(.sdram_text)/" "$BUILD/sh_src/mars.ld" # after .data: the vectors at 0x06000000 stay put cp "$DATA/stream.c1v" "$BUILD/" # C1_BENCH=1: the player times its kernels first (m_main.c, c1dec.c c1_bench). [ -n "${C1_BENCH:-}" ] && sed -i 's/^SHCCFLAGS = /SHCCFLAGS = -DC1_BENCH /' "$BUILD/Makefile" # C1_PROF=1: COMM ports carry the decode's breakdown (m_main.c). [ -n "${C1_PROF:-}" ] && sed -i 's/^SHCCFLAGS = /SHCCFLAGS = -DC1_PROF /' "$BUILD/Makefile" make -C "$BUILD" MARSDEV="$MARSDEV" TARGET=player cp "$BUILD/player.32x" "$DATA/player.32x" ls -l "$DATA/player.32x"