fill.nogap 8.74 KB

// $Id: fill.nogap,v 1.1 2002/05/21 23:55:43 berndt Exp $

`timescale 1ns/1ns

module ms_driver;

//`include "reality.vh"
`include "ms.vh"

//must add:  .pipe_busy(pipe_busy) 

wire clock;
wire reset_l;

//wire [55:0] other_modes;
//wire [55:0] color_image;
//wire [25:0] z_image;              //z_base
//wire [55:0] tex_image;
//wire [1:0] cbus_select;
//wire [2:0] cbus_command;
//wire [31:0] fill_color;
//wire [7:0] blend_color;
//wire [8:6] noise;   
//wire [17:0] span_z;              //rdpwdepthin
//wire [7:0] span_r, span_g, span_b;       //rdpwredin etc
//wire [2:0] span_a;               //rdpwalphain
//wire [7:0] pixel_a;               //ccalpha


reg [9:0] count1;		//counter for startspant0 delay vs. spanbufmt
reg [9:0] count;		//nonstallable counter for run time

reg cbus_read_enable;		// to be added to ms
reg cbus_write_enable;
reg [1:0] cbus_select;	// to be added to ms
reg [2:0] cbus_command;	// to be added to ms
reg grant;                    //dma grant
reg start;                    //dma data valid
reg finish;                   //dma read last cycle
reg read_grant;               // to be added to ms
reg dma_write_enable;             //tristate dma data out enable
reg dma_read_enable;
reg strobe_sync_full;
reg freeze;
reg unfreeze;

reg [55:0] other_modes;
//reg other_modes[54:54];         //dithrgben
//reg other_modes[53:52];		//cycle_type
//reg other_modes[47:47];         //load_tlut_en
//reg other_modes[6:6];		//image_read_en
//reg other_modes[5:5];		//z_update_en
//reg other_modes[4:4];		//z_compare_en
//reg other_modes[1:1];           //dithalphaen
//reg other_modes[0:0];           //alphacompen

reg [55:0] color_image;
//reg color_image[25:0];		//color_base
//reg color_image[52:51];		//color_size
//reg color_image[55:53];		//color_format

reg [25:0] z_image;		//z_base

reg [55:0] tex_image;
//reg tex_image[25:0];		//tex_base
//reg tex_image[52:51];		//tex_size
//reg tex_image[55:53];		//tex_format

reg [31:0] fill_color;
reg [7:0] blend_color;		//blendalpha
reg [8:6] noise;			//noise
reg startspant0;
reg [19:0] nextspanxi;
reg [11:0] nextspanxf;
reg [11:0] nextspancount;
reg nextspanxdec;
reg load_en;
reg spanbufmt;
reg [17:0] span_z;		//rdpwdepthin
reg [7:0] span_r, span_g, span_b;	//rdpwredin etc
reg [2:0] span_a;		//rdpwalphain
reg span_color_we;		//rdpcolorwen
reg [7:0] pixel_a;		//ccalpha
reg gclock_en;
reg gclock;

//later:  figure out how to set tristate bus (weak pullup/down's?)

//inouts:

wire [31:0] cbus_data;
wire [63:0] dbus_data;
wire [7:0] ebus_data;
wire [63:0] copy_load;

wire [7:0] mem_r;
wire [7:0] mem_g;
wire [7:0] mem_b;
wire [2:0] mem_a;
wire [17:0] mem_z;

ms ms (	.clock(clock), .gclock(gclock), .reset_l(reset_l),
	.cbus_read_enable(cbus_read_enable), .cbus_select(cbus_select),
	.cbus_command(cbus_command), .cbus_write_enable(cbus_write_enable),
	.grant(grant), .start(start), .finish(finish),
	.read_grant(read_grant), .dma_read_enable(dma_read_enable),
	.dma_write_enable(dma_write_enable), .stb_sync_full(strobe_sync_full),
	.freeze_gclk(freeze), .unfreeze_gclk(unfreeze),
        .cycle_type(other_modes[53:52]), .image_read_en(other_modes[6]),
	.z_update_en(other_modes[5]), .z_compare_en(other_modes[4]),
	.color_base(color_image[25:0]), .color_size(color_image[52:51]),
	.color_format(color_image[55:53]),
	.z_base(z_image[25:0]),
	.tex_base(tex_image[25:0]), .tex_size(tex_image[52:51]),
	.tex_format(tex_image[55:53]),
        .load_tlut_en(other_modes[47]), .fillcolor(fill_color[31:0]),
	.alphacompen(other_modes[0]), .dithalphaen(other_modes[1]),
	.blendalpha(blend_color[7:0]), .noise(noise[8:6]),
	.startspant0(startspant0),
	.nextspanxi(nextspanxi), .nextspanxf(nextspanxf),
	.nextspancount(nextspancount), .nextspanxdec(nextspanxdec),
        .load_en(load_en), .spanbufmt(spanbufmt),
	.rdpwdepthin(span_z), .rdpwredin(span_r), .rdpwgreenin(span_g),
	.rdpwbluein(span_b), .rdpwalphain(span_a),
	.rdpcolorwen(span_color_we), .ccalpha(pixel_a[7:0]),
	.dithrgben(other_modes[54]),

	.cbus_data(cbus_data), .dbus_data(dbus_data), .ebus_data(ebus_data), 
	.copy_load(copy_load),

	.load_dv(load_dv), .rel_sync_full(rel_sync_full),
        .stopgclock(stopgclock), .rdramreq(rdramreq), .rdramrw(rdramrw),
	.pipe_busy(pipe_busy), .read_request(read_request),
	.spanbufrd(spanbufrd),
	.rdprred(mem_r), .rdprgreen(mem_g), .rdprblue(mem_b),
	.rdpralpha(mem_a), .rdprdepthd(mem_z));

cg cg(clock, reset_l);

always @(gclock_en or clock) begin
	gclock <= clock & gclock_en;
end

always @(negedge clock or negedge reset_l) begin
	if (!reset_l) begin
		gclock_en <= high;
	end
	else if (reset_l & !clock) begin
		gclock_en <= !stopgclock;
	end
	else begin
		gclock_en <= gclock_en;
	end
end

always @(posedge clock or negedge reset_l) begin

  if (!reset_l) begin
	cbus_select <= low;
	cbus_command <= low;
	cbus_read_enable <= low;
	cbus_write_enable <= low;
	grant <= high;
	start <= high;
	finish <= low;
	read_grant <= low;
	dma_write_enable <= high;
	dma_read_enable <= low;
	strobe_sync_full <= low;
	freeze <= low;
	unfreeze <= low;
	other_modes[54:54] <= low;
	other_modes[53:52] <= 2'h3;		//1cy, 2cy, copy, fill
	other_modes[47:47] <= low;		//load_tlut_en
	other_modes[6:6] <= low;		//image_read_en
	other_modes[5:5] <= low;
	other_modes[4:4] <= low;
	other_modes[1:1] <= low;
	other_modes[0:0] <= low;

	color_image[25:0] <= 26'h1000;
	color_image[52:51] <= 2'h1;		//4,8,16,32b
	color_image[55:53] <= 3'h4;		//rgba,yuv,ci,ia,I
	z_image <= 26'h1000;
	tex_image[25:0] <= 26'h1000;
	tex_image[52:51] <= 2'h1;         //4,8,16,32b
	tex_image[55:53] <= 3'h4;             //rgba,yuv,ci,ia,I
	
	fill_color <= 32'hdeadbeef;
	blend_color <= low;
	noise <= low;
	load_en <= low;
	span_z <= low;
	span_r <= low;
	span_g <= low;
	span_b <= low;
	span_a <= low;
	span_color_we <= low;
	pixel_a <= low;
//      nextspanxi <= 20'h100;
//      nextspanxf <= 12'h200;
//      nextspanxdec <= low;
//      nextspancount <= 12'h100;
        startspant0 <= low;
	count1 <= low;
	count <= low;
	spanbufmt <= high;
end
else if (reset_l) begin


//	nextspanxi <= 20'h100;
//	nextspanxf <= 12'h200;
//	nextspanxdec <= low;
//	nextspancount <= 12'h100;

if (count1 == 1) begin
	spanbufmt <= #5 low;
        nextspanxi <= #5 20'h1ff;
        nextspanxf <= #5 12'h1ff;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h0;
        color_image[52:51] <= #5 2'h1;             //4,8,16,32b
end
else if (count1 == 10) begin
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h1ff;
        nextspanxf <= #5 12'h1ff;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h0;
        color_image[52:51] <= #5 2'h2;             //4,8,16,32b
end
else if (count1 == 19) begin
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h241;
        nextspanxf <= #5 12'h241;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h0;
        color_image[52:51] <= #5 2'h3;             //4,8,16,32b
end
else if (count1 == 28) begin
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h290;
        nextspanxf <= #5 12'h2d0;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h40;
        color_image[52:51] <= #5 2'h1;             //4,8,16,32b
end
else if (count1 == 37) begin
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h1ff;
        nextspanxf <= #5 12'h300;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h101;
        color_image[52:51] <= #5 2'h1;             //4,8,16,32b
end
else if (count1 == 71) begin
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h377;
        nextspanxf <= #5 12'h601;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h28a;
        color_image[52:51] <= #5 2'h1;             //4,8,16,32b
end
else if (count1 == 170) begin
//        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h133;
        nextspanxf <= #5 12'h175;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h42;
        color_image[52:51] <= #5 2'h2;             //4,8,16,32b
end
else begin
        spanbufmt <= #5 high;
        nextspanxi <= #5 nextspanxi;
        nextspanxf <= #5 nextspanxf;
        nextspanxdec <= #5 nextspanxdec;
        nextspancount <= #5 nextspancount;
end

//if (!stopgclock) begin
        startspant0 <= #5 ((count1 == 10'd5) || (count1 == 10'd14) ||
			(count1 == 10'd23) || (count1 == 10'd32) ||
			(count1 == 10'd41) || (count1 == 10'd75) ||
			(count1 == 10'd160));

	strobe_sync_full <= #5 (count1 == 10'd167);
//end
//else begin
	startspant0 <= startspant0;
//
//end

//hack to get rdctxt stall not forever

//if (count == 10'd238) begin
//	spanbufmt <= #5 low;
//       nextspanxi <= #5 20'h133;
//      nextspanxf <= #5 12'h175;
//     nextspanxdec <= #5 low;
//    nextspancount <= #5 12'h42;
//   color_image[52:51] <= #5 2'h2;             //4,8,16,32b
//end

        count <=  count + 1;

if (!stopgclock) begin
	count1 <=  count1 + 1;
end
else begin
	count1 <= #5 count1;
end

if (count == 300) begin
$finish;
end

end
end
endmodule //