OpenCores
URL https://opencores.org/ocsvn/test/test/trunk

Subversion Repositories test

[/] [test/] [trunk/] [wb_z80/] [rtl/] [memstate2.v] - Blame information for rev 47

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

Line No. Rev Author Line
1 47 mihal
 
2 45 mihal
///////////////////////////////////////////////////////////////////////////////////////////////////
3
//                                                                                               //
4
//  file name:   memstate2.v                                                                       //
5
//  description: memory opertions for  z80                                                       //
6
//  project:     wb_z80                                                                          //
7
//                                                                                               //
8
//  Author: B.J. Porcella                                                                        //
9
//  e-mail: bporcella@sbcglobal.net                                                              //
10
//                                                                                               //
11
//                                                                                               //
12
//                                                                                               //
13
///////////////////////////////////////////////////////////////////////////////////////////////////
14
//                                                                                               //
15
// Copyright (C) 2000-2002 B.J. Porcella                                                         //
16
//                         Real Time Solutions                                                   //
17
//                                                                                               //
18
//                                                                                               //
19
// This source file may be used and distributed without                                          //
20
// restriction provided that this copyright statement is not                                     //
21
// removed from the file and that any derivative work contains                                   //
22
// the original copyright notice and the associated disclaimer.                                  //
23
//                                                                                               //
24
//     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY                                       //
25
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED                                     //
26
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS                                     //
27
// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR                                        //
28
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,                                           //
29
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES                                      //
30
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE                                     //
31
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR                                          //
32
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF                                    //
33
// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT                                    //
34
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT                                    //
35
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE                                           //
36
// POSSIBILITY OF SUCH DAMAGE.                                                                   //
37
//                                                                                               //
38
//-------1---------2---------3--------Comments on file  -------------7---------8---------9--------0
39
// The memory state controller controls the wb bus, and provides address sequencing.
40
// Insructions are fetched in order (using PC) until the istate machine indicates that 
41
// a complete instruction is in the first pipline stage (ir1). In general, operands are being
42
// fetched (stored) to satisfy ir1 while concurrently instructions are being executed from ir2.
43
// this situation can result in a number of potential hazards.   As an example, if the ir2
44
// instruction changes the flag register and the ir1 instruction is a conditional jump, 
45
// a hazard is generated by the hazard logic, and execution of the ir1 operation is delayed 
46
// until the completion of the flag update.
47
//
48
// Reset starts execution at 0.  
49
// The PC and SP are described in this file.   modifications to other index registers - 
50
// HL IX and IY are computed here -- 
51
// For the block moves address updates are computed here   -- and commanded here.
52
// Strobes for the second address update are generally co-incident with count updates, but
53
// we provide seperate strobe update lines for clarity.
54
//
55
//  BASIC ARCHITECTURE OF THIS FILE   pc  and sp not shown, but are inputs to src mux.
56
//                    _____           and may be updated from adder output.
57
//                   |     |
58
//                   |     |          pc-1 register is required to implement relative jumps.
59
//                   |     |                     
60
//      _____        |lit  |      |\             
61
//     |     |       |     |      |  \           
62
//     |     |       |src2 |      |    \          _____          _____ 
63
//     |     |       |     |----->|     |        |     |        |     |
64
//     |src  |       |_____|      |adder|------->|     |        |     |
65
//     |mux  |                    |     |        |     |        |     |
66
//     |     |------------------->|    /         |2/1  |------->|wb   |
67
//     |     |              |     |  /           |mux  |        |adr  |
68
//     |_____|              |     |/             |     |        |     |
69
//                           ------------------->|     |        |     |
70
//                                               |_____|        |_____|
71
//
72
//
73
//
74
//
75
//  Operand Stores:
76
//  At first cut, I thought I'ld execute operand stores immediately from the memory sequencer
77
//  (essentially before ir2 got the store data).  While this might be modestly faster in 
78
//  systems that take multiple clocks to complete a memory store, On consideration, I decided 
79
//  to forgo the extra speed for conceptual simplicity....   execute operand stores on op_ph1,
80
//  and let the inst_exec engine suply the operand.
81
//
82
//  On second thought, above is not only wastful of time, but also inconsistent with the overall
83
//  schems of things - and so somewhat more complex. If we simply execute the OS from ir1, 
84
//  There is less state to contdend with, as well as extra speed.
85
//
86
//  Block Moves fundamentally execute from ir2.  We initiate the first operand fetch from ir1.
87
//
88
//  3/18/2004 Second time through.   In impleenting the execution logic it became clear that
89
//  there were "minor" problems with the handling of the DD and FD prefix insts (especially
90
//  DDCD and FDCB  ---  collectively called PFxCB below.  On review, I had to question the
91
//  value of "breaking up" the ir0 execution engine between the istate sequencer and the 
92
//  memstate sequencer.   While I dislike state sequencers of much more than 16 states  --  
93
//  the interaction between these sequencers was becomming harder to track than a single
94
//  state macine.   Thus - this file is getting re-worked.   I will call it memstate2 (at least
95
//  for awhile) as I wish to keep the old file around.  I want to show (in the state machine
96
//  logic) what the next memory operation is....   guess the best method consistent with my
97
//  documentation practices is to define a register (mem_op)  = { if, wb_we, wb_cyc }.  
98
//  This will require auxillary logic for computing the address ---  but most of the decodes
99
//  required will be there anyway.   
100
//  On further reflection, I think I will bite-the-bullet and use an always to define next_state.
101
//  I don't like to use always to define wires, but I also want to dicument the setting of 
102
//  exec_ir2 in the same place - that is 3 different things.  
103
//  
104
//  Hazards:
105
//  There are 2 kinds of hazards:  mem_hazard => we are storing into the next instruction location
106
//                                 reg_hazard => we are modifying a register (ir2) that we are using
107
//                                                here (ir1)
108
//  In the former case, we throw out the instruction that arrives on the next tick, and restart the
109
//  instruction pipeline,   In the latter case, we simply wait a tick for the ir2 operaton to 
110
//  complete before starting the ir1 operation  
111
//-------1---------2---------3--------CVS Log -----------------------7---------8---------9--------0
112
//
113 47 mihal
//  $Id: memstate2.v,v 1.3 2004-04-19 07:28:58 mihal Exp $
114 45 mihal
//
115 47 mihal
//  $Date: 2004-04-19 07:28:58 $
116
//  $Revision: 1.3 $
117 45 mihal
//  $Author: mihal $
118
//  $Locker:  $
119
//  $State: Exp $
120
//
121
// Change History:
122
//      $Log: not supported by cvs2svn $
123 47 mihal
//      Revision 1.2  2004/04/17 08:02:00  mihal
124
//      testing lint
125
//
126 46 mihal
//      Revision 1.1  2004/04/17 07:39:21  mihal
127
//      testing lint
128
//
129 45 mihal
//      Revision 1.4  2004/04/16 18:16:57  bporcella
130
//      try lint
131
//
132
//      Revision 1.3  2004/04/16 17:06:54  bporcella
133
//      no code change  -  added a comment and test lint
134
//
135
//      Revision 1.2  2004/04/16 16:21:04  bporcella
136
//      no code change  -  added a comment and test lint
137
//
138
//      Revision 1.1.1.1  2004/04/13 23:50:19  bporcella
139
//      import first files
140
//
141
//
142
//
143 46 mihal
//
144 45 mihal
//-------1---------2---------3--------Module Name and Port List------7---------8---------9--------0
145 46 mihal
 
146 45 mihal
module memstate2(wb_adr, wb_we, wb_cyc, wb_stb, wb_lock, wb_tga_io, wb_dat_o,  add_out,
147
                exec_ir2, ir1, ir2, ir1dd, ir1fd, ir2dd, ir2fd, nn, sp,
148
 
149
                upd_ar, upd_br, upd_cr, upd_dr, upd_er, upd_hr, upd_lr,upd_fr,
150
                beq0, ceq0,
151
                ar, fr, br, cr, dr, er, hr, lr,
152
                ixr, iyr,
153
                wb_dat_i, wb_ack, clk, rst,
154
                wb_int_rq,
155
                add16
156
 
157
 
158
);
159
 
160
//-------1---------2---------3--------Output Ports---------6---------7---------8---------9--------0
161
// mod only to checkout lint
162
// mod again for lint check  --   first check pretty wierd
163
// 3rd lint try
164
output [15:0]  wb_adr;
165
output         wb_we;
166
output         wb_cyc;
167
output         wb_stb;
168
output         wb_lock;     // bit set and clear insts should be atomic - could matter sometime
169
output         wb_tga_io;
170
output         wb_dat_o;   // from nn
171
output [15:0]  add_out;     // output of adder  (may not wb_adr)
172
 
173
output         exec_ir2;
174
output [9:0]   ir1, ir2;
175
output         ir1dd, ir2dd;
176
output          ir1fd, ir2fd;
177
output [15:0]   nn;
178
output [15:0]   sp;
179
 
180
 
181
 
182
 
183
//-------1---------2---------3--------Input Ports----------6---------7---------8---------9--------0
184
input           upd_ar, upd_br, upd_cr, upd_dr, upd_er, upd_hr, upd_lr,upd_fr;
185
 
186
input           beq0, ceq0;
187
input [7:0]     ar, fr, br, cr, dr, er, hr, lr;
188
input [15:0]    ixr, iyr;
189
input [7:0]     wb_dat_i;
190
input           wb_ack, clk, rst;
191
input           wb_int_rq;
192
input [15:0]    add16;         //  ir2 execution engine output for sp updates
193
 
194
 
195
//-------1---------2---------3--------Parameters-----------6---------7---------8---------9--------0
196
`include "opcodes.v"            //  states of the main memory sequencer
197
 
198
 
199
parameter   TAG_IO    = 2'b01,   // need to review general wb usage to undrstand how best to 
200
            TAG_INT   = 2'b10;   // document this.
201
            //                  12na
202
parameter   IPIPE_NOP       = 4'b0000,
203
            IPIPE_A2        = 4'b0001,
204
            IPIPE_ENN       = 4'b0010,
205
            IPIPE_ENNA2     = 4'b0011,
206
            IPIPE_EN2       = 4'b0100,
207
            IPIPE_EN2A2     = 4'b0101,
208
            IPIPE_ENNEN2    = 4'b0110,
209
            IPIPE_ENNEN2A2  = 4'b0111,
210
            IPIPE_EN1       = 4'b1000,
211
            IPIPE_EN1A2     = 4'b1001,
212
            IPIPE_BOGUS     = 4'b1010,  // no reason (yet) to load both n and ir1
213
            IPIPE_BOUS2     = 4'b1011,
214
            IPIPE_EN12      = 4'b1100,
215
            IPIPE_EN12A2    = 4'b1101,
216
            IPIPE_BOGUS3    = 4'b1110,
217
            IPIPE_BOGUS4    = 4'b1111;
218
 
219
//  well at first cut I tried to make this 2 state macines both less than 16 states.
220
//  this is 56 states at first cut.   Assignemnt is subject to change.
221
 
222
// ------  mem state decoder state machine states --------------------------------
223
parameter       DEC_IDLE      = 6'h00,
224
                DEC_HALT      = 6'h01,
225
                DEC_IF1       = 6'h02,
226
                DEC_IF2       = 6'h03,
227
                DEC_IF2A      = 6'h04,
228
                DEC_EXEC      = 6'h05,
229
                DEC_CB        = 6'h06,
230
                DEC_DDFD      = 6'h07,
231
                DEC_ED        = 6'h08,
232
                DEC_EDNN1     = 6'h09,
233
                DEC_EDNN2     = 6'h0a,
234
                DEC_EDRD1     = 6'h0b,
235
                DEC_EDRD2     = 6'h0c,
236
                DEC_EDWR      = 6'h0d,
237
                DEC_EDBCP1    = 6'h0e,
238
                DEC_EDBCP2    = 6'h0f,
239
                DEC_EDBCP3    = 6'h10,
240
                DEC_EDBIN1    = 6'h11,
241
                DEC_EDBIN2    = 6'h12,
242
                DEC_EDBIN3    = 6'h13,
243
                DEC_EDBOUT1   = 6'h14,
244
                DEC_EDBOUT2   = 6'h15,
245
                DEC_EDBOUT3   = 6'h16,
246
                DEC_EDBMV1    = 6'h17,
247
                DEC_EDBMV2    = 6'h18,
248
                DEC_EDBMV3    = 6'h19,
249
                DEC_N         = 6'h1a,
250
                DEC_NIN       = 6'h1b,
251
                DEC_NN        = 6'h1c,
252
                DEC_NNCALL1   = 6'h1d,
253
                DEC_NNCALL2   = 6'h1e,
254
                DEC_NNOS1     = 6'h1f,
255
                DEC_NNOS2     = 6'h20,
256
                DEC_NNOS3     = 6'h21,
257
                DEC_NNOF1     = 6'h22,
258
                DEC_NNOF2     = 6'h23,
259
                DEC_NNOF3     = 6'h24,
260
                DEC_NNOF4     = 6'h25,
261
                DEC_DDOS      = 6'h26,
262
                DEC_DDOF      = 6'h27,
263
                DEC_OF        = 6'h28,
264
                DEC_POP       = 6'h29,
265
                DEC_PUSH      = 6'h2a,
266
                DEC_RMW       = 6'h2b,
267
                DEC_RMW2      = 6'h2c,
268
                DEC_CBM       = 6'h2d,
269
                DEC_PFxCB     = 6'h2e,
270
                DEC_PFxCB2    = 6'h2f,
271
                DEC_PFxCB3    = 6'h30,
272
                DEC_PFxCB4    = 6'h31,
273
                DEC_INT1      = 6'h32,
274
                DEC_INT2      = 6'h33,
275
                DEC_INT3      = 6'h34,
276
                DEC_INT4      = 6'h35,
277
                DEC_INT5      = 6'h36,
278
                DEC_RET       = 6'h37,
279
                DEC_NNJMP     = 6'h38,
280
                DEC_RET2      = 6'h39 ;
281
 
282
//  initial decode assignemnts.   These assignemens are made to wires on an initial decode
283
//  to help document next state transitions
284
parameter      I1_CB    = 4'h0,
285
               I1_DDFD  = 4'h1,
286
               I1_ED    = 4'h2,
287
               I1_JMP   = 4'h3,
288
               I1_N     = 4'h4,
289
               I1_NN    = 4'h5,
290
               I1_OF    = 4'h6,
291
               I1_OS    = 4'h7,
292
               I1_POP   = 4'h8,
293
               I1_PUSH  = 4'h9,
294
               I1_RET   = 4'ha,
295
               I1_RMW   = 4'hb,
296
               I1_RST   = 4'hc,
297
               I1_R2R   = 4'hd ;
298
 
299
 
300
// A note here on the choices of mnemonics.....   in general, the target registers of 
301
// memory ops are specified by an instruction register  (ir1 for stores ir2 for loads).
302
// so Menomics in general are specifying the address source.   However, there are exceptions.
303
//
304
parameter       MEM_NOP      = 5'h00,
305
                MEM_IFPP1    = 5'h01,
306
                MEM_OS1      = 5'h02,      //  only invoked on I1 OS  multiple address sources and data sources
307
                MEM_OF1      = 5'h03,     //  Address from HL  unless   LD A,(BC) or LD A,(DE)  (used for rmw)
308
                MEM_OFSP     = 5'h04,     //  works for both POP and RET 
309
                MEM_OSSP     = 5'h05,     //  if DEC_EXEC  op from ir1  else msb nn  (implies we store from lsb nn)
310
                                          //  used in CALL also.  
311
                MEM_OFIXpD   = 5'h06,     //  used for prefix op fetches  - all single bytes
312
                MEM_OSIXpD   = 5'h07,     //  data source is same as MEM_OS1
313
                MEM_OSADR    = 5'h08,     //  used (at lesat)  for prefixed rmw --  perhaps others.
314
 
315
                MEM_CALL     = 5'h09,     // pc<=nn, nn<=pc, wb_adr<=sp   OS 
316
                MEM_OSNN     = 5'h0a,     //  if DEC_EXEC  op from ir1  else msb nn
317
                MEM_OFNN     = 5'h0b,     // striaghtfoward
318
                MEM_OFADRP1  = 5'h0c,     // used (at least) when double ops above
319
                MEM_OSADRP1  = 5'h0d,     //  ""              ""              ""
320
 
321
                MEM_IFRST    = 5'h0e,     // special address transfer
322
                MEM_IFREL_N  = 5'h0f,     // special address transfer for jmp rel
323
                MEM_JMPHL    = 5'h10,     // another special jump transfer
324
                MEM_IFNN     = 5'h11,        //  used by call and return
325
 
326
 
327
                MEM_OFHL_PM  = 5'h12,             // special block move ops  
328
                MEM_OSHL_PM  = 5'h13,             // special block move ops
329
                MEM_OSDE_PM  = 5'h14,             // special block move ops
330
 
331
                MEM_IOF_C    = 5'h15,             // special i/o ops
332
                MEM_IOS_C    = 5'h16,             // operand is ar
333
                MEM_IOF_N    = 5'h17,
334
                MEM_IOS_N    = 5'h18,
335
                MEM_OS_HL_N  = 5'h19,
336
 
337
                MEM_OSSP_PCM2 = 5'h1a,              // int code  (call 
338
                MEM_OSSP_P   = 5'h1b,              //
339
                MEM_INTA     = 5'h1c,
340
                MEM_IFINT    = 5'h1d,
341
                MEM_DECPC    = 5'h1e ;
342
 
343
 
344
 
345
 
346
 
347
 
348
 
349
 
350
 
351
//-------1---------2---------3--------Wires----------------6---------7---------8---------9--------0
352
 
353
 
354
wire        use_sp;
355
wire        use_pc;
356
wire        use_hl;
357
wire        use_de;
358
wire        use_bc;
359
wire        use_flags;
360
wire        cb_mem;
361
wire        br_test8t;  // branch test true  (8 test field)
362
wire        br_test4t;  // branch test true  (4 test field)
363
 
364
wire        ofos;
365
wire        any_os;   // most terms above only valid on mem_exec  this includes all stores
366
wire        wb_rdy_nhz;
367
wire        dec_blk_inc;
368
wire        we_next;
369
wire        hazard;
370
wire        wb_int;
371
wire [15:0] hl, de, bc;
372
wire        mem_exec_dec;
373
 
374
wire  use_a  ;
375
wire  use_b  ;
376
wire  use_c  ;
377
wire  use_d  ;
378
wire  use_e  ;
379
wire  use_h  ;
380
wire  use_l  ;
381
// don't forget that as 1r1 is executed it is transferred to ir2.  Anything I need to know
382
// about subsequent operations must be stored.
383
//               6              5              4                15
384
// assign {next_dec_state, next_mem_state, next_pipe_state} = next_state;
385
wire  [5:0]        next_dec_state;
386
wire  [4:0]        next_mem_state;
387
wire  [3:0]        next_pipe_state;
388
wire               ed_dbl_rd;
389
//-------1---------2---------3--------Registers------------6---------7---------8---------9--------0
390
 
391
reg [15:0]   pc;
392
reg [15:0]   sp;
393
reg [15:0]   wb_adr;
394
reg          wb_we;
395
reg          wb_cyc;
396
reg          wb_stb;
397
reg          wb_lock;
398
reg          wb_tga_io;
399
 
400
reg          blk_inc_flg;
401
reg [9:0]    ir1, ir2;
402
reg          ir1dd, ir2dd;
403
reg          ir1fd, ir2fd;
404
reg [15:0]   nn;
405
 
406
reg   [15:0]       next_state;      // a wire assigned in an alowys loop.
407
 
408
reg   [5:0]  dec_state;    // the register set each clock from next_dec_state;
409
 
410
reg          of16_reg,  os16_reg, rmw8_reg, call_reg, ret_reg, ioi;
411
reg          push_reg;
412
reg          pop_reg;
413
reg          inst_haz;
414
reg          exec_ir2;
415
reg          blk_rpt_flg;
416
reg          blk_io_flg;
417
reg          flag_os1;
418
reg          int_en, en_int_next;
419
reg          wb_irq_sync;
420
//-------1---------2---------3--------Assignments----------6---------7---------8---------9--------0
421
//
422
// ir is 10 bits most significant codes ir1[9:8] = { EDgrp, CBgrp }  DDgrp and FDgrp are modifiers
423
 
424
 
425
assign wb_dat_o = nn[15:8];
426
 
427
wire   sf, zf, f5f, hf, f3f, pvf, nf, cf;
428
assign { sf, zf, f5f, hf, f3f, pvf, nf, cf} = fr;
429
 
430
 
431
assign hl = {hr, lr};
432
assign de = {dr, er};
433
assign bc = {br, cr};
434
 
435
 
436
//  this "groups" the instructions to determine first memory operation
437
 
438
parameter  I1DCNT = 4;  // parameter used below simply to make possible change easier.
439
assign mem_exec_dec =
440
    {I1DCNT {CBgrp        == ir1}} & I1_CB  |//       CBgrp is rotates and bi
441
    {I1DCNT {DDgrp        == ir1}} & I1_DDFD|//      DDgrp   
442
    {I1DCNT {FDgrp        == ir1}} & I1_DDFD|//      FDgrp          FD
443
    {I1DCNT {EDgrp        == ir1}} & I1_ED  |//      EDgrp          ED
444
    {I1DCNT {JPsHL        == ir1}} & I1_JMP |//      JP HL        ; E9 // doc
445
    {I1DCNT {ADCsA_N      == ir1}} & I1_N   |//      ADC A,N      ; CE XX
446
    {I1DCNT {ADDsA_N      == ir1}} & I1_N   |//      ADD A,N      ; C6 XX
447
    {I1DCNT {ANDsN        == ir1}} & I1_N   |//      AND N        ; E6 XX
448
    {I1DCNT {CPsN         == ir1}} & I1_N   |//      CP N         ; FE XX
449
    {I1DCNT {INsA_6N7     == ir1}} & I1_N   |//      IN A,(N)     ; DB XX
450
    {I1DCNT {JRs$t2       == ir1}} & I1_N   |//      JR $+2       ; 18 XX
451
    {I1DCNT {JRsC_$t2     == ir1}} & I1_N   |//      JR C,$+2     ; 38 XX
452
    {I1DCNT {JRsNC_$t2    == ir1}} & I1_N   |//      JR NC,$+2    ; 30 XX
453
    {I1DCNT {JRsZ_$t2     == ir1}} & I1_N   |//      JR Z,$+2     ; 28 XX
454
    {I1DCNT {JRsNZ_$t2    == ir1}} & I1_N   |//      JR NZ,$+2    ; 20 XX
455
    {I1DCNT {LDs6HL7_N    == ir1}} & I1_N   |//      LD (HL),N    ; 36 XX
456
    {I1DCNT {LDsA_N       == ir1}} & I1_N   |//      LD A,N       ; 3E XX
457
    {I1DCNT {LDsB_N       == ir1}} & I1_N   |//      LD B,N       ; 06 XX
458
    {I1DCNT {LDsC_N       == ir1}} & I1_N   |//      LD C,N       ; 0E XX
459
    {I1DCNT {LDsD_N       == ir1}} & I1_N   |//      LD D,N       ; 16 XX
460
    {I1DCNT {LDsE_N       == ir1}} & I1_N   |//      LD E,N       ; 1E XX
461
    {I1DCNT {LDsH_N       == ir1}} & I1_N   |//      LD H,N       ; 26 XX
462
    {I1DCNT {LDsL_N       == ir1}} & I1_N   |//      LD L,N       ; 2E XX
463
    {I1DCNT {ORsN         == ir1}} & I1_N   |//      OR N         ; F6 XX
464
    {I1DCNT {OUTs6N7_A    == ir1}} & I1_N   |//      OUT (N),A    ; D3 XX
465
    {I1DCNT {SBCsA_N      == ir1}} & I1_N   |//      SBC A,N      ; DE XX
466
    {I1DCNT {SUBsN        == ir1}} & I1_N   |//      SUB N        ; D6 XX
467
    {I1DCNT {XORsN        == ir1}} & I1_N   |//      XOR N        ; EE XX
468
    {I1DCNT {CALLsC_NN    == ir1}} & I1_NN  |//      CALL C,NN    ; DC XX XX
469
    {I1DCNT {CALLsNC_NN   == ir1}} & I1_NN  |//      CALL NC,NN   ; D4 XX XX
470
    {I1DCNT {CALLsNN      == ir1}} & I1_NN  |//      CALL NN      ; CD XX XX
471
    {I1DCNT {CALLsNZ_NN   == ir1}} & I1_NN  |//      CALL NZ,NN   ; C4 XX XX
472
    {I1DCNT {CALLsPE_NN   == ir1}} & I1_NN  |//      CALL PE,NN   ; EC XX XX
473
    {I1DCNT {CALLsPO_NN   == ir1}} & I1_NN  |//      CALL PO,NN   ; E4 XX XX
474
    {I1DCNT {CALLsP_NN    == ir1}} & I1_NN  |//      CALL P,NN    ; F4 XX XX
475
    {I1DCNT {CALLsZ_NN    == ir1}} & I1_NN  |//      CALL Z,NN    ; CC XX XX
476
    {I1DCNT {CALLsM_NN    == ir1}} & I1_NN  |//      CALL M,NN    ; FC XX XX
477
    {I1DCNT {JP           == ir1}} & I1_NN  |//      JP           ; C3 XX XX
478
    {I1DCNT {JPsC         == ir1}} & I1_NN  |//      JP C         ; DA XX XX
479
    {I1DCNT {JPsM         == ir1}} & I1_NN  |//      JP M,        ; FA XX XX
480
    {I1DCNT {JPsNC        == ir1}} & I1_NN  |//      JP NC,       ; D2 XX XX
481
    {I1DCNT {JPsNZ        == ir1}} & I1_NN  |//      JP NZ        ; C2 XX XX
482
    {I1DCNT {JPsP         == ir1}} & I1_NN  |//      JP P         ; F2 XX XX
483
    {I1DCNT {JPsPE        == ir1}} & I1_NN  |//      JP PE,       ; EA XX XX
484
    {I1DCNT {JPsPO        == ir1}} & I1_NN  |//      JP PO        ; E2 XX XX
485
    {I1DCNT {JPsZ         == ir1}} & I1_NN  |//      JP Z         ; CA XX XX
486
    {I1DCNT {LDs6NN7_A    == ir1}} & I1_NN  |//      LD (NN),A    ; 32 XX XX
487
    {I1DCNT {LDs6NN7_HL   == ir1}} & I1_NN  |//      LD (NN),HL   ; 22 XX XX
488
    {I1DCNT {LDsA_6NN7    == ir1}} & I1_NN  |//      LD A,(NN)    ; 3A XX XX
489
    {I1DCNT {LDsBC_NN     == ir1}} & I1_NN  |//      LD BC,NN     ; 01 XX XX
490
    {I1DCNT {LDsDE_NN     == ir1}} & I1_NN  |//      LD DE,NN     ; 11 XX XX
491
    {I1DCNT {LDsHL_6NN7   == ir1}} & I1_NN  |//      LD HL,(NN)   ; 2A XX XX
492
    {I1DCNT {LDsHL_NN     == ir1}} & I1_NN  |//      LD HL,NN     ; 21 XX XX
493
    {I1DCNT {LDsSP_NN     == ir1}} & I1_NN  |//      LD SP,NN     ; 31 XX XX
494
    {I1DCNT {ADCsA_6HL7   == ir1}} & I1_OF  |//      ADC A,(HL)   ; 8E
495
    {I1DCNT {ADDsA_6HL7   == ir1}} & I1_OF  |//      ADD A,(HL)   ; 86
496
    {I1DCNT {ANDs6HL7     == ir1}} & I1_OF  |//      AND (HL)     ; A6
497
    {I1DCNT {CPs6HL7      == ir1}} & I1_OF  |//      CP (HL)      ; BE
498
    {I1DCNT {LDsA_6BC7    == ir1}} & I1_OF  |//      LD A,(BC)    ; 0A
499
    {I1DCNT {LDsA_6DE7    == ir1}} & I1_OF  |//      LD A,(DE)    ; 1A
500
    {I1DCNT {LDsA_6HL7    == ir1}} & I1_OF  |//      LD A,(HL)    ; 7E
501
    {I1DCNT {LDsB_6HL7    == ir1}} & I1_OF  |//      LD B,(HL)    ; 46
502
    {I1DCNT {LDsC_6HL7    == ir1}} & I1_OF  |//      LD C,(HL)    ; 4E
503
    {I1DCNT {LDsD_6HL7    == ir1}} & I1_OF  |//      LD D,(HL)    ; 56
504
    {I1DCNT {LDsE_6HL7    == ir1}} & I1_OF  |//      LD E,(HL)    ; 5E
505
    {I1DCNT {LDsH_6HL7    == ir1}} & I1_OF  |//      LD H,(HL)    ; 66
506
    {I1DCNT {LDsL_6HL7    == ir1}} & I1_OF  |//      LD L,(HL)    ; 6E
507
    {I1DCNT {ORs6HL7      == ir1}} & I1_OF  |//      OR (HL)      ; B6
508
    {I1DCNT {SBCs6HL7     == ir1}} & I1_OF  |//      SBC (HL)     ; 9E
509
    {I1DCNT {SUBs6HL7     == ir1}} & I1_OF  |//      SUB (HL)     ; 96
510
    {I1DCNT {XORs6HL7     == ir1}} & I1_OF  |//      XOR (HL)     ; AE
511
    {I1DCNT {LDs6BC7_A    == ir1}} & I1_OS  |//      LD (BC),A    ; 02 
512
    {I1DCNT {LDs6DE7_A    == ir1}} & I1_OS  |//      LD (DE),A    ; 12
513
    {I1DCNT {LDs6HL7_A    == ir1}} & I1_OS  |//      LD (HL),A    ; 77
514
    {I1DCNT {LDs6HL7_B    == ir1}} & I1_OS  |//      LD (HL),B    ; 70
515
    {I1DCNT {LDs6HL7_C    == ir1}} & I1_OS  |//      LD (HL),C    ; 71
516
    {I1DCNT {LDs6HL7_D    == ir1}} & I1_OS  |//      LD (HL),D    ; 72
517
    {I1DCNT {LDs6HL7_E    == ir1}} & I1_OS  |//      LD (HL),E    ; 73
518
    {I1DCNT {LDs6HL7_H    == ir1}} & I1_OS  |//      LD (HL),H    ; 74
519
    {I1DCNT {LDs6HL7_L    == ir1}} & I1_OS  |//      LD (HL),L    ; 75
520
    {I1DCNT {POPsAF       == ir1}} & I1_POP |//      POP AF       ; F1
521
    {I1DCNT {POPsBC       == ir1}} & I1_POP |//      POP BC       ; C1
522
    {I1DCNT {POPsDE       == ir1}} & I1_POP |//      POP DE       ; D1
523
    {I1DCNT {POPsHL       == ir1}} & I1_POP |//      POP HL       ; E1
524
    {I1DCNT {PUSHsAF      == ir1}} & I1_PUSH|//      PUSH AF      ; F5
525
    {I1DCNT {PUSHsBC      == ir1}} & I1_PUSH|//      PUSH BC      ; C5
526
    {I1DCNT {PUSHsDE      == ir1}} & I1_PUSH|//      PUSH DE      ; D5
527
    {I1DCNT {PUSHsHL      == ir1}} & I1_PUSH|//      PUSH HL      ; E5
528
    {I1DCNT {ADCsA_A      == ir1}} & I1_R2R |//      ADC A,A      ; 8F
529
    {I1DCNT {ADCsA_B      == ir1}} & I1_R2R |//      ADC A,B      ; 88
530
    {I1DCNT {ADCsA_C      == ir1}} & I1_R2R |//      ADC A,C      ; 89
531
    {I1DCNT {ADCsA_D      == ir1}} & I1_R2R |//      ADC A,D      ; 8A
532
    {I1DCNT {ADCsA_E      == ir1}} & I1_R2R |//      ADC A,E      ; 8B
533
    {I1DCNT {ADCsA_H      == ir1}} & I1_R2R |//      ADC A,H      ; 8C
534
    {I1DCNT {ADCsA_L      == ir1}} & I1_R2R |//      ADC A,L      ; 8D
535
    {I1DCNT {ADDsA_A      == ir1}} & I1_R2R |//      ADD A,A      ; 87
536
    {I1DCNT {ADDsA_B      == ir1}} & I1_R2R |//      ADD A,B      ; 80
537
    {I1DCNT {ADDsA_C      == ir1}} & I1_R2R |//      ADD A,C      ; 81
538
    {I1DCNT {ADDsA_D      == ir1}} & I1_R2R |//      ADD A,D      ; 82
539
    {I1DCNT {ADDsA_E      == ir1}} & I1_R2R |//      ADD A,E      ; 83
540
    {I1DCNT {ADDsA_H      == ir1}} & I1_R2R |//      ADD A,H      ; 84
541
    {I1DCNT {ADDsA_L      == ir1}} & I1_R2R |//      ADD A,L      ; 85
542
    {I1DCNT {ADDsHL_BC    == ir1}} & I1_R2R |//      ADD HL,BC    ; 09
543
    {I1DCNT {ADDsHL_DE    == ir1}} & I1_R2R |//      ADD HL,DE    ; 19
544
    {I1DCNT {ADDsHL_HL    == ir1}} & I1_R2R |//      ADD HL,HL    ; 29
545
    {I1DCNT {ADDsHL_SP    == ir1}} & I1_R2R |//      ADD HL,SP    ; 39
546
    {I1DCNT {ANDsA        == ir1}} & I1_R2R |//      AND A        ; A7
547
    {I1DCNT {ANDsB        == ir1}} & I1_R2R |//      AND B        ; A0
548
    {I1DCNT {ANDsC        == ir1}} & I1_R2R |//      AND C        ; A1
549
    {I1DCNT {ANDsD        == ir1}} & I1_R2R |//      AND D        ; A2
550
    {I1DCNT {ANDsE        == ir1}} & I1_R2R |//      AND E        ; A3
551
    {I1DCNT {ANDsH        == ir1}} & I1_R2R |//      AND H        ; A4
552
    {I1DCNT {ANDsL        == ir1}} & I1_R2R |//      AND L        ; A5
553
    {I1DCNT {CCF          == ir1}} & I1_R2R |//      CCF          ; 3F
554
    {I1DCNT {CPL          == ir1}} & I1_R2R |//      CPL          ; 2F
555
    {I1DCNT {CPsA         == ir1}} & I1_R2R |//      CP A         ; BF
556
    {I1DCNT {CPsB         == ir1}} & I1_R2R |//      CP B         ; B8
557
    {I1DCNT {CPsC         == ir1}} & I1_R2R |//      CP C         ; B9
558
    {I1DCNT {CPsD         == ir1}} & I1_R2R |//      CP D         ; BA
559
    {I1DCNT {CPsE         == ir1}} & I1_R2R |//      CP E         ; BB
560
    {I1DCNT {CPsH         == ir1}} & I1_R2R |//      CP H         ; BC
561
    {I1DCNT {CPsL         == ir1}} & I1_R2R |//      CP L         ; BD
562
    {I1DCNT {DAA          == ir1}} & I1_R2R |//      DAA          ; 27
563
    {I1DCNT {DECsA        == ir1}} & I1_R2R |//      DEC A        ; 3D
564
    {I1DCNT {DECsB        == ir1}} & I1_R2R |//      DEC B        ; 05
565
    {I1DCNT {DECsBC       == ir1}} & I1_R2R |//      DEC BC       ; 0B
566
    {I1DCNT {DECsC        == ir1}} & I1_R2R |//      DEC C        ; 0D
567
    {I1DCNT {DECsD        == ir1}} & I1_R2R |//      DEC D        ; 15
568
    {I1DCNT {DECsDE       == ir1}} & I1_R2R |//      DEC DE       ; 1B
569
    {I1DCNT {DECsE        == ir1}} & I1_R2R |//      DEC E        ; 1D
570
    {I1DCNT {DECsH        == ir1}} & I1_R2R |//      DEC H        ; 25
571
    {I1DCNT {DECsHL       == ir1}} & I1_R2R |//      DEC HL       ; 2B
572
    {I1DCNT {DECsL        == ir1}} & I1_R2R |//      DEC L        ; 2D
573
    {I1DCNT {DECsSP       == ir1}} & I1_R2R |//      DEC SP       ; 3B
574
    {I1DCNT {DI           == ir1}} & I1_R2R |//      DI           ; F3
575
    {I1DCNT {DJNZs$t2     == ir1}} & I1_R2R |//      DJNZ $+2     ; 10 XX
576
    {I1DCNT {EI           == ir1}} & I1_R2R |//      EI           ; FB
577
    {I1DCNT {EXX          == ir1}} & I1_R2R |//      EXX          ; D9
578
    {I1DCNT {EXsAF_AFp    == ir1}} & I1_R2R |//      EX AF,AF'    ; 08
579
    {I1DCNT {EXsDE_HL     == ir1}} & I1_R2R |//      EX DE,HL     ; EB
580
    {I1DCNT {HALT         == ir1}} & I1_R2R |//      HALT         ; 76
581
    {I1DCNT {INCsA        == ir1}} & I1_R2R |//      INC A        ; 3C
582
    {I1DCNT {INCsB        == ir1}} & I1_R2R |//      INC B       ; 04
583
    {I1DCNT {INCsBC       == ir1}} & I1_R2R |//      INC BC      ; 03
584
    {I1DCNT {INCsC        == ir1}} & I1_R2R |//      INC C       ; 0C
585
    {I1DCNT {INCsD        == ir1}} & I1_R2R |//      INC D        ; 14
586
    {I1DCNT {INCsDE       == ir1}} & I1_R2R |//      INC DE       ; 13
587
    {I1DCNT {INCsE        == ir1}} & I1_R2R |//      INC E        ; 1C
588
    {I1DCNT {INCsH        == ir1}} & I1_R2R |//      INC H        ; 24
589
    {I1DCNT {INCsHL       == ir1}} & I1_R2R |//      INC HL       ; 23
590
    {I1DCNT {INCsL        == ir1}} & I1_R2R |//      INC L        ; 2C
591
    {I1DCNT {INCsSP       == ir1}} & I1_R2R |//      INC SP       ; 33
592
    {I1DCNT {LDsA_A       == ir1}} & I1_R2R |//      LD A,A       ; 7F
593
    {I1DCNT {LDsA_B       == ir1}} & I1_R2R |//      LD A,B       ; 78
594
    {I1DCNT {LDsA_C       == ir1}} & I1_R2R |//      LD A,C       ; 79
595
    {I1DCNT {LDsA_D       == ir1}} & I1_R2R |//      LD A,D       ; 7A
596
    {I1DCNT {LDsA_E       == ir1}} & I1_R2R |//      LD A,E       ; 7B
597
    {I1DCNT {LDsA_H       == ir1}} & I1_R2R |//      LD A,H       ; 7C
598
    {I1DCNT {LDsA_L       == ir1}} & I1_R2R |//      LD A,L       ; 7D
599
    {I1DCNT {LDsB_A       == ir1}} & I1_R2R |//      LD B,A       ; 47
600
    {I1DCNT {LDsB_B       == ir1}} & I1_R2R |//      LD B,B       ; 40
601
    {I1DCNT {LDsB_C       == ir1}} & I1_R2R |//      LD B,C       ; 41
602
    {I1DCNT {LDsB_D       == ir1}} & I1_R2R |//      LD B,D       ; 42
603
    {I1DCNT {LDsB_E       == ir1}} & I1_R2R |//      LD B,E       ; 43
604
    {I1DCNT {LDsB_H       == ir1}} & I1_R2R |//      LD B,H       ; 44
605
    {I1DCNT {LDsB_L       == ir1}} & I1_R2R |//      LD B,L       ; 45
606
    {I1DCNT {LDsC_A       == ir1}} & I1_R2R |//      LD C,A       ; 4F
607
    {I1DCNT {LDsC_B       == ir1}} & I1_R2R |//      LD C,B       ; 48
608
    {I1DCNT {LDsC_C       == ir1}} & I1_R2R |//      LD C,C       ; 49
609
    {I1DCNT {LDsC_D       == ir1}} & I1_R2R |//      LD C,D       ; 4A
610
    {I1DCNT {LDsC_E       == ir1}} & I1_R2R |//      LD C,E       ; 4B
611
    {I1DCNT {LDsC_H       == ir1}} & I1_R2R |//      LD C,H       ; 4C
612
    {I1DCNT {LDsC_L       == ir1}} & I1_R2R |//      LD C,L       ; 4D
613
    {I1DCNT {LDsD_A       == ir1}} & I1_R2R |//      LD D,A       ; 57
614
    {I1DCNT {LDsD_B       == ir1}} & I1_R2R |//      LD D,B       ; 50
615
    {I1DCNT {LDsD_C       == ir1}} & I1_R2R |//      LD D,C       ; 51
616
    {I1DCNT {LDsD_D       == ir1}} & I1_R2R |//      LD D,D       ; 52
617
    {I1DCNT {LDsD_E       == ir1}} & I1_R2R |//      LD D,E       ; 53
618
    {I1DCNT {LDsD_H       == ir1}} & I1_R2R |//      LD D,H       ; 54
619
    {I1DCNT {LDsD_L       == ir1}} & I1_R2R |//      LD D,L       ; 55
620
    {I1DCNT {LDsE_A       == ir1}} & I1_R2R |//      LD E,A       ; 5F
621
    {I1DCNT {LDsE_B       == ir1}} & I1_R2R |//      LD E,B       ; 58
622
    {I1DCNT {LDsE_C       == ir1}} & I1_R2R |//      LD E,C       ; 59
623
    {I1DCNT {LDsE_D       == ir1}} & I1_R2R |//      LD E,D       ; 5A
624
    {I1DCNT {LDsE_E       == ir1}} & I1_R2R |//      LD E,E       ; 5B
625
    {I1DCNT {LDsE_H       == ir1}} & I1_R2R |//      LD E,H       ; 5C
626
    {I1DCNT {LDsE_L       == ir1}} & I1_R2R |//      LD E,L       ; 5D
627
    {I1DCNT {LDsH_A       == ir1}} & I1_R2R |//      LD H,A       ; 67
628
    {I1DCNT {LDsH_B       == ir1}} & I1_R2R |//      LD H,B       ; 60
629
    {I1DCNT {LDsH_C       == ir1}} & I1_R2R |//      LD H,C       ; 61
630
    {I1DCNT {LDsH_D       == ir1}} & I1_R2R |//      LD H,D       ; 62
631
    {I1DCNT {LDsH_E       == ir1}} & I1_R2R |//      LD H,E       ; 63
632
    {I1DCNT {LDsH_H       == ir1}} & I1_R2R |//      LD H,H       ; 64
633
    {I1DCNT {LDsH_L       == ir1}} & I1_R2R |//      LD H,L       ; 65
634
    {I1DCNT {LDsL_A       == ir1}} & I1_R2R |//      LD L,A       ; 6F
635
    {I1DCNT {LDsL_B       == ir1}} & I1_R2R |//      LD L,B       ; 68
636
    {I1DCNT {LDsL_C       == ir1}} & I1_R2R |//      LD L,C       ; 69
637
    {I1DCNT {LDsL_D       == ir1}} & I1_R2R |//      LD L,D       ; 6A
638
    {I1DCNT {LDsL_E       == ir1}} & I1_R2R |//      LD L,E       ; 6B
639
    {I1DCNT {LDsL_H       == ir1}} & I1_R2R |//      LD L,H       ; 6C
640
    {I1DCNT {LDsL_L       == ir1}} & I1_R2R |//      LD L,L       ; 6D
641
    {I1DCNT {LDsSP_HL     == ir1}} & I1_R2R |//      LD SP,HL     ; F9
642
    {I1DCNT {NOP          == ir1}} & I1_R2R |//      NOP         ; 00
643
    {I1DCNT {ORsA         == ir1}} & I1_R2R |//      OR A         ; B7
644
    {I1DCNT {ORsB         == ir1}} & I1_R2R |//      OR B         ; B0
645
    {I1DCNT {ORsC         == ir1}} & I1_R2R |//      OR C         ; B1
646
    {I1DCNT {ORsD         == ir1}} & I1_R2R |//      OR D         ; B2
647
    {I1DCNT {ORsE         == ir1}} & I1_R2R |//      OR E         ; B3
648
    {I1DCNT {ORsH         == ir1}} & I1_R2R |//      OR H         ; B4
649
    {I1DCNT {ORsL         == ir1}} & I1_R2R |//      OR L         ; B5
650
    {I1DCNT {RLA          == ir1}} & I1_R2R |//      RLA          ; 17
651
    {I1DCNT {RLCA         == ir1}} & I1_R2R |//      RLCA        ; 07
652
    {I1DCNT {RRA          == ir1}} & I1_R2R |//      RRA          ; 1F
653
    {I1DCNT {RRCA         == ir1}} & I1_R2R |//      RRCA        ; 0F
654
    {I1DCNT {SBCsA        == ir1}} & I1_R2R |//      SBC A        ; 9F
655
    {I1DCNT {SBCsB        == ir1}} & I1_R2R |//      SBC B        ; 98
656
    {I1DCNT {SBCsC        == ir1}} & I1_R2R |//      SBC C        ; 99
657
    {I1DCNT {SBCsD        == ir1}} & I1_R2R |//      SBC D        ; 9A
658
    {I1DCNT {SBCsE        == ir1}} & I1_R2R |//      SBC E        ; 9B
659
    {I1DCNT {SBCsH        == ir1}} & I1_R2R |//      SBC H        ; 9C
660
    {I1DCNT {SBCsL        == ir1}} & I1_R2R |//      SBC L        ; 9D
661
    {I1DCNT {SCF          == ir1}} & I1_R2R |//      SCF          ; 37
662
    {I1DCNT {SUBsA        == ir1}} & I1_R2R |//      SUB A        ; 97
663
    {I1DCNT {SUBsB        == ir1}} & I1_R2R |//      SUB B        ; 90
664
    {I1DCNT {SUBsC        == ir1}} & I1_R2R |//      SUB C        ; 91
665
    {I1DCNT {SUBsD        == ir1}} & I1_R2R |//      SUB D        ; 92
666
    {I1DCNT {SUBsE        == ir1}} & I1_R2R |//      SUB E        ; 93
667
    {I1DCNT {SUBsH        == ir1}} & I1_R2R |//      SUB H        ; 94
668
    {I1DCNT {SUBsL        == ir1}} & I1_R2R |//      SUB L        ; 95
669
    {I1DCNT {XORsA        == ir1}} & I1_R2R |//      XOR A        ; AF
670
    {I1DCNT {XORsB        == ir1}} & I1_R2R |//      XOR B        ; A8
671
    {I1DCNT {XORsC        == ir1}} & I1_R2R |//      XOR C        ; A9
672
    {I1DCNT {XORsD        == ir1}} & I1_R2R |//      XOR D        ; AA
673
    {I1DCNT {XORsE        == ir1}} & I1_R2R |//      XOR E        ; AB
674
    {I1DCNT {XORsH        == ir1}} & I1_R2R |//      XOR H        ; AC
675
    {I1DCNT {XORsL        == ir1}} & I1_R2R |//      XOR L        ; AD
676
    {I1DCNT {RET          == ir1}} & I1_RET |//      RET          ; C9
677
    {I1DCNT {RETsC == ir1 & cf  }} & I1_RET |//      RET C        ; D8
678
    {I1DCNT {RETsM == ir1 & sf  }} & I1_RET |//      RET M        ; F8
679
    {I1DCNT {RETsNC== ir1 & ~cf }} & I1_RET |//      RET NC       ; D0
680
    {I1DCNT {RETsP == ir1 & ~sf }} & I1_RET |//      RET P        ; F0
681
    {I1DCNT {RETsPE== ir1 & pvf }} & I1_RET |//      RET PE       ; E8
682
    {I1DCNT {RETsPO== ir1 & ~pvf}} & I1_RET |//      RET PO       ; E0
683
    {I1DCNT {RETsNZ== ir1 & ~zf }} & I1_RET |//      RET NZ       ; C0
684
    {I1DCNT {RETsZ == ir1 & zf  }} & I1_RET |//      RET Z        ; C8
685
    {I1DCNT {EXs6SP7_HL   == ir1}} & I1_RMW |//      EX (SP),HL   ; E3
686
    {I1DCNT {DECs6HL7     == ir1}} & I1_RMW |//      DEC (HL)     ; 35
687
    {I1DCNT {INCs6HL7     == ir1}} & I1_RMW |//      INC (HL)     ; 34
688
    {I1DCNT {RSTs0        == ir1}} & I1_RST |//      RST 0        ; C7
689
    {I1DCNT {RSTs10H      == ir1}} & I1_RST |//      RST 10H      ; D7
690
    {I1DCNT {RSTs18H      == ir1}} & I1_RST |//      RST 18H      ; DF
691
    {I1DCNT {RSTs20H      == ir1}} & I1_RST |//      RST 20H      ; E7
692
    {I1DCNT {RSTs28H      == ir1}} & I1_RST |//      RST 28H      ; EF       
693
    {I1DCNT {RSTs30H      == ir1}} & I1_RST |//      RST 30H      ; F7
694
    {I1DCNT {RSTs38H      == ir1}} & I1_RST |//      RST 38H      ; FF
695
    {I1DCNT {RSTs8H       == ir1}} & I1_RST ;//      RST 8H       ; CF 
696
 
697
//--------  CB decodes -----------------------
698
 
699
//  First cut below
700
//           CB_RLC   = 7'b01_00_000,  // these must be compaired with ir[9:3]
701
//           CB_RRC   = 7'b01_00_001,  // these must be compaired with ir[9:3]
702
//           CB_RL    = 7'b01_00_010,  // these must be compaired with ir[9:3]
703
//           CB_RR    = 7'b01_00_011,  // these must be compaired with ir[9:3]
704
//           CB_SLA   = 7'b01_00_100,  // these must be compaired with ir[9:3]
705
//           CB_SRA   = 7'b01_00_101,  // these must be compaired with ir[9:3]
706
//           CB_SLL   = 7'b01_00_110,  // these must be compaired with ir[9:3]
707
//           CB_SRL   = 7'b01_00_111,  // these must be compaired with ir[9:3]
708
 
709
//           CB_BIT   = 4'b01_01,    // these must be compaired with ir[9:6]
710
//           CB_RES   = 4'b01_10,    // these must be compaired with ir[9:6]
711
//           CB_SET   = 4'b01_11,    // these must be compaired with ir[9:6]
712
 
713
// note these are all read-modify-writ except CB_BIT
714
assign cb_mem =  (CB_MEM  == ir1[2:0]);   // this must be compaired with ir[2:0] 
715
 
716
//  The ED Group
717
// These are the "unique instructions in the 46, 47 rows that NEED? to be implemented
718
// Not sure I want to worry about all undocumented stuff in these rows - hard to believe
719
// It will matter.(IM modes are very system dependent  - hard to believe even a programmer
720
// would use undocumented instructions to muck with this stuff)
721
// reg 2 reg simply executed by ir2 logic
722
//           ED_IMs0      =  10'h246//      IM 0       ; ED 46   set IM0
723
//           ED_LDsI_A    =  10'h247//      LD I,A     ; ED 47   move a to I
724
//           ED_IMs1      =  10'h256//      IM 1       ; ED 56   set IM1
725
//           ED_LDsA_I    =  10'h257//      LD A,I     ; ED 57   move I to A
726
//           ED_IMs2      =  10'h25E//      IM 2       ; ED 5E   set IM2
727
//           ED_RRD       =  10'h267//      RRD        ; ED 67   nibble roates A HL
728
//           ED_RLD       =  10'h26F//      RLD        ; ED 6F   nibble roates A HL
729
 
730
//  set (or clear) repeat flag at  DEC_EB.
731
//  set (or clear) inc flag at     DEC_EB.
732
//  seperate flows for LD, CP, IN, OUT.
733
//           ED_LDI       == ir1//      LDI        ; ED A0    These are block move 
734
//           ED_CPI       == ir1//      CPI        ; ED A1    type insts that don't repeat
735
//           ED_INI       == ir1//      INI        ; ED A2
736
//           ED_OUTI      == ir1//      OUTI       ; ED A3
737
//           ED_LDD       == ir1//      LDD        ; ED A8
738
//           ED_CPD       == ir1//      CPD        ; ED A9
739
//           ED_IND       == ir1//      IND        ; ED AA
740
//           ED_OUTD      == ir1//      OUTD       ; ED AB
741
wire dec_blk_rpt =
742
           ED_LDIR      == ir1 |//      LDIR       ; ED B0    These are block move 
743
           ED_CPIR      == ir1 |//      CPIR       ; ED B1    type insts that DO repeat
744
           ED_INIR      == ir1 |//      INIR       ; ED B2
745
           ED_OTIR      == ir1 |//      OTIR       ; ED B3
746
           ED_LDDR      == ir1 |//      LDDR       ; ED B8
747
           ED_CPDR      == ir1 |//      CPDR       ; ED B9
748
           ED_INDR      == ir1 |//      INDR       ; ED BA
749
           ED_OTDR      == ir1 ;//      OTDR       ; ED BB
750
wire ed_blk_mv =  ED_LDIR      == ir1 |  ED_LDI       == ir1 |
751
                  ED_LDDR      == ir1 |  ED_LDD       == ir1 ;
752
wire ed_blk_cp =  ED_CPIR      == ir1 |  ED_CPI       == ir1 |
753
                  ED_CPDR      == ir1 |  ED_CPD       == ir1 ;
754
wire ed_blk_in =  ED_INIR      == ir1 |  ED_INI      == ir1 |
755
                  ED_INDR      == ir1 |  ED_IND      == ir1 ;
756
 
757
wire ed_blk_out = ED_OTIR      == ir1 |  ED_OUTI      == ir1 |
758
                  ED_OTDR      == ir1 |  ED_OUTD      == ir1 ;
759
 
760
wire dec_blk_io = ed_blk_in | ed_blk_in;
761
 
762
wire blk_done =  ~blk_rpt_flg |  beq0 & ceq0 | blk_io_flg & ceq0;
763
 
764
assign dec_blk_inc =  ED_LDIR      == ir1 |
765
                      ED_CPIR      == ir1 |
766
                      ED_INIR      == ir1 |
767
                      ED_OTIR      == ir1 |
768
                      ED_LDI       == ir1 |
769
                      ED_CPI       == ir1 |
770
                      ED_INI       == ir1 |
771
                      ED_OUTI      == ir1 ;
772
 
773
 
774
//The ED70 instruction reads from I/O port C, 
775
//but does not store the result.
776
//It just affects the flags.  Hard to test.    like the other IN x,(C) instruction. 
777
//
778
//ED71 simply outs the value 0 to I/O port C.
779
//  This suggests that we should decode as follows:
780
//  I hope if I don't get all the IM duplicates right it won't be a tragedy
781
//        ED_INsREG_6C7  =    7'b1001___000,// compair with {ir[7:6],ir[2:0]}
782
//        
783
//        ED_SBCsHL_REG  =    8'b1001__0010, // compair with {ir[9:6],ir[3:0]}
784
//        ED_ADCsHL_REG  =    8'b1001__1010, // compair with {ir[9:6],ir[3:0]}
785
//        ED_LDs6NN7_REG =    8'b1001__0011, // compair with {ir[9:6],ir[3:0]}  REG = BC,DE,HL,SP                   
786
//        ED_LDsREG_6NN7 =    8'b1001__1011, // compair with {ir[9:6],ir[3:0]}  REG = BC,DE,HL,SP
787
//        ED_NEG         =    7'b1001___100, // compair with {ir[9:6],ir[2:0]}  all A<= -A                  
788
//        ED_RETN        =    7'b1001___101, // compair with {ir[9:6],ir[2:0]} and !reti
789
wire ed_nn = ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} |
790
             ED_LDsREG_6NN7 == {ir1[9:6],ir1[3:0]}  ;
791
 
792
//  we use all these to enable interrupts
793
wire ed_retn = ED_RETN == {ir1[9:6],ir1[2:0]};
794
 
795
assign ed_dbl_rd =  ED_LDsREG_6NN7 == {ir1[9:6],ir1[3:0]};
796
 
797
 
798
// assign   cb_mem = CB_MEM = ir1[2:0];                 // CB_MEM  = 3'h110,    
799
 
800
 
801
 
802
 
803
wire jmpr_true =
804
    JRs$t2       == ir1           |
805
    JRsC_$t2     == ir1  & fr[0]  |
806
    JRsNC_$t2    == ir1  & ~fr[0] |
807
    JRsZ_$t2     == ir1  & fr[6]  |
808
    JRsNZ_$t2    == ir1  & ~fr[6] ;
809
 
810
//assign { sf, zf. f5f, hf, f3f, pvf, nf, cf} = fr;              
811
wire callnn_true   =  CALLsC_NN    == ir1  & cf  |
812
                      CALLsNC_NN   == ir1  & ~cf |
813
                      CALLsNN      == ir1        |
814
                      CALLsNZ_NN   == ir1  & ~zf |
815
                      CALLsPE_NN   == ir1  & pvf |
816
                      CALLsPO_NN   == ir1  & ~pvf|
817
                      CALLsP_NN    == ir1  & ~sf |
818
                      CALLsZ_NN    == ir1  &  zf |
819
                      CALLsM_NN    == ir1  &  sf  ;
820
 
821
wire  jmpnn_true  =  JPsC         == ir1  & cf  |
822
                     JPsNC        == ir1  & ~cf |
823
                     JP           == ir1        |
824
                     JPsNZ        == ir1  & ~zf |
825
                     JPsPE        == ir1  & pvf |
826
                     JPsPO        == ir1  & ~pvf|
827
                     JPsP         == ir1  & ~sf |
828
                     JPsZ         == ir1  &  zf |
829
                     JPsM         == ir1  &  sf  ;
830
 
831
// PUSHsAF      == ir1
832
// PUSHsBC      == ir1
833
// PUSHsDE      == ir1
834
// PUSHsHL      == ir1
835
 
836
wire os_a  =  LDs6BC7_A    == ir1 |  //      LD (BC),A    ; 02
837
              LDs6DE7_A    == ir1 |  //      LD (DE),A    ; 12
838
              LDs6HL7_A    == ir1 |  //      LD (HL),A    ; 77
839
              LDs6NN7_A    == ir1 |  //      LD (NN),A    ; 32 XX XX
840
              PUSHsAF      == ir1 |
841
              OUTs6N7_A    == ir1 |
842
              ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0] && REG8_A == ir1[5:3]} ;
843
 
844
wire os_b = LDs6HL7_B      == ir1                                       |  // LD (HL),B    ; 70
845
            ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_BC == ir1[5:4] |
846
            ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0]} & REG8_B == ir1[5:3] ;
847
 
848
wire os_c = LDs6HL7_C    == ir1                                         |  //      LD (HL),C    ; 71
849
            PUSHsBC        == ir1                                       |  // PUSH BC
850
            ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0]} & REG8_C == ir1[5:3] ;
851
 
852
wire os_d = LDs6HL7_D    == ir1                                         |  //      LD (HL),D    ; 72
853
            ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_DE == ir1[5:4] |
854
            ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0]} & REG8_D == ir1[5:3] ;
855
 
856
 
857
wire os_e = LDs6HL7_E    == ir1                                     |  //      LD (HL),E    ; 73
858
            PUSHsDE      == ir1                                         |  //      PUSH DE
859
            ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0]} & REG8_E == ir1[5:3] ;
860
 
861
wire os_h = LDs6HL7_H    == ir1                                         |  //      LD (HL),H    ; 74
862
            LDs6NN7_HL   == ir1                                         |  //      LD (NN),HL   ; 22 XX XX
863
            ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_HL == ir1[5:4] |
864
            ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0]} & REG8_H == ir1[5:3] ;
865
 
866
wire os_l = LDs6HL7_L    == ir1                                     |  //      LD (HL),L    ; 75
867
            PUSHsHL      == ir1                                     |
868
            ED_OUTs6C7_REG ==  {ir1[9:6],ir1[2:0]} & REG8_L == ir1[5:3] ;
869
 
870
wire os_sp = ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_SP == ir1[5:4];
871
 
872
wire os_f  =  PUSHsAF     == ir1 ;
873
 
874
 
875
//---------------- inst hazard ----------------------------------------------------------
876
//
877
// On some reflection, I don't think I'm going to worry about this immediately - it 
878
// should be easy to kludge in a fix if necessary  -- and there are more important things
879
// todo.  It is a very bad programming practice to muck with the instruction stream in any
880
// case --  I have to believe most target applications do not do this -- although I'll probably
881
// get hit pretty early with a instruction test that does.   Oh well  -- if that happens we fix
882
// it.   
883
// Well --  think some here --  the hazard is because of a change in design. 
884
//  If used to any extent..  Somebody WILL
885
//  want this to act the same way as the origional - even if the programming is "poor".
886
//  >>>>>>>> bite the bullet and do it.
887
//
888
// if we do an operand store and the address == pc-1 its an inst hazard, We need to execute the 
889
// store decrement pc and re-fetch.  This is a high priority interrupt. 
890
// what about multi-byte stores  - like LDs6NN7_A  or LDs6NN7_HL - i guess we  do an IF - to start
891
// the pipe before the os -- same logic.   
892
// 
893
 
894
 
895
//-----------------data hazard ----------------------------------------------------------
896
//
897
// Issues here have evolved to a degree as the design progressed.  However the 
898
// Key has always been that for each instruction (no matter how complex) there 
899
// is only a single state in which the previous instruction can also be active
900
// and that is the DEC_EXEC state.  If there is a data hazard, we need to delay
901
// execution of that state until the ir2 execution completes (which it always does
902
// in a single tick).  Note that only the RET instructions test the flag register
903
// on DEC_EXEC.
904
//
905
// WARNING:  be very careful about this.  Data hazard logic is very difficult to 
906
// verify as there are so many instruction pairs to test.
907
//
908
//  Situations  1) operand stores from ir1 when register is updated in ir2
909
//              2) flag tests when fr is being updated
910
//              3) sp issues  see below  LDsSP_HL  DECsSP  INCsSP
911
//     ANY OTHERS ???
912
// 
913
// upd_ar, upd_br, upd_cr, upd_dr, upd_er, upd_hr, upd_lr,upd_fr,
914
wire  use_hl_exec =  LDsSP_HL == ir1;
915
wire  use_sp_exec =  MEM_OFSP == next_mem_state |
916
                     MEM_OSSP == next_mem_state  ;
917
wire  upd_sp_exec  = DECsSP == ir2 |
918
                     INCsSP == ir2   ;
919
 
920
 
921
 
922
wire use_fr_exec = ( RETsC        == ir1  |
923
                     RETsM        == ir1  |
924
                     RETsNC       == ir1  |
925
                     RETsP        == ir1  |
926
                     RETsPE       == ir1  |
927
                     RETsPO       == ir1  |
928
                     RETsNZ       == ir1  |
929
                     RETsZ        == ir1   ) ;
930
 
931
assign hazard =  (dec_state == DEC_EXEC  & exec_ir2 ) & ( upd_fr & use_fr_exec  |
932
                                                          upd_ar & os_a         |
933
                                                          upd_br & os_b         |
934
                                                          upd_cr & os_c         |
935
                                                          upd_dr & os_d         |
936
                                                          upd_er & os_e         |
937
                                                          upd_hr & os_h         |
938
                                                          upd_lr & os_l         |
939
                                                          upd_hr & use_hl_exec  |
940
                                                          upd_lr & use_hl_exec  |
941
                                                          upd_sp_exec & use_sp_exec );
942
 
943
 
944
 
945
 
946
 
947
 
948
// does not include extension stuff as we are mostly looking for hazards here
949
// course we do use these terms to build more decodes
950
//
951
wire  opadr_bc  =  LDsA_6BC7  == ir1 | LDs6BC7_A == ir1;
952
wire  opadr_de  =  LDsA_6DE7  == ir1 | LDs6DE7_A == ir1;
953
wire  opadr_hl  =  LDsB_6HL7  == ir1 | ORs6HL7    == ir1 | LDs6HL7_B == ir1 |
954
                   LDsD_6HL7  == ir1 | LDsC_6HL7  == ir1 | LDs6HL7_C == ir1 |
955
                   LDsH_6HL7  == ir1 | LDsE_6HL7  == ir1 | LDs6HL7_D == ir1 |
956
                   ADDsA_6HL7 == ir1 | LDsL_6HL7  == ir1 | LDs6HL7_E == ir1 |
957
                   SUBs6HL7   == ir1 | LDsA_6HL7  == ir1 | LDs6HL7_H == ir1 |
958
                   ANDs6HL7   == ir1 | ADCsA_6HL7 == ir1 | LDs6HL7_L == ir1 |
959
                   XORs6HL7   == ir1 | SBCs6HL7   == ir1 | CPs6HL7   == ir1 ;
960
 
961
assign  use_a = os_a;
962
assign  use_b = os_b  | opadr_bc;
963
assign  use_c = os_c  | opadr_bc;
964
assign  use_d = os_d  | opadr_de;
965
assign  use_e = os_e  | opadr_de;
966
assign  use_h = os_h  | opadr_hl;
967
assign  use_l = os_l  | opadr_hl;
968
 
969
 
970
 
971
assign   use_flags = c_jmp8 | c_jmp4 | c_call | c_ret;
972
 
973
 
974
 
975
wire bc_eq0 = beq0 & ceq0;
976
//  ???  not used ?  why defined ?
977
//assign rpt_blk_mv = (blk_mv_reg )  & !bc_eq0     |
978
//                    (blk_cmp_reg) & !bc_eq0 & (nn[7:0] != 8'h0)  |
979
//                    (blk_in_reg | blk_out_reg) & !b_eq0 ;
980
 
981
 
982
 
983
 
984
 
985
 
986
 
987
//  BASIC ARCHITECTURE OF THIS FILE   pc  and sp not shown, but are inputs to src mux.
988
//                    _____           and may be updated from adder output.
989
//                   |     |
990
//                   |     |          pc-1 register is required to implement relative jumps.
991
//                   |     |                     
992
//      _____        |lit  |      |\             
993
//     |     |       |     |      |  \           
994
//     |     |       |src2 |      |    \          _____          _____ 
995
//     |     |       |     |----->|     |        |     |        |     |
996
//     |src  |       |_____|      |adder|------->|     |        |     |
997
//     |mux  |                    |     |        |     |        |     |
998
//     |     |------------------->|    /         |2/1  |------->|wb   |
999
//     |     |              |     |  /           |mux  |        |adr  |
1000
//     |_____|              |     |/             |     |        |     |
1001
//                           ------------------->|     |        |     |
1002
//                                               |_____|        |_____|
1003
//  MEM_NOP  
1004
//  MEM_IFPP1   MEM_OFIXpD     MEM_CALL    MEM_IFRST     MEM_OFHL_PM    MEM_IOF_C  
1005
//  MEM_OS1,    MEM_OSIXpD     MEM_OSNN,   MEM_IFREL_N   MEM_OSHL_PM    MEM_IOS_C  
1006
//  MEM_OF1,    MEM_OSADR      MEM_OFNN    MEM_JMPHL     MEM_OSDE_PM    MEM_IOF_N  
1007
//  MEM_OFSP    MEM_OSSP_PCM2  MEM_OFADRP1 MEM_IFNN      MEM_INTA       MEM_IOS_N  
1008
//  MEM_OSSP    MEM_OSSP_P     MEM_OSADRP1 MEM_IFINT     MEM_OS_HL_N
1009
//                                                       
1010
 
1011
wire src_sp = next_mem_state == MEM_OF1  & EXs6SP7_HL == ir1 | //special case rmw 
1012
              next_mem_state == MEM_OFSP                     |
1013
              next_mem_state == MEM_OSSP                     |
1014
              next_mem_state == MEM_CALL                       ;
1015
wire src_pc =  next_mem_state ==   MEM_IFPP1   |
1016
               next_mem_state ==  MEM_IFREL_N  ;
1017
 
1018
wire src_nn =  next_mem_state ==   MEM_IFNN |
1019
               next_mem_state ==   MEM_OSNN |
1020
               next_mem_state ==   MEM_OFNN  ;
1021
 
1022
 
1023
wire src_de  = dec_state == DEC_EXEC & LDsA_6DE7 == ir1  |      // MEM_OS1  MEM_OF1
1024
               dec_state == DEC_EXEC & LDs6DE7_A == ir1  |     // are both true at this time
1025
               next_mem_state == MEM_OSDE_PM               ;
1026
wire src_bc =  dec_state == DEC_EXEC & LDsA_6BC7 == ir1  |
1027
               dec_state == DEC_EXEC & LDs6BC7_A == ir1  |
1028
               next_mem_state ==MEM_IOF_C                |
1029
               next_mem_state ==MEM_IOS_C                 ;
1030
 
1031
 
1032
//  don't forget that hl source can be modified by prefix
1033
//  this gets messy as we use wb_adr for some of these.
1034
//
1035
wire src_hl =   next_mem_state == MEM_OF1  &
1036
                                  (dec_state == DEC_EXEC)  &
1037
                                   !src_de & !src_bc & !src_sp  |
1038
                next_mem_state == MEM_OS1  &
1039
                                  (dec_state == DEC_EXEC)  &
1040
                                   !src_de & !src_bc         |
1041
                next_mem_state == MEM_OFHL_PM                |
1042
                next_mem_state == MEM_OSHL_PM                |
1043
                next_mem_state == MEM_OS_HL_N                |
1044
                next_mem_state == MEM_JMPHL                   ;
1045
 
1046
wire src_ix =  next_mem_state == MEM_OFIXpD  &  ir1dd |
1047
               next_mem_state == MEM_OSIXpD  &  ir1dd  ;
1048
 
1049
wire src_iy =  next_mem_state == MEM_OFIXpD  &  ir1fd |
1050
               next_mem_state == MEM_OSIXpD  &  ir1fd  ;
1051
 
1052
wire src_adr = next_mem_state == MEM_OFADRP1  |
1053
               next_mem_state == MEM_OSADRP1  |
1054
               next_mem_state == MEM_NOP      |
1055
               next_mem_state == MEM_OSADR     ;
1056
 
1057
wire src_int = next_mem_state == MEM_IOF_N  |
1058
               next_mem_state == MEM_IOS_N   ;
1059
 
1060
 
1061
 
1062
wire   src_mux =   {16{ src_sp  }} & sp                 |
1063
                   {16{ src_pc  }} & pc                 |
1064
                   {16{ src_nn  }} & nn                 |
1065
                   {16{ src_hl  }} & hl                 |
1066
                   {16{ src_de  }} & de                 |
1067
                   {16{ src_bc  }} & bc                 |
1068
                   {16{ src_ix  }} & ixr                |
1069
                   {16{ src_iy  }} & iyr                |
1070
                   {16{ src_adr }} & wb_adr             |
1071
                   {16{ src_int }} & { intr, nn[15:8] } |
1072
                   {16{next_mem_state == MEM_IFRST}} & {10'h0, ir1[6:4], 3'h0} ;
1073
 
1074
wire block_mv_inc = (dec_state == DEC_ED) ? dec_blk_inc : blk_inc_flg; // flag set at DEC_ED
1075
 
1076
 
1077
 
1078
wire inc_s2 =     next_mem_state ==MEM_OFADRP1                |
1079
                  next_mem_state ==MEM_OSADRP1                |
1080
                  next_mem_state ==MEM_OFHL_PM & block_mv_inc |
1081
                  next_mem_state ==MEM_OSHL_PM & block_mv_inc |
1082
                  next_mem_state ==MEM_OSDE_PM & block_mv_inc |
1083
                  next_mem_state ==MEM_OFSP                   |
1084
                  next_mem_state ==MEM_IFPP1                  |
1085
                  next_mem_state ==MEM_OSSP_PCM2              |
1086
                  next_mem_state ==MEM_OSSP_P                  ;
1087
 
1088
wire dec_s2 =     next_mem_state ==MEM_OFHL_PM & ~block_mv_inc |
1089
                  next_mem_state ==MEM_OSHL_PM & ~block_mv_inc |
1090
                  next_mem_state ==MEM_OSDE_PM & ~block_mv_inc |
1091
                  next_mem_state == MEM_OFSP                    ;
1092
 
1093
 
1094
wire reln_s2 =    next_mem_state ==  MEM_IFREL_N   |
1095
                  next_mem_state ==  MEM_OFIXpD    |
1096
                   next_mem_state ==  MEM_OSIXpD    ;
1097
 
1098
wire   src2    = {16{ inc }}  & 16'h0001           |
1099
                 {16{ dec }}  & 16'hffff           |
1100
                 {16{ rel }}  & {{8{nn[15]}},nn[15:8]}|
1101
                 {16{~(rel_jmp|inc|dec)}} & 16'h0   ;
1102
 
1103
wire   adr_alu     = src2 + src_mux;
1104
 
1105
 
1106
wire  pre_inc_dec =    next_mem_state ==  MEM_CALL    |
1107
                       next_mem_state ==  MEM_OSSP_P  |
1108
                       next_mem_state ==  MEM_OSSP     ;
1109
 
1110
 
1111
wire   mux21 =  pre_inc_dec ? alu : src_mux;
1112
 
1113
assign wb_rdy_nhz = (!wb_cyc | wb_ack ) & ~hazard;   //  wishbone ready with no hazard
1114
wire   wb_rdy     = !wb_cyc | wb_ack;
1115
 
1116
assign we_next = next_mem_state == MEM_OS1        |
1117
                 next_mem_state == MEM_OSP        |
1118
                 next_mem_state == MEM_OSIXpD     |
1119
                 next_mem_state == MEM_OSADR      |
1120
                 next_mem_state == MEM_OSSP_PCM2  |
1121
                 next_mem_state == MEM_OSSP_P     |
1122
                 next_mem_state == MEM_CALL       |
1123
                 next_mem_state == MEM_OSNN       |
1124
                 next_mem_state == MEM_OSADRP1    |
1125
                 next_mem_state == MEM_OSHL_PM    |
1126
                 next_mem_state == MEM_OSDE_PM    |
1127
                 next_mem_state == MEM_OS_HL_N    |
1128
                 next_mem_state == MEM_IOS_C      |
1129
                 next_mem_state == MEM_IOS_N       ;
1130
 
1131
 
1132
//-------1---------2---------3--------State Machines-------6---------7---------8---------9--------0
1133
// we do this just to save virtual paper below.
1134
//              6              5              4                15
1135
assign {next_dec_state, next_mem_state, next_pipe_state} = next_state;
1136
 
1137
always @(ir1 or wb_int or inst_haz or wb_int or dec_state or mem_exec_dec or cb_mem or ed_nn or
1138
         ed_blk_cp  or ed_blk_in or ed_blk_out or ed_retn or ed_blk_mv or ed_dbl_rd or blk_done or
1139
         fr or jmpr_true or callnn_true or jmpnn_true )
1140
 
1141
begin
1142
    case (dec_state)
1143
        DEC_IDLE:       next_state = {DEC_IF1, MEM_NOP, IPIPE_NOP};
1144
 
1145
        DEC_HALT:
1146
            if (wb_int)      next_state = {DEC_INT1,MEM_NOP   ,IPIPE_NOP};// stay here until interrupt or reset
1147
            else             next_state = {DEC_HALT,MEM_NOP   ,IPIPE_NOP};
1148
        DEC_IF1 :            next_state = {DEC_IF2 ,MEM_IFPP1 ,IPIPE_NOP};
1149
        DEC_IF2 :            next_state = {DEC_EXEC,MEM_IFPP1 ,IPIPE_EN1};
1150
        DEC_IF2A:            next_state = {DEC_EXEC,MEM_IFPP1 ,IPIPE_NOP};
1151
        DEC_EXEC:
1152
            if      (inst_haz)    next_state = {DEC_IF1, MEM_DECPC , IPIPE_NOP};
1153
            else if (wb_int)      next_state = {DEC_INT1,MEM_NOP   ,IPIPE_NOP};
1154
            else
1155
                case (mem_exec_dec) // full case but can all tools understand ? just make a default
1156
                I1_CB   : next_state = {DEC_CB,   MEM_IFPP1, IPIPE_EN1};// IF2_NOP -> nn <= (MEM)
1157
                I1_DDFD : next_state = {DEC_DDFD, MEM_IFPP1, IPIPE_EN1};// gets real inst     
1158
                I1_ED   : next_state = {DEC_ED,   MEM_IFPP1, IPIPE_EN1};
1159
                I1_JMP  : next_state = {DEC_IF2,  MEM_JMPHL, IPIPE_NOP};
1160
                I1_N    : next_state = {DEC_N,    MEM_IFPP1, IPIPE_ENN};
1161
                I1_NN   : next_state = {DEC_NN,   MEM_IFPP1, IPIPE_ENN};
1162
                I1_OF   : next_state = {DEC_OF,   MEM_OF1,   IPIPE_EN12};//transfer, don't activate
1163
                I1_OS   : next_state = {DEC_IF2,  MEM_OS1,   IPIPE_EN1}; // -> ir2_NOP
1164
                I1_POP  : next_state = {DEC_POP,  MEM_OFSP,  IPIPE_EN12};
1165
                I1_PUSH : next_state = {DEC_PUSH, MEM_OSSP,  IPIPE_EN12};
1166
                I1_RET  : next_state = {DEC_RET,  MEM_OFSP,  IPIPE_EN12};
1167
                I1_RMW  : next_state = {DEC_RMW,  MEM_OF1,   IPIPE_EN12};//can't activate till data rdy
1168
                I1_RST  : next_state = {DEC_IF2,  MEM_IFRST, IPIPE_ENN};
1169
                I1_R2R  : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2};
1170
                default : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2}; //I1_R2R  
1171
                endcase
1172
        DEC_CB: if (cb_mem) next_state = {DEC_CBM, MEM_OF1, IPIPE_EN12};
1173
                else        next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2};
1174
        DEC_DDFD:   // except for CB and EB these all act the same H and L get modified by prefix
1175
            case (mem_exec_dec)
1176
            I1_CB   : next_state = {DEC_PFxCB,MEM_IFPP1, IPIPE_EN1};// IF2_NOP -> nn <= (MEM)
1177
            I1_DDFD : next_state = {DEC_DDFD, MEM_IFPP1, IPIPE_EN1};
1178
            I1_ED   : next_state = {DEC_ED,   MEM_IFPP1, IPIPE_EN1};//How do we clear the prefix?
1179
            I1_JMP  : next_state = {DEC_IF2,  MEM_JMPHL, IPIPE_NOP};
1180
            I1_N    : next_state = {DEC_N,    MEM_IFPP1, IPIPE_ENN};
1181
            I1_NN   : next_state = {DEC_NN,   MEM_IFPP1, IPIPE_ENN};
1182
            I1_OF   : next_state = {DEC_DDOF, MEM_IFPP1, IPIPE_ENN};  // d to nn - need to get d
1183
                                                                      // LD A,(BC) LD A,(DE) will
1184
                                                                      // become ix+d - do we care ?
1185
                                                                      // i hope not
1186
            I1_OS   : next_state = {DEC_DDOS, MEM_IFPP1, IPIPE_ENN};  // d to nn
1187
            I1_POP  : next_state = {DEC_POP,  MEM_OFSP,  IPIPE_EN12};
1188
            I1_PUSH : next_state = {DEC_PUSH, MEM_OSSP,  IPIPE_EN12};
1189
            I1_RET  : next_state = {DEC_RET,  MEM_OFSP,  IPIPE_EN12};
1190
            I1_RMW  : next_state = {DEC_RMW,  MEM_OF1,  IPIPE_EN12};
1191
            I1_RST  : next_state = {DEC_IF2,  MEM_IFRST, IPIPE_NOP};  // just dump next inst
1192
            I1_R2R  : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2}; //I1_R2R
1193
            default : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2}; //I1_R2R  
1194
            endcase
1195
        DEC_ED:
1196
            if (ed_nn)            next_state = {DEC_EDNN1,  MEM_IFPP1,   IPIPE_ENN};
1197
            // we need to set inc and io and repeat flags on this state for continued block
1198
            // processing  --   keep the states of this machine somewhat manageable.
1199
            else if (ed_blk_cp )  next_state = {DEC_EDBCP1, MEM_OFHL_PM, IPIPE_EN12};// MEM_OFHL_PM triggers --BC
1200
            else if (ed_blk_in )  next_state = {DEC_EDBIN1, MEM_IOF_C,   IPIPE_EN12};// MEM_IOF_C triggers --B
1201
            else if (ed_blk_out)  next_state = {DEC_EDBOUT1,MEM_OFHL_PM, IPIPE_EN12};
1202
            else if (ed_blk_mv )  next_state = {DEC_EDBMV1, MEM_OFHL_PM, IPIPE_EN12};
1203
            else if (ed_retn   )  next_state = {DEC_RET,    MEM_OFSP,    IPIPE_EN12};// see int logic below
1204
            else                  next_state = {DEC_EXEC, MEM_IFPP1,    IPIPE_EN12A2};
1205
                   // double register reads and writes here    
1206
        DEC_EDNN1:                next_state = {DEC_EDNN2, MEM_NOP,     IPIPE_ENN}; // address to nn
1207
        DEC_EDNN2:
1208
            if (ed_dbl_rd)      next_state = {DEC_EDRD1, MEM_OFNN,    IPIPE_NOP};
1209
            else                next_state = {DEC_EDWR,  MEM_OSNN,    IPIPE_NOP};// OSNN selects data ok?                  
1210
        DEC_EDRD1:              next_state = {DEC_EDRD2, MEM_OFADRP1,  IPIPE_ENN};  // 1st byte 2n         
1211
        DEC_EDRD2:              next_state = {DEC_IF2,   MEM_IFPP1,   IPIPE_ENNA2}; // 2nd byte 2nn
1212
        DEC_EDWR:               next_state = {DEC_IF1,   MEM_OSADRP1,  IPIPE_NOP};
1213
 
1214
        //  ED  block moves
1215
        DEC_EDBCP1:
1216
            if (blk_done)   next_state = {DEC_EXEC, MEM_IFPP1,IPIPE_ENNA2};
1217
            else if(wb_int) next_state = {DEC_INT1, MEM_NOP, IPIPE_ENNA2};
1218
            else            next_state = {DEC_EDBCP2, MEM_NOP,  IPIPE_ENNA2};//set flags 
1219
        DEC_EDBCP2:                 next_state = {DEC_EDBCP3, MEM_NOP,     IPIPE_NOP};//wait for fr. alu_out is slow 
1220
        DEC_EDBCP3: if (fr[7])      next_state = {DEC_EXEC  , MEM_IFPP1,   IPIPE_NOP};
1221
                    else            next_state = {DEC_EDBCP1, MEM_OFHL_PM, IPIPE_NOP};
1222
 
1223
        DEC_EDBIN1:                  next_state = {DEC_EDBIN2, MEM_NOP,   IPIPE_ENN};
1224
        DEC_EDBIN2: if (blk_done)    next_state = {DEC_IF2A,  MEM_OSHL_PM,IPIPE_NOP}; // implies nn
1225
                    else if (wb_int) next_state = {DEC_INT1,  MEM_OSHL_PM,IPIPE_NOP};
1226
                    else             next_state = {DEC_EDBIN1,MEM_OSHL_PM,IPIPE_NOP};//set flags 
1227
        DEC_EDBIN3:                  next_state = {DEC_EDBIN1, MEM_IOF_C,   IPIPE_NOP};
1228
 
1229
        DEC_EDBOUT1:                 next_state = {DEC_EDBOUT2, MEM_NOP,   IPIPE_ENN};
1230
        DEC_EDBOUT2:if (blk_done)    next_state = {DEC_EXEC,  MEM_IOS_C,IPIPE_NOP};
1231
                    else if (wb_int) next_state = {DEC_INT1,  MEM_IOS_C,IPIPE_NOP}; // DEC_EDBOUT: if (blk_rpt)
1232
                    else             next_state = {DEC_EDBOUT3,MEM_IOS_C,IPIPE_NOP};
1233
 
1234
        DEC_EDBOUT3:                 next_state = {DEC_EDBOUT1,MEM_OFHL_PM, IPIPE_NOP};
1235
 
1236
        DEC_EDBMV1:                  next_state = {DEC_EDBMV2, MEM_NOP,   IPIPE_ENN};
1237
        DEC_EDBMV2: if (blk_done)    next_state = {DEC_EXEC,  MEM_OSDE_PM,IPIPE_NOP};
1238
                    else if (wb_int) next_state = {DEC_INT1,  MEM_OSDE_PM,IPIPE_NOP}; //DEC_EDBOUT: if (blk_rpt)
1239
                    else             next_state = {DEC_EDBMV3,MEM_OSDE_PM,IPIPE_NOP};
1240
 
1241
        DEC_EDBMV3:                  next_state = {DEC_EDBMV1,MEM_OFHL_PM, IPIPE_NOP};
1242
 
1243
        DEC_N:
1244
            if (INsA_6N7== ir1)      next_state = {DEC_NIN,  MEM_IOF_N, IPIPE_EN12};
1245
            else if (OUTs6N7_A==ir1) next_state = {DEC_IF1,  MEM_IOS_N, IPIPE_EN12};
1246
            else if (LDs6HL7_N==ir1) next_state = {DEC_IF1,  MEM_OS_HL_N, IPIPE_EN12};
1247
            else if (jmpr_true)      next_state = {DEC_IF2,  MEM_IFREL_N, IPIPE_NOP};
1248
            else                     next_state = {DEC_EXEC, MEM_IFPP1,  IPIPE_EN12A2};//r2r or false jumps
1249
        DEC_NIN:                     next_state = {DEC_IF2,  MEM_IFPP1,    IPIPE_ENNA2};
1250
 
1251
 
1252
        //ISSUES: LDsSP_NN - load commanded from ir2 decode?  and mechaninsm for updating PC on
1253
        //        JMP and CALL
1254
        //  on CALL   We have IFNN for JMP  
1255
        //   For CALL  Use MEM_CALL to transfer pc<=nn, nn<=pc, adr<=sp then MEM_OSSP then IFPP1
1256
        //   For  LDsSP_NN  yes  update from ir2 decode.                    
1257
        DEC_NN:
1258
            if      (callnn_true)     next_state = {DEC_NNCALL1, MEM_NOP, IPIPE_ENN}; // this gets new adr in nn
1259
                                                                                         // if we store from nn we can't do
1260
                                                                                         // a mem op now
1261
 
1262
            else if (jmpnn_true)      next_state = {DEC_NNJMP,  MEM_NOP,  IPIPE_ENN};    // gotta get nn before we can 
1263
                                                                                         // transfer to adr.
1264
            else if (LDs6NN7_A==ir1)  next_state = {DEC_NNOS3,   MEM_IFPP1,  IPIPE_ENN};
1265
            else if (LDs6NN7_HL==ir1) next_state = {DEC_NNOS1,   MEM_IFPP1,  IPIPE_ENN};
1266
            else if (LDsA_6NN7==ir1)  next_state = {DEC_NNOF3,    MEM_IFPP1,  IPIPE_ENN};
1267
            else if (LDsHL_6NN7==ir1) next_state = {DEC_NNOF1,    MEM_IFPP1,  IPIPE_ENN};
1268
            else                      next_state = { DEC_IF2, MEM_IFPP1, IPIPE_ENNEN2A2};
1269
 
1270
        DEC_NNCALL1:        next_state = {DEC_NNCALL2, MEM_CALL ,  IPIPE_NOP};
1271
        DEC_NNCALL2:        next_state = {DEC_IF1,    MEM_OSSP,   IPIPE_ENN};//A1 activates r2r xfers from ir1
1272
        DEC_NNJMP:        next_state = {DEC_IF2,     MEM_IFNN  , IPIPE_NOP};
1273
 
1274
        // ISSUE:  we blow out ir1 here - so need to keep some status to execute OSNN2.
1275
        //  general solution  if not DEC_EXEC we get op frmo nn high byte. 
1276
        //  note that first MEM_OSNN trabsferrs nn to wb_adr.
1277
        DEC_NNOS1:           next_state = {DEC_NNOS2,   MEM_OSNN,   IPIPE_EN1};
1278
        DEC_NNOS2:           next_state = {DEC_IF2A,    MEM_OSNN,   IPIPE_NOP};
1279
        DEC_NNOS3:           next_state = {DEC_IF2A,    MEM_OSNN,   IPIPE_EN1};
1280
 
1281
        DEC_NNOF1:           next_state = {DEC_NNOF2,  MEM_OFNN, IPIPE_EN12};
1282
        DEC_NNOF2:           next_state = {DEC_NNOF4,  MEM_OFNN, IPIPE_ENN};
1283
        DEC_NNOF3:           next_state = {DEC_NNOF4,  MEM_OFNN, IPIPE_EN12};
1284
        DEC_NNOF4:           next_state = {DEC_EXEC,   MEM_IFPP1, IPIPE_ENNA2};
1285
 
1286
        DEC_DDOS:            next_state = {DEC_IF2A, MEM_OSIXpD, IPIPE_EN12};
1287
        DEC_DDOF:            next_state = {DEC_OF  , MEM_OFIXpD,  IPIPE_EN12};
1288
 
1289
 
1290
        DEC_OF:              next_state = {DEC_EXEC,  MEM_IFPP1 , IPIPE_ENNA2};
1291
        DEC_POP:             next_state = {DEC_NNOF4,  MEM_OFSP, IPIPE_ENN };
1292
        DEC_PUSH:            next_state = {DEC_IF2A ,  MEM_OSSP, IPIPE_NOP };
1293
 
1294
 
1295
        DEC_RET:             next_state = { DEC_RET2, MEM_OFSP, IPIPE_ENN };
1296
        DEC_RET2:            next_state = { DEC_NNCALL2, MEM_NOP, IPIPE_ENN };
1297
                                                                 //  blow off a tick so we don't gronk adr
1298
        DEC_RMW:             next_state = {DEC_RMW2,  MEM_NOP,   IPIPE_ENNA2}; //activate
1299
        DEC_RMW2:            next_state = {DEC_IF1 ,  MEM_OSADR, IPIPE_NOP }; // from nn
1300
 
1301
 
1302
        //  IF memory -- rmw  else these are all reg 2 reg
1303
        DEC_CBM: if (CB_BIT==ir1[9:6]) next_state = {DEC_IF2, MEM_IFPP1,   IPIPE_ENNA2};
1304
                 else                 next_state = {DEC_RMW2 ,  MEM_NOP,  IPIPE_ENNA2};
1305
 
1306
        // The DDCB anf FDCB all assume memory operands 
1307
        // These beauties always rmw memory.  If a register op is default, they also 
1308
        // update the register.  Programmers think of this as 2 ops for the price of 1.
1309
        // unfortunately it is 2 ops for the price of 4.-- its not the number of lines 
1310
        // of assembler code that count but the number of bytes assembled. Oh well I signed
1311
        // up for this......  and had a notion of what I was getting into.
1312
        //
1313
        DEC_PFxCB:     next_state = { DEC_PFxCB2, MEM_IFPP1,  IPIPE_ENN}; // this gets d
1314
        DEC_PFxCB2:    next_state = { DEC_PFxCB3, MEM_OFIXpD, IPIPE_EN1}; //actual inst 
1315
        DEC_PFxCB3:    next_state = { DEC_PFxCB4, MEM_IFPP1,  IPIPE_ENNEN2A2};
1316
        DEC_PFxCB4:    next_state = { DEC_IF2A,   MEM_OSADR,  IPIPE_EN1};  //execute ir2
1317
 
1318
        //  crap   gotta subtract 2  (we always increment pc 2 times relative to the inst
1319
        //  that got interrupted. also can't push and dec pc without 2 adders.
1320
        //  choices:  1) fix up pc in 2 ticks 2) fix in 1 tick 3) add adder and do it fast
1321
        //   if there's anyone who knows is there anyone who cares.   
1322
        //   guess I'll do it fast  --   just a 16 bit subtractor.  heck silicon is 
1323
        //   cheap.  
1324
        DEC_INT1:       next_state <= {DEC_INT2, MEM_OSSP_PCM2, IPIPE_NOP};   //must derement PC
1325
        DEC_INT2:       next_state <= {DEC_INT3, MEM_OSSP_P,   IPIPE_NOP};    //must dec sp and PC  2 ops?
1326
        DEC_INT3:       next_state <= {DEC_INT4, MEM_INTA,     IPIPE_NOP};
1327
        DEC_INT4:       next_state <= {DEC_INT5, MEM_NOP,      IPIPE_ENN};
1328
        DEC_INT5:       next_state <= {DEC_IF2,  MEM_IFINT,    IPIPE_NOP};
1329
        default:        next_state <= {DEC_IDLE, MEM_NOP,      IPIPE_NOP};
1330
    endcase
1331
end
1332
 
1333
 
1334
always @(posedge clk or posedge rst)
1335
    if (rst) dec_state <= DEC_IDLE;
1336
    else   if (wb_rdy_nhz )   dec_state <= next_dec_state;
1337
 
1338
 
1339
//-----------------------instruction register #1 ----------------------------------
1340
//  //         next_pipe_state         {ir1,ir2,nn,act_ir2}
1341
 
1342
wire update_prefix =   dec_state == DEC_EXEC  | dec_state == DEC_DDFD;
1343
 
1344
always @(posedge clk or posedge rst)
1345
    if (rst) ir1 <=   NOP;
1346
    else if (wb_rdy_nhz & next_pipe_state[3]) ir1 <=  {2'b0, wb_dat_i} ;
1347
    else if ( wb_rdy_nhz &update_prefix )     ir1 <=  {ir1[7:0]==8'hed, ir1[7:0]==8'hcd, ir1[7:0]};
1348
 
1349
//----------- prefix states -----------------------------------------
1350
//  strings of prefix insts are ignored up to last one.  Also dded and fded are ignored 
1351
//  but ddcd and fdcd are defined prefix sets.
1352
//
1353
always @(posedge clk)
1354
    if  (wb_rdy_nhz & next_pipe_state[3]) {ir1dd, ir1fd } <= 2'b0;
1355
    else if ( wb_rdy_nhz & update_prefix )
1356
        {ir1dd, ir1fd } <= {ir1dd | (ir1[7:0]==8'hdd ) & (ir1[7:0]!=8'hed) & (ir1[7:0]!=8'hfd),
1357
                            ir1fd | (ir1[7:0]==8'hfd ) & (ir1[7:0]!=8'hed) & (ir1[7:0]!=8'hdd) };
1358
 
1359
//------------------- inst reg #2 -----------------------------------
1360
//  This stuff is key to the data hazard logic.  Hazards arise only AFTER activation of 
1361
//  a previous instruction.  Fundamentally all state changes related to ir1 may be 
1362
//  delayed eithor by a delay in wb response, or by a hazard.  Ir2 state changes
1363
//  are keyed off exec_ir2 - and always happen immediately.  ( exec_ir2 always is 
1364
//  immediately reset - unless of course a new instruction is transferred and executed.
1365
//
1366
// 
1367
//
1368
always @(posedge clk or posedge rst)
1369
    if (rst) ir2 <= 10'h0;
1370
    else if (wb_rdy_nhz & next_pipe_state[2]) ir2 <= ir1;
1371
 
1372
always @(posedge clk or posedge rst)
1373
    if (rst)
1374
    begin
1375
        ir2dd <= 1'b0;
1376
        ir2fd <= 1'b0;
1377
    end
1378
    else if (wb_rdy_nhz & next_pipe_state[2])
1379
    begin
1380
        ir2dd <= ir1dd;
1381
        ir2fd <= ir1fd;
1382
    end
1383
 
1384
always @(posedge clk )
1385
    if (wb_rdy_nhz & next_pipe_state[0]) exec_ir2 <= 1'b1;
1386
    else                                 exec_ir2 <= 1'b0;
1387
 
1388
 
1389
 
1390
 
1391
 
1392
//--------------- block move flags ------------------------
1393
always @(posedge clk)
1394
    if (dec_state == DEC_ED) blk_inc_flg <= dec_blk_inc;
1395
 
1396
always @(posedge clk)
1397
    if (dec_state == DEC_ED) blk_rpt_flg <= dec_blk_rpt;
1398
 
1399
 
1400
always @(posedge clk)
1401
    if (dec_state == DEC_ED) blk_io_flg <= dec_blk_io;
1402
 
1403
 
1404
//-------------------------- memory interface stuff ----------------------------
1405
 
1406
 
1407
// --  wb_adr
1408
always @(posedge clk) if (wb_rdy) wb_adr <= mux21;
1409
 
1410
// --  wb_we; 
1411
 
1412
always @(posedge clk or posedge rst)
1413
    if (rst)         wb_we <= 1'b0;
1414
    else if (wb_rdy_nhz) wb_we <= we_next;
1415
 
1416
 
1417
 
1418
// --  wb_cyc
1419
 
1420
wire no_wb_start = mem_idle | mem_halt | mem_op3 & blk_cmp_reg | mem_op1 & rmw_reg;
1421
always @(posedge clk or posedge rst)
1422
    if (rst)         wb_cyc <= 1'b0;
1423
    else if (wb_rdy_nhz) wb_cyc <= next_mem_state != MEM_NOP ;
1424
 
1425
// --  wb_stb; 
1426
 
1427
always @(posedge clk or posedge rst)
1428
    if (rst)         wb_stb <= 1'b0;
1429
    else if (wb_rdy_nhz) wb_stb <= next_mem_state != MEM_NOP ;
1430
 
1431
 
1432
// --  wb_lock  lets not worry about lock unless somebody thinks it matters.
1433
 
1434
// --  wb_tga_io
1435
always @(posedge clk or posedge rst)
1436
    if (rst)         wb_tga_io <= 2'b0;
1437
    else if (wb_rdy_nhz)
1438
    begin
1439
        if (next_mem_state == MEM_IOF_C |
1440
            next_mem_state == MEM_IOS_C |
1441
            next_mem_state == MEM_IOF_N |
1442
            next_mem_state == MEM_IOS_N     ) wb_tga_io <= TAG_IO;
1443
 
1444
        else if (next_mem_state == MEM_INTA ) wb_tga_io <= TAG_INT;
1445
        else                                  wb_tga_io <= 2'b0   ;
1446
    end
1447
 
1448
//------------ the input-output data register  (nn) -----------------------------------------
1449
//  basicaly we store lsb's folowed by msb's 
1450
//  input is always to msb (of input regiser) first (if a 2 byte operand, lsb<=msb before transfer)
1451
//   this gets nn to position { msb, lsb } before we execute 2 byte transfer.
1452
//
1453
//  if we don't update - we byte swap as well as
1454
//  when we read
1455
//  IMPORTANT  We store from MSB's so that on block moves read and write from same place.
1456
//  this makes the output look somewhat bass-ackwards   but who is looking?
1457
// 
1458
//  There is probably a simpler way to do this.   Unfortunately there are a lot of 
1459
//  dependencies here.   Ill continue as planned till it proves untractable.
1460
//  Issue is that we are using ir1 to provide the op specification  --  but in general
1461
//  ir1 gets gronked before 2nd store (if it happens) -  so we need to capture both
1462
//  data first time  OSIXpD OS1    OSSP, and   MEM_OSNN
1463
//
1464
// on consideration lets make a flag  flag_firstos  that gets set on first store after
1465
// DEC_EXEC
1466
// ISSUE reads both here and in ir1 need to execute on wb_ack ? 
1467
// I recall wb_ack must stay active until a change in cycle  ?
1468
//  need to review wb spec.
1469
//
1470
//issue:  how is EXs6SP7_HL implemented  --  it is known as a rmw  - and only trick for this file is
1471
// that nn must be properly updates with ir2
1472
 
1473
always @(posedge clk or posedge rst)
1474
    if       (rst)                                   flag_os1 <= 1'b0;
1475
    else if  ((DEC_EXEC == next_dec_state) & wb_rdy) flag_os1 <= 1'b0;
1476
    else if  ( we_next  )                            flag_os1 <= 1'b1;
1477
 
1478
 
1479
wire [15:0] pc_2 = pc - 16'h2;
1480
always @(posedge clk)
1481
    if (wb_rdy_nhz)
1482
    begin
1483
        if ( we_next & flag_os1)                            nn <= { nn[7:0], nn[15:8] } ;
1484
        else if(we_next & ( next_mem_state == MEM_CALL))     nn <= {pc[7:0], pc[15:8]};
1485
        else if(we_next & ( next_mem_state == MEM_OSSP_PCM2))  nn <= {pc_2[7:0], pc_2[15:8]};
1486
        else if(EXs6SP7_HL== ir2 & ir2dd & exec_ir2)         nn <= ixr;
1487
        else if(EXs6SP7_HL== ir2 & ir2fd & exec_ir2)         nn <= iyr;
1488
        else if(EXs6SP7_HL== ir2         & exec_ir2)          nn <= hl;
1489
        // these are the general cases with ir1 providing register specification
1490
        else if(we_next & ( next_mem_state == MEM_OS1     |
1491
                            next_mem_state == MEM_OSIXpD  |
1492
                            next_mem_state == MEM_OSSP    |
1493
                            next_mem_state == MEM_OSNN     ) )
1494
            begin
1495
                 if (os_a)     nn[15:8] <= ar;
1496
                 if (os_b)     nn[15:8] <= br;
1497
                 if (os_c)     nn       <= {cr, br };  // use for PUSHsBC
1498
                 if (os_d)     nn[15:8] <= dr;
1499
                 if (os_e)     nn       <= {er, dr };  // use for PUSHsDE
1500
                 if (os_h)     nn[15:8] <= hr;
1501
                 if (os_l)     nn       <= {lr, hr };  // use for PUSHsHL
1502
                 if (os_f)     nn       <= {fr, ar };  // use for PUSHsAF
1503
            end
1504
 
1505
        else   nn  <= { wb_dat_i, nn[15:8] };
1506
    end
1507
 
1508
 
1509
 
1510
//-------------------  pc  and sp ----------------------------------------------------
1511
always @(posedge clk or posedge rst)
1512
    if (rst)   pc <= 16'h0;
1513
    else if (wb_rdy_nhz)
1514
    begin
1515
        if (next_mem_state == MEM_DECPC) pc <= pc - 16'h1;  // decrementer could perhaps be shared.
1516
        if (next_mem_state == MEM_IFPP1) pc <= adr_alu;
1517
        if (next_mem_state == MEM_CALL ) pc <= nn;         //Use MEM_CALL to exchange pc<=>nn
1518
        if (next_mem_state == MEM_IFRST) pc <= src_mux;
1519
        if (next_mem_state == MEM_JMPHL) pc <= src_mux;
1520
        if (next_mem_state == MEM_IFNN ) pc <= src_mux;
1521
        if (next_mem_state == MEM_IFINT) pc <= src_mux;
1522
    end
1523
 
1524
//---------------------------------- sp -----------------------------------------------------
1525
//
1526
// with pc updates are always made from ir1  as the PC is so critical to instruction flow.
1527
// (this of course creates the possibility of an "inst_hazard" - where data is stored in an 
1528
//   instruction already fetched - see below)
1529
// with sp the situation is not so simple. 
1530
// Issues - especially regarding hazards.  
1531
//
1532
//     LDsSP_NN     this should be done from ir2 - no hazard as active state is ALWAYS IF2
1533
//                
1534
//     ADDsHL_SP    The add is a pre-add so sp cannot be modified before inst is executed from ir2
1535
//     DECsSP       Just do it with ir1 at DEC_EXEC   gotcha need -- IFPP1 in general use ir2 -> hazard
1536
//     EXs6SP7_HL    rmw - no change to sp - no issue here
1537
//     INCsSP       Just do it with ir1 at DEC_EXEC          gotcha  -- IFPP1  use ir2 -> hazard
1538
//     LDsSP_HL     do from ir1 and use standard hazard logic  (if H or L is being 
1539
//                    updated -- wait)
1540
//       
1541
//     ED_LDs6NN7_REG   REG== SP     // needs to be done from ir2
1542
//     ED_LDsREG_6NN7   REG== SP     //  do from ir2 - no hazard as executed on IF2 - refill pipe
1543
 
1544
always @(posedge clk )
1545
    if (exec_ir2 )   //  this has priority of course 
1546
        begin
1547
            if (LDsSP_NN     == ir2)   sp <= nn;
1548
            if (ED_LDsREG_6NN7 == ir2) sp <= nn;
1549
            if (  DECsSP   == ir2 )  sp <= add16;
1550
            if (  INCsSP   == ir2 )  sp <= add16;
1551
        end
1552
    else if (wb_rdy_nhz)
1553
    begin
1554
         if (  DECsSP   == ir1 & dec_state == DEC_EXEC)  sp <= adr_alu;
1555
         if (  INCsSP   == ir1 & dec_state == DEC_EXEC)  sp <= adr_alu;
1556
         if (  LDsSP_HL == ir1 & dec_state == DEC_EXEC)  sp <= {hr,lr};
1557
         if (next_mem_state == MEM_OFSP      ) sp <= adr_alu;
1558
         if (next_mem_state == MEM_OSSP      ) sp <= adr_alu;
1559
         if (next_mem_state == MEM_OSSP_PCM2 ) sp <= adr_alu;
1560
         if (next_mem_state == MEM_OSSP_P    ) sp <= adr_alu;
1561
    end
1562
//----------------- inst hazard logic ------------------------------------------
1563
 
1564
 
1565
 
1566
always @(posedge clk or posedge rst)
1567
    if (rst) inst_haz <= 1'b0;
1568
    else if  (we_next & (pc - 16'h1) == mux21)  inst_haz <= 1'b1;
1569
    else if  (dec_state == DEC_EXEC)  inst_haz <= 1'b0;   // highest priority interrupt
1570
 
1571
//-------------------- int logic ----------------------------------------
1572
//  We have a wishbone interrupt system  -  which i guess does not preclude a 
1573
//  non-maskable interrupt......   but bottom line is that such an interrupt is 
1574
//  definately out of favor with current system thinking.   Within an embedded system
1575
//  ( the target application here ) a single interrupt controller  capable of handeling
1576
//   as many interrupts as desired is the best choice.  
1577
//  Therefore we enable only mode 2 interrupts and a single enable ff.
1578
//
1579
//  This begs the question of what to do with the "RETI" instruction  -- ED4D.  We opt to 
1580
//  enable interrupts with this instruction (and all its "aliases").
1581
//
1582
always @(posedge clk or posedge rst)
1583
    if (rst)                   int_en <= 1'b0;
1584
    else if (wb_rdy_nhz)
1585
    begin
1586
        if      ((dec_state == DEC_EXEC) & (DI== ir1))  int_en <= 1'b0;
1587
        else if ((dec_state == DEC_EXEC) & en_int_next) int_en <= 1'b1;
1588
        else if ((dec_state == DEC_ED)   & ed_retn)     int_en <= 1'b0;
1589
        if      (dec_state == DEC_INT1)                 int_en <= 1'b0;
1590
    end
1591
 
1592
 
1593
always @(posedge clk or posedge rst)
1594
    if (rst)                                      en_int_next <=1'b0;
1595
    else if (wb_rdy_nhz)
1596
    begin
1597
        if ((dec_state == DEC_EXEC) & (EI== ir1)) en_int_next <=1'b1;
1598
        else if (dec_state == DEC_EXEC)           en_int_next <=1'b0;
1599
    end
1600
 
1601
always @(posedge clk)
1602
    wb_irq_sync <= wb_int_rq;
1603
 
1604
assign  wb_int = wb_irq_sync & int_en;
1605
 
1606
endmodule
1607
 

powered by: WebSVN 2.1.0

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