home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / extra18 / pastrick / plusenv / newenv.asm next >
Encoding:
Assembly Source File  |  1991-12-17  |  4.8 KB  |  139 lines

  1. ;* -------------------------------------------------- *
  2. ;*                     NEWENV.ASM                     *
  3. ;*  Funktion: Vergrößertes Evironment anlegen         *
  4. ;*  Compiler: Turbo Asssembler                        *
  5. ;*            TASM newenv.asm /t                      *
  6. ;* -------------------------------------------------- *
  7. ;*         (c) 1991 Christoph Seck & DMV-Verlag       *
  8. ;* -------------------------------------------------- *
  9. .MODEL tiny
  10. .CODE
  11. .STARTUP
  12.  
  13. ;* -------------------------------------------------- *
  14.  
  15.   mov    bx,3                ; Eigenes Enviroment
  16.   mov    ax,[bx+29h]         ; suchen.
  17.   dec    ax                  ;
  18.   mov    own_env,ax          ; Dessen MCB merken.
  19.   mov    es,ax               ; Process ID
  20.   mov    cx,es:[bx-2]        ; in CX merken.
  21.   add    ax,es:[bx]          ; Naechsten MCB
  22.   inc    ax                  ; nach DS laden.
  23.   mov    ds,ax               ;
  24.   cmp    cx,[bx-2]           ; Ist er der unseres
  25.   je     in_reihe            ; Programms?
  26.   cmp    word ptr [bx-2],0   ; Ist es ein freier
  27.                              ; Block?
  28.                              ; Wenn nichts davon:
  29.   mov    al,'1'              ; Return 1 und
  30.   jne    nach_raus           ; raus.
  31.  
  32.                   ; Freien Block ans Enviroment haengen
  33.  
  34.   mov    cx,[bx]             ; Laenge des freien
  35.   inc    cx                  ; Blocks+dessen MCB
  36.   add    es:[bx],cx          ; kommt zur Laenge des
  37.   push   cs                  ; Env dazu.
  38.   pop    ds                  ;
  39.   jmp    short join          ;
  40.  
  41.                   ; Enviroment um PSP verlaengern
  42.  
  43. in_reihe:
  44.   push   cs                  ;
  45.   pop    ds                  ;
  46.   mov    es,own_env          ; Env Speicherblock
  47.   add    word ptr es:[bx],11h; um 11 vergroessern.
  48.   mov    cx,[bx-1]           ; CX=Top of Memory
  49.   mov    ax,ds               ; (in Paragraphen).
  50.   sub    cx,ax               ; CX=Speicher hinter
  51.                              ; dem Env.
  52.                              ; Laenge des PSP soll
  53.   sub    cx,11h              ; dazu kommen.
  54.  
  55.                   ; Neuer MCB nach CS:100h:
  56.  
  57.   mov    byte ptr [bx+0FDh],5ah ; Ist letzter MCB.
  58.   mov    word ptr [bx+0FEh],0   ; Gehoert DOS (frei)
  59.   mov    [bx+100h],cx        ; Und ist 'CX' lang.
  60.  
  61. join:                        ; Command PSP
  62.   mov    dx,word ptr[bx+13h] ; finden.
  63. vorne:
  64.   mov    es,dx               ;
  65.   cmp    word ptr es:[bx+13h],dx ; Ist Parent PSP=PSP?
  66.   je     ende                ;
  67.   mov    dx,es:[bx+13h]      ;
  68.   jmp    vorne               ;
  69. ende:
  70.   mov    bp,dx               ; In BP wird die Adresse
  71.                              ; von Com's PSP
  72.                              ; gespeichert.
  73.   mov    es,dx               ;
  74.   mov    ax,es:[bx+29h]      ; Command Env finden
  75.   mov    com_env,ax          ; (PSP:2Ch ansehen).
  76.  
  77.   dec    dx                  ; Commands interne
  78.   mov    es,dx               ; Env. Adresse finden:
  79.   mov    cx,es:[bx]          ; CX=Laenge von Com.
  80.   sub    cx,10h              ; in Paragraphen (steht
  81.   REPT   4                   ; in Com's MCB).
  82.   shl    cx,1                ; Wir brauchen Byte.
  83.   ENDM                       ;
  84.   inc    dx                  ;
  85.   mov    es,dx               ;
  86.   mov    di,100h             ; Nicht im PSP suchen.
  87. suchen:
  88.   cmp    es:[di],ax          ;
  89.   jne    war_nix             ; Falls gefunden:
  90.   cmp    dx,0                ; Erster Treffer?
  91.   je     error_2             ; Wenn nicht: raus!
  92.   mov    dx,0                ; Sonst: Merken.
  93.   mov    si,di               ;
  94. war_nix:
  95.   inc    di                  ;
  96.   loop   suchen              ;
  97.   cmp    dx,0                ; War Suche erfolgreich?
  98.   je     gefunden            ;
  99. error_2:
  100.   mov    al,'2'              ; Return 2 und
  101. nach_raus:
  102.   mov    ah,0Eh              ;
  103.   int    10h                 ;
  104.   sub    al,'0'              ;
  105.   jmp    short raus          ; raus.
  106. gefunden:
  107.   mov    ax,own_env          ; Korrigieren von Com's
  108.   inc    ax                  ; interner Enviroment
  109.   mov    es:[si],ax          ; Adresse.
  110.  
  111.   mov    es:[bx+29h],ax      ; Neues Enviroment
  112.                              ; im command.com PSP
  113.                              ; eintragen.
  114.   mov    ax,com_env          ; Com Enviroment
  115.   mov    es,ax               ; freimachen.
  116.   mov    ah,49h              ;
  117.   int    21h                 ;
  118.   mov    ax,own_env          ;
  119.   mov    es,ax               ; Eigenes Env=Com Env.
  120.   mov    cx,bp               ; (Process ID von
  121.   mov    es:[bx-2],cx        ; Com. eintragen).
  122.   mov    al,0                ; Return 0.
  123.  
  124. raus:
  125.   mov    ah,4Ch
  126.   int    21h
  127.  
  128. ;* -------------------------------------------------- *
  129. ; DATEN
  130.  
  131. com_env  dw ?
  132. own_env  dw ?
  133.  
  134. END
  135.  
  136. ;* -------------------------------------------------- *
  137. ;*                Ende von NEWENV.ASM                 *
  138.  
  139.