Ticket #13248: extract-loom-pce.3.sh

File extract-loom-pce.3.sh, 2.8 KB (added by eriktorbjorn, 3 years ago)
Line 
1#! /bin/sh -e
2
3dest=loom-pce
4cleanup=1
5compress=0
6ext=wav
7
8# This is a proof-of-concept script. I'm at best a bumbling amateur
9# when it comes to shell scripting. # Use this script from an empty
10# directory. Required packages (Debian):
11#
12# - cdrdao
13# - bchunk
14# - flac (optional)
15
16while [ $# -gt 0 ] ; do
17 case $1 in
18 --help)
19 echo "Usage: $0 [OPTION] [DEST]"
20 echo " --help This text"
21 echo " --keep Do not remove temporary files"
22 echo " --compress Compress audio tracks to FLAC"
23 exit 0
24 ;;
25 --keep)
26 cleanup=0
27 ;;
28 --compress)
29 compress=1
30 ;;
31 --)
32 shift
33 break
34 ;;
35 -*)
36 echo $0: $1: unrecognized option >&2
37 exit 1
38 ;;
39 *)
40 break
41 ;;
42 esac
43
44 shift
45done
46
47if [ $# -gt 0 ] ; then
48 dest=$1
49fi
50
51# Create an new directory for the final game. Make sure that it's empty
52
53mkdir -p "$dest"
54
55if [ -n "`ls -A \"$dest\"`" ] ; then
56 echo "$0: Destination directory is not empty: $dest"
57 exit 1
58fi
59
60# Rip the CD to hard disk. The cdrdao command has a bewildering number
61# of options, but apparently none for extracting single tracks. Oh
62# well, most of the tracks are interesting in some way.
63#
64# After some experimenting I came up with pretty much the same
65# parameters as in the DOSBox documentation, at which point I decided
66# to just follow their lead. The most interesting bit is probably the
67# 0x20000 option, which ensures the correct byte order for the
68# extracted audio. This allows the resulting BIN/CUE files to be run
69# in the Mednafen emulator, which is useful for testing.
70#
71# It's also possible to do this byte swapping in the bchunk step, by
72# adding the -s option there.
73#
74# This step is time-consuming, so only do it if there isn't already an
75# extracted loom.bin file there. It may be possible to generate a CUE
76# file instead of a TOC file here, but I didn't manage to.
77
78if [ ! -e loom.bin ] ; then
79 cdrdao read-cd --datafile loom.bin --driver generic-mmc:0x20000 --device /dev/cdrom --read-raw loom.toc
80fi
81
82# If there isn't a CUE file, convert the TOC file into something other
83# programs can work with.
84
85if [ ! -e loom.cue ] ; then
86 toc2cue loom.toc loom.cue
87fi
88
89# Split the BIN/CUE files into individual tracks.
90
91bchunk -w loom.bin loom.cue track
92
93# Compress the audio tracks. Note that there is a gap in the numbering
94# because of the data track.
95
96if [ $compress != 0 ] ; then
97 flac -8 *.wav
98 ext=flac
99fi
100
101mv track01.$ext "$dest"
102
103prevnr=02
104
105for nr in `seq -w 3 22` ; do
106 mv "track$nr.$ext" "$dest/track$prevnr.$ext"
107 prevnr=$nr
108done
109
110# Finally, use scummvm-tools-cli to extract the oh-so-juicy data files.
111
112scummvm-tools-cli --tool extract_loom_tg16 -o "$dest" track02.iso
113
114# Cleanup
115
116if [ $cleanup != 0 ] ; then
117 rm -f loom.toc track02.iso track23.iso track??.wav
118fi
119