//--------------------------------------------------------------------------------------------------
//
// Title       : Holdreg
// Design      : quaddecode
// Author      : mbari585
// Company     : MBARI
//
//-------------------------------------------------------------------------------------------------
//
// File        : c:\projects\genosensor\ESP 2003\quaddecode\quaddecode\src\Holdreg.v
// Generated   : Mon Oct 21 08:20:12 2002
// From        : interface description file
// By          : Itf2Vhdl ver. 1.20
//
//-------------------------------------------------------------------------------------------------
//
// Description : 
//
//-------------------------------------------------------------------------------------------------
`timescale 1ps / 1ps

//{{ Section below this comment is automatically maintained
//   and may be overwritten
//{module {Holdreg}}
module Holdreg ( RDslct4 ,outDATA ,ch0in ,ch1in ,Reset ,AS ,RD ,WR ,ADDR ,RDslct1 ,Sclk ,RDslct2 ,RDslct3 );

input RDslct4 ;
wire RDslct4 ;
input [23:0] ch0in ;
wire [23:0] ch0in ;
input [23:0] ch1in ;
wire [23:0] ch1in ;
input Reset ;
wire Reset ;
input AS ;
wire AS ;
input RD ;
wire RD ;
input WR ;
wire WR ;
input [7:0] ADDR ;
wire [7:0] ADDR ;
input RDslct1 ;
wire RDslct1 ;
input Sclk ;
wire Sclk ;
input RDslct2 ;
wire RDslct2 ;
input RDslct3 ;
wire RDslct3 ;

output [7:0] outDATA ;
wire [7:0] outDATA ;

//}} End of automatically maintained section

// -- Enter your statements here -- //

//how this works
//read from register 0 loads into holding register ch0 counter
//read from register 1 loads into holding register ch1 counter
//read from reg 0 or 1 makes holding reg 7:0 available on output
//read from reg 2 makes holding reg 15:8 avaiable
//read from reg 3 makes holding reg 23:16 available
//so to read a counter, first strobe initial ADDR 0 or 1.
//Then raise RD and then read the DATA, and lower RD.
//Then Strobe ADDR 2, and then Raise Read

//synthesis attribute keep of slcch1low is true;
//synthesis attribute keep of slcch2low is true;
//synthesis attribute keep of slcmidad is true;
//synthesis attribute keep of slchighad is true; 


//parameter 
//ch1low = 8'h00,
//ch2low = 8'h01,
//midad = 8'h02,
//highad = 8'h03;

reg rdyreg;
reg [23:0] holdingreg;

//wire enable;
//wire slcch1low;
//wire slcch2low;
//wire slcmidad; 
//wire slchighad;
//
//assign enable = (!AS & RD & !WR); 
//assign slcch1low = ((ADDR == ch1low) & enable);
//assign slcch2low = ((ADDR == ch2low) & enable);
//assign slcmidad = ((ADDR == midad) & enable);
//assign slchighad = ((ADDR == highad) & enable);

///define output muliplexer
assign outDATA = (RDslct1) ? holdingreg[7:0] :
			 	 (RDslct2) ? holdingreg[7:0] :
			 	 (RDslct3) ? holdingreg[15:8] :
			 	 (RDslct4) ? holdingreg[23:16] :
			 	  8'bz;

	
always @ (negedge Sclk)	 //this should run on the neg edge since the counter runs on the positive
	begin
		if (Reset)				// reset all the registers
			begin
				holdingreg <= 24'b0;
				rdyreg <= 1'b0;
			end				
		else
			begin
				rdyreg <= (RD & !AS & !WR); 	//rdy reg is used to let the processor know that it has
									//latched the data and is ready for reading.
				if (RDslct1) holdingreg <= ch0in; 		//clock in the data from the requested
				else if (RDslct2) holdingreg <= ch1in;	//register for reading
				else holdingreg <= holdingreg;
			end	
	end
endmodule