:: pdp8_test.ini
::
:: Run the paper tape-based diagnostics for the PDP-8 simulator.
::
::
:: Script is where the diagnostics ought to reside as well.
cd %~p0

:: Limit maximum diagnostic execution time
runlimit 2 minutes
set on
on error ignore
on runtime echof "\r\n*** Test Runtime Limit %SIM_RUNLIMIT% %SIM_RUNLIMIT_UNITS% Exceeded ***\n"; exit 1

:: Maximum memory, extended address element:
set cpu 32k
set cpu eae

:: AND, TAD, Operate and basic MQ instruction test (D0AB)
:: This test halts after the first 3 instructions to let the
:: operator verify that HLT and CLA works before continuing 
:: onto the real tests.
echof -n "** PDP-8: Basic Instruction Test (1): "
load diags/maindec-8e-d0ab-pb.bin
:: Patch address 5276 with HLT to stop execution after a 
:: full pass is done or else it will send BEL every 1440
:: iterations.
dep 5276 7402
dep sr 07777
go -q 200
if (PC != 0147 || AC != 0) echof "MAINDEC-8/E-D0AB failed."; exit 1
go -q
if (PC != 05277) echof "MAINDEC-8/E-D0AB failed."; exit 1
echof "passed"

:: Autoindexing, Indirect addressing, and the DCA instruction with
:: "minimal" testing for interrupt, AND, TAD, ISZ, JMS, JMP and
:: processor IOT instructions.
echof -n "** PDP-8: Basic Instruction Test (2): "
load diags/maindec-8e-d0bb-pb.bin
:: Patch address 3740 with HLT, otherwise the test will loop every
:: 1550 iterations and send BEL to the TTY. We really do want the
:: test to halt.
dep 3740 7402
dep sr 0
go -q 200
if (PC != 03741) echof "MAINDEC-8/E-D0BB failed."; exit 1
echof "passed"

:: The ADDER test
echof "** PDP-8: Adder tests: "
load diags/maindec-8e-d0cc-pb.bin
:: Patch address 4561 with HLT. Test loops between SIMAD, SIMROT, FCT and
:: RANDOM, ad infinitum. We really want the test to halt.
dep 4561 7402
:: And ask the tests to be quiet, test extended (banked) memory.
dep sr 0200
go -q 200
if (PC != 04622) echof "MAINDEC-8/E-D0CC failed."; exit 1
echof
echof "** PDP-8: Adder test passed."

:: Random AND tests
echof -n "** PDP-8: Random AND test: "
load diags/maindec-8e-d0db-pb.bin
:: Halt after one 4096 loop pass, suppress output
dep sr 02400
go -q 200
if (PC != 00355) echof "MAINDEC-8/E-D0DB failed."; exit 1
echof "passed."

:: Random TAD tests
echof -n "** PDP-8: Random TAD test: "
load diags/maindec-8e-d0eb-pb.bin
:: Patch 6743 with HLT to stop the test after 4096 iterations. Would
:: normally output a "T" until machine halted.
dep 6743 7402
:: Suppress output
dep sr 00400
go -q 200
if (PC != 06744) echof "MAINDEC-8/E-D0EB failed."; exit 1
echof "passed."

:: Random ISZ tests
:: Bit more of a challenge: cant just put a HLT instruction to
:: terminate the test loop. And cant squelch the output either.
if (SIM_REGEX_TYPE == "") echof "Missing Regular Expression support - skipping Random ISZ test\n"; goto ISZ_DONE
echof "** PDP-8: Random ISZ test: "
load diags/maindec-8e-d0fc-pb.bin
dep sr 0
expect -r [25] "\r\nFC" echof; echof "** PDP-8: Random ISZ test: passed."
expect -r "F [0-7]{4}" echof; echof "** PDP-8: Random ISZ test: MAINDEC-8/E-D0FC failed."; exit 1
go -q 200
:ISZ_DONE

:: Random DCA tests
echof -n "** PDP-8: Random DCA test: "
load diags/maindec-8e-d0gc-pb.bin
:: Patch 0404 with HLT to stop the test after 28,328 iterations (one complete pass)
dep 0404 7402
dep sr 0
go -q 200
if (PC != 0405) echof "MAINDEC-8/E-D0GC failed."; exit 1
echof "passed."

echof
echof "!! All Tests Passed !!"
echof
exit 0
