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 > Fast way to rotate a char?
2017-01-04 08:32
Rudi
Account closed

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

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

Example:

a char (and the bits can be random):
10110010 byte 1..
11010110 byte 2.. etc..
00111001
01010110
11011010
10110101
00110011
10110100
after "rotation" (rows and columns are swapped):
11001101
01011000
10100111
11111111
00101000
01010101
11011010
00100110
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?

-Rudi
 
... 105 posts hidden. Click here to view all posts....
 
2017-01-05 23:02
Frantic

Registered: Mar 2003
Posts: 1648
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
Rudi
Account closed

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

Registered: Dec 2001
Posts: 478
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
ChristopherJam

Registered: Aug 2004
Posts: 1409
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 
etc
2017-01-07 11:20
Krill

Registered: Apr 2002
Posts: 2980
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
Rudi
Account closed

Registered: May 2010
Posts: 125
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).
2017-01-07 19:58
Skate

Registered: Jul 2003
Posts: 494
I think Rudi wants to rotate dynamically created chars, not a static charset. Rudi, did i get you right?
2017-01-07 21:06
Frantic

Registered: Mar 2003
Posts: 1648
I think so, yes, as he wrote that "the bits can be random". (But that doesn't exclude the possibility of playing with other types of representations as such.)
2017-01-07 21:10
Rudi
Account closed

Registered: May 2010
Posts: 125
Quote: I think Rudi wants to rotate dynamically created chars, not a static charset. Rudi, did i get you right?

Yes Skate! That is right.
2017-01-08 10:53
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
I may have found a method that takes 432 cycles. An 8x8 rotation can be performed by moving around 4x4 blocks, then 2x2 subblocks and then the bits in each subblock. Now you can identify for each resulting destination bit pair (that is, bist 7+6, or 5+4, ..., or 1+0) the nybbles of the source bytes it came from. So an approach could be to take two source bytes, merge the desired nybbles into one byte, and then use look up tables to transform it to the desired bit pairs (at the right location, i.e., a bit pair 7+6 from the merged source nybbles could be transformed to a destination bit pair 3+2, for example).

ldx first_source_byte
lda second_source_byte
and #mask   ;mask=f0 if you need the high nybble and 0f for the low nybble
ora byte2DesiredNybble,x  ;look up table to merge the right nybble in the right way
tax
lda first_destination
ora bits76toRightPosition,x  ; Table filters out the desired bits and puts them in the right order at the right position.
sta first_destination
lda second_destination
ora bits54toRightPosition,x
sta second_destination
...
lda fourth_destination
ora bits10toRightPosition,x
sta fourth_destination
-----------------------+
54 cycles (source and destination bytes in ZP).


This fills in 4 times 2 bits, so you have to do that 8 times to fill the entire destination matrix. So that is 432 cycles in total. But you need a bunch of look-up tables, so it is not very memory efficient.

I hope I did not overlook something ...
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
Advanced
Users Online
Inge/HVSC
Acidchild/Padua
LHS/Padua
Mike
psych
Guests online: 81
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 Layers  (9.6)
2 No Listen  (9.6)
3 Party Elk 2  (9.6)
4 Cubic Dream  (9.6)
5 Copper Booze  (9.6)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (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 Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

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