aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2022-11-11 18:34:47 -0500
committerB. Watson <urchlay@slackware.uk>2022-11-11 18:34:47 -0500
commit18da4023b7fb86f96023ed492e11268609ea62d4 (patch)
tree96badbcb5552d0d57424d5f7174cbf88978f5bf7
parentf2a7789fa016371538e64f1220539554769f2e2b (diff)
downloaddla-asm-18da4023b7fb86f96023ed492e11268609ea62d4.tar.gz
Bullet-proof dla2img.sh, update README.txt.
-rw-r--r--README.txt48
-rwxr-xr-xdla2img.sh66
2 files changed, 82 insertions, 32 deletions
diff --git a/README.txt b/README.txt
index f55efbd..6661309 100644
--- a/README.txt
+++ b/README.txt
@@ -68,12 +68,13 @@ black, while the image is generated. Be patient...
After the image is finished generating, the image will be displayed.
The bottom line shows a menu, from which you can choose to:
-- Save: Save the image to disk. You'll be prompted for a filename,
- which must be a complete filespec (examples: D:TEST.DLA,
- D2:THING.DLA). The file will be the raw pixels, 8 per byte, 256
- pixels (32 bytes) per line, 170 lines. Size will be 5440 bytes,
- or 44 sectors on a single-density disk. If an error happens while
- saving, you'll get the chance to retry the save.
+- Save: Save the image to disk. You'll be prompted for a filename.
+ If you don't include a drive spec (e.g. D: or D2:), drive 1 (D:)
+ is assumed.
+ The file will contain the raw pixels, 8 per byte, 256 pixels (32
+ bytes) per line, 170 lines. Size will be 5440 bytes, or 44 sectors
+ on a single-density disk. If an error happens while saving, you'll
+ get the chance to retry the save.
- Redo: Run the generation process again, with the current particle count
and seed type settings.
@@ -89,24 +90,23 @@ Using dla2csv.xex (or just dla2csv)
This program operates almost identically whether it's running on an
Atari or a modern machine.
-First, you will be prompted for an input filename. On the Atari, you
-must include the drive specifier (e.g. D:TEST.DLA or D2:FOO.DLA). This
-must be a file created by the Save option in dla.xex. The file is read
-into memory immediately.
+First, you will be prompted for an input filename[*]. This must be
+a file created by the Save option in dla.xex. The file is read into
+memory immediately.
-Next, choose the line-ending type. Choices are Atari, Unix, and MS
-(aka MS-DOS or Windows). Choose the system under which you'll be
-actually using the CSV file.
+Next, choose the line-ending type. Choices are Atari, Unix (including
+Linux and Mac), and MS (aka MS-DOS or Windows). Choose the system
+under which you'll be actually using the CSV file.
-Next, you're asked for the output filename. On the Atari, this must
-include the drive specifier (e.g. D:OUTPUT.CSV). This file will be
+Next, you're asked for the output filename[*]. This file will be
overwritten if it exists (unless of course it can't be overwritten due
to permissions or the Atari locked-file bit).
Next, the conversion process starts. This takes about one minute on
the Atari, and is instantaneous on a modern machine. Progress is shown
as a percentage. When it's finished, the output CSV file has been
-written.
+written. On the Atari, you can press Ctrl-C during the conversion to
+abort the process (and delete the partial CSV file).
Last, you're asked whether to convert another file. Answering N here
will exit the program. On the Atari, you should be returned to the DOS
@@ -114,6 +114,13 @@ menu or prompt, but your mileage may vary (it works on DOS 2.0S, at
least). Answering Y (or just pressing Return) starts the whole process
over at the input filename prompt.
+[*] On the Atari, if you don't include a drive specifier (e.g. D: or D2:)
+ in the filename, drive 1 (D:) is assumed. Also, when you're asked
+ for the input or output filename, you can enter a number (a single
+ digit) to see a directory of that drive number. If you're using an
+ emulator that supports the H: (host drive) device, you can enter 0
+ to see the directory of H:.
+
Using dla2img.sh
----------------
@@ -147,5 +154,10 @@ shell's $PATH), you can run it as e.g.:
MAGICK=/path/to/magick ./dla2img.sh [arguments]
-dla2img.sh has been tested with various shells, including bash, zsh, ksh93,
-mksh, and dash.
+If you get "stat: command not found",
+Note: dla2img.sh has been tested with various shells, including bash,
+zsh, ksh93, pdksh, mksh, dash, and bosh (from Schily-tools)... and
+the ancient V7 UNIX Bourne shell compiled for Linux from AT&T source
+(seriouly). If your system doesn't have a /bin/sh that's compatible,
+edit the script and change the "#!/bin/sh" to something that works on
+your system.
diff --git a/dla2img.sh b/dla2img.sh
index f765b69..4258947 100755
--- a/dla2img.sh
+++ b/dla2img.sh
@@ -1,18 +1,35 @@
#!/bin/sh
-# This script tested with bash 5.1, zsh 5.8, ksh 93u, and dash 0.5.11.4.
-# If your environment doesn't have a shell compatible with one of those,
-# I can't help you.
+# This script deliberately written with old-school shell syntax, to
+# support as many Bourne-like shells as possible. Do not complain that
+# backticks are deprecated: this is supposed to (potentially) work
+# on ancient shells that might exist on e.g. an Atari ST or Amiga. It
+# *does* work on a wide variety of modern shells.
-SELF="$(basename $0)"
+# The only required external commands we call are magick, rm, and cat.
+# If stat is present, it will be called (but no problem, if it's
+# missing).
+
+# Tested with ImageMagick 7.1, but doesn't use any fancy features so
+# it should work with any fairly recent ImageMagick.
+
+SELF="`basename $0`"
# allow overriding magick path via environment.
-MAGICK=${MAGICK:-magick}
+if [ "$MAGICK" = "" ]; then
+ MAGICK="magick"
+fi
# only change this if the save file size changes in dla.xex.
SIZE="256x170"
-usage() {
+# ...and if you change that, change this too:
+FILESIZE="5440"
+
+INFILE="$1"
+OUTFILE="$2"
+
+if [ -z "$INFILE" -o -z "$OUTFILE" -o "$INFILE" = "-h" -o "$INFILE" = "--help" ]; then
cat <<EOF
$SELF - convert saved files from dla.xex to image files.
@@ -33,30 +50,51 @@ of supported arguments.
See also: https://slackware.uk/~urchlay/repos/dla-asm
EOF
-}
+ exit 0
+fi
-INFILE="$1"
-OUTFILE="$2"
+shift
+shift
-if [ -z "$INFILE" -o -z "$OUTFILE" -o "$INFILE" = "-h" -o "$INFILE" = "--help" ]; then
- usage
- exit 0
+if [ ! -e "$INFILE" ]; then
+ cat "$INFILE" > /dev/null # to get an error like "No such file or directory"
+ exit 1
fi
-shift 2
+# if "stat" is missing, e.g. because we're on a non-GNU system that
+# lacks the command, just skip the file size check (magick will error
+# out instead; less user-friendly but no big deal).
+if stat /dev/null >/dev/null 2>&1; then
+ if [ "`stat -L -c '%s' "$INFILE"`" != "$FILESIZE" ]; then
+ echo "$SELF: '$INFILE' not a DLA file (size != $FILESIZE)." 1>&2
+ exit 1
+ fi
+fi
+
+rm -f "$OUTFILE"
# do the conversion... if $OUTFILE has an unknown extension, we will
# not get an error, and the conversion will succeed (the output will
# just be a copy of the input!)
-$MAGICK convert -size "$SIZE" -depth 1 "$@" gray:"$INFILE" "$OUTFILE"
+# The "eval" is here to make this script work on the original Bourne
+# shell (yes, the one from V7 UNIX). Seriously. Even with spaces
+# in the arguments!
+eval "$MAGICK convert -size '$SIZE' -depth 1 "$@" gray:'$INFILE' '$OUTFILE'"
# if magick fails, exit with its error status (it already printed its
# error messages to stderr).
S="$?"
if [ "$S" != "0" ]; then
+ echo "$SELF: conversion failed (invalid output file extension?)." 1>&2
exit "$S"
fi
+# if magick "succeeds" but the output file doesn't exist, complain.
+if [ ! -e "$OUTFILE" ]; then
+ echo "$SELF: conversion failed (probably '$INFILE' is not a DLA) file)." 1>&2
+ exit 1;
+fi
+
# if magick "succeeds" but the output is identical to the input, let
# the user know.
if cmp "$INFILE" "$OUTFILE" >/dev/null 2>&1; then