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 > Updating sprite X msb
2016-03-26 15:50
ChristopherJam

Registered: Aug 2004
Posts: 1409
Updating sprite X msb

Slack bastard time. Recs for updating $d010 if I've got an eight bit x-position in my object table, but all my sprites are offset a constant number of pixels to the right? Current draft is this:
	clc
	lda mobX,x
	adc xoffset
	sta $d000,y
	lda #0
	adc #255
	eor #255
	eor $d010
	and hibit,x
	eor $d010
	sta $d010

(x is both object ID and sprite number (I'll change how I index mobX later), y is double the sprite number. hibit contains 2**i)
2016-03-26 16:43
ChristopherJam

Registered: Aug 2004
Posts: 1409
..and now
	clc
	lda mobX,x
	adc xofse
	sta $d000,y
	lda $d010
	ora hibit,x
	bcs *+5
	eor hibit,x
	sta $d010
2016-03-26 16:45
BiGFooT

Registered: Mar 2002
Posts: 33
not tested, lazy solution below:

clc
lda mobx,x
adc xoffset
sta $d000,y
bcs set ; hibit doesn't count at overflow

lda hibit,y
beq clear

set
lda $d010
ora table,y
bne done

clear
lda table,y
eor #$ff
and $d010

done
sta $d010


table .byte 128,128,64,64,32,32,16,16,8,8,4,4,2,2,1,1
2016-03-26 17:26
ChristopherJam

Registered: Aug 2004
Posts: 1409
Good idea indexing hibit with y instead of x.

I'm not going to need to bash the sprite colours for present purposes, possibly not even sprite definition, so I may be able to avoid placing sprite number in a register altogether.

The rest looks sound, and looks like it sits between my OP and my reply to myself in speed..
2016-03-26 18:31
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
When you update all sprites in one loop, you may update $d010 as follows
ldx #$07
loop:
ldy table,x  ;y contains 2 times x
clc
lda mobX,x
adc xofse
sta $d000,y
rol $d010   ;shift in a 0 or 1
dex
bpl loop
2016-03-26 18:43
The Human Code Machine

Registered: Sep 2005
Posts: 112
It's faster to unroll the code:

lda mobX
clc
adc xoffset
sta $d000
ror xhi
lda mobX+1
clc
adc xoffset
sta $d002
ror xhi

and so on

lda xhi
sta $d010
2016-03-26 18:49
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
Quoting The Human Code Machine
It's faster to unroll the code:

lda mobX
clc
adc xoffset
sta $d000
ror xhi
lda mobX+1
clc
adc xoffset
sta $d002
ror xhi

and so on

lda xhi
sta $d010


Nice! Yes, and you can use zeropage for xhi :-)
2016-03-26 18:55
The Human Code Machine

Registered: Sep 2005
Posts: 112
Yes, but it's only one cycle faster.
2016-03-26 20:25
ChristopherJam

Registered: Aug 2004
Posts: 1409
Quoting Color Bar
When you update all sprites in one loop, you may update $d010 as follows..


Ah yes, I should probably have mentioned that my use case is a multiplexer component; for the first eight sprites I will indeed shift the bits in one by one.
2016-03-27 07:46
Hoogo

Registered: Jun 2002
Posts: 105
I wonder if that multiplexer reuses the sprites in order, so that for every call y will increased by 2 and start with 0 again? Not sure if that can make a difference, just thinking...
I guess offset is variable and not available when mobX is generated?
And are you already in need of rastertime, or is it just about making this a little more pretty?
	clc
	lda mobX,x
	adc xoffset
	sta $d000,y
	lda $d010
	bcc clear
	ora hibit,y
	bcs store
clear	and hibit+1,y
store	sta $d010
hibit	!by 1, 255-1, 2, 255-2, 4, 255-4...
2016-03-27 08:26
Hein

Registered: Apr 2004
Posts: 954
8 pieces of code to jump to, all other stuff is done outside multiplexer. Y holds the current list index.

    lax (sprite_index_lo),y
    lda sprite_y,x
    sta $d001
    lda sprite_x,x
    sta $d000
    lda sprite_a,x
    sta screen+$3f8
    cmp sprite_x_msb,x	;$00 if cleared, $ff if set
    lda $d010
    and #%11111110
    bcs +
    ora #%00000001
+   sta $d010
    lda sprite_c,x
    sta $d027
 
... 4 posts 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
Alakran_64
Didi/Laxity
Tomse/RCEU
Mythus/Delysid
Guests online: 112
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 Triad  (9.3)
5 Censor Design  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

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