diff --git a/pyboy/plugins/debug.pxd b/pyboy/plugins/debug.pxd index fbc2fe8d2..563145cee 100644 --- a/pyboy/plugins/debug.pxd +++ b/pyboy/plugins/debug.pxd @@ -146,6 +146,7 @@ cdef class MemoryWindow(BaseDebugWindow): @cython.locals(header=bytes, addr=bytes) cdef void write_addresses(self) noexcept cdef void write_memory(self) noexcept + @cython.locals(text=uint8_t[:]) cdef void render_text(self) noexcept @cython.locals(i=int, c=uint8_t) cdef void draw_text(self, int, int, uint8_t[:]) noexcept diff --git a/pyboy/plugins/debug.py b/pyboy/plugins/debug.py index 948ed8970..6bc18c84d 100644 --- a/pyboy/plugins/debug.py +++ b/pyboy/plugins/debug.py @@ -418,7 +418,7 @@ def copy_tile(self, from_buffer, t, xx, yy, to_buffer, hflip, vflip, palette): _y = 7 - y if vflip else y for x in range(8): _x = 7 - x if hflip else x - to_buffer[yy + y, xx + x] = palette[from_buffer[_y + t*8][_x]] + to_buffer[yy + y, xx + x] = palette[from_buffer[_y + t*8, _x]] def mark_tile(self, x, y, color, height, width, grid): tw = width # Tile width @@ -431,16 +431,16 @@ def mark_tile(self, x, y, color, height, width, grid): yy = y for i in range(th): if 0 <= (yy + i) < self.height and 0 <= xx < self.width: - self.buf0[yy + i][xx] = color + self.buf0[yy + i, xx] = color for i in range(tw): if 0 <= (yy) < self.height and 0 <= xx + i < self.width: self.buf0[yy, xx + i] = color for i in range(tw): if 0 <= (yy + th - 1) < self.height and 0 <= xx + i < self.width: - self.buf0[yy + th - 1][xx + i] = color + self.buf0[yy + th - 1, xx + i] = color for i in range(th): if 0 <= (yy + i) < self.height and 0 <= xx + tw - 1 < self.width: - self.buf0[yy + i][xx + tw - 1] = color + self.buf0[yy + i, xx + tw - 1] = color class TileViewWindow(BaseDebugWindow): @@ -542,12 +542,12 @@ def draw_overlay(self): # Wraps around edges of the screen if y == 0 or y == constants.ROWS - 1: # Draw top/bottom bar for x in range(constants.COLS): - self.buf0[(yy+y) % 0xFF][(xx+x) % 0xFF] = COLOR + self.buf0[(yy+y) % 0xFF, (xx+x) % 0xFF] = COLOR else: # Draw body - self.buf0[(yy+y) % 0xFF][xx % 0xFF] = COLOR + self.buf0[(yy+y) % 0xFF, xx % 0xFF] = COLOR for x in range(constants.COLS): - self.buf0[(yy+y) % 0xFF][(xx+x) % 0xFF] &= self.color - self.buf0[(yy+y) % 0xFF][(xx + constants.COLS) % 0xFF] = COLOR + self.buf0[(yy+y) % 0xFF, (xx+x) % 0xFF] &= self.color + self.buf0[(yy+y) % 0xFF, (xx + constants.COLS) % 0xFF] = COLOR else: # Window # Takes a cut of the screen xx = -xx @@ -558,7 +558,7 @@ def draw_overlay(self): self.buf0[yy + y, xx + x] = COLOR else: # Draw body if 0 <= yy + y: - self.buf0[yy + y][max(xx, 0)] = COLOR + self.buf0[yy + y, max(xx, 0)] = COLOR for x in range(constants.COLS): if 0 <= xx + x < constants.COLS: self.buf0[yy + y, xx + x] &= self.color @@ -576,10 +576,10 @@ def draw_overlay(self): # Mark current scanline directly from LY,SCX,SCY,WX,WY if background_view: for x in range(constants.COLS): - self.buf0[(self.mb.lcd.SCY + self.mb.lcd.LY) % 0xFF][(self.mb.lcd.SCX + x) % 0xFF] = 0xFF00CE12 + self.buf0[(self.mb.lcd.SCY + self.mb.lcd.LY) % 0xFF, (self.mb.lcd.SCX + x) % 0xFF] = 0xFF00CE12 else: for x in range(constants.COLS): - self.buf0[(self.mb.lcd.WY + self.mb.lcd.LY) % 0xFF][(self.mb.lcd.WX + x) % 0xFF] = 0xFF00CE12 + self.buf0[(self.mb.lcd.WY + self.mb.lcd.LY) % 0xFF, (self.mb.lcd.WX + x) % 0xFF] = 0xFF00CE12 class TileDataWindow(BaseDebugWindow): @@ -812,49 +812,52 @@ def __init__(self, *args, **kwargs): def write_border(self): for x in range(self.NCOLS): - self.text_buffer[0][x] = 0xCD - self.text_buffer[2][x] = 0xCD - self.text_buffer[self.NROWS - 1][x] = 0xCD + self.text_buffer[0, x] = 0xCD + self.text_buffer[2, x] = 0xCD + self.text_buffer[self.NROWS - 1, x] = 0xCD for y in range(3, self.NROWS): - self.text_buffer[y][0] = 0xBA - self.text_buffer[y][9] = 0xB3 - self.text_buffer[y][self.NCOLS - 1] = 0xBA + self.text_buffer[y, 0] = 0xBA + self.text_buffer[y, 9] = 0xB3 + self.text_buffer[y, self.NCOLS - 1] = 0xBA - self.text_buffer[0][0] = 0xC9 - self.text_buffer[1][0] = 0xBA - self.text_buffer[0][self.NCOLS - 1] = 0xBB - self.text_buffer[1][self.NCOLS - 1] = 0xBA + self.text_buffer[0, 0] = 0xC9 + self.text_buffer[1, 0] = 0xBA + self.text_buffer[0, self.NCOLS - 1] = 0xBB + self.text_buffer[1, self.NCOLS - 1] = 0xBA - self.text_buffer[2][0] = 0xCC - self.text_buffer[2][9] = 0xD1 - self.text_buffer[2][self.NCOLS - 1] = 0xB9 + self.text_buffer[2, 0] = 0xCC + self.text_buffer[2, 9] = 0xD1 + self.text_buffer[2, self.NCOLS - 1] = 0xB9 - self.text_buffer[self.NROWS - 1][0] = 0xC8 - self.text_buffer[self.NROWS - 1][9] = 0xCF - self.text_buffer[self.NROWS - 1][self.NCOLS - 1] = 0xBC + self.text_buffer[self.NROWS - 1, 0] = 0xC8 + self.text_buffer[self.NROWS - 1, 9] = 0xCF + self.text_buffer[self.NROWS - 1, self.NCOLS - 1] = 0xBC def write_addresses(self): header = (f"Memory from 0x{self.start_address:04X} " f"to 0x{self.start_address+0x3FF:04X}").encode("cp437") for x in range(28): - self.text_buffer[1][x + 2] = header[x] + self.text_buffer[1, x + 2] = header[x] for y in range(32): addr = f"0x{self.start_address + (0x20*y):04X}".encode("cp437") for x in range(6): - self.text_buffer[y + 3][x + 2] = addr[x] + self.text_buffer[y + 3, x + 2] = addr[x] def write_memory(self): for y in range(32): for x in range(16): mem = self.mb.getitem(self.start_address + 16*y + x) a = hex(mem)[2:].zfill(2).encode("cp437") - self.text_buffer[y + 3][3*x + 11] = a[0] - self.text_buffer[y + 3][3*x + 12] = a[1] + self.text_buffer[y + 3, 3*x + 11] = a[0] + self.text_buffer[y + 3, 3*x + 12] = a[1] def render_text(self): for y in range(self.NROWS): - self.draw_text(0, 16 * y, self.text_buffer[y]) + text = array("B", [0x0] * (self.NCOLS)) + for x in range(self.NCOLS): + text[x] = self.text_buffer[y, x] + self.draw_text(0, 16 * y, text) def draw_text(self, x, y, text): self.dst.x = x