summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-09-02 08:19:29 +0000
committerIan C <ianc@noddybox.co.uk>2016-09-02 08:19:29 +0000
commit54bb3c9abdd34b92be44b87382a7b3c03a5991d9 (patch)
tree7d791e8b6758a2aeec37c94d4a5871d9b9d5b7da
parentd1b2a8b7d86d8b02f635b112a7f39e7437eac829 (diff)
Added README and clamped code point values.
-rw-r--r--README53
-rw-r--r--ascii2map.c24
-rw-r--r--example3
3 files changed, 76 insertions, 4 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..e01202a
--- /dev/null
+++ b/README
@@ -0,0 +1,53 @@
+USAGE
+=====
+This is a simple tool to generate data for a map as defined using ASCII art.
+
+usage: ascii2map [-a|-b|-c] [-d directive] [input-file [output-file]]
+
+SWITCHES
+========
+
+-a The default. Produce assembly output.
+-b Produce binary output.
+-c Produce C source output.
+-d "x" In assembly mode use "x" as the directive instead of the
+ default "byte".
+input-file The input file. If not supplied stdin is used.
+output-file The output file. If not supplied stdout is used.
+
+
+INPUT FILES
+===========
+
+Input files look like the following:
+
+#:1
+*:128
+!63
+~
+########
+# #
+#ABCDEF#
+#1# # *#
+########
+
+The "#:1" line defines that when a '#' character appears in the map then code
+'1' should be used.
+
+The following line defines the offset for any characters that aren't explicitly
+defined. e.g. in this example 63 will be deducted from the character code.
+In ASCII this would mean 'A' becomes 2, 'B' becomes 3, and so on. Any codes
+generated that fall outside the range 0 to 255 will be clamped to that range.
+
+The line with a tilde (~) on its own indicates the end of the definitions.
+
+Following it is the map to produce the definition for, eg.
+
+$ ascii2map example
+ byte 1, 1, 1, 1, 1, 1, 1, 1
+ byte 1, 0, 0, 0, 0, 0, 0, 1
+ byte 1, 2, 3, 4, 5, 6, 7, 1
+ byte 1, 0, 1, 0, 1, 0, 128, 1
+ byte 1, 1, 1, 1, 1, 1, 1, 1
+
+The following switch
diff --git a/ascii2map.c b/ascii2map.c
index 30a2c44..f24cb77 100644
--- a/ascii2map.c
+++ b/ascii2map.c
@@ -105,6 +105,24 @@ static void EndOutput(FILE *fp)
}
+static unsigned CodePoint(char c)
+{
+ int offset = c - code_point;
+
+ if (offset < 0)
+ {
+ offset = 0;
+ }
+
+ if (offset > 255)
+ {
+ offset = 255;
+ }
+
+ return (unsigned)offset;
+}
+
+
static void Output(FILE *fp, char c)
{
static int column;
@@ -138,7 +156,7 @@ static void Output(FILE *fp, char c)
}
else
{
- fprintf(fp, "%u", c - code_point);
+ fprintf(fp, "%u", CodePoint(c));
}
break;
@@ -150,7 +168,7 @@ static void Output(FILE *fp, char c)
}
else
{
- putc(c - code_point, fp);
+ putc(CodePoint(c), fp);
}
break;
@@ -177,7 +195,7 @@ static void Output(FILE *fp, char c)
}
else
{
- fprintf(fp, "%u", c - code_point);
+ fprintf(fp, "%u", CodePoint(c));
}
break;
diff --git a/example b/example
index e89d67d..329c0b6 100644
--- a/example
+++ b/example
@@ -1,8 +1,9 @@
#:1
+*:128
!63
~
########
# #
#ABCDEF#
-# # # ##
+#1# # *#
########