1 |
2 |
MichaelA |
///////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Copyright 2012-2013 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: 02/14/2012
|
45 |
|
|
// Design Name: WDC W65C02 Microprocessor Re-Implementation
|
46 |
|
|
// Module Name: M65C02_BIN
|
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 |
|
|
// Dependencies: None.
|
54 |
|
|
//
|
55 |
|
|
// Revision:
|
56 |
|
|
//
|
57 |
|
|
// 1.00 12B14 MAM Initial coding. Modified W65C02_Adder.v for binary-
|
58 |
|
|
// only operation. MAM6502_BCD performs the same ops.
|
59 |
|
|
// as a BCD-only add/sub. Removed Mode input. Deleted
|
60 |
|
|
// second stage of the W6502_Adder module used for
|
61 |
|
|
// BCD adjustment.
|
62 |
|
|
//
|
63 |
|
|
// 1.01 12B19 MAM Renamed module: MAM6502_BIN => M65C02_BIN.
|
64 |
|
|
//
|
65 |
|
|
// 1.10 13H04 MAM Made the output a 0 when enable not asserted. Makes
|
66 |
|
|
// the module compatible with an OR bus.
|
67 |
|
|
//
|
68 |
|
|
// Additional Comments:
|
69 |
|
|
//
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
module M65C02_BIN(
|
73 |
|
|
input En, // ALU Enable
|
74 |
|
|
|
75 |
|
|
input [7:0] A, // Adder Input A
|
76 |
|
|
input [7:0] B, // Adder Input B
|
77 |
|
|
input Ci, // Adder Carry In
|
78 |
|
|
|
79 |
|
|
output reg [8:0] Out, // Adder Sum <= A + B + Ci
|
80 |
|
|
output reg OV, // Adder Overflow
|
81 |
|
|
output reg Valid // Adder Outputs Valid
|
82 |
|
|
);
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
//
|
86 |
|
|
// Declarations
|
87 |
|
|
//
|
88 |
|
|
|
89 |
|
|
reg [7:0] S; // Intermediate Binary Sum: S <= A + B + Ci
|
90 |
|
|
reg C6, C7; // Sum Carry Out from Bitx
|
91 |
|
|
|
92 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
93 |
|
|
//
|
94 |
|
|
// Implementation
|
95 |
|
|
//
|
96 |
|
|
|
97 |
|
|
// Adder First Stage - Combinatorial; Binary Sums and Carries
|
98 |
|
|
|
99 |
|
|
always @(*)
|
100 |
|
|
begin
|
101 |
|
|
// Binary Addition and Generate C6 and C7 Carries
|
102 |
|
|
{C6, S[6:0]} <= ({1'b0, A[6:0]} + {1'b0, B[6:0]} + {7'b0, Ci});
|
103 |
|
|
{C7, S[7]} <= ({1'b0, A[7]} + {1'b0, B[7]} + {1'b0, C6});
|
104 |
|
|
end
|
105 |
|
|
|
106 |
|
|
always @(*)
|
107 |
|
|
begin
|
108 |
|
|
Out <= ((En) ? {C7, S} : 0);
|
109 |
|
|
OV <= ((En) ? (C7 ^ C6) : 0);
|
110 |
|
|
Valid <= En;
|
111 |
|
|
end
|
112 |
|
|
|
113 |
|
|
endmodule
|