Skip to content

Commit

Permalink
Add Whatcookie's delta time patch. Fixes #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbed committed Jun 18, 2020
1 parent 48edf2d commit 443d7bd
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 15 deletions.
3 changes: 2 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ set "AS_FLAGS=-target ppc64-unknown-unknown -m64 -mllvm --x86-asm-syntax=intel"

"%AS%" %AS_FLAGS% -c source/debug_menu.S -o build/debug_menu.o
"%AS%" %AS_FLAGS% -c source/debug_menu_localize.S -o build/debug_menu_localize.o
"%AS%" %AS_FLAGS% -c source/delta_time.S -o build/delta_time.o
"%AS%" %AS_FLAGS% -c source/disable_system_cache.S -o build/disable_system_cache.o
"%AS%" %AS_FLAGS% -c source/increase_memory_zones.S -o build/increase_memory_zones.o
"%AS%" %AS_FLAGS% -c source/lua_print_to_stdout.S -o build/lua_print_to_stdout.o
"%AS%" %AS_FLAGS% -c source/redirect_fs.S -o build/redirect_fs.o
"%AS%" %AS_FLAGS% -c source/start.S -o build/start.o
"%AS%" %AS_FLAGS% -DMAKE_SYMBOLS -c source/symbols.S -o build/symbols.o

"%LLVM_PATH%\bin\ld.lld.exe" --script link.x --no-check-sections build/debug_menu.o build/debug_menu_localize.o build/disable_system_cache.o build/increase_memory_zones.o build/lua_print_to_stdout.o build/redirect_fs.o build/start.o build/symbols.o -o bin/debug_patch.elf
"%LLVM_PATH%\bin\ld.lld.exe" --script link.x --no-check-sections build/debug_menu.o build/debug_menu_localize.o build/delta_time.o build/disable_system_cache.o build/increase_memory_zones.o build/lua_print_to_stdout.o build/redirect_fs.o build/start.o build/symbols.o -o bin/debug_patch.elf

if not defined APPVEYOR (
tools\bin\PatchElf.exe bin\boot.elf bin\debug_patch.elf bin\debug.elf -v 83681f6110d33442329073b72b8dc88a2f677172 -a --dca=0x01842d48 --dcs=53944 --ocs=0x1832d48
Expand Down
22 changes: 12 additions & 10 deletions link.x
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ SECTIONS
{
.text0 { build/debug_menu.o(.text) } : code_seg
.text1 { build/debug_menu_localize.o(.text) } : code_seg
.text2 { build/disable_system_cache.o(.text) } : code_seg
.text3 { build/increase_memory_zones.o(.text) } : code_seg
.text4 { build/lua_print_to_stdout.o(.text) } : code_seg
.text5 { build/redirect_fs.o(.text) } : code_seg
.text6 { build/symbols.o(.text) } : code_seg
.text2 { build/delta_time.o(.text) } : code_seg
.text3 { build/disable_system_cache.o(.text) } : code_seg
.text4 { build/increase_memory_zones.o(.text) } : code_seg
.text5 { build/lua_print_to_stdout.o(.text) } : code_seg
.text6 { build/redirect_fs.o(.text) } : code_seg
.text7 { build/symbols.o(.text) } : code_seg
}

. = 0x01842D48;
Expand All @@ -20,11 +21,12 @@ SECTIONS
{
.data0 { build/debug_menu.o(.data) } : data_seg
.data1 { build/debug_menu_localize.o(.data) } : data_seg
.data2 { build/disable_system_cache.o(.data) } : data_seg
.data3 { build/increase_memory_zones.o(.data) } : data_seg
.data4 { build/lua_print_to_stdout.o(.data) } : data_seg
.data5 { build/redirect_fs.o(.data) } : data_seg
.data6 { build/symbols.o(.data) } : data_seg
.data2 { build/delta_time.o(.data) } : data_seg
.data3 { build/disable_system_cache.o(.data) } : data_seg
.data4 { build/increase_memory_zones.o(.data) } : data_seg
.data5 { build/lua_print_to_stdout.o(.data) } : data_seg
.data6 { build/redirect_fs.o(.data) } : data_seg
.data7 { build/symbols.o(.data) } : data_seg
}

.patch_list : { *(.patch_list) } : data_seg
Expand Down
63 changes: 63 additions & 0 deletions source/delta_time.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "helpers.inc.S"
#include "options.inc.S"
#include "symbols.S"

.set patch_section_index, 2

#ifdef DELTA_TIME

patch_text_start call_delta_time
bl my_delta_time
nop
nop
patch_text_end call_delta_time

patch_text_start initialize_flip_mode
stb %r0, 0x6ED(%r31)
patch_text_end initialize_flip_mode

cave_start my_delta_time
# get mftb
mftb %r21 // Move from timebase register (clock)

# get mftb delta
lis %r22, my_delta_time_previous@h
addi %r22, %r22, my_delta_time_previous@l
ld %r20, 0x0(%r22) // load previous frames mftb reading
std %r21, 0x0(%r22) // store this frames mftb reading
subf %r19, %r20, %r21 // subtract previous mftb reading from this mftb frames reading

# mftb delta to float
std %r19, 0x18(%r22) // store mftb delta (to be loaded into FPR)
lfd %f30, 0x18(%r22) // load mftb delta into FPR
fcfid %f30, %f30 // convert integer to double
frsp %f30, %f30 // round to single precision

# mftb delta to seconds
lis %r18, my_delta_time_constants@h
addi %r18, %r18, my_delta_time_constants@l
lfs %f29, 0x0(%r18) // load timebase frequency constant
lfs %f28, 0x4(%r18) // load maximum timestep size
fdivs %f31, %f30, %f29 // divide timebase delta by timebase frequency

# check timestep size
fcmpu %cr7, %f31, %f28 // compare current delta time to maximum timestep
blt %cr7, _skip_return_maximum_timestep // don't return the maximum timestep size

_return_maximum_timestep:
# set maximum timestep
fmr %f31, %f28 // move maximum timestep to be returned

_skip_return_maximum_timestep:
# cleanup
xor %r20, %r20, %r20 // zero r20
xor %r19, %r19, %r19 // zero r19
blr
cave_end my_delta_time

cave_start my_delta_time_constants
.float 80000000.0 # timebase frequency (80mhz)
.float 0.05000000 # maximum timestep size (50ms or 20FPS)
cave_end my_delta_time_constants

#endif
2 changes: 1 addition & 1 deletion source/disable_system_cache.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "options.inc.S"
#include "symbols.S"

.set patch_section_index, 2
.set patch_section_index, 3

#ifdef DISABLE_SYSTEM_CACHE

Expand Down
2 changes: 1 addition & 1 deletion source/increase_memory_zones.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "options.inc.S"
#include "symbols.S"

.set patch_section_index, 3
.set patch_section_index, 4

#ifdef INCREASE_MEMORY_ZONES

Expand Down
2 changes: 1 addition & 1 deletion source/lua_print_to_stdout.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "options.inc.S"
#include "symbols.S"

.set patch_section_index, 4
.set patch_section_index, 5

#ifdef LUA_PRINT_TO_STDOUT

Expand Down
4 changes: 4 additions & 0 deletions source/options.inc.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
# Make lua's print() output to stdout
#define LUA_PRINT_TO_STDOUT

# Enable Whatcookie's delta time patch.
# This is probably BAD(!) on a real PS3.
#define DELTA_TIME

#endif
2 changes: 1 addition & 1 deletion source/redirect_fs.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "helpers.inc.S"
#include "options.inc.S"

.set patch_section_index, 5
.set patch_section_index, 6

#ifdef REDIRECT_FS

Expand Down
3 changes: 3 additions & 0 deletions source/symbols_BLUS30443.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

target_text get_debug_menu_root, 0x00015328
target_text create_debug_menu, 0x00015A58
target_text call_delta_time, 0x0001B95C
target_text call_render_debug_menu, 0x0001BB38
target_text call_create_debug_menu, 0x00020F44
target_text get_hg_man_instance, 0x00023878
target_text initialize_flip_mode, 0x00025ED8
target_text allocate_memory_debug_1, 0x0003A1FC
target_text allocate_memory_debug_2, 0x0003A244
target_text allocate_memory_debug_3, 0x0003A2B0
Expand Down Expand Up @@ -41,4 +43,5 @@ target_rdata title_sce_server_label, 0x016C7CF0

# .data

target_data my_delta_time_previous, 0x01852608 # padding re-used for delta time patch
target_data lua_print_pointer, 0x0196E568

0 comments on commit 443d7bd

Please sign in to comment.