Ignore:
Timestamp:
Apr 19, 2026, 12:16:19 PM (8 days ago)
Author:
chronos
Message:
  • Modified: Updated instruction info with all instructions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Z80/InstructionSetGen.pas

    r6 r7  
    44
    55uses
    6   Classes, SysUtils;
     6  Classes, SysUtils, Common, Z80InstructionInfo, TypInfo;
    77
    88type
     
    2828  InitInstructions: TStringList;
    2929  Combined: TStringList;
     30  Info: TStringList;
    3031  Cell: string;
    3132  Source: string;
     
    3435  Bytes: string;
    3536  Cycles: string;
     37  CyclesFalseCond: string;
    3638  FlagC: string;
    3739  FlagN: string;
     
    4345  Ident: string;
    4446  Prefix: string;
     47  NameOnly: string;
     48  Params: string;
     49  ParamsPart: string;
     50  InfoParams: string;
     51  ParamType: TParamType;
     52  NewCycles: string;
    4553const
    4654  CellStart = '<td  >';
     
    6876  InitInstructions := TStringList.Create;
    6977  InitInstructions.Add('procedure TCpuZ80.InitInstructions;');
    70   InitInstructions.Add('begin;');
     78  InitInstructions.Add('begin');
     79  Info := TStringList.Create;
     80  Info.Add('constructor TInstructionSet.Create;');
     81  Info.Add('begin');
    7182  repeat
    7283    Cell := GetBlock(Source, CellStart, CellEnd);
     
    7485      Name := GetBlock(Cell, CodeStart, CodeEnd).Trim;
    7586      if Name = '' then Continue;
     87      Name := StringReplace(Name, '<var>', '', [rfReplaceAll]);
     88      Name := StringReplace(Name, '</var>', '', [rfReplaceAll]);
     89      Params := Name;
     90      NameOnly := GetStringPart(Params, ' ');
     91
    7692      Ident := StringReplace(Name.ToUpper, ' ', '_', [rfReplaceAll]);
    7793      Ident := StringReplace(Ident, ',', '_', [rfReplaceAll]);
    78       Ident := StringReplace(Ident, '<VAR>', '', [rfReplaceAll]);
    79       Ident := StringReplace(Ident, '</VAR>', '', [rfReplaceAll]);
    8094      Ident := StringReplace(Ident, '''', '_Pair', [rfReplaceAll]);
    8195      Ident := StringReplace(Ident, '+', '_Plus_', [rfReplaceAll]);
     
    89103        Opcode := Copy(Opcode, 3, MaxInt).Trim;
    90104        if Prefix = 'CB' then Opcode := '1' + Opcode
    91         else if Prefix = 'ED' then Opcode := '2' + Opcode
    92         else if Prefix = 'DD' then Opcode := '3' + Opcode
     105        else if Prefix = 'DD' then Opcode := '2' + Opcode
     106        else if Prefix = 'ED' then Opcode := '3' + Opcode
    93107        else if Prefix = 'FD' then Opcode := '4' + Opcode;
    94108      end;
    95109      Bytes := GetBlock(Cell, DataStart, DataEnd).Trim;
    96110      Cycles := GetBlock(Cell, DataStart, DataEnd).Trim;
     111      if Pos('/', Cycles) >= 1 then begin
     112        NewCycles := GetStringPart(Cycles, '/');
     113        CyclesFalseCond := Cycles;
     114        Cycles := NewCycles;
     115      end else CyclesFalseCond := '0';
     116
    97117      FlagC := GetBlock(Cell, DataStart, DataEnd).Trim;
    98118      FlagN := GetBlock(Cell, DataStart, DataEnd).Trim;
     
    102122      FlagS := GetBlock(Cell, DataStart, DataEnd).Trim;
    103123      Description := GetBlock(Cell, DataStart, DataEnd).Trim;
     124      Description := StringReplace(Description, '<var>', '', [rfReplaceAll]);
     125      Description := StringReplace(Description, '</var>', '', [rfReplaceAll]);
     126
     127      InfoParams := '';
     128      Params := Params.ToUpper;
     129      while Params <> '' do begin
     130        ParamsPart := GetStringPart(Params, ',');
     131        ParamType := StrToParamType(ParamsPart);
     132        if ParamType <> ptNone then
     133          InfoParams := InfoParams + ', ' + GetEnumName(TypeInfo(TParamType), Integer(ParamType));
     134      end;
     135      if Copy(InfoParams, 1, 2) = ', ' then Delete(InfoParams, 1, 2);
     136
     137      Info.Add('  AddNew(in_' + Ident + ', ''' + NameOnly.ToUpper + ''', [' + InfoParams + '], ''' +
     138        StringReplace(Description, '''', '''''', [rfReplaceAll]) + ''', ' +
     139        Cycles + ', ' + CyclesFalseCond + ');');
    104140      Instruction.Add('    in_' + Ident + ' = $' + Opcode + ',');
    105141      InitInstructions.Add('  Instructions[in_' + Ident + '] := ' + Ident + ';');
    106       Head.Add('  procedure ' + Ident + ';');
     142      Head.Add('    procedure ' + Ident + ';');
    107143      Body.Add('procedure TCpuZ80.' + Ident + ';');
    108144      Body.Add('begin');
     145      Body.Add('  NotImplemented;');
    109146      Body.Add('end;');
    110147      Body.Add('');
     
    113150  Instruction.Add('  );');
    114151  Head.Add('end;');
    115   InitInstructions.Add('end;')
    116   ;
     152  InitInstructions.Add('end;');
     153  Info.Add('end;');
     154
    117155  ForceDirectories(Generated);
    118156  Instruction.SaveToFile(Generated + DirectorySeparator + 'Instruction.pas');
    119157  Head.SaveToFile(Generated + DirectorySeparator + 'Head.pas');
    120158  Body.SaveToFile(Generated + DirectorySeparator + 'Body.pas');
    121   InitInstructions.SaveToFile(Generated + DirectorySeparator + 'Body.pas');
     159  InitInstructions.SaveToFile(Generated + DirectorySeparator + 'InitInstructions.pas');
     160  Info.SaveToFile(Generated + DirectorySeparator + 'Info.pas');
    122161
    123162  Combined.Add(Instruction.Text);
     
    133172  Body.Free;
    134173  InitInstructions.Free;
     174  Info.Free;
    135175  Lines.Free;
    136176end;
Note: See TracChangeset for help on using the changeset viewer.