diff --git a/AtlasCore.cpp b/AtlasCore.cpp index 6a2d025..ce5eacd 100644 --- a/AtlasCore.cpp +++ b/AtlasCore.cpp @@ -4,7 +4,7 @@ //----------------------------------------------------------------------------- #include "stdafx.h" -#include +#include #include #include #include @@ -170,7 +170,7 @@ void AtlasCore::PrintStatistics() char buf[127]; for (ListStatsIt i = Stats.Stats.begin(); i != Stats.Stats.end(); i++) { - _snprintf(buf, 127, "Block %d", blocknum); + snprintf(buf, 127, "Block %d", blocknum); PrintStatisticsBlock(buf, *i); blocknum++; } diff --git a/AtlasCore.h b/AtlasCore.h index a391e11..285cb69 100644 --- a/AtlasCore.h +++ b/AtlasCore.h @@ -70,7 +70,7 @@ extern int MaxEmbPtr; extern AtlasCore Atlas; // Misc functions -inline unsigned int StringToUInt(std::string& NumberString); +unsigned int StringToUInt(std::string& NumberString); __int64 StringToInt64(std::string& NumberString); unsigned int GetHexDigit(char digit); unsigned int EndianSwap(unsigned int Num, int Size); \ No newline at end of file diff --git a/AtlasExtension.cpp b/AtlasExtension.cpp index 093a66c..9018629 100644 --- a/AtlasExtension.cpp +++ b/AtlasExtension.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -#include -#include +#include +#include #include "AtlasExtension.h" #include "AtlasLogger.h" #include "AtlasCore.h" @@ -87,12 +87,12 @@ AtlasExtension::AtlasExtension() : Extension(NULL) AtlasExtension::~AtlasExtension() { if(Extension) - FreeLibrary(Extension); + dlclose(Extension); } bool AtlasExtension::LoadExtension(string& ExtensionName) { - Extension = LoadLibraryA(ExtensionName.c_str()); + Extension = dlopen(ExtensionName.c_str(), RTLD_LAZY); if(Extension) return true; @@ -113,7 +113,7 @@ ExtensionFunction AtlasExtension::GetFunction(string& FunctionName) if(NULL == Extension) return NULL; - ExtensionFunction func = (ExtensionFunction)GetProcAddress(Extension, FunctionName.c_str()); + ExtensionFunction func = (ExtensionFunction)dlsym(Extension, FunctionName.c_str()); return func; } \ No newline at end of file diff --git a/AtlasExtension.h b/AtlasExtension.h index cd2f82a..b3635d5 100644 --- a/AtlasExtension.h +++ b/AtlasExtension.h @@ -1,7 +1,6 @@ #pragma once -#include +#include #include -#include #include "Table.h" #include "GenericVariable.h" @@ -49,5 +48,5 @@ class AtlasExtension ExtensionFunction GetFunction(std::string& FunctionName); private: - HMODULE Extension; + void *Extension; }; \ No newline at end of file diff --git a/AtlasFile.cpp b/AtlasFile.cpp index ad81e68..d42b649 100644 --- a/AtlasFile.cpp +++ b/AtlasFile.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include -#include +#include #include "AtlasFile.h" #include "Table.h" #include "AtlasLogger.h" @@ -540,32 +540,34 @@ inline unsigned int AtlasFile::WritePascalString(string& text) // Truncate string if it overflows ROM bounds if (PascalLength > maxwrite) // PascalLength doesn't even fit - goto nowrite; - if (maxwrite < size + PascalLength) // PascalLength and maybe partial string fits + return size + PascalLength; + else { - int overflowbytes = (size + PascalLength) - maxwrite; - TotalBytesSkipped += overflowbytes; - size = maxwrite - PascalLength; - } + if (maxwrite < size + PascalLength) // PascalLength and maybe partial string fits + { + int overflowbytes = (size + PascalLength) - maxwrite; + TotalBytesSkipped += overflowbytes; + size = maxwrite - PascalLength; + } - // Truncate string if it's too long for a fixed length string - if (size > StringLength && StringLength != 0) - { - TotalBytesSkipped += (size - StringLength); - size = StringLength - PascalLength; - printf("Changed string length for %s to %d at %X\n", text.c_str(), StringLength, GetPosT()); - } + // Truncate string if it's too long for a fixed length string + if (size > StringLength && StringLength != 0) + { + TotalBytesSkipped += (size - StringLength); + size = StringLength - PascalLength; + printf("Changed string length for %s to %d at %X\n", text.c_str(), StringLength, GetPosT()); + } - int swaplen = size; - if (bSwap) - swaplen = EndianSwap(size, PascalLength); + int swaplen = size; + if (bSwap) + swaplen = EndianSwap(size, PascalLength); - fwrite(&swaplen, PascalLength, 1, tfile); - fwrite(text.c_str(), 1, size, tfile); - BytesInserted += size + PascalLength; + fwrite(&swaplen, PascalLength, 1, tfile); + fwrite(text.c_str(), 1, size, tfile); + BytesInserted += size + PascalLength; -nowrite: - return size + PascalLength; + return size + PascalLength; + } } inline void AtlasFile::AlignString() @@ -585,7 +587,7 @@ inline void AtlasFile::AlignString() } } -inline unsigned int AtlasFile::GetMaxWritableBytes() +unsigned int AtlasFile::GetMaxWritableBytes() { if (MaxScriptPos == -1) return -1; diff --git a/AtlasFile.h b/AtlasFile.h index 2649fe8..dea1cda 100644 --- a/AtlasFile.h +++ b/AtlasFile.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include #include #include "Table.h" @@ -53,7 +53,7 @@ class AtlasFile bool InsertText(string& Text, unsigned int Line); bool FlushText(); - inline unsigned int GetMaxWritableBytes(); + unsigned int GetMaxWritableBytes(); FILE* GetFileT(); FILE* GetFileP(); void GetScriptBuf(list& Strings); diff --git a/AtlasLogger.cpp b/AtlasLogger.cpp index f55c40e..bf85276 100644 --- a/AtlasLogger.cpp +++ b/AtlasLogger.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include -#include +#include #include #include #include "AtlasLogger.h" @@ -30,7 +30,7 @@ void AtlasLogger::ReportError(unsigned int ScriptLine, const char* FormatStr ... va_list arglist; va_start(arglist, FormatStr); - int length = _vsnprintf(buf, BufSize, FormatStr, arglist); + int length = vsnprintf(buf, BufSize, FormatStr, arglist); va_end(arglist); Error.Error = buf; @@ -46,7 +46,7 @@ void AtlasLogger::ReportWarning(unsigned int ScriptLine, const char* FormatStr . va_list arglist; va_start(arglist, FormatStr); - int length = _vsnprintf(buf, BufSize, FormatStr, arglist); + int length = vsnprintf(buf, BufSize, FormatStr, arglist); va_end(arglist); Error.Error.assign(buf, length); diff --git a/AtlasLogger.h b/AtlasLogger.h index bdc12e2..9d6dd50 100644 --- a/AtlasLogger.h +++ b/AtlasLogger.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include enum ErrorSeverity { FATALERROR = 0, WARNING }; diff --git a/AtlasMain.cpp b/AtlasMain.cpp index 4135622..862b650 100644 --- a/AtlasMain.cpp +++ b/AtlasMain.cpp @@ -2,14 +2,14 @@ #include "stdafx.h" #include -#include +#include #include -#include +#include #include "AtlasCore.h" using namespace std; -int _tmain(int argc, _TCHAR* argv[]) +int main(int argc, char* argv[]) { clock_t StartTime, EndTime, ElapsedTime; int argoff = 0; diff --git a/AtlasParser.cpp b/AtlasParser.cpp index 47c08e1..aaa2fea 100644 --- a/AtlasParser.cpp +++ b/AtlasParser.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include -#include +#include #include #include #include diff --git a/AtlasParser.h b/AtlasParser.h index 44c1acb..0167e6e 100644 --- a/AtlasParser.h +++ b/AtlasParser.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include "AtlasTypes.h" diff --git a/AtlasStats.cpp b/AtlasStats.cpp index 21ddc2f..af5adb9 100644 --- a/AtlasStats.cpp +++ b/AtlasStats.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include #include -#include +#include #include "AtlasTypes.h" #include "AtlasLogger.h" #include "AtlasStats.h" diff --git a/AtlasStats.h b/AtlasStats.h index 18a2be4..e7c0943 100644 --- a/AtlasStats.h +++ b/AtlasStats.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include "AtlasTypes.h" using namespace std; diff --git a/AtlasTypes.h b/AtlasTypes.h index 18b5057..197a5ca 100644 --- a/AtlasTypes.h +++ b/AtlasTypes.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include /* Misc Functions */ static const unsigned int CMD_JMP1 = 0; diff --git a/GenericVariable.cpp b/GenericVariable.cpp index 59088b8..ab2d7d5 100644 --- a/GenericVariable.cpp +++ b/GenericVariable.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include +#include #include #include #include "GenericVariable.h" diff --git a/GenericVariable.h b/GenericVariable.h index f907af9..4301e16 100644 --- a/GenericVariable.h +++ b/GenericVariable.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include #include "AtlasTypes.h" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..90fb81b --- /dev/null +++ b/Makefile @@ -0,0 +1,71 @@ +SRCDIR = . +EXES = atlas + +### atlas sources and settings + +ATLAS_MODULE = atlas +ATLAS_CXX_SRCS = AtlasCore.cpp \ + AtlasExtension.cpp \ + AtlasFile.cpp \ + AtlasLogger.cpp \ + AtlasMain.cpp \ + AtlasParser.cpp \ + AtlasStats.cpp \ + AtlasTypes.cpp \ + GenericVariable.cpp \ + Pointer.cpp \ + PointerHandler.cpp \ + Table.cpp + +ATLAS_LIBRARIES = dl \ + ncurses + +ATLAS_OBJS = $(ATLAS_CXX_SRCS:.cpp=.o) + +### Global source lists + +CXX_SRCS = $(ATLAS_CXX_SRCS) + +### Tools + +CXX = g++ + +### Generic targets + +all: $(EXES) + +### Build rules + +.PHONY: all clean dummy + +$(SUBDIRS): dummy + @cd $@ && $(MAKE) + +# Implicit rules + +.SUFFIXES: .cpp +DEFINCL = $(INCLUDE_PATH) $(DEFINES) $(OPTIONS) + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(CXXEXTRA) $(DEFINCL) -o $@ $< + +# Rules for cleaning + +CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \ + \\\#*\\\# *~ *% .\\\#* + +clean:: + $(RM) $(CLEAN_FILES) $(CXX_SRCS:.cpp=.o) + $(RM) $(LIBS) $(EXES) + +$(SUBDIRS:%=%/__clean__): dummy + cd `dirname $@` && $(MAKE) clean + +$(EXTRASUBDIRS:%=%/__clean__): dummy + -cd `dirname $@` && $(RM) $(CLEAN_FILES) + +### Target specific build rules +$(ATLAS_MODULE): $(ATLAS_OBJS) + $(CXX) $(ATLAS_LDFLAGS) -o $@ $(ATLAS_OBJS) $(ATLAS_LIBRARIES:%=-l%) + + diff --git a/Pointer.cpp b/Pointer.cpp index 2d947c2..6cb520c 100644 --- a/Pointer.cpp +++ b/Pointer.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include +#include #include "Pointer.h" #include "AtlasLogger.h" diff --git a/Pointer.h b/Pointer.h index 671c51e..b404a6a 100644 --- a/Pointer.h +++ b/Pointer.h @@ -23,15 +23,15 @@ class Pointer void SetHeaderSize(const unsigned int Size); // Pointer writing functions - unsigned short Pointer::Get16BitPointer(const unsigned int ScriptPos) const; - unsigned int Pointer::Get24BitPointer(const unsigned int ScriptPos) const; - unsigned int Pointer::Get32BitPointer(const unsigned int ScriptPos) const; - - unsigned char Pointer::GetLowByte(const unsigned int ScriptPos) const; - unsigned char Pointer::GetHighByte(const unsigned int ScriptPos) const; - unsigned char Pointer::GetBankByte(const unsigned int ScriptPos) const; - unsigned char Pointer::GetUpperByte(const unsigned int ScriptPos) const; - unsigned int Pointer::GetHighWord(const unsigned int ScriptPos) const; + unsigned short Get16BitPointer(const unsigned int ScriptPos) const; + unsigned int Get24BitPointer(const unsigned int ScriptPos) const; + unsigned int Get32BitPointer(const unsigned int ScriptPos) const; + + unsigned char GetLowByte(const unsigned int ScriptPos) const; + unsigned char GetHighByte(const unsigned int ScriptPos) const; + unsigned char GetBankByte(const unsigned int ScriptPos) const; + unsigned char GetUpperByte(const unsigned int ScriptPos) const; + unsigned int GetHighWord(const unsigned int ScriptPos) const; protected: unsigned int AddressType; diff --git a/PointerHandler.cpp b/PointerHandler.cpp index d955394..7d9ef33 100644 --- a/PointerHandler.cpp +++ b/PointerHandler.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include -#include +#include #include "PointerHandler.h" #include "Pointer.h" #include "AtlasLogger.h" diff --git a/PointerHandler.h b/PointerHandler.h index 82fa6d0..048161e 100644 --- a/PointerHandler.h +++ b/PointerHandler.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include "Pointer.h" #include "GenericVariable.h" diff --git a/Table.cpp b/Table.cpp index 4707872..11d03cc 100644 --- a/Table.cpp +++ b/Table.cpp @@ -5,7 +5,7 @@ //----------------------------------------------------------------------------- #include "stdafx.h" -#include +#include #include #include #include diff --git a/Table.h b/Table.h index 41037ee..eb925da 100644 --- a/Table.h +++ b/Table.h @@ -12,7 +12,7 @@ #define SPACE 0x20 #include "stdafx.h" -#include +#include #include #include #include diff --git a/stdafx.h b/stdafx.h index 090c6d5..c827515 100644 --- a/stdafx.h +++ b/stdafx.h @@ -6,8 +6,8 @@ #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#define __int64 long long #include -#include // TODO: reference additional headers your program requires here #include