| |
oziphantom
Registered: Oct 2014 Posts: 490 |
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? |
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
dont know, but what is the deal with bmi sub ? with signed numbers you dont need to branch if add or sub ?
also instead of $aa branch on 0 or negative could spare some cycles.
also instead of YXdeltas 2 tables seems better Xdeltas and Y deltas so no inx is needed to reach X or Y.
my 2 cents of criticism. |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
From my point of view you're answering your own question. That is, to use additional indenting in those cases where it actually helps readability. I understand that this conflicts with your idea of being "strict", but why not be strict about function (readability in this case) instead of being strict about form? |
| |
oziphantom
Registered: Oct 2014 Posts: 490 |
the $AA resets the loop, so multiple delta runs are stored in one <256 list, to which the code indexes into say an ent might use the deltas from 34-41 when it hits $AA it goes from index 41 back to 34.
I could split the Y and X into two tables but then I would have to duplicate the $AA in both so the indexes lined up, which would eat more bytes than it would save, so its a RAM/Cycle pay off.
the bmi is to handle the MSB transition, (both do do an ADC ) just how it updates the 9th bit. If you have a nice way to handle 9bit maths inline, do tell. |
| |
Trash
Registered: Jan 2002 Posts: 122 |
I would do this and skip indenting for the different cases:
bmi C ; Why case C
beq B ; Why case B
;------------
; Case A, <explanation>
;------------
A
A
A
bne C ; Why case C
A
A
jmp D ; Why case D
;------------
; Case B, <explanation>
;------------
B
B
B
B
beq D ; Why case D
;------------
; Case C, <explanation>
;------------
C
C
C
C
;------------
; Case D, <explanation>
;------------
D
D
D
|
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
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. |
| |
Dano
Registered: Jul 2004 Posts: 234 |
What Cruzer said. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
not a single label named "shit". unreadable. |
| |
Mr. SID
Registered: Jan 2003 Posts: 424 |
You lost me at the + and - labels... :) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
I still hate all that branching going on, why not just 16 bit math?
bmi case:
+3 cycle bmi -2 cycle at adc # = +1 cycle slower than adc abs,x
bpl case:
not taken branch:2
not taken bcc: 2
inc 5
jmp 4
13 cycles = +1 cycle slower than lda adc sta (Each 4)
only 1 case its faster.
instead of #$aa it could be a dec counter bmi. |
| |
Perplex
Registered: Feb 2009 Posts: 255 |
Quoting CruzerThe 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. |
... 13 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 - Next |