# Path: pym2149/iface.py
# class Chip: pass
# 
# class Config(lurlene.iface.Config): pass
# 
# class Prerecorded: pass
# 
# class Roll: pass
# 
# class Stream: pass
# 
# class Timer: pass
# 
# Path: pym2149/ym2149.py
# class PhysicalRegisters:
# 
#     supportedchannels = 3
#     timers = property(lambda self: self.logical.timers)
#     levelbase = 0x8
# 
#     @types(Config, LogicalRegisters)
#     def __init__(self, config, logical):
#         # XXX: Add reverse wiring?
#         # Like the real thing we have 16 registers, this impl ignores the last 2:
#         self.R = tuple(Reg() for _ in range(16)) # Assume all incoming values are in [0, 255].
#         # We only have registers for the authentic number of channels:
#         for c in range(min(self.supportedchannels, config.chipchannels)):
#             logical.toneperiods[c].link(TP, self.R[c * 2], self.R[c * 2 + 1])
#             logical.toneflags[c].link(MixerFlag(c), self.R[0x7])
#             logical.noiseflags[c].link(MixerFlag(self.supportedchannels + c), self.R[0x7])
#             logical.fixedlevels[c].link(lambda l: l & 0x0f, self.R[self.levelbase + c])
#             logical.levelmodes[c].link(getlevelmode, self.R[self.levelbase + c])
#         logical.noiseperiod.link(NP, self.R[0x6])
#         logical.envperiod.link(EP, self.R[0xB], self.R[0xC])
#         logical.envshape.link(lambda s: s & 0x0f, self.R[0xD])
#         for r in self.R:
#             r.value = 0
#         self.logical = logical


from .iface import Chip, Config, Prerecorded, Roll, Stream, Timer
from .ym2149 import PhysicalRegisters
from diapyr import types
from splut.bg import MainBackground
# Copyright 2014, 2018, 2019, 2020 Andrzej Cichocki

# This file is part of pym2149.
#
# pym2149 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pym2149 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pym2149.  If not, see <http://www.gnu.org/licenses/>.


class Bundle:

    def __init__(self, prerecorded, registers):
        self.prerecorded = prerecorded
        self.registers = registers

    def __iter__(self):
        yield from self.prerecorded.frames(self.registers)

class LogicalBundle(Bundle):


# Path: pym2149/iface.py
# class Chip: pass
# 
# class Config(lurlene.iface.Config): pass
# 
# class Prerecorded: pass
# 
# class Roll: pass
# 
# class Stream: pass
# 
# class Timer: pass
# 
# Path: pym2149/ym2149.py
# class PhysicalRegisters:
# 
#     supportedchannels = 3
#     timers = property(lambda self: self.logical.timers)
#     levelbase = 0x8
# 
#     @types(Config, LogicalRegisters)
#     def __init__(self, config, logical):
#         # XXX: Add reverse wiring?
#         # Like the real thing we have 16 registers, this impl ignores the last 2:
#         self.R = tuple(Reg() for _ in range(16)) # Assume all incoming values are in [0, 255].
#         # We only have registers for the authentic number of channels:
#         for c in range(min(self.supportedchannels, config.chipchannels)):
#             logical.toneperiods[c].link(TP, self.R[c * 2], self.R[c * 2 + 1])
#             logical.toneflags[c].link(MixerFlag(c), self.R[0x7])
#             logical.noiseflags[c].link(MixerFlag(self.supportedchannels + c), self.R[0x7])
#             logical.fixedlevels[c].link(lambda l: l & 0x0f, self.R[self.levelbase + c])
#             logical.levelmodes[c].link(getlevelmode, self.R[self.levelbase + c])
#         logical.noiseperiod.link(NP, self.R[0x6])
#         logical.envperiod.link(EP, self.R[0xB], self.R[0xC])
#         logical.envshape.link(lambda s: s & 0x0f, self.R[0xD])
#         for r in self.R:
#             r.value = 0
#         self.logical = logical


# Path: pym2149/ymplayer.py
from .iface import Chip, Config, Prerecorded, Roll, Stream, Timer
from .ym2149 import PhysicalRegisters
from diapyr import types
from splut.bg import MainBackground

# Copyright 2014, 2018, 2019, 2020 Andrzej Cichocki

# This file is part of pym2149.
#
# pym2149 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pym2149 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pym2149.  If not, see <http://www.gnu.org/licenses/>.


class Bundle:

    def __init__(self, prerecorded, registers):
        self.prerecorded = prerecorded
        self.registers = registers

    def __iter__(self):
        yield from self.prerecorded.frames(self.registers)

class LogicalBundle(Bundle):


    @types(Prerecorded, [Chip])