From f21605a972cb55c3d08ccc685fa51dd5e0c43c30 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 28 Aug 2005 21:42:03 +0000 Subject: [PATCH] New atari builtin macro package that features a scrcode macro. Changed the scrcode macro from the cbm builtin macro package to accept multiple arguments of different types. git-svn-id: svn://svn.cc65.org/cc65/trunk@3598 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/.cvsignore | 1 + src/ca65/macpack.c | 2 + src/ca65/macpack.h | 1 + src/ca65/macpack/atari.mac | 59 +++++++++++++++++++++++++++++ src/ca65/macpack/cbm.mac | 76 +++++++++++++++++++++++++++++--------- src/ca65/make/gcc.mak | 6 ++- 6 files changed, 126 insertions(+), 19 deletions(-) create mode 100644 src/ca65/macpack/atari.mac diff --git a/src/ca65/.cvsignore b/src/ca65/.cvsignore index 605aeec6f..82678fd6f 100644 --- a/src/ca65/.cvsignore +++ b/src/ca65/.cvsignore @@ -1,6 +1,7 @@ .depend ca65 .kdbgrc.ca65 +atari.inc cbm.inc cpu.inc generic.inc diff --git a/src/ca65/macpack.c b/src/ca65/macpack.c index 6cf5c09d3..a6ec607c1 100644 --- a/src/ca65/macpack.c +++ b/src/ca65/macpack.c @@ -52,6 +52,7 @@ /* Predefined macro packages converted into C strings by a perl script */ +#include "atari.inc" #include "cbm.inc" #include "cpu.inc" #include "generic.inc" @@ -63,6 +64,7 @@ static struct { char* Package; } MacPackages[MAC_COUNT] = { /* Packages sorted by id */ + { "atari", MacAtari }, { "cbm", MacCBM }, { "cpu", MacCPU }, { "generic", MacGeneric }, diff --git a/src/ca65/macpack.h b/src/ca65/macpack.h index 75ca43b5c..73184c043 100644 --- a/src/ca65/macpack.h +++ b/src/ca65/macpack.h @@ -46,6 +46,7 @@ /* Constants for the predefined packages */ enum { + MAC_ATARI, MAC_CBM, MAC_CPU, MAC_GENERIC, diff --git a/src/ca65/macpack/atari.mac b/src/ca65/macpack/atari.mac new file mode 100644 index 000000000..981bd105f --- /dev/null +++ b/src/ca65/macpack/atari.mac @@ -0,0 +1,59 @@ +; 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 +.endmacro + diff --git a/src/ca65/macpack/cbm.mac b/src/ca65/macpack/cbm.mac index 6850c7b43..4685508d7 100644 --- a/src/ca65/macpack/cbm.mac +++ b/src/ca65/macpack/cbm.mac @@ -1,22 +1,62 @@ ; Convert characters to screen codes -.macro scrcode str - .repeat .strlen(str), i - .if (.strat(str, i) >= '@' .and .strat(str, i) <= 'z') - .byte .strat(str, i) - '@' - .elseif (.strat(str, i) >= 'A' .and .strat(str, i) <= 'Z') - .byte .strat(str, i) - 'A' + 65 - .elseif (.strat(str, i) = '[') - .byte 27 - .elseif (.strat(str, i) = ']') - .byte 29 - .elseif (.strat(str, i) = '^') - .byte 30 - .elseif (.strat(str, i) = '_') - .byte 31 - .else - .byte .strat(str, i) - .endif - .endrepeat + +; 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 +.endmacro + diff --git a/src/ca65/make/gcc.mak b/src/ca65/make/gcc.mak index 3eeecb781..897b09cb2 100644 --- a/src/ca65/make/gcc.mak +++ b/src/ca65/make/gcc.mak @@ -59,7 +59,8 @@ OBJS = anonname.o \ # ----------------------------------------------------------------------------- # List of all macro files -INCS = cbm.inc \ +INCS = atari.inc \ + cbm.inc \ cpu.inc \ generic.inc \ longbranch.inc @@ -102,6 +103,9 @@ depend dep: $(OBJS:.o=.c) # ----------------------------------------------------------------------------- # Rules to make config includes +atari.inc: macpack/atari.mac + @$(CVT) $< $@ MacAtari + cbm.inc: macpack/cbm.mac @$(CVT) $< $@ MacCBM -- 2.39.5