home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog-asm / asmtools.lzh / ASMTOOLS / WHY / WHY.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-08-16  |  6.5 KB  |  235 lines

  1. ; I hope I don't get stuffed into one of those silly shell archives!!
  2. ; Tabs set every 8.
  3. ;
  4. ;BETTERCLI(tm) "WHY" Command, release 1
  5. ;
  6. ;BETTERCLI WHY (C)1987 Bryce Nesbitt.  Unlimited free non-exclusive licence
  7. ;hereby    granted    to any sentient    being to use or    abuse this code    in any way
  8. ;whatsoever provided that this and any other copyright notices remain fully
  9. ;attached and are reproduced in    any simultaneously distributed printed matter
  10. ;and with the exception    that, without prior written permission,    it not
  11. ;be utilized by    any entity that    has been commonly referred to as Robert
  12. ;W. Skyles, Skyles Electric Works, Jim Drew, Regie Warren or any organization
  13. ;founded by, controlled, employing or profiting    any such entity, it's
  14. ;offspring or spouses.    ARP and    FISH use welcome.
  15. ;Author    correspondence,    bug or stupidity reports may be    directed to:
  16. ;    Bryce Nesbitt
  17. ;    1712 Marin Ave.
  18. ;    Berkeley, Ca 94707-2206
  19. ;
  20. ;This program replaces the CLI WHY command, providing faster execution and
  21. ;enhanced functionality.  The old WHY command was simply a stub    that called
  22. ;'C:FAULT', and thus could not be made properly RESIDENT.  This command was
  23. ;to replace FAULT as well, however the BCPL code does something    funky
  24. ;when calling FAULT, and I could not discover it's secret.
  25. ;
  26. ; Return code convention:
  27. ;  20  FAIL  -serious error, DOS will not open,    out of memory.
  28. ;  10  ERROR -user caused error    (syntax, file not found    etc.)
  29. ;         -less serious than    FAIL.
  30. ;  5   WARN  -technicality (file not found on DELETE, for example)
  31. ;  0   OK    -command sucessful, operation completed.
  32. ;
  33. ;This code is REUSABLE,REENTRANT and fully RESIDENT COMPATIBLE.
  34. ;Stack 1600 ok.
  35. *************************
  36. jsrlib    macro
  37.     xref    _LVO\1
  38.     jsr    _LVO\1(a6)
  39.     endm
  40. jmplib    macro
  41.     xref    _LVO\1
  42.     jmp    _LVO\1(a6)
  43.     endm
  44.     ;INCLUDE 'lib/exec_lib.i'    ;You don't have these files
  45.     ;INCLUDE 'lib/dos_lib.i'    ;so please ignore these lines.
  46.     INCLUDE    'libraries/dosextens.i'
  47. *************************
  48.         CODE
  49. outhand        equr    d6
  50. failcode    equr    d5
  51. proc        equr    a5
  52. cli        equr    a4
  53. ;d0-d4 a0-a3 scratch
  54. ;-- Setup --
  55. StartUp:    moveq    #20,failcode    ;default-SEVERE    failure
  56.         move.l    4,a6        ;get exec library base pointer
  57.         lea    dosname(pc),a1
  58.         jsrlib    OldOpenLibrary    ;get this... Compatability with    V1.0!
  59.         move.l    d0,outhand    ;temp for DOSBase
  60.         beq.s    e_dos        ;fail if it will not open
  61.         suba.l    a1,a1        ;find THIS task
  62.         jsrlib    FindTask
  63.         move.l    d0,proc
  64.         move.l    pr_CLI(proc),cli
  65.         adda.l    cli,cli        ;ban the BPTR!!
  66.         adda.l    cli,cli        ;ban the BPTR!!
  67.         move.l    outhand,a6    ;DOSBase
  68.         jsrlib    Output
  69.         move.l    d0,outhand
  70.         beq.s    e_output
  71. ;--
  72.         lea    mes1s(pc),a0    ;'Fail code '
  73.         moveq    #mes1e-mes1s,d3
  74.         bsr.s    DOWRITED
  75. ;-- Get    fail code --
  76.         move.l    cli_ReturnCode(cli),d0
  77.         bsr.s    PRINTDECIMAL
  78. ;--
  79.         lea    mes2s(pc),a0    ;'and error code '
  80.         moveq    #mes2e-mes2s,d3
  81.         bsr.s    DOWRITED
  82. ;-- Print error    number --
  83.         move.l    cli_Result2(cli),d0
  84.         bsr.s    PRINTDECIMAL
  85. ;--
  86.         lea    mes3s(pc),a0    ;';'
  87.         moveq    #mes3e-mes3s,d3
  88.         bsr.s    DOWRITED
  89. ;-- Print error    text --
  90.         move.l    cli_Result2(cli),d0
  91.         bsr.s    PCODE
  92.         moveq    #0,failcode
  93. e_error
  94. e_output    move.l    a6,a1
  95.         move.l    4,a6
  96.         jsrlib    CloseLibrary
  97. e_dos        move.l    failcode,d0
  98. rts1        rts
  99. ;
  100. ;DOWRITED(pointer,length)
  101. ;      a0      d3
  102. ;Aborts    if error
  103. ;
  104. DOWRITED    ;[d3=length]
  105.         move.l    a0,d2
  106.         move.l    outhand,d1
  107.         jsrlib    Write
  108.         cmp.l    d0,d3
  109.         beq.s    rts1
  110. e_badwrite    addq.l    #4,a7    ;pop return off    stack
  111.         jsrlib    IoErr
  112.         move.l    d0,pr_Result2(proc)
  113.         bra.s    e_error    ;(return code is set to    FAIL, 20)
  114. ;
  115. ;
  116. ;
  117. PCODE        moveq    #10,d1
  118.         lea    table(pc),a1
  119. checknext    move.l    a1,a0        ;Save pointer to this line
  120.         moveq    #-1,d3
  121. findend        cmp.b    (a1)+,d1    ;count length
  122.         dbeq    d3,findend    ;68010 loop mode!
  123.         neg.l    d3        ;compensate for    backwards count
  124.         subq.l    #1,d3        ;tweak
  125.         cmp.b    #$ff,(a0)
  126.         beq.s    gotit        ;end of    list, use default
  127.         cmp.b    (a0),d0
  128.         bne.s    checknext
  129. gotit        addq.l    #1,a0        ;skip error #
  130.         bra.s    DOWRITED    ;[a0-string|d3-len]
  131. ;
  132. ;Bloated, slow, kludg-o 32 bit signed print decimal routine.
  133. ;destroys D2,D3
  134. ;
  135. countvar    equr    d1
  136. tableoffset    equr    d2
  137.  
  138. PRINTDECIMAL    moveq    #-4,tableoffset
  139.         subq.l    #6,a7
  140.         subq.l    #6,a7    ;reserve 12 bytes for number
  141.         move.l    a7,a0
  142.         tst.l    d0
  143.         beq.s    zero
  144.         bpl.s    positive
  145.         move.b    #'-',(a0)+
  146.         neg.l    d0
  147. positive    addq.l    #4,tableoffset
  148.         cmp.l    table2(pc,tableoffset.l),d0
  149.         bcs.s    positive    ;BLO
  150.  
  151. doloop        move.l    table2(pc,tableoffset.w),countvar
  152.         beq.s    endofnum
  153.         moveq    #-1,countvar
  154. subloop        addq.l    #1,countvar
  155.         sub.l    table2(pc,tableoffset.w),d0
  156.         bcc.s    subloop
  157.         add.l    table2(pc,tableoffset.w),d0 ;Ooops! Too    far!!
  158.         ori.b    #$30,countvar
  159.         move.b    countvar,(a0)+
  160.         addq.l    #4,tableoffset
  161.         bra.s    doloop
  162.  
  163. zero        move.b    #$30,(a0)+
  164. endofnum    suba.l    a7,a0
  165.         move.l    a0,d3
  166.         move.l    a7,d2
  167.         move.l    outhand,d1
  168.         jsrlib    Write
  169.         addq.l    #6,a7
  170.         addq.l    #6,a7
  171.         cmp.l    d0,d3
  172.         bne.s    e_badwrite
  173.         rts
  174.  
  175. table2        dc.l    1000000000
  176.         dc.l    100000000
  177.         dc.l    10000000
  178.         dc.l    1000000
  179.         dc.l    100000
  180.         dc.l    10000
  181.         dc.l    1000
  182.         dc.l    100
  183.         dc.l    10
  184.         dc.l    1
  185.         dc.l    0
  186. dosname        dc.b 'dos.library',0
  187. mes1s        dc.b 'Fail code '
  188. mes1e
  189. mes2s        dc.b ', and error code '
  190. mes2e
  191. mes3s        dc.b '; '
  192. mes3e
  193.         dc.b '(C)1987 Bryce Nesbitt'
  194. ;
  195. ;Error message table. Feel free    to translate into other    languages such as
  196. ;German, Italian, or even English. Error numbers 200 and 201
  197. ;are unauthorized 'enhancments' to the standard.
  198. ;
  199. table    dc.b 103,'insufficient free store',10
  200.     dc.b 105,'task table full',10           ;!!Eliminate need!!
  201.     dc.b 120,'argument line invalid or too long',10
  202.     dc.b 121,'file is not an object module',10
  203.     dc.b 122,'invalid resident library during load',10
  204.        dc.b 200,'internal error',10
  205.        dc.b 201,'newer operating system required',10
  206.     dc.b 202,'object in use',10
  207.     dc.b 203,'object already exists',10
  208.     dc.b 204,'directory not found',10
  209.     dc.b 205,'object not found',10
  210.     dc.b 206,'invalid window description',10
  211.        ;dc.b 207,'object too large',10              ;obsolete
  212.     dc.b 209,'packet request type unknown',10
  213.     dc.b 210,'stream name component invalid',10 ;what??
  214.     dc.b 211,'invalid object lock',10
  215.     dc.b 212,'object not of required type',10
  216.     dc.b 213,'disk not validated',10
  217.     dc.b 214,'disk write-protected',10
  218.     dc.b 215,'rename across devices attempted',10
  219.     dc.b 216,'directory not empty',10
  220.        ;dc.b 217,'too many levels;,10               ;obsolete
  221.     dc.b 218,'device (or volume) not mounted',10
  222.     dc.b 219,'seek failure',10
  223.     dc.b 220,'comment too big',10
  224.     dc.b 221,'disk full',10
  225.     dc.b 222,'file is protected from deletion',10
  226.     dc.b 223,'file is write protected',10
  227.     dc.b 224,'file is read protected',10
  228.     dc.b 225,'not a valid DOS disk',10
  229.     dc.b 226,'no disk in drive',10
  230.     ;dc.b 227,'can',$27,'t open window',10
  231.     ;dc.b 228,'can',$27,'t open screen',10
  232.     dc.b 232,'no more entries in directory',10
  233.     dc.b 255,'no error message',10
  234. ;-- end --
  235.