Ejemplo n.º 1
0
    def _load_from_memory(
            self,
            vm: Chip8VirtualMachine,
            max_register: int,
            read_src: int = 0xA00,
            value_start: int = 128
    ) -> None:
        """

        Helper function that executes a bulk register save operation.

        Will write value_start +0, ... value_start + max_register to
        the first max_register registers.

        Then runs FX55, with max_register as X.

        :param vm: vm object to write to
        :param max_register: the highest register that will be saved
        :param value_start: what the start of the written values will be
        :return:
        """

        # set up the memory with values to read into registers
        for register_index in range(0, max_register + 1):
            vm.memory[read_src + register_index] = 128 + register_index

        # set up where the registers will be stored to
        vm.i_register = read_src

        load_and_execute_instruction(
            vm, 0xF065, x=max_register
        )
Ejemplo n.º 2
0
    def _write_values_to_memory(
            self,
            vm: Chip8VirtualMachine,
            max_register: int,
            write_dest: int = 0xA00,
            value_start: int = 128
    ) -> None:
        """

        Helper function that executes a bulk register save operation.

        Will write value_start +0, ... value_start + max_register to
        the first max_register registers.

        Then runs FX55, with max_register as X.

        :param vm: vm object to write to
        :param max_register: the highest register that will be saved
        :param value_start: what the start of the written values will be
        :return:
        """

        # set up the registers with unique values that can be checked
        # for correct write order in memory.
        for index in range(0, max_register + 1):
            vm.v_registers[index] = value_start + index

        # set up where the registers will be stored to
        vm.i_register = write_dest

        load_and_execute_instruction(
            vm, 0xF055, x=max_register
        )