Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
CSDb User Forums


Forums > C64 Coding > ROL'in a byte onto itself
2016-03-01 18:04
mhindsbo

Registered: Dec 2014
Posts: 27
ROL'in a byte onto itself

What is the fastest and/or shortest code for rolling a pattern through a byte? I use it to trigger an action following a certain pattern. I came up with (18 cycles worst case / 12 bytes):
          clc
          lda pattern
          bpl no_carry
          sec
no_carry  rol pattern
          bcs take_action 

if your pattern ends on a 1 (bit 0 = 1) then you could also do (17 cycles worst case / 13 bytes)
          lda pattern
          bne @cont
          lda #%00110101   ; restore pattern
@cont     asl
          sta pattern
          bcs take_action 

any other variations?
 
... 22 posts hidden. Click here to view all posts....
 
2016-03-03 23:12
Digger

Registered: Mar 2005
Posts: 188
What's could be a practical application for that?
2016-03-04 03:29
mhindsbo

Registered: Dec 2014
Posts: 27
I use it for an alternating fire pattern. This piece of code sits in the fire function and decides if it fires or not when called
2016-03-06 01:36
Copyfault

Registered: Dec 2001
Posts: 169
Quoting Hoogo
asl pattern
bcc no_action
inc pattern


Wow, that's true art!

Thanks for being (or better getting) active again, Frank ;)
2016-03-06 10:51
Style

Registered: Jun 2004
Posts: 468
Quote: Quoting Hoogo
asl pattern
bcc no_action
inc pattern


Wow, that's true art!

Thanks for being (or better getting) active again, Frank ;)


Id use

ASL mem
ADC #0
2016-03-07 20:17
Hoogo

Registered: Jun 2002
Posts: 76
Quoting Style
ASL mem
ADC #0
It's easier, faster and shorter, but does not work :) Where's the Accu coming from, and where does it go?
2016-03-07 21:04
Groepaz

Registered: Dec 2001
Posts: 7561
Quote:
It's easier, faster and shorter, but does not work

AEG would love it *g*
2016-03-09 00:29
Style

Registered: Jun 2004
Posts: 468
Quote: Quoting Style
ASL mem
ADC #0
It's easier, faster and shorter, but does not work :) Where's the Accu coming from, and where does it go?


Oh was that a prerequisite? :)


LDA groep
ASL
ADC #0
STA groep


There ;)

(wanders off to find copy of "coding drunk for beginners")
2016-03-09 14:41
mhindsbo

Registered: Dec 2014
Posts: 27
Yes the requirement was code that works (checking chapter 1 in "coding drunk for beginners" ;-) just need to add the branch to take action ;-)

All in all Hoogo's solution is both shortest and fastest. Part of the joy I get from coding on the C64 are finding elegant short, fast and clean solutions, within the constraints of the system, and I really like the aesthetics of this one :-)
2016-03-09 20:08
Perplex

Registered: Feb 2009
Posts: 166
Edit: nevermind.
2016-03-09 20:30
Oswald

Registered: Apr 2002
Posts: 3834
yeah hype it some more, most beautiful 3 lines of code I've ever seen. I mean, really! :)
Previous - 1 | 2 | 3 | 4 - 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
Lubber/Padua
Frantic/Hack'n'Trade
Didi/Laxity
Guests online: 21
Top Demos
1 Uncensored  (9.7)
2 Coma Light 13  (9.7)
3 Edge of Disgrace  (9.7)
4 Comaland  (9.6)
5 Comaland 100%  (9.6)
6 Wonderland XII  (9.5)
7 Fantasmolytic  (9.5)
8 Rocketry  (9.5)
9 We Are Demo  (9.4)
10 +H2K  (9.4)
Top onefile Demos
1 Treu Love [reu]  (9.5)
2 Daah, Those Acid Pil..  (9.4)
3 Dawnfall  (9.3)
4 One-Der  (9.2)
5 Hardware Accelerated..  (9.2)
6 MD201605  (9.1)
7 Safe VSP  (9.1)
8 Black Magic  (9.0)
9 Goatbeard  (9.0)
10 Te-Te-Te-TechTech It..  (9.0)
Top Groups
1 Censor Design  (9.4)
2 Booze Design  (9.4)
3 Crest  (9.4)
4 Oxyron  (9.4)
5 Nostalgia  (9.2)
Top Cover Designers
1 Duce  (9.8)
2 Electric  (9.7)
3 Junkie  (9.7)
4 The Elegance  (9.4)
5 Cuc  (9.2)

Home - Disclaimer
Copyright © No Name 2001-2016
Page generated in: 0.341 sec.