155155
156156class YamahaCPUBus (Module ):
157157 def __init__ (self , pads , master_cyc ):
158+ self .rst = Signal ()
158159 self .stb_m = Signal ()
159160
160161 self .a = Signal (2 )
@@ -191,6 +192,11 @@ def __init__(self, pads, master_cyc):
191192 pads .cs_t .oe .eq (1 ),
192193 pads .cs_t .o .eq (~ self .cs ),
193194 ]
195+ if hasattr (pads , "ic_t" ):
196+ self .comb += [
197+ pads .ic_t .oe .eq (1 ),
198+ pads .ic_t .o .eq (~ self .rst ),
199+ ]
194200
195201
196202class YamahaDACBus (Module ):
@@ -241,6 +247,7 @@ def __init__(self, pads, in_fifo, out_fifo, sample_decoder_cls, channel_count,
241247 wait_timer = Signal (16 )
242248
243249 enabled = Signal ()
250+ self .comb += self .cpu_bus .rst .eq (~ enabled )
244251
245252 # The code below assumes that the FSM clock is under ~50 MHz, which frees us from the need
246253 # to explicitly satisfy setup/hold timings.
@@ -732,7 +739,8 @@ def __init__(self, reader, opx_iface, clock_rate):
732739 async def play (self ):
733740 try :
734741 await self ._opx_iface .enable ()
735- await self .wait_seconds (1.0 )
742+ # Flush out the state after reset.
743+ await self ._opx_iface .wait_clocks (self ._opx_iface .sample_clocks * 1024 )
736744 await self ._reader .parse_data (self )
737745 finally :
738746 # Various parts of our stack are not completely synchronized to each other, resulting
@@ -742,6 +750,9 @@ async def play(self):
742750 await self ._opx_iface .disable ()
743751
744752 async def record (self , queue , chunk_count = 16384 ):
753+ # Skip a few initial samples that are used to flush state.
754+ await self ._opx_iface .read_samples (1024 )
755+
745756 total_count = int (self ._reader .total_seconds / self .sample_time )
746757 done_count = 0
747758 while done_count < total_count :
@@ -1014,20 +1025,23 @@ async def write_register(self, address, data):
10141025
10151026 __pin_sets = ("d" , "a" )
10161027 __pins = ("wr" , "rd" , "clk_m" ,
1017- "sh" , "mo" , "clk_sy" )
1028+ "sh" , "mo" , "clk_sy" ,
1029+ "cs" , "ic" )
10181030
10191031 @classmethod
10201032 def add_build_arguments (cls , parser , access ):
10211033 super ().add_build_arguments (parser , access )
10221034
10231035 access .add_pin_set_argument (parser , "d" , width = 8 , default = True )
1024- access .add_pin_set_argument (parser , "a" , width = 2 , default = True )
1036+ access .add_pin_set_argument (parser , "a" , width = range ( 1 , 3 ), default = 2 )
10251037 access .add_pin_argument (parser , "wr" , default = True )
10261038 access .add_pin_argument (parser , "rd" , default = True )
10271039 access .add_pin_argument (parser , "clk_m" , default = True )
10281040 access .add_pin_argument (parser , "sh" , default = True )
10291041 access .add_pin_argument (parser , "mo" , default = True )
10301042 access .add_pin_argument (parser , "clk_sy" , default = True )
1043+ access .add_pin_argument (parser , "cs" , required = False )
1044+ access .add_pin_argument (parser , "ic" , required = False )
10311045
10321046 parser .add_argument (
10331047 "-d" , "--device" , metavar = "DEVICE" , choices = ["OPL" , "OPL2" , "OPL3" , "OPM" ],
0 commit comments