diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index a441ae7..00f52cd 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -48,6 +48,7 @@ , handle_IORB/4 , handle_IORI/4 , handle_IORM/4 + , handle_SETCA/4 , handle_SETMB/4 , handle_SETMI/4 , handle_SETMM/4 @@ -513,6 +514,16 @@ handle_EQVB(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_EQVB(Core1, Mem1, IR, EA) end) end. +%% SETCA - Set to Complement of AC + +-spec handle_SETCA(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_SETCA(Core, Mem, IR, _EA) -> + AC = IR band 8#17, + CA = sim_core:get_ac(Core, AC), + Word = (bnot CA) band ((1 bsl 36) - 1), + sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem). + %% Miscellaneous =============================================================== ea_address(#ea{section = Section, offset = Offset}) -> diff --git a/erlang/apps/sim/src/sim_core.erl b/erlang/apps/sim/src/sim_core.erl index 9f63d86..2aafadc 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -293,6 +293,7 @@ dispatch(Core, Mem, IR, EA) -> 8#445 -> sim_boolean:handle_EQVI(Core, Mem, IR, EA); 8#446 -> sim_boolean:handle_EQVM(Core, Mem, IR, EA); 8#447 -> sim_boolean:handle_EQVB(Core, Mem, IR, EA); + 8#450 -> sim_boolean:handle_SETCA(Core, Mem, IR, EA); _ -> PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset, {Core, Mem, {error, {?MODULE, {dispatch, PC, IR, EA}}}} diff --git a/erlang/apps/sim/test/sim_boolean_tests.erl b/erlang/apps/sim/test/sim_boolean_tests.erl index 9e23bb2..1f59fa9 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -84,6 +84,7 @@ -define(OP_EQVI, 8#445). -define(OP_EQVM, 8#446). -define(OP_EQVB, 8#447). +-define(OP_SETCA, 8#450). %% 2.4 Boolean Functions ======================================================= @@ -574,6 +575,18 @@ eqvb_test() -> , {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#343434)} % AC1 = -1,,343434 ]). +%% SETCA - Set to Complement of AC + +setca_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_SETCA, 1, 0, 0, 0)} % 1,,101/ SETCA 1, + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#070707)} % AC1 = -1,,070707 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->