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

Subversion Repositories opengfx430

[/] [opengfx430/] [trunk/] [core/] [rtl/] [verilog/] [ogfx_reg_vram_if.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2015 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25
// *File Name: ogfx_reg_vram_if.v
26
//
27
// *Module Description:
28
//                      Video-RAM Registers interface.
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34
// $Rev$
35
// $LastChangedBy$
36
// $LastChangedDate$
37
//----------------------------------------------------------------------------
38
`ifdef OGFX_NO_INCLUDE
39
`else
40
`include "openGFX430_defines.v"
41
`endif
42
 
43
module  ogfx_reg_vram_if (
44
 
45
// OUTPUTs
46
    vid_ram_cfg_o,                             // VID_RAMx_CFG     Register
47
    vid_ram_width_o,                           // VID_RAMx_WIDTH   Register
48
`ifdef VRAM_BIGGER_4_KW
49
    vid_ram_addr_hi_o,                         // VID_RAMx_ADDR_HI Register
50
`endif
51
    vid_ram_addr_lo_o,                         // VID_RAMx_ADDR_LO Register
52
    vid_ram_data_o,                            // VID_RAMx_DATA    Register
53
 
54
    vid_ram_we_o,                              // Video-RAM Write strobe
55
    vid_ram_ce_o,                              // Video-RAM Chip enable
56
    vid_ram_din_o,                             // Video-RAM Data input
57
    vid_ram_addr_nxt_o,                        // Video-RAM Next address
58
    vid_ram_access_o,                          // Video-RAM Access
59
 
60
// INPUTs
61
    mclk,                                      // Main system clock
62
    puc_rst,                                   // Main system reset
63
 
64
    vid_ram_cfg_wr_i,                          // VID_RAMx_CFG     Write strobe
65
    vid_ram_width_wr_i,                        // VID_RAMx_WIDTH   Write strobe
66
`ifdef VRAM_BIGGER_4_KW
67
    vid_ram_addr_hi_wr_i,                      // VID_RAMx_ADDR_HI Write strobe
68
`endif
69
    vid_ram_addr_lo_wr_i,                      // VID_RAMx_ADDR_LO Write strobe
70
    vid_ram_data_wr_i,                         // VID_RAMx_DATA    Write strobe
71
    vid_ram_data_rd_i,                         // VID_RAMx_DATA    Read  strobe
72
 
73
    dbg_freeze_i,                              // Freeze auto-increment on read when CPU stopped
74
    display_width_i,                           // Display width
75
    gfx_mode_1_bpp_i,                          // Graphic mode  1 bpp resolution
76
    gfx_mode_2_bpp_i,                          // Graphic mode  2 bpp resolution
77
    gfx_mode_4_bpp_i,                          // Graphic mode  4 bpp resolution
78
    gfx_mode_8_bpp_i,                          // Graphic mode  8 bpp resolution
79
    gfx_mode_16_bpp_i,                         // Graphic mode 16 bpp resolution
80
 
81
    per_din_i,                                 // Peripheral data input
82
    vid_ram_base_addr_i,                       // Video-RAM base address
83
    vid_ram_dout_i                             // Video-RAM data input
84
);
85
 
86
// OUTPUTs
87
//=========
88
output        [15:0] vid_ram_cfg_o;            // VID_RAMx_CFG     Register
89
output        [15:0] vid_ram_width_o;          // VID_RAMx_WIDTH   Register
90
`ifdef VRAM_BIGGER_4_KW
91
output        [15:0] vid_ram_addr_hi_o;        // VID_RAMx_ADDR_HI Register
92
`endif
93
output        [15:0] vid_ram_addr_lo_o;        // VID_RAMx_ADDR_LO Register
94
output        [15:0] vid_ram_data_o;           // VID_RAMx_DATA    Register
95
 
96
output               vid_ram_we_o;             // Video-RAM Write strobe
97
output               vid_ram_ce_o;             // Video-RAM Chip enable
98
output        [15:0] vid_ram_din_o;            // Video-RAM Data input
99
output [`APIX_MSB:0] vid_ram_addr_nxt_o;       // Video-RAM Next address
100
output               vid_ram_access_o;         // Video-RAM Access
101
 
102
// INPUTs
103
//=========
104
input                mclk;                     // Main system clock
105
input                puc_rst;                  // Main system reset
106
 
107
input                vid_ram_cfg_wr_i;         // VID_RAMx_CFG     Write strobe
108
input                vid_ram_width_wr_i;       // VID_RAMx_WIDTH   Write strobe
109
`ifdef VRAM_BIGGER_4_KW
110
input                vid_ram_addr_hi_wr_i;     // VID_RAMx_ADDR_HI Write strobe
111
`endif
112
input                vid_ram_addr_lo_wr_i;     // VID_RAMx_ADDR_LO Write strobe
113
input                vid_ram_data_wr_i;        // VID_RAMx_DATA    Write strobe
114
input                vid_ram_data_rd_i;        // VID_RAMx_DATA    Read  strobe
115
 
116
input                dbg_freeze_i;             // Freeze auto-increment on read when CPU stopped
117
input  [`LPIX_MSB:0] display_width_i;          // Display width
118
input                gfx_mode_1_bpp_i;         // Graphic mode  1 bpp resolution
119
input                gfx_mode_2_bpp_i;         // Graphic mode  2 bpp resolution
120
input                gfx_mode_4_bpp_i;         // Graphic mode  4 bpp resolution
121
input                gfx_mode_8_bpp_i;         // Graphic mode  8 bpp resolution
122
input                gfx_mode_16_bpp_i;        // Graphic mode 16 bpp resolution
123
 
124
input         [15:0] per_din_i;                // Peripheral data input
125
input  [`APIX_MSB:0] vid_ram_base_addr_i;      // Video-RAM base address
126
input         [15:0] vid_ram_dout_i;           // Video-RAM data input
127
 
128
 
129
//=============================================================================
130
// 1)  WIRE AND FUNCTION DECLARATIONS
131
//=============================================================================
132
 
133
// 16 bits one-hot decoder
134
function [15:0] one_hot16;
135
   input  [3:0] binary;
136
   begin
137
      one_hot16         = 16'h0000;
138
      one_hot16[binary] =  1'b1;
139
   end
140
endfunction
141
 
142
 
143
 
144
//============================================================================
145
// 2) REGISTERS
146
//============================================================================
147
 
148
//------------------------------------------------
149
// VID_RAMx_CFG Register
150
//------------------------------------------------
151
reg                vid_ram_rmw_mode;
152
reg                vid_ram_msk_mode;
153
reg                vid_ram_win_mode;
154
reg                vid_ram_win_x_swap;
155
reg                vid_ram_win_y_swap;
156
reg                vid_ram_win_cl_swap;
157
 
158
always @ (posedge mclk or posedge puc_rst)
159
  if (puc_rst)
160
    begin
161
       vid_ram_win_cl_swap  <=  1'b0;
162
       vid_ram_win_y_swap   <=  1'b0;
163
       vid_ram_win_x_swap   <=  1'b0;
164
       vid_ram_rmw_mode     <=  1'b0;
165
       vid_ram_msk_mode     <=  1'b0;
166
       vid_ram_win_mode     <=  1'b0;
167
    end
168
  else if (vid_ram_cfg_wr_i)
169
    begin
170
       vid_ram_win_cl_swap  <=  per_din_i[0];
171
       vid_ram_win_y_swap   <=  per_din_i[1];
172
       vid_ram_win_x_swap   <=  per_din_i[2];
173
       vid_ram_rmw_mode     <=  per_din_i[4];
174
       vid_ram_msk_mode     <=  per_din_i[5];
175
       vid_ram_win_mode     <=  per_din_i[6];
176
    end
177
 
178
assign vid_ram_cfg_o  = {8'h00, 1'b0,  vid_ram_win_mode,   vid_ram_msk_mode,   vid_ram_rmw_mode   ,
179
                                1'b0,  vid_ram_win_x_swap, vid_ram_win_y_swap, vid_ram_win_cl_swap};
180
 
181
//------------------------------------------------
182
// VID_RAMx_WIDTH Register
183
//------------------------------------------------
184
reg  [`LPIX_MSB:0] vid_ram_width;
185
 
186
// width must be at least 1
187
wire [`LPIX_MSB:0] vid_ram_width_nxt  = (|per_din_i[`LPIX_MSB:0]) ? per_din_i[`LPIX_MSB:0] : {{`LPIX_MSB{1'b0}}, 1'b1};
188
 
189
always @ (posedge mclk or posedge puc_rst)
190
  if (puc_rst)                 vid_ram_width   <=  {{`LPIX_MSB{1'b0}}, 1'b1};
191
  else if (vid_ram_width_wr_i) vid_ram_width   <=  vid_ram_width_nxt;
192
 
193
wire [16:0] vid_ram_width_tmp = {{16-`LPIX_MSB{1'b0}}, vid_ram_width};
194
assign      vid_ram_width_o   = vid_ram_width_tmp[15:0];
195
 
196
 
197
//------------------------------------------------
198
// VID_RAMx_ADDR_HI Register
199
//------------------------------------------------
200
wire   [`APIX_MSB:0] vid_ram_addr;
201
wire   [`APIX_MSB:0] vid_ram_addr_inc;
202
wire                 vid_ram_addr_inc_wr;
203
 
204
`ifdef VRAM_BIGGER_4_KW
205
reg [`APIX_HI_MSB:0] vid_ram_addr_hi;
206
 
207
always @ (posedge mclk or posedge puc_rst)
208
  if (puc_rst)                   vid_ram_addr_hi <=  {`APIX_HI_MSB+1{1'b0}};
209
  else if (vid_ram_addr_hi_wr_i) vid_ram_addr_hi <=  per_din_i[`APIX_HI_MSB:0];
210
  else if (vid_ram_addr_inc_wr)  vid_ram_addr_hi <=  vid_ram_addr_inc[`APIX_MSB:16];
211
 
212
wire [16:0] vid_ram_addr_hi_tmp = {{16-`APIX_HI_MSB{1'b0}},vid_ram_addr_hi};
213
assign      vid_ram_addr_hi_o   = vid_ram_addr_hi_tmp[15:0];
214
`endif
215
 
216
//------------------------------------------------
217
// VID_RAMx_ADDR_LO Register
218
//------------------------------------------------
219
reg [`APIX_LO_MSB:0] vid_ram_addr_lo;
220
reg                  vid_ram_addr_lo_wr_dly;
221
 
222
always @ (posedge mclk or posedge puc_rst)
223
  if (puc_rst)                   vid_ram_addr_lo <=  {`APIX_LO_MSB+1{1'b0}};
224
  else if (vid_ram_addr_lo_wr_i) vid_ram_addr_lo <=  per_din_i[`APIX_LO_MSB:0];
225
  else if (vid_ram_addr_inc_wr)  vid_ram_addr_lo <=  vid_ram_addr_inc[`APIX_LO_MSB:0];
226
 
227
`ifdef VRAM_BIGGER_4_KW
228
assign      vid_ram_addr        = {vid_ram_addr_hi[`APIX_HI_MSB:0], vid_ram_addr_lo};
229
assign      vid_ram_addr_lo_o   =  vid_ram_addr_lo;
230
`else
231
assign      vid_ram_addr        = {vid_ram_addr_lo[`APIX_LO_MSB:0]};
232
wire [16:0] vid_ram_addr_lo_tmp = {{16-`APIX_LO_MSB{1'b0}},vid_ram_addr_lo};
233
assign      vid_ram_addr_lo_o   = vid_ram_addr_lo_tmp[15:0];
234
`endif
235
 
236
// Compute the next address
237
ogfx_reg_vram_addr ogfx_reg_vram_addr_inst (
238
 
239
// OUTPUTs
240
    .vid_ram_addr_nxt_o      ( vid_ram_addr_inc       ),   // Next Video-RAM address
241
 
242
// INPUTs
243
    .mclk                    ( mclk                   ),   // Main system clock
244
    .puc_rst                 ( puc_rst                ),   // Main system reset
245
    .display_width_i         ( display_width_i        ),   // Display width
246
    .gfx_mode_1_bpp_i        ( gfx_mode_1_bpp_i       ),   // Graphic mode  1 bpp resolution
247
    .gfx_mode_2_bpp_i        ( gfx_mode_2_bpp_i       ),   // Graphic mode  2 bpp resolution
248
    .gfx_mode_4_bpp_i        ( gfx_mode_4_bpp_i       ),   // Graphic mode  4 bpp resolution
249
    .gfx_mode_8_bpp_i        ( gfx_mode_8_bpp_i       ),   // Graphic mode  8 bpp resolution
250
    .gfx_mode_16_bpp_i       ( gfx_mode_16_bpp_i      ),   // Graphic mode 16 bpp resolution
251
    .vid_ram_addr_i          ( vid_ram_addr           ),   // Video-RAM address
252
    .vid_ram_addr_init_i     ( vid_ram_addr_lo_wr_dly ),   // Video-RAM address initialization
253
    .vid_ram_addr_step_i     ( vid_ram_addr_inc_wr    ),   // Video-RAM address step
254
    .vid_ram_width_i         ( vid_ram_width          ),   // Video-RAM width
255
    .vid_ram_msk_mode_i      ( vid_ram_msk_mode       ),   // Video-RAM Mask mode enable
256
    .vid_ram_win_mode_i      ( vid_ram_win_mode       ),   // Video-RAM Windows mode enable
257
    .vid_ram_win_x_swap_i    ( vid_ram_win_x_swap     ),   // Video-RAM X-Swap configuration
258
    .vid_ram_win_y_swap_i    ( vid_ram_win_y_swap     ),   // Video-RAM Y-Swap configuration
259
    .vid_ram_win_cl_swap_i   ( vid_ram_win_cl_swap    )    // Video-RAM CL-Swap configuration
260
);
261
 
262
 
263
//------------------------------------------------
264
// VID_RAMx_DATA Register
265
//------------------------------------------------
266
 
267
// Format input data for masked mode
268
wire [15:0] per_din_mask_mode = (({16{gfx_mode_1_bpp_i  &  vid_ram_msk_mode }} & {16{per_din_i[0]  }}) |
269
                                 ({16{gfx_mode_2_bpp_i  &  vid_ram_msk_mode }} &  {8{per_din_i[1:0]}}) |
270
                                 ({16{gfx_mode_4_bpp_i  &  vid_ram_msk_mode }} &  {4{per_din_i[3:0]}}) |
271
                                 ({16{gfx_mode_8_bpp_i  &  vid_ram_msk_mode }} &  {2{per_din_i[7:0]}}) |
272
                                 ({16{gfx_mode_16_bpp_i | ~vid_ram_msk_mode }} &     per_din_i       ) );
273
 
274
// Prepare data to be written according to mask mode enable
275
reg  [15:0] vid_ram_data_mask;
276
wire [15:0] per_din_ram_nxt   = per_din_mask_mode & vid_ram_data_mask;
277
 
278
// VIDEO-RAM data Register
279
reg  [15:0] vid_ram_data;
280
wire [15:0] vid_ram_data_mux;
281
wire        vid_ram_dout_rdy;
282
always @ (posedge mclk or posedge puc_rst)
283
  if (puc_rst)                vid_ram_data <=  16'h0000;
284
  else if (vid_ram_data_wr_i) vid_ram_data <=  per_din_ram_nxt | (vid_ram_data_mux & ~vid_ram_data_mask);
285
  else if (vid_ram_dout_rdy)  vid_ram_data <=  vid_ram_dout_i;
286
 
287
// Make value available in case of early read
288
assign      vid_ram_data_mux            =  vid_ram_dout_rdy ? vid_ram_dout_i : vid_ram_data;
289
 
290
// Format read-path for mask mode
291
wire [15:0] vid_ram_data_rd_mask        =  vid_ram_data_mux & vid_ram_data_mask;
292
wire        vid_ram_data_rd_mask_1_bpp  =  (|vid_ram_data_rd_mask);
293
wire  [1:0] vid_ram_data_rd_mask_2_bpp  = {(|{vid_ram_data_rd_mask[15], vid_ram_data_rd_mask[13], vid_ram_data_rd_mask[11], vid_ram_data_rd_mask[9], vid_ram_data_rd_mask[7], vid_ram_data_rd_mask[5], vid_ram_data_rd_mask[3], vid_ram_data_rd_mask[1]}),
294
                                           (|{vid_ram_data_rd_mask[14], vid_ram_data_rd_mask[12], vid_ram_data_rd_mask[10], vid_ram_data_rd_mask[8], vid_ram_data_rd_mask[6], vid_ram_data_rd_mask[4], vid_ram_data_rd_mask[2], vid_ram_data_rd_mask[0]})};
295
wire  [3:0] vid_ram_data_rd_mask_4_bpp  = {(|{vid_ram_data_rd_mask[15], vid_ram_data_rd_mask[11], vid_ram_data_rd_mask[7] , vid_ram_data_rd_mask[3]}),
296
                                           (|{vid_ram_data_rd_mask[14], vid_ram_data_rd_mask[10], vid_ram_data_rd_mask[6] , vid_ram_data_rd_mask[2]}),
297
                                           (|{vid_ram_data_rd_mask[13], vid_ram_data_rd_mask[9] , vid_ram_data_rd_mask[5] , vid_ram_data_rd_mask[1]}),
298
                                           (|{vid_ram_data_rd_mask[12], vid_ram_data_rd_mask[8] , vid_ram_data_rd_mask[4] , vid_ram_data_rd_mask[0]})};
299
wire  [7:0] vid_ram_data_rd_mask_8_bpp  = {(|{vid_ram_data_rd_mask[15], vid_ram_data_rd_mask[7]}),
300
                                           (|{vid_ram_data_rd_mask[14], vid_ram_data_rd_mask[6]}),
301
                                           (|{vid_ram_data_rd_mask[13], vid_ram_data_rd_mask[5]}),
302
                                           (|{vid_ram_data_rd_mask[12], vid_ram_data_rd_mask[4]}),
303
                                           (|{vid_ram_data_rd_mask[11], vid_ram_data_rd_mask[3]}),
304
                                           (|{vid_ram_data_rd_mask[10], vid_ram_data_rd_mask[2]}),
305
                                           (|{vid_ram_data_rd_mask[9] , vid_ram_data_rd_mask[1]}),
306
                                           (|{vid_ram_data_rd_mask[8] , vid_ram_data_rd_mask[0]})};
307
wire [15:0] vid_ram_data_rd_mask_16_bpp =     vid_ram_data_rd_mask;
308
 
309
assign      vid_ram_data_o              =  ({16{gfx_mode_1_bpp_i  &  vid_ram_msk_mode }} & {{15{1'b0}},vid_ram_data_rd_mask_1_bpp}) |
310
                                           ({16{gfx_mode_2_bpp_i  &  vid_ram_msk_mode }} & {{14{1'b0}},vid_ram_data_rd_mask_2_bpp}) |
311
                                           ({16{gfx_mode_4_bpp_i  &  vid_ram_msk_mode }} & {{12{1'b0}},vid_ram_data_rd_mask_4_bpp}) |
312
                                           ({16{gfx_mode_8_bpp_i  &  vid_ram_msk_mode }} & { {8{1'b0}},vid_ram_data_rd_mask_8_bpp}) |
313
                                           ({16{gfx_mode_16_bpp_i | ~vid_ram_msk_mode }} &             vid_ram_data_rd_mask_16_bpp) ;
314
 
315
 
316
//============================================================================
317
// 3) VIDEO MEMORY INTERFACE
318
//============================================================================
319
//
320
// Trigger a VIDEO-RAM write access after:
321
//   - a VID_RAMx_DATA register write access
322
//
323
// Trigger a VIDEO-RAM read access immediately after:
324
//   - a VID_RAMx_ADDR_LO register write access
325
//   - a VID_RAMx_DATA register read access
326
//   - a VID_RAMx_DATA register write access in MSK mode (for resolutions lower than 16bpp)
327
//
328
 
329
//--------------------------------------------------
330
// VID_RAM0: Delay software read and write strobes
331
//--------------------------------------------------
332
 
333
// Strobe writing to VID_RAMx_ADDR_LO register
334
always @ (posedge mclk or posedge puc_rst)
335
  if (puc_rst) vid_ram_addr_lo_wr_dly  <= 1'b0;
336
  else         vid_ram_addr_lo_wr_dly  <= vid_ram_addr_lo_wr_i;
337
 
338
// Strobe reading from VID_RAMx_DATA register
339
reg        vid_ram_data_rd_dly;
340
always @ (posedge mclk or posedge puc_rst)
341
  if (puc_rst) vid_ram_data_rd_dly     <= 1'b0;
342
  else         vid_ram_data_rd_dly     <= vid_ram_data_rd_i;
343
 
344
// Strobe writing to VID_RAMx_DATA register
345
reg        vid_ram_data_wr_dly;
346
always @ (posedge mclk or posedge puc_rst)
347
  if (puc_rst) vid_ram_data_wr_dly     <= 1'b0;
348
  else         vid_ram_data_wr_dly     <= vid_ram_data_wr_i;
349
 
350
// Trigger read access after a write in MSK mode
351
wire       vid_ram_data_rd_msk   = ((vid_ram_data_wr_dly  | vid_ram_data_rd_dly | vid_ram_addr_lo_wr_i) & vid_ram_msk_mode & ~gfx_mode_16_bpp_i);
352
 
353
 
354
//------------------------------------------------
355
// Compute VIDEO-RAM Strobes & Data
356
//------------------------------------------------
357
 
358
// Write access strobe
359
//       - one cycle after a VID_RAM_DATA register write access
360
assign vid_ram_we_o     =  vid_ram_data_wr_dly;
361
 
362
// Chip enable.
363
// Note: we perform a data read access:
364
//       - one cycle after a VID_RAM_DATA register read access (so that the address has been incremented)
365
//       - one cycle after a VID_RAM_ADDR_LO register write
366
wire   vid_ram_ce_early = (vid_ram_addr_lo_wr_i | vid_ram_data_rd_dly | vid_ram_data_rd_msk | // Read access
367
                           vid_ram_data_wr_i);                                                // Write access
368
 
369
reg [1:0] vid_ram_ce;
370
always @ (posedge mclk or posedge puc_rst)
371
  if (puc_rst) vid_ram_ce <= 2'b00;
372
  else         vid_ram_ce <= {vid_ram_ce[0] & ~vid_ram_data_wr_dly, vid_ram_ce_early};
373
 
374
assign vid_ram_ce_o     = vid_ram_ce[0];
375
 
376
// Data to be written
377
assign vid_ram_din_o    = {16{vid_ram_ce[0]}} & vid_ram_data;
378
 
379
// Update the VRAM_DATA register one cycle after each memory access
380
assign vid_ram_dout_rdy = vid_ram_ce[1];
381
 
382
 
383
//------------------------------------------------
384
// Compute VIDEO-RAM Address
385
//------------------------------------------------
386
 
387
// Mux ram address for early read access when ADDR_LO is updated
388
`ifdef VRAM_BIGGER_4_KW
389
wire [`APIX_MSB:0] vid_ram_addr_mux    = vid_ram_addr_lo_wr_i ? {vid_ram_addr[`APIX_MSB:16], per_din_i} :
390
                                         vid_ram_data_rd_msk  ?  vid_ram_addr_inc                       : vid_ram_addr;
391
`else
392
wire [`APIX_MSB:0] vid_ram_addr_mux    = vid_ram_addr_lo_wr_i ? {per_din_i[`APIX_LO_MSB:0]}             :
393
                                         vid_ram_data_rd_msk  ?  vid_ram_addr_inc                       : vid_ram_addr;
394
`endif
395
 
396
// Add frame pointer offset
397
wire [`APIX_MSB:0] vid_ram_addr_offset = vid_ram_base_addr_i + vid_ram_addr_mux;
398
 
399
// Detect memory accesses for ADDR update
400
wire               vid_ram_access_o    = vid_ram_data_wr_i | vid_ram_data_rd_dly | vid_ram_addr_lo_wr_i | vid_ram_data_rd_msk;
401
 
402
// Mux Address between the two interfaces
403
wire [`APIX_MSB:0] vid_ram_addr_nxt_o  = {`APIX_MSB+1{vid_ram_access_o}} & vid_ram_addr_offset;
404
 
405
// Increment the address when accessing the VID_RAMx_DATA register:
406
// - one clock cycle after a write access
407
// - with the read access (if not in read-modify-write mode)
408
assign             vid_ram_addr_inc_wr = vid_ram_addr_lo_wr_dly | vid_ram_data_wr_dly | (vid_ram_data_rd_i & ~dbg_freeze_i & ~vid_ram_rmw_mode);
409
 
410
// Compute mask for the address LSBs depending on BPP resolution
411
wire         [3:0] gfx_mode_addr_msk   = (        {4{gfx_mode_1_bpp_i}}  | // Take  4 address LSBs in  1bpp mode
412
                                          {1'b0,  {3{gfx_mode_2_bpp_i}}} | // Take  3 address LSBs in  2bpp mode
413
                                          {2'b00, {2{gfx_mode_4_bpp_i}}} | // Take  2 address LSBs in  4bpp mode
414
                                          {3'b000,   gfx_mode_8_bpp_i});   // Take  1 address LSB  in  8bpp mode
415
                                                                           // Take no address LSB  in 16bpp mode
416
// Generate Data-Mask for the mask mode (Bank 0)
417
wire    [15:0] vid_ram_data_mask_shift = one_hot16(vid_ram_addr_offset[3:0] & gfx_mode_addr_msk);
418
wire    [15:0] vid_ram_data_mask_nxt   = ({16{gfx_mode_1_bpp_i }} &     vid_ram_data_mask_shift      ) |
419
                                         ({16{gfx_mode_2_bpp_i }} & {{2{vid_ram_data_mask_shift[7]}},
420
                                                                     {2{vid_ram_data_mask_shift[6]}},
421
                                                                     {2{vid_ram_data_mask_shift[5]}},
422
                                                                     {2{vid_ram_data_mask_shift[4]}},
423
                                                                     {2{vid_ram_data_mask_shift[3]}},
424
                                                                     {2{vid_ram_data_mask_shift[2]}},
425
                                                                     {2{vid_ram_data_mask_shift[1]}},
426
                                                                     {2{vid_ram_data_mask_shift[0]}}}) |
427
                                         ({16{gfx_mode_4_bpp_i }} & {{4{vid_ram_data_mask_shift[3]}},
428
                                                                     {4{vid_ram_data_mask_shift[2]}},
429
                                                                     {4{vid_ram_data_mask_shift[1]}},
430
                                                                     {4{vid_ram_data_mask_shift[0]}}}) |
431
                                         ({16{gfx_mode_8_bpp_i }} & {{8{vid_ram_data_mask_shift[1]}},
432
                                                                     {8{vid_ram_data_mask_shift[0]}}}) |
433
                                         ({16{gfx_mode_16_bpp_i}} & {16{1'b1}}                       ) ;
434
 
435
always @ (posedge mclk or posedge puc_rst)
436
  if (puc_rst)                   vid_ram_data_mask <=  16'hffff;
437
  else if (vid_ram_data_rd_msk)  vid_ram_data_mask <=  vid_ram_data_mask_nxt;
438
  else if (vid_ram_access_o)     vid_ram_data_mask <=  16'hffff;
439
 
440
 
441
endmodule // ogfx_reg_vram_if
442
 
443
`ifdef OGFX_NO_INCLUDE
444
`else
445
`include "openGFX430_undefines.v"
446
`endif

powered by: WebSVN 2.1.0

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