Master dimmer dmx channel code help

I'm used to being the only one to my code and I type with 2 fingers but here it is again with explanations ... if you can get passed my simple and horrible attempt at coding but hey it all works so far just have this issue

#include <DMXSerial.h>
#include <EEPROM.h>
#include <TM1637Display.h>

#define CLK 3  //pin layout for TM1637
#define DIO 4
#define UP  7  //pin layout for DMX address adjustment
#define DN  8  



TM1637Display display(CLK, DIO);
long previousMillis = 0;
long interval = 8000;

int X = (EEPROM.read(0)+ EEPROM.read(1)); // get saved DMX address
int pres = 0;


const uint8_t d[] = { SEG_B | SEG_C | SEG_D | SEG_E | SEG_G };

int ch = 4;   // set number of DMX channels
                       
#define R DMXSerial.read(X)     // DMX channel 1 RED
#define G DMXSerial.read(X+1)   // DMX channel 2 GREEN
#define B DMXSerial.read(X+2)   // DMX channel 3 BLUE
#define S DMXSerial.read(X+3)   // DMX channel 4 STROBE
#define D DMXSerial.read(X+4)   // DMX channel 5 MASTER DIMMER

void setup() {
  DMXSerial.init(DMXReceiver);
  display.setBrightness(6);
  pinMode (7,INPUT);
  pinMode (8,INPUT);
  pinMode (9,OUTPUT);       // RED pin
  pinMode (10,OUTPUT);      // GREEN pin
  pinMode (11,OUTPUT);      // BLUE pin
  
  display.clear();
  
  
}

void loop() {   

  // Main funtion of RGB dimmers and STROBE
  
   if (S > 0)  {
        analogWrite (9, R);
        analogWrite (10,G);
        analogWrite (11,B);
        delay(285-S);
        analogWrite (9, 0);
        analogWrite (10,0);
        analogWrite (11,0);
        delay(285-S);
    } 
    else {
        analogWrite (9, R);
        analogWrite (10,G);
        analogWrite (11,B);
      }

// What I need to do here is get DMX channel 5 (D) to be a master dimmer eg. R is at 75%, G at 50% and B at 100% of the max 255 but D is only at 50% need  
// it to dim R,G,B proportially... the equation I have for each channel individually arduino doesn't like so i think I'm just not using the right language
//      (((((R/255)*100)-((D/255)*100))*255)/100) ---- Doesn't work does nothin on DMX that is where percentages come in 
//      R -(255-D)  ---- Kinda worked but only if channel was maxed out at 255
          
           // Display settings
           
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval){ display.clear(); }

  else { display.setSegments(d,1,0);
         display.showNumberDec(X,false,3,1); }

  // DMX address adjustment
  
  if (digitalRead(UP)==1) {
    if (pres==0){
      X++;
      pres=1;
      previousMillis = currentMillis;
      delay (100); }
    else { pres=0; }}
    
  if (digitalRead(DN)==1) {
    if (pres==0){
      X--;
      pres=1;
      previousMillis = currentMillis;
      delay (100); }
    else { pres=0; }}  

  if (X > 512-(ch)) {X=1;}
  if (X < 1) {X=512-(ch);}

  // Save DMX address
  EEPROM.write(0,highByte(X));
  EEPROM.write(1,lowByte(X));

             
    }