Fix bugs in SCF and CCF
[fpgaboy.git] / core / insn_alu_a.v
CommitLineData
e7fe9dc2
JW
1`define INSN_alu_RLCA 3'b000
2`define INSN_alu_RRCA 3'b001
3`define INSN_alu_RLA 3'b010
4`define INSN_alu_RRA 3'b011
5`define INSN_alu_DAA 3'b100
6`define INSN_alu_CPL 3'b101
7`define INSN_alu_SCF 3'b110
8`define INSN_alu_CCF 3'b111
9
10`define INSN_ALU_A 9'b000xxx111
11
5c834537
JW
12`ifdef LOCALWIRES
13 /* Y U Q */
14 /* Derived from MESS opc_main.h */
15 wire [8:0] daa_tmp_n0_h = ((`_F & `FLAG_H) || (`_A[3:0] > 9)) ? {1'b0,`_A} + 9'h06 : {1'b0,`_A};
16 wire [8:0] daa_tmp_n0 = ((`_F & `FLAG_C) || (daa_tmp_n0_h[8:4] > 9)) ? daa_tmp_n0_h + 9'h60 : daa_tmp_n0_h;
17
18 wire [8:0] daa_tmp_n_h1 = (`_F & `FLAG_H) ? ({1'b0,`_A} - 9'h06) : {1'b0,`_A};
19 wire [8:0] daa_tmp_n_h2 = ((`_F & `FLAG_H) && !(`_F & `FLAG_C)) ? {1'b0,daa_tmp_n_h1[7:0]} : daa_tmp_n_h1;
20 wire [8:0] daa_tmp_n = (`_F & `FLAG_C) ? (daa_tmp_n_h2 - 9'h60) : daa_tmp_n_h2;
21 wire [8:0] daa_tmp = (`_F & `FLAG_N) ? daa_tmp_n : daa_tmp_n0;
22`endif
23
3ad960bd
JW
24`ifdef EXECUTE
25 `INSN_ALU_A: begin
5c33c5c0
JW
26 `EXEC_NEWCYCLE
27 `EXEC_INC_PC
3ad960bd
JW
28 end
29`endif
30
31`ifdef WRITEBACK
32 `INSN_ALU_A: begin
33 case(opcode[5:3])
34 `INSN_alu_RLCA: begin
5c33c5c0
JW
35 `_A <= {`_A[6:0],`_A[7]};
36 `_F <= {`_F[7:5],`_A[7],`_F[3:0]};
3ad960bd
JW
37 end
38 `INSN_alu_RRCA: begin
5c33c5c0
JW
39 `_A <= {`_A[0],`_A[7:1]};
40 `_F <= {`_F[7:5],`_A[0],`_F[3:0]};
3ad960bd
JW
41 end
42 `INSN_alu_RLA: begin
5c33c5c0
JW
43 `_A <= {`_A[6:0],`_F[4]};
44 `_F <= {`_F[7:5],`_A[7],`_F[3:0]};
3ad960bd
JW
45 end
46 `INSN_alu_RRA: begin
1a827c5b 47 `_A <= {`_F[4],`_A[7:1]};
5c33c5c0 48 `_F <= {`_F[7:5],`_A[0],`_F[3:0]};
3ad960bd 49 end
1a827c5b 50 `INSN_alu_DAA: begin
5c834537
JW
51 `_A <= daa_tmp[7:0];
52 `_F <= {
53 (daa_tmp[7:0] == 0) ? 1'b1 : 8'b0, /* Z */
54 2'b00, /* NH */
55 daa_tmp[8], /* C */
56 `_F[3:0]
57 };
1a827c5b 58 end
3ad960bd 59 `INSN_alu_CPL: begin
5c33c5c0
JW
60 `_A <= ~`_A;
61 `_F <= {`_F[7],1'b1,1'b1,`_F[4:0]};
3ad960bd
JW
62 end
63 `INSN_alu_SCF: begin
f8c46ff5 64 `_F <= {`_F[7],3'b001,`_F[3:0]};
3ad960bd
JW
65 end
66 `INSN_alu_CCF: begin
f8c46ff5 67 `_F <= {`_F[7],2'b00,~`_F[4],`_F[3:0]};
3ad960bd
JW
68 end
69 endcase
70 end
71`endif
This page took 0.03903 seconds and 4 git commands to generate.