|
|
1.1 ! root 1: #!/bin/sh ! 2: # ! 3: # script to set first Atari program args when it starts ! 4: # ! 5: # this is achieved by chaining breakpoints from Hatari ! 6: # startup to program startup. ! 7: ! 8: # path to (2015) hatari version which debugger provides "basepage" variable ! 9: hatari=hatari ! 10: ! 11: # where temporary debugger scripts will be stored ! 12: dir=/tmp/hatari-debugger.tmp ! 13: ! 14: usage () ! 15: { ! 16: name=${0##*/} ! 17: echo "usage: $name [Hatari args] -- <Atari program> <program args>" ! 18: echo ! 19: echo "Script for running Hatari so that it autostarts given Atari program" ! 20: echo "and inserts given arguments to program (to its basepage, with builtin" ! 21: echo "Hatari debugger facilities)." ! 22: echo ! 23: echo "If arguments have same (host) path prefix as given Atari program," ! 24: echo "those prefixes are replaced with 'C:\', Unix path separators ('/')" ! 25: echo "are replaced with Atari ones ('\\') and whole filename upper-cased." ! 26: echo ! 27: echo "Other arguments are passed unmodified." ! 28: echo ! 29: echo "Example:" ! 30: echo " $name -m -- atari/sidplay.ttp atari/sids/test.sid" ! 31: echo ! 32: echo "ERROR: $1!" ! 33: exit 1 ! 34: } ! 35: ! 36: # --------- argument parsing -------- ! 37: ! 38: # generic argument checking ! 39: if [ $# -lt 3 ]; then ! 40: usage "not enough arguments" ! 41: fi ! 42: echo " $* " | grep -q ' -- ' ! 43: if [ $? -ne 0 ]; then ! 44: usage "Separator missing for Hatari -- Atari options" ! 45: fi ! 46: ! 47: # collect/remove hatari arguments ! 48: for arg in $*; do ! 49: shift ! 50: if [ $arg = '--' ]; then ! 51: break ! 52: fi ! 53: hatari="$hatari $arg" ! 54: done ! 55: ! 56: # check atari program ! 57: prg=$1 ! 58: shift ! 59: if [ \! -f $prg ]; then ! 60: usage "given Atari program doesn't exist" ! 61: fi ! 62: ! 63: # builtin shell echo can be broken, so that it interprets backlashes by default, ! 64: # i.e. concatenating '\' path separator with dirname 't', produces TAB, not '\t'... ! 65: # -> use separate echo binary ! 66: echo=$(which echo) ! 67: ! 68: # temporary dir ! 69: mkdir -p $dir ! 70: ! 71: # collect/convert atari program arguments ! 72: args=$dir/args ! 73: rm -f $args ! 74: touch $args ! 75: prefix="" ! 76: drive="C:\\" ! 77: path="${prg%/*}/" ! 78: for arg in $*; do ! 79: if [ "${arg#$path}" != "$arg" ]; then ! 80: # file path needing conversion ! 81: if [ \! -f $arg ]; then ! 82: usage "given file name '$arg' doesn't exits" ! 83: fi ! 84: # prefix with separator & drive letter & remove host path, ! 85: # upper-case, convert path separators ! 86: $echo -n "${prefix}${drive}${arg#$path}" | tr a-z A-Z | tr '/' '\\' >> $args ! 87: else ! 88: $echo -n "${prefix}$arg" >> $args ! 89: fi ! 90: prefix=" " ! 91: shift ! 92: done ! 93: ! 94: # calculate command line lenght and append zero just in case ! 95: cmdlen=$(wc -c $args | awk '{print $1}') ! 96: echo -n "\0" >> $args ! 97: if [ $cmdlen -gt 126 ]; then ! 98: usage "command line is too long, $cmdlen chars (basepage limit is 126)" ! 99: fi ! 100: ! 101: # --------- debugger scripts -------- ! 102: ! 103: # until desktop is up and TOS opens (autostart) INF file, ! 104: # it's not possible to set program breakpoints (0x3D = Fopen()) ! 105: cat > $dir/fopen.ini << EOF ! 106: b GemdosOpcode = 0x3D :once :quiet :trace :file $dir/start.ini ! 107: EOF ! 108: ! 109: # real work can be done when program starts, ! 110: # i.e. PC is at TEXT section beginning ! 111: cat > $dir/start.ini << EOF ! 112: b pc = text :once :trace :quiet :file $dir/basepage.ini ! 113: EOF ! 114: ! 115: # add command line args args to program basepage ! 116: cat > $dir/basepage.ini << EOF ! 117: setopt dec ! 118: w "basepage+0x80" $cmdlen ! 119: l $args "basepage+0x81" ! 120: info basepage ! 121: EOF ! 122: ! 123: # --------- ready, run ---------- ! 124: ! 125: # show args & debugger scripts ! 126: head $dir/* ! 127: ! 128: # run Hatari ! 129: echo $hatari --parse $dir/fopen.ini $prg ! 130: $hatari --parse $dir/fopen.ini $prg ! 131: ! 132: # cleanup ! 133: rm -r $dir
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.