[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]