******************************************
*                                        *
* Xoper 1.3 Copyright (C) Werner Gunther *
*                                        *
******************************************
*    Written for the A68K Assembler      *
*   (Fish 110) by Charlie Gibbs and      *
*          Brian R. Anderson             *
*                                        *
*  Do not use Smallcode/Smalldata when   *
*             linking                    *
******************************************

;DEBUG SET 1
            XREF    _LVOSwitch
            XDEF    _SysBase
sysbase     equ     4

CALL        MACRO
            xref    _LVO\1
            move.l  \2,a6
            jsr     _LVO\1(a6)
            ENDM
LIBCALL     MACRO
            xref    _\1
            jsr     _\1
            ENDM

ADDCMD      MACRO
cmdnum      set     cmdnum+1
            dc.b    \1,0
            ENDM

;Program startup. If called from DOS we
;use segment splitting to detach
;from our DOS-task.
start       moveq   #3,d0
            lea     dummyinput,a1
getparm     move.b  (a0)+,(a1)+
            dbf     d0,getparm
            move.b  #10,in
            lea     dosname(PC),a1
            move.l  sysbase,a0
            lea     378(a0),a0
            move.l  a0,-(a7)
            CALL    FindName,sysbase
            move.l  d0,dosbase
            move.l  0(a7),a0
            lea     gfxname(PC),a1
            CALL    FindName,sysbase
            move.l  d0,gfxbase
            move.l  (a7)+,a0
            lea     intuiname(PC),a1
            CALL    FindName,sysbase
            move.l  d0,intuibase
            move.l  d0,a0
            move.l  $38(a0),a0
            move.w  12(a0),d0
            sub.w   #550,d0
            move.w  d0,window_l

            move.l  sysbase,a4
            move.l  276(a4),a4
            tst.l   $ac(a4)
            bne.s   notwb
            lea     $5c(a4),a0
            CALL    WaitPort,sysbase
            lea     $5c(a4),a0
            CALL    GetMsg,sysbase
            move.l  d0,wbmsg
            move.w  #$740a,in
notwb:
       IFND  DEBUG
            lea     xopcon,a1
            CALL    FindPort,sysbase
            tst.l   d0
            bne     oops
       ENDC
            tst.l   wbmsg
            beq.s   fromdos
            jmp     mainprg

fromdos:

starttask:

        IFND DEBUG
            cmp.w   #'-b',dummyinput
            bne.s   stt1
            CALL    Output,dosbase
            move.l  d0,-(a7)
            move.l  #windowname,d2
            move.l  d0,d1
            moveq.l #34,d3
            CALL    Write,dosbase
            move.l  #cr,d2
            move.l  (a7)+,d1
            moveq.l #1,d3
            CALL    Write,dosbase
stt1        lea     start(PC),a1
            move.l  -4(a1),d3
            move.l  d3,myseg
            clr.l   -4(a1)
            CALL    Forbid,sysbase
            move.l  #newname,d1
            clr.l   d2
            move.l  #3500,d4
            CALL    CreateProc,dosbase
            CALL    Permit,sysbase
            clr.l   d0
            rts
oops        suba.l  a0,a0
            CALL    DisplayBeep,intuibase
            CALL    Forbid,sysbase
            move.l  wbmsg,d0
            beq.s   leave
            move.l  d0,a1
            CALL    ReplyMsg,sysbase
            clr.l   d0
leave       rts

dosname     dc.b    'dos.library',0
intuiname   dc.b    'intuition.library',0
gfxname     dc.b    'graphics.library',0
            EVEN

main        CODE    xoper
        ENDC
mainprg     move.l  sysbase,a0
            move.l  a0,_SysBase
            move.l  276(a0),a0
            move.l  a0,mytask
            move.l  #newname,10(a0)
            pea     0
            pea     xopcon
            LIBCALL CreatePort
            lea     8(a7),a7
            move.l  d0,replyport
;install a counter to determine the amount of CPU-time each
;Task uses.
            move.l  _SysBase(PC),a1
            move.l  #_LVOSwitch,a0
            move.l  2(a1,a0),oldswitch
            move.l  #myswitch,d0
            CALL    SetFunction,_SysBase(PC)
;install a counter for PORT-Interrupts
            lea     IOCounter(PC),a1
            move.l  #3,d0
            CALL    AddIntServer,_SysBase(PC)
;Attempt to open a startup script
            move.l  mytask(PC),a4
            move.l  #-1,184(a4)
            move.l  #startupname,d1
            move.l  #1005,d2
            CALL    Open,dosbase(PC)
            clr.l   184(a4)
            move.l  d0,infile
            beq.s   nostartup
            clr.b   morefl
            move.b  #1,fromfile
            bra     cli
endstartup  move.b  morefl2(PC),morefl
            clr.b   fromfile
            move.l  infile(PC),d1
            CALL    Close,dosbase(PC)

nostartup   tst.l   wbmsg
            bne.s   noin
            cmp.b   #10,dummyinput
            beq.s   noin
            cmp.w   #'-b',dummyinput
            beq.s   noin
            move.l  dummyinput,in
            move.b  #10,in+4
            bra.s   nostartup2
noin        cmp.b   #10,in
            beq.s   default
            tst.b   in
            bne.s   nostartup2

default     move.w  #$740a,in


nostartup2  cmp.w   #'-b',dummyinput
            beq     instback

;This code just opens a CON: Window. Position
;and size are taken from window_l,window_t,
;window_w,window_h.

restart     move.l  mytask(PC),a0
            clr.l   26(a0)
            lea     fname,a0
            move.l  #'con:',0(a0)
            clr.b   4(a0)
            lea     binarea(PC),a1
            lea     window_l(PC),a2
            move.l  #3,d4
rest1       move.l  #2,d3
            clr.l   d0
            move.w  (a2)+,d0
            bsr     longdec
            bsr     strcat
            move.w  #$2f00,binarea
            bsr     strcat
            dbf     d4,rest1
            lea     windowname(PC),a1
            bsr     strcat
            move.l  a0,d1
            move.l  #1005,d2
            CALL    Open,dosbase(PC)
            move.l  d0,fileptr
            move.l  d0,infile
            beq     exitall
            lsl.l   #2,d0
            move.l  d0,a4
            move.l  8(a4),conmsg
;get a pointer to our window
            move.l  #buffer,d0
            lsr.l   #2,d0
            move.l  d0,dp_Arg1
            move.l  conmsg,a0
            move.l  #25,dp_Type
            bsr     cons1
            lea     buffer,a0
            move.l  28(a0),window

            clr.l   ptr

;show a list. The string entered from keyboard is stored
;in 'in'.Every character is interpreted as one command
;i.e. 'rip' means 'resources'+'interrupts'+'ports'.
showwhat    bsr     raw
            bsr     clearscr
            tst.b   morefl
            beq.s   swh1
;if <MORE> is enabled we need to know how many lines can
;fit into our window
            move.l  #getwin,d2
            move.l  fileptr,d1
            moveq.l #4,d3
            CALL    Write,dosbase(PC)
            move.l  fileptr,d1
            move.l  #9,d3
            move.l  #buffer,d2
            CALL    Read,dosbase(PC)
            lea     buffer,a0
            lea     5(a0),a0
            bsr     isdec
            subq.b  #1,d2
            move.b  d2,rows
            clr.b   row
;search the command to be executed. If none is found,
;show a help message
swh1        clr.l   d7
input       lea     in,a0
            move.b  0(a0,d7),d0
            addq.b  #1,d7
            cmpi.b  #' ',d0
            beq.s   input
            tst.b   d0
            beq     nomore
            cmpi.b  #10,d0
            beq     nomore
            or.b    #32,d0
            cmpi.b  #'q',d0
            beq     exit
            lea     params(PC),a0
            clr.l   d1
i1          cmp.b   0(a0,d1),d0
            beq.s   foundp
            addq.b  #1,d1
            cmpi.b  #parmnum,d1
            bne.s   i1

            move.l  #usetxt,d0
            move.b  #1,mnflag
            bsr     putnam
            clr.b   mnflag
            bra     nomore

foundp      lsl.b   #2,d1
            lea     subs(PC),a0
            move.b  #1,mnflag
            jsr     0(a0,d1)
            clr.b   mnflag
            bra.s   input

;wait 'timeout' seconds for a kepress

nomore      tst.b   fromfile
            bne.s   cli
            move.l  #prompt,d2
            move.l  fileptr,d1
            moveq.l #7,d3
            CALL    Write,dosbase(PC)
            bsr     con
            move.b  timeout,d6
halt        move.l  #1000000,d4
            bsr     getkey
            move.l  mytask(PC),a0
            move.l  26(a0),d1
            and.l   #$1000,d1
            bne     exit
            tst.l   d0
            bne.s   cli
            subq.b  #1,d6
            bne.s   halt
            clr.l   d4
            bsr     getkey
            tst.l   d0
            bne.s   cli
            bra     showwhat

getkey      move.l  fileptr,d1
            moveq.l #1,d3
            move.l  #null,d2
            CALL    Write,dosbase(PC)
            move.l  d4,d2
            move.l  fileptr,d1
            CALL    WaitForChar,dosbase(PC)
            rts
;read the string from keyboard search and execute
;the command, if any.
cli         tst.b   fromfile
            beq.s   cl3
            tst.b   eof
            bne     endstartup
cl3         bsr     readline
            lea     dummy,a0
            subq.b  #1,d0
cl2         subq.b  #1,d0
            bmi.s   cl1
            cmp.b   #' ',0(a0,d0)
            beq.s   cl2
cl1         addq.b  #1,d0
            move.b  #10,0(a0,d0)
            bsr     kllblnks
            cmpi.b  #10,0(a0)
            beq     showwhat
            cmpi.b  #';',0(a0)
            beq     nomore
            lea     in,a1
            lea     commds(PC),a2
            clr.b   d2
tstcmd      move    #-1,d1
tc2         addq    #1,d1
            move.b  0(a0,d1),d3
            or.b    #32,d3
            tst.b   0(a2,d1)
            beq.s   foundcmd
            cmp.b   0(a2,d1),d3
            beq.s   tc2
nocmd       tst.b   (a2)+
            bne.s   nocmd
            addq.b  #1,d2
            cmpi.b  #cmdnum,d2
            bne     tstcmd
            bra     nm1
foundcmd    cmpi.b  #'*',d3
            beq.s   okcmd
            cmpi.b  #' ',d3
            bne.s   nocmd
okcmd       move.l  a0,-(a7)
            bsr     raw
            move.l  (a7)+,a0
            clr.b   procnum
            adda.w  d1,a0
            bsr     kllblnks
            and.l   #$ff,d2
            lsl     #2,d2
            lea     cmdaddr(PC),a1
            clr.b   printed
            jsr     0(a1,d2)
            tst.b   morefl
            beq     nomore
            tst.b   printed
            beq     nomore
            bsr     raw
            move.l  #10,d3
            move.l  fileptr,d1
            move.l  #waittxt,d2
            CALL    Write,dosbase(PC)
            bsr     readline
            bsr     con
            move.l  #1,d3
            move.l  fileptr,d1
            move.l  #thisline,d2
            CALL    Write,dosbase(PC)
            bra     nomore

nm1         lea     buffer,a2
nm2         move.b  (a1)+,(a2)+
            cmp.b   #10,-1(a1)
            bne.s   nm2
            lea     in,a1
nm0         move.b  (a0)+,(a1)+
            dbf     d0,nm0
            lea     dummy,a2
            lea     buffer,a1
nm3         move.b  (a1)+,(a2)+
            cmp.b   #10,-1(a1)
            bne.s   nm3
            bra     showwhat

subs        bra     showtask
            bra     showaddr
            bra     showdevs
            bra     showlibs
            bra     showres
            bra     showresi
            bra     showmem
            bra     showprt
            bra     showint
            bra     stack
cmdaddr     bra     settime
            bra     taskpri
            bra     info
            bra     pri
            bra     flush
            bra     freeze
            bra     warm
            bra     signal
            bra     break
            bra     alert
            bra     lastalert
            bra     hold
            bra     stopall
            bra     clear
            bra     cancel
            bra     moretst
            bra     taskports
            bra     hunks
            bra     devices
            bra     openlib
            bra     closelib
            bra     currentdir
            bra     cd
            bra     mypri
            bra     openfiles
            bra     locks
            bra     unlock
            bra     screens
            bra     windows
            bra     closescreen
            bra     closewindow
            bra     fonts
            bra     windowfonts
            bra     lockdrive
            bra     freedrive
            bra     capture
            bra     clrcold
            bra     clrcool
            bra     clrwarm
            bra     snoop
            bra     usage
            bra     inphand
            bra     nohead
            bra     sort
            bra     hide
            bra     hidden
            bra     setwindow
            bra     cancel

;------ Task-Structures-----

showaddr    clr.b   tasktyp
            bra.s   startask
showtask    move.b  #1,tasktyp
startask    tst.b   headon
            beq     noheader1
            move.l  #infoh1,d0
            bsr     putstr
            move.l  _SysBase(PC),a6
            move.l  #cpu2,d0
            btst    #1,297(a6)
            bne.s   cpupr
            move.l  #cpu1,d0
            btst    #0,297(a6)
            bne.s   cpupr
            move.l  #cpu0,d0
cpupr       bsr     putstr
            move.l  _SysBase(PC),a6
            btst    #2,297(a6)
            beq.s   no881
            move.l  #cpu3,d0
            bsr     putstr
no881       move.l  #20,d1
            bsr     tab
            move.l  #infoh3,d0
            bsr     putstr

noheader1   move.l  _SysBase(PC),a6
            move.w  #$4000,$dff09a
            move.l  280(a6),d0
            move.l  284(a6),d1
            move.l  oldidl,d3
            move.l  d0,oldidl
            sub.l   d3,d0
            move.l  olddisp,d3
            move.l  d1,olddisp
            sub.l   d1,d3
            move.l  d0,d1
            sub.l   d3,d1
            move.l  d1,maxdisp
            move.l  d3,-(a7)
            movem.l d0-d3,-(a7)
            bsr     getaskdat
            move.l  a5,savedat
            movem.l (a7)+,d0-d3
            sub.l   d3,d0
            neg.l   d3
            tst.b   headon
            beq.s   noheader2
            bsr     prcent
            bsr     newline
            move.l  #infoh2,d0
            bsr     putstr
noheader2   move.l  (a7)+,d0
            neg.l   d0
            move.l  d0,dispatches
            tst.b   headon
            beq     noheader3
            clr.l   d3
            bsr     longdec

            move.l  #20,d1
            bsr     tab
            move.l  #infoh7,d0
            bsr     putstr
            lea     secs(PC),a0
            lea     mics(PC),a1
            CALL    CurrentTime,intuibase(PC)
            move.l  secs(PC),d3
            lsl.l   #1,d3
            move.l  d3,d1
            lsl.l   #2,d3
            add.l   d1,d3
            move.l  mics(PC),d0
            move.l  #100000,d1
            bsr     div
            add.l   d0,d3
            move.l  time10(PC),d1
            move.l  d3,time10
            sub.l   d1,d3
            move.l  iocount(PC),d0
            clr.l   iocount
            mulu    #100,d0
            move.l  d3,d1
            bsr     div
            divu    #10,d0
            move.l  d0,d1
            swap    d1
            move    d0,d3
            bsr     bytedec
            lea     out,a0
            move.b  #'.',-1(a0,d0)
            or.b    #'0',d1
            move    d1,d0
            bsr     putchar

            bsr     newline
            bsr     newline
noheader3   lea     theader(PC),a0
            tst.b   tasktyp
            bne.s   phedder
            lea     t2header(PC),a0
phedder     bsr     puthead
            move.l  savedat(PC),a5

pt1         tst.b   entries
            beq     pt2
            lea     -16(a5),a5
            bsr     hideit
            tst     d0
            beq     ptend
            move.l  0(a5),a4
            move.l  a4,d0
            bsr     hexa
            tst.b   tasktyp
            beq.s   pt12
            clr.l   d0
            move.b  8(a4),d0
            bsr     gettype

pt12        clr.l   d0
            move.b  9(a5),d0
            subq.b  #1,d0
            mulu    #10,d0
            move.l  #status,d1
            add.l   d1,d0
            bsr     putstr
            tst.b   tasktyp
            bne.s   pt13

            move.l  18(a4),d0
            bsr     hex8
            move.l  #ganzlongnix,d0
            cmp.b   #4,9(a5)
            beq.s   pt14
            bsr     putstr
            bra.s   pt15
pt14        move.l  22(a4),d0
            bsr     hex8
pt15        move.l  26(a4),d0
            bsr     hex8
            move.l  54(a4),a1
            move.l  0(a1),d0
            cmp.b   #2,9(a5)
            bne.s   pt16
            move.l  #*,d0
pt16        bsr     hexa
            bra     pt4

pt13        move.b  10(a5),d3
            bsr     plusmins

            move.l  dispatches(PC),d0
            tst.b   usageflag
            beq.s   pt37
            move.l  maxdisp(PC),d0
pt37        move.l  12(a5),d3
            bsr     prcent

            clr.b   d3
            cmpi.b  #13,8(a5)
            bne.s   noproc
            tst.l   172(a4)
            beq.s   noproc
            move.l  140(a4),d3
            bsr     bytedec
            bra.s   pt4
noproc      move.l  #nix,d0
            bsr     putstr
pt4         move.l  4(a5),d0
            bsr     putnam
ptend       subq.b  #1,entries
            bra     pt1
pt2         rts

putlist     move.l  0(a4),a4
            tst.l   0(a4)
            beq.s   endlist
            bsr     putdata
            bra.s   putlist
endlist     rts

putdata     move.l  a4,0(a5)
            move.l  10(a4),4(a5)
            move.b  8(a4),8(a5)
            move.b  15(a4),9(a5)
            move.b  9(a4),10(a5)
            move.b  143(a4),11(a5)
            clr.l   12(a5)
            lea     cputime,a0
            move.l  tasksnum(PC),d1
            beq.s   pua1
pua3        cmp.l   0(a0),a4
            beq.s   pua2
            lea     8(a0),a0
            dbf     d1,pua3
            bra.s   pua1
pua2        move.l  4(a0),12(a5)
pua1        lea     16(a5),a5
            addq.b  #1,entries
            rts

gettype     and.l   #$f,d0
            mulu    #11,d0
            add.l   #type,d0
            bra     putstr

getaskdat   lea     buffer,a5
            clr.b   entries
            lea     stplist(PC),a4
            bsr     putlist
            move.l  _SysBase(PC),a4
            lea     420(a4),a4
            bsr     putlist
            move.l  _SysBase(PC),a4
            lea     406(a4),a4
            bsr     putlist
            move.l  _SysBase(PC),a4
            move.l  276(a4),a4
            bsr     putdata
            clr.l   tasksnum
            move.w  #-$4000,$dff09a
            tst.b   sorton
            beq.s   sort5
            lea     buffer,a3
            lea     -32(a5),a2
sort1       lea     16(a3),a4
sort2       move.l  0(a3),d1
            cmp.l   0(a4),d1
            bge.s   sort3
            moveq   #15,d1
sort4       move.b  0(a4,d1),d0
            move.b  0(a3,d1),0(a4,d1)
            move.b  d0,0(a3,d1)
            dbf     d1,sort4
sort3       lea     16(a4),a4
            cmp.l   a2,a4
            ble.s   sort2
            lea     16(a3),a3
            cmp.l   a2,a3
            bne.s   sort1
sort5       rts

prcent      lsl.l   #1,d3
            move.l  d3,d1
            lsl.l   #2,d3
            add.l   d1,d3
            lsl.l   #2,d3
            move.l  d3,d1
            lsl.l   #3,d3
            move.l  d3,d2
            lsl.l   #1,d3
            add.l   d2,d3
            add.l   d1,d3
            move.l  d0,d1
            move.l  d3,d0
            bsr     div
            divu    #10,d0
            move    d0,d3
            swap    d0
            move    d0,d1
            bsr     bytedec
            lea     out,a0
            move.b  #'.',-1(a0,d0)
            or.b    #'0',d1
            move    d1,d0
            bsr     putchar
            move.l  #infoh4,d0
            bra     putstr

hideit      tst.b   hideon
            bne.s   pt73
pt75        moveq   #1,d0
            rts
pt73        lea     hidestart(PC),a4
            move.l  4(a5),a0
pt74        tst.l   0(a4)
            beq.s   pt75
            move.l  0(a4),a4
            lea     4(a4),a1
            bsr     strcmp
            tst     d0
            beq     hideend
            bra.s   pt74
hideend     rts
*-------- mem-hunks ------------

showmem     lea     mheader(PC),a0
            bsr     puthead
            move.l  _SysBase(PC),a5
            lea     322(a5),a5
            clr.l   d5
mem1        move.l  0(a5),a5
            tst.l   0(a5)
            beq.s   mem2
            move.l  20(a5),d0
            bsr     hexa
            move.l  24(a5),d0
            bsr     hexa
            move.l  28(a5),d0
            add.l   d0,d5
            moveq   #1,d3
            bsr     longdec
            move.b  15(a5),d3
            bsr     bytedec
            move.b  9(a5),d3
            bsr     plusmins
            move.l  10(a5),d0
            bsr     putnam
            bra.s   mem1
mem2        move.l  #infoh6,d0
            bsr     putstr
            move.l  #15,d1
            bsr     tab
            move.l  d5,d0
            bsr     longdec
newline     move.l  #nxtline,d0
            bra     putstr

*-------- Task-Stack ------------

stack       lea     stackhead(pc),a0
            bsr     puthead
            bsr     getaskdat
sta1        tst.b   entries
            beq     sta8
            lea     -16(a5),a5
            bsr     hideit
            tst     d0
            beq     sta9
            move.l  0(a5),a1
            cmp.b   #13,8(a1)
            bne.s   sta6
            move.l  172(a1),d0
            beq.s   sta6
            lsl.l   #2,d0
            move.l  d0,a0
            tst.l   60(a0)
            beq.s   sta6
            moveq   #1,d3
            move.l  52(a0),d4
            lsl.l   #2,d4
            move.l  176(a1),d0
            sub.l   d4,d0
            bsr     hexa
            move.l  d4,d0
            bsr     longdec
            move.l  176(a1),d0
            sub.l   54(a1),d0
            bra.s   sta7

sta6        move.l  58(a1),d0
            bsr     hexa
            moveq   #1,d3
            move.l  62(a1),d0
            sub.l   58(a1),d0
            bsr     longdec
            move.l  62(a1),d0
            sub.l   54(a1),d0
sta7        bsr     longdec
            move.l  4(a5),d0
            bsr     putnam
sta9        subq.b  #1,entries
            bra     sta1
sta8        rts

*--------- interrupts ------------
showint     lea     iheader(PC),a0
            bsr     puthead
            lea     intnames(PC),a5
            lea     inttyp(PC),a4
            move.l  #15,d5
            move.l  _SysBase(PC),a3
            lea     84(a3),a3

si0         tst.b   0(a4)
            bne.s   si4
            move.l  8(a3),a2
            bra.s   si5
si4         move.l  0(a3),a2
si5         cmp.l   #0,a2
            beq.s   nxtint
            tst.b   0(a4)
            beq.s   si1
si2         move.l  0(a2),a2
            tst.l   0(a2)
            beq.s   nxtint
si1         move.l  a2,d0
            bsr     hexa
            move.l  14(a2),d0
            bsr     hexa
            move.l  18(a2),d0
            bsr     hexa
            move.b  9(a2),d3
            move.l  a3,-(a7)
            bsr     plusmins
            move.l  (a7)+,a3
            move.l  a5,d0
            bsr     putstr
            move.l  10(a2),d0
            tst.l   d0
            bne.s   prtintnam
            move.l  #ganzlongnix,d0
prtintnam   bsr     putnam
            tst.b   0(a4)
            bne.s   si2
            tst.l   0(a2)
            beq.s   nxtint
            move.l  0(a4),a4
            bra     si1
nxtint      lea     1(a4),a4
            lea     12(a5),a5
            lea     12(a3),a3
            dbf     d5,si0
            rts

*---------    resident ------------

showresi    lea     rheader(PC),a0
            bsr     puthead
            move.l  _SysBase(PC),a5
            move.l  300(a5),a5
r1          tst.l   0(a5)
            beq     r2
            move.l  0(a5),a4
            move.l  a4,d0
            bsr     hexa
            move.b  13(a4),d3
            bsr     plusmins
            move.b  10(a4),d0
            bsr     bin
            move.b  11(a4),d3
            bsr     bytedec
            move.b  12(a4),d0
            bsr     gettype
            move.l  14(a4),d0
            bsr     putnam
            lea     4(a5),a5
            bra     r1
r2          rts

*---------  ports  -------------

showprt     lea     pheader(PC),a0
            bsr     puthead
            move.l  _SysBase(PC),a4
            lea     392(a4),a4
            lea     buffer,a5
            clr.l   d5
            CALL    Forbid,_SysBase(PC)
            move.w  #$4000,$dff09a
sp2         move.l  0(a4),a4
            tst.l   0(a4)
            beq.s   sp20
            bsr     getpdata
            bra.s   sp2
sp20        tst.b   tports
            bne.s   sp15
            move.l  _SysBase(PC),a4
            move.l  276(a4),a4
            lea     92(a4),a4
            bsr     getpdata
            move.l  _SysBase(PC),a2
            lea     406(a2),a2
sp11        move.l  0(a2),a2
            tst.l   0(a2)
            beq.s   sp14
            lea     92(a2),a4
            cmp.b   #13,8(a2)
            bne.s   sp11
            bsr     getpdata
            bra     sp11
sp14        move.l  _SysBase(PC),a2
            lea     420(a2),a2
sp12        move.l  0(a2),a2
            tst.l   0(a2)
            beq.s   sp15
            lea     92(a2),a4
            cmp.b   #13,8(a2)
            bne.s   sp12
            bsr     getpdata
            bra     sp12
sp15        move.w  #-$4000,$dff09a
            CALL    Permit,_SysBase(PC)
            lea     buffer,a5
sp3         tst.b   d5
            beq     sp6
            move.l  0(a5),d0
            bsr     hexa
            move.l  4(a5),d0
            bsr     putstr
            move.l  #23,d1
            bsr     tab
            move.b  8(a5),d0
            and.l   #3,d0
            mulu    #9,d0
            add.l   #mp_flags,d0
            bsr     putstr
            move.b  9(a5),d3
            bsr     bytedec
            move.b  14(a5),d3
            bsr     bytedec
            move.l  #ganzlongnix,d0
            move.l  10(a5),a3
            cmp.l   #0,a3
            beq.s   sp8
            move.l  10(a3),d1
            move.l  d1,d2
            andi.l  #$ff000000,d2
            bne.s   sp8
            move.l  d1,d0
sp8         bsr     putnam
            lea     16(a5),a5
            subq.b  #1,d5
            bra     sp3
sp6         rts

getpdata    move.l  a4,0(a5)
            move.l  10(a4),4(a5)
            move.b  14(a4),8(a5)
            move.b  15(a4),9(a5)
            move.l  16(a4),10(a5)
            clr.b   d0
            movea.l 20(a4),a3
sp10        movea.l 0(a3),a3
            cmpa.l  #0,a3
            beq.s   sp9
            addq.b  #1,d0
            cmp.b   #255,d0
            bne.s   sp10
sp9         move.b  d0,14(a5)
            lea     16(a5),a5
            addq.b  #1,d5
            rts
*-------- resources ------------

showres     lea     lheader(PC),a0
            bsr     puthead1
            lea     resnam(PC),a0
            bsr     puthead2
            move.l  _SysBase(PC),d5
            add.l   #336,d5
            bsr     show
            rts

*--------- devices  -------------

showdevs    lea     lheader(PC),a0
            bsr     puthead1
            lea     devnam(PC),a0
            bsr     puthead2
            move.l  _SysBase(PC),d5
            add.l   #350,d5
            bsr     show
            rts

*-------- libraries -------------

showlibs    lea     lheader(PC),a0
            bsr     puthead1
            lea     libnam(PC),a0
            bsr     puthead2
            move.l  _SysBase(PC),d5
            add.l   #378,d5

show        lea     buffer,a5
            clr.b   entries
            CALL    Forbid,_SysBase(PC)
            move.l  d5,a4
sl1         move.l  0(a4),a4
            tst.l   0(a4)
            beq.s   sl2
            addq.b  #1,entries
            move.l  a4,0(a5)
            move.l  10(a4),4(a5)
            move.b  33(a4),8(a5)
            move.b  21(a4),9(a5)
            move.b  23(a4),10(a5)
            move.b  14(a4),11(a5)
            lea     12(a5),a5
            bra.s   sl1
sl2         CALL    Permit,_SysBase(PC)

            lea     buffer,a5
dl3         tst.b   entries
            beq.s   sl4
            move.l  0(a5),d0
            bsr     hexa
            move.b  8(a5),d3
            bsr     bytedec
            move.b  9(a5),d3
            bsr     bytedec
            move.b  10(a5),d3
            bsr     bytedec
            move.b  11(a5),d0
            bsr     bin
            move.l  4(a5),d0
            bsr     putnam
            lea     12(a5),a5
            subq.b  #1,entries
            bra.s   dl3
sl4         rts

;find the first entry in the device-list
;returns a1 = pointer to first entry

devinfo     move.l  dosbase(PC),a1
            move.l  34(a1),a1
            move.l  24(a1),a1
            adda.l  a1,a1
            adda.l  a1,a1
            move.l  4(a1),a1
            rts

;unlock a file
unlock      tst.b   fromfile
            bne     ul6
            bsr     readhex
            tst.b   d7
            beq     syntax
            move.l  d0,remembr
            move.l  d0,-(a7)
            move    #-1,d6
            bsr     of44
            tst.l   remembr
            beq.s   ul1
            move.l  #unlerr,d0
            bsr     putnam
            bra     ul4
ul1         move.l  #unl1,d0
            bsr     putstr
            move.l  0(a7),d0
            bsr     getpath
            move.l  #unltxt2,d0
            bsr     putstr
            bsr     readline
            ori.b   #$20,dummy
            cmp.b   #'y',dummy
            bne.s   ul5
            move.l  0(a7),d1
            CALL    UnLock,dosbase
ul5         bsr     freefinfo
ul4         lea     4(a7),a7
ul6         rts
;---------- Show all Locks------------
locks       clr.l   d6
            bra.s   of33

;---------- Open Files-----------
openfiles   moveq   #1,d6
of33        lea     ofheader(PC),a0
            bsr     puthead
of44        bsr     allocfinfo
            bsr     devinfo
            move.l  a1,a3
of1         adda.l  a3,a3
            adda.l  a3,a3
            cmp.l   #2,4(a3)
            bne     of2
            move.l  40(a3),d0
            lsl.l   #2,d0
            move.l  d0,a4
            clr.l   d3
            move.b  (a4)+,d3
            subq    #1,d3
            lea     buffer,a5
of22        move.b  (a4)+,(a5)+
            dbf     d3,of22
            move.b  #':',(a5)+
            clr.b   0(a5)
            cmp.l   #'RAM ',buffer
            bne.s   of5
            cmp.l   #'Disk',buffer+4
            bne.s   of5
            move.l  #$4d3a0000,buffer+2
of5         move.l  #buffer,d1
            move.l  #-2,d2
            CALL    Lock,dosbase(PC)
            tst.l   d0
            bne.s   of6
            move.l  #buffer,d0
            bsr     putstr
            move.l  #nomount,d0
            bsr     putnam
            bra     of2

of6         move.l  d0,-(a7)
            lsl.l   #2,d0
            move.l  d0,a5
of4         move.l  0(a5),d0
            cmp.l   #50,d0
            ble     of3
            move.l  d0,d5
            lsl.l   #2,d5
            move.l  d5,a5
            move.l  d0,d5
            tst     d6
            bpl.s   of45

            cmp.l   remembr(PC),d0
            bne.s   of4
            clr.l   remembr
            move.l  (a7)+,d1
            CALL    UnLock,dosbase(PC)
            rts

of45        move.l  8(a5),d4
            bsr     getfinfo
            move.l  finfoptr,a4

            tst.l   d6
            beq.s   of8
            bmi.s   of8
            tst.l   4(a4)
            bpl     of4
of8         move.l  d5,d0
            bsr     hexa
            move.l  #access,d0
            cmp     #-2,d4
            beq.s   of7
            add.l   #8,d0
of7         bsr     putstr
            tst.l   4(a4)
            bmi.s   of9
            move.l  #longnix,d0
            bsr     putstr
            bra     of10
of9         move.l  124(a4),d0
            bsr     longdec
of10        move.l  d5,d0
            bsr     getpath
            bra     of4

            bsr     newline
of3         move.l  (a7)+,d1
            CALL    UnLock,dosbase(PC)
of2         move.l  0(a3),a3
            cmpa.l  #0,a3
            bne     of1
            bsr     freefinfo
            rts

;---------- Dos Devices ----------

devices     lea     ddheader(PC),a0
            bsr     puthead
            bsr     devinfo
dev1        adda.l  a1,a1
            adda.l  a1,a1
            clr.b   d6
            tst.l   4(a1)
            bne     dev2
            move.l  40(a1),d0
            bsr     putbcpl
            move.l  #10,d1
            bsr     tab
            cmp.l   #20,28(a1)
            ble     dev9
            moveq   #1,d6
            move.l  28(a1),a3
            adda.l  a3,a3
            adda.l  a3,a3
            cmp.l   #20,8(a3)
            ble     dev9
            move.l  8(a3),a2
            adda.l  a2,a2
            adda.l  a2,a2
            move.l  12(a2),d3
            movem.l a1-a3,-(a7)
            bsr     bytedec
            movem.l (a7)+,a1-a3
            moveq   #1,d3
            move.l  20(a2),d0
            bsr     longdec
            move.l  40(a2),d0
            beq.s   devs20
            addq    #1,d0
            sub.l   36(a2),d0
devs20      bsr     longdec
            move.l  44(a2),d0
            bsr     longdec
            bra.s   dev8
dev9        move.l  #notfile,d0
            bsr     putstr
dev8        tst.l   8(a1)
            beq.s   dev6
            move.l  #devload,d0
            bra.s   dev5
dev6        move.l  #devnload,d0
dev5        bsr     putstr
            tst.b   d6
            beq.s   dev7
            move.l  4(a3),d0
            bne.s   dev4
dev7        move.l  16(a1),d0
            bne.s   dev4
            tst.l   8(a1)
            beq.s   dev11
            move.l  8(a1),a3
            move.l  -82(a3),d0
            bsr     putstr
            bra     dev11
dev4        bsr     putbcpl
dev11       bsr     newline
dev2        move.l  0(a1),a1
            cmpa.l  #0,a1
            bne     dev1
            rts

; Check if a named dos-device is mounted
; name in 'buffer'.
; Result: d0 = 0(false) anything else(true).

finddev     bsr     devinfo
fdev1       adda.l  a1,a1
            adda.l  a1,a1
            clr.b   d6
            tst.l   4(a1)
            bne.s   fdev2
            move.l  40(a1),a2
            lea     buffer,a0
            bsr     strbcmp
            tst     d0
            bne.s   fdev3
fdev2       move.l  0(a1),a1
            cmpa.l  #0,a1
            bne.s   fdev1
fdev3       rts

; Re-assign a drive to dos

freedrive   clr.l   dp_Arg1
            bra     ldr3

; Inhibit a disk drive

lockdrive   move.l  #1,dp_Arg1
ldr3        bsr     getstr
            bsr     finddev
            bne.s   ldr1
ldr2        move.l  #buffer,d0
            bsr     putstr
            move.l  #nomount,d0
            bsr     putstr
            move.l  #dishelp,d0
            bra     putnam
ldr1        move.l  #buffer,d1
            CALL    DeviceProc,dosbase(PC)
            tst.l   d0
            beq.s   ldr2
            move.l  d0,a0
            move.l  #31,dp_Type
            bra     cons1

;display the current directory of all processes,
;except Workbench.(Worbench pr_CurrentDir is not a lock)

currentdir  lea     wbname(PC),a1
            CALL    FindTask,_SysBase(PC)
            move.l  d0,wbaddr
            lea     cdheader(PC),a0
            bsr     puthead
            bsr     allocfinfo
            bsr     getaskdat
            lea     buffer,a5
cd2         tst.b   entries
            beq.s   cd6
            cmp.b   #13,8(a5)
            bne.s   cd5
            move.l  wbaddr(PC),d0
            cmp.l   0(a5),d0
            beq.s   cd5
            move.l  4(a5),d0
            bsr     putstr
            move.l  #15,d1
            bsr     tab
            move.l  0(a5),a4
            move.l  152(a4),d0
            bne.s   cd1
            move.l  #syst,d0
            bsr     putnam
            bra.s   cd5
cd1         bsr     getpath
cd5         subq.b  #1,entries
            lea     16(a5),a5
            bra.s   cd2
cd6         bsr     freefinfo
            rts

;Change the current directory setting of a process

cd          tst.b   fromfile
            bne     cd10
            move.l  a0,-(a7)
            lea     wbname(PC),a1
            CALL    FindTask,_SysBase(PC)
            move.l  d0,wbaddr
            move.l  (a7)+,a0
            bsr     getstr
            move.l  a0,-(a7)
            move.l  #buffer,d1
            move.l  #-2,d2
            CALL    Lock,dosbase(PC)
            move.l  (a7)+,a0
            tst.l   d0
            bne     cd16
            move.l  #dnotf,d0
            bra     putnam
cd16        move.l  d0,remembr
            move.l  a0,-(a7)
            bsr     allocfinfo
            move.l  remembr(PC),d0
            bsr     getfinfo
            move.l  finfoptr,a5
            move.l  (a7)+,a0
            tst.l   4(a5)
            bpl.s   cd11
            move.l  #notdir,d0
            bsr     putnam
            bra     cd18
cd11        bsr     nodenam
            moveq.l #2,d7
            lea     TRuNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq.s   cd15
            move.l  d0,a5
            cmp.b   #13,8(a5)
            beq.s   cd15
            bsr     syntax
            bra     cd18
cd15        cmp.l   wbaddr,d0
            bne.s   cd13
            move.l  #wberr,d0
            bsr     putnam
            bra     cd12
cd13        move.l  152(a5),d1
            move.l  remembr,152(a5)
            move.l  d1,remembr
cd12        tst.l   remembr
            beq.s   cd14
            move.l  #unltxt,d0
            bsr     putstr
            move.l  remembr(PC),d0
            bsr     getpath
            move.l  #unltxt2,d0
            bsr     putstr
            bsr     readline
            ori.b   #$20,dummy
            cmp.b   #'y',dummy
            bne.s   cd14
cd18        move.l  remembr(PC),d1
            beq.s   cd14
            CALL    UnLock,dosbase(PC)
cd14        bsr     freefinfo
cd10        rts

inphand     tst.b   background
            bne.s   inph1
            bsr     installh
inph1       move.l  #500,d4
            lea     InInterrupt(PC),a0
inph2       tst.l   4(a0)
            beq.s   inph3
            move.l  4(a0),a0
            dbf     d4,inph2
inph3       tst.b   background
            bne.s   inph4
            movem.l d4/a0,-(a7)
            bsr     removeh
            movem.l (a7)+,d4/a0
inph4       cmp.w   #-1,d4
            bne.s   inph5
            move.l  #failed,d0
            bra     putnam
inph5       move.l  a0,-(a7)
            lea     inheader(PC),a0
            bsr     puthead
            move.l  (a7)+,a5
inph6       move.l  0(a5),a5
            tst.l   0(a5)
            beq.s   inph7
            move.l  a5,d0
            bsr     hexa
            move.l  14(a5),d0
            bsr     hexa
            move.l  18(a5),d0
            bsr     hexa
            move.b  9(a5),d3
            bsr     plusmins
            move.l  10(a5),d0
            bne.s   inph8
            move.l  #longnix,d0
inph8       bsr     putnam
            bra.s   inph6
inph7       rts

;get all screen pointers.
;result: d5=number of screens
;        buffer+100 holds pointers.

getscr      lea     scrheader(PC),a0
            bsr     puthead
getscr2     move.l  intuibase(PC),a2
            move.l  60(a2),a2
            lea     buffer+100,a1
            move.w  #$4000,$dff09a
            clr.l   d5
sr1         move.l  a2,(a1)+
            move.l  0(a2),a2
            addq.l  #1,d5
            cmpa.l  #0,a2
            bne.s   sr1
            subq    #1,d5
            move.w  #-$4000,$dff09a
            rts

;display screen addresses and titles

screens     bsr     getscr
            moveq   #1,d6
            lea     buffer+100,a1
sr2         move    d6,d3
            bsr     bytedec
            move.l  0(a1),d0
            bsr     hexa
            move.l  (a1)+,a2
            move.l  22(a2),d0
            bsr     putnam
            addq    #1,d6
            dbf     d5,sr2
            rts

;display window addresses and titles

windows     clr.b   bool
windows1    bsr     getscr
            tst.b   bool
            beq.s   wn20
            move.l  d5,-(a7)
            lea     fohead(PC),a0
            bsr     puthead
            move.l  (a7)+,d5
wn20        lea     buffer+100,a4
wn2         move.l  #onscr,d0
            bsr     putstr
            move.l  (a4)+,a2
            move.l  22(a2),d0
            bsr     putnam
            move.l  4(a2),a1
            clr     d6
wn1         cmpa.l  #0,a1
            beq.s   wn3
            addq    #1,d6
            move.l  d6,d3
            bsr     bytedec
            move.l  a1,d0
            bsr     hexa
            move.l  32(a1),d0
            bsr     putnam

            tst.b   bool
            beq.s   wn21
            move.l  a1,-(a7)
            move.l  50(a1),a1
            move.l  52(a1),a1
            bsr     fontdata
            move.l  (a7)+,a1

wn21        move.l  0(a1),a1
            bra.s   wn1
wn3         dbf     d5,wn2
            rts

;close a specified screen

closescreen bsr     getscr2
            moveq   #1,d6
            cmp.b   #'$',0(a0)
            bne.s   cs1
            bsr     readhex
            tst     d7
            beq     syntax
            move.l  d0,d4
csin        clr.l   d6
cs1         lea     buffer+100,a2
cs5         tst     d6
            bne.s   cs2
            cmp.l   (a2)+,d4
            beq.s   cs3
            bra.s   cs4
cs2         move.l  (a2)+,a1
            move.l  22(a1),a1
            bsr     strcmp
            tst     d0
            beq.s   cs3
cs4         dbf     d5,cs5
            move.l  #scnofound,d0
            bra     putnam
cs3         move.l  -4(a2),a0
            CALL    CloseScreen,intuibase(PC)
            rts

;close a specified window

closewindow bsr     getscr2
            moveq   #1,d6
            cmp.b   #'$',0(a0)
            bne.s   cw1
            bsr     readhex
            tst     d7
            beq     syntax
cwin        move.l  d0,d4
            clr.l   d6
cw1         lea     buffer+100,a2
cw5         move.l  (a2)+,a4
            move.l  4(a4),a4
cw6         cmpa.l  #0,a4
            beq.s   cw4
            tst     d6
            bne.s   cw2
            cmp.l   a4,d4
            beq.s   cw3
            bra.s   cw7
cw2         move.l  32(a4),a1
            bsr     strcmp
            tst     d0
            beq.s   cw3
cw7         move.l  0(a4),a4
            bra.s   cw6
cw4         dbf     d5,cw5
            move.l  #winnofound,d0
            bra     putnam
cw3         move.l  a4,a0
            clr.l   d0
            CALL    ModifyIDCMP,intuibase(PC)
            move.l  a4,a0
            CALL    CloseWindow,intuibase(PC)
            rts

windowoff   movem.l d1-d7/a0-a6,-(a7)
            bsr     getscr2
            bsr     cwin
            move.l  -(a2),a0
            move.l  a0,d4
            tst.l   4(a0)
            bne.s   woff1
            bsr     getscr2
            bsr     csin
woff1       movem.l (a7)+,d1-d7/a0-a6
            rts

closetskwin movem.l d1-d7/a0-a6,-(a7)
ctw0        bsr     getscr2
            lea     buffer+100,a2
ctw1        move.l  (a2)+,a4
            move.l  4(a4),a4
ctw6        cmpa.l  #0,a4
            beq.s   ctw4
            move.l  86(a4),a0
            move.l  16(a0),d1
            cmp.l   d0,d1
            bne.s   ctw7
            move.l  d0,d1
            move.l  a4,d0
            bsr     windowoff
            move.l  d1,d0
            bra     ctw0
ctw7        move.l  0(a4),a4
            bra.s   ctw6
ctw4        dbf     d5,ctw1
            movem.l (a7)+,d1-d7/a0-a6
            rts

;display windows and associated fonts

windowfonts move.b  #1,bool
            bra     windows1

;display loaded font names and definitions

fonts       lea     fohead(PC),a0
            bsr     puthead
            move.l  gfxbase(PC),a1
            move.l  $8c(a1),a1
fo1         tst.l   0(a1)
            beq.s   fo3
            bsr     fontdata
            move.l  0(a1),a1
            bra     fo1
fo3         rts

fontdata    move.l  a1,d0
            bsr     hexa
            move.w  30(a1),d3
            bsr     bytedec
            move.w  20(a1),d3
            bsr     bytedec
            move.w  24(a1),d3
            bsr     bytedec
            move.l  #romfnt,d0
            btst    #1,23(a1)
            beq.s   fod1
            move.l  #diskfnt,d0
fod1        bsr     putstr
            move.b  32(a1),d3
            bsr     bytedec
            move.b  33(a1),d3
            bsr     bytedec
            move.l  10(a1),d0
            bra     putnam

;set update rate

settime     bsr     getnum
            tst.b   d7
            beq.s   syntax
            tst.w   d2
            bne.s   st1
            move.b  #1,d2
st1         move.b  d2,timeout
            rts
syntax      move.l  #synerr,d0
            bra     putnam

;copy a string from input to 'buffer'
;a0 = pointer to string

getstr      lea     buffer,a5
gst2        cmp.b   #' ',0(a0)
            beq.s   gst1
            cmp.b   #10,0(a0)
            beq.s   gst1
            move.b  (a0)+,(a5)+
            bra.s   gst2
gst1        clr.b   0(a5)
            bra     kllblnks

;read in a nodename or a processname

nodenam     bsr     isdec
            move.b  d2,procnum
nodenam2    bsr     kllblnks
            move.l  a0,a5
gno1        cmp.b   #10,(a0)+
            bne.s   gno1
            move.b  #0,-1(a0)
            rts

;modify a task's priority

taskpri     bsr     getnum
            tst.b   d7
            beq     syntax
            move.b  d2,newpri
            bsr     nodenam
            moveq.l #2,d7
            lea     TRuNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq.s   tp1
            move.l  d0,a1
            move.b  newpri,d0
            CALL    SetTaskPri,_SysBase(PC)
tp1         rts

;set the priority of our task

mypri       bsr     getnum
            tst.b   d7
            beq     syntax
            move.l  _SysBase(PC),a1
            move.l  276(a1),a1
            move.l  d2,d0
            CALL    SetTaskPri,_SysBase(PC)
            rts

;cancel a task or a process. The theory is quite simple:
;(Process->ReturnAddr)-4 points to the return address on
;the stack. Task->SPReg points to the next instruction
;to be executed. We just need a
; *(Task->SPReg) = *(Process->ReturnAddr-4).
;If the process has been started from Dos (CLI) and
;the process is doing disk I/O, the CLI will respond with
;a GURU #87000004 (AsyncPKT=unexpected packed received).
;Thats why the calling CLI is also canceled.


cancel      tst.b   fromfile
            beq.s   cancel1
            rts
cancel1     clr.l   remembr         ;used for CLI stdio
            clr.l   remembr2
            clr.b   bool
            bsr     nodenam
testagain   moveq.l #1,d7
            lea     TReNode(PC),a4
            bsr     findnam
            move.l  a5,pointer
            tst.b   d7
            bne.s   canok
            move.l  #stperr,d0
            bra     putnam
canok       move.l  d0,a1          ;d0=task
            cmp.b   #1,8(a1)       ;TASK ?
            bne.s   isproc
            CALL    RemTask,_SysBase(PC)
            rts
isproc      movem.l d0-d7/a0-a6,-(a7)
            move.l  #-1,d0            ;needed for recursive killing tasks
            CALL    AllocSignal,_SysBase(PC)
            clr.l   d1
            bset    d0,d1
            move.l  d1,cancelbit
            move.l  d0,cancelbnum
            movem.l (a7)+,d0-d7/a0-a6

            clr.l   d5
            tst.l   $ac(a1)         ;pr_CLI
            beq.s   wascreproc
            move.l  $80(a1),a2      ;Seglist
            adda.l  a2,a2
            adda.l  a2,a2
            move.l  12(a2),d1       ;empty ?
            bne.s   wascreproc
            move.l  $ac(a1),a2      ;CommandLineInterface
            adda.l  a2,a2
            adda.l  a2,a2
            move.l  60(a2),d5       ;cli_Module
            tst.l   40(a2)          ;IsInteractive
            beq     dosreturn
            move.l  28(a2),remembr  ;yes,get Cli-Window locks
            move.l  56(a2),remembr2
            bra     dosreturn
wascreproc  tst.b   bool            ;it is not a CLI, ask what to do
            bne.s   unload
            move.b  #3,bool
            move.l  #canerr0,d0     ;ask for Workbench
            bsr     putstr
            bsr     readline
            ori.b   #$20,dummy
            cmp.b   #'y',dummy
            beq.s   andagain
            move.b  #2,bool
            move.l  #canerr1,d0    ;ask for unload
            bsr     putstr
            bsr     readline
            ori.b   #$20,dummy
            cmp.b   #'y',dummy
            bne.s   andagain
            move.b  #1,bool
andagain    move.l  pointer(PC),a5
            bra     testagain      ;test if the task still there

unload      move.l  128(a1),d4 ;get Segmentlist
            beq.s   unl3
            lsl.l   #2,d4
            move.l  d4,a3
            move.l  12(a3),d4
unl3        tst.l   d4
            bne.s   unl4
            move.l  #unloaderr,d0 ;no Segments !?
            bra     putnam

unl4        cmp.b   #3,bool            ;Workbench Task
            bne.s   unl2
            move.l  a1,-(a7)
            move.l  #40,d0             ;build a copy of the
            move.l  #$10000,d1         ;Worbench startup-message
            CALL    AllocMem,_SysBase(PC)
            move.l  d0,startmess
            move.l  (a7)+,a1
            move.l  d0,a0
            move.b  #5,8(a0)
            move.w  #20,18(a0)
            move.l  d4,24(a0)
            move.l  a1,d0
            add.l   #92,d0
            move.l  d0,20(a0)
            movem.l a0-a1,-(a7)
            lea     wbname(PC),a1
            CALL    FindPort,_SysBase(PC)
            movem.l (a7)+,a0-a1
            move.l  d0,14(a0)

unl2        cmp.b   #1,bool
            bne.s   dosreturn
            move.l  a1,-(a7)           ;unload process manualy
            move.l  d4,d1
            CALL    UnLoadSeg,dosbase(PC)
            move.l  (a7)+,a1

dosreturn   move.l  140(a1),savedat ;Processnumber
dosret1     move.w  #$4000,$dff09a
            move.l  54(a1),a3
            move.l  #endtask,0(a3)
            move.l  #2,106(a1)
            move.l  mytask(PC),108(a1)
            cmp.b   #4,15(a1)        ;if waiting
            bne.s   doswait
            move.l  a1,d4
            CALL    Remove,_SysBase(PC)
            move.l  d4,a1
            lea     406(a6),a0       ; activate the task
            CALL    AddHead,_SysBase(PC)
            move.l  d4,a1
doswait     move.w  #-$4000,$dff09a
            tst.b   bool
            bne.s   endnodos
            tst.l   d5
            beq     endcanc
            move.l  $ac(a1),a2
            adda.l  a2,a2
            adda.l  a2,a2
dwa1        movem.l d0-d7/a0-a6,-(a7)
            move.l  cancelbit(PC),d0
            CALL    Wait,_SysBase(PC)
            movem.l (a7)+,d0-d7/a0-a6
            clr.l   d5
            bra     dosret1

endcanc     move.l  a1,-(a7)
            move.l  remembr(PC),d1    ;close CLI-Window
            beq.s   ecan1             ;if any
            CALL    Close,dosbase(PC)
ecan1       move.l  remembr2(PC),d1
            beq.s   ecan2
            CALL    Close,dosbase(PC)
ecan2       move.l  (a7)+,a1

            move.l  savedat(PC),d0   ;remove Task from
            move.l  dosbase(PC),a2   ;TaskArray
            move.l  34(a2),a2
            move.l  0(a2),a2
            adda.l  a2,a2
            adda.l  a2,a2
            lsl.l   #2,d0
            clr.l   0(a2,d0)

endnodos    move.l  a1,d0
            bsr     closetskwin
            move.l  cancelbnum(PC),d0      ;remove our Signal
            CALL    FreeSignal,_SysBase(PC)
            rts

;This Code is (hopefully) excuted by the Process we want
;to kill

endtask     CALL    Forbid,_SysBase(PC)
            CALL    Disable,_SysBase(PC)
            move.l  _SysBase(PC),a1
            move.l  276(a1),a1
            move.l  176(a1),a1          ;Process_ReturnAddr
            lea     -4(a1),a7           ;reset Process Stackptr
            tst.b   bool
            bne.s   et0
            movea.l mytask(PC),a1
            move.l  cancelbit(PC),d0    ;signal Xoper it
            CALL    Signal,_SysBase(PC) ;died
et0         cmp.b   #3,bool             ;Workbench Process ?
            bne.s   et1
            move.l  startmess(PC),a1
            CALL    ReplyMsg,_SysBase(PC) ;reply startup message
et1         rts

;Stop a task (just queue it on a special list)

freeze      bsr     nodenam
            moveq.l #1,d7
            lea     TReNode(PC),a4
            bsr     findnam
            tst.b   d7
            bne.s   frok
            move.l  #stperr,d0
            bra     putstr
frok        move.w  #$4000,$dff09a
            move.l  d0,a1
            CALL    Remove,_SysBase(PC)
            move.w  #-$4000,$dff09a
            move.l  d0,a1
            move.l  d0,a5
            lea     stplist(PC),a0
            CALL    AddHead,_SysBase(PC)
            add.b   #4,15(a5)
            rts
;put the task back on its list
warm        bsr     nodenam
            lea     stplist(PC),a0
            movea.l a5,a1
            clr.l   d7
            bsr     fn4
            tst.b   d7
            bne.s   waok
            move.l  #waerr,d0
            bra     putstr
waok        move.w  #$4000,$dff09a
            move.l  d0,a1
            CALL    Remove,_SysBase(PC)
            move.l  d0,a1
            move.l  d0,a5
            move.l  TReNode,a0
            cmp.b   #8,15(a1)
            bne.s   wa1
            move.l  TWaNode,a0
wa1         adda.l  _SysBase(PC),a0
            CALL    AddTail,_SysBase(PC)
            move.l  d0,a1
            sub.b   #4,15(a5)
            move.w  #-$4000,$dff09a
            move.l  18(a5),d0
            and.l   26(a5),d0
            beq.s   wa2
            movea.l a5,a1
            CALL    Signal,_SysBase(PC)
wa2         rts
;show the hunks of a process
hunks       bsr     nodenam
            moveq.l #2,d7
            lea     TRuNode(PC),a4
            bsr     findnam
            tst.b   d7
            bne.s   hu1
            rts
hu1         move.l  d0,a4
            cmp.b   #13,8(a4)
            beq.s   hu2
            move.l  #noprocs,d0
            bra     putnam
hu2         move.l  128(a4),d0
            beq.s   noprogload
            lsl.l   #2,d0
            move.l  d0,a3
            move.l  12(a3),d1
            beq.s   hu3
            move.l  #segloaded,d0
            bsr     putnam
            bra     hu5
hu3         move.l  172(a4),d1
            bne.s   hu4
noprogload  move.l  #notload,d0
            bra     putnam
hu4         move.l  #cliprocs,d0
            bsr     putnam
            lsl.l   #2,d1
            move.l  d1,a4
            move.l  60(a4),d1
            beq.s   noprogload
            move.l  #procloaded,d0
            bsr     putstr
            move.l  16(a4),d0
            bsr     putbcpl
            bsr     newline
hu5         lea     hunkheader(PC),a0
            bsr     puthead
hu6         move.l  d1,d0
            bsr     hexa
            lsl.l   #2,d1
            move.l  d1,a4
            move.l  d1,d0
            addq.l  #4,d0
            bsr     hexa
            move.l  -4(a4),d0
            bsr     hexa
            bsr     newline
            move.l  0(a4),d1
            bne.s   hu6
            rts
;change the priority of a node
pri         bsr     getnum
            tst.b   d7
            beq     syntax
            move.b  d2,newpri
            bsr     nodenam2
            moveq.l #5,d7
            lea     DevNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq.s   pi1
            move.l  d0,a1
            move.b  newpri,9(a1)
            cmp.l   #SemNode,a4
            ble.s   pi2
            move.l  #listerr,d0
            bra     putnam
pi2         CALL    Forbid,_SysBase(PC)
            CALL    Remove,_SysBase(PC)
            move.l  d0,a1
            move.l  a4,a0
            move.l  0(a0),d6
            lea     0(a6,d6),a0
            CALL    Enqueue,_SysBase(PC)
            CALL    Permit,_SysBase(PC)
pi1         rts
;set all break signals of a task
break       move.l  #$f000,d0
            bra     setthem

signal      bsr     readhex
            tst.b   d7
            beq     syntax
setthem     move.l  d0,savedat
            bsr     nodenam
            moveq.l #2,d7
            lea     TReNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq.s   pi1
            move.l  d0,a1
            move.l  savedat,d0
            and.l   18(a1),d0
            CALL    Signal,_SysBase(PC)
            rts

hide        cmp.b   #10,0(a0)
            bne.s   hid5
            bra     syntax
hid5        lea     hidestart(PC),a2
            move.l  a2,d3
hid0        tst.l   0(a2)
            beq.s   hid1
            move.l  0(a2),a2
            lea     4(a2),a1
            bsr     strcmp
            tst     d0
            beq.s   hid2
            move.l  a2,d3
            bra.s   hid0
hid1        move.l  a0,a4
            bsr     strlen2
            addq    #5,d0
            move.l  #65536,d1
            CALL    AllocMem,_SysBase(PC)
            tst.l   d0
            beq.s   hid4
            move.l  d0,a1
            move.l  d0,0(a2)
            lea     4(a1),a1
hid3        cmp.b   #10,0(a4)
            beq.s   hid4
            move.b  (a4)+,(a1)+
            bra.s   hid3
hid4        rts
hid2        move.l  d3,a3
            move.l  0(a2),0(a3)
freehidden  lea     4(a2),a0
            bsr     strlen
            addq    #5,d0
            move.l  a2,a1
            CALL    FreeMem,_SysBase(PC)
            rts

freehidmem  move.l  hidestart(PC),a4
fhm0        move.l  a4,d0
            beq.s   fhm1
            move.l  a4,a2
            move.l  0(a2),a4
            bsr     freehidden
            bra     fhm0
fhm1        rts

;'flushlibs'
flush       move.l  #$ffffff,d0
            clr.l   d1
            CALL    AllocMem,_SysBase(PC)
            rts

;display library->lib_IDString
info        bsr     nodenam2
            moveq.l #2,d7
            lea     DevNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq.s   fhm1
            move.l  d0,a0
            move.l  24(a0),d0
            beq.s   if1
            move.l  d0,d1
            andi.l  #$ff000000,d1
            bne.s   if1
            bra     putnam
if1         move.l  #noinfo,d0
            bsr     putstr
            move.l  a5,d0
            bra     putnam

capture     move.l  _SysBase(PC),a1
            lea     42(a1),a0
            moveq   #2,d6
            lea     coldtxt,a4
cap0        move.l  a4,d0
            bsr     putstr
            move.l  0(a0),d0
            bne.s   cap1
            move.l  #unset,d0
            bsr     putstr
            bra     cap2
cap1        bsr     hexa
cap2        bsr     newline
            lea     15(a4),a4
            lea     4(a0),a0
            dbf     d6,cap0

            move.l  #kicktxt,d0
            bsr     putstr
            move.l  546(a1),a0
            cmpa.l  #0,a0
            bne.s   kickm3
            move.l  #unset,d0
            bra     putnam
kickm3      move.l  a0,-(a7)
            bsr     newline
            lea     kickhead(PC),a0
            bsr     puthead
            move.l  (a7)+,a0
kickm0      cmpa.l  #0,a0
            bne.s   kickm1
            rts
kickm1      move.w  14(a0),d6
            subq    #1,d6
            lea     16(a0),a2
kickm2      move.l  0(a2),d0
            bsr     hexa
            move.l  0(a2),d0
            move.l  4(a2),d4
            add.l   d4,d0
            bsr     hexa
            move.l  d4,d0
            clr.b   d3
            bsr     longdec
            bsr     newline
            lea     8(a2),a2
            dbf     d6,kickm2
            move.l  0(a0),a0
            bra     kickm0
            rts

clrcold     move.l  _SysBase,a0
            clr.l   42(a0)
            bra.s   chksum
clrcool     move.l  _SysBase,a0
            clr.l   46(a0)
            bra.s   chksum
clrwarm     move.l  _SysBase,a0
            clr.l   50(a0)

chksum      lea     34(a0),a1
            move    #22,d0
addchk      add     (a1)+,d1
            dbf     d0,addchk
            not     d1
            move.w  d1,82(a0)
            rts

setwindow   tst.b   fromfile
            bne.s   wiw1
            move.l  #wiwerr,d0
            bra     putnam
wiw1        lea     window_l(PC),a3
            moveq   #3,d5
wiw0        bsr     getnum
            tst     d7
            beq.s   wiw2
            move.w  d2,0(a3)
            lea     2(a3),a3
            dbf     d5,wiw0
wiw2        rts

;display ExecBase->LastAlert
lastalert   movem.l $100,d1-d2
            tst.l   d1
            bne.s   al1
            move.l  _SysBase(PC),a0
            movem.l 514(a0),d1-d2
            bra.s   al1
alert       movem.l $100,d1-d2
            cmp.l   #'HELP',0
            beq.s   al1
            move.l  #noguru,d0
            bra     putnam

al1         move.l  #gurutxt,d0
            bsr     putstr
            move.l  d1,d0
            bsr     hex8
            lea     out,a0
            move.l  ptr(PC),d0
            move.b  #'.',-1(a0,d0)
            move.l  d2,d0
            bsr     hex8
            bra     newline

;toggle '<MORE>' on/off
moretst     tst.b   fromfile
            beq.s   mtst1
            bchg    #0,morefl2
            rts
mtst1       bchg    #0,morefl
            rts
;toggle CPUSE task list
usage       bchg    #0,usageflag
            rts

;toggle task-header display on/off
nohead      bchg    #0,headon
            rts

;toggle hide entries on/off
hidden      bchg    #0,hideon
            rts

;toggle sort on/off
sort       bchg    #0,sorton
            rts

;toggle task-ports display on/off
taskports   bchg    #0,tports
clo1        rts

;Open a library
openlib     bsr     nodenam2
            move.l  a5,a1
            clr.l   d0
            CALL    OpenLibrary,_SysBase(PC)
            tst.l   d0
            beq     fn5
opli1       bsr     clearscr
            bra     showlibs

;close it
closelib    bsr     nodenam2
            clr.l   d7
            lea     LibNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq.s   clo1
            move.l  d0,a1
            CALL    CloseLibrary,_SysBase(PC)
            bra     opli1

;end Xoper but stay in background
hold        lea     4(a7),a7
            bra.s   instback
quithold    lea     in,a0
            lea     dummy,a1
qh1         move.b  (a1)+,d0
            move.b  d0,(a0)+
            cmp.b   #10,d0
            bne.s   qh1

instback    tst.b   background
            bne.s   cleanit
            move.b  #1,background
            bsr     installh
cleanit     tst.l   fileptr
            beq.s   ib1
            move.l  window(PC),a0
            move.w  4(a0),window_l
            move.w  6(a0),window_t
            move.w  8(a0),window_w
            move.w  10(a0),window_h
            move.l  fileptr(PC),d1
            CALL    Close,dosbase(PC)
            clr.l   fileptr
ib1         clr.b   running
            move.l  mysignal(PC),d0
            CALL    Wait,_SysBase(PC)
            move.b  #1,running
            bra     restart

;fill all unused memory-chunks with a longword
clear       clr.l   d0
            cmp.b   #10,0(a0)
            beq.s   clr5
            bsr     readhex
            tst.b   d7
            beq     syntax
clr5        move.l  _SysBase(PC),a0
            clr.l   parmtxt
            lea     322(a0),a0
            move.w  #$4000,$dff09a
clr1        move.l  0(a0),a0
            tst.l   0(a0)
            beq.s   clr4
            move.l  16(a0),a1
clr2        tst.l   0(a1)
            beq.s   clr1
            add.l   #1,parmtxt
            move.l  4(a1),d1
            sub.l   #8,d1
            beq.s   clr31
            lsr.l   #2,d1
            subq.l  #1,d1
            lea     8(a1),a2
clr3        move.l  d0,(a2)+
            dbf     d1,clr3
clr31       move.l  0(a1),a1
            bra.s   clr2
clr4        move.w  #-$4000,$dff09a
            move.l  parmtxt(PC),d0
            bsr     bytedec
            move.l  #clrtxt,d0
            bra     putnam

;find a named node
;d7 = number of lists to search through
;a4 = pointer to the first entry in the
;     list-offset-table
;a5 = pointer to name
;returns:
;d7 = TRUE/FALSE 1/0
;d0 = node

findnam     cmp.b   #'$',0(a5)
            bne.s   fn2
            move.l  d7,d2
            move.l  a5,a0
            bsr     readhex
            tst.b   d7
            beq.s   fn6
            move.l  d2,d7
            bsr     tstnode
            tst.l   d5
            bne.s   fn3
            bra     fn5
fn6         move.l  d2,d7
fn2         move.l  _SysBase(PC),a0
            adda.l  0(a4),a0
            move.l  a5,a1
fn4         CALL    FindName,_SysBase(PC)
            tst.l   d0
            bne.s   fn1
            lea     4(a4),a4
            dbf     d7,fn2
fn5         move.l  #namerr,d0
            bsr     putstr
            move.l  a5,d0
            bsr     putnam
            clr.b   d7
            rts
fn1         move.b  procnum(PC),d2
            beq.s   fn3
            move.l  d0,a0
            cmp.b   143(a0),d2
            bne.s   fn4
fn3         moveq.l #1,d7
            rts

;list-offset-table
TRuNode     dc.l    276
TReNode     dc.l    406
TWaNode     dc.l    420
DevNode     dc.l    350
LibNode     dc.l    378
ResNode     dc.l    336
MemNode     dc.l    322
PorNode     dc.l    392
SemNode     dc.l    532

;Node has been entered in hex. Check if this node exsists
tstnode     tst.b   fromfile
            bne.s   illegalhex
            move.l  d0,d1
            and.l   #$ff000001,d1
            beq.s   inrange
            move.l  #adrerr,d0
            bsr     putnam
illegalhex  clr.l   d5
            rts
inrange     movem.l d7/a4,-(a7)
            cmp.l   #TRuNode,a4
            bne.s   inrange1
            move.l  _SysBase(PC),a0
            cmp.l   276(a0),d0
            beq.s   nodefound
            subq    #1,d7
            lea     4(a4),a4
inrange1    move.w  #$4000,$dff09a
getlist     move.l  _SysBase(PC),a0
            add.l   0(a4),a0
nxtnode     tst.l   0(a0)
            beq.s   nxtlist
            cmp.l   a0,d0
            beq.s   nodefound
            move.l  0(a0),a0
            bra.s   nxtnode
nxtlist     lea     4(a4),a4
            dbf     d7,getlist
            move.w  #-$4000,$dff09a
            movem.l d0/d7/a4,-(a7)
            move.l  #noderr,d0
            bsr     putnam
            bsr     readline
            movem.l (a7)+,d0/d7/a4
            or.b    #32,dummy
            cmp.b   #'y',dummy
            beq.s   nodefound1
            clr.l   d5
            movem.l (a7)+,d7/a4
            rts
nodefound   move.w  #-$4000,$dff09a
nodefound1  move.b  #1,d5
etst        movem.l (a7)+,d7/a0
            rts

;clear our window
clearscr    tst.b   fromfile
            bne.s   cscr1
            move.l  #cls,d2
            move.l  fileptr,d1
            moveq.l #6,d3
            CALL    Write,dosbase(PC)
cscr1       rts
;allocate FileInfoBlock
allocfinfo  move.l  #260,d0
            clr.l   d1
            CALL    AllocMem,_SysBase(PC)
            move.l  d0,finfoptr
            rts

;free FileInfoBlock
freefinfo   move.l  #260,d0
            move.l  finfoptr,a1
            CALL    FreeMem,_SysBase(PC)
            rts

;Examine ,d0=Lock
getfinfo    move.l  d0,d1
            move.l  finfoptr,d2
            CALL    Examine,dosbase(PC)
            rts

;construct a Pathname from a lock
;d0=Lock ,resulting string is written to window
getpath     movem.l d1-d7/a0-a6,-(a7)
            move.l  d0,d1
            CALL    DupLock,dosbase(PC)
            lea     out,a4
            clr.b   -(a4)
gp0         tst.l   d0
            beq.s   putall
            move.l  d0,-(a7)
            bsr     getfinfo
            move.l  finfoptr,a0
            move.l  4(a0),d4
            lea     8(a0),a0
            bsr     strlen
            lea     -1(a4),a5
            tst.l   d4
            bmi.s   nodir
            move.b  #'/',-(a4)
nodir       subq    #1,d0
            bmi.s   nofnam
gp1         move.b  0(a0,d0),-(a4)
            dbf     d0,gp1
nofnam      move.l  0(a7),d1
            CALL    ParentDir,dosbase(PC)
            move.l  d0,d4
            move.l  (a7)+,d1
            CALL    UnLock,dosbase(PC)
            move.l  d4,d0
            bra     gp0
putall      cmp.b   #'/',0(a5)
            bne.s   gp2
            move.b  #':',0(a5)
gp2         move.l  a4,d0
            bsr     putnam
            movem.l (a7)+,d1-d7/a0-a6
            rts
strlen      move.l  a0,-(a7)
            move.l  #-1,d0
strl2       addq.l  #1,d0
            tst.b   (a0)+
            bne.s   strl2
            move.l  (a7)+,a0
            rts
strlen2     move.l  a0,-(a7)
            move.l  #-1,d0
strl22      addq.l  #1,d0
            cmp.b   #10,(a0)+
            bne.s   strl22
            move.l  (a7)+,a0
            rts

;write a title and underline
;a0 = pointer to text
puthead1    bsr     strlen
            move.l  d0,d5
            move.l  a0,d0
            bra     putstr

puthead2    bsr     strlen
            add.l   d0,d5
            bra.s   ph2

puthead     bsr     strlen
            move.l  d0,d5
ph2         move.l  a0,d0
            bsr     putnam
            lea     out,a0
            move.l  a0,d0
ph1         move.b  #'-',(a0)+
            dbf     d5,ph1
            move.b  #$9b,(a0)+
            move.b  #'K',(a0)+
            move.b  #$0a,(a0)+
            clr.b   0(a0)
            bra     putstr

;move cursor to a column
;d0 = current position
;d1 = column
tab         move.l  a3,-(a7)
            lea     out,a3
sp5         cmp.b   d1,d0
            bcc.s   sp4
            move.b  #' ',0(a3,d0)
            addq.b  #1,d0
            bra.s   sp5
sp4         move.l  d1,ptr
            move.l  (a7)+,a3
            rts

;convert ascii to byte
;a0 = pointer to text
;d0 = byte
getnum      cmp.b   #'$',0(a0)
            bne.s   isdec
            bsr     readhex
            move.l  d0,d2
            rts
isdec       clr.w   d2
            clr.w   d3
            clr.b   d6
            clr.b   d7
            cmp.b   #'-',0(a0)
            bne.s   gn1
            lea     1(a0),a0
            moveq.l #1,d6
gn1         move.b  (a0)+,d3
            cmp.b   #'9',d3
            bhi.s   gn2
            cmp.b   #'0',d3
            bcs.s   gn2
            moveq.l #1,d7
            and.b   #$f,d3
            muls    #10,d2
            add.w   d3,d2
            bra.s   gn1
gn2         tst.b   d6
            beq.s   gn3
            neg.w   d2
gn3         tst.b   d7
            bne.s   gn4
            lea     -1(a0),a0
gn4         rts

;convert hex to longword
;a0 = pointer to text
;returns d0=value
;d7 = ok/error 1/0
readhex     movem.l d1-d6/a1-a5,-(a7)
            moveq   #1,d7
            cmp.b   #'$',0(a0)
            bne.s   rh3
            lea     1(a0),a0
rh3         clr.l   d0
            cmpi.b  #10,0(a0)
            beq.s   rherr
            lea     hextab(pc),a1
rh0         move.b  (a0)+,d3
            moveq.l #15,d2
rh1         cmp.b   0(a1,d2),d3
            beq.s   rh2
            dbf     d2,rh1
            bra     rhend
rh2         lsl.l   #4,d0
            or.b    d2,d0
            bra.s   rh0
rhend       tst.b   d3
            beq.s   rhok
            cmpi.b  #10,d3
            beq.s   rhok
            cmpi.b  #' ',d3
            beq.s   rhok
rherr       clr.l   d7
rhok        movem.l (a7)+,d1-d6/a1-a5
            rts

;skip blanks
;a0 pointer to text
; returns a0 = new pointer position
kllblnks    cmpi.b  #' ',0(a0)
            bne.s   gn4
            lea     1(a0),a0
            bra.s   kllblnks

; exit program. If background flag is set, wait for
; amiga-amiga-x

stopall     lea     4(a7),a7
            bra     exitall

exit        tst.b   background
            bne     quithold
exitall     move.l  stplist(PC),a3
            tst.l   0(a3)
            beq.s   ex0
            move.l  a3,d0
            bsr     waok
            bra.s   exitall

ex0         tst.b   background
            beq.s   ex1
            bsr     removeh

ex1         move.l  _SysBase(PC),a1
            move.l  #_LVOSwitch,a0
            move.l  oldswitch,d0
            CALL    SetFunction,_SysBase(PC)
            move.l  #3,d0
            lea     IOCounter(PC),a1
            CALL    RemIntServer,_SysBase(PC)

            move.l  replyport(PC),-(a7)
            LIBCALL DeletePort
            lea     4(a7),a7
            move.l  fileptr(PC),d1
            beq.s   ex11
            CALL    Close,dosbase(PC)
ex11        bsr     freehidmem
        IFND DEBUG
            CALL    Forbid,_SysBase(PC)
            move.l  wbmsg(PC),d0
            beq.s   todos
            move.l  d0,a1
            CALL    ReplyMsg,_SysBase(PC)
            clr.l   d0
            rts

todos       move.l  myseg(PC),d1
            CALL    UnLoadSeg,dosbase(PC)
        ENDC
            clr.l   d1
            CALL    Exit,dosbase(PC)

;print a bcpl-string
;d0 = bcpl-pointer to bcpl-string
putbcpl     movem.l d3/a0-a1,-(a7)
            tst.l   d0
            beq.s   pb1
            lsl.l   #2,d0
            move.l  d0,a1
            clr.l   d3
            move.b  (a1)+,d3
            move.l  ptr(PC),d0
            lea     out,a0
pb2         move.b  (a1)+,0(a0,d0)
            addq.b  #1,d0
            dbf     d3,pb2
            move.l  d0,ptr
pb1         movem.l (a7)+,d3/a0-a1
            rts

;compare strings
;a0/a1 = pointers to string
;returns d0 = true(0) false(1)
strcmp      movem.l a0-a1,-(a7)
            clr.l   d0
src2        move.b  (a0)+,d0
            beq.s   src1
            cmp.b   #10,d0
            beq.s   src1
            cmp.b   (a1)+,d0
            beq.s   src2
            bra.s   src3
src1        move.b  0(a1),d0
src3        movem.l (a7)+,a0-a1
            rts

;compare bcpl string with string
;a0 = pointer to string
;a2 = bcpl-pointer to bcpl-string
;returns d0 = true(0) false(1)
strbcmp     movem.l d1/a0/a2,-(a7)
            clr.l   d0
            clr.l   d1
            adda.l  a2,a2
            adda.l  a2,a2
            move.b  (a2)+,d1
            beq.s   stb1
            subq    #1,d1
stb2        cmp.b   (a2)+,(a0)+
            bne.s   stb1
            dbf     d1,stb2
            moveq   #1,d0
stb1        movem.l (a7)+,d1/a0/a2
            rts

;concat strings
;a0 = pointer to string
;a1 = pointer to string to be appended
;returns d0 = strlen
strcat      movem.l d1/a0-a1,-(a7)
            bsr     strlen
            move.l  d0,d1
            exg     a0,a1
            bsr     strlen
            adda.w  d1,a1
stc1        move.b  (a0)+,(a1)+
            dbf     d0,stc1
            move.l  a1,d0
            movem.l (a7)+,d1/a0-a1
            sub.l   a0,d0
            rts

;convert long to decimal
;d0 = value
;d3 bit 0 = left/right justified
;d3 bit 1 = write/leave
;returns string in 'buffer'
longdec     movem.l d1-d2/a1-a2,-(a7)
            lea     binarea+8(PC),a1
            move.l  #'    ',-8(a1)
            move.l  #'    ',-4(a1)
            clr.b   0(a1)
            lea     -1(a1),a1
            cmp     #2,d3
            bne.s   ld5
            clr.b   0(a1)
ld5         moveq   #1,d2
ld2         addq    #1,d2
            moveq   #$a,d1
            bsr     div
            addi.l  #$30,d1
            move.b  d1,-(a1)
            tst.l   d0
            bne.s   ld2

            btst    #0,d3
            bne.s   ld1
            lea     binarea(PC),a2
ld3         move.b  0(a1),(a2)+
            move.b  #' ',(a1)+
            dbf     d2,ld3
ld1         cmp     #2,d3
            beq.s   ld4
            move.l  #binarea,d0
            bsr     putstr
ld4         movem.l (a7)+,d1-d2/a1-a2
            rts

;write UBYTE
;d3 = value
bytedec     move.l  #dezimal,d0
pm1         bsr     dec
            bra     putstr

;write signed byte
;d3 = value
plusmins    move.l  #minus+1,d0
            move.w  #$2020,minus
            tst.b   d3
            bpl.s   pm1
            neg.b   d3
            jsr     dec
            move.b  #'-',-(a3)
            bra.s   putstr

dec         move.l  #$20202020,dezimal
            clr.l   d4
            and.l   #$ff,d3
            lea     dezimal+3(PC),a3
bloop       tst.b   d3
            beq.s   bend
            divu    #10,d3
            swap    d3
            ori.b   #48,d3
            move.b  d3,-(a3)
            clr.w   d3
            swap    d3
            bra.s   bloop
bend        cmpa.l  #dezimal+3,a3
            bne     nixfirst
            move.b  #'0',-(a3)
nixfirst    rts

;write a string, move cursor into next line
;d0 = pointer to text
putnam      bsr     putstr
            tst.b   d0
            beq.s   ncr
            bsr     newline
ncr         rts

;write one char
;d0 = char
putchar     movem.l d1/a0,-(a7)
            move.l  ptr(PC),d1
            lea     out,a0
            move.b  d0,0(a0,d1)
            add.l   #1,ptr
            movem.l (a7)+,d1/a0
            rts

;write a string, strings are only written when they end with LF
;d0 = pointer to string
;returns d0 = cursor position
putstr      movem.l d1-d7/a0-a6,-(a7)
            move.b  #1,printed
            move.l  d0,a2
            lea     out,a3
            move.l  ptr(PC),d0
            cmp.l   #0,a2
            beq     prend
            clr     d5
pst1        addq    #1,d5
            cmp     #81,d3
            beq     prend
            move.b  (a2)+,d1
            cmpi.b  #13,d1
            beq     pst1
            move.b  d1,0(a3,d0)
            beq     prend
            addq    #1,d0
            cmpi.b  #$0a,d1
            bne.s   pst1
            tst.b   fromfile
            bne.s   pst24
            move.l  d0,d3
            move.l  a3,d2
            move.l  fileptr,d1
            CALL    Write,dosbase(PC)
pst24       clr.l   d0
            clr     d5
            tst.b   morefl
            beq.s   pst1
            tst.b   mnflag
            beq.s   pst1
            add.b   #1,row
            move.b  row(PC),d1
            cmp.b   rows,d1
            bne.s   pst1
            move.l  #50,d2
            move.l  fileptr(PC),d1
            CALL    WaitForChar,dosbase(PC)
            beq.s   pst23
            bsr     readline
pst23       move.l  #6,d3
            move.l  fileptr(PC),d1
            move.l  #more,d2
            CALL    Write,dosbase(PC)
            bsr     readline
            bsr     raw
            clr.b   row
            move.l  fileptr(PC),d1
            move.l                                        #1,d3
            move.l  #thisline,d2
            CALL    Write,dosbase(PC)
            clr.l   d0
            bra     pst1
prend       move.l  d0,ptr
            movem.l (a7)+,d1-d7/a0-a6
            rts

;Write 8 byte hex value
;d0 = value
hex8        movem.l d1-d7/a0-a6,-(a7)
            moveq.l #7,d5
            lea     hex8area(PC),a1
            bra     hx1

;Write 6 byte hex value
;d0 = value
hexa        movem.l d1-d7/a0-a6,-(a7)
            moveq.l #5,d5
            lea     hexarea(PC),a1
hx1         lea     hextab(PC),a0
            clr.l   d2
hexloop     move.b  d0,d2
            and.b   #15,d2
            move.b  0(a0,d2),0(a1,d5)
            lsr.l   #4,d0
            dbf     d5,hexloop
            move.l  a1,d0
            movem.l (a7)+,d1-d7/a0-a6
            bra     putstr

;Convert/write byte into binary string
;d0 = value
bin         movem.l d1-d7/a0-a6,-(a7)
            move.b  #' ',binarea+9
            moveq.l #7,d4
            lea     binarea(PC),a0
binloop     moveq.l #'0'/2,d1
            roxr.b  #1,d0
            roxl.b  #1,d1
            move.b  d1,0(a0,d4)
            dbf     d4,binloop
            move.l  a0,d0
            movem.l (a7)+,d1-d7/a0-a6
            bra     putstr

;read one line of input string
readline    tst.b   fromfile
            bne.s   rlin1
            move.l  fileptr(PC),d1
            move.l  #dummy,d2
            moveq.l #80,d3
            CALL    Read,dosbase(PC)
            rts
rlin1       lea     dummy,a3
rlin4       move.l  infile(PC),d1
            move.l  a3,d2
            moveq.l #1,d3
            CALL    Read,dosbase(PC)
            tst.l   d0
            beq.s   rlin5
            cmp.b   #10,(a3)+
            beq.s   rlin2
            bra.s   rlin4
rlin5       move.b  #1,eof
rlin3       move.b  #10,0(a3)
rlin2       lea     dummy,a0
            bsr     strlen2
            addq    #1,d0
            rts

;switch console to con: mode & empty input buffer
con         tst.b   fromfile
            bne.s   conend
            bsr     cmdcon
            move.l  #50,d2
            move.l  fileptr(PC),d1
            CALL    WaitForChar,dosbase(PC)
            beq.s   conend
            bsr     readline
conend      rts


cmdcon      clr.l   dp_Arg1
            move.l  conmsg(PC),a0
            move.l  #994,dp_Type
            bra.s   cons1

;switch console window to raw mode
raw         tst.b   fromfile
            bne.s   conend
            move.l  conmsg(PC),a0
            move.l  #994,dp_Type
            move.l  #-1,dp_Arg1

;send a packet
;a0 = msgport
;dp_Type and dp_Arg1 have to be inizialized
cons1       movem.l d0-d7/a0-a6,-(a7)
            move.l  #dp_Link,LN_NAME
            move.l  #mypacket,dp_Link
            move.l  replyport(PC),dp_Port
            lea     mypacket,a1
            CALL    PutMsg,_SysBase(PC)
            move.l  replyport,a0
            CALL    WaitPort,_SysBase(PC)
            move.l  replyport(PC),a0
            CALL    GetMsg,_SysBase(PC)
            movem.l (a7)+,d0-d7/a0-a6
            rts

;32-bit division
;d0 / d1
;returns d0
div         movem.l d2-d3,-(a7)
            swap    d1
            move.w  d1,d2
            bne.s   div1
            swap    d0
            swap    d1
            swap    d2
            move.w  d0,d2
            beq.s   div2
            divu    d1,d2
            move.w  d2,d0
div2        swap    d0
            move.w  d0,d2
            divu    d1,d2
            move.w  d2,d0
            swap    d2
            move.w  d2,d1
            bra     div8
div1        moveq   #$10,d3
            cmpi.w  #$80,d1
            bcc.s   div3
            rol.l   #8,d1
            subq.w  #8,d3
div3        cmpi.w  #$800,d1
            bcc.s   div4
            rol.l   #4,d1
            subq.w  #4,d3
div4        cmpi.w  #$2000,d1
            bcc.s   div5
            rol.l   #2,d1
            subq.w  #2,d3
div5        tst.w   d1
            bmi.s   div6
            rol.l   #1,d1
            subq.w  #1,d3
div6        move.w  d0,d2
            lsr.l   d3,d0
            swap    d2
            clr.w   d2
            lsr.l   d3,d2
            swap    d3
            divu    d1,d0
            move.w  d0,d3
            move.w  d2,d0
            move.w  d3,d2
            swap    d1
            mulu    d1,d2
            sub.l   d2,d0
            bcc.s   div7
            subq.w  #1,d3
            add.l   d1,d0
div7        moveq   #0,d1
            move.w  d3,d1
            swap    d3
            rol.l   d3,d0
            swap    d0
            exg     d1,d0
div8        movem.l (a7)+,d2-d3
            rts

;install a input-handler
installh    pea     0
            pea     xopsleep
            LIBCALL CreatePort
            lea     8(a7),a7
            move.l  d0,InputMsg
            move.l  d0,-(a7)
            LIBCALL CreateStdIO
            lea     4(a7),a7
            move.l  d0,InRequest
            move.l  d0,a1
            lea     devicenam(PC),a0
            clr.l   d0
            clr.l   d1
            CALL    OpenDevice,_SysBase(PC)
            move.l  d0,devstatus
            movea.l InRequest(PC),a1
            move.l  #InInterrupt,40(a1)
            move.w  #9,28(a1)
            CALL    DoIO,_SysBase(PC)
            move.l  d0,iostatus
            move.l  #-1,d0
            CALL    AllocSignal,_SysBase(PC)
            clr.l   d1
            bset    d0,d1
            move.l  d1,mysignal
            rts

;remove handler
removeh     movea.l InRequest(PC),a1
            move.l  #InInterrupt,40(a1)
            move.w  #10,28(a1)
            CALL    DoIO,_SysBase(PC)
            movea.l InRequest(PC),a1
            CALL    CloseDevice,_SysBase(PC)
            move.l  InRequest,-(a7)
            LIBCALL DeleteStdIO
            lea     4(a7),a7
            move.l  InputMsg,-(a7)
            LIBCALL DeletePort
            lea     4(a7),a7
            rts

;this is the handler, it checks if amiga-amiga-x
;has been pressed and signals it to our task
Keyhandler  tst.b   running
            bne.s   endhandler
            cmp.b   #1,4(a0)
            bne.s   endhandler
            move.w  8(a0),d0
            andi.w  #$c0,d0
            cmpi.w  #$c0,d0
            bne.s   endhandler
            cmp.w   #$32,6(a0)
            bne.s   endhandler
wakeup      move.l  a0,-(a7)
            movea.l mytask(PC),a1
            move.l  mysignal(PC),d0
            CALL    Signal,_SysBase(PC)
            move.l  (a7)+,a0
            clr.b   4(a0)
endhandler  move.l  a0,d0
            rts

snoop       bsr     nodenam
            moveq.l #2,d7
            lea     TRuNode(PC),a4
            bsr     findnam
            tst.b   d7
            beq     tm6
            move.l  d0,captask
            pea     0
            pea     memportname
            LIBCALL CreatePort
            lea     8(a7),a7
            move.l  d0,snoopport
            beq     tm6
            lea     snoophead(PC),a0
            bsr     puthead
            move.l  _SysBase(PC),a1
            move.l  -196(a1),oldalloc
            move.l  -208(a1),oldfree
            move.l  #capmalloc,d0
            move.l  #-198,a0
            CALL    SetFunction,_SysBase(PC)
            move.l  _SysBase(PC),a1
            move.l  #capmfree,d0
            move.l  #-210,a0
            CALL    SetFunction,_SysBase(PC)
            clr.b   bool
            clr.b   cbreak
            bsr     con
waitmem     move.l  snoopport(PC),a0
            move.l  #$1000,d0
            clr.l   d1
            move.b  15(a0),d1
            bset    d1,d0
            CALL    Wait,_SysBase(PC)
            btst    #12,d0
            beq.s   tm7
            move.b  #1,cbreak
tm7         move.l  mytask(PC),a0
            move.l  snoopport(PC),a0
            CALL    GetMsg,_SysBase(PC)
            tst.l   d0
            bne     tm8
            tst.b   cbreak
            bne     snoopend
            bra     waitmem
tm8         move.l  d0,a3
            move.l  20(a3),d3
            btst    #31,d3
            beq     freed
            move.l  #allok,d0
            bsr     putstr
            lea     memname(PC),a2
            lea     membit(PC),a4
            move.l  #4,d5
tm2         move.l  0(a4),d4
            btst    d4,d3
            beq.s   tm1
            move.l  0(a2),d0
            bsr     putstr
tm1         lea     4(a2),a2
            lea     4(a4),a4
            dbf     d5,tm2
            move.l  #26,d1
            bsr     tab
            move.l  24(a3),d0
            move.l  d0,d3
            bsr     hexa
            move.l  28(a3),d0
            bne.s   tm3
            move.l  #failed,d0
            bsr     putstr
            move.l  #47,d1
            bsr     tab
            bra     tm4
tm3         bsr     hexa
            move.l  28(a3),d0
            add.l   d3,d0
            bsr     hexa
            bra     tm4

freed       move.l  #free,d0
            bsr     putstr
            move.b  #'-',d0
            move.l  #18,d1
tm9         bsr     putchar
            dbf     d1,tm9
            move.b  #' ',d0
            bsr     putchar
            move.l  d3,d0
            bsr     hexa
            move.l  24(a3),d0
            bsr     hexa
            move.l  24(a3),d0
            add.l   d3,d0
            bsr     hexa

tm4         move.l  32(a3),d0
            bsr     hexa
            bsr     newline
            move.w  18(a3),d0
            ext.l   d0
            move.l  a3,a1
            CALL    FreeMem,_SysBase(PC)
            bra     tm7

snoopend    move.l  _SysBase(PC),a1
            move.l  oldalloc(PC),d0
            move.l  #-198,a0
            CALL    SetFunction,_SysBase(PC)
            move.l  _SysBase(PC),a1
            move.l  oldfree,d0
            move.l  #-210,a0
            CALL    SetFunction,_SysBase(PC)
            move.l  snoopport,-(a7)
            LIBCALL DeletePort
            lea     4(a7),a7
tm6         rts

memname     dc.l    memlarg,memclr,memfast,memchip,mempubl
membit      dc.l    17,16,2,1,0

capmalloc   movem.l d0-d7/a0-a6,-(a7)
            move.l  _SysBase(PC),a6
            move.l  276(a6),d4
            cmp.l   captask(PC),d4
            bne.s   capm1
            tst.b   bool
            bne     capm1
            move.b  #1,bool
            move.l  #36,d6
            bsr     allocmsg
            beq     capm2
            bset    #31,d1
            move.l  d1,20(a5)
            move.l  d0,24(a5)
            move.l  60(a7),32(a5)
            move.l  a5,remembr
            movem.l (a7)+,d0-d7/a0-a6
            bsr     memalloc
            movem.l d0-d7/a0-a6,-(a7)
            move.l  remembr(PC),a1
            move.l  d0,28(a1)
            move.l  snoopport,a0
            move.b  #5,8(a1)
            CALL    PutMsg,_SysBase(PC)
            clr.b   bool
            movem.l (a7)+,d0-d7/a0-a6
            rts
capm2       clr.b   bool
capm1       movem.l (a7)+,d0-d7/a0-a6
memalloc    dc.w    $4ef9
oldalloc    dc.l    0

capmfree    movem.l d0-d7/a0-a6,-(a7)
            move.l  _SysBase(PC),a6
            move.l  276(a6),d4
            cmp.l   captask(PC),d4
            bne.s   capf1
            tst.b   bool
            bne.s   capf1
            move.b  #1,bool
            move.l  #36,d6
            bsr     allocmsg
            beq.s   capf2
            move.l  d0,20(a5)
            move.l  a1,24(a5)
            move.l  60(a7),32(a5)
            move.l  snoopport,a0
            move.b  #5,8(a5)
            move.l  a5,a1
            CALL    PutMsg,_SysBase(PC)
capf2       clr.b   bool
capf1       movem.l (a7)+,d0-d7/a0-a6
            dc.w    $4ef9
oldfree     dc.l    0

allocmsg    movem.l d0-d1/a0-a1,-(a7)
            move.l  d6,d0
            move.l  #65536,d1
            bsr     memalloc
            tst.l   d0
            beq.s   alm1
            move.l  d0,a5
            move.w  d6,18(a5)
alm1        movem.l (a7)+,d0-d1/a0-a1
            move.l  a5,d6
            rts

capopendev  movem.l d0-d7/a0-a6,-(a7)
            move.l  _SysBase(PC),a6
            move.l  276(a6),d4
            cmp.l   captask(PC),d4
            bne.s   opdev1
            tst.b   bool
            bne.s   opdev1
            move.l  #36,d6
            bsr     allocmsg
            move.l  #0,d0
opdev1:
myswitch    movem.l d0-d1/a0,-(a7)
            move.l  _SysBase(PC),a0
            move.l  276(a0),d0
            move.l  tasksnum(PC),d1
            lea     cputime,a0
            subq.l  #1,d1
            bmi.s   swadd
sw0         cmp.l   0(a0),d0
            beq.s   swi1
            lea     8(a0),a0
            dbf     d1,sw0
            bra.s   swadd
swi1        add.l   #1,4(a0)
swgo        movem.l (a7)+,d0-d1/a0
            dc.w    $4ef9
oldswitch   dc.l    0
swadd       cmp.l   #125,tasksnum
            bge.s   swgo
            add.l   #1,tasksnum
            move.l  d0,0(a0)
            move.l  #1,4(a0)
            bra.s   swgo

countio     addq.l  #1,iocount
            rts

dosbase     dc.l    0
intuibase   dc.l    0
gfxbase     dc.l    0
window      dc.l    0
parmtxt     dc.l    0
fileptr     dc.l    0
infile      dc.l    0
conmsg      dc.l    0
ptr         dc.l    0
oldidl      dc.l    0
olddisp     dc.l    0
myseg       dc.l    0
mysignal    dc.l    0
iostatus    dc.l    -1
devstatus   dc.l    -1
cancelbit   dc.l    0
cancelbnum  dc.l    0
_SysBase    dc.l    0
InputMsg    dc.l    0
InRequest   dc.l    0
startmess   dc.l    0
savedat     dc.l    0
mytask      dc.l    0
wbmsg       dc.l    0
pointer     dc.l    0
replyport   dc.l    0
finfoptr    dc.l    0
dispatches  dc.l    0
maxdisp     dc.l    0
wbaddr      dc.l    0
remembr     dc.l    0
remembr2    dc.l    0
captask     dc.l    0
snoopport   dc.l    0
tasksnum    dc.l    0
hidestart   dc.l    0
iocount     dc.l    0
dummyinput  dc.l    0

secs        dc.l    0
mics        dc.l    0
time10      dc.l    0


stplist     dc.l    lh_tail
lh_tail     dc.l    0
            dc.l    stplist
            dc.b    1
            dc.b    0

InInterrupt dc.l    0           ;ln_Succ
            dc.l    0           ;ln_Pred
            dc.b    2           ;ln_Type
            dc.b    60          ;ln_Pri
            dc.l    xopsleep    ;ln_Name
            dc.l    0           ;is_Data
            dc.l    Keyhandler  ;is_Code()

IOCounter   dc.l    0           ;ln_Succ
            dc.l    0           ;ln_Pred
            dc.b    2           ;ln_Type
            dc.b    -1          ;ln_Pri
            dc.l    IOcntname   ;ln_Name
            dc.l    0           ;is_Data
            dc.l    countio     ;is_Code()

window_l    dc.w    0
window_t    dc.w    0
window_w    dc.w    550
window_h    dc.w    200

binarea     dc.b    '          ',0
            EVEN
minus       dc.b    '  '
dezimal     dc.b    '   '
blnk        dc.b    ' ',0
entries     dc.b    0
timeout     dc.b    5
procnum     dc.b    0
running     dc.b    0
newpri      dc.b    0
tasktyp     dc.b    0
background  dc.b    0
bool        dc.b    0
printed     dc.b    0
cbreak      dc.b    0
rows        dc.b    0
row         dc.b    0
usageflag   dc.b    0
morefl      dc.b    1
morefl2     dc.b    1
mnflag      dc.b    1
tports      dc.b    1
headon      dc.b    1
hideon      dc.b    1
sorton      dc.b    1
eof         dc.b    0
fromfile    dc.b    0
params      dc.b    'tfdlrempis'
parmnum     equ     *-params
t2header    dc.b    '  ID    STATE   SIGALLOC SIGWAIT  SIGRECVD   PC   TASKNAME',0
theader     dc.b    '  ID    TYPE      STATE    PRI  CPUSE NUM TASKNAME',0
lheader     dc.b    ' NODE  CNT VER REV  FLAGS   ',0
libnam      dc.b    'LIBRARY NAME',0
devnam      dc.b    'DEVICE NAME',0
resnam      dc.b    'RESOURCE NAME',0
mheader     dc.b    'LOWER  UPPER   FREE  ATTR  PRI HUNK NAME',0
nxtline     dc.b    $9b,'K'
cr          dc.b    10,0
iheader     dc.b    ' NODE   DATA   CODE   PRI   TYPE     INTERRUPT NAME',0
inheader    dc.b    ' NODE   DATA   CODE   PRI NAME',0
rheader     dc.b    ' ADDR   PRI  FLAGS   VER   TYPE    RESIDENT NAME',0
pheader     dc.b    ' NODE  PORTNAME        FLAGS SIGBT NUM SIGTASK',0
hunkheader  dc.b    ' BCPL   DATA  LENGTH',0
ddheader    dc.b    'DEVICE   HDS SECTORS  TRACKS BUFFERS STATE    HANDLER',0
cdheader    dc.b    'PROCESSNAME    CURRENT DIRECTORY',0
ofheader    dc.b    ' LOCK  ACCESS  SIZE   PATH/FILENAME',0
scrheader   dc.b    'NUM  ADDR  TITLE',0
fohead      dc.b    ' NODE  CNT  Y   X  TYPE  LO  HI NAME',0
kickhead    dc.b    'START  END    LENGTH',0
snoophead   dc.b    'ACTION REQUIREMENTS       LENGTH FROM   TO     CALLER',0
stackhead   dc.b    'SPLower   SIZE    USED TASKNAME',0
access      dc.b    ' Read  ',0
            dc.b    ' Write ',0
romfnt      dc.b    'Rom  ',0
diskfnt     dc.b    'Disk ',0
wbname      dc.b    'Workbench',0
status      dc.b    'Added    ',0
            dc.b    'Running  ',0
            dc.b    'Ready    ',0
            dc.b    'Waiting  ',0
            dc.b    'Exeption ',0
            dc.b    'Removed  ',0
            dc.b    'Frozen   ',0
            dc.b    'Frozen   ',0
type        dc.b    'Unknown   ',0
            dc.b    'Task      ',0
            dc.b    'Interrupt ',0
            dc.b    'Device    ',0
            dc.b    'Msgport   ',0
            dc.b    'Message   ',0
            dc.b    'Freemsg   ',0
            dc.b    'Replymsg  ',0
            dc.b    'Resource  ',0
            dc.b    'Library   ',0
            dc.b    'Memory    ',0
            dc.b    'Softint   ',0
            dc.b    'Font      ',0
            dc.b    'Process   ',0
            dc.b    'Semaphore ',0
mp_flags    dc.b    'Signal  ',0
            dc.b    'Softint ',0
            dc.b    'Ignore  ',0
windowname  dc.b    'Xoper V1.3  ) 1989 Werner Gunther',0
newname     dc.b    'Xoper',0
memportname dc.b    'MemSnoop',0
xopcon      dc.b    'XopPackets',0
xopsleep    dc.b    'Xop-A-A-x',0
IOcntname   dc.b    'Xop-I/O-counter',0


cmdnum      set      0
commds      ADDCMD  'time'
            ADDCMD  'taskpri'
            ADDCMD  'info'
            ADDCMD  'pri'
            ADDCMD  'flush'
            ADDCMD  'freeze'
            ADDCMD  'warm'
            ADDCMD  'signal'
            ADDCMD  'break'
            ADDCMD  'alert'
            ADDCMD  'lastalert'
            ADDCMD  'hold'
            ADDCMD  'exit'
            ADDCMD  'clear'
            ADDCMD  'cancel'
            ADDCMD  'more'
            ADDCMD  'taskports'
            ADDCMD  'hunks'
            ADDCMD  'devices'
            ADDCMD  'openlib'
            ADDCMD  'closelib'
            ADDCMD  'currentdir'
            ADDCMD  'cd'
            ADDCMD  'mypri'
            ADDCMD  'files'
            ADDCMD  'locks'
            ADDCMD  'unlock'
            ADDCMD  'screens'
            ADDCMD  'windows'
            ADDCMD  'closescreen'
            ADDCMD  'closewindow'
            ADDCMD  'fonts'
            ADDCMD  'windowfonts'
            ADDCMD  'lockdrive'
            ADDCMD  'freedrive'
            ADDCMD  'capture'
            ADDCMD  'clrcold'
            ADDCMD  'clrcool'
            ADDCMD  'clrwarm'
            ADDCMD  'snoop'
            ADDCMD  'usage'
            ADDCMD  'inputhandler'
            ADDCMD  'header'
            ADDCMD  'sort'
            ADDCMD  'hide'
            ADDCMD  'hidden'
            ADDCMD  'window'
            ADDCMD  'kill'
hex8area    dc.b    '  '
hexarea     dc.b    '       ',0
hextab      dc.b    '0123456789abcdef'
infoh2      dc.b    'Dispatches:',0
infoh1      dc.b    'CPU:',0
infoh3      dc.b    'CPU activity: ',0
infoh6      dc.b    'Total:',0
infoh4      dc.b    '% ',0
infoh7      dc.b    'I/O Ints/Sec: ',0
cpu0        dc.b    '68000',0
cpu1        dc.b    '68010',0
cpu2        dc.b    '68020',0
cpu3        dc.b    '/68881',0
syst        dc.b    'DF0:',0
devload     dc.b    'loaded   ',0
devnload    dc.b    'unloaded ',0
prompt      dc.b    $9b,'J','->',$9b,$20,$70
cls         dc.b    $9b,'0 ',$70,$9b,'H'
getwin      dc.b    $9b,$30,$20,$71
thisline    dc.b    $0d
notfile     dc.b    '--- ------- ------- ------- ',0
ganzlongnix dc.b    '-'
longnix     dc.b    '----'
nix         dc.b    '--- ',0
noinfo      dc.b    'No Info on ',0
namerr      dc.b    'Unable to find ',0
adrerr      dc.b    'Address Error!',0
noderr      dc.b    'Can`t find this Node. Continue ? (Y/N)',0
listerr     dc.b    'Unable to find ListHeader. Sort aborted.',0
wiwerr      dc.b    'Script file only',0
noguru      dc.b    'No Alert, shall I produce one ?',0
gurutxt     dc.b    'Guru Meditation #',0
clrtxt      dc.b    'Memory Hunks cleared.',0
canerr0     dc.b    'Process is not a CLI-task',10
            dc.b    'Has it been started from Workbench ? (Y/N)',10,0
canerr1     dc.b    'Process was created by CreateProc()',10
            dc.b    'Shall I UnLoad() ? (Y/N)',10,0
unloaderr   dc.b    'Arrrgh.. can`t find segments, aborting',0
noprocs     dc.b    'Not a Process.',0
notload     dc.b    'No program loaded.',0
cliprocs    dc.b    'Cli-Process',0
procloaded  dc.b    'Loaded as a command: ',0
segloaded   dc.b    'Created by CreateProc()',0
coldtxt     dc.b    'Cold Capture: ',0
cooltxt     dc.b    'Cool Capture: ',0
warmtxt     dc.b    'Warm Capture: ',0
kicktxt     dc.b    'KickMem     : ',0
unset       dc.b    'unset',0
intnames    dc.b    'Serial Out ',0
            dc.b    'Disk Block ',0
            dc.b    'SoftInt    ',0
            dc.b    'Ports      ',0
            dc.b    'Coper      ',0
            dc.b    'VBeam      ',0
            dc.b    'Blitter    ',0
            dc.b    'Audio Ch.0 ',0
            dc.b    'Audio Ch.1 ',0
            dc.b    'Audio Ch.2 ',0
            dc.b    'Audio Ch.3 ',0
            dc.b    'Serial In  ',0
            dc.b    'Disk Sync  ',0
            dc.b    'External   ',0
            dc.b    'SoftInt    ',0
            dc.b    'NMI        ',0
inttyp      dc.b    0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1
devicenam   dc.b    'input.device',0
memlarg     dc.b    'LARGEST ',0
memclr      dc.b    'CLEAR ',0
memfast     dc.b    'FAST ',0
memchip     dc.b    'CHIP ',0
mempubl     dc.b    'PUBLIC ',0
failed      dc.b    'Failed !',0
allok       dc.b    'ALLOC: ',0
free        dc.b    'FREE: ',0
startupname dc.b    'S:Xoper.Startup',0
synerr      dc.b    'Syntax Error, type "?" for help',10,0
more        dc.b    '<MORE>'
waittxt     dc.b    '<ANY KEY>',$9b,$4a
wberr       dc.b    'Can`t examine Workbench locks',0
dnotf       dc.b    'Directory not found',0
notdir      dc.b    'Not a directory',0
nomount     dc.b    ' not mounted.',0
dishelp     dc.b    10,'Names are case sensitive and followed by a ":"',0
unlerr      dc.b    'Lock not found',0
unl1        dc.b    'Lock is on ',0
unltxt      dc.b    'Old lock was: ',0
unltxt2     dc.b    'Unlock ? (Y/N)',10,0
scnofound   dc.b    'Screen not found.',0
winnofound  dc.b    'Window not found.',0
stperr      dc.b    'Task must be "READY" or "WAITING"',10,0
waerr       dc.b    'Task must be "FROZEN"',10,0
onscr       dc.b    'On Screen: ',0
usetxt      dc.b    $9b,'1mUSAGE:',$9b,'0m Xoper [T] [A] [L] [D] [R] [E] [M] [P] [I] [S]',$9b,'K',10
            dc.b    'OR     Xoper -b',$9b,'K',10
            dc.b    $9b,'1mDISPLAY:',$9b,'0m',$9b,'K',10
            dc.b    '[T]asks [F]=taskflags [L]ibraries [D]evices [R]esources',$9b,'K',10
            dc.b    'r[E]sident [M]emory [P]orts [I]nterrupts [S]tack [Q]uit',$9b,'K',10
            dc.b    $9b,'1mCOMMANDS:',$9b,'0m',$9b,'K',10
            dc.b    'Time         <secs>',$9b,'K',10
            dc.b    'Taskpri      <priority>  [processnum] <taskname>',$9b,'K',10
            dc.b    'Mypri        <priority>',$9b,'K',10
            dc.b    'Signal       <mask(hex)> [processnum] <taskname>',$9b,'K',10
            dc.b    'Break        [processnum] <taskname>',$9b,'K',10
            dc.b    'Freeze|Warm  [processnum] <taskname>',$9b,'K',10
            dc.b    'Kill         [processnum] <taskname>',$9b,'K',10
            dc.b    'Snoop        [processnum] <taskname>',$9b,'K',10
            dc.b    'Hide         <taskname>',$9b,'K',10
            dc.b    'Pri          <priority> <nodename>',$9b,'K',10
            dc.b    'Info         <name>',$9b,'K',10
            dc.b    'Clear        <longword(hex)>',$9b,'K',10
            dc.b    'Hunks        [processnum] <procname>',$9b,'K',10
            dc.b    'CD           <directory> [processnum] <procname>',$9b,'K',10
            dc.b    'Unlock       <lock>',$9b,'K',10
            dc.b    'Openlib    | Closelib <libraryname>',$9b,'K',10
            dc.b    'Closewindow| Closescreen <title>',$9b,'K',10
            dc.b    'Lockdrive  | Freedrive   <drivename:>',$9b,'K',10
            dc.b    'Window       <leftedge topedge width height> (scriptfile only) ',$9b,'K',10
            dc.b    'Flush,Devices,Currentdir,Files,Locks,Lastalert,More,Sort',$9b,'K',10
            dc.b    'Taskports,Windows,Screens,Fonts,Windowfonts,Capture,Hidden',$9b,'K',10
            dc.b    'ClrCool,ClrCold,ClrWarm,Usage,InputHandler,Header',$9b,'K',10
            dc.b    'Hold,Exit',$9b,'K',10
null        dc.b    0

    IFD DEBUG
dosname     dc.b    'dos.library',0
intuiname   dc.b    'intuition.library',0
gfxname     dc.b    'graphics.library',0
            EVEN
    ENDC

            BSS     blabla
buffer      ds.b    2000
fname       ds.b    284
out         ds.b    80
dummy       ds.b    80
in          ds.b    80
cputime     ds.b    1000

mypacket    BSS     standardpacket

LN_SUCC     ds.l    1
LN_PRED     ds.l    1
LN_TYPE     ds.b    1
LN_PRI      ds.b    1
LN_NAME     ds.l    1
MP_FLAGS    ds.b    1
MP_SIGBIT   ds.b    1
MP_SIGTASK  ds.l    1
MN_SIZE     ds.w    1
LH_HEAD     ds.l    1
LH_TAIL     ds.l    1
LH_TAILPRED ds.l    1
LH_TYPE     ds.b    1
LH_pad      ds.b    1
dp_Link     ds.l    1
dp_Port     ds.l    1
dp_Type     ds.l    1
dp_Res1     ds.l    1
dp_Res2     ds.l    1
dp_Arg1     ds.l    1
dp_Arg2     ds.l    1
dp_Arg3     ds.l    1
dp_Arg4     ds.l    1
dp_Arg5     ds.l    1
dp_Arg6     ds.l    1
dp_Arg7     ds.l    1
            END

