News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: PSP / PPSSPP Modifying Code at Runtime - Is it a bad idea?  (Read 714 times)

flame

  • Full Member
  • ***
  • Posts: 120
    • View Profile
PSP / PPSSPP Modifying Code at Runtime - Is it a bad idea?
« on: February 03, 2018, 10:39:16 am »
PPSSPP has a setting called dynarec, dynamic recompiler, and it gets a lot of its fast emulation speed from that.

dynarec on is the default. You can turn it off. The only way I know how to get to settings when the game is running is by pushing the PS button or Xbox button on your controller, you can also get there from the PPSSPP screen when no game is loaded. From there it's System -> Developer Tools -> Dynarec (JIT).

I am working on Ao no Kiseki and to solve a certain problem my strategy was to write code that changes existing game code - a function parameter coded by an li instruction. But with Dynarec on, PPSSPP will never see it. A real PSP just runs whatever code is there so it will work fine; PPSSPP reads the code when the game boots and never again after that when dynarec is on. With it off, PPSSPP works like a PSP does.

So is it a good idea to replace that hard coded function parameter with an lw instruction? If I do that, it will work even with dynarec on.

Gemini

  • Hero Member
  • *****
  • Posts: 1990
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: PSP / PPSSPP Modifying Code at Runtime - Is it a bad idea?
« Reply #1 on: February 03, 2018, 11:21:39 am »
Woudln't automodifying code need a cache flush before execution? I believe such case would be emulated correctly even on dynarec.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

flame

  • Full Member
  • ***
  • Posts: 120
    • View Profile
Re: PSP / PPSSPP Modifying Code at Runtime - Is it a bad idea?
« Reply #2 on: February 03, 2018, 11:52:43 am »
I saw sceKernelDcacheWritebackAll syscall. The game calls it once every frame already. I don't know how else to flush the cache.

With dynarec off it does work; with it on it doesn't.

As an additional test I changed those li instructions to lw's and it did work even with dynarec on.