Skip to content

Commit

Permalink
g++ compilation fixes and makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorp committed Oct 13, 2018
1 parent e6ef7a3 commit 9e7467a
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 65 deletions.
4 changes: 2 additions & 2 deletions AtlasCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//-----------------------------------------------------------------------------

#include "stdafx.h"
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
Expand Down Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion AtlasCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 5 additions & 5 deletions AtlasExtension.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include <string>
#include <windows.h>
#include <cstring>
#include <dlfcn.h>
#include "AtlasExtension.h"
#include "AtlasLogger.h"
#include "AtlasCore.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
5 changes: 2 additions & 3 deletions AtlasExtension.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <cstring>
#include <list>
#include <windows.h>
#include "Table.h"
#include "GenericVariable.h"

Expand Down Expand Up @@ -49,5 +48,5 @@ class AtlasExtension
ExtensionFunction GetFunction(std::string& FunctionName);

private:
HMODULE Extension;
void *Extension;
};
48 changes: 25 additions & 23 deletions AtlasFile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include <cstdio>
#include <string>
#include <cstring>
#include "AtlasFile.h"
#include "Table.h"
#include "AtlasLogger.h"
Expand Down Expand Up @@ -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()
Expand All @@ -585,7 +587,7 @@ inline void AtlasFile::AlignString()
}
}

inline unsigned int AtlasFile::GetMaxWritableBytes()
unsigned int AtlasFile::GetMaxWritableBytes()
{
if (MaxScriptPos == -1)
return -1;
Expand Down
4 changes: 2 additions & 2 deletions AtlasFile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <iterator>
#include "Table.h"
Expand Down Expand Up @@ -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<TBL_STRING>& Strings);
Expand Down
6 changes: 3 additions & 3 deletions AtlasLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include <cstdio>
#include <string>
#include <cstring>
#include <list>
#include <cstdarg>
#include "AtlasLogger.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion AtlasLogger.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <cstring>
#include <list>

enum ErrorSeverity { FATALERROR = 0, WARNING };
Expand Down
6 changes: 3 additions & 3 deletions AtlasMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include "stdafx.h"
#include <ctime>
#include <string>
#include <cstring>
#include <vector>
#include <conio.h>
#include <curses.h>
#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;
Expand Down
2 changes: 1 addition & 1 deletion AtlasParser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include <map>
#include <string>
#include <cstring>
#include <list>
#include <fstream>
#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion AtlasParser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <cstring>
#include <map>
#include <fstream>
#include "AtlasTypes.h"
Expand Down
2 changes: 1 addition & 1 deletion AtlasStats.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stdafx.h"
#include <list>
#include <cstdlib>
#include <string>
#include <cstring>
#include "AtlasTypes.h"
#include "AtlasLogger.h"
#include "AtlasStats.h"
Expand Down
2 changes: 1 addition & 1 deletion AtlasStats.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <list>
#include <string>
#include <cstring>
#include "AtlasTypes.h"

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion AtlasTypes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <map>
#include <string>
#include <cstring>

/* Misc Functions */
static const unsigned int CMD_JMP1 = 0;
Expand Down
2 changes: 1 addition & 1 deletion GenericVariable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stdafx.h"
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include "GenericVariable.h"
Expand Down
2 changes: 1 addition & 1 deletion GenericVariable.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include "AtlasTypes.h"

Expand Down
71 changes: 71 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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%)


2 changes: 1 addition & 1 deletion Pointer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stdafx.h"
#include <string>
#include <cstring>
#include "Pointer.h"
#include "AtlasLogger.h"

Expand Down
18 changes: 9 additions & 9 deletions Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PointerHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include <fstream>
#include <string>
#include <cstring>
#include "PointerHandler.h"
#include "Pointer.h"
#include "AtlasLogger.h"
Expand Down
2 changes: 1 addition & 1 deletion PointerHandler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <list>
#include <string>
#include <cstring>
#include "Pointer.h"
#include "GenericVariable.h"

Expand Down
Loading

0 comments on commit 9e7467a

Please sign in to comment.