1 /* convert_roms.c: convert pro350.rom and id.rom to C files, for compilation
2 
3    Copyright (c) 1997-2006, Tarik Isani (xhomer@isani.org)
4 
5    This file is part of Xhomer.
6 
7    Xhomer is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License version 2
9    as published by the Free Software Foundation.
10 
11    Xhomer is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Xhomer; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 
21 
22 #include <stdio.h>
23 
main()24 void main()
25 {
26 FILE		*fptr1, *fptr2;
27 unsigned char	h, l;
28 int		i, j;
29 unsigned short	memval;
30 
31 
32 	printf("Converting pro350.rom to pro350.h\n");
33 
34 	/* Load boot/diagnostic ROM */
35 
36 	fptr1 = fopen("pro350.rom","r");
37 
38 	if (fptr1 == NULL)
39 	{
40 	  printf("Unable to open pro350.rom for reading\n");
41 	  exit(0);
42 	}
43 
44 	fptr2 = fopen("pro350.h","w");
45 
46 	if (fptr2 == NULL)
47 	{
48 	  printf("Unable to open pro350.h for writing\n");
49 	  exit(0);
50 	}
51 
52 	fprintf(fptr2, "/* pro350.h: PRO 350 boot ROM */\n\n");
53 
54 	fprintf(fptr2, "unsigned short ROM[8192] =\n");
55 	fprintf(fptr2, "  {\n");
56 
57 	for(i=0 ; i<1024; i++)
58 	{
59 	  fprintf(fptr2, "   ");
60 	  for(j=0 ; j<8; j++)
61 	  {
62 	    l = getc(fptr1);
63 	    h = getc(fptr1);
64 	    memval = h*256+l;
65 	    fprintf(fptr2, " 0x%04x", memval);
66 	    if ((i != 1023) || (j != 7))
67 	      fprintf(fptr2, ",");
68 	  }
69 	  fprintf(fptr2, "\n");
70 	}
71 
72 	fprintf(fptr2, "  };\n");
73 
74 	fclose(fptr2);
75 	fclose(fptr1);
76 
77 
78 	printf("Converting id.rom to id.h\n");
79 
80 	/* Load ID ROM */
81 
82 	fptr1 = fopen("id.rom","r");
83 
84 	if (fptr1 == NULL)
85 	{
86 	  printf("Unable to open id.rom for reading\n");
87 	  exit(0);
88 	}
89 
90 	fptr2 = fopen("id.h","w");
91 
92 	if (fptr2 == NULL)
93 	{
94 	  printf("Unable to open id.h for writing\n");
95 	  exit(0);
96 	}
97 
98 	fprintf(fptr2, "/* id.h: PRO 350 ID ROM */\n\n");
99 
100 	fprintf(fptr2, "unsigned short IDROM[32] =\n");
101 	fprintf(fptr2, "  {\n");
102 
103 	for(i=0 ; i<4; i++)
104 	{
105 	  fprintf(fptr2, "   ");
106 	  for(j=0 ; j<8; j++)
107 	  {
108 	    l = getc(fptr1);
109 	    h = getc(fptr1);
110 	    memval = h*256+l;
111 	    fprintf(fptr2, " 0x%04x", memval);
112 	    if ((i != 3) || (j != 7))
113 	      fprintf(fptr2, ",");
114 	  }
115 	  fprintf(fptr2, "\n");
116 	}
117 
118 	fprintf(fptr2, "  };\n");
119 
120 	fclose(fptr2);
121 	fclose(fptr1);
122 }
123