//CursorStream.bcpl utility for sending "stream" output to the cursor

get "streams.d"
get "altodefs.d"

external [ InitCursor; WriteCursor; CursorS ]
external [ CreateDisplayStream; SetBitPos; Zero; MoveBlock; Puts ]

static CursorS=0

//This proceedure must be called first
//It creats a small Stream DCB for text to be placed
//it returns the stream in case you want to output to the stream without WriteCursor
//The three parameters are pointer to a buffer, length of buffer, must be 50 words or more
//pointer to a font, 0 for sysfont, and pointer to zone, syszone if zero

let InitCursor(buff,length,fnt,zne) =valof
[
CursorS = CreateDisplayStream(1,buff,length,fnt,2,DSstopright,zne)
let dcb = CursorS>>DS.fdcb
//Zero(dcb>>DCB.bitmap,32)
SetBitPos(CursorS,0)
//WriteCursor(0)
resultis CursorS
]



//this proceedure sends "param" to routine, and copies the resulting bitmap in the
//dcb into the cursor
//example WriteCursor(Wss,"Hi") displays Hi
//example WriteCursor(Wns,cnt) displays cnt right justified in decimal
//example Wns(S,val,0,8); WriteCursor(0,0) displays what you want
//example WriteCursor($i) displays smaall "in" in bottom 4 scan lines of the cursor
//example WriteCursor($o) displays smaall "out" in bottom 4 scan lines of the cursor

and WriteCursor(routine,param) be
[
let In = table [ #2260; #2310; #2210; #2210 ]
let Out = table [ #74447; #44442; #44442; #74302 ]
if routine eq $i then [ MoveBlock(#445,In,4); return ]//in
if routine eq $o then [ MoveBlock(#445,Out,4); return ]//out
if routine then routine(CursorS,param,2)
let dcb = CursorS>>DS.fdcb
let bitmap = dcb>>DCB.bitmap
for i = 0 to 15 do #431!i = i ls dcb>>DCB.height*2? bitmap!(i lshift 1),0
Puts(CursorS, $*n); SetBitPos(CursorS,0)
]