1 | #! /bin/sh -e
|
---|
2 |
|
---|
3 | dest=loom-pce
|
---|
4 | cleanup=1
|
---|
5 | compress=0
|
---|
6 | ext=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 |
|
---|
16 | while [ $# -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
|
---|
45 | done
|
---|
46 |
|
---|
47 | if [ $# -gt 0 ] ; then
|
---|
48 | dest=$1
|
---|
49 | fi
|
---|
50 |
|
---|
51 | # Create an new directory for the final game. Make sure that it's empty
|
---|
52 |
|
---|
53 | mkdir -p "$dest"
|
---|
54 |
|
---|
55 | if [ -n "`ls -A \"$dest\"`" ] ; then
|
---|
56 | echo "$0: Destination directory is not empty: $dest"
|
---|
57 | exit 1
|
---|
58 | fi
|
---|
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 |
|
---|
78 | if [ ! -e loom.bin ] ; then
|
---|
79 | cdrdao read-cd --datafile loom.bin --driver generic-mmc:0x20000 --device /dev/cdrom --read-raw loom.toc
|
---|
80 | fi
|
---|
81 |
|
---|
82 | # If there isn't a CUE file, convert the TOC file into something other
|
---|
83 | # programs can work with.
|
---|
84 |
|
---|
85 | if [ ! -e loom.cue ] ; then
|
---|
86 | toc2cue loom.toc loom.cue
|
---|
87 | fi
|
---|
88 |
|
---|
89 | # Split the BIN/CUE files into individual tracks.
|
---|
90 |
|
---|
91 | bchunk -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 |
|
---|
96 | if [ $compress != 0 ] ; then
|
---|
97 | flac -8 *.wav
|
---|
98 | ext=flac
|
---|
99 | fi
|
---|
100 |
|
---|
101 | mv track01.$ext "$dest"
|
---|
102 |
|
---|
103 | prevnr=02
|
---|
104 |
|
---|
105 | for nr in `seq -w 3 22` ; do
|
---|
106 | mv "track$nr.$ext" "$dest/track$prevnr.$ext"
|
---|
107 | prevnr=$nr
|
---|
108 | done
|
---|
109 |
|
---|
110 | # Finally, use scummvm-tools-cli to extract the oh-so-juicy data files.
|
---|
111 |
|
---|
112 | scummvm-tools-cli --tool extract_loom_tg16 -o "$dest" track02.iso
|
---|
113 |
|
---|
114 | # Cleanup
|
---|
115 |
|
---|
116 | if [ $cleanup != 0 ] ; then
|
---|
117 | rm -f loom.toc track02.iso track23.iso track??.wav
|
---|
118 | fi
|
---|
119 |
|
---|