Block comment in ca65

Building your first 6502-based project? We'll help you get started here.
Post Reply
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Block comment in ca65

Post by jeffythedragonslayer »

How do I quickly comment out a large block of code in ca65?
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Block comment in ca65

Post by BigEd »

Maybe

Code: Select all

.if 0
...
.endif
or

Code: Select all

.ifblank
...
.endif
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Re: Block comment in ca65

Post by jeffythedragonslayer »

Thanks that helps, but it doesn't quite do what I want. The assemble still fails if the blanked-out block has syntax errors in it. In C-like languages sometimes I like to comment out a large block of code that I'm having trouble getting to compile and slowly move the /* down to uncomment a little bit of it at a time so I'm not overwhelmed with the amount of code I have to get compiling all at once. Is there no way to do that with ca65?
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Block comment in ca65

Post by BigEd »

It might be that a macro in your editor will help in bulk-commenting and un-commenting. (It might be that there is an easy way, but I don't know it.)
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Block comment in ca65

Post by GARTHWILSON »

As Ed suggests, a macro that just has the IF 0 and another other with ENDIF (ca65's terminology might be slightly different) is a way that works with most assemblers, but you'll have to be careful that none of the commented-out lines have something that it's trying to use to figure out if there's an ENDIF or an ELSE that it's supposed to pay attention to. Commenting-out code might be more of a problem than commenting-out a paragraph of prose description. I called my macros COMMENT and END_COMMENT. Here's an example usage:

Code: Select all

 COMMENT
    Don't use N-1 like other systems. It's not necessary with 816 & it'll put
    you in XSAVE.  You DEX twice before writing the first stack cell; so S0adr
    isn't used by stack.  X holds the actual ZP address of the top stack cell.
    Top of both stacks is the stack cell closest to address 0.  Altho' the '816
    can have the direct page anywhere in bank 0, it runs fastest if we leave the
    direct page on a page boundary, so we might as well leave it at ZP just like
    w/ 6502.
 END_COMMENT

In the few cases where a line starts with something that could confuse the assembler, I just change where one or more lines start and end; so for example the word else is not the first word on a line.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: Block comment in ca65

Post by BillG »

jeffythedragonslayer wrote:
Thanks that helps, but it doesn't quite do what I want. The assemble still fails if the blanked-out block has syntax errors in it. In C-like languages sometimes I like to comment out a large block of code that I'm having trouble getting to compile and slowly move the /* down to uncomment a little bit of it at a time so I'm not overwhelmed with the amount of code I have to get compiling all at once. Is there no way to do that with ca65?
Does ca65 support preprocessor directives?

#if or #ifdef handling does not parse intervening code but just looks for lines beginning with '#'.
sanny
Posts: 6
Joined: 01 Sep 2017

Re: Block comment in ca65

Post by sanny »

Just run the source file through the C preprocessor (cpp) before handling it to ca65.

Edit: current gcc preprocessor creates info lines starting with a '#'. Use "cc65 -E" to do the preprocessing.
User avatar
Sheep64
In Memoriam
Posts: 311
Joined: 11 Aug 2020
Location: A magnetic field

Re: Block comment in ca65

Post by Sheep64 »

gcc -E | grep -v '^#' should work. Unfortunately, error messages will give screwy file names and line numbers because that meta-data is now stripped out.
tmr4
Posts: 147
Joined: 19 Feb 2022

Re: Block comment in ca65

Post by tmr4 »

You want to use the c_comments option of the .FEATURE directive. That allows C type /* */ comments. It appears there are some limitations. Here's the note from the manual:
Quote:
c_comments: Allow C like comments using /* and */ as left and right comment terminators. Note that C comments may not be nested. There's also a pitfall when using C like comments: All statements must be terminated by "end-of-line". Using C like comments, it is possible to hide the newline, which results in error messages. See the following non working example:

lda #$00 /* This comment hides the newline
*/ sta $82
For the OP use, I think just putting the /* and */ on separate lines would be sufficient.

The problem with using the .if directive for this is noted in the manual as well:
Quote:
4.7 Conditional assembly
Please note that when using the conditional directives (.IF and friends), the input must consist of valid assembler tokens, even in .IF branches that are not assembled. The reason for this behaviour is that the assembler must still be able to detect the ending tokens (like .ENDIF), so conversion of the input stream into tokens still takes place. As a consequence conditional assembly directives may not be used to prevent normal text (used as a comment or similar) from being assembled.
jeffythedragonslayer
Posts: 114
Joined: 03 Oct 2021

Re: Block comment in ca65

Post by jeffythedragonslayer »

Excellent; thanks tmr4,

Code: Select all

.feature c_comments
does exactly what I want!
Post Reply