Changeset 13 for trunk/Z80/Z80.pas
- Timestamp:
- Apr 21, 2026, 2:55:51 PM (6 days ago)
- File:
-
- 1 edited
-
trunk/Z80/Z80.pas (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Z80/Z80.pas
r12 r13 4 4 5 5 uses 6 Classes, SysUtils, Memory , Base, Z80Instructions, Generics.Collections,6 Classes, SysUtils, MemoryTypes, Base, Z80Instructions, Generics.Collections, 7 7 Generics.Defaults; 8 8 … … 41 41 end; 42 42 43 TDebugMode = (dmNone, dmStepIn, dmStepOut, dmStepOver, dmStopAddress);44 45 { TBreakPoints }46 47 TBreakPoints = class(TList<Word>)48 private49 function Comparer(constref Left, Right: Word): Integer;50 public51 function Contains(Address: Word): Boolean;52 procedure AddNew(Address: Word);53 end;54 55 43 { TCpuZ80 } 56 44 57 45 TCpuZ80 = class 58 46 private 47 FOnCall: TAddressEvent; 59 48 FOnInput: TReadEvent; 60 49 FOnMessage: TMessageEvent; 61 50 FOnOutput: TWriteEvent; 62 51 FOnRead: TReadEvent; 52 FOnReturn: TBaseEvent; 53 FOnStep: TBaseEvent; 63 54 FOnWrite: TWriteEvent; 64 55 FRunning: Boolean; … … 85 76 procedure DoMessage(Text: string); 86 77 procedure DoMessageSync; 78 procedure DoOnCall(Address: Word); 79 procedure DoOnReturn; 80 procedure DoOnStep; 87 81 function ReadByte: Byte; 88 82 function ReadWord: Word; … … 832 826 InterruptEnabled: Boolean; 833 827 InterruptMode: Byte; 834 BreakPoints: TBreakPoints;835 DebugMode: TDebugMode;836 DebugStopAddress: Word;837 828 Instructions: TInstructionMethods; 838 829 procedure Step; … … 852 843 property OnOutput: TWriteEvent read FOnOutput write FOnOutput; 853 844 property OnMessage: TMessageEvent read FOnMessage write FOnMessage; 845 property OnCall: TAddressEvent read FOnCall write FOnCall; 846 property OnReturn: TBaseEvent read FOnReturn write FOnReturn; 847 property OnStep: TBaseEvent read FOnStep write FOnStep; 854 848 end; 855 849 … … 865 859 end; 866 860 Cpu.FRunning := False; 867 end;868 869 { TBreakPoints }870 871 function TBreakPoints.Comparer(constref Left, Right: Word): Integer;872 begin873 if Left > Right then Result := 1874 else if Left < Right then Result := -1875 else Result := 0;876 end;877 878 function TBreakPoints.Contains(Address: Word): Boolean;879 var880 Index: SizeInt;881 begin882 if (Count > 0) and BinarySearch(Address, Index, TComparer<Word>.Construct(Comparer)) then begin883 Result := True;884 end else Result := False;885 end;886 887 procedure TBreakPoints.AddNew(Address: Word);888 begin889 Add(Address);890 Sort;891 861 end; 892 862 … … 992 962 begin 993 963 MessageText := Text; 994 FThread.Synchronize(DoMessageSync);964 DoMessageSync; 995 965 MessageText := ''; 996 966 end; … … 999 969 begin 1000 970 if Assigned(FOnMessage) then FOnMessage(MessageText); 971 end; 972 973 procedure TCpuZ80.DoOnCall(Address: Word); 974 begin 975 if Assigned(FOnCall) then FOnCall(Address); 976 end; 977 978 procedure TCpuZ80.DoOnReturn; 979 begin 980 if Assigned(FOnReturn) then FOnReturn; 981 end; 982 983 procedure TCpuZ80.DoOnStep; 984 begin 985 if Assigned(FOnStep) then FOnStep; 1001 986 end; 1002 987 … … 1028 1013 procedure TCpuZ80.Call(Address: Word); 1029 1014 begin 1030 if DebugMode = dmStepOver then begin 1031 DebugStopAddress := PC; 1032 DebugMode := dmStopAddress; 1033 end; 1015 DoOnCall(Address); 1034 1016 PushWord(PC); 1035 1017 PC := Address; … … 1038 1020 procedure TCpuZ80.CallCond(Address: Word; Condition: Boolean); 1039 1021 begin 1040 if DebugMode = dmStepOver then begin 1041 DebugStopAddress := PC; 1042 DebugMode := dmStopAddress; 1043 end; 1022 DoOnCall(Address); 1044 1023 if Condition then begin 1045 1024 PushWord(PC); … … 1077 1056 if Condition then begin 1078 1057 PC := PopWord; 1079 if DebugMode = dmStepOut then begin 1080 FThread.Terminate; 1081 DebugMode := dmNone; 1082 end; 1058 DoOnReturn; 1083 1059 end; 1084 1060 end; … … 5555 5531 end; 5556 5532 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; 5533 DoOnStep; 5577 5534 end; 5578 5535 … … 5592 5549 constructor TCpuZ80.Create; 5593 5550 begin 5594 BreakPoints := TBreakPoints.Create;5595 5551 InitInstructions; 5596 5552 Reset; … … 5600 5556 begin 5601 5557 Running := False; 5602 FreeAndNil(BreakPoints);5603 5558 inherited; 5604 5559 end;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/mzxemu/chrome/site/your_project_logo.png)