from __future__ import annotations

from dataclasses import dataclass, field


@dataclass
class CPUState:
    pc: int = 0
    sr: int = 0
    br: int = 0
    regs: list[int] = field(default_factory=lambda: [0] * 8)
    cycles: int = 0
    steps: int = 0
    z: bool = False
    c: bool = False
    n: bool = False
    v: bool = False
    interrupt_depth: int = 0


def s8(value: int) -> int:
    return value - 0x100 if value & 0x80 else value


def s16(value: int) -> int:
    return value - 0x10000 if value & 0x8000 else value


def mask(size: int) -> int:
    return 0xFFFF if size == 2 else 0xFF


def sign_bit(size: int) -> int:
    return 0x8000 if size == 2 else 0x80
