Rev 467 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
416 | lvd | 1 | // visualize ZX picture |
2 | // |
||
3 | // here we build picture and send it sometimes to C program |
||
4 | |||
511 | lvd | 5 | `ifndef NO_PIXER |
416 | lvd | 6 | module pixer |
7 | ( |
||
8 | input wire clk, |
||
511 | lvd | 9 | |
416 | lvd | 10 | input wire vsync, |
11 | input wire hsync, |
||
12 | |||
13 | input wire [1:0] red, |
||
14 | input wire [1:0] grn, |
||
15 | input wire [1:0] blu |
||
16 | ); |
||
17 | |||
18 | |||
19 | reg r_vsync; |
||
20 | reg r_hsync; |
||
21 | |||
22 | wire vbeg,hbeg; |
||
23 | |||
24 | |||
25 | integer hcount; |
||
26 | integer hperiod; |
||
27 | integer hper1,hper2; |
||
28 | |||
29 | integer vcount; |
||
30 | integer vperiod; |
||
417 | lvd | 31 | integer vper1,vper2; |
416 | lvd | 32 | |
417 | lvd | 33 | reg clr_vcnt; |
416 | lvd | 34 | |
417 | lvd | 35 | |
36 | |||
37 | |||
38 | |||
416 | lvd | 39 | always @(posedge clk) |
40 | r_vsync <= vsync; |
||
41 | |||
42 | always @(posedge clk) |
||
43 | r_hsync <= hsync; |
||
44 | |||
45 | assign vbeg = ( (!r_vsync) && vsync ); |
||
46 | assign hbeg = ( (!r_hsync) && hsync ); |
||
47 | |||
48 | |||
417 | lvd | 49 | // get horizontal period |
416 | lvd | 50 | always @(posedge clk) |
51 | if( hbeg ) |
||
52 | hcount <= 0; |
||
53 | else |
||
54 | hcount <= hcount + 1; |
||
55 | |||
56 | always @(posedge clk) |
||
57 | if( hbeg ) |
||
58 | begin |
||
59 | hper2 <= hper1; |
||
60 | hper1 <= hcount+1; |
||
61 | end |
||
62 | |||
417 | lvd | 63 | |
64 | initial hperiod=0; |
||
65 | |||
416 | lvd | 66 | always @* |
67 | if( hper2===hper1 ) |
||
68 | hperiod = hper2; |
||
69 | |||
70 | |||
71 | |||
417 | lvd | 72 | |
73 | // get vertical period |
||
74 | initial clr_vcnt = 0; |
||
511 | lvd | 75 | |
417 | lvd | 76 | always @(posedge clk) |
77 | begin |
||
78 | if( vbeg ) |
||
79 | clr_vcnt=1; |
||
80 | |||
81 | if( hbeg ) |
||
82 | begin |
||
83 | if( clr_vcnt ) |
||
84 | begin |
||
85 | clr_vcnt=0; |
||
86 | |||
87 | vper2 <= vper1; |
||
88 | vper1 <= vcount+1; |
||
89 | vcount <= 0; |
||
90 | end |
||
91 | else |
||
92 | vcount <= vcount+1; |
||
93 | end |
||
94 | end |
||
95 | |||
96 | |||
97 | initial vperiod = 0; |
||
98 | |||
99 | always @* |
||
100 | if( vper1===vper2 ) |
||
101 | vperiod = vper2; |
||
102 | |||
103 | |||
104 | // display periods |
||
467 | lvd | 105 | // always @* |
106 | // $display("h period is %d",hperiod); |
||
107 | // always @* |
||
108 | // $display("v period is %d",vperiod); |
||
417 | lvd | 109 | |
110 | |||
111 | |||
418 | lvd | 112 | always @(posedge clk) |
113 | begin |
||
114 | sndpix(hcount,vcount,{26'd0,red,grn,blu},hperiod,vperiod); |
||
115 | end |
||
417 | lvd | 116 | |
418 | lvd | 117 | |
118 | |||
119 | |||
120 | import "DPI-C" task sndpix |
||
121 | ( |
||
122 | input int hcoord, |
||
123 | input int vcoord, |
||
124 | input int rrggbb, |
||
125 | input int hperiod, |
||
126 | input int vperiod |
||
127 | ); |
||
128 | |||
129 | |||
130 | |||
416 | lvd | 131 | endmodule |
511 | lvd | 132 | `endif |
416 | lvd | 133 |