// (C) Copyright 1979 Tripos Research Group
//     University of Cambridge
//     Computer Laboratory

SECTION "CLI-INIT"

GET "LIBHDR"
GET "CLIHDR"
GET "manhdr"

GLOBAL
$(
   maxglob  : ug+200
$)

LET cli.init(parm.pkt) = VALOF
 $( LET pkt = VEC pkt.arg6
    LET prompt = "%n %i2:%i2> "
    LET initialseg = tcb!tcb.seglist!3
    LET dummy = maxglob
    LET disc.envec = TABLE
        10,     || length of table
        256,    || block size
        0,      || sector origin
        1,      || number of surfaces
        1,      || sectors per block
        13,     || blocks per track
        1,      || number of reserved blocks
        8,      || pre-allocation factor
        1,      || interleave factor
         15,    || lower cylinder
         76     || upper cylinder



    pkt!pkt.link := notinuse

    pkt!pkt.id := task.consolehandler
    pkt!pkt.arg1 := -3
    pkt!pkt.arg2 := -4
    qpkt(pkt); taskwait()

    initio()
    selectinput(findinput("**"))
    selectoutput(findoutput("**"))
    writes("*n*niAPX86 TRIPOS starting (V3.5)*n")

    pkt!pkt.id := task.debug
    UNLESS qpkt(pkt)=0 DO taskwait()

    pkt!pkt.id := task.filehandler
    pkt!pkt.type := 0
    pkt!pkt.arg1 := 1 // action.startup
    pkt!pkt.arg2 := -2 // device number
    pkt!pkt.arg3 := 0 // unit number
    pkt!pkt.arg4 := 4 // number of cache slots
    pkt!pkt.arg5 := disc.envec
    pkt!pkt.arg6 := FALSE
    UNLESS qpkt(pkt)=0 DO taskwait()

    cli.background := FALSE
    cli.standardinput := input()
      cli.currentinput := findinput("SYS:S.INITIAL-COMMANDS")
    IF cli.currentinput=0 DO
       cli.currentinput := cli.standardinput
    cli.standardoutput := output()
    cli.currentoutput  := cli.standardoutput
        cli.commanddir := locatedir("SYS:C")
    returncode := 0
    cli.returncode := 0
    cli.faillevel  := cli.initialfaillevel
    cli.result2 := 0
    cli.commandfile%0 := 0
    cli.defaultstack := cli.initialstack
    cli.module := 0
    FOR i = 0 TO prompt%0 DO
       cli.prompt%i := prompt%i

    tcb!tcb.seglist!3 := 0
    start := cli.undefglobval
    result2 := initialseg
    RESULTIS unloadseg
 $)