| |
Frantic
Registered: Mar 2003 Posts: 1648 |
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.... |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
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. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
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.
|
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
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.) |
| |
enthusi
Registered: May 2004 Posts: 677 |
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
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
i agree with enthusi ... especially for simply example code (which shouldnt use weirdo constructs like those above in the first place) |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
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... |
| |
Devia
Registered: Oct 2004 Posts: 401 |
Good ol' GNU Indent? Maybe it'll bring you half way fast, dunno ;-)
|
| |
enthusi
Registered: May 2004 Posts: 677 |
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 :) |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
@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... |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
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 |