home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 182.lha / Stat_v1.1 / stat.asm < prev    next >
Assembly Source File  |  1988-04-28  |  5KB  |  148 lines

  1. ;----------------------------------------------------------------------------
  2. ;    stat.asm  v1.100       Copyright 1988 by Josh Rovero
  3. ;    03 Oct 88                                5449 Beaufain Blvd
  4. ;                                             Virginia Beach, VA 23464
  5. ;
  6. ;                           E-Mail: Nexus BBS 804-547-1065
  7. ;
  8. ;    Permission is granted for unlimited non-commercial use
  9. ;
  10. ;    A manual translation of James M. Synge's stat.c to assembly language.
  11. ;    Synge's stat is more useful to programmers than the AmigaDos or ARP
  12. ;    status commands because it shows where each command is loaded into
  13. ;    memory.  All variable storage is on a stack frame so the code is
  14. ;    "pure".  My thanks to James Synge for his original program and
  15. ;    source, and to Bill Hawes for some constructive criticism and
  16. ;    encouragement. It was fun (*&^%$#!!!), educational, and shows again
  17. ;    that people make better C compilers than programs do....
  18. ;
  19. ;    Note:  arp.library V34+ required.
  20. ;
  21. ;    Features:   Only 524 bytes! One tenth the size of the original compiled
  22. ;                C version.  27% smaller than even the ARP status command!
  23. ;                Can be installed as a resident command under ARP and WShell.
  24. ;
  25. ;    tools:   Inovatronics CAPE and Howe's Asm68k 1.2.1
  26. ;             Nesbitt's small.lib
  27. ;             Software Distillery Blink 6.9 and make
  28. ;             ARP
  29. ;             SLADE Software Amiga Debugger
  30. ;             The Amigan Journeyman and Apprentice
  31. ;----------------------------------------------------------------------------
  32.  
  33.      option nl
  34.      include "libraries/arpbase.i"
  35.      include "exec/memory.i"
  36.      include "exec/tasks.i"
  37.      include "libraries/dosextens.i"
  38.      option l
  39.  
  40. ; Take advantage of optimization if assembled with C.A.P.E.68k
  41.      IFD         CAPE
  42.      TRASHREG    d7
  43.      OPTIMON
  44.      ENDC
  45.  
  46. ;    This structure will exist on the stack frame
  47. ;    a5 is our frame pointer -- don't use it for anything else!
  48.  
  49. fp   equr      a5
  50.      STRUCTURE frame,0
  51.         LONG   processes
  52.         LONG   cli
  53.         LONG   tasknum
  54.         LONG   pri
  55.         APTR   pr
  56.         APTR   str_buf_1_ptr
  57.         APTR   str_buf_2_ptr
  58.         STRUCT str_buf_1,32
  59.         STRUCT str_buf_2,32
  60.         LABEL frame_size
  61.  
  62.      section one,code,public
  63.      xref  AbsExecBase,_LVOOpenLibrary,_LVOFindTask
  64.      xref  _LVOForbid,_LVOPermit
  65.  
  66. ; See the ARP programmer's docs for RESIDENT and OPENARP macro defs
  67.      RESIDENT 4000,frame_size
  68.      OPENARP  NONDEFAULT
  69.      link     fp,#-frame_size         ; set up the frame pointer
  70.      lea      str_buf_1(sp),a0        ; set up ptr to string buffer 1
  71.      move.l   a0,str_buf_1_ptr(sp)
  72.      lea      str_buf_2(sp),a0        ; set up ptr to string buffer 2
  73.      move.l   a0,str_buf_2_ptr(sp)
  74.  
  75. ; Find the maximum number of CLI processes  (20 in AmigaDos 1.2)
  76.      moveq.l  #0,d0
  77.      LINKEXE  Forbid
  78.      LINKDOS  FindCLI
  79.      move.l   d0,processes(sp)
  80.      LINKEXE  Permit
  81.  
  82. ; Print the report header
  83.      lea      report_header,a1
  84.      LINKDOS  Puts
  85.  
  86. ;    Main Program Loop -- gets task number, priority, load address
  87. ;                         task name, and its current directory.
  88.  
  89.               move.l   processes(sp),d7  ; d7 = max possible # of CLIs
  90.               moveq.l  #0,d6             ; d6 = loop counter
  91.               LINKEXE  Forbid
  92.  
  93. loop.outer:
  94.               addq.l   #1,d6
  95.               cmp.l    d6,d7             ; check loop limits
  96.               bmi      exit_ok
  97.               move.l   d6,d0
  98.               move.l   d6,tasknum(sp)    ; store the task number
  99.               LINKDOS  FindCLI
  100.               move.l   d0,pr(sp)         ; store process structure pointer
  101.               tst.l    d0
  102.               beq      loop.outer        ; this task isn't a CLI
  103.               move.l   pr(sp),a4
  104.               move.b   LN_PRI(a4),d0     ; get priority of process
  105.               ext.w    d0
  106.               ext.l    d0
  107.               move.l   d0,pri(sp)        ; store priority
  108.               move.l   pr_CLI(a4),d5     ; get CLI BPTR
  109.               asl.l    #2,d5             ; convert to APTR
  110.               move.l   d5,cli(sp)        ; store cli pointer
  111.               move.l   d5,a4
  112. active        lea      str_buf_1(sp),a0
  113.               move.l   a0,str_buf_1_ptr(sp)
  114.               move.l   cli_CommandName(a4),d0  ; get the command name
  115.               move.l   #31,d1
  116.               LINKDOS  BtoCStr
  117.               tst.l    d0
  118.               bne      running
  119.  
  120. inactive_cli  lea      waiting_msg,a0          ; if not active say "waiting"
  121.               move.l   a0,str_buf_1_ptr(sp)
  122.  
  123. running       lea      str_buf_2(sp),a0        ; get the CLI's directory
  124.               move.l   a0,str_buf_2_ptr(sp)
  125.               move.l   cli_SetName(a4),d0
  126.               move.l   #31,d1
  127.               LINKDOS  BtoCStr
  128.  
  129. print         lea      format_string,a0
  130.               lea      tasknum(sp),a1           ;start of Printf args in mem
  131.               LINKDOS  Printf
  132. endloop.outer bra      loop.outer
  133.  
  134. exit_ok       LINKEXE  Permit
  135.               moveq.l  #0,d0    ; clean up and exit
  136.               unlk     fp
  137.               LINKDOS  ArpExit
  138.               rts
  139.  
  140.               cnop     0,2
  141. report_header dc.b     'Task Pri  Address Command'
  142.               dc.b     '                          Directory',0
  143.               cnop     0,2
  144. format_string dc.b     '%3ld %4ld %8lx %-32ls %ls',$0a,0
  145.               cnop     0,2
  146. waiting_msg   dc.b     'Waiting...',0
  147.               end
  148.