summaryrefslogtreecommitdiff
path: root/bin2c.cpp
diff options
context:
space:
mode:
authorpixel <pixel>2004-05-02 12:29:02 +0000
committerpixel <pixel>2004-05-02 12:29:02 +0000
commitb0ecd395ad3f7ae5d782713dd610a056b1b33c31 (patch)
tree8e3641d1721a12540170301f84697050b9fad425 /bin2c.cpp
parent6fe28e64b960b2a58ef0cff94898f6958467927c (diff)
Added a built-in cd-tool.lua feature.
Diffstat (limited to 'bin2c.cpp')
-rw-r--r--bin2c.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/bin2c.cpp b/bin2c.cpp
new file mode 100644
index 0000000..69561a1
--- /dev/null
+++ b/bin2c.cpp
@@ -0,0 +1,40 @@
+#include <Input.h>
+#include <Output.h>
+#include <Main.h>
+
+CODE_BEGINS
+virtual int startup() throw (GeneralException) {
+ int i;
+
+ if (argc != 4) {
+ printm(M_BARE, "Usage: %s <bin file> <c file> <symbol>\n", argv[0]);
+ exit(-1);
+ }
+
+ printm(M_BARE, "Starting converting %s to %s:\n", argv[1], argv[2]);
+
+ Input binfile(argv[1]);
+ Output cfile(argv[2]);
+
+ unsigned char * map = (unsigned char *) binfile.mmap();
+
+ cfile << "int " << argv[3] << "_size = " << binfile.GetSize() << ";\n";
+ cfile << "unsigned char " << argv[3] << "[] = {";
+
+ for (i = 0; i < binfile.GetSize(); i++) {
+ String s;
+
+ s.set("0x%02x, ", map[i]);
+ if (!(i % 16)) {
+ cfile << "\n\t";
+ printm(M_BARE, "%5.2f%%\r", i * 100.0 / binfile.GetSize());
+ }
+ cfile << s;
+ }
+
+ cfile << "\n};\n";
+ printm(M_BARE, "Done! \n");
+
+ return 0;
+}
+CODE_ENDS