struct setup
{
  unsigned char maxlimit;
  unsigned char deadend;
  unsigned char deadendadd;
  unsigned char blunderset;
  unsigned char white_ai;
  unsigned char black_ai;
  unsigned char depth1;
  unsigned char depth2;
  unsigned char blunders;
  unsigned char slide_pieces;
  unsigned char enable_clippy;
  unsigned char book_openings;
  unsigned char from_args;
  unsigned char board_rotation;
  unsigned char timecontrol;
  unsigned char difficulty;
  unsigned char show_legal_moves;
  unsigned char show_threatened;
  unsigned timelimit;
#ifdef SDLFUNCS
  unsigned char screen_scale;
#endif
} setup =
{
  .maxlimit = 255,
  .blunderset = 0,
  .white_ai = 0,
  .black_ai = 1,
  .blunders = 0,
  .slide_pieces = 1,
  .enable_clippy = 1,
  .book_openings = 1,
  .from_args = 0,
  .board_rotation = 0,
  .show_legal_moves = 1,
  .show_threatened = 0,
#ifdef SDLFUNCS
  .screen_scale = 2
#endif
};

#if defined(SDLFUNCS) || defined(DOS)

int save_setup()
{
  int rc;
  FILE *fp;

  if(dontstop) return 0;

  fp = fopen("chess.set", "wb");
  if(!fp) return 1;

  if(fwrite(&setup, sizeof(setup), 1, fp) != 1)
    rc = 1;
  else
    rc = 0;

  return fclose(fp) | rc;
}

int setdeadend(void *);
void get_blunders(void);

int load_setup()
{
  int rc;
  FILE *fp = fopen("chess.set", "rb");
  if(!fp) return 1;

  if(fread(&setup, sizeof(setup), 1, fp) != 1)
    rc = 1;
  else
    rc = 0;

  fclose(fp);

  setdeadend(0);
  get_blunders();

  return rc;
}

#endif
