OXYGENHUB
◆ main openmsx / Contrib / reverse_engineering_tools / kanji / rebuild.sh
5.4 KiB · Bourne Again Shell (bash) · executable · last changed chore(): initial commit 1 month ago source blame history raw
1
#!/bin/bash --
2
cd "$( dirname -- "$0" || echo . )" &&
3
printf 'working in directory %q\n' "$( pwd )" &&
4
echo checking for source files &&
5
    ls -d BACONLDR.BIN autoexec.bas cktst31.bcl cktst31.asc ktst31{,a,b,c}.asc ktst31.md rebuild.sh cas2wav.py &&
6
    echo checking for needed tools &&
7
    ls -d "$(
8
        type -p msx_bacon ||
9
            echo ' ... no msx_bacon in $PATH '
10
    )" "$(
11
        type -p zma ||
12
            echo ' ... no zma in $PATH '
13
    )" "$(
14
        type -p openmsx ||
15
            echo ' ... no openmsx in $PATH '
16
    )" "$(
17
        type -p sox ||
18
            echo ' ... no sox in $PATH '
19
    )" "$(
20
        type -p zip ||
21
            echo ' ... no zip in $PATH '
22
    )" "$(
23
        type -p perl ||
24
            echo ' ... no perl in $PATH '
25
    )" "$(
26
        type -p python3 ||
27
            echo ' ... no python3 in $PATH '
28
    )" "$(
29
        type -p sed ||
30
            echo ' ... no sed in $PATH '
31
    )" "$(
32
        type -p dd ||
33
            echo ' ... no dd in $PATH '
34
    )" "$(
35
        type -p wc ||
36
            echo ' ... no wc in $PATH '
37
    )" &&
38
    rm -vf zma.log zma.sym cktst31.asm cktst31.bin "ktst31 [RUN'CAS-'].cas" "ktst31 [RUN'CAS-'].wav" "ktst31 [RUN'CAS-'] [2400bps].wav" ktst31.dsk ktst31.zip &&
39
    {
40
        openmsx --version &&
41
        msx_bacon -original -O3 cktst31.asc cktst31.asm &&
42
            zma cktst31.asm cktst31.bin &&
43
            rm -vf zma.log zma.sym cktst31.asm &&
44
            perl -pi -e 's/SZ=[0-9][0-9]*/SZ='$(( $( LC_ALL=C wc -c < cktst31.bin ) ))'/i' ktst31.asc &&
45
            mkdir -pv /tmp/ktst31.$$ &&
46
            cp -v BACONLDR.BIN autoexec.bas cktst31.bcl cktst31.asc cktst31.bin ktst31{,a,b,c}.asc /tmp/ktst31.$$ &&
47
            dd bs=1024 count=720 if=/dev/zero of=ktst31.dsk &&
48
            echo starting headless openmsx... &&
49
            openmsx -machine Sanyo_PHC-70FD2 -diska ktst31.dsk -diskb /tmp/ktst31.$$ \
50
                    -command 'set fastforward on' \
51
                    -command 'set renderer none' \
52
                    -command 'set old_sound_driver "$sound_driver"' \
53
                    -command 'set sound_driver null' \
54
                    -command 'after time 15 { type -release -freq 10 "_format:copy\"b:????????.???\"to\"a:\":def usr=&h65:?usr(0)\ra2 " }' \
55
                    -command 'after time 30 { set sound_driver "$old_sound_driver"; }' \
56
                    -command 'debug set_bp 0x65 "" { set sound_driver "$old_sound_driver"; exit; }' &&
57
            echo openmsx exited successfully &&
58
            python3 -c 'if True:
59
                import sys
60
61
                _, dsk = sys.argv
62
                buf = open(dsk, "rb").read()
63
                buf = bytes(
64
                    [
65
                            # zero out all timestamps in the first sector of the root directory
66
                            0 if i // 512 == 7 and i % 32 in range(13, 26) else buf[i]
67
                                    for i in range(len(buf))
68
                    ]
69
                )
70
                open(dsk, "wb").write(buf)
71
            ' ktst31.dsk &&
72
            rm -rvf /tmp/ktst31.$$ &&
73
            (
74
                hdr="$(LC_ALL=C printf '\x1f\xa6\xde\xba\xcc\x13\x7d\x74')"
75
                _cat() {
76
                    local f="$@"
77
                    local sz=$(( $( LC_ALL=C wc -c < "$f" | awk '{print $1}' ) ))
78
                    local i=0
79
                    while [[ $i -lt $sz ]]
80
                    do
81
                        echo "_cat $f $i/$sz" >&2
82
                        dd bs=1 skip=$i count=256 < <(
83
                            LC_ALL=C cat "$f"
84
                            dd bs=1 count=256 < /dev/zero 2>/dev/null |
85
                                LC_ALL=C tr '\0' $'\x1A'
86
                        ) 2>/dev/null
87
                        i=$((i+256))
88
                        if [[ $i -lt $sz ]]
89
                        then
90
                            LC_ALL=C printf %s "$hdr"
91
                        fi
92
                    done
93
                    LC_ALL=C printf '\xfe\0\0\0\0\0\0\0'
94
                }
95
                e="$(
96
                    dd bs=1 count=10 if=/dev/zero 2>/dev/null |
97
                        LC_ALL=C tr '\0' $'\xea'
98
                )"
99
                fmt='%s%s%-6s\xfe\0\0\0\0\0\0\0%s'
100
                LC_ALL=C printf "$fmt" "$hdr" "$e" "KTST31" "$hdr"
101
                _cat ktst31.asc
102
                LC_ALL=C printf "$fmt" "$hdr" "$e" "KT31A" "$hdr"
103
                _cat ktst31a.asc
104
                LC_ALL=C printf "$fmt" "$hdr" "$e" "KT31B" "$hdr"
105
                _cat ktst31b.asc
106
                LC_ALL=C printf "$fmt" "$hdr" "$e" "KT31C" "$hdr"
107
                _cat ktst31c.asc
108
            ) | LC_ALL=C sed 's,BLOAD,REM *,gi;s,KTST31[.]ASC,CAS:KTST31,gi;s,\(KT\)ST\(31[A-Z]\)[.]ASC",CAS:\1\2"  ,gi' > "ktst31 [RUN'CAS-'].cas" &&
109
            python3 cas2wav.py "ktst31 [RUN'CAS-'].cas" "ktst31 [RUN'CAS-'].wav" &&
110
            sox -r 44100 "ktst31 [RUN'CAS-'].wav" "ktst31 [RUN'CAS-'] [2400bps].wav" &&
111
            zip -9v ktst31.zip \
112
                BACONLDR.BIN \
113
                autoexec.bas \
114
                cas2wav.py \
115
                cktst31.asc \
116
                cktst31.bcl \
117
                cktst31.bin \
118
                "ktst31 [RUN'CAS-'] [2400bps].wav" \
119
                "ktst31 [RUN'CAS-'].cas" \
120
                "ktst31 [RUN'CAS-'].wav" \
121
                ktst31.asc \
122
                ktst31.dsk \
123
                ktst31.md \
124
                ktst31a.asc \
125
                ktst31b.asc \
126
                ktst31c.asc \
127
                rebuild.sh &&
128
            echo "Success, all rebuild steps completed"
129
    }