; CPROT makes the BDOS jump address at 06h to the given address and ; establishes a jump at that address to the actual BDOS entry. Memory above ; the given address is protected. cseg ext eval16 ; Syslib routine to evaluate hexadecimal ext sksp ; Syslib routine to skip space ext getccp ; Determine the address of the CCP ext eprint ; Print null-term string ext phl4hc ; Print hex string in HL ext crlf .request syslib,z33lib ld hl,081h ; Space beginning of command tail call sksp ; Skip over whitespace ld a,(hl) or a ; If no command tail, document jp z,tell cp '/' ; Z3 help jp z,tell cp '?' ; Other help jp z,tell call eval16 ; Evaluate the hex number ld a,(hl) or a ; Not completely evaluated, or if not jp nz,error1 ; only token, then error push de ; Save evaluation of token call getccp ; Get CCP address in HL ld (ccpadrs),hl ; Save for later use ld de,3 ; 3 bytes for jump or a ; Clear carry flag sbc hl,de ; Subtract 3 from CCP address pop de ; Restore evaluation of token sbc hl,de ; Subtract token eval from CCP-3 jp c,toohi_err ; If token eval is greater, then error ld hl,($memry) ; Get start of free memory sbc hl,de ; Subtract token eval from end of prog. jp nc,toolo_err ; If token eval is in program, error. ld hl,(06) ; Get old BDOS jump address push hl ; Save old BDOS push de ; Save eval ld de,(ccpadrs) ; Get CCP address ex de,hl ; DE has old BDOS, HL has ccpaddress or a ; Clear carry flag sbc hl,de ; Subtract old DOS from CCP address pop de ; Get back eval pop hl ; Get back old DOS jr c,noprot ; if DOS greater, then no prot push hl ; save old DOS again push de ; save eval address ld de,3 sbc hl,de ; decrement old DOS address by 3 pop de ; get back old eval address sbc hl,de ; Subtract eval from old DOS-3 pop hl ; Restore old DOS address jp c,alprot ; Already protected. Must be lower noprot: ld (06h),de ; All OK, so put token eval in BDOS adrs. ex de,hl ; Get token eval in HL push hl ; Save for display ld (hl),0c3h ; Put a JP at eval address inc hl ; Increment eval address ld (hl),e ; Put DOS address following jump inc hl ld (hl),d call eprint defb 0dh,0ah,'Memory protected above ',0 pop hl ; Print memory address call phl4hc call eprint defb 'h.',0dh,0ah,0 ret toohi_err: call eprint defb 0dh,0ah,'Start of CCP = ',0 ld hl,(ccpadrs) call phl4hc call eprint defb 'h.',0dh,0ah,'Protected address must be at least 3 ' defb 'bytes below this address.',0 call crlf ret toolo_err: call eprint defb 0dh,0ah,'End of CPROT = ',0 ld hl,($memry) call phl4hc call eprint defb 'h.',0dh,0ah,'Protected address must be above this ' defb 'address.',0 call crlf ret alprot: push hl ; Save old DOS address call eprint defb 0dh,0ah,'Memory already protected above ',0 pop hl call phl4hc call eprint defb 'h.',0dh,0ah,'New protection address must be below this' defb ' address.',0 call crlf ret error1: call eprint defb 0dh,0ah,'Argument error ..........',0dh,0ah,0 tell: call eprint defb 0dh,0ah,'Usage: CPROT nnnn',0dh,0ah,0dh,0ah defb 'DOS address is patched to protect memory above hex address ' defb 'nnnn.',0dh,0ah,'Address nnnn must be in free memory and ' defb 'will recieve a jump to the DOS',0dh,0ah,0 ret $memry:: ds 2 ; filled by linker ccpadrs: ds 2 ; address of CCP end