diff --git a/include/gamate.h b/include/gamate.h index 0af21623d..8b9790e39 100644 --- a/include/gamate.h +++ b/include/gamate.h @@ -170,6 +170,8 @@ /* No support for dynamically loadable drivers */ #define DYN_DRV 0 +#define JOY_DATA 0x4400 /* hw register to read the pad bits from */ + /* Masks for joy_read */ #define JOY_UP_MASK 0x01 #define JOY_DOWN_MASK 0x02 diff --git a/src/cc65/assignment.c b/src/cc65/assignment.c index 71df0c4f2..1ada3af0b 100644 --- a/src/cc65/assignment.c +++ b/src/cc65/assignment.c @@ -157,6 +157,11 @@ void Assignment (ExprDesc* Expr) Error ("Assignment to const"); } + /* Check for assignment to incomplete type */ + if (IsIncompleteESUType (ltype)) { + Error ("Assignment to incomplete type '%s'", GetFullTypeName (ltype)); + } + /* Skip the '=' token */ NextToken (); diff --git a/src/cc65/codelab.c b/src/cc65/codelab.c index f36520835..ff26645dc 100644 --- a/src/cc65/codelab.c +++ b/src/cc65/codelab.c @@ -112,6 +112,7 @@ void CL_MoveRefs (CodeLabel* OldLabel, CodeLabel* NewLabel) CodeEntry* E = CL_GetRef (OldLabel, Count); /* Change the reference to the new label */ + CHECK (E->JumpTo != NULL); CHECK (E->JumpTo == OldLabel); CL_AddRef (NewLabel, E); diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 82dc7ec63..3296968f6 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -140,19 +140,10 @@ static void Parse (void) comma = 0; while (1) { - Declaration Decl; + Declaration Decl; /* Read the next declaration */ ParseDecl (&Spec, &Decl, DM_NEED_IDENT); - if (Decl.Ident[0] == '\0') { - NextToken (); - break; - } - - if ((Decl.StorageClass & SC_FICTITIOUS) == SC_FICTITIOUS) { - /* Failed parsing */ - goto SkipOneDecl; - } /* Check if we must reserve storage for the variable. We do this, ** @@ -163,8 +154,9 @@ static void Parse (void) ** ** This means that "extern int i;" will not get storage allocated. */ - if ((Decl.StorageClass & SC_FUNC) != SC_FUNC && - (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) { + if ((Decl.StorageClass & SC_FUNC) != SC_FUNC && + (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF && + (Decl.StorageClass & SC_FICTITIOUS) != SC_FICTITIOUS) { if ((Spec.Flags & DS_DEF_STORAGE) != 0 || (Decl.StorageClass & (SC_EXTERN|SC_STATIC)) == SC_STATIC || ((Decl.StorageClass & SC_EXTERN) != 0 && @@ -296,7 +288,6 @@ static void Parse (void) } -SkipOneDecl: /* Check for end of declaration list */ if (CurTok.Tok == TOK_COMMA) { NextToken (); @@ -452,10 +443,6 @@ void Compile (const char* FileName) } Sym = GetSymType (GetElementType (Entry->Type)); - if (Size == 0 && Sym != 0 && SymIsDef (Sym)) { - /* Array of 0-size elements */ - Warning ("Array '%s[]' has 0-sized elements", Entry->Name); - } } /* For non-ESU types, Size != 0 */ diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index f4f978a3c..39f543a22 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -687,7 +687,10 @@ const Type* GetUnderlyingType (const Type* Type) Internal ("Enum tag type error in GetUnderlyingTypeCode"); } - return ((SymEntry*)Type->A.P)->V.E.Type; + /* If incomplete enum type is used, just return its raw type */ + if (((SymEntry*)Type->A.P)->V.E.Type != 0) { + return ((SymEntry*)Type->A.P)->V.E.Type; + } } return Type; @@ -1247,9 +1250,14 @@ Type* IntPromotion (Type* T) ** to unsigned int. */ return IsSignUnsigned (T) ? type_uint : type_int; - } else { - /* Otherwise, the type is not smaller than int, so leave it alone. */ + } else if (!IsIncompleteESUType (T)) { + /* The type is a complete type not smaller than int, so leave it alone. */ return T; + } else { + /* Otherwise, this is an incomplete enum, and there is expceted to be an error already. + ** Assume int to avoid further errors. + */ + return type_int; } } diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 8d24b168e..d1ac0e43f 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -457,6 +457,37 @@ static unsigned ParseOneStorageClass (void) +static void CheckArrayElementType (Type* DataType) +/* Check if data type consists of arrays of incomplete element types */ +{ + Type* T = DataType; + + while (T->C != T_END) { + if (IsTypeArray (T)) { + ++T; + if (IsIncompleteESUType (T)) { + /* We cannot have an array of incomplete elements */ + Error ("Array of incomplete element type '%s'", GetFullTypeName (T)); + } else if (SizeOf (T) == 0) { + /* If the array is multi-dimensional, try to get the true + ** element type. + */ + if (IsTypeArray (T)) { + continue; + } + /* We could support certain 0-size element types as an extension */ + if (!IsTypeVoid (T) || IS_Get (&Standard) != STD_CC65) { + Error ("Array of 0-size element type '%s'", GetFullTypeName (T)); + } + } + } else { + ++T; + } + } +} + + + static void ParseStorageClass (DeclSpec* D, unsigned DefStorage) /* Parse a storage class */ { @@ -908,8 +939,15 @@ static SymEntry* ParseUnionDecl (const char* Name) } } + /* Check for incomplete type */ + if (IsIncompleteESUType (Decl.Type)) { + Error ("Field '%s' has incomplete type '%s'", + Decl.Ident, + GetFullTypeName (Decl.Type)); + } + /* Handle sizes */ - FieldSize = CheckedSizeOf (Decl.Type); + FieldSize = SizeOf (Decl.Type); if (FieldSize > UnionSize) { UnionSize = FieldSize; } @@ -946,16 +984,16 @@ NextMember: if (CurTok.Tok != TOK_COMMA) { FieldTab = GetSymTab (); LeaveStructLevel (); - /* Empty union is not supported now */ - if (UnionSize == 0) { - Error ("Empty union type '%s' is not supported", Name); - } - /* Return a fictitious symbol if errors occurred during parsing */ if (PrevErrorCount != ErrorCount) { Flags |= SC_FICTITIOUS; } + /* Empty union is not supported now */ + if (UnionSize == 0) { + Error ("Empty union type '%s' is not supported", Name); + } + /* Make a real entry from the forward decl and return it */ return AddStructSym (Name, SC_UNION | SC_DEF | Flags, UnionSize, FieldTab); } @@ -1092,6 +1130,13 @@ static SymEntry* ParseStructDecl (const char* Name) } } + /* Check for incomplete type */ + if (IsIncompleteESUType (Decl.Type)) { + Error ("Field '%s' has incomplete type '%s'", + Decl.Ident, + GetFullTypeName (Decl.Type)); + } + /* Add a field entry to the table */ if (FieldWidth > 0) { /* Full bytes have already been added to the StructSize, @@ -1116,7 +1161,7 @@ static SymEntry* ParseStructDecl (const char* Name) AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, StructSize); } if (!FlexibleMember) { - StructSize += CheckedSizeOf (Decl.Type); + StructSize += SizeOf (Decl.Type); } } @@ -1143,16 +1188,16 @@ NextMember: if (CurTok.Tok != TOK_COMMA) { FieldTab = GetSymTab (); LeaveStructLevel (); - /* Empty struct is not supported now */ - if (StructSize == 0) { - Error ("Empty struct type '%s' is not supported", Name); - } - /* Return a fictitious symbol if errors occurred during parsing */ if (PrevErrorCount != ErrorCount) { Flags |= SC_FICTITIOUS; } + /* Empty struct is not supported now */ + if (StructSize == 0) { + Error ("Empty struct type '%s' is not supported", Name); + } + /* Make a real entry from the forward decl and return it */ return AddStructSym (Name, SC_STRUCT | SC_DEF | Flags, StructSize, FieldTab); } @@ -1904,6 +1949,9 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode) /* Do several fixes on qualifiers */ FixQualifiers (D->Type); + /* Check if the data type consists of any arrays of forbidden types */ + CheckArrayElementType (D->Type); + /* If we have a function, add a special storage class */ if (IsTypeFunc (D->Type)) { D->StorageClass |= SC_FUNC; @@ -1975,10 +2023,15 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode) Error ("Invalid size in declaration (0x%06X)", Size); } } + } - if (PrevErrorCount != ErrorCount) { - /* Don't give storage if the declaration is not parsed correctly */ - D->StorageClass |= SC_DECL | SC_FICTITIOUS; + if (PrevErrorCount != ErrorCount) { + /* Make the declaration fictitious if is is not parsed correctly */ + D->StorageClass |= SC_DECL | SC_FICTITIOUS; + + if (Mode == DM_NEED_IDENT && D->Ident[0] == '\0') { + /* Use a fictitious name for the identifier if it is missing */ + AnonName (D->Ident, "global"); } } } @@ -2223,7 +2276,7 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers) /* Get the array data */ Type* ElementType = GetElementType (T); - unsigned ElementSize = CheckedSizeOf (ElementType); + unsigned ElementSize = SizeOf (ElementType); long ElementCount = GetElementCount (T); /* Special handling for a character array initialized by a literal */ diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 416d383d0..d1ceb27c5 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1862,8 +1862,8 @@ static void UnaryOp (ExprDesc* Expr) /* Value is not constant */ LoadExpr (CF_NONE, Expr); - /* Get the type of the expression */ - Flags = TypeOf (Expr->Type); + /* Adjust the type of the value */ + Flags = g_typeadjust (TypeOf (Expr->Type), TypeOf (type_int) | CF_CONST); /* Handle the operation */ switch (Tok) { @@ -1876,6 +1876,9 @@ static void UnaryOp (ExprDesc* Expr) /* The result is an rvalue in the primary */ ED_FinalizeRValLoad (Expr); } + + /* Adjust the type of the expression */ + Expr->Type = IntPromotion (Expr->Type); } diff --git a/src/cc65/loadexpr.c b/src/cc65/loadexpr.c index 5c5434393..17b0dd0fe 100644 --- a/src/cc65/loadexpr.c +++ b/src/cc65/loadexpr.c @@ -142,6 +142,10 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr) BitFieldFullWidthFlags |= CF_UNSIGNED; } } else if ((Flags & CF_TYPEMASK) == 0) { + /* If Expr is an incomplete ESY type, bail out */ + if (IsIncompleteESUType (Expr->Type)) { + return; + } Flags |= TypeOf (Expr->Type); } diff --git a/src/cc65/locals.c b/src/cc65/locals.c index 87c8e6cb9..255a23b6d 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -173,7 +173,11 @@ static void ParseRegisterDecl (Declaration* Decl, int Reg) /* Cannot allocate a variable of zero size */ if (Size == 0) { - Error ("Variable '%s' has unknown size", Decl->Ident); + if (IsTypeArray (Decl->Type)) { + Error ("Array '%s' has unknown size", Decl->Ident); + } else { + Error ("Variable '%s' has unknown size", Decl->Ident); + } } } @@ -360,7 +364,11 @@ static void ParseAutoDecl (Declaration* Decl) /* Cannot allocate a variable of zero size */ if (Size == 0) { - Error ("Variable '%s' has unknown size", Decl->Ident); + if (IsTypeArray (Decl->Type)) { + Error ("Array '%s' has unknown size", Decl->Ident); + } else { + Error ("Variable '%s' has unknown size", Decl->Ident); + } } } @@ -414,7 +422,11 @@ static void ParseStaticDecl (Declaration* Decl) /* Cannot allocate a variable of zero size */ if (Size == 0) { - Error ("Variable '%s' has unknown size", Decl->Ident); + if (IsTypeArray (Decl->Type)) { + Error ("Array '%s' has unknown size", Decl->Ident); + } else { + Error ("Variable '%s' has unknown size", Decl->Ident); + } } } diff --git a/test/asm/Makefile b/test/asm/Makefile index 94a925376..b157bb672 100644 --- a/test/asm/Makefile +++ b/test/asm/Makefile @@ -8,23 +8,22 @@ ifdef CMD_EXE EXE = .exe MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) - DEL = del /f $(subst /,\,$1) else EXE = MKDIR = mkdir -p $1 RMDIR = $(RM) -r $1 - DEL = $(RM) $1 endif ifdef QUIET .SILENT: endif -CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) +CA65 := $(if $(wildcard ../../bin/ca65*),../../bin/ca65,ca65) +LD65 := $(if $(wildcard ../../bin/ld65*),../../bin/ld65,ld65) WORKDIR = ../../testwrk/asm -DIFF = $(WORKDIR)/isequal$(EXE) +ISEQUAL = $(WORKDIR)/isequal$(EXE) CC = gcc CFLAGS = -O2 @@ -44,29 +43,28 @@ all: $(OPCODE_BINS) $(CPUDETECT_BINS) $(WORKDIR): $(call MKDIR,$(WORKDIR)) -$(DIFF): ../isequal.c | $(WORKDIR) +$(ISEQUAL): ../isequal.c | $(WORKDIR) $(CC) $(CFLAGS) -o $@ $< define OPCODE_template -$(WORKDIR)/$1-opcodes.bin: $1-opcodes.s $(DIFF) +$(WORKDIR)/$1-opcodes.bin: $1-opcodes.s $(ISEQUAL) $(if $(QUIET),echo asm/$1-opcodes.bin) - $(CL65) --cpu $1 -t none -l $(WORKDIR)/$1-opcodes.lst -o $$@ $$< - $(DIFF) $$@ $1-opcodes.ref + $(CA65) --cpu $1 -t none -l $(WORKDIR)/$1-opcodes.lst -o $(WORKDIR)/$1-opcodes.o $$< + $(LD65) -t none -o $$@ $(WORKDIR)/$1-opcodes.o none.lib + $(ISEQUAL) $$@ $1-opcodes.ref endef # OPCODE_template $(foreach cpu,$(OPCODE_CPUS),$(eval $(call OPCODE_template,$(cpu)))) -# cpudetect.o is written by multiple rules -.NOTPARALLEL: - define CPUDETECT_template -$(WORKDIR)/$1-cpudetect.bin: cpudetect.s $(DIFF) +$(WORKDIR)/$1-cpudetect.bin: cpudetect.s $(ISEQUAL) $(if $(QUIET),echo asm/$1-cpudetect.bin) - $(CL65) --cpu $1 -t none -l $(WORKDIR)/$1-cpudetect.lst -o $$@ $$< - $(DIFF) $$@ $1-cpudetect.ref + $(CA65) --cpu $1 -t none -l $(WORKDIR)/$1-cpudetect.lst -o $(WORKDIR)/$1-cpudetect.o $$< + $(LD65) -t none -o $$@ $(WORKDIR)/$1-cpudetect.o none.lib + $(ISEQUAL) $$@ $1-cpudetect.ref endef # CPUDETECT_template @@ -74,4 +72,3 @@ $(foreach cpu,$(CPUDETECT_CPUS),$(eval $(call CPUDETECT_template,$(cpu)))) clean: @$(call RMDIR,$(WORKDIR)) - @$(call DEL,$(OPCODE_REFS:.ref=.o) cpudetect.o) diff --git a/test/dasm/Makefile b/test/dasm/Makefile index faa6b7fa0..dc0b57c76 100644 --- a/test/dasm/Makefile +++ b/test/dasm/Makefile @@ -8,12 +8,10 @@ ifdef CMD_EXE EXE = .exe MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) - DEL = del /f $(subst /,\,$1) else EXE = MKDIR = mkdir -p $1 RMDIR = $(RM) -r $1 - DEL = $(RM) $1 endif ifdef QUIET @@ -25,7 +23,7 @@ DA65 := $(if $(wildcard ../../bin/da65*),../../bin/da65,da65) WORKDIR = ../../testwrk/dasm -DIFF = $(WORKDIR)/isequal$(EXE) +ISEQUAL = $(WORKDIR)/isequal$(EXE) CC = gcc CFLAGS = -O2 @@ -44,7 +42,7 @@ all: $(BINS) $(WORKDIR): $(call MKDIR,$(WORKDIR)) -$(DIFF): ../isequal.c | $(WORKDIR) +$(ISEQUAL): ../isequal.c | $(WORKDIR) $(CC) $(CFLAGS) -o $@ $< define DISASS_template @@ -55,10 +53,10 @@ $(WORKDIR)/$1-disass.bin: $1-disass.s | $(WORKDIR) $(WORKDIR)/$1-reass.s: $(WORKDIR)/$1-disass.bin $(DA65) --cpu $1 $(START) -o $$@ $$< -$(WORKDIR)/$1-reass.bin: $(WORKDIR)/$1-reass.s $(DIFF) +$(WORKDIR)/$1-reass.bin: $(WORKDIR)/$1-reass.s $(ISEQUAL) $(if $(QUIET),echo dasm/$1-reass.bin) $(CL65) --cpu $1 -t none $(START) -o $$@ $$< - $(DIFF) $$@ $(WORKDIR)/$1-disass.bin + $(ISEQUAL) $$@ $(WORKDIR)/$1-disass.bin endef # DISASS_template @@ -66,4 +64,3 @@ $(foreach cpu,$(CPUS),$(eval $(call DISASS_template,$(cpu)))) clean: @$(call RMDIR,$(WORKDIR)) - @$(call DEL,$(SOURCES:.s=.o)) diff --git a/test/err/Makefile b/test/err/Makefile index 6fa53a1db..1273bbb2c 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -23,23 +23,23 @@ ifdef QUIET NULLERR = 2>$(NULLDEV) endif -CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) WORKDIR = ../../testwrk/err .PHONY: all clean SOURCES := $(wildcard *.c) -TESTS = $(patsubst %.c,$(WORKDIR)/%.prg,$(SOURCES)) +TESTS = $(patsubst %.c,$(WORKDIR)/%.s,$(SOURCES)) all: $(TESTS) $(WORKDIR): $(call MKDIR,$(WORKDIR)) -$(WORKDIR)/%.prg: %.c | $(WORKDIR) +$(WORKDIR)/%.s: %.c | $(WORKDIR) $(if $(QUIET),echo err/$*.s) - $(NOT) $(CL65) -o $@ $< $(NULLERR) + $(NOT) $(CC65) -o $@ $< $(NULLERR) clean: @$(call RMDIR,$(WORKDIR)) diff --git a/test/misc/bug1113.c b/test/err/bug1113.c similarity index 100% rename from test/misc/bug1113.c rename to test/err/bug1113.c diff --git a/test/err/bug1211-ice-move-refs-1.c b/test/err/bug1211-ice-move-refs-1.c new file mode 100644 index 000000000..f28d1fcbc --- /dev/null +++ b/test/err/bug1211-ice-move-refs-1.c @@ -0,0 +1,52 @@ +/* + Copyright 2020 The cc65 Authors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + Test of indirect goto with label merge ICE. + https://github.com/cc65/cc65/issues/1211 + This should compile and should be moved to tests/val/ when the bug is fixed. +*/ + +#include + +/* When operating correctly, f(0) = 31 and f(1) = 41. */ +int f (int x) +{ + static const void *const labels[] = {&&L0, &&L1}; + goto *labels[x]; +L0: if (labels[0] != labels[1]) return 31; + else return 13; +L1: return 41; +} + +static unsigned char failures = 0; + +int main (void) +{ + if (f (0) != 31) failures++; + + if (failures == 0) { + printf ("PASS\n"); + } else { + printf ("FAIL\n"); + } + + return failures; +} diff --git a/test/err/bug1211-ice-move-refs-2.c b/test/err/bug1211-ice-move-refs-2.c new file mode 100644 index 000000000..504433f45 --- /dev/null +++ b/test/err/bug1211-ice-move-refs-2.c @@ -0,0 +1,51 @@ +/* + Copyright 2020 The cc65 Authors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + Test of indirect goto with label merge ICE. + https://github.com/cc65/cc65/issues/1211 + This should compile and should be moved to tests/val/ when the bug is fixed. +*/ + +#include + +/* When operating correctly, this returns 0. */ +int f (void) +{ + static const void *const x[2] = {&&L0, &&L1}; + goto *x[0]; +L0: +L1: return 0; +} + +static unsigned char failures = 0; + +int main (void) +{ + if (f () != 0) failures++; + + if (failures == 0) { + printf ("PASS\n"); + } else { + printf ("FAIL\n"); + } + + return failures; +} diff --git a/test/misc/Makefile b/test/misc/Makefile index e48d86e30..735f83065 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -11,7 +11,6 @@ ifdef CMD_EXE NULLDEV = nul: MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) - DEL = del /f $(subst /,\,$1) else S = / NOT = ! @@ -19,7 +18,6 @@ else NULLDEV = /dev/null MKDIR = mkdir -p $1 RMDIR = $(RM) -r $1 - DEL = $(RM) $1 endif ifdef QUIET @@ -30,14 +28,16 @@ endif SIM65FLAGS = -x 200000000 -CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) +CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65) +LD65 := $(if $(wildcard ../../bin/ld65*),..$S..$Sbin$Sld65,ld65) SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) WORKDIR = ..$S..$Stestwrk$Smisc OPTIONS = g O Os Osi Osir Osr Oi Oir Or -DIFF = $(WORKDIR)$Sisequal$(EXE) +ISEQUAL = $(WORKDIR)$Sisequal$(EXE) CC = gcc CFLAGS = -O2 @@ -50,15 +50,10 @@ TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02. all: $(TESTS) -# The same input file is processed with different cl65 args, -# but cl65 uses the input file name to make the temp file name, -# and they stomp each other. -.NOTPARALLEL: - $(WORKDIR): $(call MKDIR,$(WORKDIR)) -$(DIFF): ../isequal.c | $(WORKDIR) +$(ISEQUAL): ../isequal.c | $(WORKDIR) $(CC) $(CFLAGS) -o $@ $< define PRG_template @@ -67,44 +62,65 @@ define PRG_template $(WORKDIR)/bug760.$1.$2.prg: bug760.c | $(WORKDIR) @echo "FIXME: " $$@ "currently does not compile." $(if $(QUIET),echo misc/bug760.$1.$2.prg) - $(NOT) $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + +# should compile, but gives an error +$(WORKDIR)/bug1209-ind-goto-rev.$1.$2.prg: bug1209-ind-goto-rev.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently does not compile." + $(if $(QUIET),echo misc/bug1209-ind-goto-rev.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(NOT) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) + +# should compile, but gives an error +$(WORKDIR)/bug1209-ind-goto-rev-2.$1.$2.prg: bug1209-ind-goto-rev-2.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently does not compile." + $(if $(QUIET),echo misc/bug1209-ind-goto-rev-2.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(NOT) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) + +# should compile, but gives an error +$(WORKDIR)/bug1209-ind-goto-rev-3.$1.$2.prg: bug1209-ind-goto-rev-3.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently does not compile." + $(if $(QUIET),echo misc/bug1209-ind-goto-rev-3.$1.$2.prg) + $(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(NOT) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) # should compile, but gives an error $(WORKDIR)/pptest2.$1.$2.prg: pptest2.c | $(WORKDIR) @echo "FIXME: " $$@ "currently does not compile." $(if $(QUIET),echo misc/pptest2.$1.$2.prg) - $(NOT) $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) - -# this should fail to compile, because there are errors in the code -# instead, the compiler crashes -$(WORKDIR)/bug1113.$1.$2.prg: bug1113.c | $(WORKDIR) - @echo "FIXME: " $$@ "compiler crashes but should give an error." - $(if $(QUIET),echo misc/bug1113.$1.$2.prg) - $(NOT) $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) # should compile, but then hangs in an endless loop $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) $(if $(QUIET),echo misc/endless.$1.$2.prg) - $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) # these need reference data that can't be generated by a host-compiled program, # in a useful way -$(WORKDIR)/limits.$1.$2.prg: limits.c $(DIFF) | $(WORKDIR) +$(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) $(if $(QUIET),echo misc/limits.$1.$2.prg) - $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(CC65) -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/limits.$1.$2.out - $(DIFF) $(WORKDIR)/limits.$1.$2.out limits.ref + $(ISEQUAL) $(WORKDIR)/limits.$1.$2.out limits.ref -$(WORKDIR)/goto.$1.$2.prg: goto.c $(DIFF) | $(WORKDIR) +$(WORKDIR)/goto.$1.$2.prg: goto.c $(ISEQUAL) | $(WORKDIR) $(if $(QUIET),echo misc/goto.$1.$2.prg) - $(CL65) -t sim$2 -$1 -o $$@ $$< 2>$(WORKDIR)/goto.$1.$2.out - $(DIFF) $(WORKDIR)/goto.$1.$2.out goto.ref + $(CC65) -t sim$2 -$1 -o $$@ $$< 2>$(WORKDIR)/goto.$1.$2.out + $(ISEQUAL) $(WORKDIR)/goto.$1.$2.out goto.ref # the rest are tests that fail currently for one reason or another $(WORKDIR)/sitest.$1.$2.prg: sitest.c | $(WORKDIR) @echo "FIXME: " $$@ "currently does not compile." - $(NOT) $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) # $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) endef # PRG_template @@ -114,4 +130,3 @@ $(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: @$(call RMDIR,$(WORKDIR)) - @$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/misc/bug1209-ind-goto-rev-2.c b/test/misc/bug1209-ind-goto-rev-2.c new file mode 100644 index 000000000..8918e5878 --- /dev/null +++ b/test/misc/bug1209-ind-goto-rev-2.c @@ -0,0 +1,54 @@ +/* + Copyright 2020 The cc65 Authors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + Test of indirect goto without dynamic labels and order label def, label ref, goto. + https://github.com/cc65/cc65/issues/1209 + This should compile and should be moved to tests/val/ when the bug is fixed. +*/ + +#include +#include + +/* When operating correctly, this returns 0. */ +static unsigned char y = 0; +int f (void) { +L: if (y) return 0; + { + static const void *const x[1] = {&&L}; + y = 1; + goto *x[0]; + } +} + +static unsigned char failures = 0; + +int main (void) +{ + if (f () != 0) failures++; + + if (failures == 0) { + printf ("PASS\n"); + } else { + printf ("FAIL\n"); + } + + return failures; +} diff --git a/test/misc/bug1209-ind-goto-rev-3.c b/test/misc/bug1209-ind-goto-rev-3.c new file mode 100644 index 000000000..4c3268c9a --- /dev/null +++ b/test/misc/bug1209-ind-goto-rev-3.c @@ -0,0 +1,52 @@ +/* + Copyright 2020 The cc65 Authors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + Test of indirect goto without dynamic labels and order label ref, label def, goto. + https://github.com/cc65/cc65/issues/1209 + This should compile and should be moved to tests/val/ when the bug is fixed. +*/ + +#include +#include + +/* When operating correctly, this returns 0. */ +static unsigned char y = 0; +int f (void) { + static const void *const x[1] = {&&L}; +L: if (y) return 0; + y = 1; + goto *x[0]; +} + +static unsigned char failures = 0; + +int main (void) +{ + if (f () != 0) failures++; + + if (failures == 0) { + printf ("PASS\n"); + } else { + printf ("FAIL\n"); + } + + return failures; +} diff --git a/test/err/bug1209-ind-goto-rev.c b/test/misc/bug1209-ind-goto-rev.c similarity index 91% rename from test/err/bug1209-ind-goto-rev.c rename to test/misc/bug1209-ind-goto-rev.c index 39d8639bd..ab8213a30 100644 --- a/test/err/bug1209-ind-goto-rev.c +++ b/test/misc/bug1209-ind-goto-rev.c @@ -19,7 +19,7 @@ */ /* - Tests of indirect goto with the label before the goto. + Test of indirect goto with dynamic labels and order label def, label ref, goto. https://github.com/cc65/cc65/issues/1209 This should compile and should be moved to tests/val/ when the bug is fixed. */ @@ -32,7 +32,7 @@ int f (void) { static void *x[1]; /* Define the label before referencing it with indirect label syntax. */ - L: if (x[0] != 0) return 0; +L: if (x[0] != 0) return 0; x[0] = &&L; goto *x[0]; } @@ -46,7 +46,7 @@ int main (void) if (failures == 0) { printf ("PASS\n"); } else { - printf ("FAIL: %d failures\n", failures); + printf ("FAIL\n"); } return failures; diff --git a/test/ref/Makefile b/test/ref/Makefile index f88821f64..5faf9fb19 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -11,14 +11,12 @@ ifdef CMD_EXE NULLDEV = nul: MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) - DEL = del /f $(subst /,\,$1) else S = / EXE = NULLDEV = /dev/null MKDIR = mkdir -p $1 RMDIR = $(RM) -r $1 - DEL = $(RM) $1 endif ifdef QUIET @@ -28,14 +26,16 @@ endif SIM65FLAGS = -x 200000000 -CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) +CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65) +LD65 := $(if $(wildcard ../../bin/ld65*),..$S..$Sbin$Sld65,ld65) SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) WORKDIR = ..$S..$Stestwrk$Sref OPTIONS = g O Os Osi Osir Osr Oi Oir Or -DIFF = $(WORKDIR)$Sisequal$(EXE) +ISEQUAL = $(WORKDIR)$Sisequal$(EXE) CC = gcc CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow @@ -57,7 +57,7 @@ $(WORKDIR)/%.ref: %.c | $(WORKDIR) $(CC) $(CFLAGS) -o $(WORKDIR)/$*.host $< $(NULLERR) $(WORKDIR)$S$*.host > $@ -$(DIFF): ../isequal.c | $(WORKDIR) +$(ISEQUAL): ../isequal.c | $(WORKDIR) $(CC) $(CFLAGS) -o $@ $< # "yaccdbg.c" includes "yacc.c". @@ -68,11 +68,13 @@ $(WORKDIR)/yaccdbg.%.prg: yacc.c define PRG_template -$(WORKDIR)/%.$1.$2.prg: %.c $(WORKDIR)/%.ref $(DIFF) +$(WORKDIR)/%.$1.$2.prg: %.c $(WORKDIR)/%.ref $(ISEQUAL) $(if $(QUIET),echo ref/$$*.$1.$2.prg) - $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR) + $(CC65) -t sim$2 $$(CC65FLAGS) -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/$$*.$1.$2.out - $(DIFF) $(WORKDIR)/$$*.$1.$2.out $(WORKDIR)/$$*.ref + $(ISEQUAL) $(WORKDIR)/$$*.$1.$2.out $(WORKDIR)/$$*.ref endef # PRG_template @@ -81,4 +83,3 @@ $(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: @$(call RMDIR,$(WORKDIR)) - @$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/todo/Makefile b/test/todo/Makefile index ab5eb598c..17561f8f4 100644 --- a/test/todo/Makefile +++ b/test/todo/Makefile @@ -10,14 +10,12 @@ ifdef CMD_EXE NULLDEV = nul: MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) - DEL = del /f $(subst /,\,$1) else S = / NOT = ! NULLDEV = /dev/null MKDIR = mkdir -p $1 RMDIR = $(RM) -r $1 - DEL = $(RM) $1 endif ifdef QUIET @@ -28,7 +26,9 @@ endif SIM65FLAGS = -x 200000000 -CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) +CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65) +LD65 := $(if $(wildcard ../../bin/ld65*),..$S..$Sbin$Sld65,ld65) SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) WORKDIR = ../../testwrk/val @@ -50,7 +50,9 @@ define PRG_template $(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR) $(if $(QUIET),echo val/$$*.$1.$2.prg) - $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR) + $(CC65) -t sim$2 $$(CC65FLAGS) -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) endef # PRG_template @@ -60,4 +62,3 @@ $(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: @$(call RMDIR,$(WORKDIR)) - @$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/val/Makefile b/test/val/Makefile index be63cd8da..1a9fa9a45 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -9,13 +9,11 @@ ifdef CMD_EXE NULLDEV = nul: MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) - DEL = del /f $(subst /,\,$1) else S = / NULLDEV = /dev/null MKDIR = mkdir -p $1 RMDIR = $(RM) -r $1 - DEL = $(RM) $1 endif ifdef QUIET @@ -26,7 +24,9 @@ endif SIM65FLAGS = -x 5000000000 -CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) +CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65) +LD65 := $(if $(wildcard ../../bin/ld65*),..$S..$Sbin$Sld65,ld65) SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) WORKDIR = ../../testwrk/val @@ -41,11 +41,6 @@ TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02. all: $(TESTS) -# The same input file is processed with different cl65 args, -# but cl65 uses the input file name to make the temp file name, -# and they stomp each other. -.NOTPARALLEL: - $(WORKDIR): $(call MKDIR,$(WORKDIR)) @@ -53,7 +48,9 @@ define PRG_template $(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR) $(if $(QUIET),echo val/$$*.$1.$2.prg) - $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR) + $(CC65) -t sim$2 $$(CC65FLAGS) -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) endef # PRG_template @@ -63,4 +60,3 @@ $(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: @$(call RMDIR,$(WORKDIR)) - @$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/val/bug1201.c b/test/val/bug1201.c new file mode 100644 index 000000000..6d194fbee --- /dev/null +++ b/test/val/bug1201.c @@ -0,0 +1,25 @@ + +/* bug #1201 - The unary operators +, - and ~ should do integer promote on the result types. */ + +char a; +short b; +int c; +long d; +enum E { + Z +} e; +struct S { + int a : 1; +} f; + +_Static_assert(sizeof(+a) == sizeof(int), "Result type should be int"); +_Static_assert(sizeof(+b) == sizeof(int), "Result type should be int"); +_Static_assert(sizeof(+c) == sizeof(int), "Result type should be int"); +_Static_assert(sizeof(+d) == sizeof(long), "Result type should be long"); +_Static_assert(sizeof(+e) == sizeof(int), "Result type should be int"); +_Static_assert(sizeof(+f.a) == sizeof(int), "Result type should be int"); + +int main(void) +{ + return 0; +} diff --git a/testcode/assembler/Makefile b/testcode/assembler/Makefile new file mode 100644 index 000000000..6cb3fe1f2 --- /dev/null +++ b/testcode/assembler/Makefile @@ -0,0 +1,37 @@ + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + +all: paramcount.o + +paramcount.o: paramcount.s + $(AS) -o paramcount.o -l paramcount.lst paramcount.s + +clean: + $(RM) paramcount.o + $(RM) paramcount.lst diff --git a/testcode/disasm/Makefile b/testcode/disasm/Makefile new file mode 100644 index 000000000..05e5b8373 --- /dev/null +++ b/testcode/disasm/Makefile @@ -0,0 +1,58 @@ +# Sample makefile using a preprocessor against info files +# and the --sync-lines option + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 + DA = $(CC65_HOME)/bin/da65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) + DA := $(if $(wildcard ../../../bin/da65*),../../../bin/da65,da65) +endif + +CPP = env LANG=C cpp +CPPFLAGS = # -DTEST_ERROR + +ASMS = fixed.s bank0.s bank1.s +DAIS = fixed.dai bank0.dai bank1.dai + +.SUFFIXES: .da .dai .s +.PHONY: all clean maintainer-clean +.SECONDARY: $(DAIS) + +.da.dai: + $(CPP) -o $@ $(CPPFLAGS) $< + +.dai.s: + $(DA) --sync-lines -o $@ -i $< image.bin + +all: $(ASMS) + +clean: + $(RM) $(ASMS) + +maintainer-clean: clean + $(RM) $(DAIS) + +$(DAIS): fixed.da diff --git a/testcode/disasm/sample-unix.mk b/testcode/disasm/sample-unix.mk deleted file mode 100644 index 0ef64a5e5..000000000 --- a/testcode/disasm/sample-unix.mk +++ /dev/null @@ -1,28 +0,0 @@ -# Sample makefile using a preprocessor against info files -# and the --sync-lines option - -CPP = env LANG=C cpp -CPPFLAGS = # -DTEST_ERROR - -ASMS = fixed.s bank0.s bank1.s -DAIS = fixed.dai bank0.dai bank1.dai - -.SUFFIXES: .da .dai .s -.PHONY: all clean maintainer-clean -.SECONDARY: $(DAIS) - -.da.dai: - $(CPP) -o $@ $(CPPFLAGS) $< - -.dai.s: - da65 --sync-lines -o $@ -i $< image.bin - -all: $(ASMS) - -clean: - rm -f $(ASMS) - -maintainer-clean: clean - rm -f $(DAIS) - -$(DAIS): fixed.da diff --git a/testcode/grc/Makefile b/testcode/grc/Makefile new file mode 100644 index 000000000..793506890 --- /dev/null +++ b/testcode/grc/Makefile @@ -0,0 +1,52 @@ + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 + GRC = $(CC65_HOME)/bin/grc65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) + GRC := $(if $(wildcard ../../../bin/grc65*),../../../bin/grc65,grc65) +endif + +all: test.s vlir.cvt + +test.s: test.grc + $(GRC) -s test.s test.grc + +vlir.cvt: vlir.grc vlir0.s vlir1.s vlir2.s +# using seperate calls here for demonstration purposes: + $(GRC) -t geos-cbm -s vlir.s vlir.grc + $(AS) -t geos-cbm vlir.s + $(AS) -t geos-cbm vlir0.s + $(AS) -t geos-cbm vlir1.s + $(AS) -t geos-cbm vlir2.s + $(LD) -t geos-cbm -o vlir.cvt vlir.o vlir0.o vlir1.o vlir2.o geos-cbm.lib + +# you can also do the above in one command: +# $(CL) -t geos-cbm -o vlir.cvt vlir.grc vlir0.s vlir1.s vlir2.s + +clean: + $(RM) test.s test.h + $(RM) vlir.s vlir.cvt vlir.c vlir.h + $(RM) *.o diff --git a/testcode/grc/vlir0.s b/testcode/grc/vlir0.s index 2e9a3ffd9..a54d406df 100644 --- a/testcode/grc/vlir0.s +++ b/testcode/grc/vlir0.s @@ -5,10 +5,10 @@ ; include some GEOS defines - .include "../../libsrc/geos/inc/const.inc" - .include "../../libsrc/geos/inc/jumptab.inc" - .include "../../libsrc/geos/inc/geossym.inc" - .include "../../libsrc/geos/inc/geosmac.inc" + .include "../../libsrc/geos-common/const.inc" + .include "../../libsrc/geos-cbm/jumptab.inc" + .include "../../libsrc/geos-cbm/geossym.inc" + .include "../../libsrc/geos-common/geosmac.inc" ; import load addresses for all VLIR chains ; these labels are defined upon linking with ld65 diff --git a/testcode/grc/vlir1.s b/testcode/grc/vlir1.s index eae34565e..6ee3cca37 100644 --- a/testcode/grc/vlir1.s +++ b/testcode/grc/vlir1.s @@ -5,10 +5,10 @@ ; include some GEOS defines - .include "../../libsrc/geos/inc/const.inc" - .include "../../libsrc/geos/inc/jumptab.inc" - .include "../../libsrc/geos/inc/geossym.inc" - .include "../../libsrc/geos/inc/geosmac.inc" + .include "../../libsrc/geos-common/const.inc" + .include "../../libsrc/geos-cbm/jumptab.inc" + .include "../../libsrc/geos-cbm/geossym.inc" + .include "../../libsrc/geos-common/geosmac.inc" ; export names of functions that will be used in the main program diff --git a/testcode/grc/vlir2.s b/testcode/grc/vlir2.s index 9d180c847..4c02983ff 100644 --- a/testcode/grc/vlir2.s +++ b/testcode/grc/vlir2.s @@ -5,10 +5,10 @@ ; similar to vlir1.s except the fact that this is chain #2 - .include "../../libsrc/geos/inc/const.inc" - .include "../../libsrc/geos/inc/jumptab.inc" - .include "../../libsrc/geos/inc/geossym.inc" - .include "../../libsrc/geos/inc/geosmac.inc" + .include "../../libsrc/geos-common/const.inc" + .include "../../libsrc/geos-cbm/jumptab.inc" + .include "../../libsrc/geos-cbm/geossym.inc" + .include "../../libsrc/geos-common/geosmac.inc" .export OVERLAY2_Function1 .export OVERLAY2_Function2 diff --git a/testcode/lib/accelerator/Makefile b/testcode/lib/accelerator/Makefile index 6b90a9556..f4f651535 100644 --- a/testcode/lib/accelerator/Makefile +++ b/testcode/lib/accelerator/Makefile @@ -1,4 +1,30 @@ -CL ?= cl65 +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif all: c64-scpu-test.prg c128-scpu-test.prg c64dtv-test.prg \ c64-c128-test.prg c128-test.prg chameleon-test.prg \ @@ -27,3 +53,6 @@ c65-test.prg: c65-test.c turbomaster-test.prg: turbomaster-test.c $(CL) -t c64 turbomaster-test.c -o turbomaster-test.prg + +clean: + $(RM) *.prg diff --git a/testcode/lib/apple2/Makefile b/testcode/lib/apple2/Makefile index 9d551aa62..0020b4ec5 100644 --- a/testcode/lib/apple2/Makefile +++ b/testcode/lib/apple2/Makefile @@ -1,9 +1,37 @@ # For this one see https://applecommander.github.io/ AC ?= ac.jar -CL ?= cl65 +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif -all: hgr.dsk dhgr.dsk +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + +all: hgrshow hgrtest dhgrshow + +disk: hgr.dsk dhgr.dsk hgr.dsk: hgrshow hgrtest cp prodos.dsk $@ @@ -35,3 +63,9 @@ dhgr.dsk: dhgrshow dhgrshow: dhgrshow.c $(CL) -Oirs -t apple2enh --start-addr 0x4000 -m dhgrshow.map $^ + +clean: + $(RM) hgr.dsk dhgr.dsk + $(RM) hgrshow hgrshow.map + $(RM) hgrtest hgrtest.map + $(RM) dhgrshow dhgrshow.map diff --git a/testcode/lib/atari/Makefile b/testcode/lib/atari/Makefile new file mode 100644 index 000000000..a34a5f2d9 --- /dev/null +++ b/testcode/lib/atari/Makefile @@ -0,0 +1,61 @@ + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + +all: charmapping.xex defdev.xex displaylist.xex mem.xex multi.xex ostype.xex \ + scrcode.com sys.xex + +charmapping.xex: charmapping.c + $(CL) -t atari -o charmapping.xex charmapping.c +defdev.xex: defdev.c + $(CL) -t atari -o defdev.xex defdev.c +displaylist.xex: displaylist.c + $(CL) -t atari -o displaylist.xex displaylist.c +mem.xex: mem.c ../getsp.s + $(CL) -t atari -o mem.xex mem.c ../getsp.s +multi.xex: multi-xex.s multi-xex.cfg + $(CL) -t atari -C multi-xex.cfg multi-xex.s -o multi.xex +ostype.xex: ostype.c + $(CL) -t atari -o ostype.xex ostype.c +scrcode.com: scrcode.s +# ca65 -t atari -o scrcode.o scrcode.s +# ld65 -C atari-asm.cfg -o scrcode.com scrcode.o + $(CL) -t atari -C atari-asm.cfg -o scrcode.com scrcode.s +sys.xex: sys.c + $(CL) -t atari -o sys.xex sys.c + +clean: + $(RM) charmapping.xex + $(RM) defdev.xex + $(RM) displaylist.xex + $(RM) mem.xex + $(RM) multi.xex + $(RM) ostype.xex + $(RM) scrcode.o + $(RM) scrcode.com + $(RM) sys.xex diff --git a/testcode/lib/atari/multi.xex b/testcode/lib/atari/multi.xex deleted file mode 100644 index 7da39ad47..000000000 Binary files a/testcode/lib/atari/multi.xex and /dev/null differ diff --git a/testcode/lib/atari/scrcode.s b/testcode/lib/atari/scrcode.s index cd4290781..ba778579b 100644 --- a/testcode/lib/atari/scrcode.s +++ b/testcode/lib/atari/scrcode.s @@ -43,15 +43,20 @@ key: lda CH dispdata: scrcode "fooBa", 'r', $66, 3+4 disp_len = * - dispdata +.export __AUTOSTART__: absolute = 1 .segment "AUTOSTRT" .word $02E0 .word $02E1 .word __CODE_LOAD__+1 +.export __EXEHDR__: absolute = 1 .segment "EXEHDR" .word $FFFF + +.segment "MAINHDR" + .word __CODE_LOAD__ .word __BSS_LOAD__ - 1 diff --git a/testcode/lib/atari/sys.c b/testcode/lib/atari/sys.c index 9ec7aa631..59debd758 100644 --- a/testcode/lib/atari/sys.c +++ b/testcode/lib/atari/sys.c @@ -10,6 +10,8 @@ #include <6502.h> #include +#define IOCB (OS.iocb[0]) + static struct regs regs; static struct __iocb *iocb = &IOCB; /* use IOCB #0 */ diff --git a/testcode/lib/atari5200/Makefile b/testcode/lib/atari5200/Makefile new file mode 100644 index 000000000..990ced689 --- /dev/null +++ b/testcode/lib/atari5200/Makefile @@ -0,0 +1,36 @@ + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + +all: hello + +hello: hello.c + $(CL) -t atari5200 -o hello hello.c + +clean: + $(RM) hello diff --git a/testcode/lib/dir-test.c b/testcode/lib/dir-test.c index 9102fc74d..61e42247e 100644 --- a/testcode/lib/dir-test.c +++ b/testcode/lib/dir-test.c @@ -19,9 +19,13 @@ #include #include #include -#include #include +#if defined(__CBM__) +#include +#elif defined(__APPLE2__) +#include +#endif int main(void) { @@ -51,9 +55,13 @@ int main(void) printf("contents of \"%s\":\n", name); while ((E = readdir (D)) != 0) { printf ("dirent.d_name[] : \"%s\"\n", E->d_name); +#if !defined(__ATARI__) printf ("dirent.d_blocks : %10u\n", E->d_blocks); +#endif printf ("dirent.d_type : %10d\n", E->d_type); +#if !defined(__APPLE2__) && !defined(__ATARI__) printf ("telldir() : %10lu\n", telldir (D)); +#endif printf ("---\n"); if (!go) { switch (cgetc ()) { @@ -63,14 +71,16 @@ int main(void) case 'q': goto done; - +#if !defined(__APPLE2__) && !defined(__ATARI__) case 'r': seekdir (D, E->d_off); break; - +#endif +#if !defined(__ATARI__) case 's': rewinddir (D); break; +#endif } } diff --git a/testcode/lib/gamate/Makefile b/testcode/lib/gamate/Makefile index 2cf98d189..d4f1b9673 100644 --- a/testcode/lib/gamate/Makefile +++ b/testcode/lib/gamate/Makefile @@ -1,14 +1,42 @@ +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + all: audiotest.bin lcdtest.bin ctest.bin audiotest.bin: audiotest.s - ../../../bin/cl65 -l audiotest.lst -t gamate -o audiotest.bin audiotest.s + $(CL) -l audiotest.lst -t gamate -o audiotest.bin audiotest.s lcdtest.bin: lcdtest.s - ../../../bin/cl65 -l lcdtest.lst -t gamate -o lcdtest.bin lcdtest.s + $(CL) -l lcdtest.lst -t gamate -o lcdtest.bin lcdtest.s ctest.bin: ctest.c - ../../../bin/cl65 -l ctest.lst -t gamate -o ctest.bin ctest.c + $(CL) -l ctest.lst -t gamate -o ctest.bin ctest.c nachtm.bin: nachtm.c - ../../../bin/cl65 -Os -l nachtm.lst -t gamate -o nachtm.bin nachtm.c + $(CL) -Os -l nachtm.lst -t gamate -o nachtm.bin nachtm.c gamate-fixcart nachtm.bin test1: lcdtest.bin @@ -21,5 +49,6 @@ testn: nachtm.bin cd ~/Desktop/mame/winmess/ && wine mess.exe gamate -window -skip_gameinfo -cart ~/Desktop/cc65/github/cc65/testcode/lib/gamate/nachtm.bin clean: - rm -f lcdtest.o audiotest.o ctest.o - rm -f lcdtest.bin audiotest.bin ctest.bin nachtm.bin + $(RM) lcdtest.o audiotest.o ctest.o + $(RM) lcdtest.bin audiotest.bin ctest.bin nachtm.bin + $(RM) audiotest.lst lcdtest.lst ctest.lst diff --git a/testcode/lib/gamate/ctest.c b/testcode/lib/gamate/ctest.c index 793770cee..bff3f5986 100644 --- a/testcode/lib/gamate/ctest.c +++ b/testcode/lib/gamate/ctest.c @@ -25,19 +25,19 @@ int main(int argc, char *argv[]) gotoxy(0,2);cprintf("%04x %02x %02x %02x", n, x, y, *((unsigned char*)JOY_DATA)); switch((*((unsigned char*)JOY_DATA))) { - case 0xff ^ JOY_DATA_UP: + case 0xff ^ JOY_UP_MASK: ++y; if (y == 0xc8) y = 0; break; - case 0xff ^ JOY_DATA_DOWN: + case 0xff ^ JOY_DOWN_MASK: --y; if (y == 0xff) y = 0xc7; break; - case 0xff ^ JOY_DATA_LEFT: + case 0xff ^ JOY_LEFT_MASK: ++x; break; - case 0xff ^ JOY_DATA_RIGHT: + case 0xff ^ JOY_RIGHT_MASK: --x; break; - case 0xff ^ JOY_DATA_FIRE_A: + case 0xff ^ JOY_BTN_A_MASK: break; } diff --git a/testcode/lib/heaptest.c b/testcode/lib/heaptest.c index d776e2f0c..560694bee 100644 --- a/testcode/lib/heaptest.c +++ b/testcode/lib/heaptest.c @@ -214,10 +214,10 @@ int main (void) /* Show info at start */ ShowInfo (); - +#if !defined(__APPLE2__) /* Remember the time */ T = clock (); - +#endif /* Do the tests */ Test1 (); Test2 (); @@ -226,10 +226,11 @@ int main (void) Test5 (); Test6 (); +#if !defined(__APPLE2__) /* Calculate the time and print it */ T = clock () - T; printf ("Time needed: %lu ticks\n", T); - +#endif /* Done */ return EXIT_SUCCESS; } diff --git a/testcode/lib/mouse-test.c b/testcode/lib/mouse-test.c index ea8311d19..64482b937 100644 --- a/testcode/lib/mouse-test.c +++ b/testcode/lib/mouse-test.c @@ -190,7 +190,7 @@ int main (void) #endif /* Set dark-on-light colors. Clear the screen. */ -#ifdef __CBM__ +#if defined(__CBM__) && !defined(__VIC20__) (void) bordercolor (COLOR_GRAY2); (void) bgcolor (COLOR_WHITE); (void) textcolor (COLOR_GRAY1); diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile index a4a495c9a..0c41778cc 100644 --- a/testcode/lib/pce/Makefile +++ b/testcode/lib/pce/Makefile @@ -1,3 +1,32 @@ + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + .PHONY: all clean test # Size of cartridge to generate. diff --git a/testcode/lib/scanf-test.c b/testcode/lib/scanf-test.c index 9fce01b77..f17b62294 100644 --- a/testcode/lib/scanf-test.c +++ b/testcode/lib/scanf-test.c @@ -14,9 +14,7 @@ /* Define USE_STDIO, when you want to use the stdio functions. ** Do not define it, when you want to use the conio functions. */ -/* #define USE_STDIO -*/ #include #include @@ -35,22 +33,23 @@ #define ARRAYSIZE(a) (sizeof (a) / sizeof (a)[0]) +typedef enum { + INT, + CHAR +} TYPE; + +typedef union { + int nvalue; + const char *svalue; +} VALUE; + static const struct { const char *input, *format; int rvalue; - enum TYPE { - INT, - CHAR - } type1; - union { - int nvalue; - const char *svalue; - } v1; - enum TYPE type2; - union { - int nvalue; - const char *svalue; - } v2; + TYPE type1; + VALUE v1; + TYPE type2; + VALUE v2; } test_data[] = { /* Input sequences for character specifiers must be less than 80 characters ** long. These format strings are allowwed a maximum of two assignment diff --git a/testcode/lib/strdup-test.c b/testcode/lib/strdup-test.c index e30841c3e..2fcc9816f 100644 --- a/testcode/lib/strdup-test.c +++ b/testcode/lib/strdup-test.c @@ -84,19 +84,21 @@ int main (void) /* Show info at start */ ShowInfo (); - +#if !defined(__APPLE2__) /* Remember the time */ T = clock (); - +#endif /* Do the tests */ FillArray (); ShowInfo (); FreeArray (); ShowInfo (); +#if !defined(__APPLE2__) /* Calculate the time and print it */ T = clock () - T; printf ("Time needed: %lu ticks\n", T); +#endif /* Done */ return EXIT_SUCCESS;