//D1LDRTest.bcpl -- "LDRtest" action
//	Last edited: 25 October 1979

get "mcommon.d"
get "d1.d"
manifest [ get "d1regmem.d" ]

external [
// MINIT0
	@ACTS

// MIDAS
	MidasSwat

// MASM
	@MBlock

// MRGN
	AddToEveryTimeList

// MMPRGN
	MDatatoCSS; BadAltIn

// MCMD
	LoadDone

// MGO
	@QuitF; @CantContinue

// MDEBUG
	GetPattern; ErrorStop; SetupPattern; CollectLDR; TestAborted

// MPATTERN
	NextData; CheckData; IncV

// D1ACTIONS
	@ShouldBe; @DataWas

// D1TABLES
	@MEMWID; @MEMFORMS; AltMInput; AltMForms

// D1ASM
	@Xct; @XctL16; @XctR16

// Defined here
	MicTest
]

//This procedure initiates "LDR-loop".  Its args are 1 to 6
//LDR addresses from the command line.  If a single address is passed,
//it is repeatedly executed from the Alto, preceded by generation
//of the selected data pattern.  If more than one arg, then the sequence of
//LDR addresses is executed as a test, preceded by generation of the data
//pattern, followed by a compare of the initial data against the result
//read back.  The right-most 16 bits of BITS-CHECKED should have a
//left-justified data compare mask.
let MicTest(nil,nil) = valof
[	ACTS!0 = CollectLDR(ACTS+1,LDRx)
	if ACTS!0 > 10 then MidasSwat(XSMicTextArgs)
	for I = 1 to ACTS!0-1 do ACTS!I = ACTS!I lshift 2
	resultis GetPattern(0,MicTDoIt)
]


and MicTDoIt(nil,nil) be
[	LoadDone = false; CantContinue = CantContinue % didTest
	QuitF = AddToEveryTimeList(RepLDR,ACTS!0)
	MEMWID!MDATAx = 16
	MEMFORMS!MDATAx = 0
	AltMInput!MDATAx = BadAltIn
	AltMForms!MDATAx = MDatatoCSS
	MBlock(IncV,table [ 1; 0; 0 ] ,3)
	SetupPattern(table[ -1 ] ,"with LDR instr. sequence",8)
]


and RepLDR(nOps) be
[	for I = 1 to 100 do
	[ NextData()
	  XctL16(ACTS!1,ShouldBe!0)
	  if nOps > 1 do
	  [ for J = 2 to nOps - 1 do Xct(ACTS!J)
	    XctR16(ACTS!nOps,DataWas)
	    if CheckData() then ErrorStop("Data compare error","")
	  ]
	]
	if TestAborted then ErrorStop()
]