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 > ROL'in a byte onto itself
2016-03-01 17:04
mhindsbo
Account closed

Registered: Dec 2014
Posts: 50
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-01 17:27
ChristopherJam

Registered: Aug 2004
Posts: 1378
Should be able to replace the first version with this?
    lda pattern
    asl a
    rol pattern
    bcs take_action
2016-03-01 17:39
mhindsbo
Account closed

Registered: Dec 2014
Posts: 50
indeed ... now why did I miss that ;-)
2016-03-01 18:47
Oswald

Registered: Apr 2002
Posts: 5017
my 2 cents:

cmp #$80 will put highest bit into carry aswell. useful if you dont want to destroy a.
2016-03-01 18:56
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: my 2 cents:

cmp #$80 will put highest bit into carry aswell. useful if you dont want to destroy a.


Was just about to write it!!
2016-03-01 19:21
Hoogo

Registered: Jun 2002
Posts: 102
asl pattern
bcc no_action
inc pattern
2016-03-01 19:47
Peiselulli

Registered: Oct 2006
Posts: 81
asl
adc #$00
2016-03-01 23:16
ChristopherJam

Registered: Aug 2004
Posts: 1378
Hoogo wins \O/
2016-03-02 01:49
ChristopherJam

Registered: Aug 2004
Posts: 1378
I do like that (with a change of how the state is encoded) Groepaz' solution gives you arbitrary length sequences (as long as there are no more than 128 ones and no more than 128 zeros).

The table is contiguous, too—a fact that eluded me before I realised you could use a run of numbers ending with 127 for the zero states, and from 128 up for the ones (eg. use 128,125,126,129,127 to represent the sequence 10010)
2016-03-02 07:00
Oswald

Registered: Apr 2002
Posts: 5017
Quote: I do like that (with a change of how the state is encoded) Groepaz' solution gives you arbitrary length sequences (as long as there are no more than 128 ones and no more than 128 zeros).

The table is contiguous, too—a fact that eluded me before I realised you could use a run of numbers ending with 127 for the zero states, and from 128 up for the ones (eg. use 128,125,126,129,127 to represent the sequence 10010)


dont think groepaz has put so much thought into it :)
2016-03-02 08:02
ChristopherJam

Registered: Aug 2004
Posts: 1378
Quoting Oswald
dont think groepaz has put so much thought into it :)


I probably should have said groepaz' code, (with mhindsbo's BMI appended), rather than his solution ;-)
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
chriz74
andym00
sebalozlepsi
MCM/ONSLAUGHT
Jason Page/MSL
Sentinel/Excess/TREX
Alakran_64
Apollyon/ALD
Guests online: 162
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (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.05 sec.