Changeset 12 for trunk/Z80/Z80.pas


Ignore:
Timestamp:
Apr 21, 2026, 11:04:26 AM (6 days ago)
Author:
chronos
Message:
  • Added: Implemented breakpoints and run to cursor action.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Z80/Z80.pas

    r11 r12  
    44
    55uses
    6   Classes, SysUtils, Memory, Base, Z80Instructions;
     6  Classes, SysUtils, Memory, Base, Z80Instructions, Generics.Collections,
     7  Generics.Defaults;
    78
    89type
     
    4142
    4243  TDebugMode = (dmNone, dmStepIn, dmStepOut, dmStepOver, dmStopAddress);
     44
     45  { TBreakPoints }
     46
     47  TBreakPoints = class(TList<Word>)
     48  private
     49    function Comparer(constref Left, Right: Word): Integer;
     50  public
     51    function Contains(Address: Word): Boolean;
     52    procedure AddNew(Address: Word);
     53  end;
    4354
    4455  { TCpuZ80 }
     
    821832    InterruptEnabled: Boolean;
    822833    InterruptMode: Byte;
     834    BreakPoints: TBreakPoints;
    823835    DebugMode: TDebugMode;
    824836    DebugStopAddress: Word;
     
    851863  while not Terminated do begin
    852864    Cpu.Step;
    853     if Cpu.DebugMode <> dmNone then begin
    854       if Cpu.DebugMode = dmStepIn then begin
    855         Cpu.DebugMode := dmNone;
    856         Terminate;
    857       end;
    858       if (Cpu.DebugMode = dmStopAddress) and (Cpu.DebugStopAddress = Cpu.PC) then begin
    859         Cpu.DebugMode := dmNone;
    860         Terminate;
    861       end;
    862       if Cpu.DebugMode = dmStepOver then begin
    863         Cpu.DebugMode := dmNone;
    864         Terminate;
    865       end;
    866     end;
    867865  end;
    868866  Cpu.FRunning := False;
     867end;
     868
     869{ TBreakPoints }
     870
     871function TBreakPoints.Comparer(constref Left, Right: Word): Integer;
     872begin
     873  if Left > Right then Result := 1
     874  else if Left < Right then Result := -1
     875  else Result := 0;
     876end;
     877
     878function TBreakPoints.Contains(Address: Word): Boolean;
     879var
     880  Index: SizeInt;
     881begin
     882  if (Count > 0) and BinarySearch(Address, Index, TComparer<Word>.Construct(Comparer)) then begin
     883    Result := True;
     884  end else Result := False;
     885end;
     886
     887procedure TBreakPoints.AddNew(Address: Word);
     888begin
     889  Add(Address);
     890  Sort;
    869891end;
    870892
     
    55335555  end;
    55345556  Ticks := Cardinal(Ticks + 1);
     5557
     5558  // Debugging
     5559  if DebugMode <> dmNone then begin
     5560    if DebugMode = dmStepIn then begin
     5561      DebugMode := dmNone;
     5562      FThread.Terminate;
     5563    end;
     5564    if (DebugMode = dmStopAddress) and (DebugStopAddress = PC) then begin
     5565      DebugMode := dmNone;
     5566      FThread.Terminate;
     5567    end;
     5568    if DebugMode = dmStepOver then begin
     5569      DebugMode := dmNone;
     5570      FThread.Terminate;
     5571    end;
     5572  end;
     5573  if BreakPoints.Contains(PC) then begin
     5574    DebugMode := dmNone;
     5575    FThread.Terminate;
     5576  end;
    55355577end;
    55365578
     
    55505592constructor TCpuZ80.Create;
    55515593begin
     5594  BreakPoints := TBreakPoints.Create;
    55525595  InitInstructions;
    55535596  Reset;
     
    55575600begin
    55585601  Running := False;
     5602  FreeAndNil(BreakPoints);
    55595603  inherited;
    55605604end;
Note: See TracChangeset for help on using the changeset viewer.