Пример #1
0
    def update_cache(self, lcd):
        if self.clearcache:
            self.tiles_changed.clear()
            for x in range(0x8000, 0x9800, 16):
                self.tiles_changed.add(x)
            self.clearcache = False

        for t in self.tiles_changed:
            for k in range(0, 16, 2):  # 2 bytes for each line
                byte1 = lcd.VRAM[t + k - 0x8000]
                byte2 = lcd.VRAM[t + k + 1 - 0x8000]
                y = (t + k - 0x8000) // 2

                for x in range(8):
                    colorcode = color_code(byte1, byte2, 7 - x)

                    self._tilecache[y][x] = self.color_palette[
                        lcd.BGP.getcolor(colorcode)]
                    self._spritecache0[y][x] = self.color_palette[
                        lcd.OBP0.getcolor(colorcode)]
                    self._spritecache1[y][x] = self.color_palette[
                        lcd.OBP1.getcolor(colorcode)]

                    if colorcode == 0:
                        self._spritecache0[y][x] &= ~self.alphamask
                        self._spritecache1[y][x] &= ~self.alphamask

        self.tiles_changed.clear()
Пример #2
0
    def image_data(self):
        """
        Use this function to get the raw tile data. The data is a `memoryview` corresponding to 8x8 pixels in RGBA
        colors.

        Be aware, that the graphics for this tile can change between each call to `pyboy.PyBoy.tick`.

        Returns
        -------
        memoryview :
            Image data of tile in 8x8 pixels and RGBA colors.
        """
        data = np.zeros((8, 8), dtype=np.uint32)
        # Converting from RGBA to ABGR
        color_palette = [(x >> 8) | 0xFF000000
                         for x in self.mb.renderer.color_palette]

        for k in range(0, 16, 2):  # 2 bytes for each line
            byte1 = self.mb.lcd.VRAM[self.data_address + k - VRAM_OFFSET]
            byte2 = self.mb.lcd.VRAM[self.data_address + k + 1 - VRAM_OFFSET]

            for x in range(8):
                colorcode = color_code(byte1, byte2, 7 - x)
                data[k //
                     2][x] = color_palette[self.mb.lcd.BGP.getcolor(colorcode)]

        return data
Пример #3
0
    def update_tiles(self, lcd, tiles_changed, bank):
        for t in tiles_changed:
            for k in range(0, 16, 2):  # 2 bytes for each line
                byte1 = lcd.getVRAMbank(t + k, bank)
                byte2 = lcd.getVRAMbank(t + k + 1, bank)

                y = (t + k - 0x8000) // 2

                for x in range(8):
                    #index into the palette for the current pixel
                    colorcode = color_code(byte1, byte2, 7 - x)

                    if bank:
                        self._col_index1[y][x] = colorcode
                    else:
                        self._col_index0[y][x] = colorcode

                    # update for the 8 palettes
                    for p in range(8):
                        if bank:
                            self._tilecache1[p][y][x] = self.convert_to_rgba(
                                lcd.bcpd.getcolor(p, colorcode))
                            self._spritecache1[p][y][x] = self.convert_to_rgba(
                                lcd.ocpd.getcolor(p, colorcode))

                        else:
                            self._tilecache0[p][y][x] = self.convert_to_rgba(
                                lcd.bcpd.getcolor(p, colorcode))
                            self._spritecache0[p][y][x] = self.convert_to_rgba(
                                lcd.ocpd.getcolor(p, colorcode))

                        # first color transparent for sprites
                        if colorcode == 0:
                            if bank:
                                self._spritecache1[p][y][x] &= ~self.alphamask
                            else:
                                self._spritecache0[p][y][x] &= ~self.alphamask