JesseTG / libretro.py

A Python binding for libretro. Intended for writing test scripts for cores, but can be used for any purpose.
MIT License
8 stars 3 forks source link

Incomplete memory returned by ```core.get_memory(RETRO_MEMORY_SYSTEM_RAM)``` #22

Open mode80 opened 1 day ago

mode80 commented 1 day ago

This is a super impressive project and I've been excited to try to use it as light-weight binding to access previously installed libretro cores to train ML agents via Reinforcement Learning. (Other options for this purpose require heavy dependencies and complicated build scripts which don't work consistently across different platforms.)

I'm currently blocked in this effort due to libretro.py's core.get_memory() method which is for some reason surfacing an incomplete version of the FBNeo core's memory. What I get back from from that core's RETRO_MEMORY_SYSTEM_RAM is almost entirely zeroes with patches of real data in there but not including what I need to fetch.

This is true even if I point libretro.py to the dylib for a FBNeo core known to work for this purpose. It works to use the aforementioned heavy frameworks to access memory I need with the very same dylib, so I'm wondering if it's some issue with libretro.py.

My code below receives a value of 0 when it should be something else. Printing out the full memory for debugging reveals that it's almost all "...00 00 00..." which can't be right.

    def _get_lives(self):
        """ Retrieve the current number of lives from the emulator's memory.  """
        memory = self.session.core.get_memory(RETRO_MEMORY_SYSTEM_RAM)
        if memory is None:
            return 0
        lives = memory[self.P1_LIVES_ADDR] 
        return lives

full code here

Kind of a shot in the dark, but I bring it up here in case something jumps out at you as worth checking. Would really love to make use of this if you have any ideas.

JesseTG commented 1 day ago

Glad you're able to get some practical use out of this (ticket notwithstanding)!

The odd part is that the memoryview returned by Core.get_memory doesn't make a copy; changes that the core itself makes should be reflected in the memoryview.

Let's try to narrow it down:

mode80 commented 1 day ago

All good leads! Will investigate.

JesseTG commented 18 hours ago

Oh, and since this is for FBNeo...does the issue also occur if playing a game with completely different emulated hardware?