//mrgo.bcpl	machine-independent Rep-Go, Rep-SS stuff
//	Last edited: 13 November 1979

get "mcommon.d"
get "mdecl.d"

external [
// OS
	TruePredicate; Zero; DoubleAdd

// MDATA
	@LoopCount; GoVec

// MRGN
	AddToEveryTimeList

// MCMD
	ErrorAbort; SetAbortPure

// MGO
	@QuitF; HaltWaitMenu; HaltProc

// MINIT0
	MStatus

// xxACTIONS
	@LongOne

// Machine dependent
	SetupIMA; OneStep; @CheckStopped

// Defined here for ACTIONS
	RepeatGo; RepeatSS; RepeatX
]

//Start microprocessor at selected address and repeatedly restart it
//after breakpoints until termination by mouse
let RepeatGo(MB,AVec,MemX; numargs NA) = valof
[	if NA < 3 then ErrorAbort()
	let R = RepeatX(CheckStopped,NA,true,AVec,MemX,
		"Repeating after breakpoints at ",MB)
	MStatus>>MStatus.MachRunning = true
	resultis R
]


//Repeatedly step microprocessor at selected address until termination
//by mouse
and RepeatSS(MB,AVec,MemX; numargs NA) = valof
[	if NA < 3 then ErrorAbort()
	resultis RepeatX(TruePredicate,NA,false,AVec,MemX,
		"Repeatedly stepping at ",MB)
]


and RepeatX(EveryT,NA,GoP,AVec,MemX,Msg,MB) = valof
[	SetAbortPure(lv HaltProc,nil)
	Zero(LoopCount,2)
	SetupIMA(GoP,AVec,MemX,NA,Msg,MB)
	OneStep(GoVec>>Go.RunP)
	QuitF = AddToEveryTimeList(REveryTime,EveryT)
	resultis HaltWaitMenu
]


and REveryTime(EveryT) be
[	if EveryT() do
	[ DoubleAdd(LoopCount,LongOne)
	  (GoVec>>Go.Proc)(GoVec)	//Go again
	  OneStep(GoVec>>Go.RunP)
	]
]