浏览代码

* Fixed PACKEDness of the stuct to work on gcc and MSVC
* Fixed the Makefile to actually work when rebuilding
* Fixed an index error that created invalid output

Matthew Iselin 13 年之前
父节点
当前提交
78af57b1a6
共有 3 个文件被更改,包括 22 次插入9 次删除
  1. 1 1
      Makefile
  2. 8 5
      src/tibasic.cpp
  3. 13 3
      src/tibasic.h

+ 1 - 1
Makefile

@@ -12,7 +12,7 @@ CXX := g++
 all: tibasic
 
 tibasic: $(OBJFILES)
-	g++ -o tibasic $?
+	g++ -o tibasic $(OBJFILES)
 
 -include $(DEPFILES)
 

+ 8 - 5
src/tibasic.cpp

@@ -46,7 +46,7 @@ size_t Compiler::sumBytes(const char *data, size_t len)
 bool Compiler::compile(string inFile, string outFile)
 {
     ifstream f(inFile.c_str(), ifstream::in);
-    
+
     string tmpLine;
 
     // Output information ready for writing the compiled code to a file.
@@ -115,15 +115,15 @@ bool Compiler::compile(string inFile, string outFile)
     memset(&phdr, 0, sizeof(ProgramHeader));
     memset(&ventry, 0, sizeof(VariableEntry));
 
-    phdr.extsig[0] = 0x1A; phdr.extsig[1] = 0x0A; phdr.extsig[1] = 0;
     phdr.datalen = sizeof(VariableEntry) + outputSize;
     strcpy(phdr.sig, "**TI83F*");
+    phdr.extsig[0] = 0x1A; phdr.extsig[1] = 0x0A; phdr.extsig[2] = 0;
 
     /// \todo Magic numbers!
     ventry.start = 0x0D;
     ventry.length1 = ventry.length2 = outputSize;
     ventry.type = 0x05;
-    
+
     // Convoluted magic to get the filename. Minus the extension. :)
     size_t i = 0;
     size_t n = outFile.find_last_of('/');
@@ -139,8 +139,11 @@ bool Compiler::compile(string inFile, string outFile)
     // Begin writing to file.
     FILE *out = fopen(outFile.c_str(), "wb");
     fwrite(&phdr, sizeof(phdr), 1, out);
+    cout << "file is at " << ftell(out) << endl;
     fwrite(&ventry, sizeof(ventry), 1, out);
+    cout << "file is at " << ftell(out) << endl;
     fwrite(&outputSize, 2, 1, out);
+    cout << "file is at " << ftell(out) << endl;
 
     // Sum of all bytes for checksum purposes.
     size_t sum = 0;
@@ -188,7 +191,7 @@ bool Compiler::decompile(string inFile, string outFile)
 
     size_t nBytesRead = 0;
     unsigned short temp;
-    
+
     string sOutput = "";
 
     bool bAsmProgram = false;
@@ -244,7 +247,7 @@ bool Compiler::decompile(string inFile, string outFile)
     }
 
     fclose(fp);
-    
+
     // Write the output now.
     ofstream f(outFile.c_str());
     f << sOutput;

+ 13 - 3
src/tibasic.h

@@ -19,6 +19,12 @@
 
 #include <string>
 
+#ifdef _MSC_VER
+#define PACKED
+#else
+#define PACKED __attribute__((packed))
+#endif
+
 /// Stores a token to be written and the size of that token.
 typedef struct
 {
@@ -89,8 +95,10 @@ class Compiler
         size_t sumBytes(const char *data, size_t len);
         unsigned char doChecksum(size_t sum);
 
+#ifdef _MSC_VER
 #pragma pack(push, 1)
-        
+#endif
+
         /// 8xp file header
         struct ProgramHeader
         {
@@ -98,7 +106,7 @@ class Compiler
             char extsig[3];
             char comment[42];
             unsigned short datalen;
-        };
+        } PACKED;
 
         /// Variable entry
         struct VariableEntry
@@ -110,9 +118,11 @@ class Compiler
             char ver;
             char flags;
             unsigned short length2;
-        };
+        } PACKED;
 
+#ifdef _MSC_VER
 #pragma pack(pop)
+#endif
 };
 
 #endif