Color Cycler Assembly

Started by hetoan2, February 13, 2011, 08:27:21 PM

Previous topic - Next topic

hetoan2

First Read this:
http://130.113.54.154/~monger/hsl-rgb.html

it's a little confusing but whatever. ._.

Anyways the purpose of making this is so that I can try and Make a color cycler. Normally, this would require sin or cosine, but since i'm not going the LUT route on this, I decided that an HSL to RGB converter where the degrees of hue change would be more appropriate, since you eliminate the need for sine or cosine completely.

I'm having some problems though, and i'm not entirely sure why. Its not with the formula, I know it works, it's just my iffy assembly isn't producing the results I'd like. Specifically it's outputting 000007FF as the color always, It's an ugly shade of blue. Unfortunately, I worked without leaving myself many notes to follow and I now find myself worked in a corner. :(

Hopefully some of the fine hackers here can help me debug this ugly mess.

heres the assembly:


# RAM Simul                           RR GG BB AA
# 00000000 04000000 08000000 0C000000 10 11 12 13 14000000 18000000
# 00000000 00000000 00000000 00000000 00 00 00 00 00000000 00000000
# shadef   lightf   speedinc huetemp  colorfin    alpha?   coltemp
#
# Fix Value Simul
# 00000000 04000000 08000000 0C000000 10000000 14000000 18000000 1C000000
# 00000000 3F000000 40000000 3EAAAAAB 3F2AAAAB 40C00000 3F800000 437F0000
# 0        .5       2        1/3      2/3      6        1        255

.set rambaseh,0x8000
.set rambasel,0x0000
.set fixvalh,0x8000
.set fixvall,0x0000

.set fixreg,17
.set basereg,14
.set tempf,21

.set colorf,20
.set colorreg,15
.set alpha,16
.set shadef,30  #this is saturation (don't let shade confuse you)
.set huef,27
.set rate,26
.set lightf,31
.set temp2,28
.set temp1,29
.set tempf2,25

.set temp3R,18
.set temp3G,19
.set temp3B,20

stackframe:
stwu r1,-124(r1) #allocate room for r14-r31
stmw r14,8(r1) #load r14-r31 into stackframe
stmw f20,88(r1) #load f20-f31 into stackframe

lis fixreg,fixvalh
ori fixreg,fixreg,fixvall
lis basereg,rambaseh
ori basereg,basereg,rambasel
lfs lightf,4(basereg)
lfs shadef,0(basereg)
lwz alpha,0x14(basereg)

lfs tempf,0(fixreg)
fcmpu cr0,shadef,tempf
bne skiplightforce
#colors in this area forced to grayscale
fctiw colorf,lightf #float convert to integer word
stfs colorf,0x18(basereg)
lwz colorreg,0x18(basereg)
stb colorreg,0x10(basereg)
stb colorreg,0x11(basereg)
stb colorreg,0x12(basereg)
stb alpha,0x13(basereg)

skiplightforce:
lfs tempf,4(fixreg)
fcmpu cr0,lightf,tempf
blt dark
fmuls temp2,lightf,shadef
fadds shadef,lightf,shadef #shade no longer important, so overwritten
fsubs temp2,shadef,temp2 #L+S-(L*S)
b settemp1

dark:
lfs temp2,0x18(fixreg)
fadds temp2,temp2,shadef
fmuls temp2,temp2,lightf

settemp1:
lfs tempf,8(fixreg) #load 2
fmuls temp1,tempf,lightf
fsubs temp1,temp1,temp2

#begin hue calculations

lfs huef,0x0C(basereg)
lfs rate,8(basereg)
lfs shadef,0x18(fixreg) #shadef used as second temp floatreg
fcmpu cr0,tempf,shadef
fadds tempf,huef,rate
ble storehue

lfs tempf,0(fixreg) #resets to 0, values can only be 0-1

storehue:
stfs tempf,0x0C(basereg) #necessary for cycle

#start RR
lfs tempf,0x0C(fixreg)
fadds temp3R,huef,tempf
lfs tempf,0(fixreg)
fcmpu cr0,tempf,temp3R
blt add1RR
lfs tempf,0x18(fixreg)
fcmpu cr0,tempf,temp3R
bgt sub1RR
b skipfixRR

add1RR:
lfs tempf,0x18(fixreg)
fadds temp3R,temp3R,tempf
b skipfixRR

sub1RR:
fsubs temp3R,temp3R,tempf

skipfixRR:

#start GG
lfs tempf,0(fixreg)
fcmpu cr0,tempf,temp3G
blt add1GG
lfs tempf,0x18(fixreg)
fcmpu cr0,tempf,temp3G
bgt sub1GG
b skipfixGG

add1GG:
lfs tempf,0x18(fixreg)
fadds temp3G,temp3G,tempf
b skipfixGG

sub1GG:
fsubs temp3G,temp3G,tempf

skipfixGG:

#start BB
lfs tempf,0x0C(fixreg)
fsubs temp3B,huef,tempf
lfs tempf,0(fixreg)
fcmpu cr0,tempf,temp3B
blt add1BB
lfs tempf,0x18(fixreg)
fcmpu cr0,tempf,temp3B
bgt sub1BB
b skipfixBB

add1BB:
lfs tempf,0x18(fixreg)
fadds temp3B,temp3B,tempf
b skipfixBB

sub1BB:
fsubs temp3B,temp3B,tempf

skipfixBB:

#start corrections
#
#
#temp3R fix

lfs tempf,0x14(fixreg)
fmuls tempf,tempf,temp3R
lfs shadef,0x18(fixreg)
fcmpu cr0,tempf,shadef
bge retryR1
fsubs tempf2,temp2,temp1
fmuls tempf2,tempf2,tempf
fadds temp3R,tempf2,temp1
b goodRR

retryR1:
lfs tempf,0x08(fixreg)
fmuls tempf,tempf,temp3R
lfs shadef,0x18(fixreg)
fcmpu cr0,tempf,shadef
bge retryR2
fmr temp3R,temp2
b goodRR

retryR2:
lfs tempf,0x14(fixreg)
lfs tempf2,0x08(fixreg)
fdivs tempf,tempf,tempf2
fmuls tempf,tempf,temp3R
lfs shadef,0x08(fixreg)
fcmpu cr0,tempf,shadef
bge retryR3

lfs tempf,0x10(fixreg)
fsubs temp3R,tempf,temp3R
fsubs tempf,temp2,temp1
fmuls tempf,tempf,temp3R
lfs shadef,0x14(fixreg)
fmuls tempf,shadef,tempf
fadds temp3R,temp1,tempf

b goodRR

retryR3:
fmr temp3R,temp1

goodRR:
lfs tempf,0x1C(fixreg)
fmuls temp3R,tempf,temp3R
fctiw temp3R,temp3R
stfs temp3R,0x18(basereg)
lwz tempf,0x18(basereg)
stb tempf,0x10(basereg)

#red determined & stored
#
#
#temp3G fix

lfs tempf,0x14(fixreg)
fmuls tempf,tempf,temp3G
lfs shadef,0x18(fixreg)
fcmpu cr0,tempf,shadef
bge retryG1
fsubs tempf2,temp2,temp1
fmuls tempf2,tempf2,tempf
fadds temp3G,tempf2,temp1
b goodGG

retryG1:
lfs tempf,0x08(fixreg)
fmuls tempf,tempf,temp3G
lfs shadef,0x18(fixreg)
fcmpu cr0,tempf,shadef
bge retryG2
fmr temp3G,temp2
b goodGG

retryG2:
lfs tempf,0x14(fixreg)
lfs tempf2,0x08(fixreg)
fdivs tempf,tempf,tempf2
fmuls tempf,tempf,temp3G
lfs shadef,0x08(fixreg)
fcmpu cr0,tempf,shadef
bge retryG3

lfs tempf,0x10(fixreg)
fsubs temp3G,tempf,temp3G
fsubs tempf,temp2,temp1
fmuls tempf,tempf,temp3G
lfs shadef,0x14(fixreg)
fmuls tempf,shadef,tempf
fadds temp3G,temp1,tempf

b goodGG

retryG3:
fmr temp3G,temp1

goodGG:
lfs tempf,0x1C(fixreg)
fmuls temp3G,tempf,temp3G
fctiw temp3G,temp3G
stfs temp3G,0x18(basereg)
lwz tempf,0x18(basereg)
stb tempf,0x11(basereg)

#green determined & stored
#
#
#temp3B fix

lfs tempf,0x14(fixreg)
fmuls tempf,tempf,temp3B
lfs shadef,0x18(fixreg)
fcmpu cr0,tempf,shadef
bge retryB1
fsubs tempf2,temp2,temp1
fmuls tempf2,tempf2,tempf
fadds temp3B,tempf2,temp1
b goodBB

retryB1:
lfs tempf,0x08(fixreg)
fmuls tempf,tempf,temp3B
lfs shadef,0x18(fixreg)
fcmpu cr0,tempf,shadef
bge retryB2
fmr temp3B,temp2
b goodBB

retryB2:
lfs tempf,0x14(fixreg)
lfs tempf2,0x08(fixreg)
fdivs tempf,tempf,tempf2
fmuls tempf,tempf,temp3B
lfs shadef,0x08(fixreg)
fcmpu cr0,tempf,shadef
bge retryB3

lfs tempf,0x10(fixreg)
fsubs temp3B,tempf,temp3B
fsubs tempf,temp2,temp1
fmuls tempf,tempf,temp3B
lfs shadef,0x14(fixreg)
fmuls tempf,shadef,tempf
fadds temp3B,temp1,tempf

b goodBB

retryB3:
fmr temp3B,temp1

goodBB:
lfs tempf,0x1C(fixreg)
fmuls temp3B,tempf,temp3B
fctiw temp3B,temp3B
stfs temp3B,0x18(basereg)
lwz tempf,0x18(basereg)
stb tempf,0x12(basereg)

#blue determined & stored
#store alpha value

stb alpha,0x13(basereg)


popstackframe:
lmw r14,8(r1) #read registers r14 to r31 from stack
lmw f20,88(r1) #read registers f20 to f31 from stack
addi r1,r1,124 #free stackframe




in addition to that I have some necessary RAM writes (because I'm also lazy):

this would be an example with 8150000 as the fixvalue area

055000A0 3F800000 //store dynamic variables (lighting, saturation, increase increment, and alpha value)
055000A4 3F000000
055000A8 3E000000
055000B4 000000FF


80000007 815000B0
8A00047F XXXXXXXX //move to address of interest from memory
07500000 00000020 //start fixvalue stuff (shouldn't need changing)
00000000 3F000000
40000000 3EAAAAAB
3F2AAAAB 40C00000
3F800000 437F0000
E0000000 80008000


hopefully you guys can help ._.


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

hetoan2

bump only minutes after posting because someone posted on another topic about 4 seconds after i posted this :\


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

Bully@Wiiplaza

is it somehow related to your hacking challenge?
I read that you also participate on it, lol.
Anyway, I also think that you won´t get good help... this thing is too crazy
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

hetoan2

its not THAT challenging. besides, I think some people here could do it.


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

megazig

Awwww, how come i don't hear about this fun stuff on irc

hetoan2

:S i like to bitch on IRC lol ._.



Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

hetoan2

bump :\ i really want to figure this out pl0x

i know i'm a noob :S


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

toonlink444

YOU!!!! a NOOB!!!! Get real I'm a noob not you.
In the begining there was nothing. Then it exploded
New blog!! Check it out for hacking Smash Bros Brawl!! http://letshackblank.blogspot.com/

hetoan2

i meant for bumping my topic, however, i will do this again as i post this D:


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

Y.S.

I'm not sure if this has something to do with the problem, but these two instructions are invalid.
stmw f20,88(r1)
lmw f20,88(r1)


Unlike general purpose registers(GPR's), float registers need to be stored/loaded one by one.
[spoiler]stfs f20,88(r1)
stfs f21,92(r1)
stfs f22,96(r1)
stfs f23,100(r1)
stfs f24,104(r1)
stfs f25,108(r1)
stfs f26,112(r1)
stfs f27,116(r1)
stfs f28,120(r1)
stfs f29,124(r1)
stfs f30,128(r1)
stfs f31,132(r1)


lfs f20,88(r1)
lfs f21,92(r1)
lfs f22,96(r1)
lfs f23,100(r1)
lfs f24,104(r1)
lfs f25,108(r1)
lfs f26,112(r1)
lfs f27,116(r1)
lfs f28,120(r1)
lfs f29,124(r1)
lfs f30,128(r1)
lfs f31,132(r1)[/spoiler]

hetoan2

I was completely unaware. I just assumed that because it didn't freeze that it worked :S

I'll retest and let you know.


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2

Y.S.

#11
Quotefctiw temp3B,temp3B
stfs temp3B,0x18(basereg)
lwz tempf,0x18(basereg)

You need to use stfd instruction instead of stfs when you store an integer value in an FPR.
i.e.
fctiw temp3B,temp3B
stfd temp3B,0x18(basereg)
lwz tempf,0x1C(basereg)


Edit:

I made a similar code. :)

http://www.youtube.com/watch?v=dJ_spSWihSs
[spoiler]/*-------------------------------------------------------------------------------*/
/*int --> float conversion using red zone
freg2 holds the constant 0x4330000080000000
*/

.macro fcfid freg1,freg2,reg1

stfd \freg2,-8(r1)
xoris \reg1,\reg1,0x8000
stw \reg1,-4(r1)
lfd \freg1,-8(r1)
fsub \freg1,\freg1,\freg2

.endm

/*-------------------------------------------------------------------------------*/
/*PUSH and POP*/

.macro  stmfd from, to, offset,reg
  stfd   \from,\offset(\reg)
  .if     \to-\from
  stmfd    "(\from+1)",\to, \offset+8,\reg
  .endif
.endm

.macro  lmfd from, to, offset,reg
  lfd   \from,\offset(\reg)
  .if     \to-\from
  lmfd    "(\from+1)",\to, \offset+8,\reg
  .endif
.endm

/*-------------------------------------------------------------------------------*/
/*Variables for stackframe*/

.set numGPRs,(31-12+1)
.set numFPRs,(_saveFPRs_end - _saveFPRs_start)/4
.set spaceToSave,((4 + ((4*numGPRs + 7)& ~7) + 8*numFPRs ) +7) & ~7
.set offsetforFPR,8 + ((4*numGPRs + 7) & ~7)

/*-------------------------------------------------------------------------------*/
/**/

.set PARAM_RATE,4
.set maxcolor,5
.set mincolor,6

.set H,7
.set S,8
.set L,9

.set RED,10
.set GREEN,11
.set BLUE,12

.set tmp1,13
.set tmp2,14

.set temp1,15
.set temp2,16
.set temp3,17

.set color,18

   .set CONST_FPR,19

.set CONST_0.0,      CONST_FPR+0
.set CONST_0.5,      CONST_FPR+1
.set CONST_1.0,      CONST_FPR+2
.set CONST_2.0,      CONST_FPR+3
.set CONST_one_3rd,   CONST_FPR+4
.set CONST_two_3rds,   CONST_FPR+5
.set CONST_3.0   ,   CONST_FPR+6
.set CONST_4.0,      CONST_FPR+7
.set CONST_6.0,      CONST_FPR+8
.set CONST_60.0,   CONST_FPR+9
.set CONST_255.0,   CONST_FPR+10
.set CONST_360.0,   CONST_FPR+11
.set CONST_MAGIC,   CONST_FPR+12

#GPRs
.set temp,11
.set anchor,12
.set red,14
.set green,15
.set blue,16
.set maxcolor_index,17
.set datap,18
.set savedLR,19

#indexes
.set color_index_RED,0
.set color_index_GREEN,1
.set color_index_BLUE,2

.set address,0x813454A0

/*-------------------------------------------------------------------------------*/

_stackframe:
stwu r1,-spaceToSave(r1)      #allocate room for r14-r31
stmw r12,8(r1)         #load r14-r31 into stackframe

_saveFPRs_start:
stmfd 4,31,offsetforFPR,1
_saveFPRs_end:

mflr   savedLR


bl   _const_data_end

_const_data:
.float   0.0
.float   0.5
.float   1.0
.float   2.0
.float   3.0
.float   0.33333333
.float   0.66666666
.float   4.0
.float   6.0
.float   60.0
.float   255.0
.float   360.0
.double   4503601774854144
.float   0.125
.long   address
_const_data_end:




mflr   anchor

lfs   CONST_0.0,0(anchor)
lfs   CONST_0.5,4(anchor)
lfs   CONST_1.0,8(anchor)
lfs   CONST_2.0,12(anchor)
lfs   CONST_3.0,16(anchor)
lfs   CONST_one_3rd,20(anchor)
lfs   CONST_two_3rds,24(anchor)
lfs   CONST_4.0,28(anchor)
lfs   CONST_6.0,32(anchor)
lfs   CONST_60.0,36(anchor)
lfs   CONST_255.0,40(anchor)
lfs   CONST_360.0,44(anchor)
lfd   CONST_MAGIC,48(anchor)
lfs   PARAM_RATE,56(anchor)
lwz   datap,60(anchor)


lbz   red,0(datap)
fcfid   RED,CONST_MAGIC,red
fdiv   RED,RED,CONST_255.0

lbz   green,1(datap)
fcfid   GREEN,CONST_MAGIC,green
fdiv   GREEN,GREEN,CONST_255.0

lbz   blue,2(datap)
fcfid   BLUE,CONST_MAGIC,blue
fdiv   BLUE,BLUE,CONST_255.0

/*-------------------------------------------------------------------------------*/

#RGB - HSL

#Convert the RBG values to the range 0-1

/*
Example: from the video colors page, colorbar red has R=83%, B=7%, G=7%, or in this scale, R=.83, B=.07, G=.07
Find min and max values of R, B, G
In the example, maxcolor = .83, mincolor=.07
*/


fmr   maxcolor,RED
fmr   mincolor,RED
li   maxcolor_index,color_index_RED

fcmpu   cr0,maxcolor,GREEN
bgt-   0f
fmr   maxcolor,GREEN
li   maxcolor_index,color_index_GREEN
0:

fcmpu   cr0,maxcolor,BLUE
bgt-   0f
fmr   maxcolor,BLUE
li   maxcolor_index,color_index_BLUE
0:

fcmpu   cr0,mincolor,GREEN
blt-   0f
fmr   mincolor,GREEN
0:

fcmpu   cr0,mincolor,BLUE
blt-   0f
fmr   mincolor,BLUE
0:


/*
L = (maxcolor + mincolor)/2
tmp1 = (maxcolor + mincolor)

*/

fadd   tmp1,maxcolor,mincolor
fdiv   L,tmp1,CONST_2.0

#For the example, L = (.83+.07)/2 = .45

/*
If the max and min colors are the same (ie the color is some kind of grey), S is defined to be 0, and H is undefined but in programs usually written as 0
*/

fcmpu   cr0,maxcolor,mincolor
bne-   0f
fmr   S,CONST_0.0
fmr   H,CONST_0.0
0:

/*
Otherwise, test L.
If L < 0.5, S=(maxcolor-mincolor)/(maxcolor+mincolor)
If L >=0.5, S=(maxcolor-mincolor)/(2.0-maxcolor-mincolor)

tmp1 = (maxcolor - mincolor)
tmp2 = (maxcolor + mincolor) or tmp2 = (2.0 - (maxcolor + mincolor))
*/

fsub   tmp1,maxcolor,mincolor
fadd   tmp2,maxcolor,mincolor

fcmpu   cr0,L,CONST_0.5
blt-   0f
fsub   tmp2,CONST_2.0,tmp2
0:
fdiv   S,tmp1,tmp2


#For the example, L=0.45 so S=(.83-.07)/(.83+.07) = .84

/*
If R=maxcolor, H = (G-B)/(maxcolor-mincolor)
If G=maxcolor, H = 2.0 + (B-R)/(maxcolor-mincolor)
If B=maxcolor, H = 4.0 + (R-G)/(maxcolor-mincolor)

tmp1 = (maxcolor-mincolor)
tmp2 = (X-Y) or (X-Y)/(maxcolor-mincolor)
*/

cmpwi   maxcolor_index,color_index_RED
bne-   0f
fsub   tmp2,GREEN,BLUE
fdiv   H,tmp2,tmp1
b   1f
0:

cmpwi   maxcolor_index,color_index_GREEN
bne-   0f
fsub   tmp2,BLUE,RED
fdiv   tmp2,tmp2,tmp1
fadd   H,CONST_2.0,tmp2
b   1f
0:

_maxcolor_is_BLUE:
fsub   tmp2,RED,GREEN
fdiv   tmp2,tmp2,tmp1
fadd   H,CONST_4.0,tmp2

1:


/*
For the example, R=maxcolor so H = (.07-.07)/(.83-.07) = 0
To use the scaling shown in the video color page, convert L and S back to percentages, and H into an angle in degrees (ie scale it from 0-360). From the computation in step 6, H will range from 0-6. RGB space is a cube, and HSL space is a double hexacone, where L is the principal diagonal of the RGB cube. Thus corners of the RGB cube; red, yellow, green, cyan, blue, and magenta, become the vertices of the HSL hexagon. Then the value 0-6 for H tells you which section of the hexgon you are in. H is most commonly given as in degrees, so to convert
H = H*60.0
If H is negative, add 360 to complete the conversion.
*/

fmul   H,H,CONST_60.0
fcmpu   cr0,H,CONST_0.0
bge-   0f
fadd   H,H,CONST_360.0
0:

/*-------------------------------------------------------------------------------*/
fadd   H,H,PARAM_RATE
fcmpu   cr0,H,CONST_360.0
ble-   0f
fsub   H,H,CONST_360.0
0:

/*-------------------------------------------------------------------------------*/
#HSL - RGB
/*
If S=0, define R, G, and B all to L

*/

fcmpu   cr0,S,CONST_0.0
bne-   0f

fmr   RED,L
fmul   RED,color,CONST_255.0
fctiw   RED,RED
stfd   RED,-8(r1)
lwz   red,-4(r1)
stb   red,0(datap)
stb   red,1(datap)
stb   red,2(datap)
b   _return
0:

/*
Otherwise, test L.
If L < 0.5, temp2=L*(1.0+S)
If L >= 0.5, temp2=L+S - L*S

tmp1 = (1.0+S)
tmp1 = (L+S)
tmp2 = (L*S)
*/

fcmpu   cr0,L,CONST_0.5
bge-   0f
fadd   tmp1,S,CONST_1.0
fmul   temp2,L,tmp1
b   1f
0:

fadd   tmp1,L,S
fmul   tmp2,L,S
fsub   temp2,tmp1,tmp2

1:

/*
In the colorbar example for colorbar green, H=120, L=52, S=79, so converting to the range 0-1, L=.52, so
temp2=(.52+.79) - (.52*.79) = .899
*/

/*
temp1 = 2.0*L - temp2
In the example, temp1 = 2.0*.52 - .899 = .141
*/

fmul   tmp1,CONST_2.0,L
fsub   temp1,tmp1,temp2

/*
Convert H to the range 0-1
In the example, H=120/360 = .33
For each of R, G, B, compute another temporary value, temp3, as follows:
*/

fdiv   H,H,CONST_360.0

/*
for R, temp3=H+1.0/3.0
for G, temp3=H
for B, temp3=H-1.0/3.0
*/

fadd   temp3,H,CONST_one_3rd
bl   _calculate_color
fmul   RED,color,CONST_255.0
fctiw   RED,RED
stfd   RED,-8(r1)
lwz   red,-4(r1)
stb   red,0(datap)

fmr   temp3,H
bl   _calculate_color
fmul   GREEN,color,CONST_255.0
fctiw   GREEN,GREEN
stfd   GREEN,-8(r1)
lwz   green,-4(r1)
stb   green,1(datap)

fsub   temp3,H,CONST_one_3rd
bl   _calculate_color
fmul   BLUE,color,CONST_255.0
fctiw   BLUE,BLUE
stfd   BLUE,-8(r1)
lwz   blue,-4(r1)
stb   blue,2(datap)

b   _return

/*-----------------------------------------------------------------------------------------------------------*/


/*
if temp3 < 0, temp3 = temp3 + 1.0
if temp3 > 1, temp3 = temp3 - 1.0
In the example, Rtemp3=.33+.33 = .66, Gtemp3=.33, Btemp3=.33-.33=0
*/

_calculate_color:

fcmpu   cr0,temp3,CONST_0.0
bge-   0f
fadd   temp3,temp3,CONST_1.0
0:

fcmpu   cr0,temp3,CONST_1.0
ble-   0f
fsub   temp3,temp3,CONST_1.0
0:

/*
For each of R, G, B, do the following test:

If 6.0*temp3 < 1, color=temp1+(temp2-temp1)*6.0*temp3
tmp1 = 6.0*temp3
tmp1 = (temp2-temp1)
tmp1 = (temp2-temp1)*6.0
tmp1 = (temp2-temp1)*6.0*temp3

*/

fmul   tmp1,temp3,CONST_6.0
fcmpu   cr0,tmp1,CONST_1.0
bge-   0f
fsub   tmp1,temp2,temp1
fmul   tmp1,tmp1,CONST_6.0
fmul   tmp1,tmp1,temp3
fadd   color,temp1,tmp1
blr
0:

/*
Else if 2.0*temp3 < 1, color=temp2
*/

fmul   tmp1,temp3,CONST_2.0
fcmpu   cr0,tmp1,CONST_1.0
bge-   0f
fmr   color,temp2
blr
0:

/*
Else if 3.0*temp3 < 2, color=temp1+(temp2-temp1)*((2.0/3.0)-temp3)*6.0
tmp1 = (temp2-temp1)
tmp2 = (2.0/3.0)-temp3
tmp1 = (temp2-temp1) * (2.0/3.0)-temp3
tmp1 = (temp2-temp1) * ((2.0/3.0)-temp3) * 6.0
color = (temp2-temp1) * ((2.0/3.0)-temp3) * 6.0 +temp1
*/

fmul   tmp1,temp3,CONST_3.0
fcmpu   cr0,tmp1,CONST_2.0
bge-   0f
fsub   tmp1,temp2,temp1
fsub   tmp2,CONST_two_3rds,temp3
fmul   tmp1,tmp1,tmp2
fmul   tmp1,tmp1,CONST_6.0
fadd   color,tmp1,temp1
blr
0:

/*
Else color=temp1
*/

fmr   color,temp1


blr

/*
In the example,
3.0*Rtemp3 < 2 so R=.141+(.899-.141)*((2.0/3.0-.66)*6.0=.141
2.0*Gtemp3 < 1 so G=.899
6.0*Btemp3 < 1 so B=.141+(.899-.141)*6.0*0=.141
Scale back to the range 0-100 to use the scaling shown in the video color page
For the example, R=14, G=90, B=14
*/

/*-----------------------------------------------------------------------------------------------------------*/

_return:

mtlr   savedLR
lmw   r12,8(r1)
lmfd   4,31,offsetforFPR,1
addi   r1,r1,spaceToSave


/*-----------------------------------------------------------------------------------------------------------*/
[/spoiler]

dcx2

Absolutely epic.  You made your own function!  I'm beginning to think I should make a sticky post that just links to all of your examples.  There is so much to learn.

I have two questions

1) The "red zone".  Negative stack frame index?  Is there a place where this behavior is defined?

2) What are the 0: and 0f branch labels?  I can infer their purpose - to avoid coming up with unnecessary branch labels - but is there any more meaning to them?  Is there one for branches backward?

Y.S.

The red zone is a memory area that can be used in a leaf function. The size of the area is 0xE0 bytes.
I often use this area for a temporary storage.

http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/LowLevelABI/100-32-bit_PowerPC_Function_Calling_Conventions/32bitPowerPC.html

A label that has a single number as its name is a local label. You can use the same labels name over and over.
I use these labels because I don't think it's appropriate to always give labels specific names.

"b 0f" jumps to the label 0 that appears after the branch, and "b 0b" jumps to the label 0 that appears before the branch.

http://sourceware.org/binutils/docs-2.18/as/Symbol-Names.html#Symbol-Names

hetoan2

#14
gah Y.S. why are you so smart ._.

also you should get a github. Would be nice to see what crazy stuff you're working on. i know i would have liked to see your progress on what I had failed at doing D:


Check out my site with codes obviously...
http://hetoan2.com/

and youtube...
http://youtube.com/hetoan2