From 86785bcd72807c97a3507e87c057ae7bf1d8273a Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Fri, 27 Aug 2021 20:12:35 -0400 Subject: [PATCH 1/2] Add Dockerfile and make it buildable as-is --- Makefile | 4 +- README.md | 59 +++++---------------------- docker/Dockerfile | 25 ++++++++++++ docker/setup-linux.sh | 94 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 52 deletions(-) create mode 100644 docker/Dockerfile create mode 100755 docker/setup-linux.sh diff --git a/Makefile b/Makefile index e2f00a6..8bc3004 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ OBJDIR = ./obj BINDIR = ./bin TOOLSDIR = ./tools -LINK_FLAGS = -O1 -L$(ROOTDIR)/lib -L$(ROOTDIR)/mips64-elf/lib -ldragon -lmad -lyaml -lc -lm -ldragonsys -lnosys $(LIBS) -Tn64.ld -PROG_NAME = OS64 +LINK_FLAGS = -O1 -L$(ROOTDIR)/lib -L$(ROOTDIR)/mips64-elf/lib -ldragon -lmad -lyaml -lc -lm -ldragonsys -lnosys $(LIBS) -Tn64ld.x +PROG_NAME = OS64P CFLAGS = -std=gnu99 -march=vr4300 -mtune=vr4300 -O1 -I$(INCDIR) -I$(ROOTDIR)/include -I$(ROOTDIR)/mips64-elf/include -lpthread -lrt -D_REENTRANT -DUSE_TRUETYPE $(SET_DEBUG) ASFLAGS = -mtune=vr4300 -march=vr4300 CC = $(GCCN64PREFIX)gcc diff --git a/README.md b/README.md index 122bbc3..496df30 100644 --- a/README.md +++ b/README.md @@ -2,76 +2,35 @@ Alternative Everdrive64 menu - -`Altra64` is an open source menu for [Everdrive64](http://krikzz.com/) and is based on a fork of alt64 which was +`Altra64` is an open source menu for [Everdrive64](http://krikzz.com/) and ed64+ and is based on a fork of alt64 which was originally written by saturnu, and released on the [Everdrive64 forum](http://krikzz.com/forum/index.php?topic=816.0). ## Building -If you want to build the menu, you need an n64 toolchain. When using windows 10 or Ubuntu, installation is totally automated through a script. +If you want to build the menu, you need an n64 toolchain. This is terrible to build, I ended up creating a Dockerfile in the docker folder, instructions included in it. -### Dependencies (installed automatically) -* Windows 10 (Aniversary Update or above) / Ubuntu 16.04 (or above) -* [libdragon](https://github.com/DragonMinded/libdragon) -* [libmikmod (with n64 driver)](https://github.com/networkfusion/libmikmod) -* [libmad-n64](https://github.com/networkfusion/libmad-n64) -* [libyaml](http://pyyaml.org/wiki/LibYAML) - -### Build the Toolchain - -*You may skip this step if it's already installed.* - -Clone this `Altra64` repo to a directory of your choice. - -On Windows 10: -* Ensure that ["Windows Subsystem For Linux (Ubuntu)"](https://msdn.microsoft.com/en-gb/commandline/wsl/install_guide) is installed. -* browse to the tools directory and double click on ```setup-wsfl.cmd```. - -On Ubuntu, browse to the tools directory and run the command ```$ chmod +x ./setup-linux.sh;source ./setup-linux.sh``` +Or if you trust me, you can use the one I built and pushed to docker hub, [moparisthebest/altra64-dev](https://hub.docker.com/r/moparisthebest/altra64-dev) ### Build `Altra64` To build the Rom -from the projects root directory, -On Windows 10 run +from the projects root directory, with docker installed ``` -> build +$ docker run --rm -v "$(pwd):/build" moparisthebest/altra64-dev make ``` -on linux -``` -$ make -``` -If it all worked, you will find `OS64.v64` in the `Altra64` bin directory. - -### Debug Build `Altra64` -To build the debug version of the Rom - -from the projects root directory, -On Windows 10 run -``` -> build debug -``` -on linux -``` -$ make debug -``` -If it all worked, you will find `OS64.v64` in the `Altra64` bin directory. +If it all worked, you will find `OS64.v64` in the `bin` directory. ### Clean `Altra64` + Finally, we can clean the build objects from the project -from the projects root directory, -On Windows 10 run +from the projects root directory ``` -> build clean -``` -on linux -``` -$ make clean +$ docker run --rm -v "$(pwd):/build" moparisthebest/altra64-dev make clean ``` Enjoy! diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..0c7f0ae --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,25 @@ + +# to build and test: +# docker build -t altra64-dev . && docker run --rm -v "$(pwd):/build" -it altra64-dev + +# to use to compile altra64 (or other n64 stuff I guess) +# docker run --rm -v "$(pwd):/build" altra64-dev make + +#FROM ubuntu:18.04 +FROM ubuntu:16.04 + +RUN mkdir /build + +COPY setup-linux.sh /usr/bin/setup-linux.sh + +# run it then delete all build artifacts +RUN /usr/bin/setup-linux.sh && rm -rf /root/* + +ENV N64_INST=/usr/local/libdragon +ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/libdragon/bin + +VOLUME [ "/build" ] + +WORKDIR /build + +CMD ["bash"] diff --git a/docker/setup-linux.sh b/docker/setup-linux.sh new file mode 100755 index 0000000..439acef --- /dev/null +++ b/docker/setup-linux.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# +# Copyright (c) 2017 The Altra64 project contributors +# See LICENSE file in the project root for full license information. +# + +set -euxo pipefail + +# Download and install latest updates for the system [sudo req.] +apt-get update +apt-get -y upgrade + +# Install essential packages [sudo req.] +apt-get -y install wget build-essential git texinfo libc6 libgmp-dev libmpfr-dev libmpc-dev libpng-dev zlib1g-dev libtool autoconf + +# change to the users root directory +cd ~/ + +# add a system variable and make it perminent +# echo 'N64_INST=/usr/local/libdragon' >> /etc/environment +# echo 'export N64_INST=/usr/local/libdragon' >> ~/.bashrc +export N64_INST=/usr/local/libdragon +# source ~/.bashrc + +# Pull the latest libdragon source code and make a build directory +git clone https://github.com/dragonminded/libdragon.git +# set to correct commit +cd libdragon && git checkout b26fce6 && cd .. + +# fix issues with the build scripts +sed -i -- 's|${N64_INST:-/usr/local}|/usr/local/libdragon|g' libdragon/tools/build +sed -i -- 's|--with-newlib|--with-newlib --with-system-zlib|g' libdragon/tools/build + +sed -i -- 's| -lpng|\nLDLIBS = -lpng|g' libdragon/tools/mksprite/Makefile +sed -i -- 's| -Werror| -w|g' libdragon/tools/mksprite/Makefile + +# make a build folder for libdragon +mkdir libdragon/build_gcc +cp libdragon/tools/build libdragon/build_gcc + +# run the build script (this will take a while! and if not sudo, will ask for password mid flow!) +cd libdragon/build_gcc +./build + +cd .. +# run the install script [sudo req] +make +make install +make tools +make tools-install + +cd .. +# install libmikmod (custom version) +git clone https://github.com/n64-tools/libmikmod +cd libmikmod/n64 +make +make install +cd .. # we have are in a subfolder, this is not a duplicate... + +cd .. +# install libyaml +git clone https://github.com/yaml/libyaml +cd libyaml +./bootstrap +#$(N64_INST) converterd to $N64_INST below otherwise it will not run on WSFL +export PATH=$PATH:$N64_INST/bin +CFLAGS="-std=gnu99 -march=vr4300 -mtune=vr4300" \ +LDFLAGS="-L$N64_INST/lib -Tn64ld.x" \ +LIBS="-ldragon -lc -ldragonsys -lnosys" \ +./configure --host=mips64-elf --prefix=$N64_INST +make +make install + +cd .. +# install libmad (custom version) +git clone https://github.com/n64-tools/libmad +cd libmad +export PATH=$PATH:$N64_INST/bin +CFLAGS="-std=gnu99 -march=vr4300 -mtune=vr4300" \ +LDFLAGS="-L$N64_INST/lib -Tn64ld.x" \ +LIBS="-ldragon -lc -ldragonsys -lnosys" \ +./configure --host=mips64-elf --prefix=$N64_INST +make +make install + +cd .. + +# Perform cleanup +apt-get -y autoremove +apt-get autoclean + +echo 'export N64_INST=/usr/local/libdragon' >> ~/.bashrc +echo 'export PATH="$PATH:$N64_INST/bin"' >> ~/.bashrc + From 3733e676f9e52632f1015a86a8e422e54fc18f22 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Fri, 27 Aug 2021 20:25:26 -0400 Subject: [PATCH 2/2] Implement numbered saves to avoid catastrophic save game loss --- README.md | 4 ++++ src/main.c | 61 +++++++++++++++++++++++++++++++++++++----------- src/menu_about.c | 1 + 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 496df30..7f9eeab 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ Alternative Everdrive64 menu originally written by saturnu, and released on the [Everdrive64 forum](http://krikzz.com/forum/index.php?topic=816.0). +## Reason for this fork + +The original version overwrote 1 save file per game on system reset, but if you (or your kids...) accidentally turn it off, or hit reset twice, you just lost your entire game progress forever. I have modified the saving/loading to *never* overwrite a save file, and instead save `gamename.0000.SRM`, then `gamename.0001.SRM` next and so on, up to `gamename.9999.SRM`, so that absolute worst case if you mess up you only lose 1 gaming session's save. If need be you can put the SD card into a computer and delete the latest faulty save. Upon starting a game it'll always load the highest numbered save. + ## Building If you want to build the menu, you need an n64 toolchain. This is terrible to build, I ended up creating a Dockerfile in the docker folder, instructions included in it. diff --git a/src/main.c b/src/main.c index b5e7cae..367dff7 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,6 @@ #include "cic.h" #define ED64PLUS -#define USE_TRUETYPE #ifdef ED64PLUS #define ED64_FIRMWARE_PATH "ED64P" @@ -1625,20 +1624,39 @@ int backupSaveData(display_context_t disp) int saveTypeFromSd(display_context_t disp, char *rom_name, int stype) { TRACE(disp, rom_filename); - TCHAR fname[256] = {0}; - sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%s", save_path, rom_name, saveTypeToExtension(stype, ext_type)); - TCHAR fname1[50] = {0}; - sprintf(fname1, "/"ED64_FIRMWARE_PATH"/%s/", save_path); - printText(fname1, 3, -1, disp); - TCHAR fname2[50] = {0}; - sprintf(fname2, "%s.%s", rom_name, saveTypeToExtension(stype, ext_type)); - printText(fname2, 3, -1, disp); + const char* save_type_extension = saveTypeToExtension(stype, ext_type); + TCHAR fname[256] = {0}; + int save_count = 0; //TODO: once this crosses 9999 bad infinite-loop type things happen, look into that one day + FRESULT result; + FILINFO fnoba; + printText("Finding latest save slot...", 3, -1, disp); + display_show(disp); + while (true) { + sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%04x.%s", save_path, rom_name, save_count, save_type_extension); + result = f_stat (fname, &fnoba); + if (result != FR_OK) { + // we found our first missing save slot, break + break; + } + ++save_count; + } + if (save_count > 0) { + // we've went 1 past the end, so back up + sprintf(fname, "Found latest save slot: %04x", --save_count); + printText(fname, 3, -1, disp); + sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%04x.%s", save_path, rom_name, save_count, save_type_extension); + } else { + // not even a 0000 was found, so look at the original name before numbering was implemented + printText("No save slot found!", 3, -1, disp); + printText("Looking for non-numbered file...", 3, -1, disp); + sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%s", save_path, rom_name, save_type_extension); + } + display_show(disp); int size = saveTypeToSize(stype); // int byte uint8_t cartsave_data[size]; - FRESULT result; FIL file; UINT bytesread; result = f_open(&file, fname, FA_READ); @@ -1709,14 +1727,30 @@ int saveTypeFromSd(display_context_t disp, char *rom_name, int stype) int saveTypeToSd(display_context_t disp, char *rom_name, int stype) { //after reset create new savefile + const char* save_type_extension = saveTypeToExtension(stype, ext_type); TCHAR fname[256]; //TODO: change filename buffers to 256!!! - - sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%s", save_path, rom_name, saveTypeToExtension(stype, ext_type)); + int save_count = 0; //TODO: once this crosses 9999 bad infinite-loop type things happen, look into that one day + FRESULT result; + FILINFO fnoba; + printText("Finding unused save slot...", 3, -1, disp); + display_show(disp); + while (true) { + sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%04x.%s", save_path, rom_name, save_count, save_type_extension); + result = f_stat (fname, &fnoba); + if (result != FR_OK) { + // we found our first missing save slot, break + break; + } + ++save_count; + } + sprintf(fname, "Found unused save slot: %04x", save_count); + printText(fname, 3, -1, disp); + display_show(disp); + sprintf(fname, "/"ED64_FIRMWARE_PATH"/%s/%s.%04x.%s", save_path, rom_name, save_count, save_type_extension); int size = saveTypeToSize(stype); // int byte TRACEF(disp, "size for save=%i", size); - FRESULT result; FIL file; UINT bytesread; result = f_open(&file, fname, FA_WRITE | FA_OPEN_ALWAYS); //Could use FA_CREATE_ALWAYS but this could lead to the posibility of the file being emptied @@ -1755,6 +1789,7 @@ int saveTypeToSd(display_context_t disp, char *rom_name, int stype) else { TRACE(disp, "COULDNT CREATE FILE :-("); + printText("Error saving game to SD, couldn't create file!", 3, -1, disp); } } diff --git a/src/menu_about.c b/src/menu_about.c index 0604336..33cc28e 100644 --- a/src/menu_about.c +++ b/src/menu_about.c @@ -29,4 +29,5 @@ void menu_about(display_context_t disp) printText("ChillyWilly", 9, -1, disp); printText("ShaunTaylor", 9, -1, disp); printText("Conle", 9, -1, disp); + printText("moparisthebest", 9, -1, disp); } //TODO: make scrolling text, should include libraries used.