Skip to content

Commit

Permalink
GFX_PRINTF WORKS.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeydumont committed Jul 28, 2018
1 parent ac3b475 commit 803f707
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 55 deletions.
6 changes: 4 additions & 2 deletions GenerateHooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
args = parser.parse_args()

# -- Names of the functions which we want to hook into SM64.
hooks = ["_start", "display_hook", "gfx_flush", "uss64_ready", "gfx_disp"]
HookNames = ["USS64_Start", "USS64_DisplayAddr", "USS64_gfx_flush", "USS64_Ready", "USS64_gfx_disp"]
hooks = ["_start", "display_hook", "gfx_flush", "uss64_ready", "gfx_disp", "gfx_disp_w"]
HookNames = ["USS64_Start", "USS64_DisplayAddr", "USS64_gfx_flush", "USS64_Ready", "USS64_gfx_disp", "USS64_gfx_disp_w"]
addrs = []

# -- Use nm to output the symbol table of uss64.
Expand Down Expand Up @@ -96,6 +96,8 @@
addrs = addrs+addrs_to_replace
HooksDict = dict(zip(names,addrs))

print(HooksDict)

# -- Populate the armips script with the proper addresses.
with open("patch/hook.asm", 'r') as armips_script:
armips_lines = armips_script.readlines()
Expand Down
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Development:
- Check the textures that SM64 understands (fipps is ia4, for instance).
- Write a sane build pipeline (Makefile).
- Generate patches in different formats (xdelta, bps, ...).
- Finish Fast3D support in `gbi.h`:
- [X] `G_MW_FORCEMTX` and related macros.
- [X] Fix `g{,s}SPMatrix`.
Expand Down
41 changes: 21 additions & 20 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
cd $(dirname $(readlink -f $0))
BIN_ROOT=/opt/n64/bin/
OBJ_DIR=obj/
#BIN_ROOT=/opt/n64-dev/usr/bin
#BIN_ROOT=/usr/bin/
N64_SYSROOT=/opt/n64/mips64/n64-sysroot/usr
#N64_SYSROOT=/opt/n64-dev/mips64/n64-sysroot/usr
CFLAGS='-std=gnu11 -Wall -O1 -mtune=vr4300 -march=vr4300 -mabi=32 -DF3D_GBI -DSM64_U'
CFLAGS='-std=gnu11 -Wall -ffunction-sections -fdata-sections -DF3D_GBI -DSM64_U '
CFLAGS+='-O3 -flto -ffat-lto-objects'
#CFLAGS+='-Og -g'
CROSS=mips64-
$BIN_ROOT/grc -d gz/res/resources.json gz/res/gz/fipps.png -o fipps.png.o
$BIN_ROOT/${CROSS}gcc $CFLAGS -c ${N64_SYSROOT}/include/grc.c -o grc.o
$BIN_ROOT/${CROSS}gcc $CFLAGS -c ${N64_SYSROOT}/include/vector/vector.c -o vector.o
$BIN_ROOT/${CROSS}gcc $CFLAGS -c ${N64_SYSROOT}/include/startup.c -o startup.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include uss64.c -o uss64.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include sm64.c -o sm64.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/resource.c -o resource.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/gfx.c -o gfx.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/gu.c -o gu.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/zu.c -o zu.o
$BIN_ROOT/grc -d gz/res/resources.json gz/res/gz/fipps.png -o ${OBJ_DIR}/fipps.png.o
$BIN_ROOT/${CROSS}gcc $CFLAGS -c ${N64_SYSROOT}/include/grc.c -o ${OBJ_DIR}/grc.o
$BIN_ROOT/${CROSS}gcc $CFLAGS -c ${N64_SYSROOT}/include/vector/vector.c -o ${OBJ_DIR}/vector.o
$BIN_ROOT/${CROSS}gcc $CFLAGS -c ${N64_SYSROOT}/include/startup.c -o ${OBJ_DIR}/startup.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include uss64.c -o ${OBJ_DIR}/uss64.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include sm64.c -o ${OBJ_DIR}/sm64.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/resource.c -o ${OBJ_DIR}/resource.o
$BIN_ROOT/${CROSS}gcc -Wa,-adhln -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/gfx.c -o ${OBJ_DIR}/gfx.o > ${OBJ_DIR}/gfx.s
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/gu.c -o ${OBJ_DIR}/gu.o
$BIN_ROOT/${CROSS}gcc -DZ64_VERSION=Z64_OOT10 $CFLAGS -c -I ${N64_SYSROOT}/include gz/src/gz/zu.c -o ${OBJ_DIR}/zu.o

cd ${OBJ_DIR}
LDFLAGS='-O3 -flto -nostartfiles -specs=nosys.specs -Wl,--defsym,start=0x80400000 -Wl,--gc-sections '
$BIN_ROOT/${CROSS}g++ \
-T ${N64_SYSROOT}/lib/gl-n64.ld \
-nostartfiles \
-specs=nosys.specs \
-O3 \
-Wall \
-mtune=vr4300 -march=4300 \
-Wl,--defsym,start=0x80400000 \
-mabi=32 \
uss64.o sm64.o resource.o gfx.o gu.o grc.o zu.o vector.o startup.o \
-T ${N64_SYSROOT}/lib/gl-n64.ld ${LDFLAGS} \
uss64.o sm64.o resource.o gfx.o gu.o grc.o zu.o vector.o startup.o fipps.png.o \
-o uss64.elf
$BIN_ROOT/${CROSS}objcopy -O binary uss64.elf uss64.bin
cd ../
cp ${OBJ_DIR}/uss64.bin .
16 changes: 9 additions & 7 deletions debug_scripts/uss64_dl_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ events.onexec({USS64_gfx_flush}, function()
if (mem.u32[{USS64_Ready}] == 0x01000000)
{
debug.breakhere();
var addr = mem.u32[{USS64_gfx_disp}]
var dl_hi,dl_lo;
do {
dl_hi = mem.u32[addr];
dl_lo = mem.u32[addr+4];
console.log(dl_hi.hex(), dl_lo.hex());
}
console.log('gfx_disp addr: {USS64_gfx_disp}');
console.log('gfx_disp_w addr: {USS64_gfx_disp_w}');
//var addr = mem.u32[{USS64_gfx_disp}]
//var dl_hi,dl_lo;
//do {
// dl_hi = mem.u32[addr];
// dl_lo = mem.u32[addr+4];
// console.log(dl_hi.hex(), dl_lo.hex());
//}
while (dl_hi != 0xB8000000);
}
})
48 changes: 32 additions & 16 deletions debug_scripts/uss64_dump_master_dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,50 @@ const UCODE_F3DEX2 = 0xC901CEF3; // from BT

const G_MW_SEGMENT = 6;

counter = 0;

// janky, probably not the correct place to hook
var evtdraw = events.ondraw(function()
{
if(mem.u32[RSP_COMMAND_ADDR] != RSP_DISPLAYLIST_CMD)
if (mem.u32[{USS64_Ready}] == 0x01000000)
{
return;
counter = counter + 1
}
if (mem.u32[{USS64_Ready}] == 0x01000000 && counter > 2)
{

if(mem.u32[RSP_COMMAND_ADDR] != RSP_DISPLAYLIST_CMD)
{
return;
}

events.remove(evtdraw);
events.remove(evtdraw);

var dlistAddr = mem.u32[RSP_DISPLAYLIST_ADDR];
var dlistSize = mem.u32[RSP_DISPLAYLIST_SIZE];
var ucodeEngineAddr = mem.u32[RSP_UCODE_ENGINE_ADDR];
var dlistAddr = mem.u32[RSP_DISPLAYLIST_ADDR];
var dlistSize = mem.u32[RSP_DISPLAYLIST_SIZE];
var ucodeEngineAddr = mem.u32[RSP_UCODE_ENGINE_ADDR];

var decoder = new Decoder();
var decoder = new Decoder();

decoder.setMicrocode(ucodeEngineAddr);
decoder.setDisplayList(dlistAddr, dlistSize);
decoder.run();
decoder.setMicrocode(ucodeEngineAddr);
decoder.setDisplayList(dlistAddr, dlistSize);
decoder.run();

var romname = rom.getstring(0x20).trim();
var romname = rom.getstring(0x20).trim();

var path = 'dldump-' + romname + '.txt';
var path = 'dldump-' + romname + '.txt';

var fd = fs.open(path, 'wb');
fs.write(fd, decoder.result);
fs.close(fd);
console.log('wrote result to ' + path);
var fd = fs.open(path, 'wb');
fs.write(fd, decoder.result);
fs.close(fd);
console.log('wrote result to ' + path);

debug.breakhere();
}
else
{
return;
}
});

function Decoder(dlistAddr)
Expand Down
4 changes: 2 additions & 2 deletions patch/patch.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
bash ../compile.sh
python ../GenerateHooks.py uss64.elf U
python ../GenerateHooks.py obj/uss64.elf U
armips hook_U.asm
n64cksum SM64-PracRom-asm.z64
cp ../debug_scripts_out/uss64* /c/Users/Joey/Downloads/pj64d-snapshot-5/Project64d/Scripts
cp ../debug_scripts_out/uss64* /c/Users/Joey/Documents/VGs/Emulation/Project64d/Scripts
15 changes: 8 additions & 7 deletions uss64.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static unsigned int y = 32;
static struct gfx_font *font;

// gfx_printf variables
static const char USS64String[] = " hello from uss64 ";
static const char USS64String[] = "hello from uss64";
static int master_dlist_addr;
static Gfx* master_dlist_ptr;

Expand All @@ -38,12 +38,12 @@ HOOK static void display_hook(void)
if (uss64_ready)
{
// Branch off the tail of the master DL.
PrintXY(x,y, HelloString);
gfx_flush();
//PrintXY(x,y, HelloString);

// Try to manually write the DL
gDPSetFillColor(SM64_gDisplayListHead++, GPACK_RGBA5551(255,0,0,1) << 16 | GPACK_RGBA5551(255,0,0,1));
gDPFillRectangle(SM64_gDisplayListHead++, 0, 0, 10, 10);
gfx_flush();

}
}
Expand All @@ -52,8 +52,8 @@ HOOK static void main_hook(void)
{
// Try to print with `gfx.c`.
gfx_mode_init();
gfx_printf(font, 20, 20, USS64String);
PrintXY(x,2*y,"Hello from main_hook");
gfx_printf(font, 40, 20, "hello world");
//PrintXY(x,2*y,"Hello from main_hook");

// // Get the address of the master dlist.
// master_dlist_addr = GetSegmentBase(0x01);
Expand All @@ -74,8 +74,9 @@ HOOK static void init(void)
{
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));
gfx_mode_configure(GFX_MODE_COMBINE, G_CC_MODE(G_CC_TEXEL0ONLY,
G_CC_TEXEL0ONLY));
gfx_mode_configure(GFX_MODE_TEXT, GFX_TEXT_FAST);
}

font = resource_get(RES_FONT_FIPPS);
Expand Down

0 comments on commit 803f707

Please sign in to comment.