home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / assemblr / 03 / readonly.asm < prev    next >
Assembly Source File  |  1986-06-05  |  5KB  |  131 lines

  1. title    READONLY.COM -- VERSION 1.0
  2. ;
  3. ;       ***************************************************
  4. ;       A utility that changes the mode of a file to read-
  5. ;       only status so that it cannot be changed or erased
  6. ;       by ordinary means.
  7. ;       ***************************************************
  8. ;
  9. code segment
  10. ;
  11. org     100h                    ; this is a COM file
  12. ;
  13. assume  cs:code,ds:code,es:code
  14. ;
  15.         jmp     main            ;avoid the data area
  16. ;
  17. ;       ===================================================
  18. ;
  19. ;       Data area:
  20. ;
  21. copyright       db      'Version 1.0 -- Copyright 1985 by Winn L. Rosch, Esq.'
  22.                                 ; credit where credit is due
  23. nothing         db      1ah     ; this byte lets us type the COM file
  24.                                 ;     without disasters
  25. ;
  26. ;       Error messages:
  27. ;
  28. error1          db      'Error.  Bad file specifications.$'
  29. error2          db      'Error.  No such file.$'
  30. error3          db      'Error.  Path not found.$'
  31. error5          db      'Error.  Access denied.$'
  32. message         db      'Function completed as specified.$'
  33. ;
  34. ;       ===================================================
  35. ;
  36. main:
  37.         push    cs              ; make sure that data segment is same
  38.         pop     ds              ;     as code segment
  39.         mov     bx,0081h        ; check to be sure a filename is given
  40.         mov     dl,[bx]         ; move byte following filename into DL
  41.         cmp     dl,0dh          ; check for carriage return
  42.         jz      er1             ; if we find a carriage return, run error message
  43.         mov     dx,0082h        ; ds-dx now points to filename, as required
  44.                                 ;     by the DOS function we'll be calling
  45.         mov     bx,dx
  46. ;
  47. ;       ---------------------------------------------------
  48. ;       This routine loops through the characters on the
  49. ;       command line, looking for a carriage return, which
  50. ;       delimits the filename
  51. ;       ---------------------------------------------------
  52. ;
  53. marker:
  54.         mov     al,[bx]         ; move character position into AL
  55.         cmp     al,0dh          ; check for carriage return
  56.         jz      carriage_return ; carriage return indicates end of filename
  57.         inc     bx              ; advance to next character
  58.         jmp     marker          ; keep going until we find a carriage return
  59. ;
  60. ;       ---------------------------------------------------
  61. ;       This routine merely changes the carriage return on
  62. ;       the command line into the zero required by the
  63. ;       function call so that it recognizes the proper
  64. ;       filename
  65. ;       ---------------------------------------------------
  66. ;
  67. carriage_return:
  68.         xor     ah,ah           ; make a zero
  69.         mov     [bx],ah         ; changes the space after the filename
  70.                                 ;      into a zero required by function
  71.         mov     ah,43h          ;
  72.         mov     al,00h          ; tells DOS to read attribute byte
  73.         int     21h             ; make function call
  74.         call    error_check     ; check for errors
  75.         mov     ah,43h          ; DOS file attribute byte function call
  76.         mov     al,01h          ; indicates that attribute byte to be changed
  77.         or      cx,1            ; set attribute to read-only
  78. ;
  79.                                 ;=============================================
  80.                                 ; NOTE!!!  Changing this instruction to      ;
  81.                                 ; "and al,0fffeh" will convert this program  ;
  82.                                 ; to one which will REMOVE read-only         ;
  83.                                 ; status from a write-protected file.        ;
  84.                                 ;=============================================
  85. ;
  86.         int     21h             ; make function call
  87.                                 ; if everything went okay, say so
  88.         mov     dx,offset message
  89. ;
  90. sign_off:
  91.         mov     ah,09           ; load DOS print string function
  92.         int     21h             ; call DOS
  93.         int     20h             ; exit
  94. ;
  95. ;
  96. ;
  97. er1:
  98.         mov     dx,offset error1
  99.         jmp     sign_off
  100. er2:
  101.         mov     dx,offset error2
  102.         jmp     sign_off
  103. er3:
  104.         mov     dx,offset error3
  105.         jmp     sign_off
  106. er5:
  107.         mov     dx,offset error5
  108.         jmp     sign_off
  109. ;
  110. ;       ---------------------------------------------------
  111. ;       The following procedure checks the character returned
  112. ;       in the AX register for errors after making the function
  113. ;       call.  If an error is found, it loads the appropriate
  114. ;       message, then exits.
  115. ;       ---------------------------------------------------
  116. ;
  117. error_check     proc    near
  118. ;
  119.         cmp     ax,2
  120.         jz      er2
  121.         cmp     ax,3
  122.         jz      er3
  123.         cmp     ax,5
  124.         jz      er5
  125.         ret
  126. ;
  127. error_check     endp
  128. ;
  129. code            ends
  130.                 end main
  131.