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

Subversion Repositories rtf_sprite_controller

[/] [rtf_sprite_controller/] [trunk/] [rtl/] [verilog/] [sprite_test.sv] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
 
37
import wishbone_pkg::*;
38
 
39
module sprite_test(rst, clk, cs, wb_req, wb_resp, state_o);
40
input rst;
41
input clk;
42
output reg cs;
43
output wb_write_request32_t wb_req;
44
input wb_read_response32_t wb_resp;
45
output [3:0] state_o;
46
 
47
reg [4:0] sprite_no;
48
reg [11:0] hpos [0:31];
49
reg [11:0] vpos [0:31];
50
reg [11:0] hdelta [0:31];
51
reg [11:0] vdelta [0:31];
52
reg [3:0] hcnt [0:31];
53
reg [3:0] vcnt [0:31];
54
 
55
typedef enum logic [3:0] {
56
        INIT0 = 4'd0,
57
        INIT1 = 4'd1,
58
        INIT2 = 4'd2,
59
        RUN1 = 4'd4,
60
        RUN2 = 4'd5,
61
        RUN3 = 4'd6,
62
        RUN4 = 4'd7
63
} state_t;
64
state_t state;
65
assign state_o = state;
66
 
67
wire [26:0] lfsr_o;
68
reg [23:0] count;
69
lfsr27 ulfsr1
70
(
71
        .rst(rst),
72
        .clk(clk),
73
        .ce(1'b1),
74
        .cyc(1'b0),
75
        .o(lfsr_o)
76
);
77
 
78
 
79
always_ff @(posedge clk)
80
if (rst) begin
81
        state <= INIT0;
82
        sprite_no <= 5'd0;
83
        count <= 'd0;
84
        cs <= 'd0;
85
        wb_req.bte <= LINEAR;
86
        wb_req.cti <= CLASSIC;
87
        wb_req.cyc <= 'd0;
88
        wb_req.stb <= 'd0;
89
        wb_req.we <= 'd0;
90
end
91
else begin
92
        case(state)
93
        // Time for the LFSR to randomize.
94
        INIT0:
95
                begin
96
                        count <= count + 2'd1;
97
                        if (count>=24'd100000)
98
                                state <= INIT1;
99
                end
100
        INIT1:
101
                if (~wb_resp.ack) begin
102
                        /*
103
                        cs <= 1'b1;
104
                        wb_req.cyc <= 1'b1;
105
                        wb_req.stb <= 1'b1;
106
                        wb_req.we <= 1'b1;
107
                        wb_req.sel <= 4'b1111;
108
                        wb_req.adr <= {1'b0,sprite_no,2'b00,2'b00};     // POS
109
                        */
110
//                      wb_req.dat[15:0] <= lfsr_o[11:0];
111
                  hpos[sprite_no] <= 200 + (sprite_no & 7) * 70;
112
        vpos[sprite_no] <= 100 + (sprite_no >> 3) * 100;
113
//                      hpos[sprite_no] <= lfsr_o[11:0];
114
//                      wb_req.dat[31:0] <= lfsr_o[23:12];
115
//                      vpos[sprite_no] <= lfsr_o[23:12];
116
                        hdelta[sprite_no] <= {{12{lfsr_o[26]}},lfsr_o[26:23]};
117
                        vdelta[sprite_no] <= {{12{lfsr_o[11]}},lfsr_o[11:8]};
118
                        hcnt[sprite_no] <= 'd0;
119
                        vcnt[sprite_no] <= 'd0;
120
                        state <= INIT2;
121
                end
122
        INIT2:
123
                begin
124
                        cs <= 1'b0;
125
                        wb_req.cyc <= 1'b0;
126
                        wb_req.stb <= 1'b0;
127
                        wb_req.we <= 1'b0;
128
                        sprite_no <= sprite_no + 2'd1;
129
                        if (sprite_no==5'd31)
130
                                state <= RUN1;
131
                        else
132
                                state <= INIT1;
133
                end
134
        RUN1:
135
                if (~wb_resp.ack) begin
136
                        cs <= 1'b1;
137
                        wb_req.cyc <= 1'b1;
138
                        wb_req.stb <= 1'b1;
139
                        wb_req.we <= 1'b1;
140
                        wb_req.sel <= 4'b1111;
141
                        wb_req.adr <= {23'b0,sprite_no,2'b00,2'b00};    // POS register
142
                        wb_req.dat[15: 0] <= hpos[sprite_no];
143
                        wb_req.dat[31:16] <= vpos[sprite_no];
144
                        state <= RUN2;
145
                end
146
        RUN2:
147
                if (wb_resp.ack) begin
148
                        cs <= 1'b0;
149
                        wb_req.cyc <= 1'b0;
150
                        wb_req.stb <= 1'b0;
151
                        wb_req.we <= 1'b0;
152
                        sprite_no <= sprite_no + 2'd1;
153
//                      if (sprite_no > 5'd15)
154
//                              sprite_no <= 5'd0;
155
                        state <= RUN3;
156
                end
157
        RUN3:
158
                begin
159
                        if (hcnt[sprite_no] != 4'd0)
160
                                hcnt[sprite_no] <= hcnt[sprite_no] + 2'd1;
161
                        if (vcnt[sprite_no] != 4'd0)
162
                                vcnt[sprite_no] <= vcnt[sprite_no] + 2'd1;
163
                        if ((hpos[sprite_no] < 12'd280 || hpos[sprite_no] > 12'd1000) && hcnt[sprite_no]==4'd0) begin
164
                                hdelta[sprite_no] <= -hdelta[sprite_no];
165
                                hcnt[sprite_no] <= 4'd1;
166
                        end
167
                        if ((vpos[sprite_no] < 12'd50 || vpos[sprite_no] > 12'd600) && vcnt[sprite_no]==4'd0) begin
168
                                vdelta[sprite_no] <= -vdelta[sprite_no];
169
                                vcnt[sprite_no] <= 4'd1;
170
                        end
171
                        hpos[sprite_no] <= hpos[sprite_no] + hdelta[sprite_no];
172
                        vpos[sprite_no] <= vpos[sprite_no] + vdelta[sprite_no];
173
                        state <= RUN4;
174
                end
175
        RUN4:
176
                begin
177
                        count <= count + 2'd1;
178
                        if (count > 24'd100000) begin
179
                                state <= RUN1;
180
                                count <= 'd0;
181
                        end
182
                end
183
        default:        state <= INIT0;
184
        endcase
185
end
186
 
187
endmodule

powered by: WebSVN 2.1.0

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