P
PyBoy•7d ago
MorganPG

How can I access PyBoy.mb from within a subclass.

This has probably been asked before but I wanted to try to get local link support working in PyBoy I felt it would be easier to modify if I made it a subclass of PyBoy. Here is a small snippet of my code:
class LinkBoy(PyBoy, LinkDevice):
def RecievedFullByte(self):
self.memory[0xFF02] = clearBit(self.memory[0xFF02], 7)
self.mb.cpu.set_interruptflag(0b00001000)
class LinkBoy(PyBoy, LinkDevice):
def RecievedFullByte(self):
self.memory[0xFF02] = clearBit(self.memory[0xFF02], 7)
self.mb.cpu.set_interruptflag(0b00001000)
When data is transmitted I get this error:
Traceback (most recent call last):
File "e:\LinkBoy\main.py", line 9, in <module>
link.step()
File "e:\LinkBoy\linkboy.py", line 75, in step
transfer.step()
File "e:\LinkBoy\linkboy.py", line 56, in step
self.slave.RecievedFullByte() #Notify the slave device the transfer has completed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\LinkBoy\linkboy.py", line 109, in RecievedFullByte
self.mb.cpu.set_interruptflag(0b00001000)
^^^^^^^
AttributeError: 'LinkBoy' object has no attribute 'mb'
Traceback (most recent call last):
File "e:\LinkBoy\main.py", line 9, in <module>
link.step()
File "e:\LinkBoy\linkboy.py", line 75, in step
transfer.step()
File "e:\LinkBoy\linkboy.py", line 56, in step
self.slave.RecievedFullByte() #Notify the slave device the transfer has completed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\LinkBoy\linkboy.py", line 109, in RecievedFullByte
self.mb.cpu.set_interruptflag(0b00001000)
^^^^^^^
AttributeError: 'LinkBoy' object has no attribute 'mb'
Is there any way to get around this withot directly modifying the library, or do i have to do that?
13 Replies
Sky
Sky•7d ago
The mb Motherboard is only exposed to cython, you can't access it without editing pyboy's source code. If you want to expose it to python, you need to add public before the mb declaration, inside pyboy .pxd file, then compile
MorganPG
MorganPGOP•7d ago
oh alright then ill go try that
Sky
Sky•7d ago
Maybe you need to do the same for cpu, I don't think set_interruptflag is a public method
MorganPG
MorganPGOP•7d ago
thanks for helping even if i cant figure it out, also ive never used cython so how do you compile it?
Sky
Sky•7d ago
Download pyboy source from git Cd to the directory, then just run pip install .
MorganPG
MorganPGOP•7d ago
oh alright, i was over thinking it
MorganPG
MorganPGOP•7d ago
so this, and then for cpu
No description
Sky
Sky•7d ago
Yes
MorganPG
MorganPGOP•7d ago
thanks!
MorganPG
MorganPGOP•7d ago
ive probably done it wrong im getting this now, i might of added public to the wrong place in cpu.pxd
No description
MorganPG
MorganPGOP•7d ago
i set it here
No description
MorganPG
MorganPGOP•7d ago
ill uninstall and rebuild it just incase i had the old version cached nope same issue wait i think im an idiot, i found smth on stack overflow apparently i should use cpdef so im gonna try that i fixed it, so for future reference you need to make a wrapper for the function in cpu.py
def set_interrupt_flag(self, value: int):
self.set_interruptflag(value)
def set_interrupt_flag(self, value: int):
self.set_interruptflag(value)
i added this, and it worked
Sky
Sky•6d ago
Yes, cpdef exposes a method to python, while cdef doesn't. I forgot to mention that 😅

Did you find this page helpful?