How do you get CodeWarrior to add assembler source files to a project?

bribri

Active member
This ought to be an easy and dumb question, but for the life of me I can't figure it out.

I want to add a 68k assembler source file to a CodeWarrior (Pro 4) project. But I can't figure out how! Am I supposed to use a .a extension for it? Regardless of what extension I do use -- and I've tried .a, .s, and .asm -- it won't let me add it to the project. I see my project settings has a "file mappings" section but it doesn't give me the option of specifying that the source file should be compiled as assembler. (Only options C / C++, rez, lib importer, MPW importer, PEF importer, and "balloon help".)

For that matter, is CodeWarrior's 68k assembler syntax still documented anywhere I can get at it?
 

joevt

Well-known member
I don't think CodeWarrior has a dedicated 68K assembler.

.a files are used by the MPW assembler which can produce a .o object file that a CodeWarrior project can include.

For CodeWarrior, you include assembly code inside .c files. For example, check the contents of these:
Metrowerks CodeWarrior/MacOS Support/Libraries/Runtime/Runtime 68K/(Sources)/Appl68KStartup.c
Metrowerks CodeWarrior/MacOS Support/Libraries/Runtime/Runtime 68K/(Sources)/(Startup Sources)/DRVRStartup.c
Metrowerks CodeWarrior/MacOS Support/Libraries/Runtime/Runtime 68K/(Sources)/(Startup Sources)/Startup.c
Metrowerks CodeWarrior/MacOS Support/Libraries/Runtime/Runtime 68K/(Sources)/(Startup Sources)/StartupA4.c

It appears the C compiler's integrated/inline assembler can handle fields of structs and such.

Check the CodeWarrior documentation for assembly or assembler references:
C Compilers Ref.pdf
CW Porting Guide.pdf
Debugger Guide.pdf
Error Reference.pdf
IDE User Guide.pdf
Pascal Compilers Ref.pdf
Pascal Language Ref.pdf
Pascal Library Ref.pdf
Profiler Guide.pdf
Target Mac OS.pdf
 

joevt

Well-known member
All the CodeWarrior pdfs have a "Guide to CodeWarrior Documentation" section that mentions a stand-alone assembler and an "Assembler Guide" document but I don't think CodeWarrior Pro 4 includes those.

Target Mac OS.pdf says the "Assembler Guide" documents the PowerPC assembler and the 68K assembler.

Actually, in the Compiler's folder is a PPCAsm compiler (but no compiler for 68K).
 

bribri

Active member
Hmm, I could give MPW a try, but it unfortunately uses really different syntax from GNU, which is how my code is written right now. I found a document here that suggests there's a version of CodeWarrior that uses a more GNU-like syntax:
but this looks like it's for a later CodeWarrior version, and may not have much of a relationship with the older Mac versions.

Surely they have some kind of supported way of writing assembler, though, outside of using MPW, or doing it in C files.
 

bribri

Active member
Well, I am a bit confused. The CodeWarrior documentation makes numerous references to a standalone assembler, as well as an "Assembler Guide" manual that digs into it. However, it appears the CodeWarrior Pro 4 installer just doesn't include this assembler (or at least not the image on Macintosh Garden) and I can't find any copy of that manual anywhere. I did find an Assembler Reference manual with the CodeWarrior Pro 5 reference material, but it seems like it's mainly for x86 and probably therefore Windows.
 

adespoton

Well-known member
Yup. As @joevt stated, there's references in the documentation, but CWP4 doesn't actually contain a stand-alone assembler.

Personally, what I've always done is use the in-line assembler and just had .c files with an in-line directive followed by my asm.
 

cheesestraws

Well-known member
Yes; unless there's something impractical about it I'd suggest embedding your assembler in some token C - that's what I've done in the past. There's no stand-alone assembler. Which is odd, because as you say, some of the documentation suggests there ought to be.
 

bribri

Active member
That's what I may end up doing. I'm trying to be overly clever and see if there's some way I can get the same assembly code compiling in both CodeWarrior and gcc. I was hoping the docs I was reading for CodeWarrior's standalone assembler applied to classic Mac OS, because it seemed like it supported a good subset of the gcc / AT&T style syntax, but alas it was not meant to be.

So now I'm trying to decide on what's the better approach...

1) Using a script to (crudely) convert gcc assembly files to MPW assembly, and then use MPW to compile it to a .o file I can include in a CodeWarrior project.

2) Replacing all macros in my gcc assembly with C-style macros, so that CodeWarrior can compile it.

I've already gotten both approaches to work, but they both have their drawbacks. With 1 I can keep the structure of the assembly file and its use of macros more or less intact, because MPW has the same basic macros as gcc. With 2 I can set it up so that I have a CodeWarrior project that "just works", compiling the same code as the gcc / retro68 version of my project. But the cost is converting a bunch of nice gcc-assembly macros into a ridiculous tangled web of recursive #define statements! Maybe there's a way I can use the C precompiler more elegantly for what I'm doing.
 

joevt

Well-known member
You could make your own preprocessor if the C preprocessor is not sufficient.

Decide what language you want to use for the preprocessor (e.g. bash or zsh shell or python or perl)

Decide on a delimiter that separates normal text from preprocessor commands. The C preprocessor uses # but that only works on a per line basis.

Then you have a command to do the preprocessing which basically entails converting the file into a script containing a series of commands:
the preprocessor commands that are not normal text, and printf ... for the normal text. The script gets executed to produce the preprocessed output. You can include conditionals, loops, variables, etc.

This example is from a Forth file. My Forth tokenizer doesn't have much of a preprocessor so I made one. The preprocessor uses MPW commands. I used « and » for the preprocessor delimiters because they are characters that probably are not used in normal source files.

Code:
tokenizer[
«If {addOS9Driver}»	20000
«Else»				10000
«End» ]tokenizer rom-size

fcode-version2
hex

«     If {cardType} == Radeon7000»
" "(0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 47BF 0000 0210 0809 0000 0000 0000 0000)" \ "......................................Gø.............."
«Else If {cardType} == Radeon8500»
" "(0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 CDDF 5B00 0210 4C51 0000 0000 0000 0000)" \ "......................................Õfl[...LQ........"
«Else If {cardType} == Radeon9000»
" "(0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 C5DF 5B10 0210 6649 0000 0000 0000 0000)" \ "......................................≈fl[...fI........"
«Else If {cardType} == Radeon9200»
" "(0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 C5DF 5B00 1002 1061 5900 0000 0000 0000)" \ "......................................≈fl[....aY......."
«End»

2drop

«If {exportAll}»
	external
«Else»
	headerless
«End»

Using a macro with this type of preprocessor is a little different than using a C preprocessor macro. You have to delimite the invocation of the macro not just the definition of the macro.

The makefile has a dependency to create a Forth file from this source file using the preprocessor.

The command that does the preprocessing can be used in the source file to include other source files. You might have different source files depending on what compiler you want to use.[/icode]
 

bribri

Active member
I thought about writing my own preprocessor too. The dream though is to have a project that can easily be compiled with both CodeWarrior and gcc, and I don't think CodeWarrior has an easy facility built into it for doing your own preprocessing -- I think it would require writing a plug-in. Plus now I would need two versions of the preprocessor, one for modern macOS and one for classic Mac OS. So the approach of having a script that converts the assembly into something MPW compatible (or perhaps CodeWarrior compatible) may be a better approach.

Something I may look into: gcc has an option to output the results of the C preprocessor without performing compilation. I wonder if it can do the same for its assembler's preprocessor? If so, that gives me a file that should be easy to convert to CodeWarrior-compatible assembly.
 
Top