load.init 9.58 KB

// $Id: load.init,v 1.1.1.1 2002/05/17 06:07:48 blythe 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;

//assign ebus_data = 8'hff;
//assign dbus_data = 64'hdeadbeefdeadbeef;

assign ebus_data = 8'he4;
assign dbus_data = {8{count[7:0]}};

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 <= low;
	start <= low;
	finish <= low;
	read_grant <= low;
	dma_write_enable <= low;
	dma_read_enable <= high;
	strobe_sync_full <= low;
	freeze <= low;
	unfreeze <= low;
	other_modes[54:54] <= low;		//dithrgben
	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;		//z update en
	other_modes[4:4] <= low;		//z compare en
	other_modes[1:1] <= low;		//dith alpha en
	other_modes[0:0] <= low;		//alpha compare en

	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'h3000;
	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 == 10) begin
	load_en <= high;
	spanbufmt <= #5 low;
        nextspanxi <= #5 20'h1ff;
        nextspanxf <= #5 12'h1ff;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h0;
        tex_image[52:51] <= #5 2'h1;             //4,8,16,32b
end
else if (count1 == 50) begin
        load_en <= high;
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h1ff;
        nextspanxf <= #5 12'h200;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h1;
        tex_image[52:51] <= #5 2'h2;             //4,8,16,32b
end
else if (count1 == 70) begin
        load_en <= high;
        spanbufmt <= #5 low;
        nextspanxi <= #5 20'h100;
        nextspanxf <= #5 12'h180;
        nextspanxdec <= #5 low;
        nextspancount <= #5 12'h80;
        tex_image[52:51] <= #5 2'h1;             //4,8,16,32b
end
else if (count1 == 11119) 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 == 11128) 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 == 11137) 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 == 11171) 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 == 111170) 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
	load_en <= low;
        spanbufmt <= #5 high;
        nextspanxi <= #5 nextspanxi;
        nextspanxf <= #5 nextspanxf;
        nextspanxdec <= #5 nextspanxdec;
        nextspancount <= #5 nextspancount;
end

//if (!stopgclock) begin
        startspant0 <= #5 ((count1 == 10'd20) || (count1 == 10'd60)
		|| (count1 == 10'd80));

	grant <= ((count == 10'd20) || (count == 10'd58) ||
		(count == 10'd70) || (count == 10'd150) || (count == 10'd170) || (count == 10'd200));
	start <= ((count == 10'd22) || (count == 10'd60) ||
		(count == 10'd72) || (count == 10'd152) || (count == 10'd172) || (count == 10'd202));
	finish <= ((count == 10'd22) || (count == 10'd60) ||
		(count == 10'd72) || (count == 10'd159) || (count == 10'd179) || (count == 10'd202));
//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 //