// FtpBootInit.bcpl -- Initialization for the Boot file version
// Copyright Xerox Corporation 1979, 1980, 1981, 1982
// Last modified October 1, 1982  9:04 PM by Boggs

get "AltoDefs.d"
get "Streams.d"

external
[
// outgoing procedure
InitFtpBoot

// incoming procedures
InitFtpPList; InitFtpUtil; InitPupLevel1; InitDisplay
MakeBar; MakeTitle; FTPShowDisplayStream
InitializeZone; Allocate; Free; SysErr
MyFrame; Enqueue; Unqueue; BFSInit; CallSwat
CallContextList; InitializeContext; Block; Dismiss
PupChecksum; UPupChecksum; InitBcplRuntime; LoadRam
CreateKeyboardStream

// outgoing statics
stackSize
ftpDisk; ctxQ; sysZone; sysDisk

ramFlag; errorFlag; debugFlag; tfsFlag; logFlag
userFlag; serverFlag; telnetFlag; cliFlag

// incoming statics
sysFont; fontHeight; lastShownStream; currentYPos
serverDsp; userDsp; telnetDsp; userDspLen
lvIdle; FtpRamImage

// ground out some undefs
hostName; dsp; fpSysBoot; cli; logStream
Wns; FtpCli; CliError; InitFtpCli
]

static
[
stackSize = 1200; initDone = false
ftpDisk; ctxQ; sysDisk; sysZone

ramFlag = false; errorFlag = true; debugFlag = false
logFlag = false; cliFlag = false; tfsFlag = false
userFlag = true; serverFlag = true; telnetFlag = true

// ground out some undefs
hostName; dsp; fpSysBoot; cli; logStream
Wns; FtpCli; CliError; InitFtpCli
]

manifest
[
stackLimit = 335b
numPBIs = 12

servDspSLC = 100  //server window size
userDspSLC = 200  //user window size

black = true
white = false
]

//-----------------------------------------------------------------------------------------
let InitFtpBoot() be
//-----------------------------------------------------------------------------------------
[
// cursor
@mouseX, @mouseY = 260, 25
for i = 0 to 7 do cursorBitMap!i = 177400b
for i = 8 to 15 do cursorBitMap!i = 377b

// sysZone
let freeBegin = @stackLimit
let freeEnd = MyFrame() -200
@stackLimit = freeEnd
test freeEnd-freeBegin gr 0
   ifso sysZone = InitializeZone(freeBegin, freeEnd-freeBegin, SysErr,
    (debugFlag? SysErr, 0))
   ifnot sysZone = InitializeZone(freeEnd-77777b, 77777b, SysErr,
    (debugFlag? SysErr, 0))

// contexts
ctxQ = Allocate(sysZone, 2); ctxQ!0 = 0
@lvIdle = Block
let initCtx = InitializeContext(Allocate(sysZone, 1500), 1500, InitCtx)
Enqueue(ctxQ, initCtx)
CallContextList(ctxQ!0) repeatuntil initDone
Unqueue(ctxQ, initCtx)
Free(sysZone, initCtx)
]

//-----------------------------------------------------------------------------------------
and InitCtx(ctx) be
//-----------------------------------------------------------------------------------------
[
CreateKeyboardStream()

// ground out some undefs
Wns, FtpCli, CliError = CallSwat, CallSwat, CallSwat

// microcode
ramFlag = LoadRam(FtpRamImage, true) ge 0
if ramFlag then
   [
   PupChecksum = UPupChecksum
   InitBcplRuntime()
   ]

// disk
   [
   ftpDisk = BFSInit(sysZone, true)  //open DP0
   if ftpDisk ne 0 break
   Dismiss(200)
   ] repeat
sysDisk = ftpDisk

// Pup package
InitPupLevel1(sysZone, ctxQ, numPBIs)

// Ftp subsystem
InitDisplay()

// server
MakeTitle("   FTP Server")
serverDsp = MakeBar(white, (servDspSLC/(2*fontHeight))*fontHeight)
FTPShowDisplayStream(serverDsp)

// user
MakeTitle("   FTP User")
userDspLen = 3500
userDsp = MakeBar(white, (userDspSLC/(2*fontHeight))*fontHeight)
FTPShowDisplayStream(userDsp)

// telnet
MakeTitle("   Telnet User")
telnetDsp = MakeBar(white, ((780-currentYPos)/(2*fontHeight))*fontHeight)
FTPShowDisplayStream(telnetDsp)

FTPShowDisplayStream(MakeBar(black, 1))

// Ftp package
InitFtpUtil()
InitFtpPList()

initDone = true
// returning from a context does an implicit Block()
]