Changeset 5 for trunk/CpuZ80.pas


Ignore:
Timestamp:
Apr 18, 2026, 7:24:02 PM (9 days ago)
Author:
chronos
Message:
  • Added: Some I/O ports handling.
  • Added: Messages form for capturing error messages.
  • Added: Go to address action.
  • Added: Allow to view all used memory areas in Memory window.
  • Added: Allow to reset CPU execution.
  • Modified: Improved memory mapping for MZ-700 and MZ-800 modes.
  • Fixed: Focusing currently executed instruction position.
  • Fixed: Wrong order or 8-bit registers in 16-bit pair.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CpuZ80.pas

    r2 r5  
    44
    55uses
    6   Classes, SysUtils, Memory;
     6  Classes, SysUtils, Memory, Base;
    77
    88type
    9   TReadEvent = function (Address: Word): Byte of object;
    10   TWriteEvent = procedure (Address: Word; Data: Byte) of object;
    11 
    129  TInstruction = (inNop = 0, inLdBcNn = $1, inLdBcIndirectA = $2,
    1310    inIncBc = $3, inIncB = $4, inDecB = $5, inLdBN = $6, inRlca = $7,
     
    3835  TRegBC = record
    3936    case Byte of
    40       0: (B, C: Byte);
     37      0: (C, B: Byte);
    4138      1: (Value: Word);
    4239  end;
     
    4441  TRegDE = record
    4542    case Byte of
    46       0: (D, E: Byte);
     43      0: (E, D: Byte);
    4744      1: (Value: Word);
    4845  end;
     
    5047  TRegHL = record
    5148    case Byte of
    52       0: (H, L: Byte);
     49      0: (L, H: Byte);
    5350      1: (Value: Word);
    5451  end;
     
    6158  private
    6259    FOnInput: TReadEvent;
     60    FOnMessage: TMessageEvent;
    6361    FOnOutput: TWriteEvent;
    6462    FOnRead: TReadEvent;
     
    6765    FThread: TCpuThread;
    6866    Instruction: TInstruction;
     67    MessageText: string;
    6968    procedure SetRunning(AValue: Boolean);
    7069    function DoRead(Address: Word): Byte;
     
    7271    function DoInput(Address: Word): Byte;
    7372    procedure DoOutput(Address: Word; Data: Byte);
     73    procedure DoMessage(Text: string);
     74    procedure DoMessageSync;
    7475    function ReadByte: Byte;
    7576    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;
    8284  public
    8385    A: Byte;
     
    104106    property OnInput: TReadEvent read FOnInput write FOnInput;
    105107    property OnOutput: TWriteEvent read FOnOutput write FOnOutput;
    106   end;
     108    property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
     109  end;
     110
    107111
    108112implementation
     
    164168end;
    165169
     170procedure TCpuZ80.DoMessage(Text: string);
     171begin
     172  MessageText := Text;
     173  FThread.Synchronize(DoMessageSync);
     174  MessageText := '';
     175end;
     176
     177procedure TCpuZ80.DoMessageSync;
     178begin
     179  if Assigned(FOnMessage) then FOnMessage(MessageText);
     180end;
     181
    166182function TCpuZ80.ReadByte: Byte;
    167183begin
     
    206222procedure TCpuZ80.Jr(Condition: Boolean);
    207223var
    208   Temp: Byte;
    209 begin
    210   Temp := ReadByte;
     224  Temp: ShortInt;
     225begin
     226  Temp := ShortInt(ReadByte);
    211227  if Condition then
    212     PC := PC + ShortInt(Temp);
     228    PC := PC + Temp;
    213229end;
    214230
     
    219235  Temp := ReadWord;
    220236  if Condition then PC := Temp;
     237end;
     238
     239procedure TCpuZ80.Halt;
     240begin
     241  FThread.Terminate;
    221242end;
    222243
     
    293314    inRst28: Call($28);
    294315    inRst30: Call($30);
    295     inRst38: Call($08);
     316    inRst38: Call($38);
    296317    inDi: InterruptEnabled := False;
    297318    inEi: InterruptEnabled := True;
     
    315336    inJrNzD: Jr(not Zero);
    316337    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;
    318343  end;
    319344  Ticks := Cardinal(Ticks + 1);
Note: See TracChangeset for help on using the changeset viewer.