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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [tools/] [chrgen/] [mkinit.c] - Blame information for rev 244

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

Line No. Rev Author Line
1 41 hellwig
/*
2
 * mkinit.c -- generate Verilog defparam statements from C data
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
 
11
#define LO_FILE_NAME    "chrgenlo.init"
12
#define HI_FILE_NAME    "chrgenhi.init"
13
 
14
 
15
unsigned char data[] = {
16
  #include "font-8x16"
17
};
18
 
19
 
20
unsigned char reflect(unsigned char c) {
21
  unsigned char r;
22
  int i;
23
 
24
  r = 0;
25
  for (i = 0; i < 8; i++) {
26
    r <<= 1;
27
    if (c & 1) {
28
      r |= 1;
29
    }
30
    c >>= 1;
31
  }
32
  return r;
33
}
34
 
35
 
36
int main(void) {
37
  FILE *outFile;
38
  int i, j;
39
  unsigned char b[32];
40
 
41
  if (sizeof(data) != 256 * 16) {
42
    printf("Error: wrong size of data\n");
43
    exit(1);
44
  }
45
  outFile = fopen(LO_FILE_NAME, "w");
46
  if (outFile == NULL) {
47
    printf("Error: cannot open file '%s'\n", LO_FILE_NAME);
48
    exit(1);
49
  }
50
  for (i = 0; i < 64; i++) {
51
    fprintf(outFile, "  defparam character_rom_lo.INIT_%02X = 256'h", i);
52
    for (j = 0; j < 32; j++) {
53
      b[j] = data[i * 32 + j + 0 * 16];
54
    }
55
    for (j = 31; j >= 0; j--) {
56
      fprintf(outFile, "%02X", reflect(b[j]));
57
    }
58
    fprintf(outFile, ";\n");
59
  }
60
  fclose(outFile);
61
  outFile = fopen(HI_FILE_NAME, "w");
62
  if (outFile == NULL) {
63
    printf("Error: cannot open file '%s'\n", HI_FILE_NAME);
64
    exit(1);
65
  }
66
  for (i = 0; i < 64; i++) {
67
    fprintf(outFile, "  defparam character_rom_hi.INIT_%02X = 256'h", i);
68
    for (j = 0; j < 32; j++) {
69
      b[j] = data[i * 32 + j + 128 * 16];
70
    }
71
    for (j = 31; j >= 0; j--) {
72
      fprintf(outFile, "%02X", reflect(b[j]));
73
    }
74
    fprintf(outFile, ";\n");
75
  }
76
  fclose(outFile);
77
  return 0;
78
}

powered by: WebSVN 2.1.0

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