[comp.sources.amiga] v89i191: xoper - examine & control your kernel, Part02/03

root%swap@Sun.COM (Operator) (10/28/89)

Submitted-by: g35@dhdurz1@bitnet (Werner Guenther)
Posting-number: Volume 89, Issue 191
Archive-name: kernel/xoper20.2

# This is a shell archive.
# Remove anything above and including the cut line.
# Then run the rest of the file through 'sh'.
# Unpacked files will be owned by you and have default permissions.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: SHell ARchive
# Run the following text through 'sh' to create:
#	xoper.a2
# This is archive 2 of a 3-part kit.
# This archive created: Fri Oct 27 23:48:52 1989
echo "extracting xoper.a2"
sed 's/^X//' << \SHAR_EOF > xoper.a2
X3$	    bra     restart
X
X;fill all unused memory-chunks with a longword
Xclear	    moveq   #0,d0
X	    cmp.b   #10,0(a0)
X	    beq.s   clr5
X	    bsr     readhex
X	    tst.b   d7
X	    beq     syntax
Xclr5	    move.l  _SysBase(PC),a0
X	    clr.l   parmtxt
X	    lea     322(a0),a0
X	    move.w  #$4000,$dff09a
Xclr1	    move.l  0(a0),a0
X	    tst.l   0(a0)
X	    beq.s   clr4
X	    move.l  16(a0),a1
Xclr2	    tst.l   0(a1)
X	    beq.s   clr1
X	    addq.l  #1,parmtxt
X	    move.l  4(a1),d1
X	    subq.l  #8,d1
X	    beq.s   clr31
X	    lsr.l   #2,d1
X	    subq.l  #1,d1
X	    lea     8(a1),a2
Xclr3	    move.l  d0,(a2)+
X	    dbf     d1,clr3
Xclr31	    move.l  0(a1),a1
X	    bra.s   clr2
Xclr4	    move.w  #-$4000,$dff09a
X	    move.l  parmtxt(PC),d0
X	    bsr     bytedec
X	    move.l  #clrtxt,d0
X	    bra     putnam
X
X;change the number of maximum lines in the history buffer
Xhistorylines
X	    bsr     getnum
X	    tst.b   d7
X	    beq     syntax
X	    move.w  d2,maxhlines
X	    move.w  hnum(PC),d0
X1$	    cmp.w   maxhlines(PC),d0
X	    ble.s   2$
X	    bsr     remhistline
X	    subq    #1,d0
X	    bra.s   1$
X2$	    move.l  history+8,curhist
X	    move.w  d0,hnum
X	    rts
X;set the minimum number of characters a input line
X;must have to be added to the history buffer
Xhistorylength
X	    bsr     getnum
X	    tst.b   d7
X	    beq     syntax
X	    tst.b   d2
X	    bne.s   1$
X	    addq    #1,d2
X1$	    move.w  d2,minnumchars
X	    rts
X;display all lines in the history buffer
Xshowhistory move.l  history(PC),a5
X	    moveq   #1,d5
X1$	    tst.l   0(a5)
X	    beq.s   2$
X	    move.l  d5,d3
X	    bsr     bytedec
X	    move.w  8(a5),d0
X	    ext.l   d0
X	    lea     10(a5),a0
X	    lea     inputbuffer,a1
X	    CALL    CopyMem,_SysBase(PC)
X	    move.w  8(a5),d0
X	    lea     inputbuffer,a1
X	    clr.b   0(a1,d0.w)
X	    move.l  a1,d0
X	    bsr     putnam
X	    addq    #1,d5
X	    move.l  0(a5),a5
X	    bra.s   1$
X2$	    rts
X
X;set the maximum lines the output buffer may hold
Xoutputlines bsr     getnum
X	    tst.b   d7
X	    beq     syntax
X	    moveq   #100,d3
X	    tst.l   d2
X	    bmi.s   2$
X	    cmp.l   d3,d2
X	    bge.s   1$
X2$	    move.l  d3,d2
X1$	    move.l  d2,maxlines
X	    rts
X
X;find a named node
X;d7 = number of lists to search through
X;a4 = pointer to the first entry in the
X;     list-offset-table
X;a5 = pointer to name
X;returns:
X;d7 = TRUE/FALSE 1/0
X;d0 = node
X
Xfindnam     tst.b   0(a5)
X	    bne.s   1$
X	    move.l  #nameerr,d0
X	    bsr     putnam
X	    bra     fnerr
X1$	    cmp.b   #'$',0(a5)
X	    bne.s   fn2
X	    move.l  d7,d2
X	    move.l  a5,a0
X	    bsr     readhex
X	    tst.b   d7
X	    beq.s   fn6
X	    move.l  d2,d7
X	    bsr     tstnode
X	    tst.l   d5
X	    bne.s   fn3
X	    bra     fn5
Xfn6	    move.l  d2,d7
Xfn2	    move.l  _SysBase(PC),a0
X	    adda.l  0(a4),a0
X	    move.l  a5,a1
Xfn4	    CALL    FindName,_SysBase(PC)
X	    tst.l   d0
X	    bne.s   fn1
X	    addq    #4,a4
X	    dbf     d7,fn2
Xfn5	    move.l  #namerr,d0
X	    bsr     putstr
X	    move.l  a5,d0
X	    bsr     putnam
Xfnerr	    clr.b   d7
X	    rts
Xfn1	    move.b  procnum(PC),d2
X	    beq.s   fn3
X	    move.l  d0,a0
X	    cmp.b   143(a0),d2
X	    bne.s   fn4
Xfn3	    moveq.l #1,d7
X	    rts
X
X;list-offset-table
XTRuNode     dc.l    276
XTReNode     dc.l    406
XTWaNode     dc.l    420
XDevNode     dc.l    350
XLibNode     dc.l    378
XResNode     dc.l    336
XMemNode     dc.l    322
XPorNode     dc.l    392
XSemNode     dc.l    532
X
X;Node has been entered in hex. Check if this node exsists
Xtstnode     tst.b   fromfile
X	    bne.s   illegalhex
X	    move.l  d0,d1
X	    btst    #0,d1
X	    beq.s   inrange
X	    move.l  #adrerr,d0
X	    bsr     putnam
Xillegalhex  moveq   #0,d5
X	    rts
Xinrange     movem.l d7/a4,-(a7)
X	    cmp.l   #TRuNode,a4
X	    bne.s   inrange1
X	    move.l  _SysBase(PC),a0
X	    cmp.l   276(a0),d0
X	    beq.s   nodefound
X	    subq    #1,d7
X	    addq    #4,a4
Xinrange1    move.w  #$4000,$dff09a
Xgetlist     move.l  _SysBase(PC),a0
X	    add.l   0(a4),a0
Xnxtnode     tst.l   0(a0)
X	    beq.s   nxtlist
X	    cmp.l   a0,d0
X	    beq.s   nodefound
X	    move.l  0(a0),a0
X	    bra.s   nxtnode
Xnxtlist     addq    #4,a4
X	    dbf     d7,getlist
X	    move.w  #-$4000,$dff09a
X	    movem.l d0/d7/a4,-(a7)
X	    bsr     ResumeOutput
X	    move.l  #noderr,d0
X	    bsr     putnam
X	    bsr     readline
X	    movem.l (a7)+,d0/d7/a4
X	    cmp.b   #'y',inputbuffer
X	    beq.s   nodefound1
X	    moveq   #0,d5
X	    movem.l (a7)+,d7/a4
X	    rts
Xnodefound   move.w  #-$4000,$dff09a
Xnodefound1  move.b  #1,d5
Xetst	    movem.l (a7)+,d7/a0
X	    rts
X
X;allocate FileInfoBlock
Xallocfinfo  move.l  #260,d0
X	    moveq   #0,d1
X	    CALL    AllocMem,_SysBase(PC)
X	    move.l  d0,finfoptr
X	    rts
X
X;free FileInfoBlock
Xfreefinfo   move.l  #260,d0
X	    move.l  finfoptr(PC),d1
X	    beq.s   1$
X	    move.l  d1,a1
X	    CALL    FreeMem,_SysBase(PC)
X1$	    rts
X
X;Examine ,d0=Lock
Xgetfinfo    move.l  d0,d1
X	    move.l  finfoptr,d2
X	    CALL    Examine,dosbase(PC)
X	    rts
X
X;construct a Pathname from a lock
X;d0=Lock ,resulting string is written to window
Xgetpath     movem.l d1-d7/a0-a6,-(a7)
X	    move.l  d0,d1
X	    beq.s   1$
X	    CALL    DupLock,dosbase(PC)
X1$	    lea     out,a4
X	    clr.b   -(a4)
Xgp0	    move.l  d0,-(a7)
X	    bsr     getfinfo
X	    move.l  finfoptr,a0
X	    move.l  4(a0),d4
X	    addq    #8,a0
X	    bsr     strlen
X	    lea     -1(a4),a5
X	    tst.l   d4
X	    bmi.s   nodir
X	    move.b  #'/',-(a4)
Xnodir	    subq    #1,d0
X	    bmi.s   nofnam
Xgp1	    move.b  0(a0,d0),-(a4)
X	    dbf     d0,gp1
Xnofnam	    move.l  0(a7),d1
X	    CALL    ParentDir,dosbase(PC)
X	    move.l  d0,d4
X	    move.l  (a7)+,d1
X	    beq.s   2$
X	    CALL    UnLock,dosbase(PC)
X2$	    move.l  d4,d0
X	    bne     gp0
Xputall	    cmp.b   #'/',0(a5)
X	    bne.s   gp2
X	    move.b  #':',0(a5)
Xgp2	    move.l  a4,d0
X	    bsr     putnam
X	    movem.l (a7)+,d1-d7/a0-a6
X	    rts
Xstrlen	    move.l  a0,-(a7)
X	    move.l  #-1,d0
Xstrl2	    addq.l  #1,d0
X	    tst.b   (a0)+
X	    bne.s   strl2
X	    move.l  (a7)+,a0
X	    rts
Xstrlen2     move.l  a0,-(a7)
X	    move.l  #-1,d0
Xstrl22	    addq.l  #1,d0
X	    cmp.b   #10,(a0)+
X	    bne.s   strl22
X	    move.l  (a7)+,a0
X	    rts
X
X;write a title and underline
X;a0 = pointer to text
Xputhead1    bsr     strlen
X	    move.l  d0,d5
X	    move.l  a0,d0
X	    bra     putstr
X
Xputhead2    bsr     strlen
X	    add.l   d0,d5
X	    bra.s   ph2
X
Xputhead     bsr     strlen
X	    move.l  d0,d5
Xph2	    move.l  a0,d0
X	    bsr     putnam
X	    lea     out,a0
X	    move.l  a0,d0
Xph1	    move.b  #'-',(a0)+
X	    dbf     d5,ph1
X	    move.b  #$0a,(a0)+
X	    clr.b   0(a0)
X	    bra     putstr
X
X;move cursor to a column
X;d0 = current position
X;d1 = column
Xtab	    move.l  a3,-(a7)
X	    lea     out,a3
Xsp5	    cmp.b   d1,d0
X	    bcc.s   sp4
X	    move.b  #' ',0(a3,d0)
X	    addq.b  #1,d0
X	    bra.s   sp5
Xsp4	    move.l  d1,ptr
X	    move.l  (a7)+,a3
X	    rts
X
X;convert ascii to byte
X;a0 = pointer to text
X;d0 = byte
Xgetnum	    cmp.b   #'$',0(a0)
X	    bne.s   isdec
X	    bsr     readhex
X	    move.l  d0,d2
X	    rts
Xisdec	    moveq   #0,d2
X	    move.l  d2,d3
X	    move.l  d2,d6
X	    move.l  d2,d7
X	    cmp.b   #'-',0(a0)
X	    bne.s   gn1
X	    addq    #1,a0
X	    moveq.l #1,d6
Xgn1	    move.b  (a0)+,d3
X	    cmp.b   #'9',d3
X	    bhi.s   gn2
X	    cmp.b   #'0',d3
X	    bcs.s   gn2
X	    moveq   #1,d7
X	    and.b   #$f,d3
X	    muls    #10,d2
X	    add.l   d3,d2
X	    bra.s   gn1
Xgn2	    tst.b   d6
X	    beq.s   gn3
X	    neg.l   d2
Xgn3	    tst.b   d7
X	    bne.s   gn4
X	    subq    #1,a0
Xgn4	    rts
X
X;convert hex to longword
X;a0 = pointer to text
X;returns d0=value
X;d7 = ok/error 1/0
Xreadhex     movem.l d1-d6/a1-a5,-(a7)
X	    moveq   #1,d7
X	    cmp.b   #'$',0(a0)
X	    bne.s   rh3
X	    addq    #1,a0
Xrh3	    moveq   #0,d0
X	    cmpi.b  #10,0(a0)
X	    beq.s   rherr
X	    lea     hextab(pc),a1
Xrh0	    move.b  (a0)+,d3
X	    moveq.l #15,d2
Xrh1	    cmp.b   0(a1,d2),d3
X	    beq.s   rh2
X	    dbf     d2,rh1
X	    bra     rhend
Xrh2	    lsl.l   #4,d0
X	    or.b    d2,d0
X	    bra.s   rh0
Xrhend	    tst.b   d3
X	    beq.s   rhok
X	    cmpi.b  #10,d3
X	    beq.s   rhok
X	    cmpi.b  #' ',d3
X	    beq.s   rhok
Xrherr	    moveq   #0,d7
Xrhok	    movem.l (a7)+,d1-d6/a1-a5
X	    rts
X
X;skip blanks
X;a0 pointer to text
X; returns a0 = new pointer position
Xkllblnks    cmpi.b  #' ',0(a0)
X	    bne.s   gn4
X	    addq    #1,a0
X	    bra.s   kllblnks
X
X; exit program. If background flag is set, wait for
X; amiga-amiga-x
X
Xstopall     addq    #4,a7
X	    bra     exitall
X
Xexit	    tst.b   background
X	    bne     quithold
Xexitall     bsr     killpage
X	    bsr     freeblank
X	    bsr     killhistory
X	    move.l  stplist(PC),a3
X	    tst.l   0(a3)
X	    beq.s   ex0
X	    move.l  a3,d0
X	    bsr     waok
X	    bra.s   exitall
X
Xex0	    tst.b   background
X	    beq.s   ex1
X	    bsr     removeh
X
Xex1	    move.l  _SysBase(PC),a1
X	    move.l  #_LVOSwitch,a0
X	    move.l  oldswitch,d0
X	    CALL    SetFunction,_SysBase(PC)
X	    moveq   #3,d0
X	    lea     IOCounter(PC),a1
X	    CALL    RemIntServer,_SysBase(PC)
X
X	    move.l  replyport(PC),-(a7)
X	    LIBCALL DeletePort
X	    addq    #4,a7
X	    bsr     stoptimer
X	    lea     timerio,a1
X	    CALL    CloseDevice,_SysBase(PC)
X	    move.l  timerport(PC),-(a7)
X	    LIBCALL DeletePort
X	    addq    #4,a7
X
X	    bsr     restoretrap
X
X	    tst.l   wnptr
X	    beq.s   5$
X	    move.l  wnptr(PC),a0
X	    CALL    CloseWindow,intuibase(PC)
X5$	    tst.b   ownscreen
X	    beq.s   6$
X	    move.l  screenptr(PC),a0
X	    CALL    CloseScreen,intuibase(PC)
X	    clr.l   screenptr
X
X6$	    move.l  fileptr(PC),d1
X	    beq.s   ex11
X	    CALL    Close,dosbase(PC)
Xex11	    bsr     freehidmem
X	    bsr     freealias
X	    move.l  realstack(PC),a7
X	IFND DEBUG
X	    CALL    Forbid,_SysBase(PC)
X	    move.l  wbmsg(PC),d0
X	    beq.s   todos
X	    move.l  d0,a1
X	    CALL    ReplyMsg,_SysBase(PC)
X	    moveq   #0,d0
X	    rts
X
Xtodos	    move.l  myseg(PC),d1
X	    CALL    UnLoadSeg,dosbase(PC)
X	ENDC
X	    moveq   #0,d0
X	    rts
X
X;print a bcpl-string
X;d0 = bcpl-pointer to bcpl-string
Xputbcpl     movem.l d3/a0-a1,-(a7)
X	    tst.l   d0
X	    beq.s   pb1
X	    lsl.l   #2,d0
X	    move.l  d0,a1
X	    moveq   #0,d3
X	    move.b  (a1)+,d3
X	    subq    #1,d3
X	    move.l  ptr(PC),d0
X	    lea     out,a0
Xpb2	    move.b  (a1)+,0(a0,d0)
X	    beq.s   1$
X	    addq.b  #1,d0
X	    dbf     d3,pb2
X1$	    move.l  d0,ptr
Xpb1	    movem.l (a7)+,d3/a0-a1
X	    rts
X
X;compare strings
X;a0/a1 = pointers to string
X;returns d0 = true(0) false(1), d1 = length
Xstrcmp	    movem.l a0-a1,-(a7)
X	    moveq   #0,d0
X	    move.l  d0,d1
Xsrc2	    move.b  (a0)+,d0
X	    beq.s   src1
X	    cmp.b   #10,d0
X	    beq.s   src1
X	    addq    #1,d1
X	    cmp.b   (a1)+,d0
X	    beq.s   src2
X	    bra.s   src3
Xsrc1	    move.b  0(a1),d0
Xsrc3	    movem.l (a7)+,a0-a1
X	    rts
X
Xstrbuf	    movem.l d0/a1-a2,-(a7)
X	    move.l  a0,a1
X	    lea     buffer,a2
X1$	    move.b  (a1)+,d0
X	    cmp.b   #10,d0
X	    beq.s   2$
X	    cmp.b   #' ',d0
X	    beq.s   2$
X	    or.b    #' ',d0
X	    beq.s   2$
X	    move.b  d0,(a2)+
X	    bra.s   1$
X2$	    clr.b   (a2)+
X	    movem.l (a7)+,d0/a1-a2
X	    rts
X
X;compare bcpl string with string
X;a0 = pointer to string
X;a2 = bcpl-pointer to bcpl-string
X;returns d0 = true(0) false(1)
Xstrbcmp     movem.l d1/a0/a2,-(a7)
X	    moveq   #0,d0
X	    moveq   #0,d1
X	    adda.l  a2,a2
X	    adda.l  a2,a2
X	    move.b  (a2)+,d1
X	    beq.s   stb1
X	    subq    #1,d1
Xstb2	    cmp.b   (a2)+,(a0)+
X	    bne.s   stb1
X	    dbf     d1,stb2
X	    moveq   #1,d0
Xstb1	    movem.l (a7)+,d1/a0/a2
X	    rts
X
X;convert long to decimal
X;d0 = value
X;d3 bit 0 = left/right justified
X;d3 bit 1 = write/leave
X;returns string in 'buffer'
Xlongdec     movem.l d1-d2/a1-a2,-(a7)
X	    lea     binarea+8(PC),a1
X	    move.l  #'    ',-8(a1)
X	    move.l  #'    ',-4(a1)
X	    clr.b   0(a1)
X	    subq    #1,a1
X	    cmp     #2,d3
X	    bne.s   ld5
X	    clr.b   0(a1)
Xld5	    moveq   #1,d2
Xld2	    addq    #1,d2
X	    moveq   #$a,d1
X	    bsr     div
X	    addi.l  #$30,d1
X	    move.b  d1,-(a1)
X	    tst.l   d0
X	    bne.s   ld2
X
X	    btst    #0,d3
X	    bne.s   ld1
X	    lea     binarea(PC),a2
X	    cmpa.l  a2,a1
X	    bne.s   ld3
X	    subq.l  #1,ptr
X	    bra.s   ld1
Xld3	    move.b  0(a1),(a2)+
X	    move.b  #' ',(a1)+
X	    dbf     d2,ld3
Xld1	    cmp     #2,d3
X	    beq.s   ld4
X	    move.l  #binarea,d0
X	    bsr     putstr
Xld4	    movem.l (a7)+,d1-d2/a1-a2
X	    rts
X
X;write UBYTE
X;d3 = value
Xbytedec     bsr     dec
X	    move.l  #decimal,d0
X	    bra.s   pm1
X
X;write signed byte
X;d3 = value
Xplusmins    movem.l d5/a3,-(a7)
X	    move.w  #$2020,minus
X	    move.b  d3,d5
X	    bpl.s   2$
X	    neg.b   d3
X2$	    bsr.s   dec
X	    tst.b   d5
X	    bpl.s   1$
X	    move.l  d0,a3
X	    move.b  #'-',-(a3)
X1$	    movem.l (a7)+,d5/a3
X	    move.l  #minus+1,d0
Xpm1	    bra     putstr
X
Xdec	    movem.l d3/a3,-(a7)
X	    move.l  #$20202020,decimal
X	    and.l   #$ff,d3
X	    lea     decimal+3(PC),a3
Xbloop	    tst.b   d3
X	    beq.s   bend
X	    divu    #10,d3
X	    swap    d3
X	    ori.b   #'0',d3
X	    move.b  d3,-(a3)
X	    clr.w   d3
X	    swap    d3
X	    bra.s   bloop
Xbend	    cmpa.l  #decimal+3,a3
X	    bne     1$
X	    move.b  #'0',-(a3)
X1$	    move.l  a3,d0
X	    movem.l (a7)+,d3/a3
X	    rts
X
X;write a string, move cursor into next line
X;d0 = pointer to text
Xputnam	    bsr     putstr
Xputnam1     tst.b   d0
X	    beq.s   ncr
X	    bsr     newline
Xncr	    rts
X
X;write one char
X;d0 = char
Xputchar     movem.l d1/a0,-(a7)
X	    move.l  ptr(PC),d1
X	    lea     out,a0
X	    move.b  d0,0(a0,d1)
X	    addq.l  #1,ptr
X	    movem.l (a7)+,d1/a0
X	    rts
X
X;write a string, strings are only put into the output buffer when
X;a LF is detected
X;d0 = pointer to string
X;returns d0 = cursor position
Xputstr	    movem.l d1-d7/a0-a6,-(a7)
X	    move.b  #1,printed
X	    move.l  d0,a2
X	    lea     out,a3
X	    move.l  ptr(PC),d0
X	    move.l  a2,d5
X	    bne     pst1
X	    lea     longnix(PC),a2
X
Xpst1	    move.b  (a2)+,d1
X	    cmpi.b  #13,d1
X	    beq     pst1
X	    cmpi.b  #10,d1
X	    beq.s   lineend
X	    move.b  d1,0(a3,d0)
X	    beq     prend
X	    cmp     #100,d0
X	    bge.s   pst1
X	    addq    #1,d0
X	    bra.s   pst1
X
Xlineend     tst.b   fromfile
X	    beq.s   1$
X	    moveq   #0,d0
X	    bra     prend
X
X1$	    tst.l   lastprinted
X	    bne.s   2$
X	    bsr     killpage
X
X2$	    addq    #1,d0
X	    move.l  d0,-(a7)
X	    add     #14,d0
X	    moveq   #0,d1
X	    CALL    AllocMem,_SysBase(PC)
X	    move.l  (a7)+,d1
X	    tst.l   d0
X	    beq     prend
X	    move.l  d0,a0
X	    move.w  d1,12(a0)
X	    cmp.w   maxllength(PC),d1
X	    ble.s   7$
X	    move.w  d1,maxllength
X7$	    move.l  node,8(a0)
X	    clr.l   node
X	    clr.l   0(a0)
X
X	    move.l  lastprinted(PC),d0
X	    move.l  d0,4(a0)
X	    bne.s   3$
X	    move.l  a0,outchain
X	    bra.s   4$
X3$	    move.l  d0,a1
X	    move.l  a0,0(a1)
X4$	    move.l  a0,lastprinted
X	    move.b  #' ',14(a0)
X	    subq    #1,d1
X	    lea     15(a0),a0
X	    lea     out,a1
X	    subq    #1,d1
X	    bmi.s   6$
X5$	    move.b  (a1)+,(a0)+
X	    dbf     d1,5$
X6$	    move.l  numlines(PC),d2
X	    cmp.l   maxlines(PC),d2
X	    ble.s   8$
X
X	    move.l  outchain(PC),a1
X	    move.l  0(a1),a2
X	    move.l  a2,outchain
X	    clr.l   4(a2)
X	    move.w  12(a1),d0
X	    add.w   #14,d0
X	    ext.l   d0
X	    CALL    FreeMem,_SysBase(PC)
X	    bra.s   9$
X
X8$	    addq.l  #1,d2
X	    move.l  d2,numlines
X
X9$	    moveq   #0,d0
X	    move.l  d0,d5
X	    tst.b   addlines
X	    beq     pst1
X	    bsr     addline
X	    bra     pst1
Xprend	    move.l  d0,ptr
X	    movem.l (a7)+,d1-d7/a0-a6
X	    rts
X
X;Kill output buffer
Xkillpage    movem.l d0-d7/a0-a6,-(a7)
X	    tst.l   outchain
X	    beq.s   2$
X	    move.l  outchain(PC),a1
X	    bsr     killlines
X	    clr.l   outchain
X	    clr.l   lastprinted
X	    clr.l   numlines
X	    clr.w   maxllength
X2$	    movem.l (a7)+,d0-d7/a0-a6
X	    rts
X
X;kill the remainder of the output buffer
Xkilllines   move.l  0(a1),-(a7)
X	    move.w  12(a1),d0
X	    ext.l   d0
X	    add     #14,d0
X	    CALL    FreeMem,_SysBase(PC)
X	    move.l  (a7)+,a1
X	    move.l  a1,d7
X	    bne.s   killlines
X	    rts
X
Xfreeblank   move.l  blanks(PC),d0
X	    beq.s   1$
X	    move.l  d0,a1
X	    move.w  colms(PC),d0
X	    ext.l   d0
X	    CALL    FreeMem,_SysBase(PC)
X	    clr.l   blanks
X1$	    rts
X
X;write a portion of the output buffer to the screen
Xblastout    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetAPen,gfxbase(PC)
X	    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetDrMd,gfxbase(PC)
X	    moveq   #0,d7
X
X	    move.w  loffset(PC),d2
X	    beq.s   7$
X	    move.w  colms(PC),d4
X	    add.w   d4,d2
X	    move.w  maxllength(PC),d3
X	    cmp.w   d3,d2
X	    ble.s   7$
X	    move.w  d3,d2
X	    sub.w   d4,d2
X	    bpl.s   8$
X	    moveq   #0,d2
X8$	    move.w  d2,loffset
X
X7$	    bsr     tstfirstlin
X
X1$	    tst.l   outchain
X	    beq.s   3$
X	    bsr     findline
X
X2$	    move.w  colms(PC),d5
X	    ext.l   d5
X	    move.w  loffset(PC),d4
X	    ext.l   d4
X	    moveq   #18,d6
X6$	    lea     14(a5,d4),a0
X	    move.w  12(a5),d3
X	    ext.l   d3
X	    bsr     blastline
X	    bge.s   3$
X	    tst.l   0(a5)
X	    beq.s   5$
X	    move.l  0(a5),a5
X	    bra     6$
X5$	    moveq   #0,d3
X	    bsr     blastline
X	    bcs.s   5$
X3$	    rts
X
X;get a pointer to a line  (line # in d0)
Xfindline    move.l  outchain(PC),d1
X	    beq     2$
X	    move.l  d1,a5
X1$	    tst     d0
X	    beq.s   2$
X	    tst.l   0(a5)
X	    beq.s   2$
X	    move.l  0(a5),a5
X	    dbf     d0,1$
X2$	    rts
X
X;check if the display is as 'full' as possible
Xtstfirstlin move.l  firstline(PC),d0
X	    move.l  d0,d2
X	    add.w   rows(PC),d2
X	    cmp.l   numlines(PC),d2
X	    bmi.s   1$
X	    move.l  numlines(PC),d2
X	    sub.w   rows(PC),d2
X	    bpl.s   4$
X	    moveq   #0,d2
X4$	    move.l  d2,d0
X	    move.l  d2,firstline
X1$	    rts
X
X;display one line, fill the gap between the end of the line and
X;the end of the window with spaces.
X;d6 = ypos, d5=colms, d3= linelength, d7= line # in window, a0 = text
X
Xblastline   move    d6,d1
X	    moveq   #6,d0
X	    move.l  rastport(PC),a1
X	    CALL    Move,gfxbase(PC)
X	    sub.w   d4,d3
X	    bpl.s   7$
X	    moveq   #0,d3
X	    bra.s   6$
X7$	    cmp.w   d5,d3
X	    bmi.s   4$
X	    move.w  d5,d3
X4$	    move.l  d3,d0
X	    beq.s   6$
X	    CALL    Text,gfxbase(PC)
X6$	    move.l  d5,d0
X	    sub.l   d3,d0
X	    ble.s   5$
X	    move.l  blanks(PC),a0
X	    move.l  rastport(PC),a1
X	    CALL    Text,gfxbase(PC)
X5$	    addq    #8,d6
X	    addq    #1,d7
X	    cmp.w   rows(PC),d7
X	    rts
X
X;Write pointer, display '-------' if empty
Xhexan	    tst.l   d0
X	    bne.s   hexa
X	    bra     putstr
X
X;Write 8 byte hex value
X;d0 = value
Xhexa	    bsr     gthex
X	    bra     putstr
X
Xgthex	    movem.l d1-d7/a0-a6,-(a7)
X	    moveq.l #7,d5
X	    lea     hexarea(PC),a1
X	    lea     hextab(PC),a0
X	    moveq   #0,d2
Xhexloop     move.b  d0,d2
X	    and.b   #15,d2
X	    move.b  0(a0,d2),0(a1,d5)
X	    lsr.l   #4,d0
X	    dbf     d5,hexloop
X	    move.l  a1,d0
X	    movem.l (a7)+,d1-d7/a0-a6
X	    rts
X
X;Convert/write byte into binary string
X;d0 = value
Xbin	    movem.l d1-d7/a0-a6,-(a7)
X	    lea     binarea(PC),a0
X	    move.w  #$2020,8(a0)
X	    moveq.l #7,d4
Xbinloop     moveq.l #'0'/2,d1
X	    roxr.b  #1,d0
X	    roxl.b  #1,d1
X	    move.b  d1,0(a0,d4)
X	    dbf     d4,binloop
X	    move.l  a0,d0
X	    movem.l (a7)+,d1-d7/a0-a6
X	    bra     putstr
X
X;send a packet
X;a0 = msgport
X;dp_Type and dp_Arg1 have to be inizialized
Xcons1	    movem.l d0-d7/a0-a6,-(a7)
X	    move.l  #dp_Link,LN_NAME
X	    move.l  #mypacket,dp_Link
X	    move.l  replyport(PC),dp_Port
X	    lea     mypacket,a1
X	    CALL    PutMsg,_SysBase(PC)
X	    move.l  replyport,a0
X	    CALL    WaitPort,_SysBase(PC)
X	    move.l  replyport(PC),a0
X	    CALL    GetMsg,_SysBase(PC)
X	    movem.l (a7)+,d0-d7/a0-a6
X	    rts
X
X;32-bit division
X;d0 / d1
X;returns d0
Xdiv	    movem.l d2-d3,-(a7)
X	    tst.l   d1
X	    beq     div8
X	    swap    d1
X	    move.w  d1,d2
X	    bne.s   div1
X	    swap    d0
X	    swap    d1
X	    swap    d2
X	    move.w  d0,d2
X	    beq.s   div2
X	    divu    d1,d2
X	    move.w  d2,d0
Xdiv2	    swap    d0
X	    move.w  d0,d2
X	    divu    d1,d2
X	    move.w  d2,d0
X	    swap    d2
X	    move.w  d2,d1
X	    bra     div8
Xdiv1	    moveq   #$10,d3
X	    cmpi.w  #$80,d1
X	    bcc.s   div3
X	    rol.l   #8,d1
X	    subq.w  #8,d3
Xdiv3	    cmpi.w  #$800,d1
X	    bcc.s   div4
X	    rol.l   #4,d1
X	    subq.w  #4,d3
Xdiv4	    cmpi.w  #$2000,d1
X	    bcc.s   div5
X	    rol.l   #2,d1
X	    subq.w  #2,d3
Xdiv5	    tst.w   d1
X	    bmi.s   div6
X	    rol.l   #1,d1
X	    subq.w  #1,d3
Xdiv6	    move.w  d0,d2
X	    lsr.l   d3,d0
X	    swap    d2
X	    clr.w   d2
X	    lsr.l   d3,d2
X	    swap    d3
X	    divu    d1,d0
X	    move.w  d0,d3
X	    move.w  d2,d0
X	    move.w  d3,d2
X	    swap    d1
X	    mulu    d1,d2
X	    sub.l   d2,d0
X	    bcc.s   div7
X	    subq.w  #1,d3
X	    add.l   d1,d0
Xdiv7	    moveq   #0,d1
X	    move.w  d3,d1
X	    swap    d3
X	    rol.l   d3,d0
X	    swap    d0
X	    exg     d1,d0
Xdiv8	    movem.l (a7)+,d2-d3
X	    rts
X
X;install a input-handler
Xinstallh    pea     0
X	    pea     xopsleep
X	    LIBCALL CreatePort
X	    addq    #8,a7
X	    move.l  d0,InputMsg
X	    move.l  d0,-(a7)
X	    LIBCALL CreateStdIO
X	    addq    #4,a7
X	    move.l  d0,InRequest
X	    move.l  d0,a1
X	    lea     devicenam(PC),a0
X	    moveq   #0,d0
X	    moveq   #0,d1
X	    CALL    OpenDevice,_SysBase(PC)
X	    move.l  d0,devstatus
X	    movea.l InRequest(PC),a1
X	    move.l  #InInterrupt,40(a1)
X	    move.w  #9,28(a1)
X	    CALL    DoIO,_SysBase(PC)
X	    move.l  d0,iostatus
X	    move.l  #-1,d0
X	    CALL    AllocSignal,_SysBase(PC)
X	    moveq   #0,d1
X	    bset    d0,d1
X	    move.l  d1,mysignal
X	    rts
X
X;remove handler
Xremoveh     movea.l InRequest(PC),a1
X	    move.l  #InInterrupt,40(a1)
X	    move.w  #10,28(a1)
X	    CALL    DoIO,_SysBase(PC)
X	    movea.l InRequest(PC),a1
X	    CALL    CloseDevice,_SysBase(PC)
X	    move.l  InRequest,-(a7)
X	    LIBCALL DeleteStdIO
X	    addq    #4,a7
X	    move.l  InputMsg,-(a7)
X	    LIBCALL DeletePort
X	    addq    #4,a7
X	    rts
X
X;this is the handler, it checks if amiga-amiga-x
X;has been pressed and signals it to our task
XKeyhandler  tst.b   running
X	    bne.s   endhandler
X	    cmp.b   #1,4(a0)
X	    bne.s   endhandler
X	    move.w  8(a0),d0
X	    andi.w  #$c0,d0
X	    cmpi.w  #$c0,d0
X	    bne.s   endhandler
X	    cmp.w   #$32,6(a0)
X	    bne.s   endhandler
Xwakeup	    move.l  a0,-(a7)
X	    movea.l mytask(PC),a1
X	    move.l  mysignal(PC),d0
X	    CALL    Signal,_SysBase(PC)
X	    move.l  (a7)+,a0
X	    clr.b   4(a0)
Xendhandler  move.l  a0,d0
X	    rts
X
Xsnoop	    bsr     cls
X	    bsr     nodenam
X	    moveq   #1,d7
X	    lea     TReNode(PC),a4
X	    bsr     findnam
X	    tst.b   d7
X	    bne.s   1$
X	    move.l  #stperr,d0
X	    bra     putnam
X1$	    move.l  d0,captask
X	    pea     0
X	    pea     memportname
X	    LIBCALL CreatePort
X	    addq    #8,a7
X	    move.l  d0,snoopport
X	    beq     tm6
X
X	    bsr     replyintui
X	    move.b  #1,addlines
X	    lea     snoophead(PC),a0
X	    bsr     puthead
X	    move.l  _SysBase(PC),a1
X	    move.l  -196(a1),oldalloc
X	    move.l  -208(a1),oldfree
X	    move.l  #capmalloc,d0
X	    move.l  #-198,a0
X	    CALL    SetFunction,_SysBase(PC)
X	    move.l  _SysBase(PC),a1
X	    move.l  #capmfree,d0
X	    move.l  #-210,a0
X	    CALL    SetFunction,_SysBase(PC)
X	    clr.b   bool
X	    clr.b   cbreak
X
Xwaitmem     move.l  snoopport(PC),a0
X	    moveq   #0,d1
X	    move.b  15(a0),d1
X	    bset    d1,d0
X	    move.l  d0,auxsig
X	    bsr     processmsgs
X
Xtm7	    move.l  mytask(PC),a0
X	    move.l  snoopport(PC),a0
X	    CALL    GetMsg,_SysBase(PC)
X	    tst.l   d0
X	    bne     tm8
X	    tst.b   cbreak
X	    bne     snoopend
X	    bra     waitmem
Xtm8	    move.l  d0,a3
X	    move.l  20(a3),d3
X	    btst    #31,d3
X	    beq     freed
X	    move.l  #allok,d0
X	    bsr     putstr
X	    lea     memname(PC),a2
X	    lea     membit(PC),a4
X	    moveq   #4,d5
Xtm2	    move.l  0(a4),d4
X	    btst    d4,d3
X	    beq.s   tm1
X	    move.l  0(a2),d0
X	    bsr     putstr
Xtm1	    addq    #4,a2
X	    addq    #4,a4
X	    dbf     d5,tm2
X	    moveq   #26,d1
X	    bsr     tab
X	    move.l  24(a3),d0
X	    move.l  d0,d3
X	    bsr     hexa
X	    move.l  28(a3),d0
X	    bne.s   tm3
X	    move.l  #failed,d0
X	    bsr     putstr
X	    moveq   #53,d1
X	    bsr     tab
X	    bra     tm4
Xtm3	    bsr     hexa
X	    move.l  28(a3),d0
X	    add.l   d3,d0
X	    bsr     hexa
X	    bra     tm4
X
Xfreed	    move.l  #free,d0
X	    bsr     putstr
X	    move.b  #'-',d0
X	    moveq   #18,d1
Xtm9	    bsr     putchar
X	    dbf     d1,tm9
X	    move.b  #' ',d0
X	    bsr     putchar
X	    move.l  d3,d0
X	    bsr     hexa
X	    move.l  24(a3),d0
X	    bsr     hexa
X	    move.l  24(a3),d0
X	    add.l   d3,d0
X	    bsr     hexa
X
Xtm4	    move.l  32(a3),d0
X	    bsr     hexa
X	    bsr     newline
X	    move.w  18(a3),d0
X	    ext.l   d0
X	    move.l  a3,a1
X	    CALL    FreeMem,_SysBase(PC)
X	    bra     tm7
X
Xsnoopend    move.l  _SysBase(PC),a1
X	    move.l  oldalloc(PC),d0
X	    move.l  #-198,a0
X	    CALL    SetFunction,_SysBase(PC)
X	    move.l  _SysBase(PC),a1
X	    move.l  oldfree,d0
X	    move.l  #-210,a0
X	    CALL    SetFunction,_SysBase(PC)
X	    move.l  snoopport,-(a7)
X	    LIBCALL DeletePort
X	    addq    #4,a7
X	    move.l  #stoped,d0
X	    bsr     putnam
X	    clr.b   addlines
X	    clr.l   auxsig
Xtm6	    rts
X
Xmemname     dc.l    memlarg,memclr,memfast,memchip,mempubl
Xmembit	    dc.l    17,16,2,1,0
X
Xcapmalloc   movem.l d0-d7/a0-a6,-(a7)
X	    move.l  _SysBase(PC),a6
X	    move.l  276(a6),d4
X	    cmp.l   captask(PC),d4
X	    bne.s   capm1
X	    tst.b   bool
X	    bne     capm1
X	    move.b  #1,bool
X	    moveq   #36,d6
X	    bsr     allocmsg
X	    beq     capm2
X	    bset    #31,d1
X	    move.l  d1,20(a5)
X	    move.l  d0,24(a5)
X	    move.l  60(a7),32(a5)
X	    move.l  a5,remembr
X	    movem.l (a7)+,d0-d7/a0-a6
X	    bsr     memalloc
X	    movem.l d0-d7/a0-a6,-(a7)
X	    move.l  remembr(PC),a1
X	    move.l  d0,28(a1)
X	    move.l  snoopport,a0
X	    move.b  #5,8(a1)
X	    CALL    PutMsg,_SysBase(PC)
X	    clr.b   bool
X	    movem.l (a7)+,d0-d7/a0-a6
X	    rts
Xcapm2	    clr.b   bool
Xcapm1	    movem.l (a7)+,d0-d7/a0-a6
Xmemalloc    dc.w    $4ef9
Xoldalloc    dc.l    0
X
Xcapmfree    movem.l d0-d7/a0-a6,-(a7)
X	    move.l  _SysBase(PC),a6
X	    move.l  276(a6),d4
X	    cmp.l   captask(PC),d4
X	    bne.s   capf1
X	    tst.b   bool
X	    bne.s   capf1
X	    move.b  #1,bool
X	    moveq   #36,d6
X	    bsr     allocmsg
X	    beq.s   capf2
X	    move.l  d0,20(a5)
X	    move.l  a1,24(a5)
X	    move.l  60(a7),32(a5)
X	    move.l  snoopport,a0
X	    move.b  #5,8(a5)
X	    move.l  a5,a1
X	    CALL    PutMsg,_SysBase(PC)
Xcapf2	    clr.b   bool
Xcapf1	    movem.l (a7)+,d0-d7/a0-a6
X	    dc.w    $4ef9
Xoldfree     dc.l    0
X
Xallocmsg    movem.l d0-d1/a0-a1,-(a7)
X	    move.l  d6,d0
X	    move.l  #65536,d1
X	    bsr     memalloc
X	    tst.l   d0
X	    beq.s   alm1
X	    move.l  d0,a5
X	    move.w  d6,18(a5)
Xalm1	    movem.l (a7)+,d0-d1/a0-a1
X	    move.l  a5,d6
X	    rts
X
Xmyswitch    movem.l d0-d1/a0-a1,-(a7)
X	    move.l  _SysBase(PC),a0
X	    move.l  276(a0),d0
X	    move.l  tasksnum(PC),d1
X	    lea     cputime,a0
X	    subq.l  #1,d1
X	    bmi.s   swadd
Xsw0	    cmp.l   (a0)+,d0
X	    dbeq    d1,sw0
X	    tst     d1
X	    bmi.s   swadd
Xswi1	    add.l   #1,508(a0)
Xswgo	    movem.l (a7)+,d0-d1/a0-a1
X	    dc.w    $4ef9
Xoldswitch   dc.l    0
Xswadd	    cmp.l   #125,tasksnum
X	    bge.s   swgo
X	    addq.l  #1,tasksnum
X	    move.l  d0,0(a0)
X	    move.l  #1,512(a0)
X	    bra.s   swgo
X
Xcountio     addq.l #1,iocount
X	    moveq  #0,d0
Xcio1	    rts
X
Xiconbackdrp tst.b   iconifyon
X	    beq.s   1$
X	    lea     icnwindow,a0
X	    eor.l   #$100,14(a0)    ;wn_Flags
X1$	    rts
X
Xiconifyoff  tst.b   iconifyon
X	    beq.s   cio1
X	    clr.b   iconifyon
X	    tst.b   fromfile
X	    bne.s   1$
X	    move.l  wnptr(PC),d0
X	    beq.s   1$
X	    move.l  d0,a0
X	    lea     iconifgad,a1
X	    CALL    RemoveGadget,intuibase(PC)
X	    move.l  wnptr(PC),a0
X	    CALL    RefreshWindowFrame,intuibase(PC)
X1$	    move.l  #iconify,d0
X
Xkillseg     movem.l d1-d2/a0-a4,-(a7)
X	    subq    #4,d0
X	    move.l  4,a6
X	    move.l  276(a6),a4
X	    move.l  128(a4),d1
X	    lsl.l   #2,d1
X	    move.l  d1,a3
X	    move.l  12(a3),d1
X	    bne.s   2$
X	    move.l  172(a4),d1
X	    lsl.l   #2,d1
X	    move.l  d1,a4
X	    move.l  60(a4),d1
X
X2$	    lsl.l   #2,d1
X	    cmp.l   d0,d1
X	    beq.s   4$
X	    move.l  d1,a4
X	    move.l  0(a4),d1
X	    beq.s   5$
X	    bra.s   2$
X
X4$	    move.l  d1,a0
X	    move.l  0(a0),0(a4)
X	    clr.l   0(a0)
X	    lsr.l   #2,d1
X	    CALL    UnLoadSeg,dosbase(PC)
X	    movem.l (a7)+,d1-d2/a0-a4
X5$	    rts
X
Xalert	    bsr     stoptimer
X	    move.l  excpttask(PC),d0
X	    bne.s   alert1
X	    move.l  #noguru,d0
X	    bra     putnam
Xalert1	    move.l  #softfail,d0
X	    bsr     putstr
X	    move.l  excpttask(PC),a0
X	    move.l  10(a0),d0
X	    bsr     putnam
X	    cmp.l   #3,excpterror
X	    bne.s   1$
X	    move.l  #addrserr,d0
X	    bsr     putstr
X	    move.l  excptaddr(PC),d0
X	    bsr     hexa
X	    bsr     newline
X1$	    move.l  #procount,d0
X	    bsr     putstr
X	    move.l  excptpc(PC),d0
X	    bsr     hexa
X	    bsr     newline
X	    move.l  #gurutxt,d0
X	    bsr     putstr
X	    move.l  excpterror(PC),d0
X	    bsr     hexa
X	    lea     out,a0
X	    move.l  ptr(PC),d0
X	    move.b  #'.',-1(a0,d0)
X	    move.l  excpttask(PC),d0
X	    bsr     hexa
X	    bra     newline
X
Xshowguru    bsr     alert
X	    tst.b   ownscreen
X	    bne.s   5$
X	    move.l  wnptr(PC),a0
X	    CALL    WindowToFront,intuibase(PC)
X	    bra.s   2$
X5$	    move.l  screenptr,a0
X	    CALL    ScreenToFront,intuibase(PC)
X2$	    move.l  #whatnow,d0
X	    bsr     putnam
X	    clr.l   oldpageend
X	    bsr     readline
X
X	    cmp.b   #'i',inputbuffer
X	    beq.s   4$
X1$	    cmp.b   #'k',inputbuffer
X	    bne.s   2$
X	    move.l  excpttask(PC),a1
X	    tst.l   22(a1)
X	    bne.s   3$
X	    CALL    RemTask,_SysBase(PC)
X	    bra.s   4$
X3$	    move.l  a1,d0
X	    bsr     canok
X4$	    clr.l   lastprinted
X	    rts
X
Xmyaddtask   move.l  a3,-(a7)
X	    lea     mytrap(PC),a3
X	    move.l  50(a1),d0
X	    beq.s   1$
X	    cmp.l   oldtrap(PC),d0
X	    beq.s   1$
X	    lea     myproctrap(PC),a3
X	    cmp.l   oldproctrap(PC),d0
X	    bne.s   2$
X1$	    move.l  a3,50(a1)
X2$	    move.l  (a7)+,a3
X	    dc.w    $4ef9
XOldAddTask  dc.l    0
X
Xmyproctrap  bsr     traphandle
X	    dc.w    $4ef9
Xoldproctrap dc.l    0
X
Xmytrap	    bsr     traphandle
X	    moveq   #0,d0
X	    CALL    Wait,_SysBase(PC)
X	    dc.w    $4ef9
Xoldtrap     dc.l    0
X
Xtraphandle  movem.l d0-d7/a0-a6,$180
X	    move.l  4,a6
X	    move.l  276(a6),excpttask
X	    move.l  4(a7),d0
X	    cmp.l   #9,d0
X	    beq.s   2$
X	    move.l  d0,excpterror
X	    moveq   #10,d1
X	    cmp.l   #3,d0
X	    bne.s   1$
X	    move.l  0(a7,d1.w),excptaddr
X	    moveq   #18,d1
X1$	    move.l  0(a7,d1.w),excptpc
X	    move.l  mytask(PC),a1
X	    move.l  trapsignal(PC),d0
X	    jsr     _LVOSignal(a6)
X2$	    movem.l $180,d0-d7/a0-a6
X	    rts
X
Xtrapguru    tst.b   wanttraps
X	    bne     restoretrap
X	    move.b  #1,wanttraps
X
Xaddtraps    tst.b   wanttraps
X	    beq     5$
X	    move.l  304(a6),oldtrap         ;Original EXEC trap handler
X	    moveq   #-1,d0
X	    CALL    AllocSignal,_SysBase(PC)
X	    moveq   #0,d1
X	    bset    d0,d1
X	    move.l  d1,trapsignal
X	    move.l  #_LVOAddTask,a0	    ;need a new AddTask() to change
X	    move.l  2(a6,a0),OldAddTask     ;AmigaDos's default trap handler
X	    move.l  a6,a1
X	    move.l  #myaddtask,d0
X	    CALL    SetFunction,_SysBase(PC)
X	    CALL    Forbid,_SysBase(PC)     ;change the trap handler of
X	    moveq   #0,d5		    ;aleady running tasks
X	    bsr     getaskdat		    ;get task stucture pointers
X1$	    tst.b   entries
X	    beq.s   2$
X	    lea     -16(a5),a5
X	    move.l  0(a5),a4                ;pointer to a task structure
X	    lea     myproctrap(PC),a0
X	    move.l  50(a4),d0               ;Task->tc_TrapCode
X	    cmp.l   oldproctrap(PC),d0      ;AmigaDos Handler ?
X	    beq.s   3$
X	    lea     mytrap(PC),a0           ;EXEC Handler ?
X	    cmp.l   oldtrap(PC),d0
X	    bne.s   4$			    ;must be a custom one, skip it
X3$	    move.l  a0,50(a4)               ;replace it
X4$	    subq.b  #1,entries
X	    bra.s   1$
X2$	    CALL    Permit,_SysBase(PC)
X5$	    rts
X
Xrestoretrap tst.b   wanttraps
X	    beq.s   6$
X	    tst.b   fromfile
X	    bne.s   5$
X	    move.l  #_LVOAddTask,a0
X	    move.l  OldAddTask(PC),d0
X	    move.l  _SysBase(PC),a1
X	    CALL    SetFunction,_SysBase(PC)
X	    CALL    Forbid,_SysBase(PC)
X	    bsr     getaskdat
X1$	    tst.b   entries
X	    beq.s   2$
X	    lea     -16(a5),a5
X	    move.l  0(a5),a4
X	    move.l  oldproctrap(PC),a0
X	    move.l  50(a4),d0
X	    cmp.l   #myproctrap,d0
X	    beq.s   3$
X	    move.l  oldtrap(PC),a0
X	    cmp.l   #mytrap,d0
X	    bne.s   4$
X3$	    move.l  a0,50(a4)
X4$	    subq.b  #1,entries
X	    bra.s   1$
X2$	    CALL    Permit,_SysBase(PC)
X	    clr.l   trapsignal
X5$	    clr.b   wanttraps
X6$	    rts
X
X;save the contents of the output buffer
X;to a file
Xsaveoutput  bsr     nodenam2
X	    tst.b   0(a5)
X	    beq     syntax
X	    move.l  a5,d1
X	    move.l  #1006,d2
X	    CALL    Open,dosbase(PC)
X	    move.l  d0,d5
X	    bne.s   1$
X	    move.l  #openerr,d0
X	    bsr     putstr
X	    move.l  a5,d0
X	    bra     putnam
X1$	    move.l  outchain(PC),d0
X	    beq.s   3$
X2$	    move.l  d0,a5
X	    move.w  12(a5),d3
X	    beq.s   4$
X	    ext.l   d3
X	    lea     14(a5),a1
X	    move.l  a1,d2
X	    move.l  d5,d1
X	    CALL    Write,dosbase(PC)
X	    tst.l   d0
X	    ble.s   3$
X4$	    moveq   #1,d3
X	    move.l  d5,d1
X	    move.l  #cr,d2
X	    CALL    Write,dosbase(PC)
X	    tst.l   d0
X	    ble.s   3$
X	    move.l  0(a5),d0
X	    bne.s   2$
X3$	    move.l  d5,d1
X	    CALL    Close,dosbase(PC)
X	    rts
X
Xgrabtimerio lea     tiohead(PC),a0
X	    bsr     puthead
X	    move.b  timeout(PC),d4
X	    move.b  #255,timeout
X	    bsr     starttimer
X	    move.b  d4,timeout
X	    lea     timerio,a1
X	    CALL    Disable,_SysBase(PC)
X2$	    move.l  0(a1),d2
X	    beq.s   1$
X	    move.l  d2,a1
X	    bra.s   2$
X1$	    CALL    Enable,_SysBase(PC)
X	    lea     -4(a1),a5
X	    bsr     stoptimer
X	    lea     buffer,a4
X	    moveq   #1,d4
X	    bsr     gettrq
X
X	    lea     timerio,a0
X	    lea     dummy,a1
X	    moveq   #40,d0
X	    CALL    CopyMem,_SysBase(PC)
X
X	    lea     dummy,a1
X	    lea     timernam(PC),a0
X	    moveq   #0,d1
X	    moveq   #0,d0
X	    CALL    OpenDevice,_SysBase(PC)
X
X	    lea     dummy,a1
X	    move.l  #1<<30,32(a1)
X	    CALL    SendIO,_SysBase(PC)
X
X	    lea     dummy,a5
X	    CALL    Disable,_SysBase(PC)
X8$	    move.l  0(a5),d2
X	    beq.s   7$
X	    move.l  d2,a5
X	    bra.s   8$
X7$	    CALL    Enable,_SysBase(PC)
X	    lea     -4(a5),a5
X
X	    lea     dummy,a1
X	    CALL    AbortIO,_SysBase(PC)
X	    lea     timerio,a1
X	    CALL    WaitIO,_SysBase(PC)
X	    move.w  timersig,d0
X	    moveq   #0,d1
X	    bset    d0,d1
X	    moveq   #0,d0
X	    CALL    SetSignal,_SysBase(PC)
X
X	    moveq   #0,d4
X	    bsr     gettrq
X
X	    lea     dummy,a1
X	    CALL    CloseDevice,_SysBase(PC)
X
X	    clr.l   (a4)+
X	    lea     -22(a4),a2
X	    moveq   #18,d2
X	    bsr     sortlist
X
X	    lea     buffer,a5
X5$	    move.l  (a5)+,d0
X	    beq.s   6$
X	    bsr     hexa
X	    move.w  (a5)+,d0
X	    ext.l   d0
X	    mulu    #9,d0
X	    add.l   #timerunits,d0
X	    bsr     putstr
X	    move.l  (a5)+,d3
X	    mulu    #10,d3
X	    move.l  (a5)+,d0
X	    move.l  #100000,d1
X	    bsr     div
X	    add.l   d3,d0
X	    cmp.l   #2559,d0
X	    ble.s   9$
X	    move.l  #whatsthis,d0
X	    bsr     putstr
X	    bra.s   10$
X9$	    moveq   #1,d6
X	    bsr     putfrac
X10$	    move.b  #' ',d0
X	    bsr     putchar
X	    move.l  (a5)+,a1
X	    move.l  10(a1),d0
X	    bsr     putnam
X	    bra.s   5$
X6$	    rts
X
Xgettrq	    CALL    Disable,_SysBase(PC)
X3$	    move.l  0(a5),a5
X	    tst.l   0(a5)
X	    beq.s   4$
X	    move.l  a5,(a4)+
X	    move.w  d4,(a4)+
X	    move.l  32(a5),(a4)+
X	    move.l  36(a5),(a4)+
X	    move.l  14(a5),a1
X	    move.l  16(a1),(a4)+
X	    bra.s   3$
X4$	    CALL    Enable,_SysBase(PC)
X	    rts
X
X
X;check if the timer is runnig, start it if not
Xstarttimer  lea     timerio,a1
X	    cmp.b   #5,8(a1)
X	    beq.s   1$
X	    moveq   #0,d0
X	    move.l  d0,36(a1)
X	    move.b  timeout(PC),d0
X	    beq.s   1$
X	    move.l  d0,32(a1)
X	    move.w  #9,28(a1)
X	    CALL    SendIO,_SysBase(PC)
X1$	    rts
X;Abort a timer request, if pending
Xstoptimer   lea     timerio,a1
X	    cmp.b   #5,8(a1)
X	    bne.s   1$
X	    CALL    AbortIO,_SysBase(PC)
X	    lea     timerio,a1
X	    CALL    WaitIO,_SysBase(PC)
X1$	    move.w  timersig,d0
X	    moveq   #0,d1
X	    bset    d0,d1
X	    moveq   #0,d0
X	    CALL    SetSignal,_SysBase(PC)
X	    rts
X;Xoper main loop, process all incoming messages
Xprocessmsgs move.l  wnptr(PC),a0
X	    moveq   #0,d0
X	    move.w  intuisig(PC),d1
X	    bset    d1,d0
X	    move.w  timersig(PC),d1
X	    bset    d1,d0
X	    or.w    #4096,d0
X	    or.l    auxsig(PC),d0
X	    tst.l   auxsig
X	    bne.s   1$
X	    or.l    trapsignal(PC),d0
X1$	    CALL    Wait,_SysBase(PC)
X
X	    move.l  d0,tasksigs
X
X	    move.l  trapsignal(PC),d1
X	    and.l   d0,d1
X	    beq.s   ctrl_c
X	    tst.b   gotguru
X	    bne.s   ctrl_c
X	    move.b  #1,gotguru
X	    bsr     showguru
X	    clr.b   gotguru
X
Xctrl_c	    move.q  #12,d1
X	    bsr     testsig
X	    bne     exit
X
X
Xtimermsg    move.w  timersig(PC),d1
X	    bsr     testsig
X	    beq     intuimsgs
X	    tst.w   repeat
X	    bne.s   1$
X	    bsr     showwhat
X	    bra.s   intuimsgs
X1$	    move.w  repeatlen,d0
X	    lea     repeatbuffer,a2
X	    lea     dummy,a1
X	    move.w  d0,d1
X2$	    move.b  (a2)+,(a1)+
X	    dbf     d1,2$
X	    bsr     cli
X	    bsr     starttimer
X
Xintuimsgs   move.w  intuisig(PC),d1
X	    bsr     testsig
X	    beq     processnxtmsg
Xnextimsg    move.l  wnptr(PC),a0
X	    move.l  $56(a0),a0
X	    CALL    GetMsg,_SysBase(PC)
X	    tst.l   d0
X	    beq     processnxtmsg
X	    move.l  d0,intuimsg
X
X	    move.l  d0,a0
X	    move.l  20(a0),d0
X
X	    cmp.l   #$200,d0		;CloseWindow
X	    bne.s   1$
X	    tst.b   addlines
X	    beq     exitall
X	    move.b  #1,cbreak
X	    bra     intuiend
X
X1$	    cmp.l   #2,d0		;ResizeWindow
X	    bne.s   2$
X	    bsr     setupscreen
X	    bra     intuiend
X
X2$	    cmp.l   #4,d0		;refresh
X	    bne.s   22$
X	    bsr     putiline
X	    bsr     blastout
X	    bsr     UpdateIArea
X	    bra     intuiend
X
X22$	    tst.b   addlines
X	    bne     3$
X	    cmp.l   #$40,d0		;gadgetup
X	    bne.s   3$
X	    tst.w   getanswer
X	    bne.s   3$
X	    bsr     replyintui
X	    bra     instback
X
X3$	    cmp.l   #$400,d0		;RawKey
X	    bne     notarawkey
X	    move.w  #$80,d0
X	    and.w   24(a0),d0
X	    bne     intuiend
X	    and.w   #$7f,24(a0)
X	    lea     ievent,a1
X	    move.b  #1,4(a1)
X	    move.l  24(a0),6(a1)
X	    move.w  26(a0),qualifier
X	    move.l  a1,a0
X	    lea     outevent,a1
X	    moveq   #20,d1
X	    suba.l  a2,a2
X	    CALL    RawKeyConvert,condev(PC)
X	    tst.l   d0
X	    beq     intuiend
X	    lea     inputbuffer,a1
X	    lea     outevent,a2
X	    move.w  curpos(PC),d4
X	    moveq   #0,d3
X	    tst.b   addlines
X	    bne     197$
X
X	    cmp.b   #$9b,0(a2)          ;CSI
X	    bne     110$
X
X	    cmp.b   #'?',1(a2)          ;help
X	    bne.s   399$
X	    tst.w   getanswer
X	    bne.s   399$
X	    bsr     stoptimer
X	    tst.w   bottomin
X	    bne.s   398$
X	    move.w  #1,bottomin
X	    clr.w   ibufferlen
X	    clr.w   curpos
X	    bsr     UpdateIArea
X398$	    move.l  #usetxt,d0
X	    bsr     putnam
X	    clr.l   lastprinted
X	    bsr     blastout
X	    bra.s   420$
X
X399$	    cmp.b   #'C',1(a2)          ;cursor right
X	    bne.s   400$
X	    cmp.w   ibufferlen(PC),d4
X	    bge.s   420$
X	    addq    #1,d4
X421$	    move.w  d4,curpos
X420$	    bra     100$
X
X400$	    cmp.b   #'D',1(a2)          ;cursor left
X	    bne.s   401$
X	    subq    #1,d4
X	    bpl.s   421$
X	    bra.s   420$
X
X401$	    cmp.b   #' ',1(a2)
X	    bne.s   402$
X
X	    cmp.b   #'@',2(a2)          ;shift right
X	    bne.s   403$
X
X404$	    cmp.w   ibufferlen(PC),d4
X	    bge.s   421$
X	    addq    #1,d4
X	    cmp.b   #' ',0(a1,d4)
X	    bne.s   404$
X405$	    cmp.w   ibufferlen(PC),d4
X	    bge.s   421$
X	    addq    #1,d4
X	    cmp.b   #' ',0(a1,d4)
X	    beq.s   405$
X	    bra.s   421$
X
X403$	    cmp.b   #'A',2(a2)          ;shift left
X	    bne.s   420$
X406$	    tst.w   d4
X	    beq.s   421$
X	    subq    #1,d4
X	    cmp.b   #' ',0(a1,d4)
X	    beq.s   406$
X407$	    tst.w   d4
X	    beq.s   421$
X	    subq    #1,d4
X	    cmp.b   #' ',0(a1,d4)
X	    bne.s   407$
X	    addq    #1,d4
X	    bra.s   421$
X
X402$	    cmp.b   #'A',1(a2)          ;cursor up
X	    bne.s   408$
X	    tst.w   bottomin
X	    bne.s   480$
X	    tst.w   curpos
X	    bne.s   480$
X
X	    clr.w   curpos
X	    clr.w   ibufferlen
X	    bsr     UpdateIArea
X	    bsr     clrcursor
X	    move.w  edline(PC),d3
X	    ext.l   d3
X	    tst.w   d3
X	    beq.s   481$
X	    subq    #1,d3
X	    cmp.l   firstline(PC),d3
X	    bge.s   481$
X	    move.l  d3,-(a7)
X	    subq.l  #1,firstline
X	    bsr     blastout
X	    move.l  (a7)+,d3
X481$	    move.w  d3,edline
X	    bsr     getcurpos
X	    bsr     putcursor
X	    bra     intuiend
X480$	    move.l  history(PC),a0
X	    tst.l   0(a0)
X	    beq.s   423$
X	    move.l  curhist(PC),a1
X	    cmp.l   a0,a1
X	    beq.s   409$
X	    move.l  4(a1),d0
X	    move.l  d0,curhist
X409$	    move.l  a1,gothline
X	    bsr     copyhistory
X423$	    bra     100$
X
X408$	    cmp.b   #'B',1(a2)          ;cursor down
X	    bne     410$
X	    tst.w   bottomin
X	    bne.s   414$
X	    tst.w   curpos
X	    bne.s   414$
X
X	    clr.w   curpos
X	    clr.w   ibufferlen
X	    bsr     UpdateIArea
X	    bsr     clrcursor
X	    move.w  edline(PC),d3
X	    ext.l   d3
X	    move.l  numlines(PC),d4
X	    subq    #1,d4
X	    cmp.l   d4,d3
X	    beq.s   490$
X	    move.l  firstline(PC),d2
X	    add.w   rows(PC),d2
X	    subq    #1,d2
X	    addq    #1,d3
X	    cmp.w   d2,d3
X	    ble.s   490$
X	    move.l  d3,-(a7)
X	    addq.l  #1,firstline
X	    bsr     blastout
X	    move.l  (a7)+,d3
X490$	    bra     481$
X414$	    move.l  curhist(PC),d0
X	    beq.s   423$
X	    move.l  d0,a1
X	    move.l  0(a1),a1
X	    tst.l   0(a1)
X	    bne.s   411$
X	    clr.l   gothline
X	    clr.w   curpos
X	    clr.w   ibufferlen
X	    bra     423$
X411$	    move.l  a1,curhist
X	    bra     409$
X
X410$	    cmp.b   #'T',1(a2)          ;shift up
X	    bne.s   412$
X	    tst.w   hnum
X	    beq     423$
X	    move.l  history(PC),a1
X	    move.l  a1,curhist
X	    bra     409$
X
X412$	    cmp.b   #'S',1(a2)          ;shift down
X	    bne     423$
X	    tst.w   hnum
X	    beq     423$
X	    move.l  history+8,curhist
X	    bra.s   414$
X
X110$	    moveq   #0,d3
X101$	    move.w  curpos(PC),d4
X	    tst     d0
X	    beq     100$
X	    cmp.b   #13,0(a2,d3)        ;return
X	    beq     got_enter
X
X	    cmp.b   #27,0(a2,d3)        ;esc
X	    bne     799$
X	    tst.w   getanswer
X	    bne     100$
X	    clr.b   insmode
X	    clr.w   ibufferlen
X	    move.w  #200,curpos
X	    bsr     UpdateIArea
X	    clr.w   curpos
X	    tst.w   bottomin
X	    bne.s   700$
X	    move.w  #1,bottomin
X	    bsr     getcurpos
X	    cmp.b   #5,timerstate
X	    bne.s   765$
X	    bsr     starttimer
X765$	    bra     100$
X
X700$	    move.b  timerio+8,timerstate
X	    bsr     stoptimer
X	    move.w  edline(PC),d0
X	    move.l  firstline(PC),d4
X	    cmp.w   d4,d0
X	    bmi.s   701$
X	    move.w  d4,d5
X	    add.w   rows(PC),d5
X	    cmp.w   d5,d0
X	    bmi.s   702$
X701$	    move.w  rows(PC),d0
X	    lsr.w   #1,d0
X	    add.w   d4,d0
X702$	    move.l  numlines(PC),d3
X	    subq    #1,d3
X	    cmp.w   d3,d0
X	    ble.s   703$
X	    move.w  d3,d0
X703$	    move.w  d0,edline
X	    sub.w   d4,d0
X	    lsl.w   #3,d0
X	    add.w   #18,d0
X	    move.w  d0,cposy
X	    clr.w   bottomin
X	    tst.w   loffset
X	    beq.s   704$
X	    clr.w   loffset
X	    bsr     blastout
X704$	    bra     100$
X
X799$	    cmp.b   #8,0(a2,d3)         ;Backspace
X	    bne.s   114$
X	    tst.w   d4
X	    beq     102$
X	    bsr     delchar
X	    subq    #1,d4
X	    move.w  d4,curpos
X	    bra     102$
X
X114$	    cmp.b   #127,0(a2,d3)       ;del
X	    bne.s   197$
X178$	    cmp.w   ibufferlen(PC),d4
X	    bge     102$
X	    addq    #1,d4
X	    bsr     delchar
X	    bra     102$
X
X197$	    cmp.b   #3,0(a2,d3)         ;ctrl c
X	    bne.s   104$
X	    move.b  #1,cbreak
X
X104$	    tst.b   addlines
X	    bne     processnxtmsg
X	    cmp.b   #$18,0(a2,d3)       ;ctrl x
X	    bne.s   300$
X	    clr.w   ibufferlen
X	    clr.w   curpos
X	    bra     100$
X
X300$	    cmp.b   #$19,0(a2,d3)       ;ctrl y
X	    bne.s   106$
X	    move.w  curpos,ibufferlen
X	    bra     100$
X
X106$	    move.w  #$100,d5		;NumPad
X	    and.w   qualifier(PC),d5
X	    beq     105$
X	    move.l  firstline(PC),d5
X
X	    cmp.b   #'7',0(a2,d3)       ;'Home'
X	    bne.s   200$
X	    moveq   #0,d5
X199$	    move.l  d5,firstline
X	    bsr     blastout
X	    tst.w   bottomin
X	    bne.s   196$
X	    move.w  edline(PC),d0
X	    move.l  firstline(PC),d1
X	    cmp.w   d1,d0
X	    bmi.s   190$
X	    add.w   rows(PC),d1
X	    cmp.w   d1,d0
X	    bmi.s   192$
X190$	    clr.w   curpos
X	    clr.w   ibufferlen
X	    move.w  rows(PC),d0
X	    lsr.w   #1,d0
X	    ext.l   d0
X	    add.l   firstline(PC),d0
X	    cmp.l   numlines(PC),d0
X	    bmi.s   191$
X	    move.l  numlines(PC),d0
X	    subq    #1,d0
X191$	    move.w  d0,edline
X192$	    bsr     getcurpos
X	    bsr     UpdateIArea
X196$	    bra     100$
X
X200$	    cmp.b   #'8',0(a2,d3)       ;'up arrow'
X	    bne.s   201$
X	    tst     d5
X	    beq     100$
X	    subq    #1,d5
X	    bra.s   199$
X
X201$	    cmp.b   #'9',0(a2,d3)       ;'PgUp'
X	    bne.s   203$
X	    sub.w   rows(PC),d5
X	    bpl.s   199$
X	    moveq   #0,d5
X	    bra.s   199$
X
X203$	    cmp.b   #'1',0(a2,d3)       ;'End'
X	    bne.s   205$
X222$	    move.l  numlines(PC),d5
X	    sub.w   rows(PC),d5
X	    bpl     199$
X	    moveq   #0,d5
X204$	    bra     199$
X
X205$	    cmp.b   #'2',0(a2,d3)       ;'down arrow'
X	    bne.s   206$
X	    move.l  d5,d2
X	    add.w   rows(PC),d2
X	    cmp.l   numlines(PC),d2
X	    bge     100$
X	    addq    #1,d5
X	    bra     199$
X
X206$	    cmp.b   #'3',0(a2,d3)       ;'PgDn'
X	    bne.s   500$
X	    add.w   rows(PC),d5
X	    move.l  d5,d2
X	    add.w   rows(PC),d2
X	    cmp.l   numlines(PC),d2
X	    bge.s   222$
X	    bra     199$
X
X500$	    cmp.b   #'4',0(a2,d3)       ;left arrow
X	    bne.s   501$
X	    tst.w   bottomin
X	    beq     102$
X	    move.w  loffset(PC),d2
X	    sub.w   colms(PC),d2
X	    bpl.s   502$
X	    moveq   #0,d2
X502$	    move.w  d2,loffset
X	    bsr     blastout
X	    bra     100$
X
X501$	    cmp.b   #'6',0(a2,d3)       ;right arrow
X	    bne.s   170$
X	    tst.w   bottomin
X	    beq     102$
X	    move.w  loffset(PC),d2
X	    add.w   colms(PC),d2
X	    bra.s   502$
X
X170$	    cmp.b   #'0',0(a2,d3)       ;Ins
X	    bne.s   177$
X	    eor.b   #1,insmode
X	    bra.s   102$
X
X177$	    cmp.b   #'.',0(a2,d3)       ;Del
X	    beq     178$
X
X105$	    tst.w   bottomin
X	    bne.s   777$
X	    tst.w   curpos
X	    bne.s   777$
X	    movem.l d0-d1,-(a7)
X	    move.w  edline(PC),d0
X	    bsr     findline
X	    movem.l (a7)+,d0-d1
X	    tst.l   8(a5)
X	    beq     intuiend
X777$	    move.w  curpos(PC),d5
X	    ext.l   d5
X	    moveq   #79,d2
X	    cmp.w   d2,d5
X	    bge     102$
X	    tst.b   insmode
X	    beq.s   172$
X	    cmp.w   ibufferlen(PC),d5
X	    bmi.s   171$
X	    bra.s   173$
X172$	    sub     d5,d2
X	    lea     80(a1),a4
X	    lea     79(a1),a3
X103$	    move.b  -(a3),-(a4)
X	    dbf     d2,103$
X173$	    addq.w  #1,ibufferlen
X171$	    move.b  0(a2,d3),0(a1,d5)
X	    addq.w  #1,curpos
X102$	    subq    #1,d0
X	    addq    #1,d3
X	    bra     101$
X
X100$	    bsr     UpdateIArea
X	    bra     intuiend
X
Xgot_enter   bsr     stoptimer
X	    bsr     puthist
X	    clr.b   insmode
X	    lea     dummy,a1
X	    lea     inputbuffer,a2
X	    move.w  ibufferlen(PC),d2
X	    beq.s   2$
X	    tst.w   bottomin
X	    bne.s   5$
X	    movem.l a1-a2,-(a7)
X	    move.w  edline(PC),d0
X	    bsr     findline
X	    move.l  8(a5),d0
X	    bsr     gthex
X	    lea     hexarea(PC),a0
X	    lea     0(a2,d2),a1
X	    move.b  #' ',(a1)+
X	    move.b  #'$',(a1)+
X	    moveq   #8,d0
X	    CALL    CopyMem,_SysBase(PC)
X	    move.w  ibufferlen(PC),d2
X	    add.w   #10,d2
X	    move.w  d2,ibufferlen
X	    movem.l (a7)+,a1-a2
X5$	    subq    #1,d2
X1$	    move.b  (a2)+,(a1)+
X	    dbf     d2,1$
X2$	    move.b  #10,(a1)+
X	    move.w  ibufferlen(PC),d0
X	    ext.l   d0
X	    addq    #1,d0
X	    move.l  d0,-(a7)
X	    clr.w   ibufferlen
X	    tst.w   bottomin
X	    bne.s   4$
X	    move.w  #100,curpos
X	    bsr     UpdateIArea
X4$	    clr.w   curpos
X	    move.w  #1,bottomin
X	    bsr     getcurpos
X	    bsr     UpdateIArea
X	    move.l  (a7)+,d0
X	    move.w  d0,repeatlen
X	    clr.w   repeat
X	    clr.b   printed
X	    tst.w   getanswer
X	    beq.s   6$
X	    rts
X6$	    bsr     cli
X	    tst.b   printed
X	    bne.s   3$
X	    bsr     starttimer
X3$	    bra     intuiend
X
Xnotarawkey
X
Xintuiend    bsr.s   replyintui
X	    bra     nextimsg
Xprocessnxtmsg
X	    tst.b   addlines
X	    beq.s   1$
X	    rts
X1$	    bra     processmsgs
X
Xreplyintui  move.l  intuimsg(PC),d0
X	    beq.s   1$
X	    move.l  d0,a1
X	    CALL    ReplyMsg,_SysBase
X1$	    clr.l   intuimsg
X	    rts
X
X;put an input line into the history buffer
Xputhist     move.w  ibufferlen(PC),d5
X	    move.l  d5,d0
X	    cmp.w   minnumchars(PC),d0
X	    bcs     1$
X
X	    move.l  gothline(PC),d1
X	    beq.s   5$
X	    move.l  d1,a2
X	    cmp.w   8(a2),d5
X	    bne.s   5$
X	    lea     10(a2),a2
X	    lea     inputbuffer,a1
X	    subq    #1,d0
X6$	    cmp.b   (a2)+,(a1)+
X	    bne.s   5$
X	    dbf     d0,6$
X	    move.l  gothline,curhist
X	    bra.s   1$
X
X5$	    move.w  d5,d0
X	    ext.l   d0
X	    add     #10,d0
X	    move.l  #$10000,d1		 ;MEMF_CLEAR
X	    CALL    AllocMem,_SysBase(PC)
X	    tst.l   d0
X	    beq.s   1$
X	    move.l  d0,a0
X	    move.w  d5,8(a0)
X	    lea     10(a0),a2
X	    subq    #1,d5
X	    lea     inputbuffer,a1
X2$	    move.b  (a1)+,(a2)+
X	    dbf     d5,2$
X	    move.w  hnum(PC),d5
X	    cmp.w   maxhlines(PC),d5
X	    bmi.s   3$
X	    bsr     remhistline
X	    bra.s   4$
X3$	    addq    #1,d5
X	    move.w  d5,hnum
X4$	    move.l  d0,a1
X	    move.l  d0,curhist
X	    lea     history(PC),a0
X	    CALL    AddTail,_SysBase(PC)
X1$	    clr.l   gothline
X	    rts
X
X;copy a history line into the input buffer
Xcopyhistory lea     inputbuffer,a0
X	    move.w  8(a1),d3
X	    ext.l   d3
X	    move.w  d3,curpos
X	    move.w  d3,ibufferlen
X	    subq    #1,d3
X	    lea     10(a1),a1
X1$	    move.b  (a1)+,(a0)+
X	    dbf     d3,1$
X	    rts
X;remove one line from the history buffer
X;pointer to the line in A1, returns pointer to the next line in d1
Xremhistline move.l  d0,-(a7)
X	    lea     history(PC),a0
X	    move.l  0(a0),a5
X	    tst.l   0(a5)
X	    beq.s   1$
X	    CALL    RemHead,_SysBase(PC)
X	    move.l  a5,a1
X	    move.w  8(a1),d0
X	    add     #10,d0
X	    ext.l   d0
X	    CALL    FreeMem,_SysBase(PC)
X1$	    move.l  (a7)+,d0
X	    rts
X
X;kill all history lines
Xkillhistory bsr     remhistline
X	    move.l  history(PC),a0
X	    tst.l   0(a0)
X	    bne.s   killhistory
X2$	    clr.w   hnum
X	    clr.l   curhist
X	    rts
X;delete one char from the input line
Xdelchar     lea     inputbuffer,a3
X	    lea     0(a3,d4.w),a3
X	    lea     -1(a3),a4
X	    move    d4,d5
X1$	    cmp.w   #78,d5
X	    bge.s   2$
X	    move.b  (a3)+,(a4)+
X	    addq    #1,d5
X	    bra.s   1$
X2$	    subq.w  #1,ibufferlen
X	    rts
X
Xtestsig     move.l  tasksigs(PC),d0
X	    btst    d1,d0
X	    rts
X
X;get the position of the input area
Xiareapos    move.l  wnptr(PC),a0
X	    move.w  10(a0),d0
X	    subq    #4,d0
X	    move.w  d0,ipos
X	    rts
X
X;Update the current position of the input line
Xgetcurpos   tst.w   bottomin
X	    beq.s   1$
X	    move.w  ipos,cposy
X	    rts
X1$	    move.w  edline(PC),d3
X	    sub.l   firstline(PC),d3
X	    lsl     #3,d3
X	    add.w   #18,d3
X	    move.w  d3,cposy
X	    rts
X;refresh the input area
XUpdateIArea move.l  rastport(PC),a1
X	    move.l  #1,d0
X	    CALL    SetDrMd,gfxbase(PC)
X	    moveq   #6,d0
X	    move.w  cposy(PC),d1
X	    CALL    Move,gfxbase(PC)
X	    lea     inputbuffer,a0
X	    move.w  ibufferlen(PC),d0
X	    ext.l   d0
X	    move.w  colms(PC),d1
X	    sub.w   bottomin(PC),d1
X	    cmp.w   d1,d0
X	    bmi.s   1$
X	    move.w  d1,d0
X1$	    move.w  d0,d2
X	    CALL    Text,gfxbase(PC)
X
X	    tst.w   bottomin
X	    bne.s   3$
X	    move.w  edline(PC),d0
X	    bsr     findline
X	    move.w  12(a5),d3
X	    sub.w   d2,d3
X	    bmi.s   3$
X	    move.w  colms(PC),d1
X	    sub.w   d2,d1
X	    bmi.s   2$
X	    cmp.w   d1,d3
X	    ble.s   4$
X	    move.w  d1,d3
X4$	    move.w  d3,d0
X	    lea     14(a5,d2.w),a0
X	    move.l  rastport(PC),a1
X	    CALL    Text,gfxbase(PC)
X	    add.w   ibufferlen(PC),d3
X	    move.w  d3,d2
X
X3$	    move.w  colms(PC),d0
X	    sub.w   bottomin(PC),d0
X	    move.l  blanks(PC),a0
X	    ext.l   d0
X	    sub.w   d2,d0
X	    bmi.s   2$
X	    lea     0(a0,d2.w),a0
X	    move.l  rastport(PC),a1
X	    CALL    Text,gfxbase(PC)
X2$	    bsr     putcursor
X	    rts
X
Xclrcursor   moveq   #1,d7
X	    bra.s   ptc1
Xputcursor   moveq   #6,d7
Xptc1	    move.w  curpos(PC),d0
X	    move.w  colms(PC),d1
X	    subq    #1,d1
X	    sub.w   bottomin(PC),d1
X	    cmp.w   d0,d1
X	    bmi.s   1$
X	    move.l  rastport(PC),a1
X	    move.l  d7,d0
X	    CALL    SetDrMd,gfxbase(PC)
X	    move.w  cposy(PC),d1
X	    move.w  curpos(PC),d0
X	    lsl.w   #3,d0
X	    addq    #6,d0
X	    CALL    Move,gfxbase(PC)
X	    lea     oneblank(PC),a0
X	    moveq   #1,d0
X	    CALL    Text,gfxbase(PC)
X1$	    rts
X;rebuild the window from scratch
Xsetupscreen move.l  rastport(PC),a1
X	    moveq   #0,d0
X	    CALL    SetRast,gfxbase(PC)
X	    move.l  wnptr,a0
X	    CALL    RefreshWindowFrame,intuibase(PC)
X	    bsr     getwindowsize
X	    tst.w   bottomin
X	    bne.s   1$
X	    move.w  edline(PC),d0
X	    move.l  firstline(PC),d1
X	    move.w  rows(PC),d2
X	    move.w  d2,d4
X	    move.w  numlines(PC),d3
X	    add.w   d1,d2
X	    cmp.w   d2,d0
X	    bmi.s   2$
X	    lsr.w   #1,d4
X	    sub.w   d4,d0
X	    ext.l   d0
X	    move.l  d0,firstline
X2$	    bsr     tstfirstlin
X1$	    bsr     getcurpos
X	    bsr     putiline
X	    bsr     blastout
X	    bsr     UpdateIArea
X	    move.w  rows,currenty
X	    rts
X
Xputiline    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetAPen,gfxbase(PC)
X	    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetDrMd,gfxbase(PC)
X	    move.l  wnptr(PC),a5
X	    move.w  10(a5),d1
X	    sub.w   #12,d1
X	    moveq   #0,d0
X	    CALL    Move,gfxbase(PC)
X	    move.w  8(a5),d0
X	    move.w  d1,-(a7)
X	    CALL    Draw,gfxbase(PC)
X	    move.w  (a7)+,d1
X	    tst.b   ownscreen
X	    bne.s   1$
X	    move.w  8(a5),d0
X	    addq    #1,d1
X	    CALL    Move,gfxbase(PC)
X	    sub.w   #16,d0
X	    move.w  d1,-(a7)
X	    CALL    Draw,gfxbase(PC)
X	    move.w  (a7)+,d1
X	    move.w  8(a5),d0
X	    addq    #1,d1
X	    CALL    Move,gfxbase(PC)
X	    sub.w   #16,d0
X	    CALL    Draw,gfxbase(PC)
X1$	    rts
X
Xgetwindowsize
X	    bsr     freeblank
X	    move.l  wnptr(PC),a0
X	    move.w  10(a0),d0
X	    sub.w   #26,d0
X	    lsr.w   #3,d0
X	    move.w  d0,rows
X	    move.w  8(a0),d0
X	    sub.w   #12,d0
X	    lsr.w   #3,d0
X	    move.w  d0,colms
X	    ext.l   d0
X	    moveq   #0,d1
X	    move.l  d0,d6
X	    CALL    AllocMem,_SysBase(PC)
X	    move.l  d0,blanks
X	    move.l  d0,a0
X	    subq    #1,d6
X1$	    move.b  #' ',(a0)+
X	    dbf     d6,1$
X	    bsr     iareapos
X	    rts
X
Xreadline    move.b  #'n',inputbuffer
X	    tst.b   fromfile
X	    bne.s   1$
X	    move.l  #31000,firstline
X	    bsr     blastout
X	    move.w  #1,getanswer
X	    bsr     replyintui
X5$	    bsr     processmsgs
X	    move.w  d0,d5
X	    bsr     replyintui
X	    subq    #1,d5
X	    beq.s   5$
X	    ori.b   #$20,inputbuffer
X	    clr.w   getanswer
X	    bsr     RestoreOutput
X1$	    rts
X
XResumeOutput
X	    move.l  outchain(PC),d0
X	    move.l  d0,a1
X	    beq.s   2$
X	    move.l  numlines,oldnumlines
X	    move.l  firstline,oldfirstline
X4$	    tst.l   0(a1)
X	    beq.s   3$
X	    move.l  0(a1),a1
X	    bra.s   4$
X3$	    move.l  a1,lastprinted
X2$	    move.l  a1,oldpageend
X	    rts
X
XRestoreOutput
X	    move.l  oldpageend(PC),d3
X	    beq.s   1$
X	    move.l  oldnumlines(PC),numlines
X	    move.l  oldfirstline(PC),firstline
X	    move.l  oldlastprinted(PC),lastprinted
X	    move.l  d3,a1
X	    move.l  0(a1),a1
X	    bsr     killlines
X	    move.l  d3,a1
X	    clr.l   0(a1)
X	    bsr     blastout
X1$	    rts
X
Xaddline     movem.l d0-d6/a0-a3,-(a7)
X	    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetAPen,gfxbase(PC)
X	    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetDrMd,gfxbase(PC)
X	    move.w  currenty(PC),d6
X	    cmp.w   rows(PC),d6
X	    bmi.s   1$
X	    bsr     cls
X1$	    move.l  lastprinted(PC),a0
X	    move.w  colms(PC),d5
X	    move.w  12(a0),d3
X	    lea     14(a0),a0
X	    move.w  currenty(PC),d6
X	    move    d6,d7
X	    lsl     #3,d6
X	    add.w   #18,d6
X	    moveq   #0,d4
X	    bsr     blastline
X	    addq.w  #1,currenty
X	    move.l  #31000,firstline
X	    movem.l (a7)+,d0-d6/a0-a3
X	    rts
X
Xcls	    movem.l d0-d6/a0-a3,-(a7)
X	    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetAPen,gfxbase(PC)
X	    move.l  rastport(PC),a1
X	    moveq   #1,d0
X	    CALL    SetDrMd,gfxbase(PC)
X	    move.w  colms(PC),d5
X	    clr.w   d2
X1$	    move.w  d2,d6
X	    move    d5,d7
X	    lsl     #3,d6
X	    add.w   #18,d6
X	    moveq   #0,d3
X	    move.l  blanks(PC),a0
X	    bsr     blastline
X	    addq    #1,d2
X	    cmp.w   rows(PC),d2
X	    bmi.s   1$
X	    clr.w   currenty
X	    movem.l (a7)+,d0-d6/a0-a3
X	    rts
X
Xcreatescreen moveq  #1,d1
X	    moveq   #80,d0
X	    lea     buffer,a0
X	    sub.l   a1,a1
X	    CALL    GetScreenData,intuibase(PC)
X	    move.w  buffer+76,nsviewmode
X	    move.l  buffer+12,nssize
X	    lea     newscreen(PC),a0
X	    CALL    OpenScreen,intuibase(PC)
X	    move.l  d0,screenptr
X	    move.l  d0,nwscreen
X	    move.w  #$f,nwtype
X	    beq.s   setupwindow
X	    tst.l   wnptr
X	    beq.s   1$
X	    move.l  wnptr(PC),a0
X	    move.l  4(a0),window_l
X	    move.l  8(a0),window_w
X	    CALL    CloseWindow,intuibase(PC)
X	    clr.l   intuimsg
X	    clr.l   wnptr
X1$	    clr.l   newwindow
X	    move.l  buffer+12,newwindow+4
X	    move.l  wnscrflags(PC),nwflgs
X	    move.l  wnscrflags+4(PC),nwflgs+4
X	    move.b  #1,ownscreen
X
Xsetupwindow tst.b   ownscreen
X	    bne.s   3$
X	    move.l  window_l(PC),newwindow
X	    move.l  window_w(PC),newwindow+4
X	    move.w  #1,nwtype
X	    move.l  wnnormflgs(PC),nwflgs
X	    move.l  wnnormflgs+4(PC),nwflgs+4
X3$	    lea     newwindow(PC),a0
X	    CALL    OpenWindow,intuibase(PC)
X	    move.l  d0,wnptr
X	    beq     exit
X	    move.l  d0,a0
X	    move.l  50(a0),rastport    ;wn->RPort
X	    move.l  86(a0),a1          ;wn->UserPort
X	    move.b  15(a1),d1          ;MsgPort->SigBit
X	    ext.w   d1
X	    move.w  d1,intuisig
X
X	    tst.b   iconifyon
X	    beq.s   1$
X	    tst.b   ownscreen
X	    bne.s   1$
X	    lea     iconifgad,a1
X	    moveq   #0,d0
X	    CALL    AddGadget,intuibase(PC)
X	    move.l  wnptr(PC),a0
X	    CALL    RefreshWindowFrame,intuibase(PC)
X
X1$	    lea     tattr(PC),a0
X	    CALL    OpenFont,gfxbase(PC)
X	    tst.l   d0
X	    beq.s   2$
X	    move.l  d0,a0
X	    move.l  rastport(PC),a1
X	    CALL    SetFont,gfxbase(PC)
X2$	    bsr     getwindowsize
X	    bsr     getcurpos
X
X	    bsr     putiline
X	    bsr     UpdateIArea
X	    bsr     starttimer
X	    bsr     showwhat
X	    rts
X
Xusescreen   tst.b   fromfile
X	    bne.s   1$
X	    tst.b   ownscreen
X	    bne.s   1$
X	    bsr     createscreen
X1$	    move.b  #1,ownscreen
X	    rts
X
Xusewindow   tst.b   fromfile
X	    beq.s   1$
X	    clr.b   ownscreen
X	    rts
X1$	    tst.b   ownscreen
X	    beq.s   2$
X	    move.l  wnptr(PC),d0
X	    beq.s   3$
X	    move.l  d0,a0
X	    CALL    CloseWindow,intuibase(PC)
X	    clr.l   wnptr
X	    clr.l   intuimsg
X3$	    move.l  screenptr(PC),d0
X	    beq.s   4$
X	    move.l  d0,a0
X	    CALL    CloseScreen,intuibase(PC)
X	    clr.l   screenptr
X	    clr.b   ownscreen
X4$	    bra     setupwindow
X2$	    rts
X
Xdchange     lea     dchead(PC),a0
X	    bsr     puthead
X	    lea     tdd(PC),a1
X	    move.l  _SysBase(PC),a0
X	    lea     350(a0),a0
X	    CALL    FindName,_SysBase(PC)
X	    tst.l   d0
X	    beq     R_T_S
X	    move.l  d0,a2
X	    lea     32(a2),a2
X	    moveq   #0,d5
X2$	    lea     4(a2),a2
X	    move.l  0(a2),d0
X	    beq     3$
X	    move.l  d0,a0
X	    lea     $18e(a0),a0
X	    CALL    Disable,_SysBase(PC)
X5$	    tst.l   0(a0)
X	    beq.s   6$
X	    move.l  0(a0),a0
X	    bra.s   5$
X6$	    lea     -4(a0),a5
X	    lea     buffer+100,a3
X9$	    move.l  0(a5),a5
X	    tst.l   0(a5)
X	    beq.s   11$
X	    move.l  a5,(a3)+
X	    bne.s   9$
X11$	    clr.l   (a3)+
X	    CALL    Enable,_SysBase(PC)
X	    lea     buffer+100,a3
X7$	    move.l  (a3)+,d0
X	    beq.s   3$
X	    move.l  d0,a5
X	    cmp.w   #20,28(a5)
X	    bne.s   7$
X	    move.l  40(a5),a4
X	    move.l  a4,d0
X	    move.l  d0,node
X	    bsr     hexan
X	    move.l  a4,d0
X	    beq.s   10$
X	    move.l  14(a4),d0
X	    bsr     hexan
X	    move.l  18(a4),d0
X	    bsr     hexan
X10$	    move.l  d5,d3
X	    or.b    #48,d3
X	    move.b  d3,tddrives+2
X	    move.l  #tddrives,d0
X	    bsr     putstr
X	    move.l  14(a5),d0
X	    beq.s   8$
X	    move.l  d0,a0
X	    move.l  16(a0),d0
X	    beq.s   8$
X	    move.l  d0,a0
X	    move.l  10(a0),d0
X8$	    bsr     putnam
X	    bra.s   7$
X3$	    addq    #1,d5
X	    cmp.w   #4,d5
X	    bmi     2$
XR_T_S	    rts
X
Xdosbase     dc.l    0
Xintuibase   dc.l    0
Xgfxbase     dc.l    0
Xcondev	    dc.l    0
Xparmtxt     dc.l    0
Xfileptr     dc.l    0
Xinfile	    dc.l    0
Xptr	    dc.l    0
Xoldidl	    dc.l    0
Xolddisp     dc.l    0
Xmysignal    dc.l    0
Xauxsig	    dc.l    0
Xtrapsignal  dc.l    0
Xiostatus    dc.l    -1
Xdevstatus   dc.l    -1
Xtasksigs    dc.l    0
Xcancelbit   dc.l    0
Xcancelbnum  dc.l    0
X_SysBase    dc.l    0
XInputMsg    dc.l    0
XInRequest   dc.l    0
Xstartmess   dc.l    0
Xsavedat     dc.l    0
Xwnptr	    dc.l    0
Xaliaslist   dc.l    0
Xscreenptr   dc.l    0
Xintuimsg    dc.l    0
Xmytask	    dc.l    0
Xwbmsg	    dc.l    0
Xpointer     dc.l    0
Xreplyport   dc.l    0
Xtimerport   dc.l    0
Xfinfoptr    dc.l    0
Xmyseg	    dc.l    0
Xdispatches  dc.l    0
Xmaxdisp     dc.l    0
Xdeltadisp   dc.l    0
Xwbaddr	    dc.l    0
Xnode	    dc.l    0
Xremembr     dc.l    0
Xremembr2    dc.l    0
SHAR_EOF
echo "End of archive 2 (of 3)"
# if you want to concatenate archives, remove anything after this line
exit