2021-10-24 04:26:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-11-16 01:25:32 +00:00
|
|
|
# parameters
|
|
|
|
# stdin - input containing list of game metadata, filename, display name (e.g. GAMES.CONF or some subset of it)
|
|
|
|
# stdout - binary OKVS data structure
|
|
|
|
# 1 - output filename for game count in assembler code format
|
|
|
|
# 2 - input filename of HGR titles, offsets, and sizes
|
|
|
|
# 3 - input filename of DHGR titles, offsets, and sizes
|
|
|
|
|
2021-10-24 04:26:04 +00:00
|
|
|
# make temp file with just the key/value pairs (strip blank lines, comments, eof marker)
|
|
|
|
records=$(mktemp)
|
|
|
|
awk '!/^$|^#|^\[/' > "$records"
|
|
|
|
|
2021-11-16 01:25:32 +00:00
|
|
|
# read logs of offsets & sizes for HGR and DHGR titles
|
|
|
|
# that were generated by an earlier script
|
|
|
|
hgrlog=$(< "$2")
|
|
|
|
dhgrlog=$(< "$3")
|
|
|
|
|
2021-11-13 21:18:58 +00:00
|
|
|
# generate source file with game count
|
|
|
|
(echo ";"
|
|
|
|
echo "; Game count"
|
|
|
|
echo ";"
|
|
|
|
echo "; This file is automatically generated"
|
|
|
|
echo ";"
|
|
|
|
echo "!word $(wc -l < "$records")") > "$1"
|
|
|
|
|
2021-10-24 04:26:04 +00:00
|
|
|
# make temp assembly source file that represents the binary OKVS data structure
|
2021-11-17 19:35:06 +00:00
|
|
|
source=$(mktemp)
|
2021-11-16 18:34:57 +00:00
|
|
|
(echo '*=$6000'
|
|
|
|
echo "!le16 $(wc -l <"$records")" # OKVS header
|
|
|
|
echo "!word KeyLookup"
|
|
|
|
count=0
|
2021-10-24 04:26:04 +00:00
|
|
|
while IFS="=" read -r key value; do
|
2021-11-16 18:34:57 +00:00
|
|
|
count=$((count+1))
|
2021-12-25 21:44:36 +00:00
|
|
|
if [ -z "$dhgrlog" ]; then
|
|
|
|
dhgr="0"
|
|
|
|
else
|
|
|
|
dhgr=$(echo "$key" | cut -c3) # 'has DHGR title screen' flag (0 or 1)
|
|
|
|
fi
|
2021-10-24 04:26:04 +00:00
|
|
|
cheat=$(echo "$key" | cut -c4) # 'cheat category' (0..5)
|
|
|
|
key=$(echo "$key" | cut -d"," -f2)
|
2021-11-16 01:25:32 +00:00
|
|
|
if [ "$dhgr" -eq "0" ]; then
|
|
|
|
offset=$hgrlog
|
|
|
|
size=$hgrlog
|
|
|
|
else
|
|
|
|
offset=$dhgrlog
|
|
|
|
size=$dhgrlog
|
|
|
|
fi
|
|
|
|
offset=$(echo "$offset" | awk -F, '/^'"$key"',/ { print $2 }')
|
|
|
|
size=$(echo "$size" | awk -F, '/^'"$key"',/ { print $3 }')
|
|
|
|
echo "!byte ${#key}+${#value}+10" # OKVS record length
|
2021-11-16 18:34:57 +00:00
|
|
|
echo "Key${count}"
|
2021-10-24 04:26:04 +00:00
|
|
|
echo "!byte ${#key}" # OKVS key length
|
2021-11-14 16:00:50 +00:00
|
|
|
echo "!text \"$key\"" # OKVS key (filename)
|
2021-10-28 00:08:03 +00:00
|
|
|
echo "!byte ${#value}" # OKVS value length
|
2021-11-14 16:00:50 +00:00
|
|
|
echo "!text \"$value\"" # OKVS value (display name)
|
2021-10-28 00:08:03 +00:00
|
|
|
echo "!byte 1"
|
2021-10-24 04:26:04 +00:00
|
|
|
echo "!byte $((dhgr*128))+$cheat"
|
2021-11-16 01:25:32 +00:00
|
|
|
echo "!be24 $offset"
|
|
|
|
echo "!le16 $size"
|
2021-11-16 18:34:57 +00:00
|
|
|
done < "$records"
|
|
|
|
echo "KeyLookup"
|
|
|
|
for i in $(seq $count); do
|
|
|
|
echo "!word Key$i"
|
|
|
|
done
|
|
|
|
) > "$source"
|
2021-10-24 04:26:04 +00:00
|
|
|
|
|
|
|
# assemble temp source file into binary OKVS data structure, then output that
|
|
|
|
out=$(mktemp)
|
|
|
|
acme -o "$out" "$source"
|
|
|
|
cat "$out"
|
|
|
|
|
|
|
|
# clean up
|
|
|
|
rm "$out"
|
2021-11-17 19:35:06 +00:00
|
|
|
rm "$source"
|
2021-10-24 04:26:04 +00:00
|
|
|
rm "$records"
|