unsigned char UbiquitousIdents = 0; /* Allow ubiquitous identifiers */
/* Misc stuff */
-const char Copyright[] = "(C) Copyright 1998-2004 Ullrich von Bassewitz";
+const char Copyright[] = "(C) Copyright 1998-2005 Ullrich von Bassewitz";
/* common */
#include "check.h"
+#include "strbuf.h"
+#include "strutil.h"
/* ca65 */
#include "error.h"
#include "longbranch.inc"
/* Table with pointers to the different packages */
-static char* MacPackages [] = {
- MacGeneric,
- MacLongBranch,
- MacCBM,
- MacCPU
+static struct {
+ const char* Name;
+ char* Package;
+} MacPackages[MAC_COUNT] = {
+ /* Packages sorted by id */
+ { "cbm", MacCBM },
+ { "cpu", MacCPU },
+ { "generic", MacGeneric },
+ { "longbranch", MacLongBranch },
};
+/* Directory that contains standard macro package files */
+static StrBuf MacPackDir = STATIC_STRBUF_INITIALIZER;
+
/*****************************************************************************/
-void InsertMacPack (unsigned Id)
+int MacPackFind (const char* Name)
+/* Find a macro package by name. The function will either return the id or
+ * -1 if the package name was not found.
+ */
+{
+ int I;
+
+ for (I = 0; I < MAC_COUNT; ++I) {
+ if (StrCaseCmp (Name, MacPackages[I].Name) == 0) {
+ /* Found */
+ return I;
+ }
+ }
+
+ /* Not found */
+ return -1;
+}
+
+
+
+void MacPackInsert (int Id)
/* Insert the macro package with the given id in the input stream */
{
/* Check the parameter */
- CHECK (Id < sizeof (MacPackages) / sizeof (MacPackages [0]));
+ CHECK (Id >= 0 && Id < MAC_COUNT);
+
+ /* If we have a macro package directory given, load a file from the
+ * directory, otherwise use the builtin stuff.
+ */
+ if (SB_IsEmpty (&MacPackDir)) {
+
+ /* Insert the builtin package */
+ NewInputData (MacPackages[Id].Package, 0);
- /* Insert the package */
- NewInputData (MacPackages[Id], 0);
+ } else {
+
+ StrBuf Filename = AUTO_STRBUF_INITIALIZER;
+
+ /* Build the complete file name */
+ SB_Copy (&Filename, &MacPackDir);
+ SB_AppendStr (&Filename, MacPackages[Id].Name);
+ SB_AppendStr (&Filename, ".mac");
+ SB_Terminate (&Filename);
+
+ /* Open the macro package as include file */
+ NewInputFile (SB_GetConstBuf (&Filename));
+
+ /* Destroy the contents of Filename */
+ DoneStrBuf (&Filename);
+
+ }
+}
+
+
+
+void MacPackSetDir (const char* Dir)
+/* Set a directory where files for macro packages can be found. Standard is
+ * to use the builtin packages. For debugging macro packages, external files
+ * can be used.
+ */
+{
+ /* Copy the directory name to the buffer */
+ SB_CopyStr (&MacPackDir, Dir);
+
+ /* Make sure that the last character is a path delimiter */
+ if (SB_NotEmpty (&MacPackDir)) {
+ char C = SB_LookAtLast (&MacPackDir);
+ if (C != '\\' && C != '/') {
+ SB_AppendChar (&MacPackDir, '/');
+ }
+ }
+
+ /* Terminate the buffer so it's usable as a C string */
+ SB_Terminate (&MacPackDir);
}
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2005, Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Constants for the predefined packages */
-#define MAC_GENERIC 0
-#define MAC_LONGBRANCH 1
-#define MAC_CBM 2
-#define MAC_CPU 3
+enum {
+ MAC_CBM,
+ MAC_CPU,
+ MAC_GENERIC,
+ MAC_LONGBRANCH,
+
+ /* Number of known packages */
+ MAC_COUNT
+};
-void InsertMacPack (unsigned Id);
+int MacPackFind (const char* Name);
+/* Find a macro package by name. The function will either return the id or
+ * -1 if the package name was not found.
+ */
+
+void MacPackInsert (int Id);
/* Insert the macro package with the given id in the input stream */
+void MacPackSetDir (const char* Dir);
+/* Set a directory where files for macro packages can be found. Standard is
+ * to use the builtin packages. For debugging macro packages, external files
+ * can be used.
+ */
+
/* End of macpack.h */
/* */
/* */
/* */
-/* (C) 1998-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2005, Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include "istack.h"
#include "lineinfo.h"
#include "listing.h"
+#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objfile.h"
" --include-dir dir\tSet an include directory search path\n"
" --listing\t\tCreate a listing if assembly was ok\n"
" --list-bytes n\tMaximum number of bytes per listing line\n"
+ " --macpack-dir dir\tSet a macro package directory\n"
" --memory-model model\tSet the memory model\n"
" --pagelength n\tSet the page length for the listing\n"
" --smart\t\tEnable smart mode\n"
+static void OptMacPackDir (const char* Opt attribute ((unused)), const char* Arg)
+/* Set a macro package directory */
+{
+ /* Use the directory */
+ MacPackSetDir (Arg);
+}
+
+
+
static void OptMemoryModel (const char* Opt, const char* Arg)
/* Set the memory model */
{
{ "--include-dir", 1, OptIncludeDir },
{ "--list-bytes", 1, OptListBytes },
{ "--listing", 0, OptListing },
+ { "--macpack-dir", 1, OptMacPackDir },
{ "--memory-model", 1, OptMemoryModel },
{ "--pagelength", 1, OptPageLength },
{ "--smart", 0, OptSmart },
static void DoMacPack (void)
/* Insert a macro package */
{
- /* Macro package names */
- static const char* Keys [] = {
- "GENERIC",
- "LONGBRANCH",
- "CBM",
- "CPU"
- };
-
int Package;
/* We expect an identifier */
return;
}
- /* Map the keyword to a number */
- Package = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
+ /* Search for the macro package name */
+ Package = MacPackFind (SVal);
if (Package < 0) {
/* Not found */
ErrorSkip ("Invalid macro package");
NextTok ();
/* Insert the package */
- InsertMacPack (Package);
+ MacPackInsert (Package);
}