home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma41.dms / ma41.adf / SoftProtect / SP.s < prev    next >
Encoding:
Text File  |  1995-09-07  |  7.4 KB  |  205 lines

  1.   ******************************
  2.   *      SoftProtect v1.0      *
  3.   * Written by Grzegorz Królik *
  4.   ******************************
  5.  
  6.  
  7.      incdir  "Include:"
  8.      include "exec/exec_lib.i"
  9.      include "exec/execbase.i"
  10.      include "libraries/dosextens.i"
  11.      include "libraries/arpbase.i"
  12.  
  13. call macro
  14.      jsr   _LVO\1(a6)
  15.      endm
  16.  
  17.      section "SoftProtect v1.0",code
  18.  
  19.      link    a5,#-32             ;reserve our workspace
  20.  
  21.      movem.l  d0/a0,-8(a5)       ;save the argument pointer
  22.  
  23.      move.l  4.w,a6              ;get ExecBase
  24.      move.l  ThisTask(a6),a2     ;get our task structure
  25.      tst.l   pr_CLI(a2)          ;are we CLI or Workbench?
  26.      bne.s   FromCLI             ;we are CLI, so continue
  27.  
  28.      lea     pr_MsgPort(a2),a0   ;we are Workbench,
  29.      call    WaitPort            ;so handle  messages...
  30.      lea     pr_MsgPort(a2),a0   ; (otherwise visit from guru...)
  31.      call    GetMsg              ;GetMsg function called
  32.      move.l  d0,d2
  33.      call    ReplyMsg            ;ReplyMsg function called
  34.      bra.w   Error               ;quit
  35.  
  36. FromCLI:
  37.      lea     DOSName(pc),a1      ;this opens the dos.library
  38.      moveq   #36,d0
  39.      call    OpenLibrary         ;OpenLibrary function called
  40.      tst.l   d0                  ;which OS are we under?
  41.      beq.s   OldOS               ;it's 1.2 or 1.3
  42.      clr.l   -12(a5)             ;clear the ARPBase pointer
  43.      move.l  d0,-16(a5)          ;save the DOSBase pointer
  44.  
  45.      move.l  #MyInfo,d1          ;address of the information string
  46.      move.l  -16(a5),a6
  47.      call    VPrintf             ;VPrintf function called
  48.      tst.l   d0                  ;Did an error occured?
  49.      bmi.s   CloseDOS            ;yes, close the library
  50.  
  51.      move.l  #Template,d1        ;input template address
  52.      clr.l   -24(a5)
  53.      clr.l   -20(a5)
  54.      lea     -24(a5),a0
  55.      move.l  a0,d2               ;our space
  56.      moveq   #0,d3
  57.      call    ReadArgs            ;ReadArgs function called
  58.      tst.l   d0
  59.      bne.s   Ok                  ;arguments ok
  60.  
  61.      call    IoErr               ;IoErr function called - error determined
  62.      move.l  d0,d1               ;error code
  63.      move.l  d3,d2
  64.      call    PrintFault          ;PrintFault function called
  65.      bra.s   CloseDOS            ;we can't do anything more
  66.  
  67. Exit:
  68.      move.l  -28(a5),d1          ;argument address
  69.      call    FreeArgs            ;FreeArgs function called
  70.  
  71. CloseDOS:
  72.      move.l  a6,a1               ;DOSBase as an argument to CloseLibrary()
  73.      move.l  4.w,a6              ;ExecBase reactivated
  74.      call    CloseLibrary        ;CloseLibrary function called
  75.      bra.s   Error
  76.  
  77. Ok:
  78.      move.l  d0,-28(a5)          ;remember this to free args later
  79.  
  80.      cmpi.l  #-1,-24(a5)         ;get current value
  81.      beq.w   Protect
  82.  
  83.      cmpi.l  #-1,-20(a5)
  84.      beq.w   UnProtect
  85.  
  86.      tst.l   -12(a5)             ;is the arp.library opened
  87.      beq.s   Exit                ;no, it isn't
  88.      bra.s   CloseARP
  89.  
  90. OldOS:
  91.      lea     ARPName(pc),a1      ;this open the arp.library
  92.      moveq   #ArpVersion,d0      ;version of the arp.library
  93.      call    OpenLibrary         ;OpenLibrary function called
  94.      tst.l   d0                  ;opened?
  95.      beq.s   NoARP               ;no, inform your user about it
  96.      move.l  d0,-12(a5)          ;save the ARPBase pointer
  97.  
  98.      lea     MyInfo(pc),a0       ;to be pc-relative
  99.      move.l  d0,a6
  100.      move.l  DosBase(a6),-16(a5) ;get the DOSBase pointer
  101.      call    Printf              ;Printf function called
  102.      tst.l   d0                  ;Did an error occured?
  103.      bmi.s   CloseARP            ;yes, close the library
  104.  
  105.      movem.l -8(a5),d0/a0        ;get the argument pointer
  106.      sub.l   a1,a1               ;no extra help
  107.      clr.l   -24(a5)
  108.      clr.l   -20(a5)
  109.      lea     -24(a5),a2          ;our space
  110.      lea     Template(pc),a3     ;to be pc-relative
  111.      call    GADS                ;GADS function called
  112.      tst.l   d0
  113.      bge.s   Ok                  ;arguments ok
  114.  
  115.      move.l  -24(a5),a1          ;error description
  116.      call    Puts                ;Puts function called
  117.  
  118. CloseARP:
  119.      move.l  a6,a1               ;ARPBase as an argument to CloseLibrary()
  120.      move.l  4.w,a6              ;ExecBase reactivated
  121.      call    CloseLibrary        ;CloseLibrary function called
  122.  
  123. Error:
  124.      unlk    a5                  ;free reserved workspace
  125.      moveq   #0,d0               ;error = 0
  126.      rts                         ;return
  127.  
  128. NoARP:
  129.      lea     DOSName(pc),a1
  130.      call    OldOpenLibrary      ;OldOpenLibrary function called
  131.      tst.l   d0
  132.      beq.s   Error               ;error in open
  133.      move.l  d0,a6               ;get the DOSBase
  134.      call    Output              ;Output function called
  135.      tst.l   d0                  ;found?
  136.      beq.w   CloseDOS            ;not found
  137.      move.l  d0,d1               ;get the output handle
  138.      move.l  #ArpText,d2         ;text address
  139.      move.l  #26,d3              ;text length
  140.      call    Write               ;Write function called
  141.      bra.w   CloseDOS            ;exit
  142.  
  143. Protect:
  144.      btst    #3,$bfe201          ;is the disk in df0: write protected?
  145.      bne.s   PrintON             ;yes, it is
  146.      ori.b   #12,$bfe201         ;bset #2,$bfe201, bset #3,$bfe201
  147.      andi.b  #243,$bfe001        ;bclr #2,$bfe001, bclr #3,$bfe001
  148.      moveq   #25,d1              ;time = 1/2 sec
  149.      move.l  -16(a5),a6          ;get the DOSBase
  150.      call    Delay               ;Delay function called
  151.      ori.b   #4,$bfe001          ;bset #2,$bfe001
  152.      moveq   #25,d1
  153.      call    Delay               ;Delay function called
  154.      andi.b  #251,$bfe201        ;bclr #2,$bfe201
  155.  
  156. PrintON:
  157.      move.l  #StatInfo,d1        ;address of the text
  158.      move.l  #ON,-32(a5)        ;save the arguments value
  159.      bra.s   Print               ;print the status info
  160.  
  161. UnProtect:
  162.      btst    #3,$bfe201          ;is the disk in df0: write protected?
  163.      beq.s   PrintOFF            ;no, it isn't
  164.      ori.b   #12,$bfe201         ;bset #2,$bfe201, bset #3,$bfe201
  165.      andi.b  #243,$bfe001        ;bclr #2,$bfe001, bclr #3,$bfe001
  166.      moveq   #25,d1              ;time = 1/2 sec
  167.      move.l  -16(a5),a6          ;get the DOSBase
  168.      call    Delay               ;Delay function called
  169.      ori.b   #4,$bfe001          ;bset #2,$bfe001
  170.      moveq   #25,d1
  171.      call    Delay               ;Delay function called
  172.      andi.b  #243,$bfe201        ;bclr #2,$bfe201, bclr #3,$bfe201
  173.  
  174. PrintOFF:
  175.      move.l  #StatInfo,d1        ;address of the text
  176.      move.l  #OFF,-32(a5)         ;save the arguments value
  177.  
  178. Print:
  179.      tst.l   -12(a5)             ;are we under OS 1.2 or 1.3?
  180.      bne.s   FromARP             ;yes, so use the ARP function
  181.      lea     -32(a5),a0          ;get the arguments value
  182.      move.l  a0,d2
  183.      call    VPrintf             ;VPrintf function called
  184.      bra.w   Exit                ;exit
  185.  
  186. FromARP:
  187.      move.l  d1,a0               ;get address of the text
  188.      lea     -32(a5),a1          ;get the arguments value
  189.      move.l  -12(a5),a6          ;ARPBase reactivated
  190.      call    Printf              ;Printf function called
  191.      bra.w   CloseARP            ;exit
  192.  
  193.  
  194. VerStr:   dc.b  0,"$VER: SoftProtect 1.0 (20.07.95)",0
  195. DOSName:  DOSNAME
  196. ARPName:  ArpName
  197. ArpText:  dc.b  "you need arp.library V34+",10,0
  198. MyInfo:   dc.b  10,155,"1;33mSoftProtect",155,"0m"," PUBLIC DOMAIN "
  199.           dc.b  "© 1995 by Grzegorz Królik",10,10,0
  200. StatInfo: dc.b  "Write Protection is %s",10,0
  201. ON:       dc.b  "ON",0
  202. OFF:      dc.b  "OFF",0
  203. Template: dc.b  "P=PROTECT/S,U=UNPROTECT/S",0
  204.           end
  205.