diff options
author | oharboe <oharboe> | 2008-03-06 20:04:57 +0000 |
---|---|---|
committer | oharboe <oharboe> | 2008-03-06 20:04:57 +0000 |
commit | d2ee4c79d7b0abdfd70eaf2e46da54183a2caeaa (patch) | |
tree | ccf4b3c0871ed3de6d2ef1806affd34d7ed0b177 | |
parent | 78e84633f945692c966a933df42f06f0df988e44 (diff) | |
download | zpu-d2ee4c79d7b0abdfd70eaf2e46da54183a2caeaa.zip zpu-d2ee4c79d7b0abdfd70eaf2e46da54183a2caeaa.tar.gz |
* zpu/zpu/hdl/example/zpuromgen.c - generate rom files
without java
-rw-r--r-- | zpu/ChangeLog | 3 | ||||
-rw-r--r-- | zpu/hdl/example/zpuromgen.c | 59 |
2 files changed, 62 insertions, 0 deletions
diff --git a/zpu/ChangeLog b/zpu/ChangeLog index 1e5545b..7878ea1 100644 --- a/zpu/ChangeLog +++ b/zpu/ChangeLog @@ -1,3 +1,6 @@ +2008-03-06 Adam Pierce
+ * zpu/zpu/hdl/example/zpuromgen.c - generate rom files
+ without java
2008-02-21 Øyvind Harboe
* zpu/zpu/sw/index.html. Changed it a bit to make installation easier.
* zpu/zpu/hdl/index.html. Sharpened instructions and shows two working
diff --git a/zpu/hdl/example/zpuromgen.c b/zpu/hdl/example/zpuromgen.c new file mode 100644 index 0000000..fb8c4ba --- /dev/null +++ b/zpu/hdl/example/zpuromgen.c @@ -0,0 +1,59 @@ +// zpuromgen.c
+//
+// Program to turn a binary file into a VHDL lookup table.
+// by Adam Pierce
+// 29-Feb-2008
+//
+// This software is free to use by anyone for any purpose.
+//
+
+#include <unistd.h>
+#include <stdio.h>
+
+typedef uint8_t BYTE;
+
+main(int argc, char **argv)
+{
+ BYTE opcode[4];
+ int fd;
+ int addr = 0;
+ ssize_t s;
+
+// Check the user has given us an input file.
+ if(argc < 2)
+ {
+ printf("Usage: %s <binary_file>\n\n", argv[0]);
+ return 1;
+ }
+
+// Open the input file.
+ fd = open(argv[1], 0);
+ if(fd == -1)
+ {
+ perror("File Open");
+ return 2;
+ }
+
+ while(1)
+ {
+ // Read 32 bits.
+ s = read(fd, opcode, 4);
+ if(s == -1)
+ {
+ perror("File read");
+ return 3;
+ }
+
+ if(s == 0)
+ break; // End of file.
+
+ // Output to STDOUT.
+ printf("%6d => x\"%02x%02x%02x%02x\",\n",
+ addr++, opcode[0], opcode[1],
+ opcode[2], opcode[3]);
+ }
+
+ close(fd);
+ return 0;
+}
+
|