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 > Code indenting
2017-09-11 07:40
oziphantom

Registered: Oct 2014
Posts: 478
Code indenting

I've always been a strict
label code comment
kinda guy but of late I've been experimenting with code readability and speed boosts. Indenting does seem to improve things
updateMovement
	ldx Ents.movementPtr
-	lda YXDeltas,x
	cmp #$AA
	bne +
	ldx Ents.movementPtrBase
	stx Ents.movementPtr
	jmp -
+	clc
	adc Ents.y
	sta Ents.y
	inx	
	lda YXDeltas,x
	beq _endAdd
	bmi _sub
	clc
	adc Ents.x
	sta Ents.x
	bcc _endAdd
	inc Ents.xMSB
	jmp _endAdd
_sub
	clc
	adc Ents.x
	sta Ents.x
	lda Ents.xMSB
	adc #$ff
	sta Ents.xMSB
_endAdd
	inx
	stx Ents.movementPtr
	rts
vs
updateMovement
	ldx Ents.movementPtr
-	lda YXDeltas,x
	cmp #$AA
	bne +
	    ldx Ents.movementPtrBase
	    stx Ents.movementPtr
	jmp -
+	clc
	adc Ents.y
	sta Ents.y
	inx	
	lda YXDeltas,x
	beq _endAdd
	    bmi _sub
                clc
                adc Ents.x
                sta Ents.x
                bcc _endAdd
                    inc Ents.xMSB
                    jmp _endAdd
       _sub
            clc
            adc Ents.x
            sta Ents.x
            lda Ents.xMSB
            adc #$ff
            sta Ents.xMSB
_endAdd
	inx
	stx Ents.movementPtr
	rts
this kind of falls apart when you get the to the leap frog code. I.e something like
bmi C
beq B
A
A
A
bne C
A
A
jmp D
B
B
B
B
beq D
C
C
C
C
D
D
D
So I was wondering if anybody else had tumbled down this rabbit hole or had other things to do to help?
 
... 13 posts hidden. Click here to view all posts....
 
2017-09-12 00:17
Skate

Registered: Jul 2003
Posts: 490
C64 has no tab key for a reason. :)
2017-09-12 00:51
chatGPZ

Registered: Dec 2001
Posts: 11108
and TASS already auto-idents the way god intended!
2017-09-12 07:32
oziphantom

Registered: Oct 2014
Posts: 478
Quoting Perplex
Quoting Cruzer
The only time it makes sense to indent asm code is if it's in curly brackets, e.g. because of an if-statement or for-loop.


This.


Python, Ruby et al ?
2017-09-12 07:44
oziphantom

Registered: Oct 2014
Posts: 478
Quoting Skate
C64 has no tab key for a reason. :)


And the C128 does for a reason ;) The Kernal even has Tab Stops build in.
2017-09-15 19:37
Skate

Registered: Jul 2003
Posts: 490
Quote: Quoting Skate
C64 has no tab key for a reason. :)


And the C128 does for a reason ;) The Kernal even has Tab Stops build in.


We are free to use indenting for our C128 projects then, good to know.

I have a C128 but it will take a few more decades until i need that much memory and speed. ;)
2017-09-15 20:00
Compyx

Registered: Jan 2005
Posts: 631
Quoting Cruzer
Looks retarded to me. I would just add some newlines to split the code into logical blocks. The only time it makes sense to indent asm code is if it's in curly brackets, e.g. because of an if-statement or for-loop.


I agree with the retarded bit. But even using brackets doesn't make sense, asm doesn't have block-level scope. And if there are assemblers that support that, those are retarded.
2017-09-16 05:19
Hypnosis

Registered: Mar 2015
Posts: 36
I also indent my code in loops, if-end and if-else-end cases. I indent as well as I can in other cases but fail when it gets too hairy. My assembler has some syntactic sugar to help this structuring by using curly braces. They limit the lifetime of local variables but also add automatic loop and continue labels, so you can write a loop like this.

	ldx #0
	{
		lda string,x
		beq @continue

		jsr CHROUT
		inx
		bne @loop
	}
2017-09-16 20:03
Digger

Registered: Mar 2005
Posts: 421
I am also doing indenting for loops and shit, like Cruzer said.

What's interesting however is logically grouping vars and pointers like:
Ents.movementPtrBase
Ents.movementPtr
Ents.xMSB
...

etc.

How does this work in principle?
2017-09-17 06:15
oziphantom

Registered: Oct 2014
Posts: 478
using tass and do
Ents .block
    movementPtrBase .byte ?
    movementPtr .byte ?
    xMSB .byte ?
.bend

or make a struct with it use dstruct to instance multiple copies where you want it.

Then you access it with Ents.movementPtr.
If this is a Hi/Lo word you can do
HLWord .union
 .word ?
 .struct
 	lo .byte ?
 	hi .byte ?
 .ends
.endu
then make one as
movementPtr .dunion HLWord
if you do it inside the Ents block/struct you would then have
Ents.MovementPtr and
Ents.MovementPtr.lo and
Ents.MovementPtr.hi
2017-09-19 15:39
White Flame

Registered: Sep 2002
Posts: 136
I tend to add just a single space at a time. I find it a lot more readable than the full tab-style examples above, since asm tends to be very column-aligned.

For loops, I indent the body including the first instruction, and de-indent the branch instruction:
  ldx #$7f
:  lda init,x
   sta dest,x
   dex
  bpl :-


For if/then/else/etc branching, I just try to keep conditional areas indented, but when it goes all spaghetti that's just a guideline.
Previous - 1 | 2 | 3 - 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
HBH.ZTH/Abnormal
MADMAX
eryngi
Guests online: 103
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 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (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 Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

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