[Back to MEMORY SWAG index] [Back to Main SWAG index] [Original]

    {*******************************}
    {*         �®¤ã«ì ¯à®áâ®£®     *}
    {*  �®£®¯à®æ¥áá�®£® ®�¨â®à�  *}
    {*          VSTasks v 1.01     *}
    {*   ¤«ï Turbo Pascal ver 7.0  *}
    {* (c) Copyright VVSsoft Group *}
    {*******************************}
    {$F+$S-}

    {  v.1.01  ---  ¯® áà�¢�¥�¨î á ¢¥àá¨¥© 1.0 ¨á¯à�¢«¥� ¢ëå®¤ ¨§ ¯à®æ¥áá�- }
    {               ¯à®æ¥¤ãàë ¯® ¤®áâ¨¦¥�¨î  END. � ¯à¥¤ë¤ãé¥© ¢¥àá¨¨ �ã¦�® }
    {               ¡ë«® ®¡ï§�â¥«ì�® ¯¥à¥¤ END-® áâ�¢¨âì  HaltCurrentTask, }
    {               ¨��ç¥  á¨áâ¥� "¢¨á«�".  �¥¯¥àì  ¯à¨  ¤®áâ¨¦¥�¨¨  ª®�æ� }
    {               ¯à®æ¥áá�-¯à®æ¥¤ãàë �¢â®�â® ¯à®æ¥áá §�ªàë¢�¥âáï ...    }
    {                                                                       }
    {                               (c) VVSsoft Group.  �®�®�®¢ �«�¤¨¨à.   }

    Unit VSTasks;

    interface {--------------------------------------------}

    Type

     PTaskRec =^TTaskRec;  { ---- ®¯¨á�â¥«ì ¯à®æ¥áá� -----}
     TTaskRec =
      record
       NumProc  : word;        { ã�¨ª�«ì�ë© �®¥à ¯à®æ¥áá� }
       Next     : PTaskRec;    { á«¥¤ãîé¨© ®¯¨á�â¥«ì ¯à®æ¥áá� }
       OrignSP,                { §��ç¥�¨¥ SP ¤«ï ¢®§¢à�â� }
       OrignSS  : word;        { §��ç¥�¨¥ SS ¤«ï ¢®§¢à�â� }
       Stack    : pointer;     { ãª�§�â¥«ì �� áâ¥ª ¯à®æ¥áá� }
       SSize    : word;        { à�§¥à áâ¥ª� ¯à®æ¥áá� }
      end;

    Const

      CountTask   : word = 0;       { ¢á¥£® §�à¥£¨áâà¨à®¢���® ¯à®æ¥áá®¢ }
      PCurTask    : PTaskRec = Nil; { ãª�§�â¥«ì �� â¥ªãéãî ¢ë¯®«�ï¥ãî §�¤�çã }
      HeadStack   : PTaskRec = Nil; { ãª�§�â¥«ì �� £®«®¢ã áâ¥ª� }
      UniNumber   : word = 1;       { ã�¨ª�«ì�ë© �®¥à ¤«ï á®§¤�¢�¥®£® ¯à®æ¥áá� }
      CurTask     : word = 0;       { �®¥à â¥ªãé¥£® ¯à®æ¥áá� }

    {----------------- ª®¤ë ®è¨¡®ª à¥£¨áâà�æ¨¨ ¯à®æ¥áá� --------------}

      vstMemoryLow       = 1;   { �¥â ¯�ïâ¨ ¤«ï á®§¤��¨ï áâ¥ª� ¯à®æ¥áá� }
      vstEmptyStackTask  = 2;   { �¥â §�à¥£¨áâà¨à®¢���ëå ¯à®æ¥áá®¢ }
      vstMAXLimitProc    = 3;   { á«¨èª® �®£® ¯à®æ¥áá®¢ }

    Var
      TaskError     : byte;     { ¯®á«¥¤�ïï ®è¨¡ª� }

    procedure StartTasks;
    {--- §�¯ãáª ¯à®æ¥áá®¢ �� ¢ë¯®«�¥�¨¥ ---}

    procedure SwithTasks; far;
    {--- ¯¥à¥ª«îç¥�¨¥ ¥¦¤ã §�¤�ç�¨ ---}

    function RegisterTask(TaskPoint : pointer; SizeStack: word): word;
    {--- à¥£¨áâà�æ¨ï §�¤�ç¨ ¥á«¨ - 0, â® ®è¨¡ª� ¢ ¯¥à¥¥��®© TaskError ---}
    {--- ¢®§¢à�é�¥â �®¥à §�à¥£¨áâà¨à®¢���®£® ¯à®æ¥áá� ---}

    procedure HaltCurrentTask;
    {--- á�ïâ¨¥ â¥ªãé¥© §�¤�ç¨ ---}

    procedure HaltAllTasks;
    {--- á�ïâ¨¥ ¢á¥å §�¤�ç ---}

    implementation
    {----------------------------------------------------------------}

    Var
        OriginalSS,                { �¤à¥á ®à¨£¨��«ì�®£® áâ¥ª� ¯à®£à�ë     }
        OriginalSP     : word;     { ãª�§�â¥«ì ®à¨£¨��«ì�®£® áâ¥ª� ¯à®£à�ë }
        PDopPoint      : PTaskRec; { ¤®¯®«�¨â¥«ì�ë© ãª�§�â¥«ì }

    {------- ¯¥à¥®¯à¥¤¥«¥��ë¥ äã�ªæ¨¨ ¤«ï à�¡®âë á BASM® ---------}

    function mMemAvail: word;
    Var M: longint;
        T: record
            L,H: word;
           end;
    begin
     M:=MaxAvail;
     If M>$FFFF then mMemAvail:=$FFFF
      else
       begin
        Move(M,T,SizeOf(longint));
        mMemAvail:=T.L;
       end;
    end;

    function mGetMem(S:word): pointer;
    Var P:pointer;
    begin
     GetMem(P,S);
     mGetMem:=P;
    end;

    procedure mFreeMem(P: pointer;S: word);
    Var D: pointer;
    begin
     D:=P;
     FreeMem(P,S);
    end;

    procedure StartTasks; assembler;
    { --- §�¯ãáª ¯à®æ¥áá®¢ �� ¢ë¯®«�¥�¨¥ --- }
    asm
        { 1) ��¯®�¨âì ¢ áâ¥ª¥ à¥£¨áâàë;
          2) ��¯®�¨âì ¢ áâ¥ª¥ â®çªã ¢ëå®¤� ¨§ ¥�¥¤¦¥à� ¯à®æ¥áá®¢;
          3) �®åà��¨âì à¥£¨áâàë SS ¨ SP ¤«ï ®á�®¢�®© ¯à®£à�ë;
          4) ��©â¨ ¯¥à¢ë© ¯à®æ¥áá ¤«ï §�¯ãáª�;
          5) �¥à¥ãáâ��®¢¨âì ¢á¥ â¥ªãé¨¥ ¯¥à¥¥��ë¥;
          6) �¥à¥ãáâ��®¢¨âì SS:SP ¨ ¢®ááâ��®¢¨âì à¥£¨áâàë;
          7) �à®¨§¢¥áâ¨ "¤«¨��ë© ¢ëå®¤" (ç¨â�© ¢å®¤) RETF ¢ ¯à®æ¥áá;
          8) �®á«¥ ¢®§¢à�â� ¢ â®çªã ¢ëå®¤� ¨§ ¯à®æ¥áá�, ¢®ááâ��®¢¨âì
             à¥£¨áâàë. }
       {----------------------------------------------------}
                     PUSH BP                    { á®åà��ï¥ à¥£¨áâàë            }
                     PUSH DI                    {}
                     PUSH SI                    {}
                     PUSH DS                    {}
                     PUSH ES                    {}
                     LEA  DI, @ExitPoint        { ¢ DI á¥é¥�¨¥ ¢ëå®¤�          }
                     PUSH CS                    { á®åà��ï¥ â®çªã ¢ëå®¤� ¨§     }
                     PUSH DI                    { ¯à®æ¥áá®¢                     }
                     MOV  OriginalSS, SS        { á®åà��ï¥ SS:SP               }
                     MOV  OriginalSP, SP        {}
                     MOV  AX, CountTask         { ¥á«¨ �¥â §�à¥£¨áâà¨à®¢. §�¤�ç }
                     XOR  BX, BX                {}
                     CMP  AX, BX                {}
                     JE   @Exit                 { ®ç¥à¥¤ì ¯à®æ¥áá®¢ ¯ãáâ�       }
                     MOV  DI, HeadStack.word[0] { ¢ ES:DI ãª�§�â¥«ì ��          }
                     MOV  ES, HeadStack.word[2] { ®¯¨á�â¥«ì ¯à®æ¥áá�            }
                     MOV  AX, ES:[DI]           { �®¥à â¥ªãé¥£® ¯à®æ¥áá�       }
                     MOV  CurTask, AX           {}
                     MOV  PCurTask.word[0], DI  { PCurTask à�¢�® ¯¥à¢®ã        }
                     MOV  PCurTask.word[2], ES  { ¯à®æ¥ááã                      }
                     CLI                        {}
                     MOV  SS, ES:[DI+8]         { ¯¥à¥ãáâ��®¢ª� áâ¥ª�           }
                     MOV  SP, ES:[DI+6]         {}
                     STI                        {}
                     POP  BP                    { ¢®áâ���¢«¨¢�¥ à¥£¨áâàë       }
                     POP  ES                    { ¯à®æ¥áá�                      }
                     POP  DS                    {}
                     RETF                       { "¢ëå®¤" ¢ ¯à®æ¥áá             }
     @Exit:          POP  AX                    { ¤®áâ�¥ ¨§ áâ¥ª� �¥�ã¦�®¥     }
                     POP  AX                    {}
                     MOV  AL, vstEmptyStackTask {}
                     MOV  TaskError, AL         {}
     @ExitPoint:     POP  ES                    { ¢®ááâ���¢«¨¢�¥ à¥£¨áâàë      }
                     POP  DS                    {}
                     POP  SI                    {}
                     POP  DI                    {}
                     POP  BP                    {}
    end;

    procedure SwithTasks; assembler;
    { --- ¯¥à¥ª«îç¥�¨¥ ¥¦¤ã §�¤�ç�¨ --- }
    asm
        { 1) C®åà��¥�¨¥ ¢á¥å à¥£¨áâà®¢ â¥ªãé¥£® ¯à®æ¥áá� [DS,ES,BP];
          2) ��å®¦¤¥�¨¥ á«¥¤ãîé¥£® ¯à®æ¥áá� ¤«ï ¨á¯®«�¥�¨ï;
          3) C®åà��¥�¨¥ ãª�§�â¥«¥© SS:SP �� áâ¥ª â¥ªãé¥£® ¯à®æ¥áá�;
          4) �§¥�¥�¨¥ ãª�§�â¥«¥© SS:SP �� áâ¥ª ¤«ï ¯®á«¥¤ãîé¥£® ¯à®æ¥áá�;
          5) �§¥�¥�¨¥ ¢á¥å â¥ªãé¨å ¯¥à¥¥��ëå;
          6) �®ááâ��®¢«¥�¨¥ à¥£¨áâà®¢ ¤«ï �®¢®£® ¯à®æ¥áá� [BP,ES,DS]; }
       {-----------------------------------------------------------------}
                     PUSH DS                    { á®åà��¥�¨¥ à¥£¨áâà®¢ áâ�à®£®  }
                     PUSH ES                    { ¯à®æ¥áá�                      }
                     PUSH BP                    {}
                     MOV  AX, SEG @Data         { ãáâ��®¢ª� á¥£¥�â� ¤���ëå     }
                     MOV  DS, AX                {}
                     MOV  ES, PCurTask.word[2]  { ¢ ES:DI ãª�§�â¥«ì �� ®¯¨á�â¥«ì}
                     MOV  DI, PCurTask.word[0]  { â¥ªãé¥£® ¯à®æ¥áá�             }
                     MOV  ES:[DI+8], SS         { á®åà��ï¥ SS:SP ¢ â¥ªãé¥     }
                     MOV  ES:[DI+6], SP         { ®¯¨á�â¥«¥ ¯à®æ¥áá�            }
                     MOV  BX, ES:[DI+4]         { ¢ BX:SI ãª�§�â¥«ì �� á«¥¤ãîé¨©}
                     MOV  SI, ES:[DI+2]         { ¯à®æ¥áá                       }
                     MOV  ES, BX                { ã¦¥ ¢ ES:SI                   }
                     XOR  AX, AX                { ¯à®¢¥àª� �� Nil               }
                     CMP  BX, AX                {}
                     JNE  @Next                 { ¥á«¨ �¥ Nil-ª ®¡à�¡®âª¥       }
                     CMP  SI, AX                {}
                     JNE  @Next                 {}
                     MOV  ES, HeadStack.word[2] { ¨��ç¥ á«¥¤ãîé¨© - ��ç�«ì�ë©   }
                     MOV  SI, HeadStack.word[0] { ®¯¨á�â¥«ì HeadStack           }
     @Next:          MOV  PCurTask.word[2], ES  { ¥�ï¥ ãª�§�â¥«ì �� â¥ªãé¨©   }
                     MOV  PCurTask.word[0], SI  { ®¯¨á�â¥«ì                     }
                     MOV  AX, ES:[SI]           { ¥�ï¥ �®¥à â¥ªãé¥£® ¯à®æ¥áá�}
                     MOV  CurTask, AX           {}
                     CLI                        {}
                     MOV  SS, ES:[SI+8]         { ¥�ï¥ ãª�§�â¥«¨ áâ¥ª�        }
                     MOV  SP, ES:[SI+6]         { ¯®¤ �®¢ë© ¯à®æ¥áá             }
                     STI                        {}
                     POP  BP                    { ¢®ááâ��®¢«¥�¨¥ à¥£¨áâà®¢      }
                     POP  ES                    { �®¢®£® ¯à®æ¥áá�               }
                     POP  DS                    {}
    end;

    function RegisterTask(TaskPoint: pointer; SizeStack: word): word; assembler;
    { --- à¥£¨áâà�æ¨ï §�¤�ç¨ --- }
    { ¥á«¨ ¢®é§¢à�é¥� 0, â® ®è¨¡ª� ¢ ¯¥à¥¥��®© TaskError }
    asm
        { 1) �®§¤��¨¥ ¢ ¯�ïâ¨ ®¯¨á�â¥«ï ¯à®æ¥áá�;
          2) �ë¤¥«¥�¨¥ ¯�ïâ¨ ¯®¤ áâ¥ª ¯à®æ¥áá�;
          3) ��å®¦¤¥�¨¥ ã�¨ª�«ì�®£® ®¯¨á�â¥«ï ¯à®æ¥áá�;
          4) �¢ï§ª� ®¯¨á�â¥«ï �®¢®£® ¯à®æ¥áá� ¢ æ¥¯®çªã ¯à®æ¥áá®¢;
          5) �®åà��¥�¨¥ ¢ áâ¥ª¥ ¯à®æ¥áá� �¤à¥á� ¢å®¤� ¢ ¯à®æ¥áá ¨ à¥£¨áâà®¢;
          6) �ëå®¤ ¢ ®á�®¢�ãî ¯à®£à�ã. }
        {---------------------------------------------------------}
                     XOR  AX, AX                {}
                     NOT  AX                    {}
                     CMP  AX, UniNumber         {}
                     JE   @TooManyProc          { á«¨èª® �®£® ¯à®æ¥áá®¢       }
                     CALL mMemAvail             { ¯à®¢¥àª� ��«¨ç¨ï ¯�ïâ¨       }
                     MOV  BX, SizeStack         {}
                     CMP  AX, BX                {}
                     JB   @LowMem               { ¥á«¨ ¯�ïâ¨ �¥â               }
                     PUSH BX                    {}
                     CALL mGetMem               { ¢ DX:AX ãª�§�â¥«ì �� áâ¥ª     }
                     PUSH DX                    {}
                     PUSH AX                    {}
                     CALL mMemAvail             { ¯�ïâì ¤«ï TTaskRec           }
                     MOV  CX, TYPE TTaskRec     {}
                     CMP  AX, CX                {}
                     JB   @LowMemAndFree        { ¥á«¨ �¥ å¢�â¨â                }
                     PUSH CX                    { £®â®¢¨ ¯�à�¥âàë             }
                     CALL mGetMem               { ¢ë¤¥«ï¥ ¯�ïâì               }
                     PUSH ES                    {}
                     MOV  ES, DX                { ES:DI ãª�§ë¢�¥â �� ®¯¨á�â¥«ì  }
                     MOV  DI, AX                { �®¢®£® ¯à®æ¥áá�               }
                     MOV  AX, UniNumber         { ¯à¨á¢�¨¢�¥ ã�¨ª�«ì�ë© �®¥à  }
                     MOV  ES:[DI], AX           {}
                     INC  AX                    { ¨�ªà¥¥�â UniNumber           }
                     MOV  UniNumber, AX         {}
                     MOV  BX, HeadStack.word[0] { ãª�§�â¥«ì �� á«¥¤ãîé¨©        }
                     MOV  CX, HeadStack.word[2] { ®¯¨á�â¥«ì = HeadStack         }
                     MOV  ES:[DI+2], BX         {}
                     MOV  ES:[DI+4], CX         {}
                     POP  CX                    { ¢ CX  §��ç¥�¨¥ ES             }
                     POP  AX                    { ¢ AX á¥é¥�¨¥ áâ¥ª�           }
                     MOV  ES:[DI+10], AX        { á¥é¥�¨¥ ãª�§�â¥«ï Stack      }
                     MOV  BX, SizeStack         { á®åà��ï¥ à�§¥à áâ¥ª� ¢      }
                     MOV  ES:[DI+14], BX        { SSize â¥ªãé¥£® ®¯¨á�â¥«ï      }
                     ADD  AX, BX                { ¢ëç¨á«ï¥ §��ç¥�¨¥ SP         }
                     JNC  @NotCorrect           { ¥á«¨ ª®àà¥ªæ¨ï �¥ �ã¦��       }
                     XOR  AX, AX                {}
                     NOT  AX                    { AX=$FFFF                      }
     @NotCorrect:    SUB  AX, $01               {}
                     POP  BX                    { ¢ BX á¥£¥�â áâ¥ª�            }
                     MOV  ES:[DI+12], BX        { á¥£¥�â ãª�§�â¥«ï Stack       }
                     MOV  ES:[DI+8], BX         { OrignSS=BX                    }
                     PUSH ES                    { á®åà��ï¥ á¥£¥�â ãª�§�â¥«ï   }
                     MOV  ES, CX                { ¢®ááâ��®¢¨«¨ ES               }
                     MOV  CX, TaskPoint.WORD[0] { á¥é¥�¨¥ ��ç�«� §�¤�ç¨        }
                     MOV  DX, TaskPoint.WORD[2] { á¥£¥�â ��ç�«� §�¤�ç¨         }
                     PUSH BP
                     CLI                        {}
                     MOV  SI, SS                { á®åà��ï¥ SS ¢ SI             }
                     MOV  BP, SP                { á®åà��ï¥ SP ¢ BP             }
                     MOV  SS, BX                { ¯¥à¥ãáâ���¢«¨¢�¥ áâ¥ª        }
                     MOV  SP, AX                {}
                     MOV  BX,SEG    HaltCurrentTask { �¢â®�â¨ç¥áª¨© ¢ëå®¤ ¢    }
                     MOV  AX,OFFSet HaltCurrentTask { ¯à®æ¥¤ãàã HaltCurrentTask }
                     PUSH BX                    { ¯® ¤®áâ¨¦¥�¨î ®¯¥à�â®à� END   }
                     PUSH AX                    { â¥ªãé¥© ¯à®æ¥¤ãàë-¯à®æ¥áá�    }
                     PUSH DX                    { á®åà��ï¥ â®çªã ¢å®¤� ¢       }
                     PUSH CX                    { ¯à®æ¥áá                       }
                     PUSH DS                    { á®åà��ï¥ ¢ �¥ DS            }
                     PUSH ES                    { -\\- ES                       }
                     MOV  DX, SP                { £®â®¢¨ ¯á¥¢¤® BP             }
                     ADD  DX, $02               { §�â�«ª¨¢�¥ ¥£® ¢ áâ¥ª        }
                     PUSH DX                    {}
                     MOV  CX, SP                {}
                     MOV  SS, SI                { ¢®ááâ���¢«¨¢�¥ áâ¥ª          }
                     MOV  SP, BP                {}
                     STI                        {}
                     POP  BP                    { ¢®ááâ���¢«¨¢�¥ BP            }
                     MOV  AX, ES                {}
                     POP  ES                    {}
                     MOV  ES:[DI+6], CX         { OrignSP=CX                    }
                     PUSH ES                    {}
                     MOV  ES, AX                {}
                     POP  AX                    {}
                     MOV  HeadStack.WORD[0], DI { ¯¥à¥ãáâ���¢«¨¢�¥ ãª�§�â¥«ì   }
                     MOV  HeadStack.WORD[2], AX { HeadStack                     }
                     MOV  AX, CountTask         { ¨�ªà¥¥�â¨àã¥ CountTask      }
                     INC  AX                    {}
                     MOV  CountTask, AX         {}
                     MOV  AX, UniNumber         { ¢®§¢à�é�¥ë© �®¥à ¯à®æ¥áá�   }
                     DEC  AX                    {}
                     JMP  @Exit                 { ¢ëå®¤ ¨§ ¯à®æ¥¤ãàë            }
     @TooManyProc:   MOV  AL, vstMAXLimitProc   {}
                     MOV  TaskError, AL         {}
                     JMP  @ErrExit              {}
     @LowMemAndFree: MOV  BX, SizeStack         {}
                     PUSH BX                    {}
                     CALL mFreeMem              {}
     @LowMem:        MOV  AL, vstMemoryLow      {}
                     MOV  TaskError, AL         {}
     @ErrExit:       XOR  AX, AX                {}
     @Exit:
    end;

    procedure HaltCurrentTask; assembler;
    { --- á�ïâ¨¥ â¥ªãé¥© §�¤�ç¨ --- }
    asm
        { 1) ��å®¦¤¥�¨¥ ¢ ®ç¥à¥¤¨ ¯à®æ¥áá®¢ á«¥¤ãîé¥£® ¯à®æ¥áá�;
          2) �¥à¥ª«îç¥�¨¥ �� ¥£® SS ¨ SP;
          3) �¥à¥ãáâ��®¢ª� ¢á¥å ¯¥à¥¥��ëå;
          4) ��¨çâ®¦¥�¨¥ áâ¥ª� ¯à¥¤ë¤ãé¥£® ¯à®æ¥áá�;
          5) �¤�«¥�¨¥ ¨§ ®ç¥à¥¤¨ ¯à®æ¥áá®¢ ®¯¨á�â¥«ï ¯à®æ¥áá�;
          6) �¤�«¥�¨¥ ¨§ ¯�ïâ¨ ®¯¨á�â¥«ï ¯à®æ¥áá�;
          7a) �á«¨ ¡ë« ��©¤¥� á«¥¤ãîé¨© ¯à®æ¥áá - â® ¢®ááâ��®¢«¥�¨¥
              ¥£® à¥£¨áâà®¢ ¨ RETF;
          7b) �á«¨ ¡®«ìè¥ ¯à®æ¥áá®¢ �¥â, â® ãáâ��®¢ª� SS:SP ®á�®¢�®©
              ¯à®£à�ë ¨ RETF ¢ �¥¥. }
       {--------------------------------------------------------------}
                     MOV  AX, SEG @Data         { ¯¥à¥ãáâ��®¢ª� á¥£¥�â� DS     }
                     MOV  ES, PCurTask.word[2]  { ¢ ES:DI ãª�§�â¥«ì �� â¥ªãé¨©  }
                     MOV  DI, PCurTask.word[0]  { ®¯¨á�â¥«ì                     }
                     XOR  AX, AX                { ®¡�ã«¥�¨¥ ¤®¯®«�¨â¥«ì�®£®     }
                     MOV  PDopPoint.word[0], AX { ãª�§�â¥«ï                     }
                     MOV  PDopPoint.word[2], AX {}
                     MOV  AX, ES                { AX:DI                         }
                     MOV  DX, HeadStack.word[2] { ¢ DX:BX §��ç¥�¨¥ ��ç�«� áâ¥ª� }
                     MOV  BX, HeadStack.word[0] { ¯à®æ¥áá®¢                     }
     @Loop:          CMP  DX, AX                { ¯à®¢¥àª� à�¢¥�áâ¢� ãª�§�â¥«¥© }
                     JNE  @NextProc             { AX:DI ¨ DX:BX                 }
                     CMP  BX, DI                { ¥á«¨ �¥ à�¢�ë, â® ¯®¨áª à�¢�ëå}
                     JNE  @NextProc             {}
                     JMP  @DelProcess           { ª ã¤�«¥�¨î ¯à®æ¥áá�           }
     @NextProc:      MOV  ES, DX                { áâà®¨ à¥£¨áâà®¢ãî ¯�àã       }
                     MOV  SI, BX                { ES:SI - ãª�§�â¥«ì             }
                     MOV  PDopPoint.word[0], BX { á®åà��ï¥ ãª�§�â¥«ì ��        }
                     MOV  PDopPoint.word[2], DX { ¯à¥¤ë¤ãé¨© í«¥¥�â ®¯¨á�â¥«ì  }
                     MOV  DX, ES:[SI+4]         { ¢ DX:BX ãª�§�â¥«ì �� á«¥¤ãîé¨©}
                     MOV  BX, ES:[SI+2]         { í«¥¥�â áâ¥ª� ®¯¨á�â¥«¥©      }
                     JMP  @Loop                 {}
     @DelProcess:    MOV  ES, AX                { ES:DI                         }
                     MOV  BX, ES:[DI+2]         { ¢ BX á¥é¥�¨¥ á«¥¤ãîé¥£®      }
                     MOV  PCurTask.word[0], BX  { í«¥¥�â�                      }
                     MOV  DX, ES:[DI+4]         { â®¦¥ á á¥£¥�â®              }
                     MOV  PCurTask.word[2], DX  {}
                     XOR  CX, CX                { ¯à®¢¥àï¥ PDopPoint �� Nil    }
                     CMP  CX, PDopPoint.word[0] {}
                     JNE  @NotNil               { ¥á«¨ �¥ Nil                   }
                     CMP  CX, PDopPoint.word[2] {}
                     JNE  @NotNil               {}
                     MOV  HeadStack.word[0], BX { ¯¥à¥áâ�¢«ï¥ ãª�§�â¥«ì ��     }
                     MOV  HeadStack.word[2], DX { ��ç�«® áâ¥ª�                  }
                     JMP  @FreeMem              {}
     @NotNil:        PUSH ES                    {}
                     PUSH DI                    {}
                     MOV  ES, PDopPoint.word[2] { ¢ ES:DI ãª�§�â¥«ì ��          }
                     MOV  DI, PDopPoint.word[0] { ¯à¥¤ë¤ãé¨© í«¥¥�â            }
                     MOV  ES:[DI+2], BX         { ¯¥à¥áâ�¢«ï¥ ãª�§�â¥«ì Next ã }
                     MOV  ES:[DI+4], DX         { ¯à¥¤ë¤ãé¥£® í«¥¥�â�          }
                     POP  DI                    { ¢ ES:DI ãª�§�â¥«ì �� ã¤�«ï¥ë©}
                     POP  ES                    { í«¥¥�â                       }
     @FreeMem:       CLI                        {}
                     MOV  SS, OriginalSS        { ¢®ááâ���¢«¨¢�¥ áâ¥ª          }
                     MOV  SP, OriginalSP        { ®á�®¢�®© ¯à®£à�ë            }
                     STI                        {}
                     MOV  DX, ES:[DI+12]        { ¢ DX:BX ãª�§�â¥«ì ��  áâ¥ª    }
                     MOV  BX, ES:[DI+10]        { ã¤�«ï¥®£® ¯à®æ¥áá�           }
                     MOV  CX, ES:[DI+14]        { ¢ CX à�§¥à áâ¥ª�             }
                     PUSH ES                    {}
                     PUSH DI
                     PUSH DX                    { £®â®¢¨ áâ¥ª ¨ ®á¢®¡®¦¤�¥    }
                     PUSH BX                    { ¯�ïâì áâ¥ª� ã¤�«ï¥®£®       }
                     PUSH CX                    { ¯à®æ¥áá�                      }
                     CALL mFreeMem              {}
                     POP  DI                    {}
                     POP  ES                    {}
                     MOV  CX, TYPE TTaskRec     { à�§¥à §�¯¨á¨ TTaskRec -> CX  }
                     PUSH ES                    { ã¤�«ï¥ ®¯¨á�â¥«ì ¯à®æ¥áá� ¨§ }
                     PUSH DI                    { ¯�ïâ¨                        }
                     PUSH CX                    {}
                     CALL mFreeMem              {}
                     XOR  AX, AX                { ®¡�ã«¨âì �®¥à â¥ãé¥£® ¯à®æ¥áá�}
                     MOV  CurTask, AX           {}
                     MOV  AX, CountTask         { ¤¥ªà¥¥�â CountTask           }
                     DEC  AX                    {}
                     MOV  CountTask, AX         {}
                     JZ   @Exit                 { ¯à®æ¥áá®¢ ¡®«ìè¥ �¥â          }
                     MOV  ES, PCurTask.word[2]  { PCurTask -> ES:DI             }
                     MOV  DI, PCurTask.word[0]  {}
                     MOV  BX, ES                {}
                     XOR  AX, AX                {}
                     CMP  AX, BX                { ¥á«¨ PCurTask �¥ à�¢¥�        }
                     JNE  @SetProcess           { Nil, â® ¯¥à¥ãáâ��®¢¨âì        }
                     CMP  AX, DI                { â¥ªãé¨© ¯à®æ¥áá               }
                     JNE  @SetProcess           {}
                     MOV  ES, HeadStack.word[2] { HeadStack -> ES:DI            }
                     MOV  DI, HeadStack.word[0] {}
                     MOV  PCurTask.word[2], ES  { ES:DI -> PCurTask             }
                     MOV  PCurTask.word[0], DI  {}
     @SetProcess:    MOV  AX, ES:[DI]           { NumProc -> AX                 }
                     MOV  CurTask, AX           {}
                     CLI                        {}
                     MOV  SS, ES:[DI+8]         { ¯¥à¥ãáâ��®¢ª� áâ¥ª�           }
                     MOV  SP, ES:[DI+6]         {}
                     STI                        {}
                     POP  BP                    { ¢®ááâ��®¢«¥�¨¥ à¥£¨áâà®¢      }
                     POP  ES                    { ¯à®æ¥áá�                      }
                     POP  DS                    {}
     @Exit:
    end;

    procedure HaltAllTasks; assembler;
    { --- á�ïâ¨¥ ¢á¥å §�¤�ç --- }
    asm
        { 1) �¡�ã«¥�¨¥ ¢á¥å ¯¥à¥¥��ëå;
          2) �¤�«¥�¨¥ ®ç¥à¥¤¨ ¯à®æ¥áá®¢ á® áâ¥ª�¨;
          3) �áâ��®¢ª� SS:SP ®á�®¢�®© ¯à®£à�ë ¨ RETF ¢ �¥¥. }
                     MOV  AX, SEG @Data         { ¢®ááâ���¢«¨¢�¥ á¥£¥�â DS    }
                     MOV  DS, AX                {}
                     XOR  AX, AX                { PCurTask=Nil                  }
                     MOV  PCurTask.word[0], AX  {}
                     MOV  PCurTask.word[2], AX  {}
                     CLI                        {}
                     MOV  SS, OriginalSS        { ¢®ááâ���¢«¨¢�¥ áâ¥ª ¯à®£à�ë}
                     MOV  SP, OriginalSP        {}
                     STI                        {}
     @Loop:          XOR  AX, AX                {}
                     CMP  AX, CountTask         { á®âà¨ ¥áâì «¨ ¯à®æ¥ááë      }
                     JE   @StackEmpty           { ¥á«¨ �¥â ¢ëå®¤                }
                     MOV  ES, HeadStack.word[2] { ¢ ES:DI ãª�§�â¥«ì �� ¯¥à¢ë©   }
                     MOV  DI, HeadStack.word[0] { í«¥¥�â ®ç¥à¥¤¨ ¯à®æ¥áá®¢     }
                     MOV  DX, ES:[DI+4]         { DX:BX ãª�§�â¥«ì �� á«¥¤ãîé¨©  }
                     MOV  BX, ES:[DI+2]         { í«¥¥�â áâ¥ª� ¨«¨ Nil         }
                     MOV  HeadStack.word[2], DX { HeadStack = DX:BX             }
                     MOV  HeadStack.word[0], BX {}
                     MOV  AX, ES:[DI+12]        { ¢ AX:CX ãª�§�â¥«ì �� áâ¥ª     }
                     MOV  CX, ES:[DI+10]        { ¯à®æ¥áá�                      }
                     PUSH ES                    { £®â®¢¨ áâ¥ª ¤«ï ¢ë§®¢� ¯à®æ¥-}
                     PUSH DI                    { ¤ãàë ®ç¨áâª¨ ¯�ïâ¨           }
                     PUSH AX                    { AX:CX - ãª�§�â¥«ì �� áâ¥ª     }
                     PUSH CX                    { ¯à®æ¥áá�                      }
                     MOV  AX, ES:[DI+14]        { ¢ AX à�§¥à áâ¥ª�             }
                     PUSH AX                    {}
                     CALL mFreeMem              { ã�¨çâ®¦�¥ áâ¥ª ¯à®æ¥áá�      }
                     MOV  AX, TYPE TTaskRec     { ¢ AX à�§¥à ®¯¨á�â¥«ï ¯à®æ¥áá�}
                     PUSH AX                    {}
                     CALL mFreeMem              { ã�¨çâ®¦�¥ ®¯¨á�â¥«ì ¯à®æ¥áá� }
                     MOV  AX, CountTask         { ¤¥ªà¥¥�â¨àã¥ CountTask      }
                     DEC  AX                    {}
                     MOV  CountTask, AX         {}
                     JMP  @Loop                 { ã�¨çâ®¦�âì á«¥¤ãîé¨© ¯à®æ¥áá  }
     @StackEmpty:    MOV  CurTask, AX           { CurTask=0                     }
    end;

    {----------------------------------------------------------------}
    end.

[Back to MEMORY SWAG index] [Back to Main SWAG index] [Original]