OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [cpu/] [control/] [execute.v] - Blame information for rev 8

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

Line No. Rev Author Line
1 8 gdevic
//=============================================================================
2
// This module implements the instruction execute state logic.
3
//
4
//  Copyright (C) 2014-2016  Goran Devic
5
//
6
//  This program is free software; you can redistribute it and/or modify it
7
//  under the terms of the GNU General Public License as published by the Free
8
//  Software Foundation; either version 2 of the License, or (at your option)
9
//  any later version.
10
//
11
//  This program is distributed in the hope that it will be useful, but WITHOUT
12
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
//  more details.
15
//
16
//  You should have received a copy of the GNU General Public License along
17
//  with this program; if not, write to the Free Software Foundation, Inc.,
18
//  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
//=============================================================================
20
// Using a compiled format will include files generated by "gencompile.py" script
21
// These files are a processed version of "exec_matrix_compiled.vh"
22
// You would define this on Xilinx and undefine (comment out) on Altera
23
`define USE_COMPILED_FORMAT
24
 
25
module execute
26
(
27
    //----------------------------------------------------------
28
    // Control signals generated by the instruction execution
29
    //----------------------------------------------------------
30
    `include "exec_module.vh"
31
 
32
    output reg nextM,                   // Last M cycle of any instruction
33
    output reg setM1,                   // Last T clock of any instruction
34
    output reg fFetch,                  // Function: opcode fetch cycle ("M1")
35
    output reg fMRead,                  // Function: memory read cycle
36
    output reg fMWrite,                 // Function: memory write cycle
37
    output reg fIORead,                 // Function: IO Read cycle
38
    output reg fIOWrite,                // Function: IO Write cycle
39
 
40
    //----------------------------------------------------------
41
    // Inputs from the instruction decode PLA
42
    //----------------------------------------------------------
43
    input wire [104:0] pla,             // Statically decoded instructions
44
 
45
    //----------------------------------------------------------
46
    // Inputs from various blocks
47
    //----------------------------------------------------------
48
    input wire in_intr,                 // Servicing maskable interrupt
49
    input wire in_nmi,                  // Servicing non-maskable interrupt
50
    input wire in_halt,                 // Currently in HALT mode
51
    input wire im1,                     // Interrupt Mode 1
52
    input wire im2,                     // Interrupt Mode 2
53
    input wire use_ixiy,                // Special decode signal
54
    input wire flags_cond_true,         // Flags condition is true
55
    input wire repeat_en,               // Enable repeat of a block instruction
56
    input wire flags_zf,                // ZF to test a condition
57
    input wire flags_nf,                // NF to test for subtraction
58
    input wire flags_sf,                // SF to test for 8-bit sign of a value
59
    input wire flags_cf,                // CF to set HF for CCF
60
 
61
    //----------------------------------------------------------
62
    // Machine and clock cycles
63
    //----------------------------------------------------------
64
    input wire M1,                      // Machine cycle #1
65
    input wire M2,                      // Machine cycle #2
66
    input wire M3,                      // Machine cycle #3
67
    input wire M4,                      // Machine cycle #4
68
    input wire M5,                      // Machine cycle #5
69
    input wire T1,                      // T-cycle #1
70
    input wire T2,                      // T-cycle #2
71
    input wire T3,                      // T-cycle #3
72
    input wire T4,                      // T-cycle #4
73
    input wire T5,                      // T-cycle #5
74
    input wire T6                       // T-cycle #6
75
);
76
 
77
// Detects unknown instructions by signalling the known ones
78
reg validPLA;                           // Valid PLA asserts this reg
79
// Activates a state machine to compute WZ=IX+d; takes 5T cycles
80
reg ixy_d;                              // Compute WX=IX+d
81
// Signals the setting of IX/IY and CB/ED prefix flags; inhibits clearing them
82
reg setIXIY;                            // Set IX/IY flag at the next T cycle
83
reg setCBED;                            // Set CB or ED flag at the next T cycle
84
// Holds asserted by non-repeating versions of block instructions (LDI/CPI,...)
85
reg nonRep;                             // Non-repeating block instruction
86
// Suspends incrementing PC through address latch unless in HALT or interrupt mode
87
reg pc_inc_hold;                        // Normally 0 unless in one of those modes
88
 
89
//--------------------------------------------------------------
90
// Define various shortcuts to field naming
91
//--------------------------------------------------------------
92
`define GP_REG_BC       2'h0
93
`define GP_REG_DE       2'h1
94
`define GP_REG_HL       2'h2
95
`define GP_REG_AF       2'h3
96
 
97
`define PFSEL_P         2'h0
98
`define PFSEL_V         2'h1
99
`define PFSEL_IFF2      2'h2
100
`define PFSEL_REP       2'h3
101
 
102
//--------------------------------------------------------------
103
// Make available different bits and sections of the opcode byte
104
//--------------------------------------------------------------
105
wire op0 = pla[99];
106
wire op1 = pla[100];
107
wire op2 = pla[101];
108
wire op3 = pla[102];
109
wire op4 = pla[103];
110
wire op5 = pla[104];
111
 
112
wire [1:0] op21 = { pla[101], pla[100] };
113
wire [1:0] op54 = { pla[104], pla[103] };
114
 
115
//--------------------------------------------------------------
116
// 8-bit register selections needs to swizzle mux for A and F
117
//--------------------------------------------------------------
118
wire rsel0 = op0 ^ (op1 & op2);
119
wire rsel3 = op3 ^ (op4 & op5);
120
 
121
`ifdef USE_COMPILED_FORMAT
122
`include "temp_wires.vh"                // Define all temp wires used with compiled equations
123
`endif
124
 
125
always @(*) // always_comb
126
begin
127
    //-----------------------------------------------------------------------------
128
    // Default assignment of all control outputs to 0 to prevent generating latches
129
    //-----------------------------------------------------------------------------
130
    `include "exec_zero.vh"             // Initial assignment to all ctl wires to zero
131
 
132
    // Reset internal control regs
133
    validPLA = 0;                       // Will be set by every *valid* PLA entry
134
    nextM = 0;                          // Will be set to advance to the next M cycle
135
    setM1 = 0;                          // Will be set on a last M/T cycle of an instruction
136
 
137
    // Reset global machine cycle functions
138
    fFetch = M1;                        // Fetch is aliased to M1
139
    fMRead = 0; fMWrite = 0; fIORead = 0; fIOWrite = 0;
140
    ixy_d = 0;
141
    setIXIY = 0;
142
    setCBED = 0;
143
    nonRep = 0;
144
    pc_inc_hold = 0;
145
 
146
    //-------------------------------------------------------------------------
147
    // State-based signal assignment; code generated from Timings spreadsheet
148
    //-------------------------------------------------------------------------
149
`ifdef USE_COMPILED_FORMAT
150
    `include "exec_matrix_compiled.vh"  // Compiled execution equations
151
`else
152
    `include "exec_matrix.vh"           // Execution statements in the original nested-if format
153
`endif
154
 
155
    // Needed by data bus 0 override logic, make only one bus writer active at any time
156
    ctl_bus_db_oe = ctl_bus_db_oe & ~(ctl_bus_zero_oe | ctl_bus_ff_oe);
157
 
158
end
159
 
160
endmodule

powered by: WebSVN 2.1.0

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