English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 26 November 2016, 01:08   #1
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,539
The proper way of disabling a sprite? (Using DisplayLibrary)

This is probably fairly obvious but I haven't discovered the proper way to handle it.

If you draw a sprite with the DisplaySprite command, eg

Code:
DisplaySprite CopList#,Sprite#,X,Y,Sprite Channel
Then the sprite remains static until you move it or draw a different sprite on that sprite channel.

But say if you no longer want to use that sprite channel at all? How do you simply turn it off? What I've been doing is simply moving the X value outside of the screen but surely that's not the right way to do it?
earok is offline  
Old 26 November 2016, 18:08   #2
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
To just remove it from the display, you can create a small transparent sprite and display that instead. To turn off the actual sprite display however is called "disarming" the sprite. I've never actually done it, but it seems writing 0 to the sprite control registers (SPR0CTL to SPR7CTL) disarms the sprites and disables their DMA, stopping their display and freeing that DMA slot up for other uses. Apparently this should only be done during a vertical blank however or you'll be left with vertical bars on your screen where the sprite used to be.

More info in the RKRMs here, and I'm sure plenty of people have more experience than I do with sprites - I've only ever done basic stuff with them.

Edit: SPR7CTL is the top register, not SPR8CTL...

Last edited by Daedalus; 27 November 2016 at 17:57.
Daedalus is offline  
Old 26 November 2016, 21:33   #3
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by Daedalus View Post
Apparently this should only be done during a vertical blank however or you'll be left with vertical bars on your screen where the sprite used to be.
That's because the SPRxDAT register is loaded with new sprite data each time a new horizontal line is reached. If you switch off a sprite whilst the SPRxDAT register still has non-zero data in it then you get the horizontal bars. Simply set SPRxDAT to 0 (where x represents the sprite number - 0 to 7) and you should avoid this problem

It should be ok to write directly to SPRxDAT as some games manually load sprite registers with data to create backgrounds - usually done using the copperlist.
Lonewolf10 is offline  
Old 27 November 2016, 08:09   #4
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,539
Cheers guys
earok is offline  
Old 04 June 2018, 23:55   #5
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,213
Code:
;; Disable sprite channel
;; SPRxPOS = 0, move it away
Poke.w $dff140 + (channel * 8), 0
;; SPRxCTL = 0, disable the channel
Poke.w $dff142 + (channel * 8), 0
This works. Obviously not optimised - probably a switch/case on channel would be faster than two multiplications, but it works well enough for what I'm doing.
E-Penguin is offline  
Old 05 June 2018, 09:12   #6
MickGyver
Registered User
 
MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 643
Quote:
Originally Posted by E-Penguin View Post
Code:
;; Disable sprite channel
;; SPRxPOS = 0, move it away
Poke.w $dff140 + (channel * 8), 0
;; SPRxCTL = 0, disable the channel
Poke.w $dff142 + (channel * 8), 0
This works. Obviously not optimised - probably a switch/case on channel would be faster than two multiplications, but it works well enough for what I'm doing.
You could also do a logical left shift instead of multiplication: channel LSL 3. A shift of three bits left is the same as multiplying times eight. Bitwise operations are very usable and often faster. Have somebody tested the speed difference of multiplication/division and LSL/LSR in BB2?

https://en.wikipedia.org/wiki/Logical_shift
MickGyver is offline  
Old 05 June 2018, 10:36   #7
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,213
Yes, good point. I don't know about BB2 but the MULU instruction on 68000 is pretty slow. https://wiki.neogeodev.org/index.php...ctions_timings

I think switch/case wrapped up in a macro is probably the fastest way, using constants rather than calculating anything.
E-Penguin is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling / hiding partitions Turran support.Hardware 30 15 July 2015 20:58
Disabling Pop-up on EAB stefcep project.EAB 5 07 May 2009 00:11
Disabling the Apollo A630 frost242 support.Hardware 3 21 February 2009 13:57
WarpEngine disabling 68040 alanh support.Hardware 4 11 October 2008 22:19
Disabling Cyberstorm MK I THX1138 support.Hardware 7 04 May 2006 09:57

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:05.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13608 seconds with 15 queries