Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Båtsman ! (Registered 2018-06-21) You are not logged in 
CSDb User Forums

Forums > C64 Coding > Fast way to rotate a char?
2017-01-04 08:32

Registered: May 2010
Posts: 101
Fast way to rotate a char?

Im not talking about rol or ror, but swap bits so that they are rotated 90 degrees:


a char (and the bits can be random):
10110010 byte 1..
11010110 byte 2.. etc..
after "rotation" (rows and columns are swapped):
is it possible to use lookup tables for this or would that lookup table be too big?
or other lookuptable for getting and setting bits?

... 99 posts hidden. Click here to view all posts....
2017-01-05 14:30

Registered: May 2010
Posts: 101
There is some interesting cyclic dynamic going on when looking at a bit-swapping method for 8x8 bits:

these figures shows that the outer layer is rotated 8 times first, then the next layer is rotated 6 times and so forth:
xxxxxxxx    ........    ........    ........
x......x    .xxxxxx.    ........    ........
x......x    .x....x.    ..xxxx..    ........
x......x    .x....x.    ..x..x..    ...xx...
x......x    .x....x.    ..x..x..    ...xx...
x......x    .x....x.    ..xxxx..    ........
x......x    .xxxxxx.    ........    ........
xxxxxxxx    ........    ........    ........
in this example one start with c0r0 and swap that with c7r0, then c1r0->c7r1, c2r0->c7r2 etc. so it goes around like a circle would. when that process is finished, the next inner layer does the same thing. until all four layers are done. and the result is a 90 deg rotation. its just one other way of looking at it. but still, a lookup-table for this? its difficult for me to see how. (im just giving out a few ideas for trying out other approach maybe).
2017-01-05 16:23

Registered: Aug 2004
Posts: 795
Problem with bitshifter is it only deals with one bit at a time.

c2p exchanges four bitpairs in only 20-30 cycles. The expensive part is moving bits to matching positions within the two bytes they're being exchanged between...
2017-01-05 19:58

Registered: Mar 2005
Posts: 276
Nice read. But what fx do you have in mind Rudi?
2017-01-05 21:54

Registered: May 2010
Posts: 101
Quote: Nice read. But what fx do you have in mind Rudi?

My initial thinking was to make a sine-scroller, where the sinus-transform is done in chunky and then transformed using c2p. Of course the c2p-routine has to be fast enough for this. It would also bring out some new ideas for other vertical effects (that are first done with horisontal tricks, and then transformed using c2p). Unfortunately there seem to be no _really_ fast c2p routine.

Im still figuring out how that 4x4, 2x2 plus 1x1 rotator works. or that is; looking at every detail of the bit swaps.

Edit: hires-sinescroller.
2017-01-05 23:02

Registered: Mar 2003
Posts: 1339
It is not really what you specified in your first post, but just a thought that may be worth considering: Would it be okay to represent the original char in some different way? If so, there might (possibly) be ways to represent that char that would make it easier to "rotate" it to +90˚ angle although at the cost that you may then also need to do some operations on the data to be able to "read out" the normal 0˚ angle.

Just thinking aloud here. Trying to rethink the problem rather than the solution, so to speak. Not sure if it would be allowed.
2017-01-05 23:16

Registered: May 2010
Posts: 101
Frantic? Sorry mate, but my first post is what i need. the figures dont lie :)
2017-01-05 23:47

Registered: Dec 2001
Posts: 238
Interesting Thread :)

Sticking to the figures of the initial post the goal is to have a char mirror* routine with a cycle count as low as possbile for 8x8-Chars HiRes with arbitrary bit patterns [*mirror in the sense of mirroring along the diagonal line from bitpos (0,0) to (7,7)].

Maybe it's possible to weaken the requirement of _arbitrary_ bitpatterns... I'm thinking about using a charset with chars $00-$7f for the "given" bitpatterns and $80-$ff for the corresponding "mirrored" patterns. This way, mirroring would only be a question of setting the msb of the corresponding bytes in the screenram.

Guess in order to have a chance to make this approach work you'd need several charsets spread along the screen - and this still requires that appropriate slices of the screen will have at most 128 different bitpatterns.

Another downside: expanding this approach to 90° rotations will lower the number of different bitpatterns even further to 64.

But maybe this thought is of any help; it just came up while reading so I wanted to share it.
2017-01-06 09:32

Registered: Aug 2004
Posts: 795
For things like sine scrollers, there may be value in doing a partial rotation; only takes 240 cycles per char to reshape eight bytes into
; 00224466
; 00224466
; 00224466
; 00224466
; 11335577
; 11335577
; 11335577
; 11335577
(digit is index of source byte)
using something like
  ldx s+0
  ldy s+1     ; 8   cycles priming the xy line cache. Need to do this on row 0 and row 4

  lda t00,x
  ora t01,y   ; 8
  ldx s+4
  ldy s+6     ; 8
  ora t02,x
  ora t03,y   ; 8
  sta dst+0   ; 4      28 cycles for this block; one of these per dest byte

  lda t12,x
  ora t13,y
  ldx s+0
  ldy s+2
  ora t10,x
  ora t11,y
  sta dst+1 
2017-01-07 11:20

Registered: Apr 2002
Posts: 952
Rudi: So you want to rotate chars by arbitrary angles, not just swap X and Y (90°)? What's the problem with Frantic's suggestion of pre-calculating another representation of the original characters to optimise run-time rendering of the rotated characters, thus trading memory for speed?
2017-01-07 15:51

Registered: May 2010
Posts: 101
Krill: No. I ONLY want to swap x and y 90 degrees. No other degrees. Im working on Axis's method with masks and so on.. (bcoz it seems to be the one technique that use fewest cycles).
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 - 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
Users Online
Bieno/Commodore Plus
Guests online: 34
Top Demos
1 Uncensored  (9.7)
2 Comaland 100%  (9.7)
3 Edge of Disgrace  (9.7)
4 Coma Light 13  (9.6)
5 The Shores of Reflec..  (9.6)
6 Wonderland XII  (9.6)
7 We Come in Peace  (9.6)
8 Lunatico  (9.6)
9 Incoherent Nightmare  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Daah, Those Acid Pil..  (9.6)
2 FMX Music Demo  (9.5)
3 Pandemoniac Part 2 o..  (9.5)
4 Dawnfall V1.1  (9.5)
5 Treu Love [reu]  (9.5)
6 Arok 20 Invitation  (9.5)
7 Merry Xmas 2017  (9.4)
8 In Memoriam BHF  (9.4)
9 Dawnfall  (9.4)
10 Synthesis  (9.4)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.4)
5 Crest  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.9)
3 Irata  (9.8)
4 Wotnau  (9.7)
5 MWS  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.053 sec.