home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / zsus / progpack / cprot.lbr / CPROT.ZZ0 / CPROT.Z80
Encoding:
Text File  |  1992-05-13  |  4.5 KB  |  118 lines

  1. ; CPROT makes the BDOS jump address at 06h to the given address and 
  2. ; establishes a jump at that address to the actual BDOS entry.  Memory above 
  3. ; the given address is protected.  
  4.           
  5.           
  6.           cseg          
  7.           ext       eval16         ; Syslib routine to evaluate hexadecimal
  8.           ext       sksp        ; Syslib routine to skip space
  9.           ext       getccp         ; Determine the address of the CCP
  10.           ext       eprint        ; Print null-term string
  11.           ext    phl4hc        ; Print hex string in HL
  12.           ext    crlf
  13.           .request  syslib,z33lib 
  14.           ld    hl,081h        ; Space beginning of command tail
  15.           call      sksp        ; Skip over whitespace
  16.           ld    a,(hl) 
  17.           or    a        ; If no command tail, document
  18.           jp    z,tell
  19.           cp    '/'        ; Z3 help
  20.           jp    z,tell
  21.           cp    '?'        ; Other help
  22.           jp    z,tell
  23.           call      eval16        ; Evaluate the hex number
  24.           ld    a,(hl)
  25.           or    a        ; Not completely evaluated, or if not
  26.           jp    nz,error1    ; only token, then error
  27.           push      de        ; Save evaluation of token
  28.           call      getccp        ; Get CCP address in HL
  29.           ld    (ccpadrs),hl    ; Save for later use
  30.           ld    de,3        ; 3 bytes for jump
  31.           or    a        ; Clear carry flag
  32.           sbc       hl,de        ; Subtract 3 from CCP address
  33.           pop       de        ; Restore evaluation of token
  34.           sbc       hl,de        ; Subtract token eval from CCP-3
  35.           jp    c,toohi_err    ; If token eval is greater, then error
  36.           ld    hl,($memry)    ; Get start of free memory
  37.           sbc       hl,de        ; Subtract token eval from end of prog.
  38.           jp    nc,toolo_err    ; If token eval is in program, error.
  39.           ld    hl,(06)        ; Get old BDOS jump address
  40.           push      hl        ; Save old BDOS
  41.           push      de        ; Save eval
  42.           ld    de,(ccpadrs)    ; Get CCP address
  43.           ex    de,hl        ; DE has old BDOS, HL has ccpaddress
  44.           or    a        ; Clear carry flag
  45.           sbc       hl,de          ; Subtract old DOS from CCP address
  46.           pop       de             ; Get back eval
  47.           pop       hl             ; Get back old DOS
  48.           jr    c,noprot           ; if DOS greater, then no prot
  49.           push      hl        ; save old DOS again
  50.           push      de        ; save eval address
  51.           ld    de,3
  52.           sbc       hl,de        ; decrement old DOS address by 3
  53.           pop       de        ; get back old eval address
  54.           sbc       hl,de        ; Subtract eval from old DOS-3
  55.           pop       hl        ; Restore old DOS address
  56.           jp    c,alprot    ; Already protected.  Must be lower
  57. noprot:       ld    (06h),de    ; All OK, so put token eval in BDOS adrs.
  58.           ex    de,hl        ; Get token eval in HL
  59.           push      hl        ; Save for display
  60.           ld    (hl),0c3h    ; Put a JP at eval address
  61.           inc       hl        ; Increment eval address
  62.           ld    (hl),e        ; Put DOS address following jump
  63.           inc       hl
  64.           ld    (hl),d
  65.           call      eprint
  66.           defb      0dh,0ah,'Memory protected above ',0
  67.           pop       hl         ; Print memory address
  68.           call      phl4hc
  69.           call    eprint
  70.           defb    'h.',0dh,0ah,0
  71.           ret
  72.  
  73.  
  74. toohi_err:    call      eprint
  75.           defb      0dh,0ah,'Start of CCP = ',0
  76.           ld    hl,(ccpadrs)
  77.           call      phl4hc
  78.           call      eprint
  79.           defb      'h.',0dh,0ah,'Protected address must be at least 3 '
  80.           defb      'bytes below this address.',0
  81.           call    crlf
  82.           ret
  83.           
  84. toolo_err:    call      eprint
  85.           defb      0dh,0ah,'End of CPROT = ',0
  86.           ld    hl,($memry)
  87.           call      phl4hc
  88.           call      eprint
  89.           defb      'h.',0dh,0ah,'Protected address must be above this '
  90.           defb      'address.',0
  91.           call    crlf
  92.           ret
  93.           
  94. alprot:       push      hl         ; Save old DOS address
  95.           call      eprint
  96.           defb      0dh,0ah,'Memory already protected above ',0
  97.           pop       hl
  98.           call      phl4hc
  99.           call      eprint
  100.           defb      'h.',0dh,0ah,'New protection address must be below this'
  101.           defb      ' address.',0
  102.           call     crlf
  103.           ret
  104.  
  105. error1:       call      eprint
  106.           defb      0dh,0ah,'Argument error ..........',0dh,0ah,0
  107.           
  108. tell:     call      eprint
  109.           defb      0dh,0ah,'Usage:  CPROT nnnn',0dh,0ah,0dh,0ah
  110.           defb      'DOS address is patched to protect memory above hex address '
  111.           defb      'nnnn.',0dh,0ah,'Address nnnn must be in free memory and '
  112.           defb      'will recieve a jump to the DOS',0dh,0ah,0
  113.           ret
  114.           
  115. $memry::      ds    2          ; filled by linker
  116. ccpadrs:      ds    2          ; address of CCP
  117.         end
  118.