Super easy.
Say you've got 8 bit positions, no subpixels. To add some to say... the X coordinate, you do this:
Code:
lda #3;Move 3 pixels to the right.
clc
adc OBJx,x
sta OBJx,x
I know you know this, just leading into it.
But... say 3 pixels is too fast. You want to add 2.5 instead. Just use 16bit math.
Code:
lda #128
clc
adc OBJsubpixelx,x
sta OBJsubpixelx,x
lda #2
adc OBJx,x
sta OBJx,x
OBJx is still the on screen position. Every other frame adding the one set high bit to OBJsubpixelx makes the add to the position add 3 instead of 2 because it will set the carry.
Let's take it further. #128, and #2 could just as easily be your player's current speed.
Code:
lda OBJspeedlow,x
clc
adc OBJsubpixelx,x
sta OBJsubpixelx,x
lda OBJspeedhigh,x
adc OBJx,x
sta OBJx,x
And to accelerate slowly...
Code:
lda OBJspeedlow,x
clc
adc #$01
sta OBJspeedlow,x
lda OBJspeedhigh,x
adc #$00
sta OBJspeedhigh,x
One last note. It's not required to use a full byte for your subpixel positions. Adding to the higher bits of a byte will never change the lower bits. So if you only want 3 bits of sub pixel precision, you can do this:
Code:
lda OBJspeedlow,x
clc
adc #%00100000
sta OBJspeedlow,x
lda OBJspeedhigh,x
adc #$00
sta OBJspeedhigh,x
And the lowest 5 bits in the byte that you're using for something else won't be changed. No need for and/or cookie cutting. You do need to and out the lower bits when you add the speed to position, though. (Only works if the sub pixels bits are the highest bits in the byte)