data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v
1: b'%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.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/Slice_Decode,data/full_repos/permissive/502764644/defines.v\n             data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode,data/full_repos/permissive/502764644/defines.v.v\n             data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode,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/Slice_Decode/Slice_Decode.v:76: Define or directive not defined: \'`SLICE_DECODE_START_CODE\'\nassign Shift_8_En_O = (state == `SLICE_DECODE_START_CODE);\n                                ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:76: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\nassign Shift_8_En_O = (state == `SLICE_DECODE_START_CODE);\n                                                        ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:78: Define or directive not defined: \'`SLICE_DECODE_QUANTISER_SCALE\'\n   (state == `SLICE_DECODE_QUANTISER_SCALE) | \n             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:78: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n   (state == `SLICE_DECODE_QUANTISER_SCALE) | \n                                          ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:79: Define or directive not defined: \'`SLICE_DECODE_EXTRA_BIT_SLICE\'\n   (state == `SLICE_DECODE_EXTRA_BIT_SLICE);\n             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:81: Define or directive not defined: \'`SLICE_DECODE_IDLE\'\nassign Done_Slice_Decode_O = (state == `SLICE_DECODE_IDLE);\n                                       ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:81: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\nassign Done_Slice_Decode_O = (state == `SLICE_DECODE_IDLE);\n                                                         ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:83: Define or directive not defined: \'`SLICE_DECODE_EXTRA_BIT_SLICE\'\nassign Slice_Buffer_Value_O = (state == `SLICE_DECODE_EXTRA_BIT_SLICE) ? \n                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:83: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\nassign Slice_Buffer_Value_O = (state == `SLICE_DECODE_EXTRA_BIT_SLICE) ? \n                                                                     ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:84: Define or directive not defined: \'`INFO_SLICE_QUANT\'\n   {`INFO_SLICE_QUANT,13\'h0000,Quantiser_Scale} : Macroblock_Buffer_Value;\n    ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:86: Define or directive not defined: \'`SLICE_DECODE_EXTRA_BIT_SLICE\'\n   (state == `SLICE_DECODE_EXTRA_BIT_SLICE) | Macroblock_Buffer_Write_En;\n             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:86: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n   (state == `SLICE_DECODE_EXTRA_BIT_SLICE) | Macroblock_Buffer_Write_En;\n                                          ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:90: Define or directive not defined: \'`SLICE_DECODE_IDLE\'\n      state <= `SLICE_DECODE_IDLE;\n               ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:90: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      state <= `SLICE_DECODE_IDLE;\n                                 ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:96: Define or directive not defined: \'`SLICE_DECODE_IDLE\'\n         `SLICE_DECODE_IDLE : begin\n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:96: syntax error, unexpected \':\', expecting endcase\n         `SLICE_DECODE_IDLE : begin\n                            ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:99: Define or directive not defined: \'`SLICE_DECODE_START_CODE\'\n                  state <= `SLICE_DECODE_START_CODE;\n                           ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:99: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n                  state <= `SLICE_DECODE_START_CODE;\n                                                   ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:102: Define or directive not defined: \'`SLICE_DECODE_START_CODE\'\n         `SLICE_DECODE_START_CODE : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:102: syntax error, unexpected begin, expecting IDENTIFIER or PACKAGE-IDENTIFIER or TYPE-IDENTIFIER or new\n         `SLICE_DECODE_START_CODE : begin\n                                    ^~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:105: Define or directive not defined: \'`SLICE_DECODE_QUANTISER_SCALE\'\n                  state <= `SLICE_DECODE_QUANTISER_SCALE;\n                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:105: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n                  state <= `SLICE_DECODE_QUANTISER_SCALE;\n                                                        ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:108: Define or directive not defined: \'`SLICE_DECODE_QUANTISER_SCALE\'\n         `SLICE_DECODE_QUANTISER_SCALE : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:112: syntax error, unexpected <=, expecting IDENTIFIER\n                     state <= `SLICE_DECODE_EXTRA_INFO;\n                           ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:112: Define or directive not defined: \'`SLICE_DECODE_EXTRA_INFO\'\n                     state <= `SLICE_DECODE_EXTRA_INFO;\n                              ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:114: syntax error, unexpected <=, expecting IDENTIFIER\n                     state <= `SLICE_DECODE_EXTRA_BIT_SLICE;\n                           ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:114: Define or directive not defined: \'`SLICE_DECODE_EXTRA_BIT_SLICE\'\n                     state <= `SLICE_DECODE_EXTRA_BIT_SLICE;\n                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:116: syntax error, unexpected <=, expecting IDENTIFIER\n               end else shift_counter <= shift_counter - 1;\n                                      ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:118: Define or directive not defined: \'`SLICE_DECODE_EXTRA_INFO\'\n         `SLICE_DECODE_EXTRA_INFO : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:119: Define or directive not defined: \'`SLICE_DECODE_IDLE\'\n               state <= `SLICE_DECODE_IDLE;\n                        ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:121: Define or directive not defined: \'`SLICE_DECODE_EXTRA_BIT_SLICE\'\n         `SLICE_DECODE_EXTRA_BIT_SLICE : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:122: Define or directive not defined: \'`SLICE_DECODE_MACROBLOCKS_WAIT\'\n               state <= `SLICE_DECODE_MACROBLOCKS_WAIT;\n                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:124: Define or directive not defined: \'`SLICE_DECODE_MACROBLOCKS_WAIT\'\n         `SLICE_DECODE_MACROBLOCKS_WAIT : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:127: Define or directive not defined: \'`SLICE_DECODE_MACROBLOCKS\'\n                  state <= `SLICE_DECODE_MACROBLOCKS;\n                           ^~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:130: Define or directive not defined: \'`SLICE_DECODE_MACROBLOCKS\'\n         `SLICE_DECODE_MACROBLOCKS : begin\n         ^~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:134: syntax error, unexpected <=, expecting IDENTIFIER\n                     if (~Slice_Buffer_Full_I) Macroblock_Start <= 1\'b1;\n                                                                ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:135: syntax error, unexpected <=, expecting IDENTIFIER\n                     else state <= `SLICE_DECODE_MACROBLOCKS_WAIT;\n                                ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:135: Define or directive not defined: \'`SLICE_DECODE_MACROBLOCKS_WAIT\'\n                     else state <= `SLICE_DECODE_MACROBLOCKS_WAIT;\n                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:137: syntax error, unexpected <=, expecting IDENTIFIER\n                     state <= `SLICE_DECODE_IDLE;\n                           ^~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:137: Define or directive not defined: \'`SLICE_DECODE_IDLE\'\n                     state <= `SLICE_DECODE_IDLE;\n                              ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:140: syntax error, unexpected end\n            end\n            ^~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:151: Define or directive not defined: \'`PREDICTOR_RESET\'\n      Y_Predictor <= `PREDICTOR_RESET;\n                     ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:151: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      Y_Predictor <= `PREDICTOR_RESET;\n                                     ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:152: Define or directive not defined: \'`PREDICTOR_RESET\'\n      Cb_Predictor <= `PREDICTOR_RESET;\n                      ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:152: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      Cb_Predictor <= `PREDICTOR_RESET;\n                                      ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:153: Define or directive not defined: \'`PREDICTOR_RESET\'\n      Cr_Predictor <= `PREDICTOR_RESET;\n                      ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:153: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      Cr_Predictor <= `PREDICTOR_RESET;\n                                      ^\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:155: Define or directive not defined: \'`PREDICTOR_RESET\'\n      Y_Predictor <= `PREDICTOR_RESET;\n                     ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/502764644/mpeg_audio_video/Sequence_Decode/Slice_Decode/Slice_Decode.v:155: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      Y_Predictor <= `PREDICTOR_RESET;\n                                     ^\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module Slice_Decode(
   resetn,
   clock,

   Start_Slice_Decode_I,
   Done_Slice_Decode_O,
   
   Data_In_I,
   Shift_1_En_O,
   Shift_8_En_O,

   Start_Code_Upcoming_I,
   
   Slice_Buffer_Value_O,
   Slice_Buffer_Write_En_O,
   Slice_Buffer_Full_I,

   Picture_Type_I,
 	Picture_Structure_I,
	Intra_VLC_Format_I,
	Frame_Pred_Frame_DCT_I,
	Concealment_Vectors_I,
	F_Codes_I
);

input                resetn;
input                clock;

input                Start_Slice_Decode_I;
output               Done_Slice_Decode_O;

input    [1:0]       Data_In_I;
output               Shift_1_En_O;
output               Shift_8_En_O;

input                Start_Code_Upcoming_I;

output   [31:0]      Slice_Buffer_Value_O;
output               Slice_Buffer_Write_En_O;
input                Slice_Buffer_Full_I;

input 	[1:0]		   Picture_Type_I;
input 	[1:0]		 	Picture_Structure_I;
input 					Intra_VLC_Format_I;
input 					Frame_Pred_Frame_DCT_I;
input 					Concealment_Vectors_I;
input 	[15:0]		F_Codes_I;

reg      [2:0]       state;
reg      [2:0]       shift_counter;
reg      [4:0]       Quantiser_Scale;

reg                  Macroblock_Start;
wire                 Macroblock_Done;
wire                 Macroblock_Shift_En;
wire     [31:0]      Macroblock_Buffer_Value;
wire                 Macroblock_Buffer_Write_En;

assign Shift_8_En_O = (state == `SLICE_DECODE_START_CODE);
assign Shift_1_En_O = Macroblock_Shift_En | 
   (state == `SLICE_DECODE_QUANTISER_SCALE) | 
   (state == `SLICE_DECODE_EXTRA_BIT_SLICE);
                      
assign Done_Slice_Decode_O = (state == `SLICE_DECODE_IDLE);

assign Slice_Buffer_Value_O = (state == `SLICE_DECODE_EXTRA_BIT_SLICE) ? 
   {`INFO_SLICE_QUANT,13'h0000,Quantiser_Scale} : Macroblock_Buffer_Value;
assign Slice_Buffer_Write_En_O = 
   (state == `SLICE_DECODE_EXTRA_BIT_SLICE) | Macroblock_Buffer_Write_En;

always @(posedge clock or negedge resetn) begin
   if (~resetn) begin
      state <= `SLICE_DECODE_IDLE;
      shift_counter <= 3'h0;
      Quantiser_Scale <= 5'h00;
      Macroblock_Start <= 1'b0;
   end else begin
      case(state) 
         `SLICE_DECODE_IDLE : begin
               if (Start_Slice_Decode_I) begin
                  shift_counter <= 3'h3;
                  state <= `SLICE_DECODE_START_CODE;
               end
            end
         `SLICE_DECODE_START_CODE : begin
               if (shift_counter == 3'h0) begin
                  shift_counter <= 3'h4;
                  state <= `SLICE_DECODE_QUANTISER_SCALE;
               end else shift_counter <= shift_counter - 1;
            end
         `SLICE_DECODE_QUANTISER_SCALE : begin
               Quantiser_Scale <= {Quantiser_Scale[3:0],Data_In_I[1]};
               if (shift_counter == 3'h0) begin
                  if (Data_In_I[0] == 1'b1) begin
                     state <= `SLICE_DECODE_EXTRA_INFO;
                  end else begin
                     state <= `SLICE_DECODE_EXTRA_BIT_SLICE;
                  end
               end else shift_counter <= shift_counter - 1;
            end
         `SLICE_DECODE_EXTRA_INFO : begin
               state <= `SLICE_DECODE_IDLE;
            end
         `SLICE_DECODE_EXTRA_BIT_SLICE : begin
               state <= `SLICE_DECODE_MACROBLOCKS_WAIT;
            end
         `SLICE_DECODE_MACROBLOCKS_WAIT : begin
               if (~Slice_Buffer_Full_I) begin
                  Macroblock_Start <= 1'b1;
                  state <= `SLICE_DECODE_MACROBLOCKS;
               end
            end
         `SLICE_DECODE_MACROBLOCKS : begin
               Macroblock_Start <= 1'b0;
               if (~Macroblock_Start & Macroblock_Done) begin
                  if (~Start_Code_Upcoming_I) begin
                     if (~Slice_Buffer_Full_I) Macroblock_Start <= 1'b1;
                     else state <= `SLICE_DECODE_MACROBLOCKS_WAIT;
                  end else begin
                     state <= `SLICE_DECODE_IDLE;
                  end
               end
            end
      endcase
   end
end

reg      [11:0]      Y_Predictor, Cb_Predictor, Cr_Predictor;
wire     [11:0]      New_Y_Predictor, New_Cb_Predictor, New_Cr_Predictor;
wire                 Update_Y_Predictor, Update_Cb_Predictor, Update_Cr_Predictor;

always @(posedge clock or negedge resetn) begin
   if (~resetn) begin
      Y_Predictor <= `PREDICTOR_RESET;
      Cb_Predictor <= `PREDICTOR_RESET;
      Cr_Predictor <= `PREDICTOR_RESET;
   end else if (Start_Slice_Decode_I) begin
      Y_Predictor <= `PREDICTOR_RESET;
      Cb_Predictor <= `PREDICTOR_RESET;
      Cr_Predictor <= `PREDICTOR_RESET;
   end else begin
      if (Update_Y_Predictor) Y_Predictor <= New_Y_Predictor;
      if (Update_Cb_Predictor) Cb_Predictor <= New_Cb_Predictor;
      if (Update_Cr_Predictor) Cr_Predictor <= New_Cr_Predictor;
   end
end

Macroblock_Decode Macroblock_Decoder(
   .resetn(resetn),
   .clock(clock),
   .Start_Macroblock_Decode_I(Macroblock_Start),
   .Done_Macroblock_Decode_O(Macroblock_Done),
   .Data_In_I(Data_In_I[1]),
   .Shift_En_O(Macroblock_Shift_En),
   .Y_Predictor_I(Y_Predictor), 
   .New_Y_Predictor_O(New_Y_Predictor), 
   .Update_Y_Predictor_O(Update_Y_Predictor),
   .Cb_Predictor_I(Cb_Predictor), 
   .New_Cb_Predictor_O(New_Cb_Predictor), 
   .Update_Cb_Predictor_O(Update_Cb_Predictor),
   .Cr_Predictor_I(Cr_Predictor), 
   .New_Cr_Predictor_O(New_Cr_Predictor),
   .Update_Cr_Predictor_O(Update_Cr_Predictor),
   .Buffer_Value_O(Macroblock_Buffer_Value),
   .Buffer_Write_En_O(Macroblock_Buffer_Write_En),
   .Picture_Type_I(Picture_Type_I),
 	.Picture_Structure_I(Picture_Structure_I),
	.Intra_VLC_Format_I(Intra_VLC_Format_I),
	.Frame_Pred_Frame_DCT_I(Frame_Pred_Frame_DCT_I),
	.Concealment_Vectors_I(Concealment_Vectors_I),
	.F_Codes_I(F_Codes_I)
);

endmodule
module Slice_Decode(
   resetn,
   clock,

   Start_Slice_Decode_I,
   Done_Slice_Decode_O,
   
   Data_In_I,
   Shift_1_En_O,
   Shift_8_En_O,

   Start_Code_Upcoming_I,
   
   Slice_Buffer_Value_O,
   Slice_Buffer_Write_En_O,
   Slice_Buffer_Full_I,

   Picture_Type_I,
 	Picture_Structure_I,
	Intra_VLC_Format_I,
	Frame_Pred_Frame_DCT_I,
	Concealment_Vectors_I,
	F_Codes_I
);


input                resetn;
input                clock;

input                Start_Slice_Decode_I;
output               Done_Slice_Decode_O;

input    [1:0]       Data_In_I;
output               Shift_1_En_O;
output               Shift_8_En_O;

input                Start_Code_Upcoming_I;

output   [31:0]      Slice_Buffer_Value_O;
output               Slice_Buffer_Write_En_O;
input                Slice_Buffer_Full_I;

input 	[1:0]		   Picture_Type_I;
input 	[1:0]		 	Picture_Structure_I;
input 					Intra_VLC_Format_I;
input 					Frame_Pred_Frame_DCT_I;
input 					Concealment_Vectors_I;
input 	[15:0]		F_Codes_I;

reg      [2:0]       state;
reg      [2:0]       shift_counter;
reg      [4:0]       Quantiser_Scale;

reg                  Macroblock_Start;
wire                 Macroblock_Done;
wire                 Macroblock_Shift_En;
wire     [31:0]      Macroblock_Buffer_Value;
wire                 Macroblock_Buffer_Write_En;

assign Shift_8_En_O = (state == `SLICE_DECODE_START_CODE);
assign Shift_1_En_O = Macroblock_Shift_En | 
   (state == `SLICE_DECODE_QUANTISER_SCALE) | 
   (state == `SLICE_DECODE_EXTRA_BIT_SLICE);
                      
assign Done_Slice_Decode_O = (state == `SLICE_DECODE_IDLE);

assign Slice_Buffer_Value_O = (state == `SLICE_DECODE_EXTRA_BIT_SLICE) ? 
   {`INFO_SLICE_QUANT,13'h0000,Quantiser_Scale} : Macroblock_Buffer_Value;
assign Slice_Buffer_Write_En_O = 
   (state == `SLICE_DECODE_EXTRA_BIT_SLICE) | Macroblock_Buffer_Write_En;

always @(posedge clock or negedge resetn) begin
   if (~resetn) begin
      state <= `SLICE_DECODE_IDLE;
      shift_counter <= 3'h0;
      Quantiser_Scale <= 5'h00;
      Macroblock_Start <= 1'b0;
   end else begin
      case(state) 
         `SLICE_DECODE_IDLE : begin
               if (Start_Slice_Decode_I) begin
                  shift_counter <= 3'h3;
                  state <= `SLICE_DECODE_START_CODE;
               end
            end
         `SLICE_DECODE_START_CODE : begin
               if (shift_counter == 3'h0) begin
                  shift_counter <= 3'h4;
                  state <= `SLICE_DECODE_QUANTISER_SCALE;
               end else shift_counter <= shift_counter - 1;
            end
         `SLICE_DECODE_QUANTISER_SCALE : begin
               Quantiser_Scale <= {Quantiser_Scale[3:0],Data_In_I[1]};
               if (shift_counter == 3'h0) begin
                  if (Data_In_I[0] == 1'b1) begin
                     state <= `SLICE_DECODE_EXTRA_INFO;
                  end else begin
                     state <= `SLICE_DECODE_EXTRA_BIT_SLICE;
                  end
               end else shift_counter <= shift_counter - 1;
            end
         `SLICE_DECODE_EXTRA_INFO : begin
               state <= `SLICE_DECODE_IDLE;
            end
         `SLICE_DECODE_EXTRA_BIT_SLICE : begin
               state <= `SLICE_DECODE_MACROBLOCKS_WAIT;
            end
         `SLICE_DECODE_MACROBLOCKS_WAIT : begin
               if (~Slice_Buffer_Full_I) begin
                  Macroblock_Start <= 1'b1;
                  state <= `SLICE_DECODE_MACROBLOCKS;
               end
            end
         `SLICE_DECODE_MACROBLOCKS : begin
               Macroblock_Start <= 1'b0;
               if (~Macroblock_Start & Macroblock_Done) begin
                  if (~Start_Code_Upcoming_I) begin
                     if (~Slice_Buffer_Full_I) Macroblock_Start <= 1'b1;
                     else state <= `SLICE_DECODE_MACROBLOCKS_WAIT;
                  end else begin
                     state <= `SLICE_DECODE_IDLE;
                  end
               end
            end
      endcase
   end
end

reg      [11:0]      Y_Predictor, Cb_Predictor, Cr_Predictor;
wire     [11:0]      New_Y_Predictor, New_Cb_Predictor, New_Cr_Predictor;
wire                 Update_Y_Predictor, Update_Cb_Predictor, Update_Cr_Predictor;

always @(posedge clock or negedge resetn) begin
   if (~resetn) begin
      Y_Predictor <= `PREDICTOR_RESET;
      Cb_Predictor <= `PREDICTOR_RESET;
      Cr_Predictor <= `PREDICTOR_RESET;
   end else if (Start_Slice_Decode_I) begin
      Y_Predictor <= `PREDICTOR_RESET;
      Cb_Predictor <= `PREDICTOR_RESET;
      Cr_Predictor <= `PREDICTOR_RESET;
   end else begin
      if (Update_Y_Predictor) Y_Predictor <= New_Y_Predictor;
      if (Update_Cb_Predictor) Cb_Predictor <= New_Cb_Predictor;
      if (Update_Cr_Predictor) Cr_Predictor <= New_Cr_Predictor;
   end
end

Macroblock_Decode Macroblock_Decoder(
   .resetn(resetn),
   .clock(clock),
   .Start_Macroblock_Decode_I(Macroblock_Start),
   .Done_Macroblock_Decode_O(Macroblock_Done),
   .Data_In_I(Data_In_I[1]),
   .Shift_En_O(Macroblock_Shift_En),
   .Y_Predictor_I(Y_Predictor), 
   .New_Y_Predictor_O(New_Y_Predictor), 
   .Update_Y_Predictor_O(Update_Y_Predictor),
   .Cb_Predictor_I(Cb_Predictor), 
   .New_Cb_Predictor_O(New_Cb_Predictor), 
   .Update_Cb_Predictor_O(Update_Cb_Predictor),
   .Cr_Predictor_I(Cr_Predictor), 
   .New_Cr_Predictor_O(New_Cr_Predictor),
   .Update_Cr_Predictor_O(Update_Cr_Predictor),
   .Buffer_Value_O(Macroblock_Buffer_Value),
   .Buffer_Write_En_O(Macroblock_Buffer_Write_En),
   .Picture_Type_I(Picture_Type_I),
 	.Picture_Structure_I(Picture_Structure_I),
	.Intra_VLC_Format_I(Intra_VLC_Format_I),
	.Frame_Pred_Frame_DCT_I(Frame_Pred_Frame_DCT_I),
	.Concealment_Vectors_I(Concealment_Vectors_I),
	.F_Codes_I(F_Codes_I)
);

endmodule