OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [dskchk2/] [genimg.c] - Blame information for rev 235

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 hellwig
/*
2
 * genimg.c -- generate test image
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <stdarg.h>
10
 
11
 
12
#define NUM_SECTORS     262144          /* sync with image checker */
13
#define SECTOR_SIZE     512
14
 
15
 
16
/**************************************************************/
17
 
18
 
19
void error(char *fmt, ...) {
20
  va_list ap;
21
 
22
  va_start(ap, fmt);
23
  printf("Error: ");
24
  vprintf(fmt, ap);
25
  printf("\n");
26
  va_end(ap);
27
  exit(1);
28
}
29
 
30
 
31
/**************************************************************/
32
 
33
 
34
static unsigned int randomState = 0;
35
 
36
 
37
void setRandomSeed(unsigned int seed) {
38
  randomState = seed;
39
}
40
 
41
 
42
unsigned int nextRandomNumber(void) {
43
  unsigned int retVal;
44
 
45
  retVal = randomState;
46
  randomState = randomState * 1103515245 + 12345;
47
  return retVal;
48
}
49
 
50
 
51
/**************************************************************/
52
 
53
 
54
static void usage(char *myself) {
55
  printf("Usage: %s <image file name>\n", myself);
56
  exit(1);
57
}
58
 
59
 
60
int main(int argc, char *argv[]) {
61
  char *imageFileName;
62
  FILE *imageFile;
63
  unsigned int sector;
64
  unsigned char buffer[SECTOR_SIZE];
65
  int i;
66
  unsigned int number;
67
 
68
  if (argc != 2) {
69
    usage(argv[0]);
70
  }
71
  imageFileName = argv[1];
72
  imageFile = fopen(imageFileName, "w");
73
  if (imageFile == NULL) {
74
    error("cannot open image file '%s'", imageFileName);
75
  }
76
  for (sector = 0; sector < NUM_SECTORS; sector++) {
77
    setRandomSeed(sector);
78
    for (i = 0; i < SECTOR_SIZE / 4; i++) {
79
      number = nextRandomNumber();
80
      buffer[4 * i + 0] = (number >> 24) & 0xFF;
81
      buffer[4 * i + 1] = (number >> 16) & 0xFF;
82
      buffer[4 * i + 2] = (number >>  8) & 0xFF;
83
      buffer[4 * i + 3] = (number >>  0) & 0xFF;
84
    }
85
    if (fwrite(buffer, 1, SECTOR_SIZE, imageFile) != SECTOR_SIZE) {
86
      error("cannot write image file '%s'", imageFileName);
87
    }
88
  }
89
  fclose(imageFile);
90
  return 0;
91
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.