Skip to content

Commit

Permalink
Improve vblank and scroll compliance in low-res
Browse files Browse the repository at this point in the history
  • Loading branch information
GMH-Code committed Oct 8, 2024
1 parent 34f42a7 commit 351ff13
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
6 changes: 4 additions & 2 deletions scchip/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python3

__author__ = "Gregory Maynard-Hoare"
__copyright__ = "Copyright (C) 2024 Gregory Maynard-Hoare"
__license__ = "GNU Affero General Public License v3.0"
__version__ = "1.4.3"

# App identification
APP_NAME = "SuperChocChip Emulator"
APP_VERSION = "1.4.2"
APP_COPYRIGHT = "Copyright (C) 2023 Gregory Maynard-Hoare, licensed under GNU Affero General Public License v3.0"
APP_VERSION = __version__
APP_COPYRIGHT = "".join((__copyright__, ", licensed under ", __license__))
APP_INTRO = "{} V{} -- ".format(APP_NAME, APP_VERSION)

# Emulated system architectures
Expand Down
23 changes: 14 additions & 9 deletions scchip/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def __init__(self, arch, ram, stack, framebuffer, inputs, audio, debugger, clock
auto_clock_speed = clock_speed

self.core_interval = None if auto_clock_speed <= 0 else 1.0 / auto_clock_speed
self.arch_is_chip48 = (arch == ARCH_CHIP48)
self.arch_is_dblheight = (arch == ARCH_CHIP8_HIRES)
self.arch_is_halfscroll = (arch < ARCH_XO_CHIP) # Half-pixel scroll systems
arch_is_schip = (arch >= ARCH_SUPERCHIP_1_0 and arch <= ARCH_SUPERCHIP_1_1) # Includes CHIP-48

"""
Expand All @@ -68,6 +68,7 @@ def __init__(self, arch, ram, stack, framebuffer, inputs, audio, debugger, clock
- Index overflow quirks : Disabled. Some Super-CHIP games fail if enabled.
- Index increment quirks: Enabled for accurate CHIP-48 behaviour only.
- Jump quirks : Enabled on Super-CHIP-based systems only.
- Sprite delay quirks : Enabled on CHIP-8, CHIP-8 double-height, and CHIP-48. Only active in low-res mode.
"""

self.load_quirks = (
Expand All @@ -76,9 +77,13 @@ def __init__(self, arch, ram, stack, framebuffer, inputs, audio, debugger, clock
self.shift_quirks = arch_is_schip if shift_quirks is None else shift_quirks
self.logic_quirks = (arch <= ARCH_CHIP8_HIRES) if logic_quirks is None else logic_quirks
self.index_overflow_quirks = False if index_overflow_quirks is None else index_overflow_quirks
self.index_increment_quirks = self.arch_is_chip48 if index_increment_quirks is None else index_increment_quirks
self.index_increment_quirks = (
arch == ARCH_CHIP48
) if index_increment_quirks is None else index_increment_quirks
self.jump_quirks = arch_is_schip if jump_quirks is None else jump_quirks
self.sprite_delay_quirks = (arch <= ARCH_CHIP8_HIRES) if sprite_delay_quirks is None else sprite_delay_quirks
self.sprite_delay_quirks = (
(arch <= ARCH_CHIP8_HIRES) or (arch == ARCH_CHIP48)
) if sprite_delay_quirks is None else sprite_delay_quirks

# Define instruction pointers.
# n = Nibble
Expand Down Expand Up @@ -623,8 +628,8 @@ def _Dxyn(self): # DRW Vx, Vy, nibble
# Super-CHIP 1.1 and above reports number of rows collided
self.v[0xF] = int(rows_collided > 0) if self.arch < ARCH_SUPERCHIP_1_1 else rows_collided

# Wait for vertical blanking interrupt. Normally only used if emulating original CHIP-8 system
if self.sprite_delay_quirks:
# Wait for vertical blanking interrupt in low-res mode. Normally only used by early CHIP-8 and CHIP-48 systems
if self.sprite_delay_quirks and self.lo_res:
self.vblank_wait = True

def _Ex9E_d(self): # SKP Vx (debug)
Expand Down Expand Up @@ -812,13 +817,13 @@ def _00FB_d(self): # SCR (debug)
self.debug("SCR")

def _00FB(self): # SCR
self.framebuffer.scroll_right(2 if self.lo_res else 4)
self.framebuffer.scroll_right(2 if self.arch_is_halfscroll and self.lo_res else 4)

def _00FC_d(self): # SCL (debug)
self.debug("SCL")

def _00FC(self): # SCL
self.framebuffer.scroll_left(2 if self.lo_res else 4)
self.framebuffer.scroll_left(2 if self.arch_is_halfscroll and self.lo_res else 4)

def _Fx30_d(self): # LD HF, Vx (debug)
self.debug("LD HF, V{:01x}".format(self.vx))
Expand All @@ -832,7 +837,7 @@ def _00Cn_d(self): # SCD n (debug)
def _00Cn(self): # SCD n
scroll_distance = self.nibble

if self.arch_is_chip48 and self.lo_res:
if self.arch_is_halfscroll and self.lo_res:
if scroll_distance & 1:
raise CPUError("Scrolling down vertically by a half-pixel in low resolution mode is unsupported.")

Expand All @@ -848,7 +853,7 @@ def _00Dn_d(self): # SCU n (debug)
def _00Dn(self): # SCU n
scroll_distance = self.nibble

if self.arch_is_chip48 and self.lo_res:
if self.arch_is_halfscroll and self.lo_res:
if scroll_distance & 1:
raise CPUError("Scrolling up vertically by a half-pixel in low resolution mode is unsupported.")

Expand Down
2 changes: 1 addition & 1 deletion superchocchip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__author__ = "Gregory Maynard-Hoare"
__copyright__ = "Copyright (C) 2024 Gregory Maynard-Hoare"
__license__ = "GNU Affero General Public License v3.0"
__version__ = "1.4.2"
__version__ = "1.4.3"

from argparse import ArgumentParser
from scchip import main
Expand Down
4 changes: 2 additions & 2 deletions test/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def test_cpu_fx30(self): # LD HF, Vx
def test_cpu_00cn_00dn(self): # SCD n (Super-CHIP 1.1 and above) / SCU n (XO-CHIP only)
for opcode in 0x00C1, 0x00D1:
# Switch to CHIP-48 and low-res modes
self.cpu.arch_is_chip48 = True
self.cpu.arch_is_halfscroll = True
self._check_opcode(0x00FE)

# Check half-pixel scrolling in CHIP-48 is raised as unsupported
Expand All @@ -419,7 +419,7 @@ def test_cpu_00cn_00dn(self): # SCD n (Super-CHIP 1.1 and above) / SCU n (XO-CH
self._check_opcode(opcode + 1) # Double-pixel scroll check

# Switch back to XO-CHIP and check low-res scrolling is now supported
self.cpu.arch_is_chip48 = False
self.cpu.arch_is_halfscroll = False
self._check_opcode(0x00FE)
self._check_opcode(opcode)
self._check_opcode(opcode + 1)
Expand Down

0 comments on commit 351ff13

Please sign in to comment.