How to include a file given as macro parameter in ca65

36 Views Asked by At

I'm trying to write a ca65 macro that should include a file given as the macro parameter. ca65 is the assembler of the cc65 compiler suite.

While I got this to work with the .incbin command:

.macro includethis4 filename
  .incbin .concat (filename, ".", "i")    ;this works
.endmacro

includethis4 "dummyfile"   ;this works!

I get an error "Error: String constant expected" when using .include instead of .incbin

.macro includethis3 filename
  .include .concat (filename, ".", "i")    ;this fails
.endmacro

includethis3 "dummyfile"   ;this fails!

It is clear to me that .include and .incbin do different things; .include includes the file into the sourcecode and parses it while .incbin adds the file's contents to the output. For my application, I need .include.

Using .include with a concatenated string works when used outside of the macro:

.include .concat ("dummyfile", ".", "i")    ;this works

The same line, with a constant string still causes an "Error: String constant expected" when used within a macro, even if the macro has no parameters:

.macro includethis2 
  .include .concat ("dummyfile", ".", "i")   ;this fails
.endmacro

includethis2    ;this fails

My testfile "dummyfile.i" was empty, so there cannot have been side-effects from the included file. The command to assemble my examples was

ca65 testmacroinc.s

My questions are:

  1. why does it work with .incbin, but not with .include ?
  2. how can I achieve the functionality of .include .concat (filename, ".", "i") within a macro?
0

There are 0 best solutions below