tunaisafish
2nd Jan 2006, 07:16 PM
In the process of writing my first mod, I found that both DisaSim and the PJSE plugin were not intepreting what parameters were being passed correctly in some cases.
This is the result of my research that followed.
It's pure reverse engineering of what actually happens now with various data thrown at a BHAV. So you probably won't find all examples in Maxis code, but in your own code it may help track down some unexpected behaviour. 1 mis-typed bit could make all the difference.
Thanks to Dizzy2 and P.Jones for their source files that got me started.
I used a private function to pop-up a dialog to compile these parameters.
Not tested whether global or semi BHAVs are different, but assume (hope) they are. I experimented with formats 8007 and 8009, and with the flags = 6, but no differences were seen.
Below is obviously not PHP, but I couldn't find the pre tags, and code looked too spaced.
Passing Parameters from BHAV to BHAV
(Applicable to TS2 + EP1 + EP2)
P_in = How many params declared in this BHAV
P_out = How many params declared in called BHAV
NV = Node Version (0 or 1)
b[n] = Operand bytes (0 to 15)
Kill = true when b[0..7] == 0xffffffffffffffff
X = b[12]
X0 = bit0
X1 = bit1
X72 = true when (X & 0xFC) == 0xFC
Truth Table for P_out > 0
NV X72 X1 X0 Kill P_out Method
0 ? ? 1 0 <9 4OI
0 ? ? 1 0 >8 NAR
0 ? ? 1 1 ? NAR
0 ? ? 0 0 ? 8C0
0 ? ? 0 1 ? UNK
1 1 1 1 0 ? 8C1
1 1 1 1 1 ? UNK
1 0 1 1 0 <9 4OI
1 0 1 1 0 >8 NAR
1 0 1 1 1 ? NAR
1 ? 0 1 0 <9 4OI
1 ? 0 1 0 >8 NAR
1 ? 0 1 1 ? NAR
1 ? 1 0 0 <9 PAR
1 ? 1 0 0 >8 NAR
1 ? 1 0 1 ? NAR
1 ? 0 0 0 ? 8C1
1 ? 0 0 1 ? UNK
>1 ? ? ? ? ? not tested
Method Key
NAR - no args
PRM - Use Parameters
8C0 - 8 Constants 0
8C1 - 8 Constants 1
4OI - 4 Owner Indices
UNK - Unknown
What Is Passed
Up to 8 shorts can be passed by all methods.
If P_out > 8, then pad the params over the 8th with unknown shorts.
NAR - no args
passes up to 8 shorts of 0x0
PRM - Use Parameters
Up to 8 shorts as currently defined in Params[0 .. (P_in - 1)]
Pad remaining up to 8th with 0x0
8C0 - 8 Constants 0
Set b[12] to 0
Up to 8 shorts read in LE order from b[0..15]
8C1 - 8 Constants 1
Up to 8 shorts read in LE order from b[0..15]
4OV - 4 Owner Indices
Up to 4 shorts defined in b[0..11] (owner1,low1,high1,...)
followed by 4 shorts of 0x0.
UNK - Unknown
Up to 8 (seemingly random but repeatable) shorts.
Related notes:
Parameters are passed by value.
ie. The called BHAV can change the params without changing the callee params.
If you want to pass by reference, use Temps.
I've only seen one BHAV, an entry point, that declares more that 8 params.
I've not searched for others.
# Group = 0x7FD0DEBA, Instance = 0x2009
# Title = Function - Portal - Test - SG
# Format = 8009, Params = 10, Locals = 0
This BHAV is also called from a Myne door BHAV with no args!
Edit: I've now searched for others.
BHAVs with more than 8 params from EP2 objects.package
Group/Instance/Params/Title
7F0C60C8 2002 9 Portal
7F117CD9 2005 9 Function - Portal
7F429113 1001 9 Function - Portal
7F429113 1002 9 Function - Portal - TEST
7F585FFD 1006 9 Function - Portal
7F585FFD 1007 9 Function - Portal - TEST
7F5BA5F7 1005 9 Function - Portal - TEST
7F5BA5F7 1006 9 Function - Portal
7FD0DEBA 1009 10 Function - Portal - Test - SG
7F739728 100F 13 CT - Handle Grow Up Feedback
7F739728 1142 14 CT - Handle Feedback - Verify All
7F739728 1003 15 CT - Handle Feedback
7F739728 11A7 15 CT - Handle Feedback - Lifetime Want
This is the result of my research that followed.
It's pure reverse engineering of what actually happens now with various data thrown at a BHAV. So you probably won't find all examples in Maxis code, but in your own code it may help track down some unexpected behaviour. 1 mis-typed bit could make all the difference.
Thanks to Dizzy2 and P.Jones for their source files that got me started.
I used a private function to pop-up a dialog to compile these parameters.
Not tested whether global or semi BHAVs are different, but assume (hope) they are. I experimented with formats 8007 and 8009, and with the flags = 6, but no differences were seen.
Below is obviously not PHP, but I couldn't find the pre tags, and code looked too spaced.
Passing Parameters from BHAV to BHAV
(Applicable to TS2 + EP1 + EP2)
P_in = How many params declared in this BHAV
P_out = How many params declared in called BHAV
NV = Node Version (0 or 1)
b[n] = Operand bytes (0 to 15)
Kill = true when b[0..7] == 0xffffffffffffffff
X = b[12]
X0 = bit0
X1 = bit1
X72 = true when (X & 0xFC) == 0xFC
Truth Table for P_out > 0
NV X72 X1 X0 Kill P_out Method
0 ? ? 1 0 <9 4OI
0 ? ? 1 0 >8 NAR
0 ? ? 1 1 ? NAR
0 ? ? 0 0 ? 8C0
0 ? ? 0 1 ? UNK
1 1 1 1 0 ? 8C1
1 1 1 1 1 ? UNK
1 0 1 1 0 <9 4OI
1 0 1 1 0 >8 NAR
1 0 1 1 1 ? NAR
1 ? 0 1 0 <9 4OI
1 ? 0 1 0 >8 NAR
1 ? 0 1 1 ? NAR
1 ? 1 0 0 <9 PAR
1 ? 1 0 0 >8 NAR
1 ? 1 0 1 ? NAR
1 ? 0 0 0 ? 8C1
1 ? 0 0 1 ? UNK
>1 ? ? ? ? ? not tested
Method Key
NAR - no args
PRM - Use Parameters
8C0 - 8 Constants 0
8C1 - 8 Constants 1
4OI - 4 Owner Indices
UNK - Unknown
What Is Passed
Up to 8 shorts can be passed by all methods.
If P_out > 8, then pad the params over the 8th with unknown shorts.
NAR - no args
passes up to 8 shorts of 0x0
PRM - Use Parameters
Up to 8 shorts as currently defined in Params[0 .. (P_in - 1)]
Pad remaining up to 8th with 0x0
8C0 - 8 Constants 0
Set b[12] to 0
Up to 8 shorts read in LE order from b[0..15]
8C1 - 8 Constants 1
Up to 8 shorts read in LE order from b[0..15]
4OV - 4 Owner Indices
Up to 4 shorts defined in b[0..11] (owner1,low1,high1,...)
followed by 4 shorts of 0x0.
UNK - Unknown
Up to 8 (seemingly random but repeatable) shorts.
Related notes:
Parameters are passed by value.
ie. The called BHAV can change the params without changing the callee params.
If you want to pass by reference, use Temps.
I've only seen one BHAV, an entry point, that declares more that 8 params.
I've not searched for others.
# Group = 0x7FD0DEBA, Instance = 0x2009
# Title = Function - Portal - Test - SG
# Format = 8009, Params = 10, Locals = 0
This BHAV is also called from a Myne door BHAV with no args!
Edit: I've now searched for others.
BHAVs with more than 8 params from EP2 objects.package
Group/Instance/Params/Title
7F0C60C8 2002 9 Portal
7F117CD9 2005 9 Function - Portal
7F429113 1001 9 Function - Portal
7F429113 1002 9 Function - Portal - TEST
7F585FFD 1006 9 Function - Portal
7F585FFD 1007 9 Function - Portal - TEST
7F5BA5F7 1005 9 Function - Portal - TEST
7F5BA5F7 1006 9 Function - Portal
7FD0DEBA 1009 10 Function - Portal - Test - SG
7F739728 100F 13 CT - Handle Grow Up Feedback
7F739728 1142 14 CT - Handle Feedback - Verify All
7F739728 1003 15 CT - Handle Feedback
7F739728 11A7 15 CT - Handle Feedback - Lifetime Want