Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Linux support. #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@ CFLAGS=-Wall -O2
LDFLAGS=
SOURCES=main.c 65816.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=dispel.exe

CAN_INSTALL = no
ifeq ($(OS),Windows_NT)
EXECUTABLE = dispel.exe
else
EXECUTABLE = dispel
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CAN_INSTALL = yes
endif
endif
all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.c.o:
$(CC) -c $(CFLAGS) $< -o $@

install:
cp -v $(EXECUTABLE) /usr/local/bin
#FIXME It ALWAYS copies dispel to /usr/bin, regardless of OS
uninstall:
rm -rf /usr/local/bin/$(EXECUTABLE)
clean:
rm *.o ${EXECUTABLE}
22 changes: 13 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@

#ifdef __APPLE__
#include <sys/uio.h>
#endif
#ifdef _WIN32
#else
#ifndef _WIN32
#include <sys/io.h>
#else
#include <io.h>
#endif
#endif

#include "dispel.h"

Expand Down Expand Up @@ -276,20 +279,16 @@ int main(int argc, char *argv[])
}

// Read the file into memory
#ifndef _WIN32
fseek(fin, 0L, SEEK_END);
#if !defined(_WIN32)
fseek(fin, 0L, SEEK_END); //Apple and linux code
len = ftell(fin);
fseek(fin, 0L, SEEK_SET);
#else
len = filelength(fileno(fin));
len = filelength(fileno(fin)); //Windows code
#endif

// Make sure the image is big enough

if (len < 0x8000 || (skip == 1 && len < 0x8200))
{
printf("This file looks too small to be a legitimate rom image.\n");
}

// Allocate mem for file. Extra 3 bytes to prevent segfault during memcpy
if ((data = malloc(len+3)) == NULL)
Expand Down Expand Up @@ -323,6 +322,11 @@ int main(int argc, char *argv[])
hirom = 0;
}
}
if ((!hirom&&(len < 0x8000 || (skip == 1 && len < 0x8200)))||(hirom&&(len < 0x10000 || (skip == 1 && len < 0x10200)))) //Check if ROM is big enough for current mapping
{
printf("This file looks too small to be a rom image.\n");
exit(1);
}

// Unmangle the address options

Expand Down