aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-03-20 23:40:58 +0000
committerIan C <ianc@noddybox.co.uk>2016-03-20 23:40:58 +0000
commit8bfa93de6afda0163401c6f01eb5a89c535c262c (patch)
treecf7f8c3fb736465ec187bab8b0707cd9ca3d915b
parent618d4de3bd173a7bda6d6a2b911bc0717c10102b (diff)
Move output drivers to separate files in preperation for additional drivers.
-rw-r--r--doc/casm.html63
-rw-r--r--src/Makefile33
-rw-r--r--src/casm.c15
-rw-r--r--src/example/Makefile32
-rw-r--r--src/example/spectrum.asm19
-rw-r--r--src/output.c19
-rw-r--r--src/test/122
-rw-r--r--src/test/bank4
8 files changed, 159 insertions, 48 deletions
diff --git a/doc/casm.html b/doc/casm.html
index d3a545b..35d6683 100644
--- a/doc/casm.html
+++ b/doc/casm.html
@@ -751,12 +751,8 @@ holding the character code of the character.
<h3>Output Format</h3>
-By default the assembled code is written to a file called `output` as raw
-binary covering the block of memory that the assembly touched. If memory
-banks have been used then *output* is appended with the memory bank number, so
-that a separate output file is generated for each bank.
-
-The generated output can be controlled with the following options.
+By default the assembled code is written to a file called <b>output</b> as raw
+binary. The generated output can be controlled with the following options.
<table>
@@ -767,7 +763,18 @@ The generated output can be controlled with the following options.
option output-file, <i>file</i>
</td>
<td class="def">
-Send the output to <i>file</i>.
+Send the output to <i>file</i>. Defaults to <b>output</b>.
+</td></tr>
+
+<tr><td class="cmd">
+option output-bank, <i>printf formatted filename</i>
+</td>
+<td class="def">
+Send the output if multiple banks to use to <i>printf formatted filename</i>.
+It defaults to <b>output.%u</b> and accepts just one argument in the
+formatting string of an unsigned integer.
+If more or a different format specifier is used the behaviour of the assembler
+will be undefined. How this is used depends on the output driver.
</td></tr>
<tr><td class="cmd">
@@ -780,36 +787,52 @@ supported output formats:
<table>
<tr><td class="cmd">
-raw
+<a href="#rawout">raw</a>
</td>
<td class="def">
-A simply raw binary image of the memory.
+A raw binary image.
</td></tr>
<tr><td class="cmd">
-spectrum
+<a href="#specout">spectrum</a>
</td>
<td class="def">
+A Spectrum emulator TAP file.
+</td></tr>
+
+</table>
+
+</td></tr>
+
+</table>
+
+The output formats are described in detail in the following sections.
+
+
+<h3 id="rawout">RAW Output Format</h3>
+
+In this mode the file is created covering the block of memory that the assembly
+touched. If memory banks have been used then the <b>output-bank</b> setting is
+used to generate the output filename.
+
+
+<h3 id="specout">Spectrum TAP Output Format</h3>
<p>
-Generates a Spectrum TAP file for an emulator.
+Generates a Spectrum TAP file for an emulator. A TAP file is a simple binary
+file holding the bytes that the real Spectrum would have written to a tape.
</p>
-The TAP file will be given the same name as the output filename, and its load
-address will be set to the start of the created memory. If memory banks have
-been used then each bank is output to the TAP file as separate code files.
+<p>The TAP file will be given the same name as the output filename, and the
+internal code block will also be given the same name, unless if memory banks
+have been used then each code file in the TAP file will use the
+<b>output-bank</b> setting is used to generate the filename for each block.
</p>
<p>
Remember that TAP files can be concatenated, so the output could be appended to
another TAP file containing a BASIC loader for example.
</p>
-</td></tr>
-
-</table>
-</td></tr>
-
-</table>
<h3>Listing</h3>
diff --git a/src/Makefile b/src/Makefile
index d862ea0..1980209 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -38,7 +38,9 @@ SOURCE = casm.c \
listing.c \
alias.c \
6502.c \
- z80.c
+ z80.c \
+ rawout.c \
+ specout.c
OBJECTS = casm.o \
expr.o \
@@ -54,7 +56,9 @@ OBJECTS = casm.o \
listing.o \
alias.o \
6502.o \
- z80.o
+ z80.o \
+ rawout.o \
+ specout.o
$(TARGET): $(OBJECTS)
$(CC) $(CLAGS) -o $(TARGET) $(OBJECTS)
@@ -63,27 +67,32 @@ clean:
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) core *.core
6502.o: 6502.c global.h basetype.h util.h state.h expr.h label.h parse.h \
- cmd.h codepage.h 6502.h
+ cmd.h codepage.h 6502.h
alias.o: alias.c global.h basetype.h util.h state.h alias.h
casm.o: casm.c global.h basetype.h util.h state.h expr.h label.h macro.h \
- cmd.h parse.h codepage.h output.h stack.h listing.h alias.h z80.h 6502.h
+ cmd.h parse.h codepage.h stack.h listing.h alias.h output.h rawout.h \
+ specout.h z80.h 6502.h
codepage.o: codepage.c global.h basetype.h util.h state.h codepage.h \
- parse.h cmd.h
+ parse.h cmd.h
expr.o: expr.c global.h basetype.h util.h state.h expr.h label.h
label.o: label.c global.h basetype.h util.h state.h codepage.h parse.h \
- cmd.h stack.h label.h
+ cmd.h stack.h label.h
listing.o: listing.c global.h basetype.h util.h state.h label.h macro.h \
- cmd.h parse.h expr.h varchar.h listing.h
+ cmd.h parse.h expr.h varchar.h listing.h
macro.o: macro.c global.h basetype.h util.h state.h codepage.h parse.h \
- cmd.h varchar.h macro.h
+ cmd.h varchar.h macro.h
output.o: output.c global.h basetype.h util.h state.h output.h parse.h \
- cmd.h
+ cmd.h rawout.h specout.h
parse.o: parse.c global.h basetype.h util.h state.h codepage.h parse.h \
- cmd.h
+ cmd.h
+rawout.o: rawout.c global.h basetype.h util.h state.h rawout.h parse.h \
+ cmd.h
+specout.o: specout.c global.h basetype.h util.h state.h specout.h parse.h \
+ cmd.h
stack.o: stack.c global.h basetype.h util.h state.h stack.h
state.o: state.c global.h basetype.h util.h state.h expr.h
util.o: util.c global.h basetype.h util.h state.h
varchar.o: varchar.c global.h basetype.h util.h state.h codepage.h \
- parse.h cmd.h varchar.h
+ parse.h cmd.h varchar.h
z80.o: z80.c global.h basetype.h util.h state.h expr.h label.h parse.h \
- cmd.h codepage.h varchar.h z80.h
+ cmd.h codepage.h varchar.h z80.h
diff --git a/src/casm.c b/src/casm.c
index 1340eb7..7624978 100644
--- a/src/casm.c
+++ b/src/casm.c
@@ -37,11 +37,14 @@
#include "cmd.h"
#include "state.h"
#include "codepage.h"
-#include "output.h"
#include "stack.h"
#include "listing.h"
#include "alias.h"
+#include "output.h"
+#include "rawout.h"
+#include "specout.h"
+
/* ---------------------------------------- PROCESSORS
*/
#include "z80.h"
@@ -375,6 +378,8 @@ static CommandStatus OPTION(const char *label, int argc, char *argv[],
opt = argv[1];
}
+ /* TODO: There should be someway to make this better
+ */
if ((entry = ParseTable(opt, ListOptions())))
{
return ListSetOption(entry->value, ac, args, q, err, errsize);
@@ -391,6 +396,14 @@ static CommandStatus OPTION(const char *label, int argc, char *argv[],
{
return OutputSetOption(entry->value, ac, args, q, err, errsize);
}
+ else if ((entry = ParseTable(opt, RawOutputOptions())))
+ {
+ return RawOutputSetOption(entry->value, ac, args, q, err, errsize);
+ }
+ else if ((entry = ParseTable(opt, SpecTAPOutputOptions())))
+ {
+ return SpecTAPOutputSetOption(entry->value, ac, args, q, err, errsize);
+ }
else if ((entry = ParseTable(opt, cpu->options())))
{
return cpu->set_option(entry->value, ac, args, q, err, errsize);
diff --git a/src/example/Makefile b/src/example/Makefile
new file mode 100644
index 0000000..282cd6d
--- /dev/null
+++ b/src/example/Makefile
@@ -0,0 +1,32 @@
+# casm - Simple, portable assembler
+#
+# Copyright (C) 2003-2015 Ian Cowburn (ianc@noddybox.demon.co.uk)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# -------------------------------------------------------------------------
+#
+# Makefile for examples
+#
+
+ALL = spectrum.tap # c64.t64 zx81.p
+CASM = ../casm
+
+all: $(ALL)
+
+spectrum.tap: spectrum.asm
+ $(CASM) spectrum.asm
+
+clean:
+ rm -f $(ALL)
diff --git a/src/example/spectrum.asm b/src/example/spectrum.asm
new file mode 100644
index 0000000..01175f9
--- /dev/null
+++ b/src/example/spectrum.asm
@@ -0,0 +1,19 @@
+ ; Simple example spectrum code
+ ;
+ ; To use:
+ ;
+ ; LOAD "" CODE
+ ; RANDOMIZE USR 32768
+ ;
+
+ option output-file,spectrum.tap
+ option output-format,spectrum
+
+ org 32768
+
+ ld a,0
+loop:
+ out ($fe), a
+ inc a
+ and 7
+ jp loop
diff --git a/src/output.c b/src/output.c
index 13a7809..789531f 100644
--- a/src/output.c
+++ b/src/output.c
@@ -28,6 +28,10 @@
#include "global.h"
#include "output.h"
+#include "rawout.h"
+#include "specout.h"
+/* TODO #include "zx81out.h" */
+
/* ---------------------------------------- GLOBALS
*/
@@ -35,12 +39,14 @@
enum option_t
{
OPT_OUTPUTFILE,
+ OPT_OUTPUTBANK,
OPT_OUTPUTFORMAT
};
static const ValueTable option_set[] =
{
{"output-file", OPT_OUTPUTFILE},
+ {"output-bank", OPT_OUTPUTBANK},
{"output-format", OPT_OUTPUTFORMAT},
{NULL}
};
@@ -52,6 +58,7 @@ typedef enum
} Format;
static char output[4096] = "output";
+static char output_bank[4096] = "output.%u";
static char error[1024];
static Format format = Raw;
@@ -212,6 +219,10 @@ CommandStatus OutputSetOption(int opt, int argc, char *argv[],
CopyStr(output, argv[0], sizeof output);
break;
+ case OPT_OUTPUTBANK:
+ CopyStr(output_bank, argv[0], sizeof output_bank);
+ break;
+
case OPT_OUTPUTFORMAT:
CMD_TABLE(argv[0], format_table, val);
format = val->value;
@@ -244,14 +255,18 @@ int OutputCode(void)
switch(format)
{
case Raw:
- return OutputRawBinary(bank, count);
+ return RawOutput(output, output_bank, bank, count,
+ error, sizeof error);
case SpectrumTap:
- return OutputSpectrumTap(bank, count);
+ return SpecTAPOutput(output, output_bank, bank, count,
+ error, sizeof error);
default:
break;
}
+
+ return FALSE;
}
diff --git a/src/test/1 b/src/test/1
index 304e4b8..5531840 100644
--- a/src/test/1
+++ b/src/test/1
@@ -3,8 +3,8 @@
;
; Comments
;
- list on
- list labels,on
+ option +list
+ option list-labels,on
alias fred,equ
@@ -49,20 +49,18 @@ should_end_10h:
should_end_100h:
cpu z80
- option list
cpu 6502
- option list
- option zp,true
- option zp,on
- option zp,yes
- option zp,false
- option zp,off
- option zp,no
+ option zero-page,true
+ option zero-page,on
+ option zero-page,yes
+ option zero-page,false
+ option zero-page,off
+ option zero-page,no
- option +zp
- option -zp
+ option +zero-page
+ option -zero-page
one equ 1
two fred ONE * 2
diff --git a/src/test/bank b/src/test/bank
index cf0f313..6e29010 100644
--- a/src/test/bank
+++ b/src/test/bank
@@ -1,5 +1,7 @@
- option output-format,spectrum
+ ; option output-format,spectrum
+ option output-bank,code-%u
+ option output-file,output.tap
org 33000,0
bank 0