Replaced builtin macro packages with .mac files that are included like ordinary .inc files.

The benefits are:
- Independency of ca65 build from perl
- More transparent behaviour
This commit is contained in:
Oliver Schmidt
2013-04-07 22:10:30 +02:00
parent 414a59ce65
commit 54299fae5a
11 changed files with 9 additions and 420 deletions

View File

@@ -1,173 +0,0 @@
/*****************************************************************************/
/* */
/* macpack.c */
/* */
/* Predefined macro packages for the ca65 macroassembler */
/* */
/* */
/* */
/* (C) 1998-2008, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed 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. */
/* */
/*****************************************************************************/
/* common */
#include "check.h"
#include "strbuf.h"
#include "strutil.h"
/* ca65 */
#include "error.h"
#include "scanner.h"
#include "macpack.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Predefined macro packages converted into C strings by a perl script */
#include "atari.inc"
#include "cbm.inc"
#include "cpu.inc"
#include "generic.inc"
#include "longbranch.inc"
/* Table with pointers to the different packages */
static struct {
const char* Name;
char* Package;
} MacPackages[MAC_COUNT] = {
/* Packages sorted by id */
{ "atari", MacAtari },
{ "cbm", MacCBM },
{ "cpu", MacCPU },
{ "generic", MacGeneric },
{ "longbranch", MacLongBranch },
};
/* Directory that contains standard macro package files */
static StrBuf MacPackDir = STATIC_STRBUF_INITIALIZER;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
int MacPackFind (const StrBuf* 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 (SB_CompareStr (Name, MacPackages[I].Name) == 0) {
/* Found */
return I;
}
}
/* Not found */
return -1;
}
int MacPackInsert (int Id)
/* Insert the macro package with the given id in the input stream. Returns
* true if the macro package was found and successfully inserted. Returns
* false otherwise.
*/
{
int RetCode;
/* Check the parameter */
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);
/* Always successful */
RetCode = 1;
} 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 */
RetCode = NewInputFile (SB_GetConstBuf (&Filename));
/* Destroy the contents of Filename */
SB_Done (&Filename);
}
/* Return the success code */
return RetCode;
}
void MacPackSetDir (const StrBuf* 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_Copy (&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);
}

View File

@@ -1,96 +0,0 @@
/*****************************************************************************/
/* */
/* macpack.h */
/* */
/* Predefined macro packages for the ca65 macroassembler */
/* */
/* */
/* */
/* (C) 1998-2008, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed 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. */
/* */
/*****************************************************************************/
#ifndef MACPACK_H
#define MACPACK_H
/* common */
#include "strbuf.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Constants for the predefined packages */
enum {
MAC_ATARI,
MAC_CBM,
MAC_CPU,
MAC_GENERIC,
MAC_LONGBRANCH,
/* Number of known packages */
MAC_COUNT
};
/*****************************************************************************/
/* Code */
/*****************************************************************************/
int MacPackFind (const StrBuf* Name);
/* Find a macro package by name. The function will either return the id or
* -1 if the package name was not found.
*/
int MacPackInsert (int Id);
/* Insert the macro package with the given id in the input stream. Returns
* true if the macro package was found and successfully inserted. Returns
* false otherwise.
*/
void MacPackSetDir (const StrBuf* 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 */
#endif

View File

@@ -1,59 +0,0 @@
; Convert characters to screen codes
; Helper macro that converts and outputs one character
.macro _scrcode char
.if (char >= 0) .and (char <= 31)
.byte (char + 64)
.elseif (char >= 32) .and (char <= 95)
.byte (char - 32)
.elseif (char >= 96) .and (char <= 127)
.byte char
.elseif (char >= 128) .and (char <= 159)
.byte (char + 64)
.elseif (char >= 160) .and (char <= 223)
.byte (char - 32)
.elseif (char >= 224) .and (char <= 255)
.byte char
.else
.error "scrcode: Character constant out of range"
.endif
.endmacro
.macro scrcode arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
; Bail out if next argument is empty
.if .blank (arg1)
.exitmacro
.endif
; Check for a string
.if .match ({arg1}, "")
; Walk over all string chars
.repeat .strlen (arg1), i
_scrcode {.strat (arg1, i)}
.endrepeat
; Check for a number
.elseif .match (.left (1, {arg1}), 0)
; Just output the number
_scrcode arg1
; Check for a character
.elseif .match (.left (1, {arg1}), 'a')
; Just output the character
_scrcode arg1
; Anything else is an error
.else
.error "scrcode: invalid argument type"
.endif
; Call the macro recursively with the remaining args
scrcode arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
.endmacro

View File

@@ -1,62 +0,0 @@
; Convert characters to screen codes
; Helper macro that converts and outputs one character
.macro _scrcode char
.if (char >= '@' .and char <= 'z')
.byte (char - '@')
.elseif (char >= 'A' .and char <= 'Z')
.byte (char - 'A' + 65)
.elseif (char = '[')
.byte 27
.elseif (char = ']')
.byte 29
.elseif (char = '^')
.byte 30
.elseif (char = '_')
.byte 31
.elseif (char < 256)
.byte char
.else
.error "scrcode: Character constant out of range"
.endif
.endmacro
.macro scrcode arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
; Bail out if next argument is empty
.if .blank (arg1)
.exitmacro
.endif
; Check for a string
.if .match ({arg1}, "")
; Walk over all string chars
.repeat .strlen (arg1), i
_scrcode {.strat (arg1, i)}
.endrepeat
; Check for a number
.elseif .match (.left (1, {arg1}), 0)
; Just output the number
_scrcode arg1
; Check for a character
.elseif .match (.left (1, {arg1}), 'a')
; Just output the character
_scrcode arg1
; Anything else is an error
.else
.error "scrcode: invalid argument type"
.endif
; Call the macro recursively with the remaining args
scrcode arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
.endmacro

View File

@@ -1,24 +0,0 @@
; CPU bitmask constants
CPU_ISET_NONE = $0001
CPU_ISET_6502 = $0002
CPU_ISET_6502X = $0004
CPU_ISET_65SC02 = $0008
CPU_ISET_65C02 = $0010
CPU_ISET_65816 = $0020
CPU_ISET_SUNPLUS = $0040
CPU_ISET_SWEET16 = $0080
CPU_ISET_HUC6280 = $0100
; CPU capabilities
CPU_NONE = CPU_ISET_NONE
CPU_6502 = CPU_ISET_6502
CPU_6502X = CPU_ISET_6502|CPU_ISET_6502X
CPU_65SC02 = CPU_ISET_6502|CPU_ISET_65SC02
CPU_65C02 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02
CPU_65816 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65816
CPU_SUNPLUS = CPU_ISET_SUNPLUS
CPU_SWEET16 = CPU_ISET_SWEET16
CPU_HUC6280 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02|CPU_ISET_HUC6280

View File

@@ -1,75 +0,0 @@
#!/usr/bin/perl
# Check number of params
die "Usage: cvt-cfg.pl input output varname\n" unless ($#ARGV == 2);
# Get the parameters
$InputName = shift (@ARGV);
$OutputName = shift (@ARGV);
$VarName = shift (@ARGV);
# Open both files
open (IN, "<$InputName") or die "Cannot open $InputName\n";
open (OUT, ">$OutputName") or die "Cannot open $OutputName\n";
# Print the header to the output file
print OUT "static char $VarName" . "[] = \n";
# Read from input, print to output
while ($Line = <IN>) {
# Remove the newline
chomp $Line;
# Separate an existing comment. No need to be overly clever, just ignore
# semicolons in strings.
if ($Line =~ /(.*?)(\s*)(;\s*)(.*?)\s*$/) {
$Line = $1;
$CommentSpace = $2;
$Comment = $4;
} else {
$CommentSpace = "";
$Comment = "";
}
# Remove leading and trailing spaces
$Line =~ s/^\s*|\s*$//g;
# Ignore empty lines
if ($Line eq "") {
if ($Comment ne "") {
print OUT "/* $Comment */\n";
}
next;
}
# Replace control chars
$Line =~ s/\\/\\\\/g;
$Line =~ s/\"/\\\"/g;
$Line =~ s/\'/\\\'/g;
# Print to output
print OUT "\"$Line\\n\"";
# Add a comment if we have one
if ($Comment ne "") {
print OUT "$CommentSpace/* $Comment */";
}
# Terminate the line
print OUT "\n";
}
# Terminate the variable declaration
print OUT ";\n";
# Close the files
close IN;
close OUT;
# Done
exit 0;

View File

@@ -1,45 +0,0 @@
; add - Add without carry
.macro add Arg1, Arg2
clc
.if .paramcount = 2
adc Arg1, Arg2
.else
adc Arg1
.endif
.endmacro
; sub - subtract without borrow
.macro sub Arg1, Arg2
sec
.if .paramcount = 2
sbc Arg1, Arg2
.else
sbc Arg1
.endif
.endmacro
; bge - jump if unsigned greater or equal
.macro bge Arg
bcs Arg
.endmacro
; blt - Jump if unsigned less
.macro blt Arg
bcc Arg
.endmacro
; bgt - jump if unsigned greater
.macro bgt Arg
.local L
beq L
bcs Arg
L:
.endmacro
; ble - jump if unsigned less or equal
.macro ble Arg
beq Arg
bcc Arg
.endmacro

View File

@@ -1,88 +0,0 @@
.macro jeq Target
.if .match(Target, 0)
bne *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
beq Target
.else
bne *+5
jmp Target
.endif
.endmacro
.macro jne Target
.if .match(Target, 0)
beq *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bne Target
.else
beq *+5
jmp Target
.endif
.endmacro
.macro jmi Target
.if .match(Target, 0)
bpl *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bmi Target
.else
bpl *+5
jmp Target
.endif
.endmacro
.macro jpl Target
.if .match(Target, 0)
bmi *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bpl Target
.else
bmi *+5
jmp Target
.endif
.endmacro
.macro jcs Target
.if .match(Target, 0)
bcc *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bcs Target
.else
bcc *+5
jmp Target
.endif
.endmacro
.macro jcc Target
.if .match(Target, 0)
bcs *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bcc Target
.else
bcs *+5
jmp Target
.endif
.endmacro
.macro jvs Target
.if .match(Target, 0)
bvc *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bvs Target
.else
bvc *+5
jmp Target
.endif
.endmacro
.macro jvc Target
.if .match(Target, 0)
bvs *+5
jmp Target
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
bvc Target
.else
bvs *+5
jmp Target
.endif
.endmacro

View File

@@ -65,7 +65,6 @@
#include "istack.h"
#include "lineinfo.h"
#include "listing.h"
#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objfile.h"
@@ -526,18 +525,6 @@ static void OptListing (const char* Opt, const char* Arg)
static void OptMacPackDir (const char* Opt attribute ((unused)), const char* Arg)
/* Set a macro package directory */
{
/* Make a string buffer from Arg */
StrBuf Dir;
/* Use the directory */
MacPackSetDir (SB_InitFromString (&Dir, Arg));
}
static void OptMemoryModel (const char* Opt, const char* Arg)
/* Set the memory model */
{
@@ -891,7 +878,6 @@ int main (int argc, char* argv [])
{ "--large-alignment", 0, OptLargeAlignment },
{ "--list-bytes", 1, OptListBytes },
{ "--listing", 1, OptListing },
{ "--macpack-dir", 1, OptMacPackDir },
{ "--memory-model", 1, OptMemoryModel },
{ "--pagelength", 1, OptPageLength },
{ "--relax-checks", 0, OptRelaxChecks },

View File

@@ -21,9 +21,6 @@ override CFLAGS += -DCA65_INC=$(CA65_INC)
EBIND = emxbind
LDFLAGS =
# Perl script for macro file conversion
CVT=macpack/cvt-mac.pl
# -----------------------------------------------------------------------------
# List of all object files
@@ -45,7 +42,6 @@ OBJS = anonname.o \
istack.o \
lineinfo.o \
listing.o \
macpack.o \
macro.o \
main.o \
nexttok.o \
@@ -72,12 +68,6 @@ OBJS = anonname.o \
# -----------------------------------------------------------------------------
# List of all macro files
INCS = atari.inc \
cbm.inc \
cpu.inc \
generic.inc \
longbranch.inc
LIBS = $(COMMON)/common.a
# ------------------------------------------------------------------------------
@@ -93,17 +83,15 @@ all: depend
@$(MAKE) -f make/gcc.mak all
endif
$(EXE): $(INCS) $(OBJS) $(LIBS)
$(EXE): $(OBJS) $(LIBS)
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
@if [ $(OS2_SHELL) ] ; then $(EBIND) $(EXE) ; fi
inc: $(INCS)
clean:
$(RM) *~ core.* *.map
zap: clean
$(RM) *.o $(EXE) $(INCS) .depend
$(RM) *.o $(EXE) .depend
# ------------------------------------------------------------------------------
# Make the dependencies
@@ -112,31 +100,3 @@ zap: clean
depend dep: $(INCS) $(OBJS:.o=.c)
@echo "Creating dependency information"
$(CC) $(CFLAGS) -MM $(OBJS:.o=.c) > .depend
# -----------------------------------------------------------------------------
# Rules to make config includes
atari.inc: macpack/atari.mac
@$(CVT) $< $@ MacAtari
cbm.inc: macpack/cbm.mac
@$(CVT) $< $@ MacCBM
cpu.inc: macpack/cpu.mac
@$(CVT) $< $@ MacCPU
generic.inc: macpack/generic.mac
@$(CVT) $< $@ MacGeneric
longbranch.inc: macpack/longbranch.mac
@$(CVT) $< $@ MacLongBranch

View File

@@ -67,7 +67,6 @@
#include "incpath.h"
#include "instr.h"
#include "listing.h"
#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objcode.h"
@@ -1444,28 +1443,16 @@ static void DoLocalChar (void)
static void DoMacPack (void)
/* Insert a macro package */
{
int Package;
/* We expect an identifier */
if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
/* Search for the macro package name */
LocaseSVal ();
Package = MacPackFind (&CurTok.SVal);
if (Package < 0) {
/* Not found */
ErrorSkip ("Invalid macro package");
return;
}
/* Insert the package. If this fails, skip the remainder of the line to
* avoid additional error messages.
*/
if (MacPackInsert (Package) == 0) {
SkipUntilSep ();
} else {
SB_AppendStr (&CurTok.SVal, ".mac");
SB_Terminate (&CurTok.SVal);
if (NewInputFile (SB_GetConstBuf (&CurTok.SVal)) == 0) {
/* Error opening the file, skip remainder of line */
SkipUntilSep ();
}
}
}