Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Tool for indentation of 6502/6510 code
2010-03-04 09:48
Frantic

Registered: Mar 2003
Posts: 1627
Tool for indentation of 6502/6510 code

Hello!

I was thinking about smashing together a small perl script or something like that for automatic indentation of 6502/6510 asm code. I was thinking about having parameters such as tabsize to use (default 4 spaces), number of tabs to use (default 2 or 3 or so), and optional conversion of tab characters to spaces instead. That would be useful for me (and perhaps others) for pre-preparation of code to be put up at codebase64, since tabs are translated to something like 6 spaces or so, and people often mix tab chars and spaces, which produces quite messy results when posting the code on codebase.

But... Before doing this, I though I should just check if someone already wrote such a tool. No need to reinvent the...

//FTC
 
... 1 post hidden. Click here to view all posts....
 
2010-03-04 10:10
Frantic

Registered: Mar 2003
Posts: 1627
I was mainly considering something relatively simple for the standard cases, in order to save some work regarding codebase stuff, but you are of course right that one would ultimately like to be able to handle more complex indentation. However, I guess that would require some sort of templates and stuff like that, since getting into that kind of detail would probably require some knowledge of the specific assembler syntax involved (such as some assemblers treat stuff (which is not comments) that begin on the first line as labels whereas some others allow labels to begin elsewhere, which requires other ways of distinguishing code tokens from label tokens etc (btw: does ca65 require all labels to end with a ":" character?).

If one would go into that sort of detail, perhaps it would be nice to expand the aims of the tool to also include the possibility to make conversions between various assembler syntaxes, such as adding colons to labels automatically, renaming "asl a" to "asl" or vice versa, ".byte" to "!byte" or vice versa and so on. I mean, if "knowledge" about various assembler syntaxes would be taken into account anyway...

My primary aim was something more along the lines of standard "turbo assembler" formatting.
2010-03-04 10:26
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: What indentation standard are you considering? I often do stuff like
ldy #$20
:   ldx $1000,y
    :   lda $2000,x
        sta $3000,x
        inx
    bpl :-
    dey
bne :--
to keep the sources easier to follow.


same here!

Ca65 doesn't require the labels to end with a colon, but that's the default behaviour.

It can mimic the behaviour of f.e. treating all non-opcodes at column 0 as labels, even without the ending colon.

2010-03-04 11:17
Frantic

Registered: Mar 2003
Posts: 1627
Yeah, I sometimes use such indentation too. However, when I think a bit more about it, I am not sure how automatic identification of correct indentation in such cases would actually be possible. I mean, in just a slightly more complex example it becomes less obvious how to treat the indentation. I mean.. Something like the following should be quite ambiguous, right? One could not take for granted that any branch instruction should produce a decrease of the indentation, right? (i.e. it is not comparable to matching braces in c code or so).

ldy #$20
:	ldx $1000,	
	:	lda $2000,	
		sta $3000,x
		inx
		bpl :-	
		lda xxxx
		cmp xxxx
		bcc :--
		inx
	bpl :-
	dey
bne :--


One could of course assume that indentation was somewhat correct in the first place, and should be preserved to some degree, but on the other hand that is a bit conflicting with the overall aim of re-indenting the code in the first place. :)

EDIT: Well.. one could also assume that the last reference back to a :-label is the "closing brace", but that would require looking ahead in the file, which is not how my script currently works (it works line by line)... (Yes, I already coded a bit on such a script yesterday.)
2010-03-04 13:24
enthusi

Registered: May 2004
Posts: 675
well, not all posters will use ca65 :)
I prefer something simple + stupid such as:
    ldx #$00
source
    lda $8000,x
target
    sta $6000,x
    dex
changer
    bne source
2010-03-04 13:36
chatGPZ

Registered: Dec 2001
Posts: 11114
i agree with enthusi ... especially for simply example code (which shouldnt use weirdo constructs like those above in the first place)
2010-03-04 14:39
Frantic

Registered: Mar 2003
Posts: 1627
Yes, I agree also. This is also what I intend to do first (if nobody else did it), as I said.

So... Nobody did such a tool? There is no other tools which would easily be extended, or so? I looked around a little, but found nothing obvious, but I may have missed some possibilities out there...
2010-03-05 07:53
Devia

Registered: Oct 2004
Posts: 401
Good ol' GNU Indent? Maybe it'll bring you half way fast, dunno ;-)
2010-03-05 08:04
enthusi

Registered: May 2004
Posts: 675
Just a personal side note (aka blabla):
as far as I can see, codebase64 aint exactly a beginner's first steps guide (luckyly).
And learning to read code is an essential part of coding.
I'd even prefer to keep each posters identation as is, just as the code style differs alot between people, as in setting a vector via ldx,ldy or lda,lda or whatever.
Rather than changing what is there already, there might be some guide line for new entries that people are free to follow or not?
Yay for that :)
2010-03-05 20:49
Frantic

Registered: Mar 2003
Posts: 1627
@enthusi: I agree with you and I am not planning to use this to homogenize all the stuff on Codebase. However, sometimes someone posts something which is clearly fucked up, and sometimes someone hesitates to add something when they discover that what they are trying to post looks fucked up when previewing their messages (mixing spaces and tabs etc), and sometimes people ask me to add stuff for them (6 tabs before the code line might look nice on some ultra wide screen or something, but not on codebase :)... It is only with these uses in mind that I was planning to code this (and for my own personal use, for example to use it in TextMate). I wasn't even thinking of adding this as a function to codebase itself. It was just related...
2010-03-06 09:47
Frantic

Registered: Mar 2003
Posts: 1627
Okay.. I wrote a relatively simple script for code indentation now. Among other things, it can be used with tools such as petcom (by Craig Bruce) to convert turbo assembler sources to indented ascii sources for use with cross assemblers or for display on codebase. I wrote some info on source conversion on the following Codebase page, and you'll find the indentation script there too if you want it:

http://codebase64.org/doku.php?id=source_conversion

Please take care when using the indentation script (do not overwrite your original source files) since I cannot guarantee that it doesn't fuck your sources up, slightly, or in worst case even a whole lot. :)

Please also give me bug reports...
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
DeMOSic/HF^MS^BCC^LSD
Brittle/Dentifrice^(?)
Krill/Plush
Hagar/The Supply Team
Meikel aka ZUX/Sparks
A3/AFL
Guests online: 154
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 S!R  (9.9)
3 Antitrack  (9.8)
4 Mr Zero Page  (9.8)
5 OTD  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.054 sec.