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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_fsm.v] - Blame information for rev 254

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 128 gabrielosh
////////////////////////////////////////////////////////////////////////////
2
////                                                                    ////
3
//// T6507LP IP Core                                                    ////
4
////                                                                    ////
5
//// This file is part of the T6507LP project                           ////
6
//// http://www.opencores.org/cores/t6507lp/                            ////
7
////                                                                    ////
8
//// Description                                                        ////
9
//// 6507 FSM                                                           ////
10
////                                                                    ////
11
//// TODO:                                                              ////
12
//// - Fix relative mode, bit 7 means negative                          ////
13
//// - Check reset behavior                                             ////
14
//// - Comment the code                                                 ////
15
////                                                                    ////
16
//// Author(s):                                                         ////
17
//// - Gabriel Oshiro Zardo, gabrieloshiro@gmail.com                    ////
18
//// - Samuel Nascimento Pagliarini (creep), snpagliarini@gmail.com     ////
19
////                                                                    ////
20
////////////////////////////////////////////////////////////////////////////
21
////                                                                    ////
22
//// Copyright (C) 2001 Authors and OPENCORES.ORG                       ////
23
////                                                                    ////
24
//// This source file may be used and distributed without               ////
25
//// restriction provided that this copyright statement is not          ////
26
//// removed from the file and that any derivative work contains        ////
27
//// the original copyright notice and the associated disclaimer.       ////
28
////                                                                    ////
29
//// This source file is free software; you can redistribute it         ////
30
//// and/or modify it under the terms of the GNU Lesser General         ////
31
//// Public License as published by the Free Software Foundation;       ////
32
//// either version 2.1 of the License, or (at your option) any         ////
33
//// later version.                                                     ////
34
////                                                                    ////
35
//// This source is distributed in the hope that it will be             ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied         ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ////
38
//// PURPOSE. See the GNU Lesser General Public License for more        ////
39
//// details.                                                           ////
40
////                                                                    ////
41
//// You should have received a copy of the GNU Lesser General          ////
42
//// Public License along with this source; if not, download it         ////
43
//// from http://www.opencores.org/lgpl.shtml                           ////
44
////                                                                    ////
45
////////////////////////////////////////////////////////////////////////////
46
 
47
`include "timescale.v"
48
 
49 253 creep
module t6507lp_fsm(clk, reset_n, alu_result, alu_status, data_in, alu_x, alu_y, address, rw_mem, data_out, alu_opcode, alu_a, alu_enable);
50 128 gabrielosh
        parameter [3:0] DATA_SIZE = 4'd8;
51
        parameter [3:0] ADDR_SIZE = 4'd13;
52
 
53
        localparam [3:0] DATA_SIZE_ = DATA_SIZE - 4'b0001;
54
        localparam [3:0] ADDR_SIZE_ = ADDR_SIZE - 4'b0001;
55
 
56
        input clk;                              // master clock
57
        input reset_n;                          // active low reset
58
        input [DATA_SIZE_:0] alu_result; // result from alu operation
59
        input [DATA_SIZE_:0] alu_status; // alu status register
60
        input [DATA_SIZE_:0] data_in;            // data that comes from the bus controller
61
        input [DATA_SIZE_:0] alu_x;              // alu x index register
62
        input [DATA_SIZE_:0] alu_y;              // alu y index register
63
        output reg [ADDR_SIZE_:0] address;       // system bus address
64 253 creep
        output reg rw_mem;                      // read = 0, write = 1
65 128 gabrielosh
        output reg [DATA_SIZE_:0] data_out;      // data that will be written somewhere else
66
        output reg [DATA_SIZE_:0] alu_opcode;    // current opcode
67
        output reg [DATA_SIZE_:0] alu_a; // extra operand sent to the alu
68
        output reg alu_enable;                  // a flag that when high tells the alu when to perform the operations
69
 
70
 
71
        // FSM states. If aiming for less power consumption try gray coding.
72
        //localparam FETCH_OP_CALC = 5'b00001; this was never used
73
        localparam FETCH_OP = 5'b00000;
74
        localparam FETCH_LOW = 5'b00010;
75
        localparam FETCH_HIGH = 5'b00011;
76
        localparam READ_MEM = 5'b00100;
77
        localparam DUMMY_WRT_CALC = 5'b00101;
78
        localparam WRITE_MEM = 5'b00110;
79
        localparam FETCH_OP_CALC_PARAM = 5'b00111;
80
        localparam READ_MEM_CALC_INDEX = 5'b01000;
81
        localparam FETCH_HIGH_CALC_INDEX = 5'b01001;
82
        localparam READ_MEM_FIX_ADDR = 5'b01010;
83
        localparam FETCH_OP_EVAL_BRANCH = 5'b01011;
84
        localparam FETCH_OP_FIX_PC = 5'b01100;
85
        localparam READ_FROM_POINTER = 5'b01101;
86
        localparam READ_FROM_POINTER_X = 5'b01110;
87
        localparam READ_FROM_POINTER_X1 = 5'b01111;
88
        localparam PUSH_PCH = 5'b10000;
89
        localparam PUSH_PCL = 5'b10001;
90
        localparam PUSH_STATUS = 5'b10010;
91
        localparam FETCH_PCL = 5'b10011;
92
        localparam FETCH_PCH = 5'b10100;
93
        localparam INCREMENT_SP = 5'b10101;
94
        localparam PULL_STATUS = 5'b10110;
95
        localparam PULL_PCL = 5'b10111;
96
        localparam PULL_PCH = 5'b11000;
97
        localparam INCREMENT_PC = 5'b11001;
98
        localparam PUSH_REGISTER = 5'b11010;
99
        localparam PULL_REGISTER = 5'b11011;
100
        localparam DUMMY = 5'b11100;
101
        localparam RESET = 5'b11111;
102
 
103 146 creep
        `include "t6507lp_package.v"
104 128 gabrielosh
 
105 253 creep
        // rw_mem signals
106 128 gabrielosh
        localparam MEM_READ = 1'b0;
107
        localparam MEM_WRITE = 1'b1;
108
 
109
        reg [ADDR_SIZE_:0] pc;           // program counter
110
        reg [DATA_SIZE:0] sp;            // stack pointer. 9 bits wide.
111
        reg [DATA_SIZE_:0] ir;           // instruction register
112
        reg [ADDR_SIZE_:0] temp_addr;    // temporary address
113
        reg [DATA_SIZE_:0] temp_data;    // temporary data
114
 
115
        reg [4:0] state, next_state; // current and next state registers
116
 
117
        // wiring that simplifies the FSM logic by simplifying the addressing modes
118
        reg absolute;
119
        reg absolute_indexed;
120
        reg accumulator;
121
        reg immediate;
122
        reg implied;
123
        reg indirectx;
124
        reg indirecty;
125
        reg relative;
126
        reg zero_page;
127
        reg zero_page_indexed;
128
        reg [DATA_SIZE_:0] index; // will be assigned with either X or Y
129
 
130
        // regs that store the type of operation. again, this simplifies the FSM a lot.
131
        reg read;
132
        reg read_modify_write;
133
        reg write;
134
        reg jump;
135
        reg jump_indirect;
136 212 creep
        reg index_is_x;
137
        reg index_is_branch;
138 128 gabrielosh
 
139
        // regs for the special instructions
140
        reg brk;
141
        reg rti;
142
        reg rts;
143
        reg pha;
144
        reg php;
145 212 creep
        reg pla;
146 128 gabrielosh
        reg plp;
147 194 creep
        reg jsr;
148
        reg tsx;
149 205 creep
        reg txs;
150 212 creep
        reg nop;
151 128 gabrielosh
 
152 246 creep
        reg invalid;
153
 
154 128 gabrielosh
        wire [ADDR_SIZE_:0] next_pc;      // a simple logic to add one to the PC
155
        assign next_pc = pc + 13'b0000000000001;
156
 
157 200 creep
        wire [DATA_SIZE:0] sp_plus_one;          // simple adder and subtracter for the stack pointer
158
        assign sp_plus_one = {1'b1, sp[7:0] + 8'b000000001};
159 128 gabrielosh
 
160 200 creep
        wire [DATA_SIZE:0] sp_minus_one;
161
        assign sp_minus_one = {1'b1, sp[7:0] - 8'b000000001};
162 128 gabrielosh
 
163
        reg [ADDR_SIZE_:0] address_plus_index;   // this two registers are used when the instruction uses indexing.
164
        reg page_crossed;                       // address_plus_index always adds index to address and page_crossed asserts when the sum creates a carry.
165
 
166
        reg branch;     // a simple reg that is asserted everytime a branch will be executed.                   
167
 
168
        // this is the combinational logic related to indexed instructions
169
        always @(*) begin
170 200 creep
                address_plus_index = 13'h000;
171 128 gabrielosh
                page_crossed = 1'b0;
172
 
173 212 creep
                case (state)
174 242 creep
                        READ_MEM_FIX_ADDR, FETCH_HIGH_CALC_INDEX: begin
175 212 creep
                                {page_crossed, address_plus_index[7:0]} = temp_addr[7:0] + index;
176
                                address_plus_index[12:8] = temp_addr[12:8] + page_crossed;
177 128 gabrielosh
                        end
178 242 creep
                        READ_FROM_POINTER_X1: begin
179
                                {page_crossed, address_plus_index[7:0]} = temp_addr[7:0] + index;
180 243 creep
                                address_plus_index[12:8] = data_in[4:0];
181 242 creep
                        end
182 212 creep
                        FETCH_OP_FIX_PC, FETCH_OP_EVAL_BRANCH: begin
183
                                if (branch) begin
184
                                        {page_crossed, address_plus_index[7:0]} = pc[7:0] + index;
185
                                        address_plus_index[12:8] = pc[12:8] + page_crossed;
186
                                        // warning: pc might feed these lines twice and cause branch failure
187
                                end     // solution: add a temp reg i guess
188 128 gabrielosh
                        end
189 212 creep
 
190
                        READ_FROM_POINTER: begin
191
                                if (indirectx) begin
192
                                        {page_crossed, address_plus_index[7:0]} = temp_data + index;
193
                                        //address_plus_index[12:8] = 5'b00000; // already assigned earlier at this block
194
                                end
195
                                else if (jump_indirect) begin
196
                                        address_plus_index[7:0] = temp_addr[7:0] + 8'h01;
197
                                        //address_plus_index[12:8] = 5'b00000;
198
                                end
199
                                else begin // indirecty falls here
200
                                        address_plus_index[7:0] = temp_data + 8'h01;
201
                                        //address_plus_index[12:8] = 5'b00000;
202
                                end
203 128 gabrielosh
                        end
204 212 creep
 
205
                        READ_FROM_POINTER_X: begin
206
                                {page_crossed, address_plus_index[7:0]} = temp_data + index + 8'h01;
207
                                //address_plus_index[12:8] = 5'b00000;
208
                        end
209
 
210
                        READ_MEM_CALC_INDEX: begin
211
                                {page_crossed, address_plus_index[7:0]} = temp_addr[7:0] + index;
212
                                //address_plus_index[12:8] = 5'b00000;
213
                        end
214
                endcase
215 128 gabrielosh
        end
216
 
217 146 creep
        reg [2:0] rst_counter; // a counter to preserve the cpu idle for six cycles
218
 
219 128 gabrielosh
        always @ (posedge clk or negedge reset_n) begin // sequencial always block
220
                if (reset_n == 1'b0) begin
221
                        // all registers must assume default values
222 200 creep
                        pc <= 13'h0; // TODO: this is written somewhere. something about a reset vector. must be checked.
223 194 creep
                        sp <= 9'b111111111; // the default is 'h1FF 
224 128 gabrielosh
                        ir <= 8'h00;
225
                        temp_addr <= 13'h0000;
226
                        temp_data <= 8'h00;
227
                        state <= RESET;
228
                        // registered outputs also receive default values
229
                        address <= 13'h0000;
230 253 creep
                        rw_mem <= MEM_READ;
231 128 gabrielosh
                        data_out <= 8'h00;
232 200 creep
                        rst_counter <= 3'h0;
233 212 creep
                        index <= 8'h00;
234 128 gabrielosh
                end
235
                else begin
236
                        state <= next_state;
237 146 creep
 
238 128 gabrielosh
                        case (state)
239
                                RESET: begin    // The processor was reset
240 200 creep
                                        rst_counter <= rst_counter + 3'b001;
241 194 creep
                                        //sp <= 9'b111111111; // this prevents flipflops with different drivers
242 128 gabrielosh
                                        //$write("under reset"); 
243
                                end
244
                                /*
245
                                FETCH_OP: executed when the processor was reset or the last instruction could not fetch.
246
                                FETCH_OP_CALC_PARAM: enables the alu with an argument (alu_a) and fetchs the next instruction opcode. (pipelining)
247
                                */
248
                                FETCH_OP, FETCH_OP_CALC_PARAM: begin // this is the pipeline happening!
249
                                        pc <= next_pc;
250
                                        address <= next_pc;
251 253 creep
                                        rw_mem <= MEM_READ;
252 128 gabrielosh
                                        ir <= data_in;
253
                                end
254
                                /*
255
                                in this state the opcode is already known so truly execution begins.
256
                                all instructions execute this cycle.
257
                                */
258 196 creep
                                FETCH_LOW: begin
259 212 creep
                                        //$display("index_is_x = %b",index_is_x);
260
                                        if (index_is_x == 1'b1) begin
261
                                                index <= alu_x;
262
                                                //$display("alu_x = %d",alu_x);
263
                                        end
264
                                        else begin
265
                                                index <= alu_y;
266
                                                //$display("alu_y = %d",alu_y);
267
                                        end
268
                                        if (index_is_branch) begin
269
                                                index <= temp_data;
270
                                        end
271 195 creep
                                        if (accumulator || implied || txs || tsx) begin
272 128 gabrielosh
                                                pc <= pc; // is this better?
273
                                                address <= pc;
274 253 creep
                                                rw_mem <= MEM_READ;
275 194 creep
 
276
                                                if (txs) begin
277 196 creep
                                                        sp[7:0] <= alu_x;
278 194 creep
                                                end
279
                                                //alu_a
280 128 gabrielosh
                                        end
281
                                        else if (immediate || relative) begin
282
                                                pc <= next_pc;
283
                                                address <= next_pc;
284 253 creep
                                                rw_mem <= MEM_READ;
285 128 gabrielosh
                                                temp_data <= data_in; // the follow-up byte is saved in temp_data 
286
                                        end
287
                                        else if (absolute || absolute_indexed || jump_indirect) begin
288
                                                pc <= next_pc;
289 196 creep
                                                address <= next_pc;
290 253 creep
                                                rw_mem <= MEM_READ;
291 128 gabrielosh
                                                temp_addr <= {{5{1'b0}},data_in};
292
                                                temp_data <= 8'h00;
293
                                        end
294
                                        else if (zero_page) begin
295
                                                pc <= next_pc;
296
                                                address <= {{5{1'b0}},data_in};
297
                                                temp_addr <= {{5{1'b0}},data_in};
298
 
299
                                                if (write) begin
300 253 creep
                                                        rw_mem <= MEM_WRITE;
301 128 gabrielosh
                                                        data_out <= alu_result;
302
                                                end
303
                                                else begin
304 253 creep
                                                        rw_mem <= MEM_READ;
305 128 gabrielosh
                                                        data_out <= 8'h00;
306
                                                end
307
                                        end
308
                                        else if (zero_page_indexed) begin
309
                                                pc <= next_pc;
310
                                                address <= {{5{1'b0}}, data_in};
311
                                                temp_addr <= {{5{1'b0}}, data_in};
312 253 creep
                                                rw_mem <= MEM_READ;
313 128 gabrielosh
                                        end
314
                                        else if (indirectx || indirecty) begin
315
                                                pc <= next_pc;
316
                                                address <= data_in;
317
                                                temp_data <= data_in;
318 253 creep
                                                rw_mem <= MEM_READ;
319 128 gabrielosh
                                        end
320
                                        else begin // the special instructions will fall here: BRK, RTI, RTS...
321
                                                if (brk) begin
322
                                                        pc <= next_pc;
323
                                                        address <= sp;
324
                                                        data_out <= {{3{1'b0}}, pc[12:8]};
325 253 creep
                                                        rw_mem <= MEM_WRITE;
326 128 gabrielosh
                                                end
327
                                                else if (rti || rts) begin
328
                                                        address <= sp;
329 253 creep
                                                        rw_mem <= MEM_READ;
330 128 gabrielosh
                                                end
331
                                                else if (pha || php) begin
332
                                                        pc <= pc;
333
                                                        address <= sp;
334
                                                        data_out <= (pha) ? alu_result : alu_status;
335 253 creep
                                                        rw_mem <= MEM_WRITE;
336 128 gabrielosh
                                                end
337
                                                else if (pla || plp) begin
338
                                                        pc <= pc;
339
                                                        address <= sp;
340 253 creep
                                                        rw_mem <= MEM_READ;
341 128 gabrielosh
                                                end
342 246 creep
                                                else if (invalid) begin
343
                                                        address <= pc;
344 253 creep
                                                        rw_mem <= MEM_READ;
345 246 creep
                                                end
346 128 gabrielosh
                                                else begin // jsr
347
                                                        address <= sp;
348 253 creep
                                                        rw_mem <= MEM_READ;
349 128 gabrielosh
                                                        temp_addr <= {{5{1'b0}}, data_in};
350
                                                        pc <= next_pc;
351
                                                end
352
                                        end
353
                                end
354
                                FETCH_HIGH_CALC_INDEX: begin
355
                                        pc <= next_pc;
356
                                        temp_addr[12:8] <= data_in[4:0];
357
                                        address <= {data_in[4:0], address_plus_index[7:0]};
358 253 creep
                                        rw_mem <= MEM_READ;
359 128 gabrielosh
                                        data_out <= 8'h00;
360
                                end
361
                                // this cycle fetchs the next operand while still evaluating if a branch occurred.
362
                                FETCH_OP_EVAL_BRANCH: begin
363
                                        if (branch) begin
364
                                                pc <= {{5{1'b0}}, address_plus_index[7:0]};
365
                                                address <= {{5{1'b0}}, address_plus_index[7:0]};
366 253 creep
                                                rw_mem <= MEM_READ;
367 128 gabrielosh
                                                data_out <= 8'h00;
368
                                        end
369
                                        else begin
370
                                                pc <= next_pc;
371
                                                address <= next_pc;
372 253 creep
                                                rw_mem <= MEM_READ;
373 128 gabrielosh
                                                data_out <= 8'h00;
374
                                                ir <= data_in;
375
                                        end
376
                                end
377
                                // sometimes when reading memory page crosses may occur. the pc register must be fixed, i.e., add 16'h0100
378
                                FETCH_OP_FIX_PC: begin
379
                                        if (page_crossed) begin
380
                                                pc[12:8] <= address_plus_index[12:8];
381
                                                address[12:8] <= address_plus_index[12:8];
382
                                        end
383
                                        else begin
384
                                                pc <= next_pc;
385
                                                address <= next_pc;
386 253 creep
                                                rw_mem <= MEM_READ;
387 128 gabrielosh
                                                ir <= data_in;
388
                                        end
389
                                end
390
                                // several instructions ocupy 3 bytes in memory. this cycle reads the third byte.
391
                                FETCH_HIGH: begin
392
                                        if (jump) begin
393
                                                pc <= {data_in[4:0], temp_addr[7:0]}; // PCL <= first byte, PCH <= second byte
394
                                                address <= {data_in[4:0], temp_addr[7:0]};
395 253 creep
                                                rw_mem <= MEM_READ;
396 128 gabrielosh
                                                data_out <= 8'h00;
397
                                        end
398
                                        else begin
399
                                                if (write) begin
400
                                                        pc <= next_pc;
401
                                                        temp_addr[12:8] <= data_in[4:0];
402
                                                        address <= {data_in[4:0],temp_addr[7:0]};
403 253 creep
                                                        rw_mem <= MEM_WRITE;
404 128 gabrielosh
                                                        data_out <= alu_result;
405
                                                end
406
                                                else begin // read_modify_write or just read
407
                                                        pc <= next_pc;
408
                                                        temp_addr[12:8] <= data_in[4:0];
409
                                                        address <= {data_in[4:0],temp_addr[7:0]};
410 253 creep
                                                        rw_mem <= MEM_READ;
411 128 gabrielosh
                                                        data_out <= 8'h00;
412
                                                end
413
                                        end
414
                                end
415
                                // read memory at address
416
                                READ_MEM: begin
417
                                        if (read_modify_write) begin
418
                                                pc <= pc;
419
                                                address <= temp_addr;
420 253 creep
                                                rw_mem <= MEM_WRITE;
421 128 gabrielosh
                                                temp_data <= data_in;
422
                                                data_out <= data_in; // writeback the same value
423
                                        end
424
                                        else begin
425
                                                pc <= pc;
426
                                                address <= pc;
427
                                                temp_data <= data_in;
428 253 creep
                                                rw_mem <= MEM_READ;
429 128 gabrielosh
                                                data_out <= 8'h00;
430
                                        end
431
                                end
432
                                READ_MEM_CALC_INDEX: begin
433
                                                address <= address_plus_index;
434
                                                temp_addr <= address_plus_index;
435
 
436
                                                if (write) begin
437 253 creep
                                                        rw_mem <= MEM_WRITE;
438 128 gabrielosh
                                                        data_out <= alu_result;
439
                                                end
440
                                                else begin
441 253 creep
                                                        rw_mem <= MEM_READ;
442 128 gabrielosh
                                                        data_out <= 8'h00;
443
                                                end
444
 
445
                                end
446
                                READ_MEM_FIX_ADDR: begin
447
                                        if (read) begin
448 253 creep
                                                rw_mem <= MEM_READ;
449 128 gabrielosh
                                                data_out <= 8'h00;
450
 
451
                                                if (page_crossed) begin // fix address 
452
                                                        address <= address_plus_index;
453
                                                        temp_addr <= address_plus_index;
454
                                                end
455
                                                else begin
456
                                                        address <= pc;
457
                                                        temp_data <= data_in;
458
                                                end
459
                                        end
460
                                        else if (write) begin
461 253 creep
                                                rw_mem <= MEM_WRITE;
462 128 gabrielosh
                                                data_out <= alu_result;
463
                                                address <= address_plus_index;
464
                                                temp_addr <= address_plus_index;
465
 
466
                                        end
467
                                        else begin // read modify write
468 253 creep
                                                rw_mem <= MEM_READ;
469 128 gabrielosh
                                                data_out <= 8'h00;
470
                                                address <= address_plus_index;
471
                                                temp_addr <= address_plus_index;
472
                                        end
473
                                end
474
                                // some instructions have a dummy write cycle. this is it.
475
                                DUMMY_WRT_CALC: begin
476
                                        pc <= pc;
477
                                        address <= temp_addr;
478 253 creep
                                        rw_mem <= MEM_WRITE;
479 128 gabrielosh
                                        data_out <= alu_result;
480
                                end
481
                                WRITE_MEM: begin
482
                                        pc <= pc;
483
                                        address <= pc;
484 253 creep
                                        rw_mem <= MEM_READ;
485 128 gabrielosh
                                        data_out <= 8'h00;
486
                                end
487
                                READ_FROM_POINTER: begin
488
                                        if (jump_indirect) begin
489
                                                pc[7:0] <= data_in;
490 253 creep
                                                rw_mem <= MEM_READ;
491 128 gabrielosh
                                                address <= address_plus_index;
492
                                        end
493
                                        else begin
494
                                                pc <= pc;
495 253 creep
                                                rw_mem <= MEM_READ;
496 128 gabrielosh
 
497
                                                if (indirectx) begin
498
                                                        address <= address_plus_index;
499
                                                end
500
                                                else begin // indirecty falls here
501
                                                        address <= address_plus_index;
502
                                                        temp_addr <= {{5{1'b0}}, data_in};
503
                                                end
504
                                        end
505
                                end
506
                                READ_FROM_POINTER_X: begin
507
                                        pc <= pc;
508
                                        address <= address_plus_index;
509
                                        temp_addr[7:0] <= data_in;
510 253 creep
                                        rw_mem <= MEM_READ;
511 128 gabrielosh
                                end
512
                                READ_FROM_POINTER_X1: begin
513
                                        if (jump_indirect) begin
514
                                                pc[12:8] <= data_in[4:0];
515 253 creep
                                                rw_mem <= MEM_READ;
516 128 gabrielosh
                                                address <= {data_in[4:0], pc[7:0]};
517
                                        end
518
                                        else if (indirectx) begin
519
                                                address <= {data_in[4:0], temp_addr[7:0]};
520
                                                if (write) begin
521 253 creep
                                                        rw_mem <= MEM_WRITE;
522 128 gabrielosh
                                                        data_out <= alu_result;
523
                                                end
524
                                                else begin
525 253 creep
                                                        rw_mem <= MEM_READ;
526 128 gabrielosh
                                                end
527
                                        end
528
                                        else begin // indirecty falls here
529
                                                address <= address_plus_index;
530
                                                temp_addr[12:8] <= data_in;
531 253 creep
                                                rw_mem <= MEM_READ;
532 128 gabrielosh
                                        end
533
                                end
534 246 creep
                                PUSH_PCH: begin // this is probably wrong
535 128 gabrielosh
                                        pc <= pc;
536
                                        address <= sp_minus_one;
537
                                        data_out <= pc[7:0];
538 253 creep
                                        rw_mem <= MEM_WRITE;
539 128 gabrielosh
                                        sp <= sp_minus_one;
540
                                end
541
                                PUSH_PCL: begin
542
                                        if (jsr) begin
543
                                                pc <= pc;
544
                                                address <= pc;
545 253 creep
                                                rw_mem <= MEM_READ;
546 128 gabrielosh
                                                sp <= sp_minus_one;
547
                                        end
548
                                        else begin
549
                                                pc <= pc;
550
                                                address <= sp_minus_one;
551
                                                data_out <= alu_status;
552 253 creep
                                                rw_mem <= MEM_WRITE;
553 128 gabrielosh
                                                sp <= sp_minus_one;
554
                                        end
555
                                end
556
                                PUSH_STATUS: begin
557 199 creep
                                        address <= 13'h1FFE;
558 253 creep
                                        rw_mem <= MEM_READ;
559 196 creep
                                        sp <= sp_minus_one;
560 128 gabrielosh
                                end
561
                                FETCH_PCL: begin
562
                                        pc[7:0] <= data_in;
563 199 creep
                                        address <= 13'h1FFF;
564 253 creep
                                        rw_mem <= MEM_READ;
565 128 gabrielosh
                                end
566
                                FETCH_PCH: begin
567
                                        pc[12:8] <= data_in[4:0];
568
                                        address <= {data_in[4:0], pc[7:0]};
569 253 creep
                                        rw_mem <= MEM_READ;
570 128 gabrielosh
                                end
571
                                INCREMENT_SP: begin
572
                                        sp <= sp_plus_one;
573
                                        address <= sp_plus_one;
574
                                end
575
                                PULL_STATUS: begin
576
                                        sp <= sp_plus_one;
577
                                        address <= sp_plus_one;
578
                                        temp_data <= data_in;
579
                                end
580
                                PULL_PCL: begin
581
                                        sp <= sp_plus_one;
582
                                        address <= sp_plus_one;
583
                                        pc[7:0] <= data_in;
584
                                end
585
                                PULL_PCH: begin
586
                                        pc[12:8] <= data_in[4:0];
587
                                        address <= {data_in[4:0], pc[7:0]};
588
                                end
589
                                INCREMENT_PC: begin
590
                                        pc <= next_pc;
591
                                        address <= next_pc;
592
                                end
593
                                PUSH_REGISTER: begin
594
                                        pc <= pc;
595
                                        address <= pc;
596
                                        sp <= sp_minus_one;
597 253 creep
                                        rw_mem <= MEM_READ;
598 128 gabrielosh
                                        temp_data <= data_in;
599
                                end
600
                                PULL_REGISTER: begin
601
                                        pc <= pc;
602
                                        address <= pc;
603
                                        temp_data <= data_in;
604
                                end
605
                                DUMMY: begin
606
                                        address <= sp;
607 253 creep
                                        rw_mem <= MEM_WRITE;
608 128 gabrielosh
                                end
609
                                default: begin
610
                                        //$write("unknown state"); // TODO: check if synth really ignores this 2 lines. Otherwise wrap it with a `ifdef 
611
                                        //$finish(0); 
612
                                end
613
 
614
                        endcase
615
                end
616
        end
617
 
618
        always @ (*) begin // this is the next_state logic and the combinational output logic always block
619
                alu_opcode = 8'h00;
620
                alu_a = 8'h00;
621
                alu_enable = 1'b0;
622
                next_state = RESET; // these lines prevents latches
623
 
624 246 creep
                if (invalid == 1'b1) begin
625
                        next_state = FETCH_OP;
626
                end
627
                else case (state)
628 128 gabrielosh
                        RESET: begin
629 200 creep
                                if (rst_counter == 3'd6) begin
630 146 creep
                                        next_state = FETCH_OP;
631
                                end
632 128 gabrielosh
                        end
633
                        FETCH_OP: begin
634
                                next_state = FETCH_LOW;
635
                        end
636
                        FETCH_OP_CALC_PARAM: begin
637
                                next_state = FETCH_LOW;
638
                                alu_opcode = ir;
639
                                alu_enable = 1'b1;
640
                                alu_a = temp_data;
641
                        end
642
                        FETCH_LOW: begin
643 195 creep
                                if (accumulator  || implied || txs) begin
644 205 creep
                                        if (!nop) begin
645
                                                alu_opcode = ir;
646
                                                alu_enable = 1'b1;
647
                                        end
648 194 creep
                                        next_state = FETCH_OP;
649 128 gabrielosh
                                end
650 195 creep
                                else if (tsx) begin
651
                                        alu_opcode = ir;
652
                                        alu_enable = 1'b1;
653
                                        next_state = FETCH_OP;
654
                                        alu_a = sp[7:0];
655
                                end
656 128 gabrielosh
                                else if (immediate) begin
657
                                        next_state = FETCH_OP_CALC_PARAM;
658
                                end
659
                                else if (zero_page) begin
660
                                        if (read || read_modify_write) begin
661
                                                next_state = READ_MEM;
662
                                        end
663
                                        else if (write) begin
664
                                                next_state = WRITE_MEM;
665
                                                alu_opcode = ir;
666
                                                alu_enable = 1'b1;
667
                                                alu_a = 8'h00;
668
                                        end
669
                                        else begin
670
                                                //$write("unknown behavior"); 
671
                                                //$finish(0);
672
                                        end
673
                                end
674
                                else if (zero_page_indexed) begin
675
                                        next_state = READ_MEM_CALC_INDEX;
676
                                end
677
                                else if (absolute || jump_indirect) begin
678
                                        next_state = FETCH_HIGH;
679
                                        if (write) begin // this is being done one cycle early but i have checked and the ALU will still work properly
680
                                                alu_opcode = ir;
681
                                                alu_enable = 1'b1;
682
                                                alu_a = 8'h00;
683
                                        end
684
                                end
685
                                else if (absolute_indexed) begin
686
                                        next_state = FETCH_HIGH_CALC_INDEX;
687
                                end
688
                                else if (relative) begin
689
                                        next_state = FETCH_OP_EVAL_BRANCH;
690
                                end
691
                                else if (indirectx || indirecty) begin
692
                                        next_state = READ_FROM_POINTER;
693
                                end
694
                                else begin // all the special instructions will fall here
695
                                        if (brk) begin
696
                                                next_state = PUSH_PCH;
697
                                        end
698
                                        else if (rti || rts) begin
699
                                                next_state = INCREMENT_SP;
700
                                        end
701
                                        else if (pha) begin
702
                                                alu_opcode = ir;
703
                                                alu_enable = 1'b1;
704
                                                //alu_a = 8'h00;
705
                                                next_state = PUSH_REGISTER;
706
                                        end
707
                                        else if (php) begin
708
                                                next_state = PUSH_REGISTER;
709
                                        end
710
                                        else if (pla || plp) begin
711
                                                next_state = INCREMENT_SP;
712
                                        end
713
                                        else begin // jsr
714
                                                next_state = DUMMY;
715
                                        end
716
                                end
717
                        end
718
                        READ_FROM_POINTER: begin
719
                                if (indirectx) begin
720
                                        next_state = READ_FROM_POINTER_X;
721
                                end
722
                                else begin // indirecty and jump indirect falls here
723
                                        next_state = READ_FROM_POINTER_X1;
724
                                end
725
                        end
726
                        READ_FROM_POINTER_X: begin
727
                                next_state = READ_FROM_POINTER_X1;
728
                        end
729
                        READ_FROM_POINTER_X1: begin
730
                                if (jump_indirect) begin
731
                                        next_state = FETCH_OP;
732
                                end
733
                                else if (indirecty) begin
734
                                        next_state = READ_MEM_FIX_ADDR;
735
                                end
736
                                else begin
737
                                        if (read) begin // no instruction using pointers is from type read_modify_write
738
                                                next_state = READ_MEM;
739
                                        end
740
                                        else if (write) begin
741
                                                alu_opcode = ir;
742
                                                alu_enable = 1'b1;
743
                                                next_state = WRITE_MEM;
744
                                        end
745
                                end
746
                        end
747
                        FETCH_OP_EVAL_BRANCH: begin
748
                                if (branch) begin
749
                                        next_state = FETCH_OP_FIX_PC;
750
                                end
751
                                else begin
752
                                        next_state = FETCH_LOW;
753
                                end
754
                        end
755
                        FETCH_OP_FIX_PC: begin
756
                                if (page_crossed) begin
757
                                        next_state = FETCH_OP;
758
                                end
759
                                else begin
760
                                        next_state = FETCH_LOW;
761
                                end
762
                        end
763
                        FETCH_HIGH_CALC_INDEX: begin
764
                                next_state = READ_MEM_FIX_ADDR;
765
                        end
766
                        READ_MEM_FIX_ADDR: begin
767
                                if (read) begin
768
                                        if (page_crossed) begin
769
                                                next_state = READ_MEM;
770
                                        end
771
                                        else begin
772
                                                next_state = FETCH_OP_CALC_PARAM;
773
                                        end
774
                                end
775
                                else if (read_modify_write) begin
776
                                        next_state = READ_MEM;
777
                                end
778
                                else if (write) begin
779
                                        next_state = WRITE_MEM;
780
                                        alu_enable = 1'b1;
781
                                        alu_opcode = ir;
782
                                end
783
                                else begin
784
                                        //$write("unknown behavior"); 
785
                                        //$finish(0);
786
                                end
787
                        end
788
                        FETCH_HIGH: begin
789
                                if (jump_indirect) begin
790
                                        next_state = READ_FROM_POINTER;
791
                                end
792
                                else if (jump) begin
793
                                        next_state = FETCH_OP;
794
                                end
795
                                else if (read || read_modify_write) begin
796
                                        next_state = READ_MEM;
797
                                end
798
                                else if (write) begin
799
                                        next_state = WRITE_MEM;
800
                                end
801
                                else begin
802
                                        //$write("unknown behavior"); 
803
                                        //$finish(0);
804
                                end
805
                        end
806
                        READ_MEM_CALC_INDEX: begin
807
                                if (read || read_modify_write) begin
808
                                        next_state = READ_MEM;
809
                                end
810
                                else if (write) begin
811
                                        alu_opcode = ir;
812
                                        alu_enable = 1'b1;
813
                                        next_state = WRITE_MEM;
814
                                end
815
                                else begin
816
                                        //$write("unknown behavior"); 
817
                                        //$finish(0);
818
                                end
819
                        end
820
                        READ_MEM: begin
821
                                if (read) begin
822
                                        next_state = FETCH_OP_CALC_PARAM;
823
                                end
824
                                else if (read_modify_write) begin
825
                                        next_state = DUMMY_WRT_CALC;
826
                                end
827
                        end
828
                        DUMMY_WRT_CALC: begin
829
                                alu_opcode = ir;
830
                                alu_enable = 1'b1;
831
                                alu_a = data_in;
832
                                next_state = WRITE_MEM;
833
                        end
834
                        WRITE_MEM: begin
835
                                next_state = FETCH_OP;
836
                        end
837
                        PUSH_PCH: begin
838
                                next_state = PUSH_PCL;
839
                        end
840
                        PUSH_PCL: begin
841
                                if (jsr) begin
842
                                        next_state = FETCH_HIGH;
843
                                end
844
                                else begin
845
                                        next_state = PUSH_STATUS;
846
                                end
847
                        end
848
                        PUSH_STATUS: begin
849
                                next_state = FETCH_PCL;
850
                        end
851
                        FETCH_PCL: begin
852
                                next_state = FETCH_PCH;
853
                        end
854
                        FETCH_PCH: begin
855
                                next_state = FETCH_OP;
856
                        end
857
                        INCREMENT_SP: begin
858
                                if (rti) begin
859
                                        next_state = PULL_STATUS;
860
                                end
861
                                else if (pla || plp) begin
862
                                        next_state = PULL_REGISTER;
863
                                end
864
                                else begin // rts
865
                                        next_state = PULL_PCL;
866
                                end
867
                        end
868
                        PULL_STATUS: begin
869
                                next_state = PULL_PCL;
870
                        end
871
                        PULL_PCL: begin
872
                                next_state = PULL_PCH;
873 202 creep
 
874
                                if (rti) begin
875
                                        alu_opcode = ir;
876
                                        alu_enable = 1'b1;
877
                                        alu_a = temp_data;
878
                                end
879 128 gabrielosh
                        end
880
                        PULL_PCH: begin
881
                                if (rti) begin
882
                                        next_state = FETCH_OP;
883
                                end
884
                                else begin // rts
885
                                        next_state = INCREMENT_PC;
886
                                end
887
                        end
888
                        INCREMENT_PC: begin
889
                                next_state = FETCH_OP;
890
                        end
891
                        PUSH_REGISTER: begin
892
                                next_state = FETCH_OP;
893
                        end
894
                        PULL_REGISTER: begin
895
                                next_state = FETCH_OP_CALC_PARAM;
896
                        end
897
                        DUMMY: begin
898
                                next_state = PUSH_PCH;
899
                        end
900
                        default: begin
901
                                next_state = RESET;
902
                        end
903
                endcase
904
        end
905
 
906
        // this always block is responsible for updating the address mode and the type of operation being done
907
        always @ (*) begin // 
908
                absolute = 1'b0;
909
                absolute_indexed = 1'b0;
910
                accumulator = 1'b0;
911
                immediate = 1'b0;
912
                implied = 1'b0;
913
                indirectx = 1'b0;
914
                indirecty = 1'b0;
915
                relative = 1'b0;
916
                zero_page = 1'b0;
917
                zero_page_indexed = 1'b0;
918 254 creep
                index_is_x = 1'b0;
919 212 creep
                index_is_branch = 1'b0;
920 128 gabrielosh
 
921 212 creep
                //index = 8'h00;
922 128 gabrielosh
 
923
                read = 1'b0;
924
                read_modify_write = 1'b0;
925
                write = 1'b0;
926
                jump = 1'b0;
927
                jump_indirect = 1'b0;
928
                branch = 1'b0;
929
 
930
                brk = 1'b0;
931
                rti = 1'b0;
932
                rts = 1'b0;
933
                pha = 1'b0;
934
                php = 1'b0;
935
                pla = 1'b0;
936
                plp = 1'b0;
937
                jsr = 1'b0;
938 194 creep
                tsx = 1'b0;
939
                txs = 1'b0;
940 205 creep
                nop = 1'b0;
941 128 gabrielosh
 
942 246 creep
                invalid = 1'b0;
943
 
944 128 gabrielosh
                case (ir)
945 205 creep
                        CLC_IMP, CLD_IMP, CLI_IMP, CLV_IMP, DEX_IMP, DEY_IMP, INX_IMP, INY_IMP, SEC_IMP, SED_IMP, SEI_IMP, TAX_IMP,
946
                        TAY_IMP, TXA_IMP, TYA_IMP: begin
947 128 gabrielosh
                                implied = 1'b1;
948
                        end
949 205 creep
                        NOP_IMP: begin
950
                                implied = 1'b1;
951
                                nop = 1'b1;
952
                        end
953 128 gabrielosh
                        ASL_ACC, LSR_ACC, ROL_ACC, ROR_ACC: begin
954
                                accumulator = 1'b1;
955
                        end
956
                        ADC_IMM, AND_IMM, CMP_IMM, CPX_IMM, CPY_IMM, EOR_IMM, LDA_IMM, LDX_IMM, LDY_IMM, ORA_IMM, SBC_IMM: begin
957
                                immediate = 1'b1;
958
                        end
959
                        ADC_ZPG, AND_ZPG, ASL_ZPG, BIT_ZPG, CMP_ZPG, CPX_ZPG, CPY_ZPG, DEC_ZPG, EOR_ZPG, INC_ZPG, LDA_ZPG, LDX_ZPG, LDY_ZPG,
960
                        LSR_ZPG, ORA_ZPG, ROL_ZPG, ROR_ZPG, SBC_ZPG, STA_ZPG, STX_ZPG, STY_ZPG: begin
961
                                zero_page = 1'b1;
962
                        end
963
                        ADC_ZPX, AND_ZPX, ASL_ZPX, CMP_ZPX, DEC_ZPX, EOR_ZPX, INC_ZPX, LDA_ZPX, LDY_ZPX, LSR_ZPX, ORA_ZPX, ROL_ZPX, ROR_ZPX,
964
                        SBC_ZPX, STA_ZPX, STY_ZPX: begin
965
                                zero_page_indexed = 1'b1;
966 212 creep
                                index_is_x = 1'b1;
967
                                //index = alu_x;
968 128 gabrielosh
                        end
969
                        LDX_ZPY, STX_ZPY: begin
970
                                zero_page_indexed = 1'b1;
971 212 creep
                                index_is_x = 1'b0;
972
                                //index = alu_y;
973 128 gabrielosh
                        end
974
                        BCC_REL: begin
975
                                relative = 1'b1;
976 212 creep
                                index_is_branch = 1'b1;
977
                                //index = temp_data;
978 128 gabrielosh
 
979
                                if (!alu_status[C]) begin
980
                                        branch = 1'b1;
981
                                end
982
                                else begin
983
                                        branch = 1'b0;
984
                                end
985
                        end
986
                        BCS_REL: begin
987
                                relative = 1'b1;
988 212 creep
                                index_is_branch = 1'b1;
989
                                //index = temp_data;
990 128 gabrielosh
 
991
                                if (alu_status[C]) begin
992
                                        branch = 1'b1;
993
                                end
994
                                else begin
995
                                        branch = 1'b0;
996
                                end
997
                        end
998
                        BEQ_REL: begin
999
                                relative = 1'b1;
1000 212 creep
                                index_is_branch = 1'b1;
1001
                                //index = temp_data;
1002 128 gabrielosh
 
1003
                                if (alu_status[Z]) begin
1004
                                        branch = 1'b1;
1005
                                end
1006
                                else begin
1007
                                        branch = 1'b0;
1008
                                end
1009
                        end
1010
                        BNE_REL: begin
1011
                                relative = 1'b1;
1012 212 creep
                                index_is_branch = 1'b1;
1013
                                //index = temp_data;
1014 128 gabrielosh
 
1015
                                if (alu_status[Z] == 1'b0) begin
1016
                                        branch = 1'b1;
1017
                                end
1018
                                else begin
1019
                                        branch = 1'b0;
1020
                                end
1021
                        end
1022
                        BPL_REL: begin
1023
                                relative = 1'b1;
1024 212 creep
                                index_is_branch = 1'b1;
1025
                                //index = temp_data;
1026 128 gabrielosh
 
1027
                                if (!alu_status[N]) begin
1028
                                        branch = 1'b1;
1029
                                end
1030
                                else begin
1031
                                        branch = 1'b0;
1032
                                end
1033
                        end
1034
                        BMI_REL: begin
1035
                                relative = 1'b1;
1036 212 creep
                                index_is_branch = 1'b1;
1037
                                //index = temp_data;
1038 128 gabrielosh
 
1039
                                if (alu_status[N]) begin
1040
                                        branch = 1'b1;
1041
                                end
1042
                                else begin
1043
                                        branch = 1'b0;
1044
                                end
1045
                        end
1046
                        BVC_REL: begin
1047
                                relative = 1'b1;
1048 212 creep
                                index_is_branch = 1'b1;
1049
                                //index = temp_data;
1050 128 gabrielosh
 
1051
                                if (!alu_status[V]) begin
1052
                                        branch = 1'b1;
1053
                                end
1054
                                else begin
1055
                                        branch = 1'b0;
1056
                                end
1057
                        end
1058
                        BVS_REL: begin
1059
                                relative = 1'b1;
1060 212 creep
                                index_is_branch = 1'b1;
1061
                                //index = temp_data;
1062 128 gabrielosh
 
1063
                                if (alu_status[V]) begin
1064
                                        branch = 1'b1;
1065
                                end
1066
                                else begin
1067
                                        branch = 1'b0;
1068
                                end
1069
                        end
1070
                        ADC_ABS, AND_ABS, ASL_ABS, BIT_ABS, CMP_ABS, CPX_ABS, CPY_ABS, DEC_ABS, EOR_ABS, INC_ABS, LDA_ABS,
1071
                        LDX_ABS, LDY_ABS, LSR_ABS, ORA_ABS, ROL_ABS, ROR_ABS, SBC_ABS, STA_ABS, STX_ABS, STY_ABS: begin
1072
                                absolute = 1'b1;
1073
                        end
1074
                        ADC_ABX, AND_ABX, ASL_ABX, CMP_ABX, DEC_ABX, EOR_ABX, INC_ABX, LDA_ABX, LDY_ABX, LSR_ABX, ORA_ABX, ROL_ABX, ROR_ABX,
1075
                        SBC_ABX, STA_ABX: begin
1076
                                absolute_indexed = 1'b1;
1077 212 creep
                                index_is_x = 1'b1;
1078 128 gabrielosh
                        end
1079
                        ADC_ABY, AND_ABY, CMP_ABY, EOR_ABY, LDA_ABY, LDX_ABY, ORA_ABY, SBC_ABY, STA_ABY: begin
1080
                                absolute_indexed = 1'b1;
1081 212 creep
                                index_is_x = 1'b0;
1082 128 gabrielosh
                        end
1083
                        ADC_IDX, AND_IDX, CMP_IDX, EOR_IDX, LDA_IDX, ORA_IDX, SBC_IDX, STA_IDX: begin
1084
                                indirectx = 1'b1;
1085 212 creep
                                index_is_x = 1'b1;
1086 128 gabrielosh
                        end
1087
                        ADC_IDY, AND_IDY, CMP_IDY, EOR_IDY, LDA_IDY, ORA_IDY, SBC_IDY, STA_IDY: begin
1088
                                indirecty = 1'b1;
1089 212 creep
                                index_is_x = 1'b0;
1090 128 gabrielosh
                        end
1091
                        JMP_ABS: begin
1092
                                absolute = 1'b1;
1093
                                jump = 1'b1;
1094
                        end
1095
                        JMP_IND: begin
1096
                                jump_indirect = 1'b1;
1097
                        end
1098
                        BRK_IMP: begin
1099
                                brk = 1'b1;
1100
                        end
1101
                        RTI_IMP: begin
1102
                                rti = 1'b1;
1103
                        end
1104
                        RTS_IMP: begin
1105
                                rts = 1'b1;
1106
                        end
1107
                        PHA_IMP: begin
1108
                                pha = 1'b1;
1109
                        end
1110
                        PHP_IMP: begin
1111
                                php = 1'b1;
1112
                        end
1113
                        PLA_IMP: begin
1114
                                pla = 1'b1;
1115
                        end
1116
                        PLP_IMP: begin
1117
                                plp = 1'b1;
1118
                        end
1119
                        JSR_ABS: begin
1120
                                jsr = 1'b1;
1121 246 creep
                                jump = 1'b1;
1122 128 gabrielosh
                        end
1123 194 creep
                        TSX_IMP: begin
1124
                                tsx = 1'b1;
1125
                        end
1126
                        TXS_IMP: begin
1127
                                txs = 1'b1;
1128
                        end
1129 128 gabrielosh
                        default: begin
1130 212 creep
                                index_is_x = 1'b1;
1131 128 gabrielosh
                                //$write("state : %b", state);
1132
                                if (reset_n == 1'b1 && state != FETCH_OP_FIX_PC) begin // the processor is NOT being reset neither it is fixing the pc
1133 246 creep
                                        invalid = 1'b1;
1134 128 gabrielosh
                                        //$write("\nunknown OPCODE!!!!! 0x%h\n", ir);
1135
                                        //$finish();
1136
                                end
1137
                        end
1138
                endcase
1139
 
1140
                case (ir)
1141
                        ASL_ACC, ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX, LSR_ACC, LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX, ROL_ACC, ROL_ZPG, ROL_ZPX, ROL_ABS,
1142
                        ROL_ABX, ROR_ACC, ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX, INC_ZPG, INC_ZPX, INC_ABS, INC_ABX, DEC_ZPG, DEC_ZPX, DEC_ABS,
1143
                        DEC_ABX: begin
1144
                                read_modify_write = 1'b1;
1145
                        end
1146
                        STA_ZPG, STA_ZPX, STA_ABS, STA_ABX, STA_ABY, STA_IDX, STA_IDY, STX_ZPG, STX_ZPY, STX_ABS, STY_ZPG, STY_ZPX, STY_ABS: begin
1147
                                write = 1'b1;
1148
                        end
1149
                        default: begin // this should work fine since the previous case statement will detect the unknown/undocumented/unsupported opcodes
1150
                                read = 1'b1;
1151
                        end
1152
                endcase
1153
        end
1154
endmodule
1155
 
1156
 
1157
 

powered by: WebSVN 2.1.0

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