// BasicBootInit.bcpl
// Copyright Xerox Corporation 1979
// Last modified April 20, 1979  2:48 PM by Boggs

get "SysInternals.d"
get "AltoDefs.d"

external
[
// outgoing procedures
BasicBootInit

// incoming procedures
SwatTrap; SwatInterrupt; ParityInterrupt

// incoming statics
SerialNumber; AltoVersion
]

//----------------------------------------------------------------------------
let BasicBootInit(nil, nil) be
//----------------------------------------------------------------------------
// Small asm procedures are coded inline to avoid proliferating files 
[
// reset interrupt system
@activeInterrupts = 0
(table [ 61001b; 1401b ])()  //EnableInterrupts
@wakeupsWaiting = 0

// display
maskTable!-1 = 0
for i = 0 to 15 do maskTable!i = -1 rshift (15-i)

// debugger Linkage
for core = 0 to 7 do @core = 77400B
for i = 0 to 31 do trapVector!i = SwatTrap
interruptVector!swatInterruptLevel = SwatInterrupt
@activeInterrupts = @activeInterrupts % swatInterruptBit
@displayInterrupt = @displayInterrupt % swatInterruptBit

SerialNumber = (table [ 61004b; 1401b ])(0) & 377b
AltoVersion = (table [ 61014b; 1401b ])()
@613b = (AltoVersion<<VERS.eng gr 1)? -1, 0

// parity errors
if AltoVersion<<VERS.eng eq 3 then
   [
   @MECR = -1  //correction on, don't report any errors
   for bank = 1 to 3 do
      [
      bankRegs!0 = bank
      let bbt = vec 16; bbt = (bbt+1) & -2
      for i = 0 to 15 do bbt!i = 0
      bbt>>BBT.dBank = 1
      bbt>>BBT.sBank = 1
      //127 "scan lines" of 512 words each.
      //skip I/O area in high memory.
      bbt>>BBT.dbmr = 512
      bbt>>BBT.sbmr = 512
      bbt>>BBT.dw = 512 * 16
      bbt>>BBT.dh = 127
      (table [ 055001b; 145000b; 111000b; 045001b; 126460b
               061024b; 031001b; 035001b; 001401b ])(bbt)  // BitBlt
      ]
   ]
@MESR = 0
@MECR = defaultMECR
interruptVector!parityInterruptLevel = ParityInterrupt
@activeInterrupts = @activeInterrupts % parityInterruptBit

let cursor = table [
   100000b; 140000b; 160000b; 170000b; 174000b; 176000b; 177000b; 170000b;
   154000b; 114000b; 006000b; 006000b; 003000b; 003000b; 001400b; 001400b ]
for i = 0 to 15 do cursorBitMap!i = cursor!i
]