#!/bin/sh
# DF-2675 ladder: keep target D-buffers (17-page) on cpu5 at positions above
# head(0), sweep cpu0 with fresh .ko reads, detect neighbor clobber via p16watch.
cd /root
# mount image B (100 fresh target dirs)
vnconfig -c vn1 /root/fat64kB.img
mkdir -p /mntB
mount_msdos /dev/vn1 /mntB || exit 1
NEXTP=0
CYCLE=0
while [ $CYCLE -lt 24 ]; do
  CYCLE=$((CYCLE+1))
  # push head(5) with fresh reads of the B image's UNUSED tail (blocks 3300+)
  i=0
  while [ $i -lt 12 ]; do
    /root/pinread 5 /root/fat64kB.img $((17039360 + i * 65536)) 65536 > /dev/null 2>&1
    i=$((i+1))
  done
  # place 5 fresh targets on cpu5
  j=0
  while [ $j -lt 5 ]; do
    D=$(printf "/mntB/B%02d" $NEXTP)
    /root/pindir 5 $D > /dev/null 2>&1
    NEXTP=$((NEXTP+1))
    j=$((j+1))
    if [ $NEXTP -ge 100 ]; then break 2; fi
  done
  # sweep cpu0 with 10 fresh kos
  head -$((20 + CYCLE * 10)) /root/kos.txt | tail -10 > /root/sweepset.txt
  /root/sweep 0 /root/sweepset.txt > /dev/null 2>&1
  H=$(/root/p16watch | grep -v " c=00000000 " | grep OVR | wc -l)
  echo "cycle $CYCLE: targets-placed=$NEXTP clobbered=$H"
  if [ "$H" -gt 0 ]; then echo CLOBBERED; break; fi
done
echo "=== final"
/root/p16watch
