Changeset 5 for trunk/CpuZ80.pas
- Timestamp:
- Apr 18, 2026, 7:24:02 PM (9 days ago)
- File:
-
- 1 edited
-
trunk/CpuZ80.pas (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CpuZ80.pas
r2 r5 4 4 5 5 uses 6 Classes, SysUtils, Memory ;6 Classes, SysUtils, Memory, Base; 7 7 8 8 type 9 TReadEvent = function (Address: Word): Byte of object;10 TWriteEvent = procedure (Address: Word; Data: Byte) of object;11 12 9 TInstruction = (inNop = 0, inLdBcNn = $1, inLdBcIndirectA = $2, 13 10 inIncBc = $3, inIncB = $4, inDecB = $5, inLdBN = $6, inRlca = $7, … … 38 35 TRegBC = record 39 36 case Byte of 40 0: ( B, C: Byte);37 0: (C, B: Byte); 41 38 1: (Value: Word); 42 39 end; … … 44 41 TRegDE = record 45 42 case Byte of 46 0: ( D, E: Byte);43 0: (E, D: Byte); 47 44 1: (Value: Word); 48 45 end; … … 50 47 TRegHL = record 51 48 case Byte of 52 0: ( H, L: Byte);49 0: (L, H: Byte); 53 50 1: (Value: Word); 54 51 end; … … 61 58 private 62 59 FOnInput: TReadEvent; 60 FOnMessage: TMessageEvent; 63 61 FOnOutput: TWriteEvent; 64 62 FOnRead: TReadEvent; … … 67 65 FThread: TCpuThread; 68 66 Instruction: TInstruction; 67 MessageText: string; 69 68 procedure SetRunning(AValue: Boolean); 70 69 function DoRead(Address: Word): Byte; … … 72 71 function DoInput(Address: Word): Byte; 73 72 procedure DoOutput(Address: Word; Data: Byte); 73 procedure DoMessage(Text: string); 74 procedure DoMessageSync; 74 75 function ReadByte: Byte; 75 76 function ReadWord: Word; 76 procedure PushWord(Data: Word); inline; 77 function PopWord: Word; inline; 78 procedure Call(Address: Word); inline; 79 procedure Cp(Data: Byte); inline; 80 procedure Jr(Condition: Boolean); inline; 81 procedure Jp(Condition: Boolean); inline; 77 procedure PushWord(Data: Word); 78 function PopWord: Word; 79 procedure Call(Address: Word); 80 procedure Cp(Data: Byte); 81 procedure Jr(Condition: Boolean); 82 procedure Jp(Condition: Boolean); 83 procedure Halt; 82 84 public 83 85 A: Byte; … … 104 106 property OnInput: TReadEvent read FOnInput write FOnInput; 105 107 property OnOutput: TWriteEvent read FOnOutput write FOnOutput; 106 end; 108 property OnMessage: TMessageEvent read FOnMessage write FOnMessage; 109 end; 110 107 111 108 112 implementation … … 164 168 end; 165 169 170 procedure TCpuZ80.DoMessage(Text: string); 171 begin 172 MessageText := Text; 173 FThread.Synchronize(DoMessageSync); 174 MessageText := ''; 175 end; 176 177 procedure TCpuZ80.DoMessageSync; 178 begin 179 if Assigned(FOnMessage) then FOnMessage(MessageText); 180 end; 181 166 182 function TCpuZ80.ReadByte: Byte; 167 183 begin … … 206 222 procedure TCpuZ80.Jr(Condition: Boolean); 207 223 var 208 Temp: Byte;209 begin 210 Temp := ReadByte;224 Temp: ShortInt; 225 begin 226 Temp := ShortInt(ReadByte); 211 227 if Condition then 212 PC := PC + ShortInt(Temp);228 PC := PC + Temp; 213 229 end; 214 230 … … 219 235 Temp := ReadWord; 220 236 if Condition then PC := Temp; 237 end; 238 239 procedure TCpuZ80.Halt; 240 begin 241 FThread.Terminate; 221 242 end; 222 243 … … 293 314 inRst28: Call($28); 294 315 inRst30: Call($30); 295 inRst38: Call($ 08);316 inRst38: Call($38); 296 317 inDi: InterruptEnabled := False; 297 318 inEi: InterruptEnabled := True; … … 315 336 inJrNzD: Jr(not Zero); 316 337 inJrNcD: Jr(not Carry); 317 else raise Exception.Create('Unsupported instruction ' + IntToHex(Word(Instruction), 4)); 338 else begin 339 Dec(PC); 340 DoMessage('Unsupported instruction ' + IntToHex(Word(Instruction), 4) + ' on address ' + IntToHex(Word(PC), 4)); 341 Halt; 342 end; 318 343 end; 319 344 Ticks := Cardinal(Ticks + 1);
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)