Results 1 to 14 of 14

Thread: Deciphering Chrysler 68RFE Code

  1. #1
    Banned
    Join Date
    Jan 2018
    Location
    Everywhere
    Posts
    1,772

    Deciphering Chrysler 68RFE Code

    So I have been putting in some time lately learning code and deciphering bits of the Chrysler code for the 68RFE. And it is no easy task. I'll show a little snip of code here to show what it looks like for those that go through this stuff to build software like the VCM editor, figuring things out and mapping things out so people can have a way to tune their vehicles.

    I may be a bit off on some of this...

    89 6f 85 e7 lbz r11,-0x7a19(r15)
    38 a0 00 00 li r5,0x0
    7d 6b 58 f8 nor r11,r11,r11
    55 6b 06 b5 rlwinm. r11,r11,0x0,0x1a,0x1a
    40 82 00 0c bne LAB_002c5b2c
    88 ae 93 82 lbz r5,-0x6c7e(r14)
    48 00 00 64 b LAB_002c5b8c


    The above snip of code is checking to see if the TCC lockup is commanded and if it is commanded, set the max allowed line pressure for while the TCC in lockup. If TCC lock is not commanded, branch to another set of instructions.

    Lets break this down.

    89 6f 85 e7 lbz r11,-0x7a19(r15)
    This line here is pointing to an address in volatile memory where the TCC lockup status is stored. It takes the byte sized value stored at that location in memory and loads it into register 11 (r11) then zero's out all other bits in that register. A byte is 8 bits while a register is 32 bits. The value that will be stored at the location in the volatile memory can be either 0x20 (TCC lockup not commanded) or it can 0x40 (TCC lockup commanded).

    The end result stored in r11 if TCC lockup is not commanded would look like this: 00000000000000000000000000100000 (0x20)
    The end result stored in r11 if TCC lockup is commanded would look like this: 00000000000000000000000001000000 (0x40)

    38 a0 00 00 li r5,0x0
    Here it is just taking the value of 0x0 and storing it into the r5 register.

    7d 6b 58 f8 nor r11,r11,r11
    This line of code is taking the stored value in r11, complimenting the bits with itself and then inverting all the bits then storing the end result back into r11. Since it is complimenting the bits with itself, we can just look at this as inverting all the bits in the stored value.

    The end result stored in r11 if TCC lockup is not commanded would look like this: 11111111111111111111111111011111 (0xFFFFFFDF)
    The end result stored in r11 if TCC lockup is commanded would look like this: 11111111111111111111111110111111 (0xFFFFFFBF)

    55 6b 06 b5 rlwinm. r11,r11,0x0,0x1a,0x1a
    This line here is a complex instruction. This is a rotate left word immediate then AND with mask instruction and because it has the . at the end of it, it also stores a value in what is called a Condition Register Field 0. The only part of this I have figured out is how it calculates the value to be stored in the Condition Register Field 0 and what it does with it once it is in there.

    But ultimately what it is doing in its use here is creating a mask of bits and using it to compare against the bits of the value stored in r11 and it is only looking specificaly at bit 26 in the mask and the value stored in r11. If bit 26 in the mask and the value in r11 match, it stores a value of 0x1 back into r11. If bit 26 in each do not match, it stores a value 0x0 into r11.

    The mask would look like this: 00000000000000000000000000100000 (0x20)

    If we put the TCC lockup not commanded value on top of the mask value:

    11111111111111111111111111011111 (0xFFFFFFDF)
    00000000000000000000000000100000 (0x20)

    We can see that bit 26 does not match, this would make our result 0x0 that gets stored back into r11

    If we put the TCC lockup commanded value on top of the mask value:

    11111111111111111111111110111111 (0xFFFFFFBF)
    00000000000000000000000000100000 (0x20)

    Here we see that bit 26 does match in both values, so the result getting stored back into r11 would be 0x1

    The rlwinm. instruction gets way more complex than what it is doing here.

    40 82 00 0c bne LAB_002c5b2c
    What this line is doing is basically saying that if the above is not equal then branch off to another set of instructions.

    88 ae 93 82 lbz r5,-0x6c7e(r14)
    Here on this line, if the above was equal and it didn't branch off to another set of instructions, it pulls the stored max line pressure for TCC lockup from its location and places in into register r5.

    48 00 00 64 b LAB_002c5b8c
    It then branches off to a different set of instructions afterwards from here to load the max line pressure while TCC is in lockup in a specific address in the volatile memory block then branches off again to continue where it left off from before branching to the above set of code.


    Again, part of whats happening here I may have slightly off, specifically at the rlwinm. instruction, its a pretty complex instruction to wrap the mind around. But in a nutshell this is whats happening while the ecm code is deciding what to set the max allowable line pressure to be. Now if you could imagine the extra work a person would need to go through to determine what this bit of code is without knowing any of the parameters at all. I know that this piece of code is for the max line pressure while TCC is in lockup because this bit, -0x6c7e(r14), points directly to the parameter for the max line pressure while in TCC lockup.
    Last edited by Jim P; 12-14-2022 at 11:21 AM.

  2. #2
    Banned
    Join Date
    Jan 2018
    Location
    Everywhere
    Posts
    1,772
    Here is the pseudocode for all the above:

    uVar1 = 0;
    if ((~*(byte *)(unaff__r15 + -0x7a19) & 0x20) == 0) {
    uVar2 = *(undefined *)(unaff__r14 + -0x6c7e);
    }
    else if


    To put into simpler words:

    Max allowed line pressure = 0
    If bit 26 from TCC lockup commanded value IS EQUAL to 0
    Get max line pressure while TCC lockup value from its location
    Otherwise do...
    Last edited by Jim P; 12-13-2022 at 09:43 PM.

  3. #3
    I always appreciate the knowledge that you share Jim and thank you for sharing this bit of assembly logic that you have been figuring out. Do you know what ISA Chrysler is using for the 68RFE controller? I believe you have stated that Cummins uses PowerPC ISA for their controllers.

    I do have one question on the result byte nomenclature. I thought when leading a byte value with 0x that means it is hexadecimal format. You are using 0x followed by the raw bits. I can be totally wrong about this as I have not spent much time studying hex or various ISA's.

    If you are a Medium subscriber, I would recommend you check out the author Erik Engheim. He writes a lot about different ISA's and how they work. He has also created his own ISA for teaching others how logic works.

    Again, thank you for sharing all the hard work you do!
    2019 CCSB Bighorn - Excited HP Tuners finally supported Cummins CM2350&2450 platforms

  4. #4
    Banned
    Join Date
    Jan 2018
    Location
    Everywhere
    Posts
    1,772
    Quote Originally Posted by jfreemanak View Post
    I always appreciate the knowledge that you share Jim and thank you for sharing this bit of assembly logic that you have been figuring out. Do you know what ISA Chrysler is using for the 68RFE controller? I believe you have stated that Cummins uses PowerPC ISA for their controllers.

    I do have one question on the result byte nomenclature. I thought when leading a byte value with 0x that means it is hexadecimal format. You are using 0x followed by the raw bits. I can be totally wrong about this as I have not spent much time studying hex or various ISA's.

    If you are a Medium subscriber, I would recommend you check out the author Erik Engheim. He writes a lot about different ISA's and how they work. He has also created his own ISA for teaching others how logic works.

    Again, thank you for sharing all the hard work you do!
    Corrected the bits and hex format. Yes PowerPC is used as the ISA.

  5. #5
    nice work sir,let me know when and where class is for in-person training lol
    love the info and detail you always post
    2010 F-350 03 5.9/848ecm, built 5R110, 30% over sticks, 10mm pump, 64mm Stealth Turbo
    2008 F-350 03 5.9
    Fumminstuning.com

  6. #6
    Banned
    Join Date
    Jan 2018
    Location
    Everywhere
    Posts
    1,772
    Lol I dunno if I?m the guy to really go as far teaching programming language and stuff. It?s not an easy subject lol. But I wanted to showcase a bit what it looks like for someone to be going through figuring out what is what in these things. It?s pretty complex and there is a lot of weird stuff going on in there and I won?t be covering things like how it is that I know that the -0x6c7e(r14) mentioned above is the TCC max lockup line pressure and that it points to that parameter.

  7. #7
    Potential Tuner
    Join Date
    Nov 2023
    Posts
    2
    ����

  8. #8
    Advanced Tuner
    Join Date
    Sep 2023
    Posts
    436
    All I see is a bunch of question marks inside a black diamond or something

  9. #9
    Me too. I am assuming those are emoji's that aren't recognized by Chromium.
    2019 CCSB Bighorn - Excited HP Tuners finally supported Cummins CM2350&2450 platforms

  10. #10
    Advanced Tuner
    Join Date
    Sep 2023
    Posts
    436
    Maybe

  11. #11
    Advanced Tuner
    Join Date
    Sep 2023
    Posts
    436
    2012 68RFE Line Pressure Sensor Fault Logic

    Code:
    // Function to check the line pressure sensor for faults
    void LP_Sensor_Fault_Check(void)
    {
        // Declare necessary variables
        char cVar1;  // Character variable (used for flags in conditions)
        byte bVar2;  // Byte variable (used for line pressure sensor thresholds and flags)
        byte bVar3;  // Byte variable (used for temporary variable in the fault counter)
        byte bVar4;  // Byte variable (used for various registers and counters)
        ushort uVar5;  // Unsigned short (used for increments and comparisons)
        byte bVar6;  // Byte variable (used for additional flags)
    
        // Read line pressure sensor maximum voltage
        bVar2 = Line_Pressure_Sensor_Max_Voltage;
        // Read the status flag register
        bVar4 = Status_Flag_Register;
    
        // Check if a specific bit (bit 4) in the status flag register is clear
        if ((bVar4 & 0x10) == 0) {
            // If bit is clear, reset the fault status and counters
            bVar4 = Line_Pressure_Sensor_Fault_Status_Flag_Register;
            Line_Pressure_Sensor_Fault_Status_Flag_Register = bVar4 & 0xfe; // Clear the fault flag
            Pressure_Sensor_High_Fault_Counter = 0;  // Reset the high fault counter
            Pressure_Sensor_Low_Fault_Counter = 0;   // Reset the low fault counter
            return; // Exit function
        }
    
        // Read the line pressure sensor analog-to-digital conversion value
        bVar4 = Line_Pressure_Analog_to_Digital;
    
        // Check if the sensor value is below the maximum voltage threshold or if the desired pressure is exceeded
        if ((bVar4 < Line_Pressure_Sensor_Max_Voltage) ||
            (bVar6 = DESLPRES, PSHFC_Desired_Line_Pressure_Check_Limit <= bVar6)) {
    
            // Check if the value is below a secondary threshold for maximum voltage
            if (bVar4 < Line_Pressure_Sensor_Max_Voltage_#2) {
    LAB_DecrementHighFaultCounter:
                // Decrement the high fault counter
                bVar4 = Pressure_Sensor_High_Fault_Counter;
                bVar6 = (byte)((ushort)bVar4 - (ushort)Pressure_Sensor_High_Fault_Counter_Decrement);
                if ((short)((ushort)bVar4 - (ushort)Pressure_Sensor_High_Fault_Counter_Decrement) < 0) {
                    bVar6 = 0;  // Ensure the counter doesn't go negative
                }
                Pressure_Sensor_High_Fault_Counter = bVar6;
            }
            else {
                // Check specific system fault flags and thresholds for the sensor
                bVar6 = Line_Pressure_System_Fault_Flag_Register;
                if ((((~bVar6 & 4) == 0) && (bVar6 = General_Purpose_Flag_Register_1, (bVar6 & 4) == 0)) &&
                    (bVar6 = DESLPRES, bVar6 < PSHFC_Desired_Line_Pressure_Check_#2_Threshold))
                    goto LAB_IncrementHighFaultCounter;
                
                // If pressure is below secondary max voltage threshold, go to the fault handling
                if (bVar4 < Line_Pressure_Sensor_Max_Voltage_#2) goto LAB_DecrementHighFaultCounter;
            }
        }
        else {
    LAB_IncrementHighFaultCounter:
            // Increment the high fault counter if the sensor is still within range
            bVar4 = Pressure_Sensor_High_Fault_Counter;
            uVar5 = (ushort)bVar4 + (ushort)Pressure_Sensor_High_Fault_Counter_Increment;
            if (0xff < uVar5) {
                uVar5 = 0xff;  // Cap the value to 0xff
            }
            Pressure_Sensor_High_Fault_Counter = (byte)uVar5;
    
            // Check if the fault counter exceeds the threshold and set the fault flag
            bVar4 = General_Purpose_Flag_Register_104;
            if (((bVar4 & 0x10) == 0) && ((ushort)Pressure_Sensor_High_Fault_Set_Threshold < (uVar5 & 0xff))) {
                General_Purpose_Flag_Register_104 = bVar4 | 0x10;  // Set the fault flag
                FUN_002c6d90(0xcd);  // Call a function
            }
        }
    
        // Read the minimum voltage threshold for the pressure sensor
        bVar6 = Line_Pressure_Sensor_Min_Voltage;
        bVar4 = Line_Pressure_Analog_to_Digital;
    
        // Check if the current sensor value is above the minimum voltage threshold and other conditions
        if ((Line_Pressure_Sensor_Min_Voltage < bVar4) &&
            (((Line_Pressure_Sensor_Min_Voltage_#2 < bVar4 ||
               (bVar4 = Line_Pressure_Sensor_Condition_Flag_Register, (bVar4 & 1) != 0)) ||
            ((bVar4 = General_Purpose_Flag_Register_1, (bVar4 & 4) != 0 ||
             (((bVar4 = THDATA, bVar4 <= Line_Pressure_Low_Throttle_Threshold ||
               (cVar1 = Line_Pressure_Threshold_or_Error_Flag, cVar1 == -0x40)) ||
              (uVar5 = Line_Pressure_Low_Engine_Runtime_Counter,
               uVar5 < Line_Pressure_Low_Engine_Runtime_Threshold)))))))) {
    
            // Decrement the low fault counter if conditions for low voltage are met
            bVar4 = Pressure_Sensor_Low_Fault_Counter;
            bVar3 = (byte)((ushort)bVar4 - (ushort)Pressure_Sensor_Low_Fault_Counter_Decrement);
            if ((short)((ushort)bVar4 - (ushort)Pressure_Sensor_Low_Fault_Counter_Decrement) < 0) {
                bVar3 = 0;  // Ensure the counter doesn't go negative
            }
            Pressure_Sensor_Low_Fault_Counter = bVar3;
        }
        else {
            // Increment the low fault counter if sensor value is valid
            bVar4 = Pressure_Sensor_Low_Fault_Counter;
            uVar5 = (ushort)bVar4 + (ushort)Pressure_Sensor_Low_Fault_Counter_Increment;
            if (0xff < uVar5) {
                uVar5 = 0xff;  // Cap the counter at 0xff
            }
            Pressure_Sensor_Low_Fault_Counter = (char)uVar5;
    
            // Check if the fault counter exceeds the threshold and set the fault flag
            bVar4 = General_Purpose_Flag_Register_104;
            if (((bVar4 & 0x20) == 0) && ((ushort)Pressure_Sensor_Low_Fault_Set_Threshold < (uVar5 & 0xff))) {
                General_Purpose_Flag_Register_104 = bVar4 | 0x20;  // Set the fault flag
                FUN_002c6d90(0xcc);  // Call a function
            }
        }
    
        // Final check to update the fault status register based on the sensor reading
        bVar4 = Line_Pressure_Analog_to_Digital;
        if (bVar6 < bVar4) {
            if (bVar4 < bVar2) {
                bVar4 = Line_Pressure_Sensor_Fault_Status_Flag_Register;
                bVar4 = bVar4 | 1;  // Set the fault flag
                goto LAB_SetFaultFlag;
            }
    LAB_CheckVoltageRange:
            bVar2 = DESLPRES;
            if (PSHFC_Desired_Line_Pressure_Check_Limit <= bVar2) goto LAB_CheckLinePressure;
        }
        else {
            if (bVar2 <= bVar4) goto LAB_CheckVoltageRange;
    LAB_CheckLinePressure:
            if (bVar6 < bVar4) {
                return;  // Exit if conditions met
            }
        }
    
        // Clear the fault flag if necessary
        bVar4 = Line_Pressure_Sensor_Fault_Status_Flag_Register;
        bVar4 = bVar4 & 0xfe;  // Clear the fault bit
    LAB_SetFaultFlag:
        Line_Pressure_Sensor_Fault_Status_Flag_Register = bVar4;  // Update the fault status register
        return;  // Exit function
    }
    Last edited by Jim P 2.0; 01-04-2025 at 04:42 PM.

  12. #12
    Advanced Tuner
    Join Date
    Sep 2023
    Posts
    436
    Code:
    void Line_Pressure_Faults(void)
    {
        byte bVar1;  // Temporary variable for pressure thresholds
        ushort uVar2;  // Temporary variable for comparison and increments related to counters
        byte bVar3;  // Temporary variable for reading and updating registers
        byte bVar4;  // Temporary variable for line pressure and fault counters
        byte bVar5;  // Temporary variable for maximum line pressure comparison
        char cVar6;  // Character variable for flags or specific conditions
        byte bVar7;  // Temporary variable for fault counter values
        ushort uVar8;  // Temporary variable for thresholds and comparisons
    
        // Read Status Flag Register and check for bit 4 (0x10) condition
        bVar3 = Status_Flag_Register; // Load status flag register value
        if ((bVar3 & 0x10) == 0) {  // If bit 4 is clear (no fault)
            bVar7 = 0;  // Reset fault counter to 0
            goto Update_Circuit_Fault_Counter;  // Update fault counter with the reset value
        }
        else {  // If bit 4 is set (potential fault)
            // Check the General Purpose Flag for additional processing
            bVar3 = General_Purpose_Flag_Register_104;  // Load general-purpose flag
            if ((bVar3 & 1) != 0) {  // If the first bit (bit 0) is set
                goto Handle_Faults_And_Update_Flags;  // Go to fault handling logic
            }
    
            // Check Pressure Sensor High/Low Fault Counters
            bVar7 = Pressure_Sensor_High_Fault_Counter;  // Load high fault counter value
            if ((bVar7 < Pressure_Sensor_High_Fault_Counter_Check_1) &&
                (bVar4 = Pressure_Sensor_Low_Fault_Counter, bVar4 < Pressure_Sensor_Low_Fault_Counter_Check_1)) {
                // If both high and low fault counters are below threshold, check line pressure
                bVar1 = DESLPRES;  // Load desired line pressure value
                bVar4 = Line_Pressure;  // Load actual line pressure value
                if (((uint)bVar4 <= (uint)bVar1 + (uint)LPSFC_Desired_Line_Pressure_Offset_1) ||
                    (bVar5 = Max_LP, bVar1 = Line_Pressure_Sensor_Circuit_Fault_Count_Increment,
                     (uint)bVar5 <= (uint)bVar4)) {
                    goto Check_And_Validate_Fault_Conditions;  // Check fault conditions if valid
                }
            }
            else {  // If either high or low fault counters exceed threshold, check fault conditions
                goto Check_And_Validate_Fault_Conditions;
            }
        }
    
        // Check and Validate Fault Conditions
    Check_And_Validate_Fault_Conditions:
        bVar4 = Line_Pressure;
        if ((((uint)bVar4 <= (uint)LPSFC_Pressure_Threshold) || (bVar1 = Line_Pressure_Sensor_Condition_Flag_Register, (~bVar1 & 1) != 0)) ||
            (bVar1 = Current_Sensor_Fault_State, bVar1 < Pressure_Sensor_Fault_Minimum_Threshold)) {
            // If pressure is below threshold or certain flags are set, handle faults
            if ((((Pressure_Sensor_High_Fault_Counter_Check_1 <= bVar7) ||
                (bVar3 = Pressure_Sensor_Low_Fault_Counter,
                 Pressure_Sensor_Low_Fault_Counter_Check_1 <= bVar3)) ||
                (bVar3 = DESLPRES, (uint)bVar3 + (uint)LPSFC_Desired_Line_Pressure_Offset_2 <= (uint)bVar4)) ||
               ((int)(uint)bVar4 <=
                (int)((int)(short)(ushort)bVar3 - (uint)LPSFC_Desired_Line_Pressure_Offset_2))) {
                goto Handle_Faults_And_Update_Flags;  // Handle faults and update flags
            }
            // If pressure is valid, decrement the fault counter
            bVar3 = Line_Pressure_Sensor_Circuit_Fault_Counter;
            bVar7 = (byte)((ushort)bVar3 - (ushort)Line_Pressure_Sensor_Circuit_Fault_Count_Decrement);
            if ((short)((ushort)bVar3 - (ushort)Line_Pressure_Sensor_Circuit_Fault_Count_Decrement) < 0) {
                bVar7 = 0;  // Prevent underflow, reset counter to 0
            }
            goto Update_Circuit_Fault_Counter;  // Update fault counter with the new value
        }
        // If no fault is detected, increment the fault counter
        bVar1 = Line_Pressure_Sensor_Circuit_Fault_Count_Increment_1;
        if (Pressure_Sensor_High_Fault_Counter_Check_1 <= bVar7) {
            goto Handle_Faults_And_Update_Flags;  // If high fault counter exceeded, handle fault
        }
    
        // Increment the fault counter and update, capping it at 255 (0xFF)
        bVar7 = Line_Pressure_Sensor__Circuit_Fault_Counter;
        uVar8 = (ushort)bVar7 + (ushort)bVar1;
        if (0xff < uVar8) {
            uVar8 = 0xff;  // Cap counter at 255 if it exceeds
        }
        Line_Pressure_Sensor_Circuit_Fault_Counter = (byte)uVar8;  // Update fault counter
    
        // Check if fault flag should be set based on counter threshold
        if ((ushort)Line_Pressure_Sensor_Circuit_Fault_Flag_Set_Threshold <= (uVar8 & 0xff)) {
            General_Purpose_Flag_Register_104 = bVar3 | 1;  // Set fault flag
            FUN_002c6d90(0xca);  // Trigger external function with fault flag
        }
    
        // Handle faults and update flags
    Handle_Faults_And_Update_Flags:
        bVar3 = General_Purpose_Flag_Register_104;
        if ((((~bVar3 & 0x80) != 0) || (bVar7 = Line_Pressure, bVar7 <= Line_Pressure_Primed_Threshold))
            && ((cVar6 = Line_Pressure_Threshold_or_Error_Flag, cVar6 != -0x40 &&
                (((uVar8 = Line_Pressure_Low_Engine_Runtime_Counter,
                Line_Pressure_Low_Engine_Runtime_Threshold <= uVar8 &&
                (bVar7 = Status_Flag_Register, (~bVar7 & 0x47) == 0x47)) && ((bVar3 & 2) == 0)))))) {
            bVar7 = Low_Pressure_Fault_Detection_Offset;
            uVar8 = (ushort)bVar7 + (ushort)LPLC_DCMIN_Offset_1 & 0xff;
            bVar4 = Pressure_Sensor_Low_Fault_Counter;
            if (uVar8 < bVar7) {
                uVar8 = 0xff;  // Cap value if it exceeds
            }
            if (bVar4 < Pressure_Sensor_Low_Fault_Counter_Check_1) {
                bVar1 = DESLPRES;  
                bVar7 = Line_Pressure;
                if ((((int)(uint)bVar7 <
                     (int)((int)(short)(ushort)bVar1 - (uint)LPLC_Desired_Line_Pressure_Offset_1)) ||
                     ((uint)bVar7 < (uint)Line_Pressure_Low_Threshold)) &&
                    (uVar2 = LPRESDC, uVar2 >> 8 <= uVar8)) {
                    bVar7 = Line_Pressure_Low_Fault_Counter;
                    Line_Pressure_Low_Fault_Counter = bVar7 + Line_Pressure_Low_Count_Increment;
                    if ((byte)(bVar7 + Line_Pressure_Low_Count_Increment) < Line_Pressure_Low_Count_Increment) {
                        Line_Pressure_Low_Fault_Counter = 0xff;  // Cap at 255
                    }
                    bVar7 = Line_Pressure_Low_Fault_Counter;
                    if (Line_Pressure_Low_Flag_Set_Threshold <= bVar7) {
                        General_Purpose_Flag_Register_104 = bVar3 | 2;  // Set low pressure fault flag
                        FUN_002c6d90(0xc9);  // Trigger external function for low pressure
                    }
                }
                else if ((bVar4 < Pressure_Sensor_Low_Fault_Counter_Check_1) &&
                         (((int)((int)(short)(ushort)bVar1 - (uint)LPLC_Desired_Line_Pressure_Offset_1) <=
                           (int)(uint)bVar7 || (uVar2 = LPRESDC, uVar8 < uVar2 >> 8)))) {
                    bVar3 = Line_Pressure_Low_Fault_Counter;
                    bVar7 = bVar3 - Line_Pressure_Low_Count_Decrement;
                    if (bVar3 < Line_Pressure_Low_Count_Decrement) {
                        bVar7 = 0;  // Prevent underflow, reset to 0
                    }
                    Line_Pressure_Low_Fault_Counter = bVar7;  // Update counter
                }
            }
        }
    
        // Handle high-pressure faults
        bVar3 = Pressure_Fault_Status_Flags;
        if ((bVar3 & 4) == 0) {  // If high-pressure fault flag is not set
            bVar7 = High_Pressure_Fault_Detection_Offset;
            uVar8 = (ushort)bVar7 - (ushort)Line_Pressure_High_Count_DCMAX_Offset_1 & 0xff;
            if (bVar7 < Line_Pressure_High_Count_DCMAX_Offset_1) {
                uVar8 = 0;  // Set to 0 if offset below threshold
            }
            bVar7 = Pressure_Sensor_High_Fault_Counter;
            if (bVar7 < Pressure_Sensor_High_Fault_Counter_Check_1) {
                bVar4 = Line_Pressure;
                if (((LPHC_Pf2_Check_1 < bVar4) && (uVar2 = LPRESDC, uVar8 <= uVar2 >> 8)) &&
                    (bVar1 = Line_Pressure_Sensor__Circuit_Fault_Counter, bVar1 == DAT_002f3b0d)) {
                    bVar7 = Line_Pressure_High_Fault_Counter;
                    Line_Pressure_High_Fault_Counter = bVar7 + Line_Pressure_High_Count_Increment;
                    if ((byte)(bVar7 + Line_Pressure_High_Count_Increment) < Line_Pressure_High_Count_Increment) {
                        Line_Pressure_High_Fault_Counter = 0xff;  // Cap at 255
                    }
                    bVar7 = Line_Pressure_High_Fault_Counter;
                    if ((Line_Pressure_High_Flag_Set_Threshold <= bVar7) &&
                        (bVar7 = General_Purpose_Flag_Register_104, (bVar7 & 1) == 0)) {
                        Pressure_Fault_Status_Flags = bVar3 | 4;  // Set high pressure fault flag
                        FUN_002c6d90(0xcb);  // Trigger external function for high pressure
                    }
                }
                else if ((bVar7 < Pressure_Sensor_High_Fault_Counter_Check_1) &&
                        ((bVar4 <= LPHC_Pf2_Check_1 || (uVar2 = LPRESDC, uVar2 >> 8 < uVar8)))) {
                    bVar3 = Line_Pressure_High_Fault_Counter;
                    bVar7 = bVar3 - Line_Pressure_High_Count_Decrement;
                    if (bVar3 < Line_Pressure_High_Count_Decrement) {
                        bVar7 = 0;  // Prevent underflow
                    }
                    Line_Pressure_High_Fault_Counter = bVar7;  // Update high fault counter
                }
            }
        }
    
        return;
    }
    Last edited by Jim P 2.0; 01-04-2025 at 06:05 PM.

  13. #13
    Advanced Tuner
    Join Date
    Sep 2023
    Posts
    436
    I will clean this up and add in comments later to describe what is going on

    Code:
    void Grade_Hunt/Decel_Upshift_Inhibit_Clear(void)
    
    {
      ushort uVar1;
      byte bVar2;
      byte bVar3;
      short sVar4;
      ushort uVar5;
      
      bVar2 = General_Purpose_Flag_Register_1;
      if (((((bVar2 & 4) == 0) && (bVar3 = Gear/TCC_State_Code, (~bVar3 & 4) == 0)) &&
          (uVar5 = Engine_RPM, Minimum_Engine_Speed_for_Clearing_the_D12UI_Flag < uVar5)) &&
         ((uVar5 < Maximum_Engine_Speed_for_Clearing_the_D12UI_Flag &&
          (uVar5 = Engine_Torque, uVar5 < Engine_Torque_Limit_for_Clearing_D12UI)))) {
        sVar4 = Decel_1-2_Upshift_Inhibit_Clear_Counter;
        if (sVar4 != -1) {
          sVar4 = sVar4 + 1;
          goto LAB_002a5db4;
        }
      }
      else {
        sVar4 = 0;
    LAB_002a5db4:
        Decel_1-2_Upshift_Inhibit_Clear_Counter = sVar4;
      }
      if ((((bVar2 & 4) == 0) && (bVar3 = Gear/TCC_State_Code, (~bVar3 & 8) == 0)) &&
         ((uVar5 = Engine_RPM, Minimum_Engine_Speed_for_Clearing_the_D22PUI_Flag < uVar5 &&
          ((uVar5 < Maximum_Engine_Speed_for_Clearing_the_D22PUI_Flag &&
           (uVar5 = Engine_Torque, uVar5 < Engine_Torque_Limit_for_Clearing_D22PUI)))))) {
        sVar4 = Decel_2-2P_Upshift_Inhibit_Clear_Counter;
        if (sVar4 != -1) {
          sVar4 = sVar4 + 1;
          goto LAB_002a5e1c;
        }
      }
      else {
        sVar4 = 0;
    LAB_002a5e1c:
        Decel_2-2P_Upshift_Inhibit_Clear_Counter = sVar4;
      }
      if (((((bVar2 & 4) == 0) && (bVar3 = Gear/TCC_State_Code, (~bVar3 & 0x10) == 0)) &&
          (uVar5 = Engine_RPM, Minimum_Engine_Speed_for_Clearing_the_D2P3UI_Flag < uVar5)) &&
         ((uVar5 < Maximum_Engine_Speed_for_Clearing_the_D2P3UI_Flag &&
          (uVar5 = Engine_Torque, uVar5 < Engine_Torque_Limit_for_Clearing_D2P3UI)))) {
        sVar4 = Decel_2P-3_Upshift_Inhibit_Clear_Counter;
        if (sVar4 != -1) {
          sVar4 = sVar4 + 1;
          goto LAB_002a5e84;
        }
      }
      else {
        sVar4 = 0;
    LAB_002a5e84:
        Decel_2P-3_Upshift_Inhibit_Clear_Counter = sVar4;
      }
      if ((((bVar2 & 4) == 0) && (bVar3 = Gear/TCC_State_Code, (~bVar3 & 0x20) == 0)) &&
         ((uVar5 = Engine_RPM, Minimum_Engine_Speed_for_Clearing_the_D34UI_Flag < uVar5 &&
          ((uVar5 < Maximum_Engine_Speed_for_Clearing_the_D34UI_Flag &&
           (uVar5 = Engine_Torque, uVar5 < Engine_Torque_Limit_for_Clearing_D34UI)))))) {
        sVar4 = Decel_3-4_Upshift_Inhibit_Clear_Counter;
        if (sVar4 != -1) {
          sVar4 = sVar4 + 1;
          goto LAB_002a5eec;
        }
      }
      else {
        sVar4 = 0;
    LAB_002a5eec:
        Decel_3-4_Upshift_Inhibit_Clear_Counter = sVar4;
      }
      if (((bVar2 & 4) == 0) && (bVar2 = Gear/TCC_State_Code, (~bVar2 & 0x40) == 0)) {
        uVar5 = Engine_RPM;
        if (uVar5 <= Minimum_Engine_Speed_for_Clearing_the_D44PUI_Flag) goto LAB_002a5f50;
        if (Maximum_Engine_Speed_for_Clearing_the_D44PUI_Flag <= uVar5) goto LAB_002a5f50;
        uVar5 = Engine_Torque;
        if (Engine_Torque_Limit_for_Clearing_D44PUI <= uVar5) goto LAB_002a5f50;
        sVar4 = Decel_4-4P_Upshift_Inhibit_Clear_Counter;
        if (sVar4 != -1) {
          sVar4 = sVar4 + 1;
          goto LAB_002a5f54;
        }
      }
      else {
    LAB_002a5f50:
        sVar4 = 0;
    LAB_002a5f54:
        Decel_4-4P_Upshift_Inhibit_Clear_Counter = sVar4;
      }
      uVar5 = Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register;
      if ((~uVar5 & 0x800) == 0) {
        bVar2 = Throttle_Angle;
        if (Throttle_Threshold_for_D12UI <= bVar2) {
          uVar1 = Decel_1-2_Upshift_Inhibit_Clear_Counter;
          if (uVar1 <= Decel_Upshift_Inhibit_Clear_Counter_Limit) goto LAB_002a5fa4;
        }
        uVar5 = uVar5 & 0xf7ff;
    LAB_002a5fa0:
        Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register = uVar5;
      }
      else if ((~uVar5 & 0x10) == 0) {
        uVar5 = uVar5 | 0x800;
        goto LAB_002a5fa0;
      }
    LAB_002a5fa4:
      uVar5 = Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register;
      if ((~uVar5 & 0x20) == 0) {
        bVar2 = Throttle_Angle;
        if ((Throttle_Threshold_for_D22PUI <= bVar2) &&
           (uVar1 = OSS_RPM_Filtered,
           uVar1 <= Output_Speed_Threshold_to_Clear_the_2-2P_Grade-Hunt_Detection_Flag)) {
          uVar1 = Decel_2-2P_Upshift_Inhibit_Clear_Counter;
          if (uVar1 <= Decel_Upshift_Inhibit_Clear_Counter_Limit) goto LAB_002a6020;
        }
        sVar4 = Engine_Temperature;
        if (sVar4 < Engine_Temperature_Threshold) {
          uVar5 = uVar5 & 0xffdf;
    LAB_002a601c:
          Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register = uVar5;
        }
      }
      else if (((~Configuration_Flags_for_Shift_Schedule_Logic_2 & 0x10) == 0) && ((~uVar5 & 1) == 0)) {
        uVar5 = uVar5 | 0x20;
        goto LAB_002a601c;
      }
    LAB_002a6020:
      uVar5 = Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register;
      if ((~uVar5 & 0x40) == 0) {
        bVar2 = Throttle_Angle;
        if ((Throttle_Threshold_for_D2P3UI <= bVar2) &&
           (uVar1 = OSS_RPM_Filtered,
           uVar1 <= Output_Speed_Threshold_to_Clear_the_2P-3_Grade-Hunt_Detection_Flag)) {
          uVar1 = Decel_2P-3_Upshift_Inhibit_Clear_Counter;
          if (uVar1 <= Decel_Upshift_Inhibit_Clear_Counter_Limit) goto LAB_002a609c;
        }
        sVar4 = Engine_Temperature;
        if (sVar4 < Engine_Temperature_Threshold) {
          uVar5 = uVar5 & 0xffbf;
    LAB_002a6098:
          Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register = uVar5;
        }
      }
      else if (((~Configuration_Flags_for_Shift_Schedule_Logic_2 & 0x10) == 0) && ((~uVar5 & 2) == 0)) {
        uVar5 = uVar5 | 0x40;
        goto LAB_002a6098;
      }
    LAB_002a609c:
      uVar5 = Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register;
      if ((~uVar5 & 0x80) == 0) {
        bVar2 = Throttle_Angle;
        if ((Throttle_Threshold_for_D34UI <= bVar2) &&
           (uVar1 = OSS_RPM_Filtered,
           uVar1 <= Output_Speed_Minimum_Threshold_for_Clearing_the_3-4_Grade-Hunt_Detection_Flag)) {
          uVar1 = Decel_3-4_Upshift_Inhibit_Clear_Counter;
          if (uVar1 <= Decel_Upshift_Inhibit_Clear_Counter_Limit) goto LAB_002a6118;
        }
        sVar4 = Engine_Temperature;
        if (Engine_Temperature_Threshold <= sVar4) goto LAB_002a6118;
        uVar5 = uVar5 & 0xff7f;
      }
      else {
        if (((~Configuration_Flags_for_Shift_Schedule_Logic_2 & 0x10) != 0) || ((~uVar5 & 4) != 0))
        goto LAB_002a6118;
        uVar5 = uVar5 | 0x80;
      }
      Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register = uVar5;
    LAB_002a6118:
      uVar5 = Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register;
      if ((~uVar5 & 0x100) == 0) {
        bVar2 = Throttle_Angle;
        if (((Throttle_Threshold_for_D44PUI <= bVar2) &&
            (uVar1 = OSS_RPM_Filtered,
            uVar1 <= Output_Speed_Threshold_to_clear_4-4P_Grade_Hunt_Detection_Flag)) &&
           (uVar1 = Decel_4-4P_Upshift_Inhibit_Clear_Counter,
           uVar1 <= Decel_Upshift_Inhibit_Clear_Counter_Limit)) {
          return;
        }
        sVar4 = Engine_Temperature;
        if (Engine_Temperature_Threshold <= sVar4) {
          return;
        }
        uVar5 = uVar5 & 0xfeff;
      }
      else {
        if ((~Configuration_Flags_for_Shift_Schedule_Logic_2 & 0x10) != 0) {
          return;
        }
        if ((~uVar5 & 8) != 0) {
          return;
        }
        uVar5 = uVar5 | 0x100;
      }
      Grade_Hunt/Decel_Upshift_Inhibit_Flags_Register = uVar5;
      return;
    }
    Last edited by Jim P 2.0; 01-09-2025 at 03:10 PM.

  14. #14
    Advanced Tuner
    Join Date
    Sep 2023
    Posts
    436
    Still some stuff to identify but contains a sliver of the TCC lockup logic

    Code:
    void FUN_002d267c(void)
    {
      byte bVar1; // Temporary variable to hold byte-sized data
      ushort uVar2; // Temporary variable to hold unsigned 16-bit data
      byte bVar3; // Temporary variable to hold byte-sized data
      ushort uVar4; // Variable to store the selected turbine speed threshold
    
      // Read initial system flags
      uVar2 = DAT_600023bc; 
      // Set default turbine speed threshold for overheat mode
      uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_While_in_Overheat;
    
      // Outer condition to determine whether to proceed with the logic
      if ((((((~uVar2 & 1) != 0) && // Check if the least significant bit (LSB) of uVar2 is cleared
            (bVar1 = DAT_6000248c, // Load additional system flags into bVar1
            uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_Exhaust_Brake_Pending_in_2nd_Gear, // Update turbine speed threshold for exhaust brake
            (~bVar1 & 2) != 0)) && // Check if bit 1 of bVar1 is cleared
          (bVar1 = DAT_6000248d, (~bVar1 & 0x20) != 0)) && // Check if bit 5 of bVar1 is cleared
         ((uVar2 = DAT_600023c0, // Load another set of system flags
           uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_IDFSO, // Update turbine speed threshold for IDFSO
           (~uVar2 & 0x400) != 0 && // Check if bit 10 of uVar2 is cleared
           (bVar1 = DAT_600020d5, (~bVar1 & 0x80) != 0)))) && // Check if bit 7 of bVar1 is cleared
        (uVar2 = DAT_600023c2, (~uVar2 & 2) != 0)) // Check if bit 1 of uVar2 is cleared
      {
        // Read the flag register related to torque management
        bVar1 = Flag_Register_for_?(Related_to_TQ_Management);
        if ((~bVar1 & 0x40) == 0) { // Check if bit 6 of bVar1 is NOT cleared
          bVar1 = General_Purpose_Flag_Register_1;
          if ((((((bVar1 & 4) != 0) || // Check if bit 2 of bVar1 is set(Change state of Gear/TCC request)
                (bVar3 = Gear/TCC_State_Code,
                uVar4 = Unlock_to_Partial_Lock_Turbine_Speed_Threshold_for_2nd_Gear_in_Driver_Select_Mode, // Set threshold for 2nd gear
                (~bVar3 & 8) != 0)) && // Check if bit 3 of bVar3 is cleared
               (((bVar1 & 4) != 0 || 
                (bVar3 = Gear/TCC_State_Code,
                uVar4 = Unlock_to_Partial_Lock_Turbine_Speed_Threshold_for_2P_Gear_in_Driver_Select_Mode, // Set threshold for 2P gear
                (~bVar3 & 0x10) != 0)))) && // Check if bit 4 of bVar3 is cleared
              (((bVar1 & 4) != 0 || 
               (bVar3 = Gear/TCC_State_Code,
               uVar4 = Unlock_to_Partial_Lock_Turbine_Speed_Threshold_for_3rd_Gear_in_Driver_Select_Mode, // Set threshold for 3rd gear
               (~bVar3 & 0x20) != 0)))) && // Check if bit 5 of bVar3 is cleared
             (((bVar1 & 4) != 0 || 
              (bVar3 = Gear/TCC_State_Code,
              uVar4 = Unlock_to_Partial_Lock_Turbine_Speed_Threshold_for_4th_Gear_in_Driver_Select_Mode, // Set threshold for 4th gear
              (~bVar3 & 0x40) != 0)))) { // Check if bit 6 of bVar3 is cleared
            if ((bVar1 & 4) != 0) { // Final check if bit 2 of bVar1 is set
              return; // Exit early if condition is met
            }
            bVar1 = Gear/TCC_State_Code;
            uVar4 = Unlock_to_Partial_Lock_Turbine_Speed_Threshold_for_4P_Gear_in_Driver_Select_Mode; // Set threshold for 4P gear
            if ((~bVar1 & 0x80) != 0) { // Check if bit 7 of bVar1 is cleared
              return; // Exit early if condition is met
            }
          }
        }
        else {
          uVar2 = DAT_6000225a; // Load additional system flags
          bVar1 = General_Purpose_Flag_Register_1;
          if ((uVar2 & 4) == 0) { // Check if bit 2 of uVar2 is cleared
            if (((((bVar1 & 4) != 0) || 
                 (bVar3 = Gear/TCC_State_Code,
                 uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_2nd_Gear, // Set threshold for 2nd gear
                 (~bVar3 & 8) != 0)) && // Check if bit 3 of bVar3 is cleared
                (((bVar1 & 4) != 0 || 
                 (bVar3 = Gear/TCC_State_Code,
                 uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_2P_Gear, // Set threshold for 2P gear
                 (~bVar3 & 0x10) != 0)))) && // Check if bit 4 of bVar3 is cleared
               ((((bVar1 & 4) != 0 || 
                 (bVar3 = Gear/TCC_State_Code,
                 uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_3rd_Gear, // Set threshold for 3rd gear
                 (~bVar3 & 0x20) != 0)) && // Check if bit 5 of bVar3 is cleared
                (((bVar1 & 4) != 0 || 
                 (bVar3 = Gear/TCC_State_Code,
                 uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_4th_Gear, // Set threshold for 4th gear
                 (~bVar3 & 0x40) != 0)))))) { // Check if bit 6 of bVar3 is cleared
              if ((bVar1 & 4) != 0) { // Final check if bit 2 of bVar1 is set
                return; // Exit early if condition is met
              }
              bVar1 = Gear/TCC_State_Code;
              uVar4 = Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_4P_Gear; // Set threshold for 4P gear
              if ((~bVar1 & 0x80) != 0) { // Check if bit 7 of bVar1 is cleared
                return; // Exit early if condition is met
              }
            }
          }
          else if (((((bVar1 & 4) != 0) || 
                    (bVar3 = Gear/TCC_State_Code,
                    uVar4 = Tow/Haul_Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_2nd_Gear, // Set Tow/Haul threshold for 2nd gear
                    (~bVar3 & 8) != 0)) && // Check if bit 3 of bVar3 is cleared
                   (((bVar1 & 4) != 0 || 
                    (bVar3 = Gear/TCC_State_Code,
                    uVar4 = Tow/Haul_Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_2P_Gear, // Set Tow/Haul threshold for 2P gear
                    (~bVar3 & 0x10) != 0)))) && // Check if bit 4 of bVar3 is cleared
                  ((((bVar1 & 4) != 0 || 
                    (bVar3 = Gear/TCC_State_Code,
                    uVar4 = Tow/Haul_Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_3rd_Gear, // Set Tow/Haul threshold for 3rd gear
                    (~bVar3 & 0x20) != 0)) && // Check if bit 5 of bVar3 is cleared
                   (((bVar1 & 4) != 0 || 
                    (bVar3 = Gear/TCC_State_Code,
                    uVar4 = Tow/Haul_Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_for_4th_Gear, // Set Tow/Haul threshold for 4th gear
                    (~bVar3 & 0x40) != 0)))))) { // Check if bit 6 of bVar3 is cleared
            if ((bVar1 & 4) != 0) { // Final check if bit 2 of bVar1 is set
              return; // Exit early if condition is met
            }
            bVar1 = Gear/TCC_State_Code;
            uVar4 = Tow/Haul_Unlock_to_Partial_Lock_Minimum_Filtered_Turbine_Speed_(Ntf)_for_4P_Gear; // Set Tow/Haul threshold for 4P gear
            if ((~bVar1 & 0x80) != 0) { // Check if bit 7 of bVar3 is cleared
              return; // Exit early if condition is met
            }
          }
        }
      }
      // Final assignment of the determined turbine speed threshold
      DAT_600023f6 = uVar4;
      return;
    }