This code should be here:
   if (cdiv > 0xffff)
     cdiv = 0xffff;