mirror of
https://github.com/a2-4am/4cade.git
synced 2025-01-29 22:29:51 +00:00
build improvements (no binary changes)
This commit is contained in:
parent
a55bd69fd4
commit
83ca5f91af
4
Makefile
4
Makefile
@ -144,7 +144,7 @@ $(X): $(GAMES.CONF)
|
||||
|
||||
# precompute binary data structure for mega-attract mode configuration file
|
||||
$(ATTRACT.IDX): $(MD)
|
||||
bin/buildokvs.sh < res/ATTRACT.CONF > "$@"
|
||||
bin/buildokvs.py < res/ATTRACT.CONF > "$@"
|
||||
|
||||
# precompute binary data structure and substitute special characters in global help
|
||||
$(HELPTEXT): $(MD)
|
||||
@ -170,7 +170,7 @@ $(SS): $(SS.SOURCES) | $(MD)
|
||||
# precompute binary data structures for each game's mini-attract configuration file
|
||||
$(ATTRACT): $(ATTRACT.SOURCES) | $(MD)
|
||||
mkdir -p "$@"
|
||||
$(PARALLEL) 'bin/buildokvs.sh < "{}" > "$@/{/}"' ::: res/ATTRACT/*
|
||||
$(PARALLEL) 'bin/buildokvs.py < "{}" > "$@/{/}"' ::: res/ATTRACT/*
|
||||
(cd "$(ATTRACT)"/ && for f in [ABCDEFGHIJKLMNOP]*; do echo "$$f"; done) > "$(MINI.ATTRACT0.LIST)"
|
||||
(cd "$(ATTRACT)"/ && for f in [QRSTUVWXYZ]*; do echo "$$f"; done) > "$(MINI.ATTRACT1.LIST)"
|
||||
@touch "$@"
|
||||
|
28
bin/buildokvs.py
Executable file
28
bin/buildokvs.py
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# parameters
|
||||
# stdin - input containing key=value pairs (e.g. res/ATTRACT.CONF or some file in res/ATTRACT/)
|
||||
# stdout - binary OKVS data structure
|
||||
|
||||
import struct
|
||||
import sys
|
||||
|
||||
def build(records):
|
||||
# yield OKVS header (2 x 2 bytes, unsigned int, little-endian)
|
||||
yield struct.pack('<2H', len(records), 0)
|
||||
|
||||
for key, dummy, value in records:
|
||||
# yield record length (1 byte)
|
||||
yield struct.pack('B', len(key) + len(value) + 3)
|
||||
|
||||
# yield key (Pascal-style string)
|
||||
yield struct.pack(f'{len(key)+1}p', key.encode('ascii'))
|
||||
|
||||
# yield value (Pascal-style string)
|
||||
yield struct.pack(f'{len(value)+1}p', value.encode('ascii'))
|
||||
|
||||
if __name__ == "__main__":
|
||||
records = [x.strip() for x in sys.stdin.readlines()]
|
||||
records = [x.partition('=') for x in records if x and x[0] not in ('#', '[')]
|
||||
for b in build(records):
|
||||
sys.stdout.buffer.write(b)
|
@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# make temp file with just the key/value pairs (strip blank lines, comments, eof marker)
|
||||
records=$(mktemp)
|
||||
tr -d "\r" | awk '!/^$|^#/' > "$records"
|
||||
|
||||
# make temp assembly source file that represents the binary OKVS data structure
|
||||
source=$(mktemp)
|
||||
(echo "*=0" # dummy program counter for assembler
|
||||
echo "!le16 $(wc -l <"$records"), 0" # OKVS header
|
||||
while IFS="=" read -r key value; do
|
||||
echo "!byte ${#key}+${#value}+3" # OKVS record length
|
||||
echo "!byte ${#key}" # OKVS key length
|
||||
echo "!text \"$key\"" # OKVS key
|
||||
echo "!byte ${#value}" # OKVS value length
|
||||
echo "!text \"$value\"" # OKVS value
|
||||
done < "$records") > "$source"
|
||||
|
||||
# assemble temp source file into binary OKVS data structure, then output that
|
||||
out=$(mktemp)
|
||||
acme -o "$out" "$source"
|
||||
cat "$out"
|
||||
|
||||
# clean up
|
||||
rm "$out"
|
||||
rm "$source"
|
||||
rm "$records"
|
@ -49,15 +49,13 @@ def build(records, args):
|
||||
!word {record_count:>8}
|
||||
""")
|
||||
|
||||
# yield OKVS record count (2 bytes, unsigned int, little-endian)
|
||||
yield struct.pack('<H', record_count)
|
||||
|
||||
# yield OKVS lookup table address (2 bytes, unsigned int, little-endian)
|
||||
# lookup table is stored after all record data, so first calculate total record size
|
||||
# record_count * (length-prefixed key + length-prefixed value + 8 other bytes)
|
||||
# then lookup table address is that + gSearchIndex + 4 bytes for the OKVS header
|
||||
total_record_size = len("".join([x for xs in records for x in xs[1:]])) + 10*record_count
|
||||
yield struct.pack('<H', total_record_size + gSearchIndex + 4)
|
||||
|
||||
# yield OKVS header (2 x 2 bytes, unsigned int, little-endian)
|
||||
yield struct.pack('<2H', record_count, total_record_size + gSearchIndex + 4)
|
||||
|
||||
rec_key_address = gSearchIndex + 5
|
||||
key_addresses = []
|
||||
|
@ -32,10 +32,9 @@ def build(records, args):
|
||||
else:
|
||||
for flags, key, dummy in games_list:
|
||||
games_cache[key] = (flags, "")
|
||||
record_count = len(records)
|
||||
|
||||
# yield OKVS header (2 x 2 bytes, unsigned int, little-endian)
|
||||
yield struct.pack('<2H', record_count, 0)
|
||||
yield struct.pack('<2H', len(records), 0)
|
||||
|
||||
for key, dummy, value in records:
|
||||
filename = value or key
|
||||
|
Loading…
x
Reference in New Issue
Block a user