Changeset 14 for trunk/Z80/Z80.pas


Ignore:
Timestamp:
Apr 21, 2026, 3:52:53 PM (6 days ago)
Author:
chronos
Message:
  • Modified: Pausing CPU thread execution with event object instead of freeing thread object.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Z80/Z80.pas

    r13 r14  
    44
    55uses
    6   Classes, SysUtils, MemoryTypes, Base, Z80Instructions, Generics.Collections,
    7   Generics.Defaults;
     6  Classes, SysUtils, SyncObjs, MemoryTypes, Base, Z80Instructions,
     7  Generics.Collections, Generics.Defaults;
    88
    99type
     
    5858    InstructionAddress: Word;
    5959    MessageText: string;
     60    FEvent: TEvent;
     61    FPaused: Boolean;
    6062    procedure Error(Message: string);
    6163    function GetCarry: Boolean;
     
    6567    procedure SetCarry(AValue: Boolean);
    6668    procedure SetParityOverflow(AValue: Boolean);
     69    procedure SetPaused(AValue: Boolean);
    6770    procedure SetSignNegative(AValue: Boolean);
    6871    procedure SetZero(AValue: Boolean);
     
    837840    property SignNegative: Boolean read GetSignNegative write SetSignNegative;
    838841    property Thread: TCpuThread read FThread;
     842    property Paused: Boolean read FPaused write SetPaused;
    839843    property Running: Boolean read FRunning write SetRunning;
    840844    property OnRead: TReadEvent read FOnRead write FOnRead;
     
    856860begin
    857861  while not Terminated do begin
     862    Cpu.FEvent.WaitFor(INFINITE);
    858863    Cpu.Step;
    859864  end;
     
    900905end;
    901906
     907procedure TCpuZ80.SetPaused(AValue: Boolean);
     908begin
     909  if not Running then Exit;
     910
     911  if FPaused = AValue then Exit;
     912  if FPaused then begin
     913    FPaused := False;
     914    FEvent.SetEvent;
     915  end;
     916  FPaused := AValue;
     917  if FPaused then begin
     918    FPaused := True;
     919    FEvent.ResetEvent;
     920  end;
     921end;
     922
    902923procedure TCpuZ80.SetSignNegative(AValue: Boolean);
    903924begin
     
    912933procedure TCpuZ80.SetRunning(AValue: Boolean);
    913934begin
     935  if FRunning and FPaused then Paused := False;
     936
    914937  if FRunning = AValue then Exit;
    915938  if FRunning then begin
    916939    FThread.Terminate;
     940    if FPaused then Paused := False;
    917941    FThread.WaitFor;
    918942    FreeAndNil(FThread);
     
    54975521var
    54985522  Opcode: Byte;
    5499   Proc: TEvent;
     5523  Proc: TBaseEvent;
    55005524begin
    55015525  InstructionAddress := PC;
     
    55375561begin
    55385562  PC := 0;
     5563  SP := 0;
     5564  IX := 0;
     5565  IY := 0;
    55395566  AF.Value := 0;
    55405567  BC.Value := 0;
    55415568  DE.Value := 0;
    55425569  HL.Value := 0;
    5543   SP := 0;
    55445570  InterruptEnabled := True;
    55455571  InterruptMode := 0;
     
    55495575constructor TCpuZ80.Create;
    55505576begin
     5577  FRunning := False;
     5578  FPaused := False;
     5579  FEvent := TEvent.Create(nil, True, True, '');
    55515580  InitInstructions;
    55525581  Reset;
     
    55565585begin
    55575586  Running := False;
     5587  FreeAndNil(FEvent);
    55585588  inherited;
    55595589end;
Note: See TracChangeset for help on using the changeset viewer.