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; /* State within this bus cycle (see STATE_*). */
99 reg [2:0] cycle; /* 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, wr, newcycle;
110 reg [7:0] tmp, tmp2; /* Generic temporary regs. */
113 assign busdata = buswr ? buswdata : 8'bzzzzzzzz;
115 reg ie = 0, iedelay = 0;
141 state <= `STATE_WRITEBACK;
145 always @(posedge clk)
149 busaddress <= {registers[`REG_PCH], registers[`REG_PCL]};
153 busaddress <= address;
159 state <= `STATE_DECODE;
164 opcode <= `INSN_VOP_INTR;
171 if (rd) rdata <= busdata;
182 address <= 16'bxxxxxxxxxxxxxxxx; // Make it obvious if something of type has happened.
183 wdata <= 8'bxxxxxxxx;
184 state <= `STATE_EXECUTE;
186 `STATE_EXECUTE: begin
187 `define EXEC_INC_PC \
188 {registers[`REG_PCH], registers[`REG_PCL]} <= {registers[`REG_PCH], registers[`REG_PCL]} + 1
189 `define EXEC_NEXTADDR_PCINC \
190 address <= {registers[`REG_PCH], registers[`REG_PCL]} + 1
191 `define EXEC_NEWCYCLE \
192 newcycle <= 1; rd <= 1; wr <= 0
194 `INSN_LD_reg_imm8: begin
198 `EXEC_NEXTADDR_PCINC;
203 if (opcode[5:3] == `INSN_reg_dHL) begin
204 address <= {registers[`REG_H], registers[`REG_L]};
219 /* XXX Interrupts needed for HALT. */
221 `INSN_LD_HL_reg: begin
225 `INSN_reg_A: wdata <= registers[`REG_A];
226 `INSN_reg_B: wdata <= registers[`REG_B];
227 `INSN_reg_C: wdata <= registers[`REG_C];
228 `INSN_reg_D: wdata <= registers[`REG_D];
229 `INSN_reg_E: wdata <= registers[`REG_E];
230 `INSN_reg_H: wdata <= registers[`REG_H];
231 `INSN_reg_L: wdata <= registers[`REG_L];
233 address <= {registers[`REG_H], registers[`REG_L]};
242 `INSN_LD_reg_HL: begin
245 address <= {registers[`REG_H], registers[`REG_L]};
255 `INSN_LD_reg_reg: begin
259 `INSN_reg_A: tmp <= registers[`REG_A];
260 `INSN_reg_B: tmp <= registers[`REG_B];
261 `INSN_reg_C: tmp <= registers[`REG_C];
262 `INSN_reg_D: tmp <= registers[`REG_D];
263 `INSN_reg_E: tmp <= registers[`REG_E];
264 `INSN_reg_H: tmp <= registers[`REG_H];
265 `INSN_reg_L: tmp <= registers[`REG_L];
268 `INSN_LD_reg_imm16: begin
272 `EXEC_NEXTADDR_PCINC;
276 `EXEC_NEXTADDR_PCINC;
279 2: begin `EXEC_NEWCYCLE; end
282 `INSN_LD_SP_HL: begin
285 tmp <= registers[`REG_H];
290 tmp <= registers[`REG_L];
294 `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */
298 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
300 `INSN_stack_AF: wdata <= registers[`REG_A];
301 `INSN_stack_BC: wdata <= registers[`REG_B];
302 `INSN_stack_DE: wdata <= registers[`REG_D];
303 `INSN_stack_HL: wdata <= registers[`REG_H];
308 address <= {registers[`REG_SPH],registers[`REG_SPL]}-2;
310 `INSN_stack_AF: wdata <= registers[`REG_F];
311 `INSN_stack_BC: wdata <= registers[`REG_C];
312 `INSN_stack_DE: wdata <= registers[`REG_E];
313 `INSN_stack_HL: wdata <= registers[`REG_L];
316 2: begin /* Twiddle thumbs. */ end
323 `INSN_POP_reg: begin /* POP is 12 cycles! */
327 address <= {registers[`REG_SPH],registers[`REG_SPL]};
331 address <= {registers[`REG_SPH],registers[`REG_SPL]} + 1;
342 address <= {8'hFF,registers[`REG_C]};
343 if (opcode[4]) begin // LD A,(C)
347 wdata <= registers[`REG_A];
359 address <= {registers[`REG_H],registers[`REG_L]};
360 if (opcode[3]) begin // LDx A, (HL)
364 wdata <= registers[`REG_A];
374 if ((opcode[2:0] == `INSN_reg_dHL) && (cycle == 0)) begin
375 // fffffffff fuck your shit, read from (HL) :(
377 address <= {registers[`REG_H], registers[`REG_L]};
382 `INSN_reg_A: tmp <= registers[`REG_A];
383 `INSN_reg_B: tmp <= registers[`REG_B];
384 `INSN_reg_C: tmp <= registers[`REG_C];
385 `INSN_reg_D: tmp <= registers[`REG_D];
386 `INSN_reg_E: tmp <= registers[`REG_E];
387 `INSN_reg_H: tmp <= registers[`REG_H];
388 `INSN_reg_L: tmp <= registers[`REG_L];
389 `INSN_reg_dHL: tmp <= rdata;
404 `EXEC_INC_PC; // This goes FIRST in RST
408 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
409 wdata <= registers[`REG_PCH];
413 address <= {registers[`REG_SPH],registers[`REG_SPL]}-2;
414 wdata <= registers[`REG_PCL];
418 {registers[`REG_PCH],registers[`REG_PCL]} <=
419 {10'b0,opcode[5:3],3'b0};
423 `INSN_RET,`INSN_RETCC: begin
427 address <= {registers[`REG_SPH],registers[`REG_SPL]};
429 1: begin // SPECIAL CASE: cycle does NOT increase linearly with ret!
430 `EXEC_INC_PC; // cycle 1 is skipped if we are not retcc
432 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
433 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
434 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
435 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
438 address <= {registers[`REG_SPH],registers[`REG_SPL]};
442 address <= {registers[`REG_SPH],registers[`REG_SPL]} + 1;
444 3: begin /* twiddle thumbs */ end
447 // do NOT increment PC!
451 `INSN_CALL,`INSN_CALLCC: begin
455 `EXEC_NEXTADDR_PCINC;
460 `EXEC_NEXTADDR_PCINC;
465 if (!opcode[0]) // i.e., is callcc
466 /* We need to check the condition code to bail out. */
468 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
469 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
470 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
471 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
475 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 1;
476 wdata <= registers[`REG_PCH];
480 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
481 wdata <= registers[`REG_PCL];
485 `EXEC_NEWCYCLE; /* do NOT increment the PC */
489 `INSN_JP_imm,`INSN_JPCC_imm: begin
493 `EXEC_NEXTADDR_PCINC;
498 `EXEC_NEXTADDR_PCINC;
503 if (!opcode[0]) begin // i.e., JP cc,nn
504 /* We need to check the condition code to bail out. */
506 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
507 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
508 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
509 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
521 `INSN_JR_imm,`INSN_JRCC_imm: begin
525 `EXEC_NEXTADDR_PCINC;
530 if (opcode[5]) begin // i.e., JP cc,nn
531 /* We need to check the condition code to bail out. */
533 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
534 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
535 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
536 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
545 `INSN_INCDEC16: begin
549 `INSN_reg16_BC: begin
550 tmp <= registers[`REG_B];
551 tmp2 <= registers[`REG_C];
553 `INSN_reg16_DE: begin
554 tmp <= registers[`REG_D];
555 tmp2 <= registers[`REG_E];
557 `INSN_reg16_HL: begin
558 tmp <= registers[`REG_H];
559 tmp2 <= registers[`REG_L];
561 `INSN_reg16_SP: begin
562 tmp <= registers[`REG_SPH];
563 tmp2 <= registers[`REG_SPL];
573 `INSN_VOP_INTR: begin
576 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 1;
577 wdata <= registers[`REG_PCH];
581 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
582 wdata <= registers[`REG_PCL];
601 state <= `STATE_WRITEBACK;
603 `STATE_WRITEBACK: begin
608 1: case (opcode[5:3])
609 `INSN_reg_A: begin registers[`REG_A] <= rdata; end
610 `INSN_reg_B: begin registers[`REG_B] <= rdata; end
611 `INSN_reg_C: begin registers[`REG_C] <= rdata; end
612 `INSN_reg_D: begin registers[`REG_D] <= rdata; end
613 `INSN_reg_E: begin registers[`REG_E] <= rdata; end
614 `INSN_reg_H: begin registers[`REG_H] <= rdata; end
615 `INSN_reg_L: begin registers[`REG_L] <= rdata; end
616 `INSN_reg_dHL: begin /* Go off to cycle 2 */ end
621 /* Nothing needs happen here. */
622 /* XXX Interrupts needed for HALT. */
624 `INSN_LD_HL_reg: begin
625 /* Nothing of interest here */
627 `INSN_LD_reg_HL: begin
632 `INSN_reg_A: registers[`REG_A] <= tmp;
633 `INSN_reg_B: registers[`REG_B] <= tmp;
634 `INSN_reg_C: registers[`REG_C] <= tmp;
635 `INSN_reg_D: registers[`REG_D] <= tmp;
636 `INSN_reg_E: registers[`REG_E] <= tmp;
637 `INSN_reg_H: registers[`REG_H] <= tmp;
638 `INSN_reg_L: registers[`REG_L] <= tmp;
643 `INSN_LD_reg_reg: begin
645 `INSN_reg_A: registers[`REG_A] <= tmp;
646 `INSN_reg_B: registers[`REG_B] <= tmp;
647 `INSN_reg_C: registers[`REG_C] <= tmp;
648 `INSN_reg_D: registers[`REG_D] <= tmp;
649 `INSN_reg_E: registers[`REG_E] <= tmp;
650 `INSN_reg_H: registers[`REG_H] <= tmp;
651 `INSN_reg_L: registers[`REG_L] <= tmp;
654 `INSN_LD_reg_imm16: begin
659 `INSN_reg16_BC: registers[`REG_C] <= rdata;
660 `INSN_reg16_DE: registers[`REG_E] <= rdata;
661 `INSN_reg16_HL: registers[`REG_L] <= rdata;
662 `INSN_reg16_SP: registers[`REG_SPL] <= rdata;
667 `INSN_reg16_BC: registers[`REG_B] <= rdata;
668 `INSN_reg16_DE: registers[`REG_D] <= rdata;
669 `INSN_reg16_HL: registers[`REG_H] <= rdata;
670 `INSN_reg16_SP: registers[`REG_SPH] <= rdata;
675 `INSN_LD_SP_HL: begin
677 0: registers[`REG_SPH] <= tmp;
678 1: registers[`REG_SPL] <= tmp;
681 `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */
683 0: begin /* type F */ end
684 1: begin /* type F */ end
685 2: begin /* type F */ end
686 3: {registers[`REG_SPH],registers[`REG_SPL]} <=
687 {registers[`REG_SPH],registers[`REG_SPL]} - 2;
690 `INSN_POP_reg: begin /* POP is 12 cycles! */
695 `INSN_stack_AF: registers[`REG_F] <= rdata;
696 `INSN_stack_BC: registers[`REG_C] <= rdata;
697 `INSN_stack_DE: registers[`REG_E] <= rdata;
698 `INSN_stack_HL: registers[`REG_L] <= rdata;
703 `INSN_stack_AF: registers[`REG_A] <= rdata;
704 `INSN_stack_BC: registers[`REG_B] <= rdata;
705 `INSN_stack_DE: registers[`REG_D] <= rdata;
706 `INSN_stack_HL: registers[`REG_H] <= rdata;
708 {registers[`REG_SPH],registers[`REG_SPL]} <=
709 {registers[`REG_SPH],registers[`REG_SPL]} + 2;
715 0: begin /* Type F */ end
717 registers[`REG_A] <= rdata;
722 0: begin /* Type F */ end
725 registers[`REG_A] <= rdata;
726 {registers[`REG_H],registers[`REG_L]} <=
727 opcode[4] ? // if set, LDD, else LDI
728 ({registers[`REG_H],registers[`REG_L]} - 1) :
729 ({registers[`REG_H],registers[`REG_L]} + 1);
734 if ((opcode[2:0] == `INSN_reg_dHL) && (cycle == 0)) begin
735 /* Sit on our asses. */
736 end else begin /* Actually do the computation! */
740 registers[`REG_A] + tmp;
742 { /* Z */ ((registers[`REG_A] + tmp) == 0) ? 1'b1 : 1'b0,
744 /* H */ (({1'b0,registers[`REG_A][3:0]} + {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
745 /* C */ (({1'b0,registers[`REG_A]} + {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
746 registers[`REG_F][3:0]
751 registers[`REG_A] + tmp + {7'b0,registers[`REG_F][4]};
753 { /* Z */ ((registers[`REG_A] + tmp + {7'b0,registers[`REG_F][4]}) == 0) ? 1'b1 : 1'b0,
755 /* 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,
756 /* C */ (({1'b0,registers[`REG_A]} + {1'b0,tmp} + {8'b0,registers[`REG_F][4]}) >> 8 == 1) ? 1'b1 : 1'b0,
757 registers[`REG_F][3:0]
762 registers[`REG_A] - tmp;
764 { /* Z */ ((registers[`REG_A] - tmp) == 0) ? 1'b1 : 1'b0,
766 /* H */ (({1'b0,registers[`REG_A][3:0]} - {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
767 /* C */ (({1'b0,registers[`REG_A]} - {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
768 registers[`REG_F][3:0]
773 registers[`REG_A] - (tmp + {7'b0,registers[`REG_F][4]});
775 { /* Z */ ((registers[`REG_A] - (tmp + {7'b0,registers[`REG_F][4]})) == 0) ? 1'b1 : 1'b0,
777 /* 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,
778 /* C */ (({1'b0,registers[`REG_A]} - ({1'b0,tmp} + {8'b0,registers[`REG_F][4]})) >> 8 == 1) ? 1'b1 : 1'b0,
779 registers[`REG_F][3:0]
784 registers[`REG_A] & tmp;
786 { /* Z */ ((registers[`REG_A] & tmp) == 0) ? 1'b1 : 1'b0,
788 registers[`REG_F][3:0]
793 registers[`REG_A] | tmp;
795 { /* Z */ ((registers[`REG_A] | tmp) == 0) ? 1'b1 : 1'b0,
797 registers[`REG_F][3:0]
802 registers[`REG_A] ^ tmp;
804 { /* Z */ ((registers[`REG_A] ^ tmp) == 0) ? 1'b1 : 1'b0,
806 registers[`REG_F][3:0]
811 { /* Z */ ((registers[`REG_A] - tmp) == 0) ? 1'b1 : 1'b0,
813 /* H */ (({1'b0,registers[`REG_A][3:0]} - {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
814 /* C */ (({1'b0,registers[`REG_A]} - {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
815 registers[`REG_F][3:0]
825 `INSN_alu_RLCA: begin
826 registers[`REG_A] <= {registers[`REG_A][6:0],registers[`REG_A][7]};
827 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][7],registers[`REG_F][3:0]};
829 `INSN_alu_RRCA: begin
830 registers[`REG_A] <= {registers[`REG_A][0],registers[`REG_A][7:1]};
831 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][0],registers[`REG_F][3:0]};
834 registers[`REG_A] <= {registers[`REG_A][6:0],registers[`REG_F][4]};
835 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][7],registers[`REG_F][3:0]};
838 registers[`REG_A] <= {registers[`REG_A][4],registers[`REG_A][7:1]};
839 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][0],registers[`REG_F][3:0]};
842 registers[`REG_A] <= ~registers[`REG_A];
843 registers[`REG_F] <= {registers[`REG_F][7],1'b1,1'b1,registers[`REG_F][4:0]};
846 registers[`REG_F] <= {registers[`REG_F][7:5],1'b1,registers[`REG_F][3:0]};
849 registers[`REG_F] <= {registers[`REG_F][7:5],~registers[`REG_F][4],registers[`REG_F][3:0]};
853 `INSN_NOP: begin /* NOP! */ end
856 0: begin /* type F */ end
857 1: begin /* type F */ end
858 2: begin /* type F */ end
859 3: {registers[`REG_SPH],registers[`REG_SPL]} <=
860 {registers[`REG_SPH],registers[`REG_SPL]}-2;
863 `INSN_RET,`INSN_RETCC: begin
865 0: if (opcode[0]) // i.e., not RETCC
866 cycle <= 1; // Skip cycle 1; it gets incremented on the next round.
867 1: begin /* Nothing need happen here. */ end
868 2: registers[`REG_PCL] <= rdata;
869 3: registers[`REG_PCH] <= rdata;
871 {registers[`REG_SPH],registers[`REG_SPL]} <=
872 {registers[`REG_SPH],registers[`REG_SPL]} + 2;
873 if (opcode[4] && opcode[0]) /* RETI */
878 `INSN_CALL,`INSN_CALLCC: begin
880 0: begin /* type F */ end
881 1: tmp <= rdata; // tmp contains newpcl
882 2: tmp2 <= rdata; // tmp2 contains newpch
883 3: begin /* type F */ end
884 4: registers[`REG_PCH] <= tmp2;
886 {registers[`REG_SPH],registers[`REG_SPL]} <=
887 {registers[`REG_SPH],registers[`REG_SPL]} - 2;
888 registers[`REG_PCL] <= tmp;
892 `INSN_JP_imm,`INSN_JPCC_imm: begin
894 0: begin /* type F */ end
895 1: tmp <= rdata; // tmp contains newpcl
896 2: tmp2 <= rdata; // tmp2 contains newpch
897 3: {registers[`REG_PCH],registers[`REG_PCL]} <=
902 {registers[`REG_PCH],registers[`REG_PCL]} <=
903 {registers[`REG_H],registers[`REG_L]};
905 `INSN_JR_imm,`INSN_JRCC_imm: begin
907 0: begin /* type F */ end
909 2: {registers[`REG_PCH],registers[`REG_PCL]} <=
910 {registers[`REG_PCH],registers[`REG_PCL]} +
911 {tmp[7]?8'hFF:8'h00,tmp};
914 `INSN_INCDEC16: begin
916 0: {tmp,tmp2} <= {tmp,tmp2} +
917 (opcode[3] ? 16'hFFFF : 16'h0001);
920 `INSN_reg16_BC: begin
921 registers[`REG_B] <= tmp;
922 registers[`REG_C] <= tmp2;
924 `INSN_reg16_DE: begin
925 registers[`REG_D] <= tmp;
926 registers[`REG_E] <= tmp2;
928 `INSN_reg16_HL: begin
929 registers[`REG_H] <= tmp;
930 registers[`REG_L] <= tmp2;
932 `INSN_reg16_SP: begin
933 registers[`REG_SPH] <= tmp;
934 registers[`REG_SPL] <= tmp2;
940 `INSN_VOP_INTR: begin
946 {registers[`REG_PCH],registers[`REG_PCL]} <=
948 {registers[`REG_SPH],registers[`REG_SPL]} <=
949 {registers[`REG_SPH],registers[`REG_SPL]} - 2;
954 `INSN_EI: iedelay <= 1;
958 state <= `STATE_FETCH;