1 |
2 |
MichaelA |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Copyright 2012 by Michael A. Morris, dba M. A. Morris & Associates
|
4 |
|
|
//
|
5 |
|
|
// All rights reserved. The source code contained herein is publicly released
|
6 |
|
|
// under the terms and conditions of the GNU Lesser Public License. No part of
|
7 |
|
|
// this source code may be reproduced or transmitted in any form or by any
|
8 |
|
|
// means, electronic or mechanical, including photocopying, recording, or any
|
9 |
|
|
// information storage and retrieval system in violation of the license under
|
10 |
|
|
// which the source code is released.
|
11 |
|
|
//
|
12 |
|
|
// The source code contained herein is free; it may be redistributed and/or
|
13 |
|
|
// modified in accordance with the terms of the GNU Lesser General Public
|
14 |
|
|
// License as published by the Free Software Foundation; either version 2.1 of
|
15 |
|
|
// the GNU Lesser General Public License, or any later version.
|
16 |
|
|
//
|
17 |
|
|
// The source code contained herein is freely released WITHOUT ANY WARRANTY;
|
18 |
|
|
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
19 |
|
|
// PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
|
20 |
|
|
// more details.)
|
21 |
|
|
//
|
22 |
|
|
// A copy of the GNU Lesser General Public License should have been received
|
23 |
|
|
// along with the source code contained herein; if not, a copy can be obtained
|
24 |
|
|
// by writing to:
|
25 |
|
|
//
|
26 |
|
|
// Free Software Foundation, Inc.
|
27 |
|
|
// 51 Franklin Street, Fifth Floor
|
28 |
|
|
// Boston, MA 02110-1301 USA
|
29 |
|
|
//
|
30 |
|
|
// Further, no use of this source code is permitted in any form or means
|
31 |
|
|
// without inclusion of this banner prominently in any derived works.
|
32 |
|
|
//
|
33 |
|
|
// Michael A. Morris
|
34 |
|
|
// Huntsville, AL
|
35 |
|
|
//
|
36 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
`timescale 1ns / 1ps
|
39 |
|
|
|
40 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
// Company: M. A. Morris & Associates
|
42 |
|
|
// Engineer: Michael A. Morris
|
43 |
|
|
//
|
44 |
|
|
// Create Date: 22:35:57 02/04/2012
|
45 |
|
|
// Design Name: WDC W65C02 Microprocessor Re-Implementation
|
46 |
|
|
// Module Name: M65C02_RAM
|
47 |
|
|
// Project Name: C:\XProjects\ISE10.1i\MAM6502
|
48 |
|
|
// Target Devices: Generic SRAM-based FPGA
|
49 |
|
|
// Tool versions: Xilinx ISE10.1i SP3
|
50 |
|
|
//
|
51 |
|
|
// Description:
|
52 |
|
|
//
|
53 |
|
|
// The module provides a generic RAM model that can be used to simulate RAM
|
54 |
|
|
// found in an FPGA.
|
55 |
|
|
//
|
56 |
|
|
// Dependencies:
|
57 |
|
|
//
|
58 |
|
|
// Revision:
|
59 |
|
|
//
|
60 |
|
|
// 0.00 12B04 MAM Initial File Creation
|
61 |
|
|
//
|
62 |
|
|
// 1.00 12K18 MAM Modified the RAM model to support three different
|
63 |
|
|
// kinds of RAM. The model supports asynchronous, LUT-
|
64 |
|
|
// based RAM ({Ext, ZP} == 1), synchronous BRAM-based
|
65 |
|
|
// RAM ({Ext, ZP} == 0 | 3), and synchronous, pipelined
|
66 |
|
|
// RAM ({Ext, ZP} == 2).
|
67 |
|
|
//
|
68 |
|
|
// Additional Comments:
|
69 |
|
|
//
|
70 |
|
|
// In normal use, the model provided in this module can be used to develop a
|
71 |
|
|
// memory controller for the M65C02_Core that supports LUT RAM for page 0
|
72 |
|
|
// acesses, BRAM for page 1 and internal program and data memory, and pipelined
|
73 |
|
|
// SynchRAM for external program and data memory. It is possible to support ex-
|
74 |
|
|
// ternal non-pipelined synchronous RAM by setting the RAM module to the BRAM
|
75 |
|
|
// mode and providing additional registers in the output paths but not on the
|
76 |
|
|
// input paths of the FPGA.
|
77 |
|
|
//
|
78 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
|
80 |
|
|
module M65C02_RAM #(
|
81 |
|
|
parameter pAddrSize = 10,
|
82 |
|
|
parameter pDataSize = 8,
|
83 |
|
|
parameter pFileName = "M65C02_RAM.txt"
|
84 |
|
|
)(
|
85 |
|
|
input Clk,
|
86 |
|
|
|
87 |
|
|
input ZP, // Emulate LUT-based Asynchronous RAM
|
88 |
|
|
input Ext, // Emulate BRAM-based Pipelined SyncSRAM
|
89 |
|
|
|
90 |
|
|
input WE,
|
91 |
|
|
input [(pAddrSize - 1):0] AI,
|
92 |
|
|
input [(pDataSize - 1):0] DI,
|
93 |
|
|
output [(pDataSize - 1):0] DO
|
94 |
|
|
);
|
95 |
|
|
|
96 |
|
|
localparam pRAM_Max = ((2**pAddrSize) - 1);
|
97 |
|
|
|
98 |
|
|
reg [(pDataSize - 1):0] RAM [pRAM_Max:0];
|
99 |
|
|
|
100 |
|
|
reg rWE;
|
101 |
|
|
reg [(pAddrSize - 1):0] rAI;
|
102 |
|
|
reg [(pDataSize - 1):0] rDI, rDO;
|
103 |
|
|
|
104 |
|
|
wire W;
|
105 |
|
|
wire [(pAddrSize - 1):0] A;
|
106 |
|
|
wire [(pDataSize - 1):0] D;
|
107 |
|
|
|
108 |
|
|
always @(posedge Clk)
|
109 |
|
|
begin
|
110 |
|
|
{rWE, rAI, rDI} <= #1 {WE, AI, DI};
|
111 |
|
|
end
|
112 |
|
|
|
113 |
|
|
assign W = ((ZP) ? WE : rWE);
|
114 |
|
|
assign A = ((ZP) ? AI : rAI);
|
115 |
|
|
assign D = ((ZP) ? DI : rDI);
|
116 |
|
|
|
117 |
|
|
initial
|
118 |
|
|
$readmemh(pFileName, RAM, 0, pRAM_Max);
|
119 |
|
|
|
120 |
|
|
always @(posedge Clk)
|
121 |
|
|
begin
|
122 |
|
|
if(W)
|
123 |
|
|
RAM[A] <= #1 D;
|
124 |
|
|
end
|
125 |
|
|
|
126 |
|
|
always @(posedge Clk)
|
127 |
|
|
begin
|
128 |
|
|
rDO <= #1 RAM[A];
|
129 |
|
|
end
|
130 |
|
|
|
131 |
|
|
assign DO = ((Ext) ? rDO : RAM[A]);
|
132 |
|
|
|
133 |
|
|
endmodule
|