X-Git-Url: http://git.joshuawise.com/fpgaboy.git/blobdiff_plain/b057a5d6e6db6db06ae33703ca72cd235eec91d6..1a827c5b1f95a12df5eac754a84a6bc8e0bf6c40:/core/insn_alu_a.v?ds=sidebyside diff --git a/core/insn_alu_a.v b/core/insn_alu_a.v index 57a74fc..80d317d 100644 --- a/core/insn_alu_a.v +++ b/core/insn_alu_a.v @@ -1,3 +1,14 @@ +`define INSN_alu_RLCA 3'b000 +`define INSN_alu_RRCA 3'b001 +`define INSN_alu_RLA 3'b010 +`define INSN_alu_RRA 3'b011 +`define INSN_alu_DAA 3'b100 +`define INSN_alu_CPL 3'b101 +`define INSN_alu_SCF 3'b110 +`define INSN_alu_CCF 3'b111 + +`define INSN_ALU_A 9'b000xxx111 + `ifdef EXECUTE `INSN_ALU_A: begin `EXEC_NEWCYCLE @@ -21,9 +32,81 @@ `_F <= {`_F[7:5],`_A[7],`_F[3:0]}; end `INSN_alu_RRA: begin - `_A <= {`_A[4],`_A[7:1]}; + `_A <= {`_F[4],`_A[7:1]}; `_F <= {`_F[7:5],`_A[0],`_F[3:0]}; end + `INSN_alu_DAA: begin + if (`_F[6]) begin + if (`_F[4]) begin + if(`_A[3:0] >= 4'h6 && `_A[7:4] >= 4'h6 && `F[5]) begin + `_A <= `_A + 8'h9A; + `_F <= {((`_A + 8'h9A) == 8'b0), `_F[6:0]}; + end + else begin + `_A <= `_A + 8'hA0; + `_F <= {((`_A + 8'hA0) == 8'b0), `_F[6:0]}; + end + end + else begin + if(`_A[3:0] <= 4'h9 && `_A[7:4] <= 4'h9 && !`_F[5]) begin + `_F <= {(`_A == 8'b0), `_F[6:0]}; + end + else begin + `_A <= `_A + 8'hFA; + `_F <= {((`_A + 8'hFA) == 8'b0), `_F[6:0]}; + end + end + end + else begin + if (`_F[4]) begin + if(`_F[5]) begin + `_A <= `_A + 8'h66; + `_F <= {((`_A + 8'h66) == 8'b0), `_F[6:0]}; + end + else if (`_A[3:0] > 4'b9) begin + `_A <= `_A + 8'h66; + `_F <= {((`_A + 8'h66) == 8'b0), `_F[6:0]}; + end + else begin + `_A <= `_A + 8'h60; + `_F <= {((`_A + 8'h60) == 8'b0), `_F[6:0]}; + end + end + else begin + if(`_F[5]) begin + if(`_A[7:4] > 4'h9) begin + `_A <= `_A + 8'h66; + `_F <= {((`_A + 8'h66) == 8'b0), `_F[6:5], 1'b1, `_F[3:0]}; + end + else begin + `_A <= `_A + 8'h06; + `_F <= {((`_A + 8'h06) == 8'b0), `_F[6:0]}; + end + end + else begin + if(`_A[3:0] > 4'h9) begin + if (`_A[7:4] > 4'h8) begin + `_A <= `_A + 8'h66; + `_F <= {((`_A + 8'h66) == 8'b0), `_F[6:5], 1'b1, `_F[3:0]}; + end + else begin + `_A <= `_A + 8'h06; + `_F <= {((`_A + 8'h06) == 8'b0), `_F[6:0]}; + end + end + else begin + if (`_A[7:4] > 4'h9) begin + `_A <= `_A + 8'h66; + `_F <= {((`_A + 8'h66) == 8'b0), `_F[6:5], 1'b1, `_F[3:0]}; + end + else begin + `_F <= {(`_A == 8'b0), `_F[6:0]}; + end + end + end + end + end + end `INSN_alu_CPL: begin `_A <= ~`_A; `_F <= {`_F[7],1'b1,1'b1,`_F[4:0]};