Exemplo n.º 1
0
def get_ram():
    """
    Returns the RAM in bytes.
    """
    ram_array = jarray.zeros(Gb.RAM_SIZE, "i")
    Gb.getRAM(ram_array)
    return RomList(ram_array)
def shutdown():
    """
    Stops the emulator. Closes the window.

    The "opposite" of this is the load_rom function.
    """
    Gb.shutdown()
def set_memory(memory):
    """
    Sets memory in the emulator.

    Use get_memory() to retrieve the current state.
    """
    Gb.writeMemory(memory)
Exemplo n.º 4
0
    def remove_cheat(id):
        """
        Removes a specific cheat from memory by id.

        void gbCheatRemove(int i)
        """
        Gb.cheatRemove(id)
Exemplo n.º 5
0
def get_registers():
    """
    Returns a list of current register values.
    """
    register_array = jarray.zeros(Gb.NUM_REGISTERS, "i")
    Gb.getRegisters(register_array)
    return list(register_array)
Exemplo n.º 6
0
    def remove_all():
        """
        Removes all cheats from memory.

        void gbCheatRemoveAll()
        """
        Gb.cheatRemoveAll()
Exemplo n.º 7
0
def get_rom():
    """
    Returns the ROM in bytes.
    """
    rom_array = jarray.zeros(Gb.ROM_SIZE, "i")
    Gb.getROM(rom_array)
    return RomList(rom_array)
Exemplo n.º 8
0
def get_memory():
    """
    Returns memory in bytes.
    """
    memory_size = 0x10000
    memory = jarray.zeros(memory_size, "i")
    Gb.getMemory(memory)
    return RomList(memory)
def set_memory_at(address, value):
    """
    Sets a byte at a certain address in memory.

    This directly sets the memory instead of copying
    the memory from the emulator.
    """
    Gb.setMemoryAt(address, value)
Exemplo n.º 10
0
def set_state(state, do_step=False):
    """
    Injects the given state into the emulator. Use do_step if you want to call
    step(), which also allows SDL to render the latest frame. Note that the
    default is to not step, and that the screen (if it is enabled) will appear
    as if it still has the last state loaded. This is normal.
    """
    Gb.loadState(_create_byte_buffer(state))
    if do_step:
        step()
Exemplo n.º 11
0
def get_pixels():
    """
    Returns a list of pixels on the screen display. Broken, probably. Use
    screenshot() instead.
    """
    sys.stderr.write("ERROR: seems to be broken on VBA's end? Good luck. Use"
    " screenshot() instead.\n")
    size = Gb.DISPLAY_WIDTH * Gb.DISPLAY_HEIGHT
    pixels = jarray.zeros(size, "i")
    Gb.getPixels(pixels)
    return RomList(pixels)
Exemplo n.º 12
0
def screenshot(filename, literal=False):
    """
    Saves a PNG screenshot to the file at filename. Use literal if you want to
    store it in the current directory. Default is to save it to screenshots/
    under the project.
    """
    screenshots_path = os.path.join(project_path, "screenshots/")
    filename = os.path.join(screenshots_path, filename)
    if len(filename) < 4 or filename[-4:] != ".png":
        filename += ".png"
    Gb.nwritePNG(filename)
    print "Screenshot saved to: " + str(filename)
Exemplo n.º 13
0
def press(buttons, steplimit=1):
    """
    Press a button. Use steplimit to say for how many steps you want to press
    the button (try leaving it at the default, 1).
    """
    if hasattr(buttons, "__len__"):
        number = button_combiner(buttons)
    elif isinstance(buttons, int):
        number = buttons
    else:
        number = buttons
    for step_counter in range(0, steplimit):
        Gb.step(number)
def get_buttons():
    """
    Returns the currentButtons[0] value

    (an integer with bits set for which
    buttons are currently pressed).
    """
    return Gb.getCurrentButtons()
Exemplo n.º 15
0
def load_rom(path=None):
    """
    Starts the emulator with a certain ROM. Defaults to rom_path if no
    parameters are given.
    """
    if path == None:
        path = rom_path
    try:
        root = load_state("root")
    except:
        # "root.sav" is required because if you create it in the future, you
        # will have to shutdown the emulator and possibly lose your state. Some
        # functions require there to be at least one root state available to do
        # computations between two states.
        sys.stderr.write("ERROR: unable to read \"root.sav\", please run"
        " generate_root() or get_root() to make an initial save.\n")
    Gb.startEmulator(path)
Exemplo n.º 16
0
def get_state():
    """
    Retrieves the current state of the emulator.
    """
    buf = Gb.saveState()
    state = [buf.get(x) for x in range(0, buf.capacity())]
    arr = array("b")
    arr.extend(state)
    return arr.tostring() # instead of state
Exemplo n.º 17
0
# for _check_java_library_path
from java.lang import System

# for passing states to the emulator
from java.nio import ByteBuffer

# For getRegisters and other times we have to pass a java int array to a
# function.
import jarray

# load in the vba-clojure bindings
import com.aurellem.gb.Gb as Gb

# load the vba-clojure library
Gb.loadVBA()

from vba_config import *

try:
    import vba_keyboard as keyboard
except ImportError:
    print "Not loading the keyboard module (which uses networkx)."

if not os.path.exists(rom_path):
    raise Exception("rom_path is not configured properly; edit vba_config.py?")

def _check_java_library_path():
    """
    Returns the value of java.library.path. The vba-clojure library must be
    compiled and linked from this location.
Exemplo n.º 18
0
def step():
    """
    Advances the emulator forward by one step.
    """
    Gb.step()
Exemplo n.º 19
0
 def load_file(filename):
     """
     Loads a .clt file. By default each cheat is disabled.
     """
     Gb.loadCheatsFromFile(filename)
Exemplo n.º 20
0
 def disable(id):
     """
     void gbCheatDisable(int i)
     """
     Gb.cheatDisable(id)
Exemplo n.º 21
0
 def enable(id):
     """
     void gbCheatEnable(int i)
     """
     Gb.cheatEnable(id)
Exemplo n.º 22
0
def nstep(steplimit):
    """
    Step the game forward by a certain number of instructions.
    """
    for counter in range(0, steplimit):
        Gb.step()
Exemplo n.º 23
0
def read_memory(address):
    """
    Read an integer at an address.
    """
    return Gb.readMemory(address)
Exemplo n.º 24
0
def step_until_capture():
    """
    Loop step() until SDLK_F12 is detected.
    """
    Gb.stepUntilCapture()
Exemplo n.º 25
0
def set_registers(registers):
    """
    Applies the set of registers to the CPU.
    """
    Gb.writeRegisters(registers)
Exemplo n.º 26
0
 def add_gamegenie(code, description=""):
     """
     void gbAddGgCheat(const char *code, const char *desc)
     """
     Gb.cheatAddGamegenie(code, description)
Exemplo n.º 27
0
 def add_gameshark(code, description=""):
     """
     gbAddGsCheat(const char *code, const char *desc)
     """
     Gb.cheatAddGameshark(code, description)
Exemplo n.º 28
0
def say_hello():
    """
    Test that the VBA/GB bindings are working.
    """
    Gb.sayHello()