OpenCores
URL https://opencores.org/ocsvn/pdp1/pdp1/trunk

Subversion Repositories pdp1

[/] [pdp1/] [trunk/] [rtl/] [verilog/] [vector2scanline.v] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 yannv
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Engineer: Yann Vernier
4
// 
5
// Create Date:    21:37:32 02/19/2011 
6
// Design Name: 
7
// Module Name:    vector2scanline 
8
// Project Name: PDP-1
9
// Target Devices: Spartan 3A
10
// Tool versions: 
11
// Description: Converts vector data (exposed points) into raster video
12
//
13
// Dependencies: 
14
//
15 5 yannv
// Revision: $Id$
16
// $Log$
17
// Additional Comments: 
18
//
19 3 yannv
//////////////////////////////////////////////////////////////////////////////////
20
 
21
module vector2scanline(
22 5 yannv
                       clk_i,          // clock
23 3 yannv
 
24 5 yannv
                       strobe_i,      // new exposed pixel trigger
25
                       x_i,          // column of exposed pixel
26
                       y_i,          // row of exposed pixel
27 3 yannv
 
28 4 yannv
                       // Video output interface
29 5 yannv
                       xout_i,   // current pixel column
30
                       yout_i,   // current pixel row
31
                       newline_i,      // line buffer swap signal
32
                       newframe_i,     // new frame signal
33
                       pixel_o  // output pixel intensity
34
                       /*AUTOARG*/);
35 3 yannv
 
36 5 yannv
 
37 4 yannv
   parameter X_WIDTH = 10;     // bit width of column coordinate
38
   parameter Y_WIDTH = 10;     // bit width of row coordinate
39
   parameter HIST_WIDTH = 10;  // log2 of maximum lit pixels (exposure buffer)
40
   parameter AGE_WIDTH = 8;    // width of exposure age counter
41 5 yannv
 
42
   input clk_i;
43
 
44
   input strobe_i;
45
   input [X_WIDTH-1:0] x_i;
46
   input [Y_WIDTH-1:0] y_i;
47 3 yannv
 
48 5 yannv
   input [X_WIDTH-1:0] xout_i;
49
   input [Y_WIDTH-1:0] yout_i;
50
   input               newline_i, newframe_i;
51
   output [AGE_WIDTH-1:0] pixel_o;
52
 
53 4 yannv
   // positions and age of lit pixels
54
   reg [X_WIDTH+Y_WIDTH+AGE_WIDTH-1:0] exposures [(2**HIST_WIDTH)-1:0];
55
   // output register of exposed pixels buffer
56
   reg [X_WIDTH+Y_WIDTH+AGE_WIDTH-1:0] expr;
57
   // data for next pixel to store in exposure buffer
58
   wire [X_WIDTH-1:0]                   expx;
59
   wire [Y_WIDTH-1:0]                   expy;
60 5 yannv
   wire [AGE_WIDTH-1:0]         expi;
61 4 yannv
   // whether this pixel needs to be stored back in exposure buffer
62
   wire                                exposed;
63 5 yannv
   // whether this pixel belongs to the next (backbuffer) scanline
64
   wire                                rowmatch;
65 4 yannv
   // addresses for exposure buffer read and write ports
66
   reg [HIST_WIDTH-1:0]         exprptr=0, expwptr=0;
67 5 yannv
 
68 4 yannv
   // scanline pixel buffers, store intensity
69
   // double-buffered; one gets wiped as it is displayed
70
   // the other gets filled in with current exposures
71
   reg [AGE_WIDTH-1:0]                  scanline0 [(2**X_WIDTH)-1:0];
72
   reg [AGE_WIDTH-1:0]                  scanline1 [(2**X_WIDTH)-1:0];
73
   // output intensity for current pixel
74
   reg [AGE_WIDTH-1:0]                  pixelout;
75
   // selection register for which scanline buffer is output/filled in
76
   reg                                 bufsel = 0;
77
   // address lines for scanline buffers
78
   wire [X_WIDTH-1:0]                   sl0w, sl1w;
79 5 yannv
 
80 4 yannv
   // RAM read out of exposure buffer
81 5 yannv
   always @(posedge clk_i) begin
82 4 yannv
      expr<=exposures[exprptr];
83
      if (!strobe) begin
84
         // do not skip current read position if strobe inserts a new pixel
85
         exprptr<=exprptr+1;
86
      end
87
   end
88 3 yannv
 
89 4 yannv
   // decode and mux: split fields from exposure buffer, or collect new at strobe
90 5 yannv
   assign expx = strobe_i?x_i:expr[X_WIDTH+Y_WIDTH+AGE_WIDTH-1:Y_WIDTH+AGE_WIDTH];
91
   assign expy = strobe_i?y_i:expr[Y_WIDTH+AGE_WIDTH-1:AGE_WIDTH];
92
   assign expi = strobe_i?(2**AGE_WIDTH)-1:expr[AGE_WIDTH-1:0];
93 4 yannv
   // detect whether pixel even needs to be stored back
94
   assign exposed = expi!=0;
95 5 yannv
   // detect whether pixel applies to current backbuffer
96
      // TODO: use a next line input port, this incrementer won't work for
97
      // line 0 (which is unused in display.vhd) and could be shared.
98
   assign rowmatch=(expy==y_i+1);
99 4 yannv
 
100 5 yannv
   always @(posedge clk_i) begin
101 4 yannv
      // Feed incoming exposures into exposure buffer
102
      if (exposed) begin
103 5 yannv
         exposures[expwptr] <= {expx, expy, expy==yout_i?expi-1:expi};
104 4 yannv
         expwptr <= expwptr+1;
105
      end
106
   end
107 5 yannv
 
108
   // scanline buffers switch output or expose roles based on bufsel
109
   assign sl0w=bufsel?expx:xout_i;
110
   assign sl1w=bufsel?xout_i:expx;
111 3 yannv
 
112 5 yannv
   always @(posedge clk_i) begin
113 4 yannv
      // Read out front buffer
114 5 yannv
      pixelout <= bufsel?scanline1[xout_i]:scanline0[xout_i];
115
 
116
      // Store exposures for next scanline and wipe front buffer
117
      if (bufsel) begin
118
         if (rowmatch)
119
           scanline0[sl0w] <= expi;
120
         scanline1[sl1w] <= 0;
121
      end else begin
122
         if (rowmatch)
123
           scanline1[sl1w] <= expi;
124
         scanline0[sl0w] <= 0;
125 4 yannv
      end
126 5 yannv
 
127 4 yannv
      // swap buffers when signaled
128 5 yannv
      if (newline_i) begin
129 4 yannv
         bufsel <= ~bufsel;
130
      end
131
   end
132 5 yannv
 
133
   // output pixel intensity
134
   assign pixel_o = pixelout;
135 3 yannv
 
136
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.