Page 1 of 1

Unnecessary double check?

Posted: Mon Aug 17, 2009 5:47 pm
by spacy51

gba.cpp, Ln 2645:

case 0xC6:
{

Code: Select all

  bool start= ((DM1CNT_H ^ value) & 0x8000) ? true : false;


  value &= 0xF7E0;

 

Code: Select all

  DM1CNT_H = value;


  UPDATE_REG(0xC6, DM1CNT_H);

 

Code: Select all

  if(start [b]&& (value & 0x8000)[/b]) {


    dma1Source = DM1SAD_L | (DM1SAD_H << 16);


    dma1Dest = DM1DAD_L | (DM1DAD_H << 16);


    CPUCheckDMA(0, 2);


  }


}


break;

 

My personal logic tells me that the bold part is unneeded.


Unnecessary double check?

Posted: Mon Aug 17, 2009 7:12 pm
by jbo_85

The bold part is needed. It fails if DM1CNT_H or value is >= 0x8000.


Unnecessary double check?

Posted: Mon Aug 17, 2009 8:13 pm
by spacy51

Look at the beginning.

start is only true if bit 15 of value is set, so it does not make sense to seperately check for that again in the bold part.


Unnecessary double check?

Posted: Mon Aug 17, 2009 8:18 pm
by jbo_85

Look at the beginning.

start is only true if bit 15 of value is set, so it does not make sense to seperately check for that again in the bold part.

It tests bit 15 of (DM1CNT_H ^ value) and not just bit 15 of value.