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: 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
2010-03-04 10:04
Radiant

Registered: Sep 2004
Posts: 639
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.
2010-03-04 10:10
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.
2010-03-04 10:26
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.

2010-03-04 11:17
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.)
2010-03-04 13:24
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
2010-03-04 13:36
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)
2010-03-04 14:39
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...
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: 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 :)
2010-03-05 20:49
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...
 
... 1 post hidden. Click here to view all posts....
 
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
Fred/Channel 4
algorithm
JEZ
rambo/Therapy/ Resou..
kbs/Pht/Lxt
Impetigo/Crescent
Krill/Plush
𝘁𝗡𝗚/FairLight
Guests online: 261
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.1)

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