From 803f707aebf2d13387b04b074f8a8b177b76fc06 Mon Sep 17 00:00:00 2001 From: Joey Dumont Date: Sat, 28 Jul 2018 19:12:31 -0400 Subject: [PATCH] GFX_PRINTF WORKS. --- GenerateHooks.py | 6 ++-- TODO.md | 3 ++ compile.sh | 41 ++++++++++++----------- debug_scripts/uss64_dl_debug.js | 16 +++++---- debug_scripts/uss64_dump_master_dl.js | 48 ++++++++++++++++++--------- gz | 2 +- patch/patch.sh | 4 +-- uss64.c | 15 +++++---- 8 files changed, 80 insertions(+), 55 deletions(-) diff --git a/GenerateHooks.py b/GenerateHooks.py index 0e87108..a880694 100644 --- a/GenerateHooks.py +++ b/GenerateHooks.py @@ -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. @@ -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() diff --git a/TODO.md b/TODO.md index 6d4c913..73e6942 100644 --- a/TODO.md +++ b/TODO.md @@ -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`. diff --git a/compile.sh b/compile.sh index b9c23e1..821bea0 100755 --- a/compile.sh +++ b/compile.sh @@ -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 . \ No newline at end of file diff --git a/debug_scripts/uss64_dl_debug.js b/debug_scripts/uss64_dl_debug.js index 8d01cc1..99f58de 100644 --- a/debug_scripts/uss64_dl_debug.js +++ b/debug_scripts/uss64_dl_debug.js @@ -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); } }) \ No newline at end of file diff --git a/debug_scripts/uss64_dump_master_dl.js b/debug_scripts/uss64_dump_master_dl.js index fdf2033..d9a1764 100644 --- a/debug_scripts/uss64_dump_master_dl.js +++ b/debug_scripts/uss64_dump_master_dl.js @@ -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) diff --git a/gz b/gz index cc7eb55..bbfd0f2 160000 --- a/gz +++ b/gz @@ -1 +1 @@ -Subproject commit cc7eb55db1ba1bbe5fbfdd17620cc3ff3c39ed7c +Subproject commit bbfd0f2f1dbddbd18a707d6700fd0847e7f6a858 diff --git a/patch/patch.sh b/patch/patch.sh index a9163bd..e1c8289 100755 --- a/patch/patch.sh +++ b/patch/patch.sh @@ -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 diff --git a/uss64.c b/uss64.c index 37bc3d1..11370b6 100644 --- a/uss64.c +++ b/uss64.c @@ -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; @@ -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(); } } @@ -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); @@ -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);