6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 4:04 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Block comment in ca65
PostPosted: Sat May 21, 2022 8:36 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
How do I quickly comment out a large block of code in ca65?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 8:41 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Maybe
Code:
.if 0
...
.endif
or
Code:
.ifblank
...
.endif


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 8:54 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
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?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 8:57 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
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.)


Top
 Profile  
Reply with quote  
PostPosted: Sat May 21, 2022 9:24 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
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:
 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?


Top
 Profile  
Reply with quote  
PostPosted: Sun May 22, 2022 1:18 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
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 '#'.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 22, 2022 4:52 pm 
Offline

Joined: Fri Sep 01, 2017 6:20 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 01, 2022 4:30 pm 
Offline
User avatar

Joined: Tue Aug 11, 2020 3:45 am
Posts: 311
Location: A magnetic field
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.

_________________
Modules | Processors | Boards | Boxes | Beep, Beep! I'm a sheep!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 01, 2022 6:42 pm 
Offline

Joined: Sat Feb 19, 2022 10:14 pm
Posts: 147
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 01, 2022 9:31 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Excellent; thanks tmr4,
Code:
.feature c_comments
does exactly what I want!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: