Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokes303 authored Sep 18, 2019
1 parent 34bd2dd commit 92d91eb
Show file tree
Hide file tree
Showing 13 changed files with 1,592 additions and 0 deletions.
139 changes: 139 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
DEVKITPRO=/opt/devkitpro
DEVKITPPC=/opt/devkitpro/devkitPPC
WUT_ROOT=/opt/devkitpro/wut

#-------------------------------------------------------------------------------
.SUFFIXES:
#-------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif

TOPDIR ?= $(CURDIR)

include $(DEVKITPRO)/wut/share/wut_rules

#-------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#-------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := src
DATA := data
INCLUDES := include

#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(MACHDEP)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__

CXXFLAGS := $(CFLAGS)

ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)

LIBS := -lwut

#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level
# containing include and lib
#-------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(WUT_ROOT)


#-------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#-------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#-------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#-------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#-------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#-------------------------------------------------------------------------------
export LD := $(CC)
#-------------------------------------------------------------------------------
else
#-------------------------------------------------------------------------------
export LD := $(CXX)
#-------------------------------------------------------------------------------
endif
#-------------------------------------------------------------------------------

export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

.PHONY: $(BUILD) clean all

#-------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#-------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).rpx $(TARGET).elf

#-------------------------------------------------------------------------------
else
.PHONY: all

DEPENDS := $(OFILES:.o=.d)

#-------------------------------------------------------------------------------
# main targets
#-------------------------------------------------------------------------------
all : $(OUTPUT).rpx

$(OUTPUT).rpx : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)

#-------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#-------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#-------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

-include $(DEPENDS)

#-------------------------------------------------------------------------------
endif
#-------------------------------------------------------------------------------
99 changes: 99 additions & 0 deletions src/file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "file.hpp"
#include "utils.hpp"

#include <coreinit/time.h>

uint8_t readUInt8(std::string file, uint32_t pos) {
FILE* fp = fopen((installDir + file).c_str(), "rb");
fseek(fp, pos, SEEK_SET);
uint8_t result = 0xFF;
fread(&result, 1, 1, fp);
fclose(fp);
return result;
}
uint16_t readUInt16(std::string file, uint32_t pos) {
FILE* fp = fopen((installDir + file).c_str(), "rb");
fseek(fp, pos, SEEK_SET);
uint16_t result = 0xFFFF;
fread(&result, 2, 1, fp);
fclose(fp);
return result;
}
uint32_t readUInt32(std::string file, uint32_t pos) {
FILE* fp = fopen((installDir + file).c_str(), "rb");
fseek(fp, pos, SEEK_SET);
uint32_t result = 0xFFFFFFFF;
fread(&result, 4, 1, fp);
fclose(fp);
return result;
}
uint64_t readUInt64(std::string file, uint32_t pos) {
FILE* fp = fopen((installDir + file).c_str(), "rb");
fseek(fp, pos, SEEK_SET);
uint64_t result = 0xFFFFFFFFFFFFFFFF;
fread(&result, 8, 1, fp);
fclose(fp);
return result;
}

void initRandom() {
srand(OSGetTime());
}
void writeVoidBytes(FILE* fp, uint32_t len) {
uint8_t bytes[len] = {0};
fwrite(bytes, len, 1, fp);
}
uint8_t charToByte(char c) {
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'A' && c <= 'F')
return c - 'A' + 0xA;
else if (c >= 'a' && c <= 'f')
return c - 'A' + 0xA;
return 0x77;
}
void writeCustomBytes(FILE* fp, std::string str) {
uint32_t len = str.size();
uint8_t bytes[len / 2] = {0};
for (uint32_t i = 0; i < len; i++) {
uint8_t b = charToByte(str[i]);
bytes[i / 2] += + ((i % 2 == 0) ? b * 0x10 : b);
}
fwrite(bytes, len / 2, 1, fp);
}
void writeRandomBytes(FILE* fp, uint32_t len) {
uint8_t bytes[len];
for (uint32_t i = 0; i < len; i++) {
bytes[i] = rand() % 0xFF;
}
fwrite(bytes, len, 1, fp);
}
//Ported from various sites
int makeDir(const char *path) {
if (!path)
return -1;

int res = mkdir(path, 777);
WHBLogPrintf("mkdir res: %d", res);
return res;
}
bool fileExists(const char *path) {
FILE *temp = fopen(path, "r");
if (temp == NULL)
return false;

fclose(temp);
return true;
}
bool dirExists(const char *path) {
WHBLogPrintf("f");
FSDirectoryHandle dh;

FSStatus fss = FSOpenDir(fsCli, fsCmd, path, &dh, 0);
WHBLogPrintf("fss: %u", fss);
if (fss == FS_STATUS_OK) {
FSCloseDir(fsCli, fsCmd, dh, 0);
return true;
}
return false;
}
16 changes: 16 additions & 0 deletions src/file.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "main.hpp"

uint8_t readUInt8(std::string file, uint32_t pos);
uint16_t readUInt16(std::string file, uint32_t pos);
uint32_t readUInt32(std::string file, uint32_t pos);
uint64_t readUInt64(std::string file, uint32_t pos);

void initRandom();
void writeVoidBytes(FILE* fp, uint32_t length);
uint8_t charToByte(char c);
void writeCustomBytes(FILE* fp, std::string str);
void writeRandomBytes(FILE* fp, uint32_t length);

int makeDir(const char *path);
bool fileExists(const char *path);
bool dirExists(const char *path);
Loading

0 comments on commit 92d91eb

Please sign in to comment.