-
Notifications
You must be signed in to change notification settings - Fork 23
Description
PlatformerMovement/src/state/Player.s
Line 205 in 1ee11f2
| .proc bound_position_y |
I'm fully new to assembly.. and learning mostly from your videos. But when I got to this function in your code.. I did not understand how the function worked and went down a bit of a rabbit hole so I could graps it. I finally learned that the shift was filling the carry... and it what was being used by the rotate. Basically building merging the 2 bytes into a single usable one. I did a small break down to understand it:
; Convert from 12.4 fixed point into screen coordinates
lda positionY ;(3)
sta $00 ;(3)
lda positionY + 1 ;(4)
sta $01 ;(3)
lsr $01 ; abcd efgh - 0abc defg : h (5)
ror $00 ; ABCD EFGH - h:ABC DEFG (5)
lsr $01 ; 00ab cdef : g (5)
ror $00 ; g:hAB CDEF (5)
lsr $01 ; 000a bcde : f (5)
ror $00 ; f:ghA BCDE (5)
lsr $01 ; 0000 abcd : e (5)
ror $00 : e:fgh ABCD - efgh ABDC (5)
lda $00 ; (3) =56
after seeing how the data was being manipulated... I thought of how I felt like it would be a little less obtuse to just mask the bits and put them together. Doesn't use that secret carry flag
lda positionY ;(3)
;and #%11110000 ;(2)
lsr ;(2)
lsr
lsr
lsr
sta $00 ;(3)
lda positionY + 1 ;(4)
;and #%00001111 ;(2)
asl ;(2)
asl
asl
asl
ora $00 ;(3) = 29
I put the cycle cost based on this page in parenthesis.
Anyway.. thank you for your efforts and resources. I actually only really posted this to get your critique. And is it actually more optimal?
edit: playing more with it.. actually dont need the 2 ands either, and save 4 cycles. At the cost of clarity