VRAM.v 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Dual port, Dual clock VRAM implementation
  3. * One port is accessed by the CPU, the other is accessed by the GPU
  4. */
  5. module VRAM
  6. #(
  7. parameter WIDTH = 32,
  8. parameter WORDS = 256,
  9. parameter LIST = "memory/vram32.list"
  10. )
  11. (
  12. input cpu_clk,
  13. input [WIDTH-1:0] cpu_d,
  14. input [13:0] cpu_addr,
  15. input cpu_we,
  16. output reg [WIDTH-1:0] cpu_q,
  17. input gpu_clk,
  18. input [WIDTH-1:0] gpu_d,
  19. input [13:0] gpu_addr,
  20. input gpu_we,
  21. output reg [WIDTH-1:0] gpu_q
  22. );
  23. reg [WIDTH-1:0] ram [0:WORDS-1]; //basically the memory cells
  24. //cpu port
  25. always @(posedge cpu_clk)
  26. begin
  27. cpu_q <= ram[cpu_addr];
  28. if (cpu_we)
  29. begin
  30. cpu_q <= cpu_d;
  31. ram[cpu_addr] <= cpu_d;
  32. end
  33. end
  34. //gpu port
  35. always @(posedge gpu_clk)
  36. begin
  37. gpu_q <= ram[gpu_addr];
  38. if (gpu_we)
  39. begin
  40. gpu_q <= gpu_d;
  41. ram[gpu_addr] <= gpu_d;
  42. end
  43. end
  44. //initialize VRAM
  45. initial
  46. begin
  47. $readmemb(LIST, ram);
  48. end
  49. endmodule