1 |
2 |
MichaelA |
M65C02 Processor Core Source Files
|
2 |
|
|
==================================
|
3 |
|
|
|
4 |
|
|
Copyright (C) 2012, Michael A. Morris .
|
5 |
|
|
All Rights Reserved.
|
6 |
|
|
|
7 |
|
|
Released under LGPL.
|
8 |
|
|
|
9 |
|
|
Organization
|
10 |
|
|
------------
|
11 |
|
|
|
12 |
|
|
The source files are provided in subdirectories:
|
13 |
|
|
|
14 |
|
|
M65C02-Test-Programs
|
15 |
|
|
Memory-Images
|
16 |
|
|
Microprogram-Sources
|
17 |
|
|
RTL
|
18 |
|
|
Settings
|
19 |
|
|
|
20 |
|
|
The contents of each of the subdirectories is provided below.
|
21 |
|
|
|
22 |
|
|
The M65C02 test programs as assembler programs. Two test programs are
|
23 |
|
|
provided. The first program was a simple program used to test the operation of
|
24 |
|
|
jumps, branches, stack operations, and register transfers. With this test
|
25 |
|
|
program, a major part of the microprogram was tested and verified.
|
26 |
|
|
|
27 |
|
|
The second test program is a more complete program. All instructions, i.e. all
|
28 |
|
|
256 opcodes, are tested using the second program. The operation of the
|
29 |
|
|
interrupt logic and the automatic wait state inserted during decimal (BCD)
|
30 |
|
|
mode addition and subtraction (ADC/SBC) are also tested with the second test
|
31 |
|
|
program. It is not a comprehensive diagnostics program. Examination of the
|
32 |
|
|
simulation output was used to test the operation of many of the M65C02's
|
33 |
|
|
instructions. However, the second test program does contain some self-checks,
|
34 |
|
|
and those were used to speed the process of testing each instruction and each
|
35 |
|
|
addressing mode. (The most recent release of the core, Release 2.2, exposed an
|
36 |
|
|
issue that affected the PSW on entry into the ISR. Proper adjustment of the
|
37 |
|
|
PSW in the PSW was not being tested within the simulated ISR. The problem was
|
38 |
|
|
detected further into the test program when and BCD arithmetic failed. Since
|
39 |
|
|
this is a critical behavior, the ISR has been modified to include checks that
|
40 |
|
|
verify that the BCD mode (PSW.D) is not set, and that interrupt mask is set
|
41 |
|
|
(PSW.I) when the ISR is entered.)
|
42 |
|
|
|
43 |
|
|
The M65C02 is a microprogrammed implementation. There are two microprogram
|
44 |
|
|
memories used. The first, M65C02_Decoder_ROM, provides the control of the ALU
|
45 |
|
|
during the execute phase. The second, M65C02_uPgm_V3, provides the control of
|
46 |
|
|
the core. That is, the second microprogram implements each addressing mode,
|
47 |
|
|
deals with interrupts and BRK, and controls the fetching and execution of all
|
48 |
|
|
instructions. Both microprogram ROMs include an instruction decoder. When the
|
49 |
|
|
instruction is present on the input data bus, it is captured into the
|
50 |
|
|
instruction register, IR, but it is simultaneously applied to the address bus
|
51 |
|
|
of the two microprogram ROMs.
|
52 |
|
|
|
53 |
|
|
In the Decoder ROM, the opcode is applied in a normal fashion, so the Decoder
|
54 |
|
|
ROM is organized linearly. In the uPgm ROM, the opcode is applied to the
|
55 |
|
|
address bus with the opcode's nibbles swapped. Thus, the instruction decoder
|
56 |
|
|
in the uPgm ROM is best thought of as being organized by the rows in the
|
57 |
|
|
opcode matrix of the M65C02.
|
58 |
|
|
|
59 |
|
|
There are three memory image files provided in the corresponding subdirectory.
|
60 |
|
|
One is for the M65C02 test program, and the other two are for the microprogram
|
61 |
|
|
ROMs. The microprogram ROMs are implemented using Block RAMs, whose contents
|
62 |
|
|
are initialized by the contents of the two microprogram ROM image files.
|
63 |
|
|
|
64 |
|
|
The RTL source files are provided along with a user constraint file (UCF) that
|
65 |
|
|
was used during development to optimize the implementation times of the core.
|
66 |
|
|
The UCF does provide the PERIOD constraint used during development to judge
|
67 |
|
|
whether the operating speed objective would be met by the M65C02. The LOCing
|
68 |
|
|
of the pins was done to aid the implementation tools, and is not reflective of
|
69 |
|
|
any implementation constraints inherent in the M65C02 core logic.
|
70 |
|
|
|
71 |
|
|
The project, synthesis, and implementation settings were captured in a TCL
|
72 |
|
|
file. That file allows the duplication of the exact settings used to
|
73 |
|
|
synthesize and implement it in a Spartan-3AN FPGA.
|
74 |
|
|
|
75 |
|
|
M65C02-Test-Programs
|
76 |
|
|
--------------------
|
77 |
|
|
|
78 |
|
|
M65C02_Tst3.a65 - Kingswood A65 assembler source code test program
|
79 |
|
|
M65C02.bin - M65C02_Tst2.a65 output of the Kingswood assembler
|
80 |
|
|
M65C02.txt - M65C02_Tst2.a65 ASCII hex output of bin2txt.exe
|
81 |
|
|
M65C02_Tst.A65 - First test pgm: jmps, branches, stk ops, transfers
|
82 |
|
|
|
83 |
|
|
Memory-Images
|
84 |
|
|
-------------
|
85 |
|
|
|
86 |
|
|
M65C02_Decoder_ROM.coe - M65C02 core microprogram ALU control fields
|
87 |
|
|
M65C02_uPgm_V3a.coe - M65C02 core microprogram (Addressing mode control)
|
88 |
|
|
M65C02_Tst3.txt - Memory initialization file for M65C02 test program
|
89 |
|
|
|
90 |
|
|
Microprogram-Sources
|
91 |
|
|
--------------------
|
92 |
|
|
|
93 |
|
|
M65C02_Decoder_ROM.txt - M65C02 core microprogram ALU control fields
|
94 |
|
|
M65C02_Decoder_ROM.out - Listing file
|
95 |
|
|
M65C02_uPgm_V3a.txt - M65C02 core microprogram (sequence control)
|
96 |
|
|
M65C02_uPgm_V3a.out - Listing file
|
97 |
|
|
|
98 |
|
|
RTL
|
99 |
|
|
-------------
|
100 |
|
|
|
101 |
|
|
The implementation of the core provided consists of five Verilog source files:
|
102 |
|
|
|
103 |
|
|
M65C02_Core.v - Top level module
|
104 |
|
|
M65C02_MPCv3.v - Microprogram Controller (Fairchild F9408 MPC)
|
105 |
|
|
M65C02_AddrGen.v - M65C02 Address Generator module
|
106 |
|
|
M65C02_ALU.v - M65C02 ALU module
|
107 |
|
|
M65C02_BIN.v - M65C02 Binary Mode Adder module
|
108 |
|
|
M65C02_BCD.v - M65C02 Decimal Mode Adder module
|
109 |
|
|
M65C02.ucf - User Constraints File: period and pin LOCs
|
110 |
|
|
|
111 |
|
|
In addition to the above files, the directory also contains another core. This
|
112 |
|
|
core is the base core and is based on the original release, but includes the
|
113 |
|
|
corrections needed to perform all zero page addressing modes correctly. The
|
114 |
|
|
solution employed for this version of the core is implemented in logic instead
|
115 |
|
|
of in the microprogram. The results are the same, but less flexible. Thus, if
|
116 |
|
|
this core would be extended to support additional instructions, then the
|
117 |
|
|
solution used for correctly supporting zero page addressing modes may require
|
118 |
|
|
modification, and it can impose limits on the microprogram. This core has been
|
119 |
|
|
maintained while the new core is being migrated to support LUT, BRAM, and
|
120 |
|
|
external SynchRAM using a microcycle length controller in the microprogram
|
121 |
|
|
controller instead of an asynchronous wait state inserter in the microprogram
|
122 |
|
|
controller. The files for the base (original) core are:
|
123 |
|
|
|
124 |
|
|
M65C02_Base.v - Top level module
|
125 |
|
|
M65C02_MPC.v - Microprogram Controller (Fairchild F9408 MPC)
|
126 |
|
|
M65C02_AddrGen.v - M65C02 Address Generator module
|
127 |
|
|
M65C02_ALU.v - M65C02 ALU module
|
128 |
|
|
M65C02_BIN.v - M65C02 Binary Mode Adder module
|
129 |
|
|
M65C02_BCD.v - M65C02 Decimal Mode Adder module
|
130 |
|
|
M65C02.ucf - User Constraints File: period and pin LOCs
|
131 |
|
|
|
132 |
|
|
As can be seen, only the core logic file and the microprogram controller are
|
133 |
|
|
different between the two implementations. The fixed portion of the
|
134 |
|
|
microprogram (which implements the ALU control word) is also common, but the
|
135 |
|
|
variable microprogram (which implements the addressing modes, instruction
|
136 |
|
|
sequences, and trap handling) are different. For this base (original) core,
|
137 |
|
|
the microprogram files are the following:
|
138 |
|
|
|
139 |
|
|
M65C02_Decoder_ROM.txt - M65C02 core microprogram ALU control fields
|
140 |
|
|
M65C02_Decoder_ROM.out - Listing file
|
141 |
|
|
M65C02_uPgm_V3.txt - M65C02 core microprogram (sequence control)
|
142 |
|
|
M65C02_uPgm_V3.out - Listing file
|
143 |
|
|
|
144 |
|
|
Settings
|
145 |
|
|
-------------
|
146 |
|
|
|
147 |
|
|
M65C02.tcl - Project settings file
|
148 |
|
|
|
149 |
|
|
Status
|
150 |
|
|
------
|
151 |
|
|
|
152 |
|
|
All files are current.
|