// DiEx.bcpl -- program to write and check headers on a DIABLO disk
//
Last modified April 24, 1982 5:06 PM by Boggs

get "Streams.d"
get "SysDefs.d"
get "DiEx.defs"

external [ Junta; EnableInterrupts; MyFrame; EtherRcvr ]
manifest new = #100
static [ displayCB ]
structure VERS [ eng bit 4; blank bit 12 ]

let DiEx() be Junta(levDisplay, MainLoop)

and MainLoop() be
[
InitFunction()
displayCB = rv DAstart
@#10 = #030013//lda 2,13
@#11 = #002014//jmp@14
@#12 = #000010//point to instruction in #10
@#13 = MyFrame()//
@#14 = ReStart//


DisplayAll(); goto MainLp
ReStart: @#521 = 0; EnableInterrupts()
Msg("*n*N>>DiEx restarted by brute force!!!!!*n*n>>")
MainLp:
SetCursor($←)
char = false
[ // The main loop
rv DAstart = displayCB
FindActiveParam()
] repeat
]

and DisplayAll() be
[
Active = false
if WriteEnable then
[
DisplayParam(InitLabels, 1, Tab1)
DisplayParam(InitFullTest, 1, Tab3)
DisplayParam(TestData, 3, Tab3)
]
DisplayParam(DoTest, 0, Tab4)
DisplayParam(Quit, 0, Tab5)

DisplayParam(InitVerify, 1, Tab2)
DisplayParam(StoreCustom, 1, Tab4)
DisplayParam(InitCustom, 2, Tab4)

DisplayParam(MsgEnable, 3, Tab0)
DisplayParam(SetPackType, 3, Tab1)
DisplayParam(ListData, 3, Tab2)
DisplayParam(Ethernet, 3, Tab5)

if (table [ 61014b; 1401b ])()<<VERS.eng gr 3 then
DisplayParam(Partition, 7, Tab2)

DisplayParam(Repeats, 4, Tab3)
DisplayParam(Random, 4, Tab4)
DisplayParam(DisplayOn, 4, Tab5)
DisplayStatus() //find on file "TriexStatus.bcpl"
DisplayAddr() //find on file "TriexAddr.bcpl"
DisplayAddrCont() //find on file "TriexAddr.bcpl"
DisplayComm() //find on file "TriexComm.bcpl"
DisplayPatterns() //find on file "TriexRun.bcpl"
]

and Partition() be
[
let str = "Partition = "
let curPart = (table [ 61037b; 1401b ])(0)
let newPart = NewNumber("Disk Partition number.", curPart, str)
if newPart ne curPart then (table [ 61037b; 1401b ])(newPart)
PrintParam("$S$D", str, (table [ 61037b; 1401b ])(0))
]

and Quit() be
[
if NewBoolian("Return to Exec", true) then
[
@#420 = 0
EtherRcvr(0)
finish
]
PrintParam("Quit")
]

and DoTest() be
[
if NewBoolian("Run the disk with the specified parameters") then
[ RunDisk(0); SetCursor($←) ]
PrintParam("Do Test")
]

and Ethernet() be
[
if NewBoolian("Enable ethernet activity for task interference.") then
[
T>>P.Ethernet = T>>P.Ethernet eq 0
EtherRcvr(T>>P.Ethernet)
SetCursor($←)
]
PrintParam("Eth Rcvr: $S",T>>P.Ethernet?"On","Off")
]

and Repeats() be
[ let str = "Repeats = "
let Hnt = "500 or more repeats will run for ever."
T>>P.Repeats = NewNumber(Hnt,T>>P.Repeats, str)
T>>P.Repeats = SetBounds(T>>P.Repeats, 1, 500)
PrintParam("$S$D",str,T>>P.Repeats)
]

and Random() be
[ let str = "Random = "
let Hnt = "Specify the number of random seeks to be done at the end of each pass"
T>>P.nRandom = NewNumber(Hnt,T>>P.nRandom, str)
T>>P.nRandom = SetBounds(T>>P.nRandom, 0)
PrintParam("$S$D",str,T>>P.nRandom)
]

and DisplayOn() be
[
if NewBoolian("Turn off the display during testing.") then
T>>P.StopDisplay = T>>P.StopDisplay eq 0
PrintParam("Display: $S",T>>P.StopDisplay?"Off","On")
]

and InitFullTest() be
[
if NewBoolian("Initialise all parameters for full test of disk.") then
[ MoveBlock(T,T+1*TableSize,TableSize); DisplayAll() ]
PrintParam("Init Full Test")
]

and InitLabels() be
[
if NewBoolian("Initialise all parameters for Header and Label initialization.") then
[ MoveBlock(T,T+2*TableSize,TableSize); DisplayAll() ]
PrintParam("Init Labels")
]

and InitVerify() be
[
if NewBoolian("Initialise all parameters for Verification of Readability of data on the disk.") then
[ MoveBlock(T,T+3*TableSize,TableSize); DisplayAll() ]
PrintParam("Init Verify")
]

and InitCustom() be
[
if NewBoolian("Initialise all parameters to Custom test.") then
[ MoveBlock(T,T+4*TableSize,TableSize)
nHeads = T!-1; nSectors = T!-2; nTracks = T!-3; FirstDr = T!-4; LastDr = T!-5
DisplayAll()
]
PrintParam("Init Custom")
]

and StoreCustom() be
[
if NewBoolian("Save current parameters as the ’Custom’ test.") then
[ MoveBlock(T+4*TableSize,T,TableSize)
T!-1 = nHeads; T!-2 = nSectors; T!-3 = nTracks; T!-4 = FirstDr; T!-5 = LastDr
Hint(" Done")
]
PrintParam("Save Custom")
]


and ListData() be
[ let str = nil
if NewBoolian("Will print the contents of the header, label & data of the sector read.") then T>>P.ListPage = T>>P.ListPage+1
switchon T>>P.ListPage into
[
default: T>>P.ListPage = 0; str = "No"; endcase
case 1: str = "Yes"; endcase
case 2: str = "If err"; endcase
]
PrintParam("List Data: $S",str)
]

and MsgEnable() be
[
if NewBoolian("Turn error reporting off for scoping hardware.") then
T>>P.MsgEnable = T>>P.MsgEnable eq 0
PrintParam("Report Errs: $S",T>>P.MsgEnable?"Yes","No")
]

and SetPackType() be
[
if NewBoolian("Pack’s Headers contain drive number - change if you are getting ’000002’ errors.") then
PackType = PackType eq 0
PrintParam("Header Fmt: $S",PackType?"DP1","DP0")
]

and TestData() be
[ let str = nil
if NewBoolian("Will cause the data read to be checked against the data written.") then
T>>P.TestData = T>>P.TestData+1
switchon T>>P.TestData into
[
default: T>>P.TestData = 0; str = "No"; endcase
case 1: str = "Yes"; endcase
case 2: str = "If err"; endcase
]
PrintParam("Check Data: $S",str)
]