@@ -3531,7 +3551,8 @@ Here's a list of all control commands and a description, what they do:
6502 and 65SC02 instructions.
See: , and
+ name=".PSC02">, and
+ [4510
].POPCPU
@@ -3604,7 +3625,8 @@ Here's a list of all control commands and a description, what they do:
6502 instructions.
See: , and
+ name=".PC02">, and
+
.PUSHCPU
@@ -3796,7 +3818,7 @@ Here's a list of all control commands and a description, what they do:
Switch the CPU instruction set. The command is followed by a string that
specifies the CPU. Possible values are those that can also be supplied to
the command line option,
- namely: 6502, 6502X, 65SC02, 65C02, 65816 and HuC6280.
+ namely: 6502, 6502X, 65SC02, 65C02, 65816, 4510 and HuC6280.
See: ,
,
@@ -3805,6 +3827,7 @@ Here's a list of all control commands and a description, what they do:
,
,
,
+
,
@@ -4501,6 +4524,7 @@ each supported CPU a constant similar to
CPU_65816
CPU_SWEET16
CPU_HUC6280
+ CPU_4510
is defined. These constants may be used to determine the exact type of the
@@ -4514,6 +4538,7 @@ another constant is defined:
CPU_ISET_65816
CPU_ISET_SWEET16
CPU_ISET_HUC6280
+ CPU_ISET_4510
The value read from the / pseudo variable may
diff --git a/src/ca65/condasm.c b/src/ca65/condasm.c
index 24cbae696..b8bda4c7d 100644
--- a/src/ca65/condasm.c
+++ b/src/ca65/condasm.c
@@ -386,6 +386,16 @@ void DoConditionals (void)
CalcOverallIfCond ();
break;
+ case TOK_IFP4510:
+ D = AllocIf (".IFP4510", 1);
+ NextTok ();
+ if (IfCond) {
+ SetIfCond (D, GetCPU() == CPU_4510);
+ }
+ ExpectSep ();
+ CalcOverallIfCond ();
+ break;
+
case TOK_IFP816:
D = AllocIf (".IFP816", 1);
NextTok ();
@@ -457,6 +467,7 @@ int CheckConditionals (void)
case TOK_IFNDEF:
case TOK_IFNREF:
case TOK_IFP02:
+ case TOK_IFP4510:
case TOK_IFP816:
case TOK_IFPC02:
case TOK_IFPSC02:
diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c
index 250ceecc9..b44c28dd8 100644
--- a/src/ca65/pseudo.c
+++ b/src/ca65/pseudo.c
@@ -1530,6 +1530,14 @@ static void DoP816 (void)
+static void DoP4510 (void)
+/* Switch to 4510 CPU */
+{
+ SetCPU (CPU_4510);
+}
+
+
+
static void DoPageLength (void)
/* Set the page length for the listing */
{
@@ -2033,6 +2041,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccKeepToken, DoConditionals }, /* .IFNDEF */
{ ccKeepToken, DoConditionals }, /* .IFNREF */
{ ccKeepToken, DoConditionals }, /* .IFP02 */
+ { ccKeepToken, DoConditionals }, /* .IFP4510 */
{ ccKeepToken, DoConditionals }, /* .IFP816 */
{ ccKeepToken, DoConditionals }, /* .IFPC02 */
{ ccKeepToken, DoConditionals }, /* .IFPSC02 */
@@ -2063,6 +2072,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoOrg },
{ ccNone, DoOut },
{ ccNone, DoP02 },
+ { ccNone, DoP4510 },
{ ccNone, DoP816 },
{ ccNone, DoPageLength },
{ ccNone, DoUnexpected }, /* .PARAMCOUNT */
diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c
index 994f95fba..e186b19a7 100644
--- a/src/ca65/scanner.c
+++ b/src/ca65/scanner.c
@@ -216,6 +216,7 @@ struct DotKeyword {
{ ".IFNDEF", TOK_IFNDEF },
{ ".IFNREF", TOK_IFNREF },
{ ".IFP02", TOK_IFP02 },
+ { ".IFP4510", TOK_IFP4510 },
{ ".IFP816", TOK_IFP816 },
{ ".IFPC02", TOK_IFPC02 },
{ ".IFPSC02", TOK_IFPSC02 },
@@ -251,6 +252,7 @@ struct DotKeyword {
{ ".ORG", TOK_ORG },
{ ".OUT", TOK_OUT },
{ ".P02", TOK_P02 },
+ { ".P4510", TOK_P4510 },
{ ".P816", TOK_P816 },
{ ".PAGELEN", TOK_PAGELENGTH },
{ ".PAGELENGTH", TOK_PAGELENGTH },
diff --git a/src/ca65/token.h b/src/ca65/token.h
index 93dfaa092..8998cc162 100644
--- a/src/ca65/token.h
+++ b/src/ca65/token.h
@@ -193,6 +193,7 @@ typedef enum token_t {
TOK_IFNDEF,
TOK_IFNREF,
TOK_IFP02,
+ TOK_IFP4510,
TOK_IFP816,
TOK_IFPC02,
TOK_IFPSC02,
@@ -223,6 +224,7 @@ typedef enum token_t {
TOK_ORG,
TOK_OUT,
TOK_P02,
+ TOK_P4510,
TOK_P816,
TOK_PAGELENGTH,
TOK_PARAMCOUNT,
diff --git a/test/assembler/4510-cpudetect.ref b/test/assembler/4510-cpudetect.ref
new file mode 100644
index 000000000..515557c85
Binary files /dev/null and b/test/assembler/4510-cpudetect.ref differ
diff --git a/test/assembler/6502-cpudetect.ref b/test/assembler/6502-cpudetect.ref
new file mode 100644
index 000000000..9b0aeb1f0
Binary files /dev/null and b/test/assembler/6502-cpudetect.ref differ
diff --git a/test/assembler/6502x-cpudetect.ref b/test/assembler/6502x-cpudetect.ref
new file mode 100644
index 000000000..3434ecbea
Binary files /dev/null and b/test/assembler/6502x-cpudetect.ref differ
diff --git a/test/assembler/65816-cpudetect.ref b/test/assembler/65816-cpudetect.ref
new file mode 100644
index 000000000..4f6e767b0
Binary files /dev/null and b/test/assembler/65816-cpudetect.ref differ
diff --git a/test/assembler/65c02-cpudetect.ref b/test/assembler/65c02-cpudetect.ref
new file mode 100644
index 000000000..9f790d5ff
Binary files /dev/null and b/test/assembler/65c02-cpudetect.ref differ
diff --git a/test/assembler/65sc02-cpudetect.ref b/test/assembler/65sc02-cpudetect.ref
new file mode 100644
index 000000000..4e11bd708
Binary files /dev/null and b/test/assembler/65sc02-cpudetect.ref differ
diff --git a/test/assembler/Makefile b/test/assembler/Makefile
index 47f403469..faefddf7a 100644
--- a/test/assembler/Makefile
+++ b/test/assembler/Makefile
@@ -5,26 +5,43 @@ BINDIR = ../../bin
#WORKDIR := ../../testwrk
WORKDIR := .
-TARGETS = 6502 6502x 65sc02 65c02
-#TARGETS += 65816
-TARGETS += 4510
-TARGETS += huc6280
-#TARGETS += m740
+BASE_TARGETS = 6502 6502x 65sc02 65c02
+BASE_TARGETS += 4510 huc6280
-all: $(addprefix $(WORKDIR)/, $(addsuffix -opcodes.bin, $(TARGETS)))
+OPCODE_TARGETS = $(BASE_TARGETS)
+CPUDETECT_TARGETS = $(BASE_TARGETS)
+
+CPUDETECT_TARGETS += 65816
+
+# default target defined later
+all:
+
+# generate opcode targets and expand target list
+define opcode
+OPCODE_TARGETLIST += $(1)-opcodes.bin
+$$(WORKDIR)/$(1)-opcodes.bin: $(1)-opcodes.s
+ @$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-opcodes.lst --obj-path $$(WORKDIR) -o $$@ $$<
+ @diff -q $(1)-opcodes.ref $$@ || (cat $$(WORKDIR)/$(1)-opcodes.lst ; exit 1)
+ @echo ca65 --cpu $(1) opcodes ok
+endef
+$(foreach target,$(OPCODE_TARGETS),$(eval $(call opcode,$(target))))
+
+# generate cpudetect targets and expand target list
+define cpudetect
+CPUDETECT_TARGETLIST += $(1)-cpudetect.bin
+$$(WORKDIR)/$(1)-cpudetect.bin: cpudetect.s
+ @$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-cpudetect.lst --obj-path $$(WORKDIR) -o $$@ $$<
+ @diff -q $(1)-cpudetect.ref $$@ || (cat $$(WORKDIR)/$(1)-cpudetect.lst ; exit 1)
+ @echo ca65 --cpu $(1) cpudetect ok
+endef
+$(foreach target,$(CPUDETECT_TARGETS),$(eval $(call cpudetect,$(target))))
+
+# now that all targets have been generated, get to the manual ones
+all: $(OPCODE_TARGETLIST) $(CPUDETECT_TARGETLIST)
@#
-.PHONY: all clean $(addprefix $(WORKDIR)/, $(addsuffix -opcodes.bin, $(TARGETS)))
-
clean:
rm -f *.o *.bin *.lst
-define build
-$$(WORKDIR)/$(1)-opcodes.bin: $(1)-opcodes.s
- @$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-opcodes.lst --obj-path $$(WORKDIR) -o $$@ $$<
- @diff -q $(1)-opcodes.ref $$@ || (cat $$(WORKDIR)/$(1)-opcodes.lst ; exit 1)
- @echo ca65 --cpu $(1) ok
-endef
-
-$(foreach target,$(TARGETS),$(eval $(call build,$(target))))
+.PHONY: all clean $(OPCODE_TARGETLIST) $(CPUDETECT_TARGETLIST)
diff --git a/test/assembler/README b/test/assembler/README
index 697c24449..a2b1e9a41 100644
--- a/test/assembler/README
+++ b/test/assembler/README
@@ -2,6 +2,9 @@
Assembler Testcases
===================
+Opcode Tests:
+-------------
+
These testcases are inspired by the ones now removed from test/assembler.
The main purpose is to have each possible opcode generated at least once,
either by an assembly instruction or a ".byte"-placeholder. Typically
@@ -23,7 +26,23 @@ The testcases for 6502, 6502x, 65sc02, 65c02, 4510, and huc6280 have been
put together by Sven Oliver ("SvOlli") Moll, as well as a template for the
m740 instructions set.
-Still to do is to find a way to implement a testcase for the 65816
+Still to do is to find a way to implement an opcode testcase for the 65816
processor, since it's capable of executing instructions with an 8-bit and
a 16-bit operator alike, only distinguished by one processor flag.
+
+CPU detect Tests
+----------------
+
+These tests all assemble the same file "cpudetect.s" which contains several
+conditionals for several CPUs, only using every option known to the "--cpu"
+commandline switch of ca65/cl65.
+
+
+Reference (".ref") Files
+------------------------
+
+A hint on creating these files: when running the test, it will fail due to
+the missing ".ref" file. Review the output of the ".lst" very pedantic, then
+copy the ".bin" to the ".ref" file.
+
diff --git a/test/assembler/huc6280-cpudetect.ref b/test/assembler/huc6280-cpudetect.ref
new file mode 100644
index 000000000..646e0f48c
Binary files /dev/null and b/test/assembler/huc6280-cpudetect.ref differ