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
50 `define INSN_cc_NZ 2'b00
51 `define INSN_cc_Z 2'b01
52 `define INSN_cc_NC 2'b10
53 `define INSN_cc_C 2'b11
55 `define INSN_reg_A 3'b111
56 `define INSN_reg_B 3'b000
57 `define INSN_reg_C 3'b001
58 `define INSN_reg_D 3'b010
59 `define INSN_reg_E 3'b011
60 `define INSN_reg_H 3'b100
61 `define INSN_reg_L 3'b101
62 `define INSN_reg_dHL 3'b110
63 `define INSN_reg16_BC 2'b00
64 `define INSN_reg16_DE 2'b01
65 `define INSN_reg16_HL 2'b10
66 `define INSN_reg16_SP 2'b11
67 `define INSN_stack_AF 2'b11
68 `define INSN_stack_BC 2'b00
69 `define INSN_stack_DE 2'b01
70 `define INSN_stack_HL 2'b10
71 `define INSN_alu_ADD 3'b000
72 `define INSN_alu_ADC 3'b001
73 `define INSN_alu_SUB 3'b010
74 `define INSN_alu_SBC 3'b011
75 `define INSN_alu_AND 3'b100
76 `define INSN_alu_XOR 3'b101
77 `define INSN_alu_OR 3'b110
78 `define INSN_alu_CP 3'b111 // Oh lawd, is dat some CP?
79 `define INSN_alu_RLCA 3'b000
80 `define INSN_alu_RRCA 3'b001
81 `define INSN_alu_RLA 3'b010
82 `define INSN_alu_RRA 3'b011
83 `define INSN_alu_DAA 3'b100
84 `define INSN_alu_CPL 3'b101
85 `define INSN_alu_SCF 3'b110
86 `define INSN_alu_CCF 3'b111
90 output reg [15:0] busaddress, /* BUS_* is latched on STATE_FETCH. */
92 output reg buswr, output reg busrd);
94 reg [1:0] state = 0; /* State within this bus cycle (see STATE_*). */
95 reg [2:0] cycle = 0; /* Cycle for instructions. */
97 reg [7:0] registers[11:0];
99 reg [15:0] address; /* Address for the next bus operation. */
101 reg [7:0] opcode; /* Opcode from the current machine cycle. */
103 reg [7:0] rdata, wdata; /* Read data from this bus cycle, or write data for the next. */
104 reg rd = 1, wr = 0, newcycle = 1;
106 reg [7:0] tmp, tmp2; /* Generic temporary regs. */
109 assign busdata = buswr ? buswdata : 8'bzzzzzzzz;
134 always @(posedge clk)
138 busaddress <= {registers[`REG_PCH], registers[`REG_PCL]};
142 busaddress <= address;
148 state <= `STATE_DECODE;
157 if (rd) rdata <= busdata;
164 address <= 16'bxxxxxxxxxxxxxxxx; // Make it obvious if something of type has happened.
165 wdata <= 8'bxxxxxxxx;
166 state <= `STATE_EXECUTE;
168 `STATE_EXECUTE: begin
169 `define EXEC_INC_PC \
170 {registers[`REG_PCH], registers[`REG_PCL]} <= {registers[`REG_PCH], registers[`REG_PCL]} + 1
171 `define EXEC_NEXTADDR_PCINC \
172 address <= {registers[`REG_PCH], registers[`REG_PCL]} + 1
173 `define EXEC_NEWCYCLE \
174 newcycle <= 1; rd <= 1; wr <= 0
176 `INSN_LD_reg_imm8: begin
180 `EXEC_NEXTADDR_PCINC;
185 if (opcode[5:3] == `INSN_reg_dHL) begin
186 address <= {registers[`REG_H], registers[`REG_L]};
201 /* XXX Interrupts needed for HALT. */
203 `INSN_LD_HL_reg: begin
207 `INSN_reg_A: wdata <= registers[`REG_A];
208 `INSN_reg_B: wdata <= registers[`REG_B];
209 `INSN_reg_C: wdata <= registers[`REG_C];
210 `INSN_reg_D: wdata <= registers[`REG_D];
211 `INSN_reg_E: wdata <= registers[`REG_E];
212 `INSN_reg_H: wdata <= registers[`REG_H];
213 `INSN_reg_L: wdata <= registers[`REG_L];
215 address <= {registers[`REG_H], registers[`REG_L]};
224 `INSN_LD_reg_HL: begin
227 address <= {registers[`REG_H], registers[`REG_L]};
237 `INSN_LD_reg_reg: begin
241 `INSN_reg_A: tmp <= registers[`REG_A];
242 `INSN_reg_B: tmp <= registers[`REG_B];
243 `INSN_reg_C: tmp <= registers[`REG_C];
244 `INSN_reg_D: tmp <= registers[`REG_D];
245 `INSN_reg_E: tmp <= registers[`REG_E];
246 `INSN_reg_H: tmp <= registers[`REG_H];
247 `INSN_reg_L: tmp <= registers[`REG_L];
250 `INSN_LD_reg_imm16: begin
254 `EXEC_NEXTADDR_PCINC;
258 `EXEC_NEXTADDR_PCINC;
261 2: begin `EXEC_NEWCYCLE; end
264 `INSN_LD_SP_HL: begin
267 tmp <= registers[`REG_H];
272 tmp <= registers[`REG_L];
276 `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */
280 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
282 `INSN_stack_AF: wdata <= registers[`REG_A];
283 `INSN_stack_BC: wdata <= registers[`REG_B];
284 `INSN_stack_DE: wdata <= registers[`REG_D];
285 `INSN_stack_HL: wdata <= registers[`REG_H];
290 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
292 `INSN_stack_AF: wdata <= registers[`REG_F];
293 `INSN_stack_BC: wdata <= registers[`REG_C];
294 `INSN_stack_DE: wdata <= registers[`REG_E];
295 `INSN_stack_HL: wdata <= registers[`REG_L];
298 2: begin /* Twiddle thumbs. */ end
305 `INSN_POP_reg: begin /* POP is 12 cycles! */
309 address <= {registers[`REG_SPH],registers[`REG_SPL]};
313 address <= {registers[`REG_SPH],registers[`REG_SPL]};
324 address <= {8'hFF,registers[`REG_C]};
325 if (opcode[4]) begin // LD A,(C)
329 wdata <= registers[`REG_A];
341 address <= {registers[`REG_H],registers[`REG_L]};
342 if (opcode[3]) begin // LDx A, (HL)
346 wdata <= registers[`REG_A];
356 if ((opcode[2:0] == `INSN_reg_dHL) && (cycle == 0)) begin
357 // fffffffff fuck your shit, read from (HL) :(
359 address <= {registers[`REG_H], registers[`REG_L]};
364 `INSN_reg_A: tmp <= registers[`REG_A];
365 `INSN_reg_B: tmp <= registers[`REG_B];
366 `INSN_reg_C: tmp <= registers[`REG_C];
367 `INSN_reg_D: tmp <= registers[`REG_D];
368 `INSN_reg_E: tmp <= registers[`REG_E];
369 `INSN_reg_H: tmp <= registers[`REG_H];
370 `INSN_reg_L: tmp <= registers[`REG_L];
371 `INSN_reg_dHL: tmp <= rdata;
386 `EXEC_INC_PC; // This goes FIRST in RST
390 address <= {registers[`REG_SPH],registers[`REG_SPL]}-1;
391 wdata <= registers[`REG_PCH];
395 address <= {registers[`REG_SPH],registers[`REG_SPL]}-2;
396 wdata <= registers[`REG_PCL];
400 {registers[`REG_PCH],registers[`REG_PCL]} <=
401 {10'b0,opcode[5:3],3'b0};
405 `INSN_RET,`INSN_RETCC: begin
409 address <= {registers[`REG_SPH],registers[`REG_SPL]};
411 1: begin // SPECIAL CASE: cycle does NOT increase linearly with ret!
412 `EXEC_INC_PC; // cycle 1 is skipped if we are not retcc
414 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
415 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
416 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
417 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
420 address <= {registers[`REG_SPH],registers[`REG_SPL]};
424 address <= {registers[`REG_SPH],registers[`REG_SPL]} + 1;
426 3: begin /* twiddle thumbs */ end
429 // do NOT increment PC!
433 `INSN_CALL,`INSN_CALLCC: begin
437 `EXEC_NEXTADDR_PCINC;
442 `EXEC_NEXTADDR_PCINC;
447 if (!opcode[0]) // i.e., is callcc
448 /* We need to check the condition code to bail out. */
450 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
451 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
452 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
453 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
457 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 1;
458 wdata <= registers[`REG_PCH];
462 address <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
463 wdata <= registers[`REG_PCL];
467 `EXEC_NEWCYCLE; /* do NOT increment the PC */
471 `INSN_JP_imm,`INSN_JPCC_imm: begin
475 `EXEC_NEXTADDR_PCINC;
480 `EXEC_NEXTADDR_PCINC;
485 if (!opcode[0]) begin // i.e., JP cc,nn
486 /* We need to check the condition code to bail out. */
488 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
489 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
490 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
491 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
503 `INSN_JR_imm,`INSN_JRCC_imm: begin
507 `EXEC_NEXTADDR_PCINC;
512 if (opcode[5]) begin // i.e., JP cc,nn
513 /* We need to check the condition code to bail out. */
515 `INSN_cc_NZ: if (registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
516 `INSN_cc_Z: if (~registers[`REG_F][7]) begin `EXEC_NEWCYCLE; end
517 `INSN_cc_NC: if (registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
518 `INSN_cc_C: if (~registers[`REG_F][4]) begin `EXEC_NEWCYCLE; end
527 `INSN_INCDEC16: begin
531 `INSN_reg16_BC: begin
532 tmp <= registers[`REG_B];
533 tmp2 <= registers[`REG_C];
535 `INSN_reg16_DE: begin
536 tmp <= registers[`REG_D];
537 tmp2 <= registers[`REG_E];
539 `INSN_reg16_HL: begin
540 tmp <= registers[`REG_H];
541 tmp2 <= registers[`REG_L];
543 `INSN_reg16_SP: begin
544 tmp <= registers[`REG_SPH];
545 tmp2 <= registers[`REG_SPL];
558 state <= `STATE_WRITEBACK;
560 `STATE_WRITEBACK: begin
565 1: case (opcode[5:3])
566 `INSN_reg_A: begin registers[`REG_A] <= rdata; end
567 `INSN_reg_B: begin registers[`REG_B] <= rdata; end
568 `INSN_reg_C: begin registers[`REG_C] <= rdata; end
569 `INSN_reg_D: begin registers[`REG_D] <= rdata; end
570 `INSN_reg_E: begin registers[`REG_E] <= rdata; end
571 `INSN_reg_H: begin registers[`REG_H] <= rdata; end
572 `INSN_reg_L: begin registers[`REG_L] <= rdata; end
573 `INSN_reg_dHL: begin /* Go off to cycle 2 */ end
578 /* Nothing needs happen here. */
579 /* XXX Interrupts needed for HALT. */
581 `INSN_LD_HL_reg: begin
582 /* Nothing of interest here */
584 `INSN_LD_reg_HL: begin
589 `INSN_reg_A: registers[`REG_A] <= tmp;
590 `INSN_reg_B: registers[`REG_B] <= tmp;
591 `INSN_reg_C: registers[`REG_C] <= tmp;
592 `INSN_reg_D: registers[`REG_D] <= tmp;
593 `INSN_reg_E: registers[`REG_E] <= tmp;
594 `INSN_reg_H: registers[`REG_H] <= tmp;
595 `INSN_reg_L: registers[`REG_L] <= tmp;
600 `INSN_LD_reg_reg: begin
602 `INSN_reg_A: registers[`REG_A] <= tmp;
603 `INSN_reg_B: registers[`REG_B] <= tmp;
604 `INSN_reg_C: registers[`REG_C] <= tmp;
605 `INSN_reg_D: registers[`REG_D] <= tmp;
606 `INSN_reg_E: registers[`REG_E] <= tmp;
607 `INSN_reg_H: registers[`REG_H] <= tmp;
608 `INSN_reg_L: registers[`REG_L] <= tmp;
611 `INSN_LD_reg_imm16: begin
616 `INSN_reg16_BC: registers[`REG_C] <= rdata;
617 `INSN_reg16_DE: registers[`REG_E] <= rdata;
618 `INSN_reg16_HL: registers[`REG_L] <= rdata;
619 `INSN_reg16_SP: registers[`REG_SPL] <= rdata;
624 `INSN_reg16_BC: registers[`REG_B] <= rdata;
625 `INSN_reg16_DE: registers[`REG_D] <= rdata;
626 `INSN_reg16_HL: registers[`REG_H] <= rdata;
627 `INSN_reg16_SP: registers[`REG_SPH] <= rdata;
632 `INSN_LD_SP_HL: begin
634 0: registers[`REG_SPH] <= tmp;
635 1: registers[`REG_SPL] <= tmp;
638 `INSN_PUSH_reg: begin /* PUSH is 16 cycles! */
640 0: {registers[`REG_SPH],registers[`REG_SPL]} <=
641 {registers[`REG_SPH],registers[`REG_SPL]} - 1;
642 1: {registers[`REG_SPH],registers[`REG_SPL]} <=
643 {registers[`REG_SPH],registers[`REG_SPL]} - 1;
644 2: begin /* type F */ end
645 3: begin /* type F */ end
648 `INSN_POP_reg: begin /* POP is 12 cycles! */
650 0: {registers[`REG_SPH],registers[`REG_SPL]} <=
651 {registers[`REG_SPH],registers[`REG_SPL]} + 1;
654 `INSN_stack_AF: registers[`REG_F] <= rdata;
655 `INSN_stack_BC: registers[`REG_C] <= rdata;
656 `INSN_stack_DE: registers[`REG_E] <= rdata;
657 `INSN_stack_HL: registers[`REG_L] <= rdata;
659 {registers[`REG_SPH],registers[`REG_SPL]} <=
660 {registers[`REG_SPH],registers[`REG_SPL]} + 1;
664 `INSN_stack_AF: registers[`REG_A] <= rdata;
665 `INSN_stack_BC: registers[`REG_B] <= rdata;
666 `INSN_stack_DE: registers[`REG_D] <= rdata;
667 `INSN_stack_HL: registers[`REG_H] <= rdata;
674 0: begin /* Type F */ end
676 registers[`REG_A] <= rdata;
681 0: begin /* Type F */ end
684 registers[`REG_A] <= rdata;
685 {registers[`REG_H],registers[`REG_L]} <=
686 opcode[4] ? // if set, LDD, else LDI
687 ({registers[`REG_H],registers[`REG_L]} - 1) :
688 ({registers[`REG_H],registers[`REG_L]} + 1);
693 if ((opcode[2:0] == `INSN_reg_dHL) && (cycle == 0)) begin
694 /* Sit on our asses. */
695 end else begin /* Actually do the computation! */
699 registers[`REG_A] + tmp;
701 { /* Z */ ((registers[`REG_A] + tmp) == 0) ? 1'b1 : 1'b0,
703 /* H */ (({1'b0,registers[`REG_A][3:0]} + {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
704 /* C */ (({1'b0,registers[`REG_A]} + {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
705 registers[`REG_F][3:0]
710 registers[`REG_A] + tmp + {7'b0,registers[`REG_F][4]};
712 { /* Z */ ((registers[`REG_A] + tmp + {7'b0,registers[`REG_F][4]}) == 0) ? 1'b1 : 1'b0,
714 /* 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,
715 /* C */ (({1'b0,registers[`REG_A]} + {1'b0,tmp} + {8'b0,registers[`REG_F][4]}) >> 8 == 1) ? 1'b1 : 1'b0,
716 registers[`REG_F][3:0]
721 registers[`REG_A] - tmp;
723 { /* Z */ ((registers[`REG_A] - tmp) == 0) ? 1'b1 : 1'b0,
725 /* H */ (({1'b0,registers[`REG_A][3:0]} - {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
726 /* C */ (({1'b0,registers[`REG_A]} - {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
727 registers[`REG_F][3:0]
732 registers[`REG_A] - (tmp + {7'b0,registers[`REG_F][4]});
734 { /* Z */ ((registers[`REG_A] - (tmp + {7'b0,registers[`REG_F][4]})) == 0) ? 1'b1 : 1'b0,
736 /* 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,
737 /* C */ (({1'b0,registers[`REG_A]} - ({1'b0,tmp} + {8'b0,registers[`REG_F][4]})) >> 8 == 1) ? 1'b1 : 1'b0,
738 registers[`REG_F][3:0]
743 registers[`REG_A] & tmp;
745 { /* Z */ ((registers[`REG_A] & tmp) == 0) ? 1'b1 : 1'b0,
747 registers[`REG_F][3:0]
752 registers[`REG_A] | tmp;
754 { /* Z */ ((registers[`REG_A] | tmp) == 0) ? 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 registers[`REG_F][3:0]
770 { /* Z */ ((registers[`REG_A] - tmp) == 0) ? 1'b1 : 1'b0,
772 /* H */ (({1'b0,registers[`REG_A][3:0]} - {1'b0,tmp[3:0]}) >> 4 == 1) ? 1'b1 : 1'b0,
773 /* C */ (({1'b0,registers[`REG_A]} - {1'b0,tmp}) >> 8 == 1) ? 1'b1 : 1'b0,
774 registers[`REG_F][3:0]
784 `INSN_alu_RLCA: begin
785 registers[`REG_A] <= {registers[`REG_A][6:0],registers[`REG_A][7]};
786 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][7],registers[`REG_F][3:0]};
788 `INSN_alu_RRCA: begin
789 registers[`REG_A] <= {registers[`REG_A][0],registers[`REG_A][7:1]};
790 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][0],registers[`REG_F][3:0]};
793 registers[`REG_A] <= {registers[`REG_A][6:0],registers[`REG_F][4]};
794 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][7],registers[`REG_F][3:0]};
797 registers[`REG_A] <= {registers[`REG_A][4],registers[`REG_A][7:1]};
798 registers[`REG_F] <= {registers[`REG_F][7:5],registers[`REG_A][0],registers[`REG_F][3:0]};
801 registers[`REG_A] <= ~registers[`REG_A];
802 registers[`REG_F] <= {registers[`REG_F][7],1'b1,1'b1,registers[`REG_F][4:0]};
805 registers[`REG_F] <= {registers[`REG_F][7:5],1,registers[`REG_F][3:0]};
808 registers[`REG_F] <= {registers[`REG_F][7:5],~registers[`REG_F][4],registers[`REG_F][3:0]};
812 `INSN_NOP: begin /* NOP! */ end
815 0: begin /* type F */ end
816 1: begin /* type F */ end
817 2: begin /* type F */ end
818 3: {registers[`REG_SPH],registers[`REG_SPL]} <=
819 {registers[`REG_SPH],registers[`REG_SPL]}-2;
822 `INSN_RET,`INSN_RETCC: begin
824 0: if (opcode[0]) // i.e., not RETCC
825 cycle <= 1; // Skip cycle 1; it gets incremented on the next round.
826 1: begin /* Nothing need happen here. */ end
827 2: registers[`REG_PCL] <= rdata;
828 3: registers[`REG_PCH] <= rdata;
830 {registers[`REG_SPH],registers[`REG_SPL]} <=
831 {registers[`REG_SPH],registers[`REG_SPL]} + 2;
832 if (opcode[4] && opcode[0]) /* RETI */
837 `INSN_CALL,`INSN_CALLCC: begin
839 0: begin /* type F */ end
840 1: tmp <= rdata; // tmp contains newpcl
841 2: tmp2 <= rdata; // tmp2 contains newpch
842 3: begin /* type F */ end
843 4: registers[`REG_PCH] <= tmp2;
845 {registers[`REG_SPH],registers[`REG_SPL]} <=
846 {registers[`REG_SPH],registers[`REG_SPL]} - 2;
847 registers[`REG_PCL] <= tmp;
851 `INSN_JP_imm,`INSN_JPCC_imm: begin
853 0: begin /* type F */ end
854 1: tmp <= rdata; // tmp contains newpcl
855 2: tmp2 <= rdata; // tmp2 contains newpch
856 3: {registers[`REG_PCH],registers[`REG_PCL]} <=
861 {registers[`REG_PCH],registers[`REG_PCL]} <=
862 {registers[`REG_H],registers[`REG_L]};
864 `INSN_JR_imm,`INSN_JRCC_imm: begin
866 0: begin /* type F */ end
868 2: {registers[`REG_PCH],registers[`REG_PCL]} <=
869 {registers[`REG_PCH],registers[`REG_PCL]} +
870 {tmp[7]?8'hFF:8'h00,tmp};
873 `INSN_INCDEC16: begin
875 0: {tmp,tmp2} <= {tmp,tmp2} +
876 (opcode[3] ? 16'hFFFF : 16'h0001);
879 `INSN_reg16_BC: begin
880 registers[`REG_B] <= tmp;
881 registers[`REG_C] <= tmp2;
883 `INSN_reg16_DE: begin
884 registers[`REG_D] <= tmp;
885 registers[`REG_E] <= tmp2;
887 `INSN_reg16_HL: begin
888 registers[`REG_H] <= tmp;
889 registers[`REG_L] <= tmp2;
891 `INSN_reg16_SP: begin
892 registers[`REG_SPH] <= tmp;
893 registers[`REG_SPL] <= tmp2;
902 state <= `STATE_FETCH;