Skip to content

Commit

Permalink
mb.tick wip. sound needs sdl2 refactored out, breakpoint_reached need…
Browse files Browse the repository at this point in the history
…s work
  • Loading branch information
Baekalfen committed Nov 8, 2023
1 parent bfada37 commit a374459
Show file tree
Hide file tree
Showing 19 changed files with 638 additions and 638 deletions.
2 changes: 1 addition & 1 deletion pyboy/core/bootrom.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ cdef Logger logger

cdef class BootROM:
cdef uint8_t[:] bootrom
cdef uint8_t getitem(self, uint16_t) noexcept
cdef uint8_t getitem(self, uint16_t) noexcept nogil
8 changes: 4 additions & 4 deletions pyboy/core/cartridge/base_mbc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ cdef class BaseMBC:
cdef void init_rambanks(self, uint8_t) noexcept
cdef str getgamename(self, uint8_t[:,:]) noexcept

cdef uint8_t getitem(self, uint16_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef void overrideitem(self, int, uint16_t, uint8_t) noexcept
cdef uint8_t getitem(self, uint16_t) noexcept nogil
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef void overrideitem(self, int, uint16_t, uint8_t) noexcept nogil

cdef class ROMOnly(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
2 changes: 1 addition & 1 deletion pyboy/core/cartridge/mbc1.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ from .base_mbc cimport BaseMBC
cdef Logger logger

cdef class MBC1(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef uint8_t bank_select_register1
cdef uint8_t bank_select_register2
2 changes: 1 addition & 1 deletion pyboy/core/cartridge/mbc2.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ from .base_mbc cimport BaseMBC
cdef Logger logger

cdef class MBC2(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
2 changes: 1 addition & 1 deletion pyboy/core/cartridge/mbc3.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ from .base_mbc cimport BaseMBC
cdef Logger logger

cdef class MBC3(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
2 changes: 1 addition & 1 deletion pyboy/core/cartridge/mbc5.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ from .base_mbc cimport BaseMBC
cdef Logger logger

cdef class MBC5(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
8 changes: 4 additions & 4 deletions pyboy/core/cartridge/rtc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ cdef class RTC:
cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept
@cython.locals(days=uint64_t)
cdef void latch_rtc(self) noexcept
cdef void writecommand(self, uint8_t) noexcept
cdef uint8_t getregister(self, uint8_t) noexcept
cdef void latch_rtc(self) noexcept nogil
cdef void writecommand(self, uint8_t) noexcept nogil
cdef uint8_t getregister(self, uint8_t) noexcept nogil
@cython.locals(t=cython.double, days=uint64_t)
cdef void setregister(self, uint8_t, uint8_t) noexcept
cdef void setregister(self, uint8_t, uint8_t) noexcept nogil
16 changes: 9 additions & 7 deletions pyboy/core/cpu.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ cdef class CPU:

cdef uint8_t interrupts_flag, interrupts_enabled, interrupts_flag_register, interrupts_enabled_register

cdef inline int check_interrupts(self) noexcept
cdef void set_interruptflag(self, int) noexcept
cdef bint handle_interrupt(self, uint8_t, uint16_t) noexcept
cdef inline int check_interrupts(self) noexcept nogil
cdef void set_interruptflag(self, int) noexcept nogil
cdef bint handle_interrupt(self, uint8_t, uint16_t) noexcept nogil

@cython.locals(opcode=uint16_t)
cdef inline uint8_t fetch_and_execute(self) noexcept
cdef int tick(self) noexcept
cdef inline uint8_t fetch_and_execute(self) noexcept nogil
cdef int tick(self) noexcept nogil
cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept

Expand All @@ -50,5 +50,7 @@ cdef class CPU:

cdef pyboy.core.mb.Motherboard mb

cdef void set_bc(CPU, uint16_t) noexcept
cdef void set_de(CPU, uint16_t) noexcept
cdef void set_bc(CPU, uint16_t) noexcept nogil
cdef void set_de(CPU, uint16_t) noexcept nogil

cdef dump_state(self, str) noexcept with gil
2 changes: 1 addition & 1 deletion pyboy/core/interaction.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ cdef uint8_t set_bit(uint8_t, uint8_t) noexcept
cdef class Interaction:
cdef uint8_t directional, standard
cdef bint key_event(self, WindowEvent) noexcept
cdef uint8_t pull(self, uint8_t) noexcept
cdef uint8_t pull(self, uint8_t) noexcept nogil
cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept
95 changes: 48 additions & 47 deletions pyboy/core/lcd.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ cdef class LCD:
cdef Renderer renderer

@cython.locals(interrupt_flag=uint8_t)
cdef uint8_t tick(self, int) noexcept
cdef uint64_t cycles_to_interrupt(self) noexcept
cdef uint8_t tick(self, int) noexcept nogil
cdef uint64_t cycles_to_interrupt(self) noexcept nogil

cdef void set_lcdc(self, uint8_t) noexcept
cdef uint8_t get_lcdc(self) noexcept
cdef void set_stat(self, uint8_t) noexcept
cdef uint8_t get_stat(self) noexcept
cdef void set_lcdc(self, uint8_t) noexcept nogil
cdef uint8_t get_lcdc(self) noexcept nogil
cdef void set_stat(self, uint8_t) noexcept nogil
cdef uint8_t get_stat(self) noexcept nogil

cdef int cycles_to_mode0(self) noexcept
cdef int cycles_to_mode0(self) noexcept nogil

cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept

cdef (int, int) getwindowpos(self) noexcept
cdef (int, int) getviewport(self) noexcept
cdef (int, int) getwindowpos(self) noexcept nogil
cdef (int, int) getviewport(self) noexcept nogil

# CGB
cdef bint cgb
Expand All @@ -80,21 +80,21 @@ cdef class PaletteRegister:
cdef uint32_t[4] palette_mem_rgb

@cython.locals(x=uint16_t)
cdef bint set(self, uint64_t) noexcept
cdef uint8_t get(self) noexcept
cdef uint32_t getcolor(self, uint8_t) noexcept
cdef bint set(self, uint64_t) noexcept nogil
cdef uint8_t get(self) noexcept nogil
cdef uint32_t getcolor(self, uint8_t) noexcept nogil

cdef class STATRegister:
cdef uint8_t value
cdef uint8_t _mode
cdef uint8_t set_mode(self, uint8_t) noexcept
cdef uint8_t update_LYC(self, uint8_t, uint8_t) noexcept
cdef void set(self, uint64_t) noexcept
cdef uint8_t set_mode(self, uint8_t) noexcept nogil
cdef uint8_t update_LYC(self, uint8_t, uint8_t) noexcept nogil
cdef void set(self, uint64_t) noexcept nogil

cdef class LCDCRegister:
cdef uint8_t value

cdef void set(self, uint64_t) noexcept
cdef void set(self, uint64_t) noexcept nogil

cdef public bint lcd_enable
cdef public bint windowmap_select
Expand Down Expand Up @@ -123,11 +123,11 @@ cdef class Renderer:

cdef int[10] sprites_to_render
cdef int ly_window
cdef void invalidate_tile(self, int, int) noexcept
cdef void invalidate_tile(self, int, int) noexcept nogil

cdef int[144][5] _scanlineparameters

cdef void blank_screen(self, LCD) noexcept
cdef void blank_screen(self, LCD) noexcept nogil

# CGB
cdef array _tilecache1_raw
Expand All @@ -148,37 +148,38 @@ cdef class Renderer:
tilecache=uint32_t[:,:],
bg_priority_apply=uint8_t,
)
cdef void scanline(self, LCD, int) noexcept
cdef void scanline(self, LCD, int) noexcept nogil

@cython.locals(
y=int,
x=int,
spriteheight=int,
spritecount=int,
n=int,
x=int,
y=int,
_n=int,
tileindex=int,
attributes=int,
xflip=bint,
yflip=bint,
spritepriority=bint,
palette=uint8_t,
spritecache=uint32_t[:,:],
sprites_priority=list,
dy=int,
dx=int,
yy=int,
xx=int,
color_code=uint8_t,
pixel=uint32_t,
bgmappriority=bint,
color_code=uint8_t,
_n=int,
)
cdef void scanline_sprites(self, LCD, int, uint32_t[:,:], bint) noexcept
cdef void sort_sprites(self, int) noexcept

cdef void clear_cache(self) noexcept
cdef void clear_tilecache0(self) noexcept
cdef void clear_tilecache1(self) noexcept # CGB Only
cdef void clear_spritecache0(self) noexcept
cdef void clear_spritecache1(self) noexcept
cdef void scanline_sprites(self, LCD, int, uint32_t[:,:], bint) noexcept nogil
cdef void sort_sprites(self, int) noexcept nogil

cdef void clear_cache(self) noexcept nogil
cdef void clear_tilecache0(self) noexcept nogil
cdef void clear_tilecache1(self) noexcept nogil # CGB Only
cdef void clear_spritecache0(self) noexcept nogil
cdef void clear_spritecache1(self) noexcept nogil
@cython.locals(
x=int,
t=int,
Expand All @@ -188,7 +189,7 @@ cdef class Renderer:
byte2=uint8_t,
colorcode=uint32_t,
)
cdef void update_tilecache0(self, LCD, int, int) noexcept
cdef void update_tilecache0(self, LCD, int, int) noexcept nogil
@cython.locals(
x=int,
t=int,
Expand All @@ -198,7 +199,7 @@ cdef class Renderer:
byte2=uint8_t,
colorcode=uint32_t,
)
cdef void update_tilecache1(self, LCD, int, int) noexcept # CGB Only
cdef void update_tilecache1(self, LCD, int, int) noexcept nogil # CGB Only
@cython.locals(
x=int,
t=int,
Expand All @@ -208,7 +209,7 @@ cdef class Renderer:
byte2=uint8_t,
colorcode=uint32_t,
)
cdef void update_spritecache0(self, LCD, int, int) noexcept
cdef void update_spritecache0(self, LCD, int, int) noexcept nogil
@cython.locals(
x=int,
t=int,
Expand All @@ -218,7 +219,7 @@ cdef class Renderer:
byte2=uint8_t,
colorcode=uint32_t,
)
cdef void update_spritecache1(self, LCD, int, int) noexcept
cdef void update_spritecache1(self, LCD, int, int) noexcept nogil


cdef void save_state(self, IntIOInterface) noexcept
Expand All @@ -232,7 +233,7 @@ cdef class Renderer:
vertflip = uint8_t,
bg_priority = uint8_t,
)
cdef (int, int, int, int, int) _cgb_get_background_map_attributes(self, LCD, int) noexcept
cdef (int, int, int, int, int) _cgb_get_background_map_attributes(self, LCD, int) noexcept nogil

cdef class CGBLCD(LCD):
pass
Expand All @@ -249,19 +250,19 @@ cdef class CGBRenderer(Renderer):
cdef class VBKregister:
cdef uint8_t active_bank

cdef void set(self, uint8_t) noexcept
cdef uint8_t get(self) noexcept
cdef void set(self, uint8_t) noexcept nogil
cdef uint8_t get(self) noexcept nogil

cdef class PaletteIndexRegister:
cdef uint8_t value
cdef int auto_inc
cdef int index
cdef int hl

cdef void set(self, uint8_t) noexcept
cdef uint8_t get(self) noexcept
cdef int getindex(self) noexcept
cdef void shouldincrement(self) noexcept
cdef void set(self, uint8_t) noexcept nogil
cdef uint8_t get(self) noexcept nogil
cdef int getindex(self) noexcept nogil
cdef void shouldincrement(self) noexcept nogil

cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept
Expand All @@ -271,10 +272,10 @@ cdef class PaletteColorRegister:
cdef uint32_t[8 * 4] palette_mem_rgb
cdef PaletteIndexRegister index_reg

cdef uint32_t cgb_to_rgb(self, uint16_t, uint8_t) noexcept
cdef void set(self, uint16_t) noexcept
cdef uint16_t get(self) noexcept
cdef uint32_t getcolor(self, uint8_t, uint8_t) noexcept
cdef uint32_t cgb_to_rgb(self, uint16_t, uint8_t) noexcept nogil
cdef void set(self, uint16_t) noexcept nogil
cdef uint16_t get(self) noexcept nogil
cdef uint32_t getcolor(self, uint8_t, uint8_t) noexcept nogil

cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept
16 changes: 8 additions & 8 deletions pyboy/core/mb.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ cdef class Motherboard:
cdef list breakpoints_list
cdef int breakpoint_latch

cdef inline bint processing_frame(self) noexcept
cdef inline bint processing_frame(self) noexcept nogil

cdef void buttonevent(self, WindowEvent) noexcept
cdef void stop(self, bint) noexcept
@cython.locals(cycles=int64_t, escape_halt=cython.int, mode0_cycles=int64_t)
cdef bint tick(self) noexcept
cdef bint tick(self) noexcept nogil

cdef void switch_speed(self) noexcept
cdef void switch_speed(self) noexcept nogil

@cython.locals(pc=cython.int, bank=cython.int)
cdef bint breakpoint_reached(self) noexcept

cdef uint8_t getitem(self, uint16_t) noexcept
cdef void setitem(self, uint16_t, uint8_t) noexcept
cdef uint8_t getitem(self, uint16_t) noexcept nogil
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil

@cython.locals(offset=cython.int, dst=cython.int, n=cython.int)
cdef void transfer_DMA(self, uint8_t) noexcept
cdef void transfer_DMA(self, uint8_t) noexcept nogil
cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface) noexcept

Expand All @@ -82,8 +82,8 @@ cdef class HDMA:
cdef uint16_t curr_src
cdef uint16_t curr_dst

cdef void set_hdma5(self, uint8_t, Motherboard) noexcept
cdef int tick(self, Motherboard) noexcept
cdef void set_hdma5(self, uint8_t, Motherboard) noexcept nogil
cdef int tick(self, Motherboard) noexcept nogil

cdef void save_state(self, IntIOInterface) noexcept
cdef void load_state(self, IntIOInterface, int) noexcept
7 changes: 4 additions & 3 deletions pyboy/core/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@ def tick(self):

# Escape halt. This happens when pressing 'return' in the debugger. It will make us skip breaking on halt
# for every cycle, but do break on the next instruction -- even in an interrupt.
escape_halt = self.cpu.halted and self.breakpoint_latch == 1
if self.breakpoints_enabled and (not escape_halt) and self.breakpoint_reached():
return True
# escape_halt = self.cpu.halted and self.breakpoint_latch == 1
# TODO: Replace with GDB Stub
# if self.breakpoints_enabled and (not escape_halt) and self.breakpoint_reached():
# return True

# TODO: Move SDL2 sync to plugin
self.sound.sync()
Expand Down
Loading

0 comments on commit a374459

Please sign in to comment.