#include const char *comments = "created by LC2_ram beta:\n" "-- for use with LC-2 model created by\n" "-- Eric Frohnhofer and Ron Feliciano\n"; const char *ram_header = "library IEEE;\n" "use IEEE.std_logic_1164.all;\n" "use IEEE.std_logic_unsigned.all;\n" "use IEEE.std_logic_arith.all;\n\n" "entity ram_module is\n" " port(clk : in std_logic;\n" " enable : in std_logic;\n" " R_W : in std_logic;\n" " addr : in std_logic_vector (15 downto 0);\n" " data_in : in std_logic_vector (15 downto 0);\n" " data_out : out std_logic_vector (15 downto 0));\n" "end ram_module;\n\n" "architecture BHV of ram_module is\n\n" "type memory is array (0 to 1000) of std_logic_vector(15 downto 0); \n\n" "signal reg : memory := (\n\n" " \"0100000100000000\",\n"; const char *trap_fill = " \"1111110100000000\",\n"; const char *trap_addresses = " \"0000010000000000\",\n" " \"0000010000110000\",\n" " \"0000010001010000\",\n" " \"0000010010100000\",\n" " \"0000010011100000\",\n" " \"1111110101110000\",\n"; const char *ram_end = " \"0000000000000000\"" ");\n\n" "begin\n" " process(clk, enable, R_W, addr)\n" " begin\n" " if (enable = '1') then\n" " if (clk = '1' and clk' event) then\n" " if (R_W = '1') then\n" " data_out <= reg(conv_integer(addr));\n" " else\n" " reg(conv_integer(addr)) <= data_in;\n" " end if;\n" " else \n" " end if;\n" " end if;\n\n" "end process;\n" "end BHV;"; int main(int argc, char * argv[]) { int count=0, i=0; char buffer[17]; FILE *input, *output; if (argc < 3) { fprintf(stderr, "Syntax Error: %s: INFILE OUTFILE\n", argv[0]); return -1; } //open the .bin file printf("Attempting to open .bin file...\n"); if((input = fopen(argv[1], "rt"))==0) { fprintf(stderr, "Error:Cannot open inputfile\n"); return -2; } printf("...%s sucessfully opened\n", argv[1]); //open .vhd file printf("Creating output file...\n"); if((output = fopen(argv[2], "w"))==0) { fprintf(stderr, "Error: Outfile allocation failed\n"); return -3; } printf("...%s sucessuflly created\n", argv[2]); printf("Now writting contents of %s...\n", argv[2]); //write ram header fprintf(output, "-- %s %s%s", argv[2], comments, ram_header); //fill in traps from 1 to 31 for (i = 0; i < 31; i++) { fprintf(output,"%s", trap_fill); } //fill in trap addresses fprintf(output, "%s", trap_addresses); //fill in the rest of the trap addresses for (i = 0; i < 218 ;i++) { fprintf(output,"%s", trap_fill); } //copy data from .bin fscanf(input, "%s", buffer); while(!feof(input)) { fscanf(input, "%s", buffer); fprintf(output," \"%s\",\n", buffer); count++; } //fill in exta lines for(i = 0;i < (1000 - count- 256);i++) { fprintf(output," \"0000000000000000\",\n"); } fprintf(output, "%s", ram_end); printf("...Writting contents of %s complete\n", argv[2]); return 1; }