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-04 16:02
Rudi
Account closed

Registered: May 2010
Posts: 125
I dont see how sprites will solve the C2P-problem (with as few cycles as possible)? but then again, Im not too experienced with sprites on the C64. A goal would be to calculate as many chars (per frame) as possible for C2P.
2017-01-04 16:04
chatGPZ

Registered: Dec 2001
Posts: 11148
tlr: wasnt there some VIC that only clears (or retriggers?) the collisions once?
2017-01-04 19:07
tlr

Registered: Sep 2003
Posts: 1727
Quote: tlr: wasnt there some VIC that only clears (or retriggers?) the collisions once?

That was lightpen triggering. It's working very differently on 6569R1.
2017-01-04 19:22
Skate

Registered: Jul 2003
Posts: 491
I just made a rough calculation. Using 16k of precalc data (which is already terrible), each char takes 500-600 cycles to rotate. So, c2p routine looks like the best solution in every aspect. I'm still thinking an alternative approach though.
2017-01-04 19:54
Flavioweb

Registered: Nov 2011
Posts: 447
Quoting Skate
I just made a rough calculation. Using 16k of precalc data (which is already terrible), each char takes 500-600 cycles to rotate.

Just to say (...maybe i'm off-topic...) this code took 544 cicles rotate a char counterclockwise.
    *=$C000
    .FOR S=0, S<8, S=S+1
    LDA SOURCE+S
    .FOR D=0, D<8, D=D+1
    ASL
    ROL DEST+D
    .NEXT
    .NEXT
    RTS
;-------------------
SOURCE
    .BYTE %11111111
    .BYTE %10000000
    .BYTE %01000000
    .BYTE %00100000
    .BYTE %00010000
    .BYTE %00001000
    .BYTE %00000100
    .BYTE %11111111
DEST
    .BYTE %00000000
    .BYTE %00000000
    .BYTE %00000000
    .BYTE %00000000
    .BYTE %00000000
    .BYTE %00000000
    .BYTE %00000000
    .BYTE %00000000
;---------------------------------------
2017-01-04 19:57
Rudi
Account closed

Registered: May 2010
Posts: 125
This takes ~472 cycles, and is basically similar to Oswalds approach:
	;counter-clockwise rotation by 90 degrees.
	
	;column 1
	ror $74
	rol
	ror $75
	rol
	ror $76
	rol
	ror $77
	rol
	ror $78
	rol
	ror $79
	rol
	ror $7a
	rol
	ror $7b
	rol
	sta $7c
	;tot = 59 cycles

	;column 2
	ror $74
	rol
	ror $75
etc..
	ror $7b
	rol
	sta $83
;tot = 59*8 = 472 cycles
did a test in zp. so rotated (destination) bytes are in $7c to $83. this req eight bytes to be copied to zeropage ($74 to $7b) (as an example).
2017-01-04 20:35
Oswald

Registered: Apr 2002
Posts: 5028
axis' one is close to max possible I guess, go for it if understandable version is not enough :)
2017-01-04 20:42
Skate

Registered: Jul 2003
Posts: 491
Table lookup doesn't necessarily be faster than bit shifting. What i was saying is even using large tables to get rid of bit shifting doesn't save cycles unless you start thinking out of the box.
2017-01-04 20:56
Skate

Registered: Jul 2003
Posts: 491
here is an algo which looks similar to c2p method without 8 bit restrictions.

void transpose8(unsigned char A[8], int m, int n, 
                unsigned char B[8]) {
   unsigned x, y, t; 

   // Load the array and pack it into x and y. 

   x = (A[0]<<24)   | (A[m]<<16)   | (A[2*m]<<8) | A[3*m]; 
   y = (A[4*m]<<24) | (A[5*m]<<16) | (A[6*m]<<8) | A[7*m]; 

   t = (x ^ (x >> 7)) & 0x00AA00AA;  x = x ^ t ^ (t << 7); 
   t = (y ^ (y >> 7)) & 0x00AA00AA;  y = y ^ t ^ (t << 7); 

   t = (x ^ (x >>14)) & 0x0000CCCC;  x = x ^ t ^ (t <<14); 
   t = (y ^ (y >>14)) & 0x0000CCCC;  y = y ^ t ^ (t <<14); 

   t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F); 
   y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F); 
   x = t; 

   B[0]=x>>24;    B[n]=x>>16;    B[2*n]=x>>8;  B[3*n]=x; 
   B[4*n]=y>>24;  B[5*n]=y>>16;  B[6*n]=y>>8;  B[7*n]=y; 
}
2017-01-05 07:37
HCL

Registered: Feb 2003
Posts: 717
Ah, that's just beautiful Axis!!

..as usual, i'm the last one to read the thread.. but if anyone still wonders what that code does, it is mirroring the 8x8-matrix by starting with 2x2-bit-blocks, then 4x4-blocks, then finally the whole 8x8-block. Mirroring and rotation is of course just a matter of configuring the macros :).

..and of course Graham did this 15+ years ago, hope that makes you all feel as retard as i do ;).
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 - 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
Viti/Hokuto Force
Wayne/Art Ravers
TBC
aNdy/AL/Cosine
Visage/Lethargy
Edhellon/Resource
wix
sebalozlepsi
kbs/Pht/Lxt
Higgie/Kraze/Slacker..
Flavioweb/🇮🇹HF..
Guests online: 111
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 No Bounds  (9.6)
7 Comaland 100%  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 Layers  (9.6)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Covert Bitops  (9.4)
2 Nostalgia  (9.4)
3 Oxyron  (9.3)
4 Booze Design  (9.3)
5 Crest  (9.3)
Top Original Suppliers
1 Black Beard  (9.7)
2 Derbyshire Ram  (9.5)
3 hedning  (9.2)
4 Baracuda  (9.1)
5 Jazzcat  (8.6)

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