diff --git a/Makefile b/Makefile index c644800..c0d5f8a 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,16 @@ 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) @@ -12,6 +20,10 @@ $(EXECUTABLE): $(OBJECTS) .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} diff --git a/main.c b/main.c index 29312d8..8a053fb 100644 --- a/main.c +++ b/main.c @@ -10,10 +10,13 @@ #ifdef __APPLE__ #include -#endif -#ifdef _WIN32 +#else +#ifndef _WIN32 +#include +#else #include #endif +#endif #include "dispel.h" @@ -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) @@ -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