Skip to content

Commit

Permalink
Minimize asm 0-padding in opcodes and mbc
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguy11325 authored and Baekalfen committed Dec 8, 2023
1 parent f765f2c commit 5348839
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 29 deletions.
10 changes: 5 additions & 5 deletions pyboy/core/cartridge/base_mbc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# GitHub: https://github.com/Baekalfen/PyBoy
#

from libc.stdint cimport uint8_t, uint16_t, uint32_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t

from pyboy.core.cartridge.rtc cimport RTC
from pyboy.logging.logging cimport Logger
Expand All @@ -29,7 +29,7 @@ cdef class BaseMBC:
cdef uint16_t rambank_selected
cdef uint16_t rombank_selected
cdef uint8_t[:] rombank_view
cdef uint8_t[:] rambank_view
cdef uint8_t[:] rambank_view
cdef bint cgb

cdef void save_state(self, IntIOInterface) noexcept
Expand All @@ -39,9 +39,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 nogil
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef uint8_t getitem(self, uint64_t) noexcept nogil
cdef void setitem(self, uint64_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 nogil
cdef void setitem(self, uint64_t, uint8_t) noexcept nogil
6 changes: 2 additions & 4 deletions pyboy/core/cartridge/mbc1.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
# GitHub: https://github.com/Baekalfen/PyBoy
#

from libc.stdint cimport uint8_t, uint16_t

from pyboy.logging.logging cimport Logger

from libc.stdint cimport uint8_t, uint16_t, uint64_t
from .base_mbc cimport BaseMBC


cdef Logger logger

cdef class MBC1(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef void setitem(self, uint64_t, uint8_t) noexcept nogil
cdef uint8_t bank_select_register1
cdef uint8_t bank_select_register2
6 changes: 2 additions & 4 deletions pyboy/core/cartridge/mbc2.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
# GitHub: https://github.com/Baekalfen/PyBoy
#

from libc.stdint cimport uint8_t, uint16_t

from pyboy.logging.logging cimport Logger

from libc.stdint cimport uint8_t, uint16_t, uint64_t
from .base_mbc cimport BaseMBC


cdef Logger logger

cdef class MBC2(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef void setitem(self, uint64_t, uint8_t) noexcept nogil
5 changes: 2 additions & 3 deletions pyboy/core/cartridge/mbc3.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
# GitHub: https://github.com/Baekalfen/PyBoy
#

from libc.stdint cimport uint8_t, uint16_t

from pyboy.logging.logging cimport Logger

from libc.stdint cimport uint8_t, uint16_t, uint64_t
from .base_mbc cimport BaseMBC


cdef Logger logger

cdef class MBC3(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef void setitem(self, uint64_t, uint8_t) noexcept nogil
4 changes: 2 additions & 2 deletions pyboy/core/cartridge/mbc5.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# GitHub: https://github.com/Baekalfen/PyBoy
#

from libc.stdint cimport uint8_t, uint16_t

from pyboy.logging.logging cimport Logger

from libc.stdint cimport uint8_t, uint16_t, uint64_t
from .base_mbc cimport BaseMBC


cdef Logger logger

cdef class MBC5(BaseMBC):
cdef void setitem(self, uint16_t, uint8_t) noexcept nogil
cdef void setitem(self, uint64_t, uint8_t) noexcept nogil
4 changes: 2 additions & 2 deletions pyboy/core/mb.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ cdef class Motherboard:
@cython.locals(pc=cython.int, bank=cython.int)
cdef bint breakpoint_reached(self) noexcept with gil

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

@cython.locals(offset=cython.int, dst=cython.int, n=cython.int)
cdef void transfer_DMA(self, uint8_t) noexcept nogil
Expand Down
11 changes: 4 additions & 7 deletions pyboy/core/opcodes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
# DO NOT MODIFY THIS FILE.
# CHANGES TO THE CODE SHOULD BE MADE IN 'opcodes_gen.py'.

from . cimport cpu
cimport cython
from libc.stdint cimport uint8_t, uint16_t, uint32_t

from pyboy.logging.logging cimport Logger

from . cimport cpu


cdef Logger logger

cdef uint16_t FLAGC, FLAGH, FLAGN, FLAGZ
cdef uint8_t[512] OPCODE_LENGTHS
@cython.locals(v=uint16_t, a=uint16_t, b=uint16_t, pc=uint16_t, oplen=uint8_t)
cdef int execute_opcode(cpu.CPU, uint16_t) noexcept nogil
cdef uint8_t no_opcode(cpu.CPU) noexcept nogil
@cython.locals(v=cython.int, a=cython.int, b=cython.int, pc=cython.ushort)
cdef int execute_opcode(cpu.CPU, uint64_t) noexcept nogil

cdef uint8_t no_opcode(cpu.CPU) noexcept nogil
@cython.locals(v=int, flag=uint8_t, t=int)
cdef uint8_t NOP_00(cpu.CPU) noexcept nogil # 00 NOP
@cython.locals(v=int, flag=uint8_t, t=int)
Expand Down
2 changes: 1 addition & 1 deletion pyboy/core/opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,7 @@ def JP_CA(cpu, v): # CA JP Z,a16


def PREFIX_CB(cpu): # CB PREFIX CB
logger.critical("CB cannot be called!")
logger.critical('CB cannot be called!')
cpu.PC += 1
cpu.PC &= 0xFFFF
return 4
Expand Down
2 changes: 1 addition & 1 deletion pyboy/core/opcodes_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
cdef uint16_t FLAGC, FLAGH, FLAGN, FLAGZ
cdef uint8_t[512] OPCODE_LENGTHS
@cython.locals(v=cython.int, a=cython.int, b=cython.int, pc=cython.ushort)
cdef int execute_opcode(cpu.CPU, uint16_t) noexcept nogil
cdef int execute_opcode(cpu.CPU, uint64_t) noexcept nogil
cdef uint8_t no_opcode(cpu.CPU) noexcept nogil
"""
Expand Down

0 comments on commit 5348839

Please sign in to comment.