mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-22 18:42:34 +00:00
sim: sim_arithmetic: handle SOS{,L,E,LE,A,GE,N,G}, add unit tests
This commit is contained in:
parent
a29203aa77
commit
c81966398c
@ -79,6 +79,14 @@
|
||||
, handle_SOJL/4
|
||||
, handle_SOJLE/4
|
||||
, handle_SOJN/4
|
||||
, handle_SOS/4
|
||||
, handle_SOSA/4
|
||||
, handle_SOSE/4
|
||||
, handle_SOSG/4
|
||||
, handle_SOSGE/4
|
||||
, handle_SOSL/4
|
||||
, handle_SOSLE/4
|
||||
, handle_SOSN/4
|
||||
]).
|
||||
|
||||
-include("sim_core.hrl").
|
||||
@ -730,6 +738,104 @@ handle_SOJG(Core, Mem, IR, EA) ->
|
||||
{Word, Flags} = sub1(CA),
|
||||
jump_if_G(sim_core:set_flags(sim_core:set_ac(Core, AC, Word), Flags), Mem, Word, EA).
|
||||
|
||||
%% SOS - Subtract One from Memory and Skip if Condition Satisfied
|
||||
|
||||
-spec handle_SOS(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOS(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOS(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSL(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSL(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSL(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSE(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSE(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSE(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSLE(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSLE(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSLE(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSA(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSA(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSA(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSGE(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSGE(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSGE(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSN(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSN(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSN(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_SOSG(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_SOSG(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
{Word, Flags} = sub1(CE),
|
||||
handle_AOSG(Core, Mem, IR, EA, Word, Flags);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> ?FUNCTION_NAME(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
%% Miscellaneous ===============================================================
|
||||
|
||||
jump_if_E(Core, Mem, X, EA) ->
|
||||
|
||||
@ -344,6 +344,14 @@ dispatch(Core, Mem, IR, EA) ->
|
||||
8#365 -> sim_arithmetic:handle_SOJGE(Core, Mem, IR, EA);
|
||||
8#366 -> sim_arithmetic:handle_SOJN(Core, Mem, IR, EA);
|
||||
8#367 -> sim_arithmetic:handle_SOJG(Core, Mem, IR, EA);
|
||||
8#370 -> sim_arithmetic:handle_SOS(Core, Mem, IR, EA);
|
||||
8#371 -> sim_arithmetic:handle_SOSL(Core, Mem, IR, EA);
|
||||
8#372 -> sim_arithmetic:handle_SOSE(Core, Mem, IR, EA);
|
||||
8#373 -> sim_arithmetic:handle_SOSLE(Core, Mem, IR, EA);
|
||||
8#374 -> sim_arithmetic:handle_SOSA(Core, Mem, IR, EA);
|
||||
8#375 -> sim_arithmetic:handle_SOSGE(Core, Mem, IR, EA);
|
||||
8#376 -> sim_arithmetic:handle_SOSN(Core, Mem, IR, EA);
|
||||
8#377 -> sim_arithmetic:handle_SOSG(Core, Mem, IR, EA);
|
||||
8#400 -> sim_boolean:handle_SETZ(Core, Mem, IR, EA);
|
||||
8#401 -> sim_boolean:handle_SETZ(Core, Mem, IR, EA); % SETZI = SETZ
|
||||
8#402 -> sim_boolean:handle_SETZM(Core, Mem, IR, EA);
|
||||
|
||||
@ -111,6 +111,14 @@
|
||||
-define(OP_SOJGE, 8#365).
|
||||
-define(OP_SOJN, 8#366).
|
||||
-define(OP_SOJG, 8#367).
|
||||
-define(OP_SOS, 8#370).
|
||||
-define(OP_SOSL, 8#371).
|
||||
-define(OP_SOSE, 8#372).
|
||||
-define(OP_SOSLE, 8#373).
|
||||
-define(OP_SOSA, 8#374).
|
||||
-define(OP_SOSGE, 8#375).
|
||||
-define(OP_SOSN, 8#376).
|
||||
-define(OP_SOSG, 8#377).
|
||||
|
||||
%% 2.6.1 Add One to Both Halves of AC and Jump =================================
|
||||
|
||||
@ -1153,6 +1161,167 @@ sojg_test() ->
|
||||
expect(Prog2, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?AC(1), ?LOW36(-3)}]). % AC(1) = -3
|
||||
|
||||
%% SOS - Subtract One from Memory and Skip if Condition Satisfied
|
||||
|
||||
sos_test() ->
|
||||
Prog =
|
||||
[ {1, 8#101, ?INSN(?OP_SOS, 1, 0, 0, 8#150)} % 1,,101/ SOS 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]). % AC(1) = 1
|
||||
|
||||
sosl_test() ->
|
||||
Prog1 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSL, 1, 0, 0, 8#150)} % 1,,101/ SOSL 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(-2)} % 1,,150/ -2
|
||||
],
|
||||
expect(Prog1, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(-3)} % C(1,,150) = -3
|
||||
, {?AC(1), ?LOW36(-3)}]), % AC(1) = -3
|
||||
Prog2 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSL, 1, 0, 0, 8#150)} % 1,,101/ SOSL 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog2, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]). % AC(1) = 1
|
||||
|
||||
sose_test() ->
|
||||
Prog1 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSE, 1, 0, 0, 8#150)} % 1,,101/ SOSE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(1)} % 1,,150/ 1
|
||||
],
|
||||
expect(Prog1, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(0)} % C(1,,150) = 0
|
||||
, {?AC(1), ?LOW36(0)}]), % AC(1) = 0
|
||||
Prog2 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSE, 1, 0, 0, 8#150)} % 1,,101/ SOSE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog2, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]). % AC(1) = 1
|
||||
|
||||
sosle_test() ->
|
||||
Prog1 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSLE, 1, 0, 0, 8#150)} % 1,,101/ SOSLE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(0)} % 1,,150/ 0
|
||||
],
|
||||
expect(Prog1, [], {1, 8#103}, ?DEFAULT_FLAGS, % jump, no carry flags
|
||||
[ {?EA(1, 8#150), ?LOW36(-1)} % C(1,,150) = -1
|
||||
, {?AC(1), ?LOW36(-1)}]), % AC(1) = -1
|
||||
Prog2 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSLE, 1, 0, 0, 8#150)} % 1,,101/ SOSLE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(1)} % 1,,150/ 1
|
||||
],
|
||||
expect(Prog2, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(0)} % C(1,,150) = 0
|
||||
, {?AC(1), ?LOW36(0)}]), % AC(1) = 0
|
||||
Prog3 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSLE, 1, 0, 0, 8#150)} % 1,,101/ SOSLE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog3, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]). % AC(1) = 1
|
||||
|
||||
sosa_test() ->
|
||||
Prog =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSA, 1, 0, 0, 8#150)} % 1,,101/ SOSA 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]). % AC(1) = 1
|
||||
|
||||
sosge_test() ->
|
||||
Prog1 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSGE, 1, 0, 0, 8#150)} % 1,,101/ SOSGE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog1, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]), % AC(1) = 1
|
||||
Prog2 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSGE, 1, 0, 0, 8#150)} % 1,,101/ SOSGE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(1)} % 1,,150/ 1
|
||||
],
|
||||
expect(Prog2, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(0)} % C(1,,150) = 0
|
||||
, {?AC(1), ?LOW36(0)}]), % AC(1) = 0
|
||||
Prog3 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSGE, 1, 0, 0, 8#150)} % 1,,101/ SOSGE 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(0)} % 1,,150/ 0
|
||||
],
|
||||
expect(Prog3, [], {1, 8#102}, ?DEFAULT_FLAGS, % no jump, no carry flags
|
||||
[ {?EA(1, 8#150), ?LOW36(-1)} % C(1,,150) = -1
|
||||
, {?AC(1), ?LOW36(-1)}]). % AC(1) = -1
|
||||
|
||||
sosn_test() ->
|
||||
Prog1 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSN, 1, 0, 0, 8#150)} % 1,,101/ SOSN 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog1, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]), % AC(1) = 1
|
||||
Prog2 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSN, 1, 0, 0, 8#150)} % 1,,101/ SOSN 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(1)} % 1,,150/ 1
|
||||
],
|
||||
expect(Prog2, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(0)} % C(1,,150) = 0
|
||||
, {?AC(1), ?LOW36(0)}]). % AC(1) = 0
|
||||
|
||||
sosg_test() ->
|
||||
Prog1 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSG, 1, 0, 0, 8#150)} % 1,,101/ SOSG 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(2)} % 1,,150/ 2
|
||||
],
|
||||
expect(Prog1, [], {1, 8#103}, ?CARRY_FLAGS, % jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(1)} % C(1,,150) = 1
|
||||
, {?AC(1), ?LOW36(1)}]), % AC(1) = 1
|
||||
Prog2 =
|
||||
[ {1, 8#101, ?INSN(?OP_SOSG, 1, 0, 0, 8#150)} % 1,,101/ SOSG 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {1, 8#103, ?INSN_INVALID} % 1,,103/ <invalid>
|
||||
, {1, 8#150, ?LOW36(-2)} % 1,,150/ -2
|
||||
],
|
||||
expect(Prog2, [], {1, 8#102}, ?CARRY_FLAGS, % no jump, carry 0 and 1
|
||||
[ {?EA(1, 8#150), ?LOW36(-3)} % C(1,,150) = -3
|
||||
, {?AC(1), ?LOW36(-3)}]). % AC(1) = -3
|
||||
|
||||
%% Common code to run short sequences ==========================================
|
||||
|
||||
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user