14 `define FLAG_Z 8'b10000000
15 `define FLAG_N 8'b01000000
16 `define FLAG_H 8'b00100000
17 `define FLAG_C 8'b00010000
19 `define STATE_FETCH 2'h0
20 `define STATE_DECODE 2'h1
21 `define STATE_EXECUTE 2'h2
22 `define STATE_WRITEBACK 2'h3
24 `define INSN_LD_reg_imm8 8'b00xxx110
25 `define INSN_HALT 8'b01110110
26 `define INSN_LD_HL_reg 8'b01110xxx
27 `define INSN_LD_reg_HL 8'b01xxx110
28 `define INSN_LD_reg_reg 8'b01xxxxxx
29 `define INSN_LD_reg_imm16 8'b00xx0001
30 `define INSN_LD_SP_HL 8'b11111001
31 `define INSN_PUSH_reg 8'b11xx0101
32 `define INSN_POP_reg 8'b11xx0001
33 `define INSN_LDH_AC 8'b111x0010 // Either LDH A,(C) or LDH (C),A
34 `define INSN_LDx_AHL 8'b001xx010 // LDD/LDI A,(HL) / (HL),A
35 `define INSN_ALU8 8'b10xxxxxx // 10 xxx yyy
36 `define INSN_NOP 8'b00000000
37 `define INSN_RST 8'b11xxx111
38 `define INSN_RET 8'b110x1001 // 1 = RETI, 0 = RET
39 `define INSN_RETCC 8'b110xx000
40 `define INSN_CALL 8'b11001101
41 `define INSN_CALLCC 8'b110xx100 // Not that call/cc.
42 `define INSN_JP_imm 8'b11000011
43 `define INSN_JPCC_imm 8'b110xx010
44 `define INSN_ALU_A 8'b00xxx111
45 `define INSN_JP_HL 8'b11101001
46 `define INSN_JR_imm 8'b00011000
47 `define INSN_JRCC_imm 8'b001xx000
48 `define INSN_INCDEC16 8'b00xxx011
49 `define INSN_VOP_INTR 8'b11111100 // 0xFC is grabbed by the fetch if there is an interrupt pending.
50 `define INSN_DI 8'b11110011
51 `define INSN_EI 8'b11111011
53 `define INSN_cc_NZ 2'b00
54 `define INSN_cc_Z 2'b01
55 `define INSN_cc_NC 2'b10
56 `define INSN_cc_C 2'b11
58 `define INSN_reg_A 3'b111
59 `define INSN_reg_B 3'b000
60 `define INSN_reg_C 3'b001
61 `define INSN_reg_D 3'b010
62 `define INSN_reg_E 3'b011
63 `define INSN_reg_H 3'b100
64 `define INSN_reg_L 3'b101
65 `define INSN_reg_dHL 3'b110
66 `define INSN_reg16_BC 2'b00
67 `define INSN_reg16_DE 2'b01
68 `define INSN_reg16_HL 2'b10
69 `define INSN_reg16_SP 2'b11
70 `define INSN_stack_AF 2'b11
71 `define INSN_stack_BC 2'b00
72 `define INSN_stack_DE 2'b01
73 `define INSN_stack_HL 2'b10
74 `define INSN_alu_ADD 3'b000
75 `define INSN_alu_ADC 3'b001
76 `define INSN_alu_SUB 3'b010
77 `define INSN_alu_SBC 3'b011
78 `define INSN_alu_AND 3'b100
79 `define INSN_alu_XOR 3'b101
80 `define INSN_alu_OR 3'b110
81 `define INSN_alu_CP 3'b111 // Oh lawd, is dat some CP?
82 `define INSN_alu_RLCA 3'b000
83 `define INSN_alu_RRCA 3'b001
84 `define INSN_alu_RLA 3'b010
85 `define INSN_alu_RRA 3'b011
86 `define INSN_alu_DAA 3'b100
87 `define INSN_alu_CPL 3'b101
88 `define INSN_alu_SCF 3'b110
89 `define INSN_alu_CCF 3'b111
93 output reg [15:0] busaddress = 0, /* BUS_* is latched on STATE_FETCH. */
95 output reg buswr = 0, output reg busrd = 0,
96 input irq, input [7:0] jaddr);
98 reg [1:0] state = 0; /* State within this bus cycle (see STATE_*). */
99 reg [2:0] cycle = 0; /* Cycle for instructions. */
101 reg [7:0] registers[11:0];
103 reg [15:0] address; /* Address for the next bus operation. */
105 reg [7:0] opcode; /* Opcode from the current machine cycle. */
107 reg [7:0] rdata, wdata; /* Read data from this bus cycle, or write data for the next. */
108 reg rd = 1, wr = 0, newcycle = 1;
110 reg [7:0] tmp, tmp2; /* Generic temporary regs. */
113 assign busdata = buswr ? buswdata : 8'bzzzzzzzz;
115 reg ie = 0, iedelay = 0;
142 always @(posedge clk)
146 busaddress <= {registers[`REG_PCH], registers[`REG_PCL]};
150 busaddress <= address;
156 state <= `STATE_DECODE;
161 opcode <= `INSN_VOP_INTR;
168 if (rd) rdata <= busdata;
179 address <= 16'bxxxxxxxxxxxxxxxx; // Make it obvious if something of type has happened.
180 wdata <= 8'bxxxxxxxx;
181 state <= `STATE_EXECUTE;
183 `STATE_EXECUTE: begin
184 `define EXEC_INC_PC \
185 {registers[`REG_PCH], registers[`REG_PCL]} <= {registers[`REG_PCH], registers[`REG_PCL]} + 1
186 `define EXEC_NEXTADDR_PCINC \
187 address <= {registers[`REG_PCH], registers[`REG_PCL]} + 1
188 `define EXEC_NEWCYCLE \
189 newcycle <= 1; rd <= 1; wr <= 0
191 `INSN_LD_reg_imm8: begin
195 `EXEC_NEXTADDR_PCINC;
200 if (opcode[5:3] == `INSN_reg_dHL) begin
201 address <= {registers[`REG_H], registers[`REG_L]};
216 /* XXX Interrupts needed for HALT. */
218 `INSN_LD_HL_reg: begin
222 `INSN_reg_A: wdata <= registers[`REG_A];
223 `INSN_reg_B: wdata <= registers[`REG_B];
224 `INSN_reg_C: wdata <= registers[`REG_C];
225 `INSN_reg_D: wdata <= registers[`REG_D];
226 `INSN_reg_E: wdata <= registers[`REG_E];
227 `INSN_reg_H: wdata <= registers[`REG_H];
228 `INSN_reg_L: wdata <= registers[`REG_L];
230 address <= {registers[`REG_H], registers[`REG_L]};
239 `INSN_LD_reg_HL: begin
242 address <= {registers[`REG_H], registers[`REG_L]};
252 `INSN_LD_reg_reg: begin
256 `INSN_reg_A: tmp <= registers[`REG_A];
257 `INSN_reg_B: tmp <= registers[`REG_B];
258 `INSN_reg_C: tmp <= registers[`REG_C];
259 `INSN_reg_D: tmp <= registers[`REG_D];
260 `INSN_reg_E: tmp <= registers[`REG_E];
261 `INSN_reg_H: tmp <= registers[`REG_H];
262 `INSN_reg_L: tmp <= registers[`REG_L];
265 `INSN_LD_reg_imm16: begin
269 `EXEC_NEXTADDR_PCINC;
273 `EXEC_NEXTADDR_PCINC;
276 2: begin `EXEC_NEWCYCLE; end
279 `INSN_LD_SP_HL: begin
282 tmp <= registers[`REG_H];
287 tmp <= registers[`REG_L];
291 `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */
295 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
297 `INSN_stack_AF: wdata <= registers[`REG_A];
298 `INSN_stack_BC: wdata <= registers[`REG_B];
299 `INSN_stack_DE: wdata <= registers[`REG_D];
300 `INSN_stack_HL: wdata <= registers[`REG_H];
305 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
307 `INSN_stack_AF: wdata <= registers[`REG_F];
308 `INSN_stack_BC: wdata <= registers[`REG_C];
309 `INSN_stack_DE: wdata <= registers[`REG_E];
310 `INSN_stack_HL: wdata <= registers[`REG_L];
313 2: begin /* Twiddle thumbs. */ end
320 `INSN_POP_reg: begin /* POP is 12 cycles! */
324 address <= {registers[`REG_SPH],registers[`REG_SPL]};
328 address <= {registers[`REG_SPH],registers[`REG_SPL]};
339 address <= {8'hFF,registers[`REG_C]};
340 if (opcode[4]) begin // LD A,(C)
344 wdata <= registers[`REG_A];
356 address <= {registers[`REG_H],registers[`REG_L]};
357 if (opcode[3]) begin // LDx A, (HL)
361 wdata <= registers[`REG_A];
371 if ((opcode[2:0] == `INSN_reg_dHL) && (cycle == 0)) begin
372 // fffffffff fuck your shit, read from (HL) :(
374 address <= {registers[`REG_H], registers[`REG_L]};
379 `INSN_reg_A: tmp <= registers[`REG_A];
380 `INSN_reg_B: tmp <= registers[`REG_B];
381 `INSN_reg_C: tmp <= registers[`REG_C];
382 `INSN_reg_D: tmp <= registers[`REG_D];
383 `INSN_reg_E: tmp <= registers[`REG_E];
384 `INSN_reg_H: tmp <= registers[`REG_H];
385 `INSN_reg_L: tmp <= registers[`REG_L];
386 `INSN_reg_dHL: tmp <= rdata;
401 `EXEC_INC_PC; // This goes FIRST in RST
405 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
406 wdata <= registers[`REG_PCH];
410 address <= {registers[`REG_SPH],registers[`REG_SPL]}-2;
411 wdata <= registers[`REG_PCL];
415 {registers[`REG_PCH],registers[`REG_PCL]} <=
416 {10'b0,opcode[5:3],3'b0};
420 `INSN_RET,`INSN_RETCC: begin
424 address <= {registers[`REG_SPH],registers[`REG_SPL]};
426 1: begin // SPECIAL CASE: cycle does NOT increase linearly with ret!
427 `EXEC_INC_PC; // cycle 1 is skipped if we are not retcc
429 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
430 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
431 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
432 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
435 address <= {registers[`REG_SPH],registers[`REG_SPL]};
439 address <= {registers[`REG_SPH],registers[`REG_SPL]} + 1;
441 3: begin /* twiddle thumbs */ end
444 // do NOT increment PC!
448 `INSN_CALL,`INSN_CALLCC: begin
452 `EXEC_NEXTADDR_PCINC;
457 `EXEC_NEXTADDR_PCINC;
462 if (!opcode[0]) // i.e., is callcc
463 /* We need to check the condition code to bail out. */
465 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
466 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
467 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
468 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
472 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 1;
473 wdata <= registers[`REG_PCH];
477 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
478 wdata <= registers[`REG_PCL];
482 `EXEC_NEWCYCLE; /* do NOT increment the PC */
486 `INSN_JP_imm,`INSN_JPCC_imm: begin
490 `EXEC_NEXTADDR_PCINC;
495 `EXEC_NEXTADDR_PCINC;
500 if (!opcode[0]) begin // i.e., JP cc,nn
501 /* We need to check the condition code to bail out. */
503 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
504 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
505 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
506 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
518 `INSN_JR_imm,`INSN_JRCC_imm: begin
522 `EXEC_NEXTADDR_PCINC;
527 if (opcode[5]) begin // i.e., JP cc,nn
528 /* We need to check the condition code to bail out. */
530 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
531 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
532 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
533 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
542 `INSN_INCDEC16: begin
546 `INSN_reg16_BC: begin
547 tmp <= registers[`REG_B];
548 tmp2 <= registers[`REG_C];
550 `INSN_reg16_DE: begin
551 tmp <= registers[`REG_D];
552 tmp2 <= registers[`REG_E];
554 `INSN_reg16_HL: begin
555 tmp <= registers[`REG_H];
556 tmp2 <= registers[`REG_L];
558 `INSN_reg16_SP: begin
559 tmp <= registers[`REG_SPH];
560 tmp2 <= registers[`REG_SPL];
570 `INSN_VOP_INTR: begin
573 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 1;
574 wdata <= registers[`REG_PCH];
578 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
579 wdata <= registers[`REG_PCL];
598 state <= `STATE_WRITEBACK;
600 `STATE_WRITEBACK: begin
605 1: case (opcode[5:3])
606 `INSN_reg_A: begin registers[`REG_A] <= rdata; end
607 `INSN_reg_B: begin registers[`REG_B] <= rdata; end
608 `INSN_reg_C: begin registers[`REG_C] <= rdata; end
609 `INSN_reg_D: begin registers[`REG_D] <= rdata; end
610 `INSN_reg_E: begin registers[`REG_E] <= rdata; end
611 `INSN_reg_H: begin registers[`REG_H] <= rdata; end
612 `INSN_reg_L: begin registers[`REG_L] <= rdata; end
613 `INSN_reg_dHL: begin /* Go off to cycle 2 */ end
618 /* Nothing needs happen here. */
619 /* XXX Interrupts needed for HALT. */
621 `INSN_LD_HL_reg: begin
622 /* Nothing of interest here */
624 `INSN_LD_reg_HL: begin
629 `INSN_reg_A: registers[`REG_A] <= tmp;
630 `INSN_reg_B: registers[`REG_B] <= tmp;
631 `INSN_reg_C: registers[`REG_C] <= tmp;
632 `INSN_reg_D: registers[`REG_D] <= tmp;
633 `INSN_reg_E: registers[`REG_E] <= tmp;
634 `INSN_reg_H: registers[`REG_H] <= tmp;
635 `INSN_reg_L: registers[`REG_L] <= tmp;
640 `INSN_LD_reg_reg: begin
642 `INSN_reg_A: registers[`REG_A] <= tmp;
643 `INSN_reg_B: registers[`REG_B] <= tmp;
644 `INSN_reg_C: registers[`REG_C] <= tmp;
645 `INSN_reg_D: registers[`REG_D] <= tmp;
646 `INSN_reg_E: registers[`REG_E] <= tmp;
647 `INSN_reg_H: registers[`REG_H] <= tmp;
648 `INSN_reg_L: registers[`REG_L] <= tmp;
651 `INSN_LD_reg_imm16: begin
656 `INSN_reg16_BC: registers[`REG_C] <= rdata;
657 `INSN_reg16_DE: registers[`REG_E] <= rdata;
658 `INSN_reg16_HL: registers[`REG_L] <= rdata;
659 `INSN_reg16_SP: registers[`REG_SPL] <= rdata;
664 `INSN_reg16_BC: registers[`REG_B] <= rdata;
665 `INSN_reg16_DE: registers[`REG_D] <= rdata;
666 `INSN_reg16_HL: registers[`REG_H] <= rdata;
667 `INSN_reg16_SP: registers[`REG_SPH] <= rdata;
672 `INSN_LD_SP_HL: begin
674 0: registers[`REG_SPH] <= tmp;
675 1: registers[`REG_SPL] <= tmp;
678 `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */
680 0: {registers[`REG_SPH],registers[`REG_SPL]} <=
681 {registers[`REG_SPH],registers[`REG_SPL]} - 1;
682 1: {registers[`REG_SPH],registers[`REG_SPL]} <=
683 {registers[`REG_SPH],registers[`REG_SPL]} - 1;
684 2: begin /* type F */ end
685 3: begin /* type F */ end
688 `INSN_POP_reg: begin /* POP is 12 cycles! */
690 0: {registers[`REG_SPH],registers[`REG_SPL]} <=
691 {registers[`REG_SPH],registers[`REG_SPL]} + 1;
694 `INSN_stack_AF: registers[`REG_F] <= rdata;
695 `INSN_stack_BC: registers[`REG_C] <= rdata;
696 `INSN_stack_DE: registers[`REG_E] <= rdata;
697 `INSN_stack_HL: registers[`REG_L] <= rdata;
699 {registers[`REG_SPH],registers[`REG_SPL]} <=
700 {registers[`REG_SPH],registers[`REG_SPL]} + 1;
704 `INSN_stack_AF: registers[`REG_A] <= rdata;
705 `INSN_stack_BC: registers[`REG_B] <= rdata;
706 `INSN_stack_DE: registers[`REG_D] <= rdata;
707 `INSN_stack_HL: registers[`REG_H] <= rdata;
714 0: begin /* Type F */ end
716 registers[`REG_A] <= rdata;
721 0: begin /* Type F */ end
724 registers[`REG_A] <= rdata;
725 {registers[`REG_H],registers[`REG_L]} <=
726 opcode[4] ? // if set, LDD, else LDI
727 ({registers[`REG_H],registers[`REG_L]} - 1) :
728 ({registers[`REG_H],registers[`REG_L]} + 1);
733 if ((opcode[2:0] == `INSN_reg_dHL) && (cycle == 0)) begin
734 /* Sit on our asses. */
735 end else begin /* Actually do the computation! */
739 registers[`REG_A] + tmp;
741 { /* Z */ ((registers[`REG_A] + tmp) == 0) ? 1'b1 : 1'b0,
743 /* H */ (({1'b0,registers[`REG_A][3:0]} + {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
744 /* C */ (({1'b0,registers[`REG_A]} + {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
745 registers[`REG_F][3:0]
750 registers[`REG_A] + tmp + {7'b0,registers[`REG_F][4]};
752 { /* Z */ ((registers[`REG_A] + tmp + {7'b0,registers[`REG_F][4]}) == 0) ? 1'b1 : 1'b0,
754 /* H */ (({1'b0,registers[`REG_A][3:0]} + {1'b0,tmp[3:0]} + {4'b0,registers[`REG_F][4]}) >> 4 == 1) ? 1'b1 : 1'b0,
755 /* C */ (({1'b0,registers[`REG_A]} + {1'b0,tmp} + {8'b0,registers[`REG_F][4]}) >> 8 == 1) ? 1'b1 : 1'b0,
756 registers[`REG_F][3:0]
761 registers[`REG_A] - tmp;
763 { /* Z */ ((registers[`REG_A] - tmp) == 0) ? 1'b1 : 1'b0,
765 /* H */ (({1'b0,registers[`REG_A][3:0]} - {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
766 /* C */ (({1'b0,registers[`REG_A]} - {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
767 registers[`REG_F][3:0]
772 registers[`REG_A] - (tmp + {7'b0,registers[`REG_F][4]});
774 { /* Z */ ((registers[`REG_A] - (tmp + {7'b0,registers[`REG_F][4]})) == 0) ? 1'b1 : 1'b0,
776 /* H */ (({1'b0,registers[`REG_A][3:0]} - ({1'b0,tmp[3:0]} + {4'b0,registers[`REG_F][4]})) >> 4 == 1) ? 1'b1 : 1'b0,
777 /* C */ (({1'b0,registers[`REG_A]} - ({1'b0,tmp} + {8'b0,registers[`REG_F][4]})) >> 8 == 1) ? 1'b1 : 1'b0,
778 registers[`REG_F][3:0]
783 registers[`REG_A] & tmp;
785 { /* Z */ ((registers[`REG_A] & tmp) == 0) ? 1'b1 : 1'b0,
787 registers[`REG_F][3:0]
792 registers[`REG_A] | tmp;
794 { /* Z */ ((registers[`REG_A] | tmp) == 0) ? 1'b1 : 1'b0,
796 registers[`REG_F][3:0]
801 registers[`REG_A] ^ tmp;
803 { /* Z */ ((registers[`REG_A] ^ tmp) == 0) ? 1'b1 : 1'b0,
805 registers[`REG_F][3:0]
810 { /* Z */ ((registers[`REG_A] - tmp) == 0) ? 1'b1 : 1'b0,
812 /* H */ (({1'b0,registers[`REG_A][3:0]} - {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
813 /* C */ (({1'b0,registers[`REG_A]} - {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
814 registers[`REG_F][3:0]
824 `INSN_alu_RLCA: begin
825 registers[`REG_A] <= {registers[`REG_A][6:0],registers[`REG_A][7]};
826 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][7],registers[`REG_F][3:0]};
828 `INSN_alu_RRCA: begin
829 registers[`REG_A] <= {registers[`REG_A][0],registers[`REG_A][7:1]};
830 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][0],registers[`REG_F][3:0]};
833 registers[`REG_A] <= {registers[`REG_A][6:0],registers[`REG_F][4]};
834 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][7],registers[`REG_F][3:0]};
837 registers[`REG_A] <= {registers[`REG_A][4],registers[`REG_A][7:1]};
838 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][0],registers[`REG_F][3:0]};
841 registers[`REG_A] <= ~registers[`REG_A];
842 registers[`REG_F] <= {registers[`REG_F][7],1'b1,1'b1,registers[`REG_F][4:0]};
845 registers[`REG_F] <= {registers[`REG_F][7:5],1,registers[`REG_F][3:0]};
848 registers[`REG_F] <= {registers[`REG_F][7:5],~registers[`REG_F][4],registers[`REG_F][3:0]};
852 `INSN_NOP: begin /* NOP! */ end
855 0: begin /* type F */ end
856 1: begin /* type F */ end
857 2: begin /* type F */ end
858 3: {registers[`REG_SPH],registers[`REG_SPL]} <=
859 {registers[`REG_SPH],registers[`REG_SPL]}-2;
862 `INSN_RET,`INSN_RETCC: begin
864 0: if (opcode[0]) // i.e., not RETCC
865 cycle <= 1; // Skip cycle 1; it gets incremented on the next round.
866 1: begin /* Nothing need happen here. */ end
867 2: registers[`REG_PCL] <= rdata;
868 3: registers[`REG_PCH] <= rdata;
870 {registers[`REG_SPH],registers[`REG_SPL]} <=
871 {registers[`REG_SPH],registers[`REG_SPL]} + 2;
872 if (opcode[4] && opcode[0]) /* RETI */
877 `INSN_CALL,`INSN_CALLCC: begin
879 0: begin /* type F */ end
880 1: tmp <= rdata; // tmp contains newpcl
881 2: tmp2 <= rdata; // tmp2 contains newpch
882 3: begin /* type F */ end
883 4: registers[`REG_PCH] <= tmp2;
885 {registers[`REG_SPH],registers[`REG_SPL]} <=
886 {registers[`REG_SPH],registers[`REG_SPL]} - 2;
887 registers[`REG_PCL] <= tmp;
891 `INSN_JP_imm,`INSN_JPCC_imm: begin
893 0: begin /* type F */ end
894 1: tmp <= rdata; // tmp contains newpcl
895 2: tmp2 <= rdata; // tmp2 contains newpch
896 3: {registers[`REG_PCH],registers[`REG_PCL]} <=
901 {registers[`REG_PCH],registers[`REG_PCL]} <=
902 {registers[`REG_H],registers[`REG_L]};
904 `INSN_JR_imm,`INSN_JRCC_imm: begin
906 0: begin /* type F */ end
908 2: {registers[`REG_PCH],registers[`REG_PCL]} <=
909 {registers[`REG_PCH],registers[`REG_PCL]} +
910 {tmp[7]?8'hFF:8'h00,tmp};
913 `INSN_INCDEC16: begin
915 0: {tmp,tmp2} <= {tmp,tmp2} +
916 (opcode[3] ? 16'hFFFF : 16'h0001);
919 `INSN_reg16_BC: begin
920 registers[`REG_B] <= tmp;
921 registers[`REG_C] <= tmp2;
923 `INSN_reg16_DE: begin
924 registers[`REG_D] <= tmp;
925 registers[`REG_E] <= tmp2;
927 `INSN_reg16_HL: begin
928 registers[`REG_H] <= tmp;
929 registers[`REG_L] <= tmp2;
931 `INSN_reg16_SP: begin
932 registers[`REG_SPH] <= tmp;
933 registers[`REG_SPL] <= tmp2;
939 `INSN_VOP_INTR: begin
942 1: {registers[`REG_SPH],registers[`REG_SPL]}
943 <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
946 {registers[`REG_PCH],registers[`REG_PCL]} <=
952 `INSN_EI: iedelay <= 1;
956 state <= `STATE_FETCH;