data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v
1: b'%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:17: Cannot find include file: defines.v\n`include "defines.v" \n         ^~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation,data/full_repos/permissive/502764644/defines.v\n             data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation,data/full_repos/permissive/502764644/defines.v.v\n             data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation,data/full_repos/permissive/502764644/defines.v.sv\n             defines.v\n             defines.v.v\n             defines.v.sv\n             obj_dir/defines.v\n             obj_dir/defines.v.v\n             obj_dir/defines.v.sv\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:57: Define or directive not defined: \'`COEFF_BUFFER_ADDR_WIDTH\'\noutput [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_O;\n        ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:57: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\noutput [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_O;\n                                ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:60: Define or directive not defined: \'`COEFF_BUFFER_ADDR_WIDTH\'\ninput [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Reset_Address_I;\n       ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:60: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\ninput [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Reset_Address_I;\n                               ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:92: Define or directive not defined: \'`COEFF_BUFFER_ADDR_WIDTH\'\nreg [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address;\n     ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:92: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\nreg [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address;\n                             ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:93: Define or directive not defined: \'`COEFF_BUFFER_ADDR_WIDTH\'\nwire [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_Offset;\n      ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:93: syntax error, unexpected \':\', expecting TYPE-IDENTIFIER\nwire [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_Offset;\n                              ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:109: Define or directive not defined: \'`INV_QUANT_MB_INFO\'\n ((state == `INV_QUANT_MB_INFO) & (Coeff_Code != `INFO_BLOCK_CODE)) ? \'d1 : \'d0;\n            ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:109: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n ((state == `INV_QUANT_MB_INFO) & (Coeff_Code != `INFO_BLOCK_CODE)) ? \'d1 : \'d0;\n                              ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:109: Define or directive not defined: \'`INFO_BLOCK_CODE\'\n ((state == `INV_QUANT_MB_INFO) & (Coeff_Code != `INFO_BLOCK_CODE)) ? \'d1 : \'d0;\n                                                 ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:112: Define or directive not defined: \'`INV_QUANT_SKIPPED\'\n (state == `INV_QUANT_SKIPPED) ? \n           ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:112: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n (state == `INV_QUANT_SKIPPED) ? \n                             ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:113: Define or directive not defined: \'`INFO_BLOCK_CODE\'\n  {`INFO_BLOCK_CODE,18\'h00000} : \n   ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:118: Define or directive not defined: \'`INV_QUANT_MB_INFO\'\nassign Prediction_Data_En_O = (state == `INV_QUANT_MB_INFO);\n                                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:118: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\nassign Prediction_Data_En_O = (state == `INV_QUANT_MB_INFO);\n                                                          ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:122: Define or directive not defined: \'`INV_QUANT_IDLE\'\n      state <= `INV_QUANT_IDLE;\n               ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:122: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      state <= `INV_QUANT_IDLE;\n                              ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:136: Define or directive not defined: \'`INV_QUANT_IDLE\'\n         `INV_QUANT_IDLE : begin\n         ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:136: syntax error, unexpected \':\', expecting endcase\n         `INV_QUANT_IDLE : begin\n                         ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:138: Define or directive not defined: \'`INFO_BLOCK_CODE\'\n      if (Coeff_Code == `INFO_BLOCK_CODE) begin\n                        ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:143: Define or directive not defined: \'`INV_QUANT_BLOCK_DEQUANT\'\n        state <= `INV_QUANT_BLOCK_DEQUANT;\n                 ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:143: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n        state <= `INV_QUANT_BLOCK_DEQUANT;\n                                         ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:144: Define or directive not defined: \'`INV_QUANT_SKIPPED\'\n       end else state <= `INV_QUANT_SKIPPED;\n                         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:144: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n       end else state <= `INV_QUANT_SKIPPED;\n                                           ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:145: Define or directive not defined: \'`INV_QUANT_MB_INFO\'\n      end else state <= `INV_QUANT_MB_INFO;\n                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:148: Define or directive not defined: \'`INV_QUANT_MB_INFO\'\n         `INV_QUANT_MB_INFO : begin\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:151: Define or directive not defined: \'`INFO_BLOCK_CODE\'\n      `INFO_BLOCK_CODE : begin\n      ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:151: syntax error, unexpected \':\', expecting endcase\n      `INFO_BLOCK_CODE : begin\n                       ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:152: Define or directive not defined: \'`INV_QUANT_IDLE\'\n        state <= `INV_QUANT_IDLE;\n                 ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:154: Define or directive not defined: \'`INFO_SLICE_QUANT\'\n      `INFO_SLICE_QUANT : begin\n      ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:157: Define or directive not defined: \'`INFO_MACRO_MODES\'\n      `INFO_MACRO_MODES : begin\n      ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:159: syntax error, unexpected <=, expecting IDENTIFIER\n        if (Coeff_Buffer_Data_I[9]) Quant_Scale_Code <= Coeff_Buffer_Data_I[4:0];\n                                                     ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:161: Define or directive not defined: \'`INFO_MACRO_ADDR_INCR\'\n      `INFO_MACRO_ADDR_INCR : begin\n      ^~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:164: syntax error, unexpected <=, expecting IDENTIFIER\n         block_count <= 3\'d5;\n                     ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:167: Define or directive not defined: \'`INV_QUANT_SKIPPED\'\n         state <= `INV_QUANT_SKIPPED;         \n                  ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:172: Define or directive not defined: \'`INV_QUANT_SKIPPED\'\n   `INV_QUANT_SKIPPED : begin\n   ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:174: syntax error, unexpected <=, expecting IDENTIFIER\n               if (~Block_Deq_Done) Block_Deq_Start <= 1\'b0;\n                                                    ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:177: syntax error, unexpected <=, expecting IDENTIFIER\n                     Macroblock_Count <= next_Macroblock_Count;\n                                      ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:179: syntax error, unexpected <=, expecting IDENTIFIER\n        state <= `INV_QUANT_IDLE;\n              ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:179: Define or directive not defined: \'`INV_QUANT_IDLE\'\n        state <= `INV_QUANT_IDLE;\n                 ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:181: syntax error, unexpected \'[\', expecting IDENTIFIER\n        MB_Start_Predict[0] <= 1\'b1;\n                        ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:186: syntax error, unexpected <=, expecting IDENTIFIER\n                     Block_Deq_Start <= 1\'b1;\n                                     ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:190: syntax error, unexpected end\n    end \n    ^~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:191: Define or directive not defined: \'`INV_QUANT_BLOCK_DEQUANT\'\n         `INV_QUANT_BLOCK_DEQUANT : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:193: syntax error, unexpected <=, expecting IDENTIFIER\n               if (~Block_Deq_Done) Block_Deq_Start <= 1\'b0;\n                                                    ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:196: Define or directive not defined: \'`INFO_BLOCK_CODE_EOB\'\n      (Block_Retrieve_Write_En_O & Block_Deq_Done & (Coeff_Code == `INFO_BLOCK_CODE_EOB))\n                                                                   ^~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:196: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n      (Block_Retrieve_Write_En_O & Block_Deq_Done & (Coeff_Code == `INFO_BLOCK_CODE_EOB))\n                                                                                       ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Inverse_Quantisation/Inverse_Quantisation.v:201: syntax error, unexpected <=, expecting IDENTIFIER\n                     Macroblock_Count <= next_Macroblock_Count;\n                                      ^~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module Inverse_Quantisation(
   resetn,
   clock,
   
   Intra_DC_Precision_I,
   Quant_Scale_Type_I,
   Alternate_Scan_I,
	Load_Seq_Intra_Quant_I,
	Load_Seq_NIntra_Quant_I,
   
   Coeff_Buffer_Empty_I,
   Coeff_Buffer_En_O,
   Coeff_Buffer_Address_O,
   Coeff_Buffer_Data_I,
	Coeff_Buffer_Reset_I,
	Coeff_Buffer_Reset_Address_I,

   Block_Retrieve_Ready_I,
   Block_Retrieve_Write_En_O,
   Block_Retrieve_Address_O,
   Block_Retrieve_Data_O,
   Block_Retrieve_Waiting_O,
   
   MB_Start_Predict_O,
   Macroblock_Modes_O,
   Prediction_Data_En_O
);

input                resetn;
input                clock;

input 	[1:0]			Intra_DC_Precision_I;
input 					Quant_Scale_Type_I;
input 					Alternate_Scan_I;
input 					Load_Seq_Intra_Quant_I;
input 					Load_Seq_NIntra_Quant_I;

input                Coeff_Buffer_Empty_I;
output               Coeff_Buffer_En_O;
output [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_O;
input    [31:0]      Coeff_Buffer_Data_I;
input						Coeff_Buffer_Reset_I;
input [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Reset_Address_I;

input                Block_Retrieve_Ready_I;
output               Block_Retrieve_Write_En_O;
output   [5:0]       Block_Retrieve_Address_O;
output   [11:0]      Block_Retrieve_Data_O;
output               Block_Retrieve_Waiting_O;

output 					MB_Start_Predict_O;
output 	[4:0]			Macroblock_Modes_O;
output 					Prediction_Data_En_O;

reg                  Block_Deq_Start;
wire                 Block_Deq_Done;
wire                 Block_Deq_Adv_Coeff;

reg      [4:0]       Quant_Scale_Code;
reg      [4:0]       Macroblock_modes;
reg      [5:0]       Macroblock_Address;
wire     [5:0]       next_Macroblock_Count;
wire     [5:0]       next_next_Macroblock_Count;
wire     [5:0]       next_Macroblock_Address;
reg      [5:0]       Macroblock_Count;

wire     [31:0]      Coeff_Buffer_Data;
wire     [13:0]      Coeff_Code;
wire     [5:0]       Coeff_Run;
wire     [11:0]      Coeff_Level;

reg 						clear_flag;
reg      [2:0]       state;
reg      [2:0]       block_count;
reg [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address;
wire [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_Offset;

reg 		[3:0]			MB_Start_Predict;

assign MB_Start_Predict_O = MB_Start_Predict[3];

assign Coeff_Code = Coeff_Buffer_Data_I[31:18];
assign Coeff_Run = Coeff_Buffer_Data_I[17:12];
assign Coeff_Level = Coeff_Buffer_Data_I[11:0];

assign next_Macroblock_Count = Macroblock_Count + 1;
assign next_next_Macroblock_Count = Macroblock_Count + 2;
assign next_Macroblock_Address = Macroblock_Address + Coeff_Buffer_Data_I[5:0];

assign Coeff_Buffer_Address_O = Coeff_Buffer_Address + Coeff_Buffer_Address_Offset;
assign Coeff_Buffer_Address_Offset = 
	((state == `INV_QUANT_MB_INFO) & (Coeff_Code != `INFO_BLOCK_CODE)) ? 'd1 : 'd0;

assign Coeff_Buffer_Data = 
	(state == `INV_QUANT_SKIPPED) ? 
		{`INFO_BLOCK_CODE,18'h00000} : 
		Coeff_Buffer_Data_I;

assign Block_Retrieve_Waiting_O = Block_Deq_Done;
assign Macroblock_Modes_O = Macroblock_modes;
assign Prediction_Data_En_O = (state == `INV_QUANT_MB_INFO);

always @(posedge clock or negedge resetn) begin
   if (~resetn) begin
      state <= `INV_QUANT_IDLE;
      Macroblock_Count <= 6'h00;
      block_count <= 3'h0;
      clear_flag <= 1'b0;
		Coeff_Buffer_Address <= 'd0;
      Quant_Scale_Code <= 5'h01;
      Macroblock_modes <= 5'h00;
      Macroblock_Address <= 6'h00;
      Block_Deq_Start <= 1'b0;
      MB_Start_Predict <= 4'h0;
   end else begin
   	MB_Start_Predict <= {MB_Start_Predict[2:0],1'b0};
      if (Coeff_Buffer_Reset_I) Coeff_Buffer_Address <= Coeff_Buffer_Reset_Address_I;
      case (state) 
         `INV_QUANT_IDLE : begin
               if (Block_Retrieve_Ready_I) begin
						if (Coeff_Code == `INFO_BLOCK_CODE) begin
							block_count <= 3'd5;
							Block_Deq_Start <= 1'b1;
							MB_Start_Predict[0] <= 1'b1;
							if (next_Macroblock_Count == Macroblock_Address) begin
								state <= `INV_QUANT_BLOCK_DEQUANT;
							end else state <= `INV_QUANT_SKIPPED;
						end else state <= `INV_QUANT_MB_INFO;
               end
            end
         `INV_QUANT_MB_INFO : begin
					Coeff_Buffer_Address <= Coeff_Buffer_Address_O;
					case (Coeff_Code)
						`INFO_BLOCK_CODE : begin
								state <= `INV_QUANT_IDLE;
							end
						`INFO_SLICE_QUANT : begin
								Quant_Scale_Code <= Coeff_Buffer_Data_I[4:0];
							end
						`INFO_MACRO_MODES : begin
								Macroblock_modes <= Coeff_Buffer_Data_I[9:5];
								if (Coeff_Buffer_Data_I[9]) Quant_Scale_Code <= Coeff_Buffer_Data_I[4:0];
							end
						`INFO_MACRO_ADDR_INCR : begin
								Macroblock_Address <= next_Macroblock_Address;
								if (next_Macroblock_Count != next_Macroblock_Address) begin
									block_count <= 3'd5;
									Block_Deq_Start <= 1'b1;
									MB_Start_Predict[0] <= 1'b1;
									state <= `INV_QUANT_SKIPPED;									
								end
							end               
					endcase
				end
			`INV_QUANT_SKIPPED : begin
					clear_flag <= 1'b1;
               if (~Block_Deq_Done) Block_Deq_Start <= 1'b0;
               if (~Block_Deq_Start & Block_Deq_Done & Block_Retrieve_Ready_I) begin
                  if (block_count == 3'd0) begin
                     Macroblock_Count <= next_Macroblock_Count;
							if (next_next_Macroblock_Count == Macroblock_Address)
								state <= `INV_QUANT_IDLE;
							else begin
								MB_Start_Predict[0] <= 1'b1;
								block_count <= 3'd5;
								Block_Deq_Start <= 1'b1;
							end								
                  end else begin
                     Block_Deq_Start <= 1'b1;
                     block_count <= block_count - 1;
                  end
               end
				end	
         `INV_QUANT_BLOCK_DEQUANT : begin
					clear_flag <= 1'b1;
               if (~Block_Deq_Done) Block_Deq_Start <= 1'b0;

               if (Block_Deq_Adv_Coeff | 
						(Block_Retrieve_Write_En_O & Block_Deq_Done & (Coeff_Code == `INFO_BLOCK_CODE_EOB))
					) Coeff_Buffer_Address <= Coeff_Buffer_Address + 1;

               if (~Block_Deq_Start & Block_Deq_Done & Block_Retrieve_Ready_I) begin
                  if (block_count == 3'd0) begin
                     Macroblock_Count <= next_Macroblock_Count;
                     state <= `INV_QUANT_IDLE;
                  end else begin
                     Block_Deq_Start <= 1'b1;
                     block_count <= block_count - 1;
                  end
               end
            end
      endcase
   end
end

assign Coeff_Buffer_En_O = 1'b1;
Block_Inverse_Quantisation Block_Dequantiser(
   .resetn(resetn),
   .clock(clock),
   .Start_Inverse_Quantisation_I(Block_Deq_Start),
   .Done_Inverse_Quantisation_O(Block_Deq_Done),
   .Macroblock_Intra_I(Macroblock_modes[0]),
   .Intra_DC_Precision_I(Intra_DC_Precision_I),
   .Quant_Scale_Type_I(Quant_Scale_Type_I),
   .Quant_Scale_Code_I(Quant_Scale_Code),
   .Alternate_Scan_I(Alternate_Scan_I),
	.Load_Seq_Intra_Quant_I(Load_Seq_Intra_Quant_I),
	.Load_Seq_NIntra_Quant_I(Load_Seq_NIntra_Quant_I),
   .Advance_Coeff_Address_O(Block_Deq_Adv_Coeff),
   .Coeff_Buffer_Data_I(Coeff_Buffer_Data),
   .Block_Retrieve_Write_En_O(Block_Retrieve_Write_En_O),
   .Block_Retrieve_Address_O(Block_Retrieve_Address_O),
   .Block_Retrieve_Data_O(Block_Retrieve_Data_O)
);

endmodule
module Inverse_Quantisation(
   resetn,
   clock,
   
   Intra_DC_Precision_I,
   Quant_Scale_Type_I,
   Alternate_Scan_I,
	Load_Seq_Intra_Quant_I,
	Load_Seq_NIntra_Quant_I,
   
   Coeff_Buffer_Empty_I,
   Coeff_Buffer_En_O,
   Coeff_Buffer_Address_O,
   Coeff_Buffer_Data_I,
	Coeff_Buffer_Reset_I,
	Coeff_Buffer_Reset_Address_I,

   Block_Retrieve_Ready_I,
   Block_Retrieve_Write_En_O,
   Block_Retrieve_Address_O,
   Block_Retrieve_Data_O,
   Block_Retrieve_Waiting_O,
   
   MB_Start_Predict_O,
   Macroblock_Modes_O,
   Prediction_Data_En_O
);


input                resetn;
input                clock;

input 	[1:0]			Intra_DC_Precision_I;
input 					Quant_Scale_Type_I;
input 					Alternate_Scan_I;
input 					Load_Seq_Intra_Quant_I;
input 					Load_Seq_NIntra_Quant_I;

input                Coeff_Buffer_Empty_I;
output               Coeff_Buffer_En_O;
output [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_O;
input    [31:0]      Coeff_Buffer_Data_I;
input						Coeff_Buffer_Reset_I;
input [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Reset_Address_I;

input                Block_Retrieve_Ready_I;
output               Block_Retrieve_Write_En_O;
output   [5:0]       Block_Retrieve_Address_O;
output   [11:0]      Block_Retrieve_Data_O;
output               Block_Retrieve_Waiting_O;

output 					MB_Start_Predict_O;
output 	[4:0]			Macroblock_Modes_O;
output 					Prediction_Data_En_O;

reg                  Block_Deq_Start;
wire                 Block_Deq_Done;
wire                 Block_Deq_Adv_Coeff;

reg      [4:0]       Quant_Scale_Code;
reg      [4:0]       Macroblock_modes;
reg      [5:0]       Macroblock_Address;
wire     [5:0]       next_Macroblock_Count;
wire     [5:0]       next_next_Macroblock_Count;
wire     [5:0]       next_Macroblock_Address;
reg      [5:0]       Macroblock_Count;

wire     [31:0]      Coeff_Buffer_Data;
wire     [13:0]      Coeff_Code;
wire     [5:0]       Coeff_Run;
wire     [11:0]      Coeff_Level;

reg 						clear_flag;
reg      [2:0]       state;
reg      [2:0]       block_count;
reg [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address;
wire [`COEFF_BUFFER_ADDR_WIDTH:0] Coeff_Buffer_Address_Offset;

reg 		[3:0]			MB_Start_Predict;

assign MB_Start_Predict_O = MB_Start_Predict[3];

assign Coeff_Code = Coeff_Buffer_Data_I[31:18];
assign Coeff_Run = Coeff_Buffer_Data_I[17:12];
assign Coeff_Level = Coeff_Buffer_Data_I[11:0];

assign next_Macroblock_Count = Macroblock_Count + 1;
assign next_next_Macroblock_Count = Macroblock_Count + 2;
assign next_Macroblock_Address = Macroblock_Address + Coeff_Buffer_Data_I[5:0];

assign Coeff_Buffer_Address_O = Coeff_Buffer_Address + Coeff_Buffer_Address_Offset;
assign Coeff_Buffer_Address_Offset = 
	((state == `INV_QUANT_MB_INFO) & (Coeff_Code != `INFO_BLOCK_CODE)) ? 'd1 : 'd0;

assign Coeff_Buffer_Data = 
	(state == `INV_QUANT_SKIPPED) ? 
		{`INFO_BLOCK_CODE,18'h00000} : 
		Coeff_Buffer_Data_I;

assign Block_Retrieve_Waiting_O = Block_Deq_Done;
assign Macroblock_Modes_O = Macroblock_modes;
assign Prediction_Data_En_O = (state == `INV_QUANT_MB_INFO);

always @(posedge clock or negedge resetn) begin
   if (~resetn) begin
      state <= `INV_QUANT_IDLE;
      Macroblock_Count <= 6'h00;
      block_count <= 3'h0;
      clear_flag <= 1'b0;
		Coeff_Buffer_Address <= 'd0;
      Quant_Scale_Code <= 5'h01;
      Macroblock_modes <= 5'h00;
      Macroblock_Address <= 6'h00;
      Block_Deq_Start <= 1'b0;
      MB_Start_Predict <= 4'h0;
   end else begin
   	MB_Start_Predict <= {MB_Start_Predict[2:0],1'b0};
      if (Coeff_Buffer_Reset_I) Coeff_Buffer_Address <= Coeff_Buffer_Reset_Address_I;
      case (state) 
         `INV_QUANT_IDLE : begin
               if (Block_Retrieve_Ready_I) begin
						if (Coeff_Code == `INFO_BLOCK_CODE) begin
							block_count <= 3'd5;
							Block_Deq_Start <= 1'b1;
							MB_Start_Predict[0] <= 1'b1;
							if (next_Macroblock_Count == Macroblock_Address) begin
								state <= `INV_QUANT_BLOCK_DEQUANT;
							end else state <= `INV_QUANT_SKIPPED;
						end else state <= `INV_QUANT_MB_INFO;
               end
            end
         `INV_QUANT_MB_INFO : begin
					Coeff_Buffer_Address <= Coeff_Buffer_Address_O;
					case (Coeff_Code)
						`INFO_BLOCK_CODE : begin
								state <= `INV_QUANT_IDLE;
							end
						`INFO_SLICE_QUANT : begin
								Quant_Scale_Code <= Coeff_Buffer_Data_I[4:0];
							end
						`INFO_MACRO_MODES : begin
								Macroblock_modes <= Coeff_Buffer_Data_I[9:5];
								if (Coeff_Buffer_Data_I[9]) Quant_Scale_Code <= Coeff_Buffer_Data_I[4:0];
							end
						`INFO_MACRO_ADDR_INCR : begin
								Macroblock_Address <= next_Macroblock_Address;
								if (next_Macroblock_Count != next_Macroblock_Address) begin
									block_count <= 3'd5;
									Block_Deq_Start <= 1'b1;
									MB_Start_Predict[0] <= 1'b1;
									state <= `INV_QUANT_SKIPPED;									
								end
							end               
					endcase
				end
			`INV_QUANT_SKIPPED : begin
					clear_flag <= 1'b1;
               if (~Block_Deq_Done) Block_Deq_Start <= 1'b0;
               if (~Block_Deq_Start & Block_Deq_Done & Block_Retrieve_Ready_I) begin
                  if (block_count == 3'd0) begin
                     Macroblock_Count <= next_Macroblock_Count;
							if (next_next_Macroblock_Count == Macroblock_Address)
								state <= `INV_QUANT_IDLE;
							else begin
								MB_Start_Predict[0] <= 1'b1;
								block_count <= 3'd5;
								Block_Deq_Start <= 1'b1;
							end								
                  end else begin
                     Block_Deq_Start <= 1'b1;
                     block_count <= block_count - 1;
                  end
               end
				end	
         `INV_QUANT_BLOCK_DEQUANT : begin
					clear_flag <= 1'b1;
               if (~Block_Deq_Done) Block_Deq_Start <= 1'b0;

               if (Block_Deq_Adv_Coeff | 
						(Block_Retrieve_Write_En_O & Block_Deq_Done & (Coeff_Code == `INFO_BLOCK_CODE_EOB))
					) Coeff_Buffer_Address <= Coeff_Buffer_Address + 1;

               if (~Block_Deq_Start & Block_Deq_Done & Block_Retrieve_Ready_I) begin
                  if (block_count == 3'd0) begin
                     Macroblock_Count <= next_Macroblock_Count;
                     state <= `INV_QUANT_IDLE;
                  end else begin
                     Block_Deq_Start <= 1'b1;
                     block_count <= block_count - 1;
                  end
               end
            end
      endcase
   end
end

assign Coeff_Buffer_En_O = 1'b1;
Block_Inverse_Quantisation Block_Dequantiser(
   .resetn(resetn),
   .clock(clock),
   .Start_Inverse_Quantisation_I(Block_Deq_Start),
   .Done_Inverse_Quantisation_O(Block_Deq_Done),
   .Macroblock_Intra_I(Macroblock_modes[0]),
   .Intra_DC_Precision_I(Intra_DC_Precision_I),
   .Quant_Scale_Type_I(Quant_Scale_Type_I),
   .Quant_Scale_Code_I(Quant_Scale_Code),
   .Alternate_Scan_I(Alternate_Scan_I),
	.Load_Seq_Intra_Quant_I(Load_Seq_Intra_Quant_I),
	.Load_Seq_NIntra_Quant_I(Load_Seq_NIntra_Quant_I),
   .Advance_Coeff_Address_O(Block_Deq_Adv_Coeff),
   .Coeff_Buffer_Data_I(Coeff_Buffer_Data),
   .Block_Retrieve_Write_En_O(Block_Retrieve_Write_En_O),
   .Block_Retrieve_Address_O(Block_Retrieve_Address_O),
   .Block_Retrieve_Data_O(Block_Retrieve_Data_O)
);

endmodule