/FAQServer 2:5025/38.12@fidonet/ //TSR PSP

 ------------------------------------------------------------------------------
  FROM: Ilya Khaikov 2:468/37.17@fidonet
  SUBJ: TSR  PSP
 ------------------------------------------------------------------------------
                     , Ilya!   :

 IK>  ,  ,   Subj ?
 IK>      ,     .

  !     UMB.
 ()

:
;--CUT-------------------------------------------------------------------------
Addr| Size  | Owner |
05A0|    240|TSR.EXE| environment
05B0| 74,816|TSR.EXE| programm
17F5|545,856|   free|
;--CUT-------------------------------------------------------------------------
  :
;--CUT-------------------------------------------------------------------------
Addr| Size  | Owner |
05A0|    240|   free|  environment
05B0|    256|   free|  PSP
05C0| 74,560|TSR.EXE|
17F5|545,856|   free|
;--CUT-------------------------------------------------------------------------
      ,     .
   ,     
(  17F5),  envir  PSP    .
         ,
   ,      .
  (  ).    UMB  (  -
)  LOW MEMORY    MCB,    .
 ( ),   -   .
PS:   ASSEMBLER       . 
=== Cut ===
;ߘ;
; TSR in Upper Memory Block          Written by Michael Stewart ;
;ܘ;
;------------------------------------------------------------------------------
 MultiplexReturn equ 0FF21h
 Multiplex  equ 0FF12h
;------------------------------------------------------------------------------
.MODEL TINY
.CODE
.STARTUP
.386
;
;------------------------------------------------------------------------------
; Write logo
;------------------------------------------------------------------------------
  mov ah,09h
  lea dx,WrittenBy
  int 21h
;------------------------------------------------------------------------------
; Check for installed state
;------------------------------------------------------------------------------
  mov ax,Multiplex
  int 2Fh
  cmp ax,MultiplexReturn
  jnz short EndOfInstallCheck
  mov cs:[TSRSeg],bx
  EndOfInstallCheck:
;------------------------------------------------------------------------------
; Read command line /U parameter and uninstall if it was given
;------------------------------------------------------------------------------
  cmp byte ptr ds:[0080h],1
  ja CMDParamFound
  jmp Install
  CMDParamFound:
  mov cx,63
  mov si,0081h
  CMDparamsLoop:
  cmp word ptr [si],752Fh
  jz short Uninstall
  cmp word ptr [si],552Fh
  jz short Uninstall
  inc si
  loop CMDparamsLoop
  jmp Install
;------------------------------------------------------------------------------
  Uninstall:
;------------------------------------------------------------------------------
  or word ptr cs:[TSRSeg],0
  jnz CheckVectors
  mov ah,09h
  lea dx,NotYetInMemory
  int 21h
  jmp Terminate
;------------------------------------------------------------------------------
  CheckVectors:
;------------------------------------------------------------------------------
 ;----------------------------------------------------------------------
 mov ax,cs:[TSRSeg]  ;Is vector 2Fh ours
 mov cl,16
 shl eax,cl
 mov ax,[offset New_2Fh-offset TSRStart]
 xor si,si
 mov ds,si
 mov si,(2Fh*4)
 cmp eax,ds:[si]
 jnz short CantUninstall
 ;----------------------------------------------------------------------
 ;----------------------------------------------------------------------
 mov ax,cs:[TSRSeg]  ;Is vector __h ours
 mov cl,16
 shl eax,cl
 mov ax,[offset New___h-offset TSRStart]
 xor si,si
 mov ds,si
 mov si,(__h*4)
 cmp eax,ds:[si]
 jnz short CantUninstall
 ;----------------------------------------------------------------------

;------------------------------------------------------------------------------
; RestoreVectors
;------------------------------------------------------------------------------
 ;----------------------------------------------------------------------
 mov si,cs:[TSRSeg]  ;Restore vector 2Fh
 mov ds,si
 mov si,[offset Old_2Fh-offset TSRStart]
 xor di,di
 mov es,di
 mov di,(2Fh*4)
 movsd
 ;----------------------------------------------------------------------
 ;----------------------------------------------------------------------
 mov si,cs:[TSRSeg]  ;Restore vector __h
 mov ds,si
 mov si,[offset Old___h-offset TSRStart]
 xor di,di
 mov es,di
 mov di,(__h*4)
 movsd
 ;----------------------------------------------------------------------

;------------------------------------------------------------------------------
; Free resident block
;------------------------------------------------------------------------------
  mov si,cs:[TSRSeg]  ;Free Resident Block
  dec si
  mov ds,si
  mov word ptr ds:[0001h],0000h
  push cs
  pop ds
  mov ah,09h
  lea dx,OkUninstall
  int 21h
  jmp Terminate
  CantUninstall:
  push cs
  pop ds
  mov ah,09h
  lea dx,CantRemove
  int 21h
  jmp Terminate
;------------------------------------------------------------------------------
  Install:
;------------------------------------------------------------------------------
  or word ptr cs:[TSRSeg],0
  jz Locate1
  mov ah,09h
  lea dx,AlreadyInMemory
  int 21h
  jmp Terminate
  Locate1:
  jmp InstallToUMB

;==============================================================================
; RESIDENT PART OF THE PROGRAMM
;==============================================================================
 TSRStart:
;
;..............................................................................
  new_2Fh:
  cmp ax,Multiplex
  jz short Identificate
  out_2Fh: db 0EAh
  old_2Fh  dd 0
  Identificate:
  mov ax,MultiplexReturn
  mov bx,cs
  iret
;..............................................................................
;
;
;..............................................................................
New___h:
 ;----------------------------------------------------------------------



 ;----------------------------------------------------------------------
Out___h: db 0EAh
Old___h  dd 0
;..............................................................................
;
 TSREnd:
;------------------------------------------------------------------------------
; Free the ENVIRONMENT
;------------------------------------------------------------------------------
  mov ax,cs:[002Ch]
  mov es,ax
  mov ah,49h
  int 21h
  mov word ptr cs:[002Ch],0000h
;------------------------------------------------------------------------------
; Install to UMB
;------------------------------------------------------------------------------
InstallToUMB: mov ax,5803h ;Set new UMB link state
  mov bx,0001h
  int 21h
  mov ax,5800h ;Get current strategy
  int 21h
  jc MemError
  push ax
  mov ax,5801h ;Set new strategy
  mov bx,0080h
  int 21h
  jc MemError
  mov ax,4800h ;Allocate memory
  mov bx,(TSREnd-TSRStart)/16+1
  int 21h
  jc MemError
  mov cs:[TSRSeg],ax
  mov ax,5801h ;Set old strategy
  pop bx
  int 21h
  jc MemError
  mov ax,cs:[TSRSeg]
  dec ax
  mov es,ax
  inc ax
  mov es:[0001h],ax
  lea si,TSRName
  mov di,0008h
  mov cx,0008h
  rep movsb
  jmp short NoMemErrors
MemError: push cs
  pop ds
  mov ah,09h
  lea dx,MemErrorMsg
  int 21h
  mov ax,4C4Ch
  int 21h
NoMemErrors:
  mov es,ax
  mov di,[offset TSRStart-offset TSRStart]
  lea si,[TSRStart]
  mov cx,[offset TSREnd-offset TSRStart]
  rep movsb
  mov di,[offset Old_2Fh-offset TSRStart]
  xor si,si
  mov ds,si
  mov si,(2Fh*4)
  push ds si es
  movsd
  pop ds di es
  mov cl,16
  shl eax,cl
  mov ax,[offset New_2Fh-offset TSRStart]
  stosd
  push cs
  pop ds
  mov ah,09h
  lea dx,Installed
  int 21h
;==============================================================================
; Set interrupt vectors
;------------------------------------------------------------------------------
 ;----------------------------------------------------------------------
 mov di,cs:[TSRSeg]
 mov es,di
 mov di,offset [Old___h] - offset [TSRStart]
 xor si,si
 mov ds,si
 mov si,(__h*4)
 movsd
 mov ax,es
 push ds
 pop es
 mov di,(__h*4)
 mov cl,16
 shl eax,cl
 mov ax,offset [New___h] - offset [TSRStart]
 stosd
 ;----------------------------------------------------------------------

;------------------------------------------------------------------------------
; Terminate:
;------------------------------------------------------------------------------
Terminate: mov ax,4C00h
  int 21h
;


.DATA
;
MemErrorMsg db ' Memory allocation error.',0Dh,0Ah,7,'$'
TSRName  db '        ' ;must be 8 bytes !!!
TSRSeg  dw 0
AlreadyInMemory db ' Already installed in memory',0Dh,0Ah,'$'
NotYetInMemory db ' Not yet installed in memory',0Dh,0Ah,'$'
CantRemove db ' Cant uninstall from memory. Somebody changed my'
  db ' vectors',0Dh,0Ah,'$'
Installed db ' Successfuly installed into memory',0Dh,0Ah,'$'
OkUninstall db ' Successfuly uninstalled from memory',0Dh,0Ah,'$'
WrittenBy db 'by Michael Stewart /-==-/ 2:50/435.66@fidonet'
  db '.org',0Dh,0Ah
  db ' /U to uninstall from memory',0Dh,0Ah,0Dh,0Ah,'$'
;
END
=== Cut ===

                                      !
                                     With best regards, Michael Stewart.

File created by Faq2Site converter. (C) 1998-2002 Edward Grebenyukov
Hosted by uCoz