Skip to content

Commit

Permalink
Test of simple gfx hello_world using glank's gz.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeydumont committed Feb 17, 2018
1 parent 124b07a commit 3d855e8
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 6 deletions.
58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# --------------------------------------------------------------------------- #
# Author: Joey Dumont <[email protected]> #
# Date: 2018-01-15 #
# Description: CMake compilation instructions for the SM64 practice ROM. #
# License: CC0 - Public Domain #
# ----------------------------------------------------------------------------#

# ----------------------------------------------------------------- #
# -- Name and version of library -- #
# ----------------------------------------------------------------- #
set(uss64)
set (USSR64_VERSION_MAJOR 0)
set (USSR64_VERSION_MINOR 0)
set (USSR64_VERSION_RELEASE 0)

# ----------------------------------------------------------------- #
# -- Configuration and Dependencies -- #
# ----------------------------------------------------------------- #
# -- Default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

# -- CMake version and installation directory.
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX /opt/n64)
endif()

# -- Include CMake modules of this package.
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")

# ----------------------------------------------------------------- #
# -- Compiler Configuration -- #
# ----------------------------------------------------------------- #
set (CMAKE_C_FLAGS_RELEASE "-G 0 -O2 -Wall -mtune=vr4300 -march=vr4300 -mabi=32")
set (CMAKE_CXX_FLAGS_RELEASE "-G 0 -O2 -Wall -mtune=vr4300 -march=vr4300 -mabi=32")

add_definitions(-DZ64_VERSION=Z64_OOT10)

# ----------------------------------------------------------------- #
# -- Compilation Instructions -- #
# ----------------------------------------------------------------- #
# -- Included files.
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(/opt/n64-dev/n64-sysroot/include)

# -- Create object.
add_library(uss64 OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/hello_world.c)

# ----------------------------------------------------------------- #
# -- Installation Instructions -- #
# ----------------------------------------------------------------- #

# -- Output binaries in directory
set (CMAKE_OBJECTS_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
install (TARGETS uss64 OBJECTS DESTINATION bin)
11 changes: 11 additions & 0 deletions Toolchain-mips64-linux-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------- #
# Author: Joey Dumont <[email protected]> #
# Date: 2018-02-14 #
# Description: Toolchain file for MIPS64 on Linux. #
# License: CC0 - Public Domain #
# ----------------------------------------------------------------------------#

set (CMAKE_SYSTEM_NAME Generic)
set (CMAKE_SYSTEM_PROCESSOR mips64)

set (CMAKE_C_COMPILER mips64-gcc)
44 changes: 44 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# --------------------------------------------------------------------------- #
# Author: Joey Dumont <[email protected]> #
# Date: 2018-02-14 #
# Description: Simple build script. #
# License: CC0 - Public Domain #
# ----------------------------------------------------------------------------#

# Check the number of arguments.
if [ $# -gt 2 ]; then
printf "Usage is\n"
printf "\tbash build.sh release/debug [toolchain-file]\n"
exit 1
fi

# Change to file directory.
cd "$(dirname "$(readlink -f "$0")")";

# Check if build/ dir exists.
if [ ! -d build ]; then
mkdir build
else
rm -rf build
mkdir build
fi

# Change to build dir and compile the library.
cd build
CMAKE_FLAGS=
CMAKE_TOOLCHAIN_FILE=
if [ $# -gt 0 ]; then
if [ $1 == release ]; then
CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_BUILD_TYPE=Release"
elif [ $1 == debug ]; then
CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_BUILD_TYPE=Debug"
fi
fi

if [ $# -gt 1 ]; then
CMAKE_TOOLCHAIN_FILE=$1
else
CMAKE_TOOLCHAIN_FILE=../Toolchain-mips64-linux-x86_64.cmake
fi

cmake ${CMAKE_FLAGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} ..
13 changes: 12 additions & 1 deletion compile.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
cd $(dirname $(readlink -f $0))
mips64-gcc -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c -I /opt/n64-dev/n64-sysroot/include hello_world.c -o hello_world.o
grc gz/res/gz/fipps.png -d gz/res/resources.json -o fipps.png.o
mips64-gcc -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c /opt/n64-dev/n64-sysroot/include/grc.c -o grc.o
mips64-gcc -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c /opt/n64-dev/n64-sysroot/include/vector/vector.c -o vector.o
mips64-gcc -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c /opt/n64-dev/n64-sysroot/include/startup.c -o startup.o
mips64-gcc -DZ64_VERSION=Z64_OOT10 -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c -I /opt/n64-dev/n64-sysroot/include hello_world.c -o hello_world.o
mips64-gcc -DZ64_VERSION=Z64_OOT10 -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c -I /opt/n64-dev/n64-sysroot/include gz/src/gz/resource.c -o resource.o
mips64-gcc -DZ64_VERSION=Z64_OOT10 -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c -I /opt/n64-dev/n64-sysroot/include gz/src/gz/gfx.c -o gfx.o
mips64-gcc -DZ64_VERSION=Z64_OOT10 -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c -I /opt/n64-dev/n64-sysroot/include gz/src/gz/gu.c -o gu.o
mips64-gcc -DZ64_VERSION=Z64_OOT10 -G 0 -Wall -O2 -mtune=vr4300 -march=vr4300 -mabi=32 -c -I /opt/n64-dev/n64-sysroot/include gz/src/gz/zu.c -o zu.o
mips64-g++ -T /opt/n64-dev/n64-sysroot/lib/gl-n64.ld -nostartfiles -specs=nosys.specs -O3 -flto -Wl,--gc-sections -Wl,--defsym,start=0x80400000 \
hello_world.o resource.o gfx.o gu.o grc.o zu.o vector.o startup.o -o uss64.o
mips64-objcopy -O binary uss64.elf uss64.bin
30 changes: 28 additions & 2 deletions hello_world.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
#include <stddef.h>
#include <n64.h>
#include <startup.h>
#include "gz/src/gz/z64.h"
#include "gz/src/gz/resource.h"
#include "gz/src/gz/gfx.h"

extern void PrintXY(unsigned int x, unsigned int y, const char *str);
static const char HelloString[] = "- hello n64 -";
static unsigned int x = 32;
static unsigned int y = 32;
static _Bool _ready = 0;

void MainHook(void)
static struct gfx_font *font;

// Try to write Hello World using native GFx.
ENTRY void _start(void)
{
if (!_ready)
{
/* initialize gfx */
{
gfx_start();
gfx_mode_configure(GFX_MODE_FILTER, G_TF_POINT);
gfx_mode_configure(GFX_MODE_COMBINE, G_CC_MODE(G_CC_MODULATEIA_PRIM,
G_CC_MODULATEIA_PRIM));
}

font = resource_get(RES_FONT_FIPPS);
_ready = 1;
}

gfx_mode_init();
gfx_printf(font, x, y, HelloString);


// Lives back to normal position
//PrintXY(0x36, 0xD1, (void*)0x80338388, *(int16_t*)0x8033B260);

// Print hello world
PrintXY(x, y, HelloString);
//PrintXY(x, y, HelloString);
}
4 changes: 2 additions & 2 deletions patch/hook.asm
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ jal LoadNewCodeInExpRam

// Replace unused Mario behaviour with the our payload, executed at each frame.
.orga behaviourHook
.dw MainHook
.dw 0x80400000

// Import the payload at the end of the ROM.
.orga romPadding
.headersize 0
NewCodeRomStart:
.headersize 0x80400000 - orga()
NewCodeVaddrStart:
.importobj "../hello_world.o"
.incbin "../uss64.bin"
.headersize 0
NewCodeRomEnd:

Expand Down

0 comments on commit 3d855e8

Please sign in to comment.