Ignore:
Timestamp:
Nov 6, 2009, 2:10:40 PM (15 years ago)
Author:
george
Message:
  • Přidáno: Vývojová větev Void.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Z80/UZ80Compiler.pas

    r2 r3  
    1717    Mask: TDynamicNumber;
    1818    property Size: Integer read GetSize write SetSize;
     19    constructor Create;
     20    destructor Destroy; override;
    1921  end;
    2022
     
    4345    destructor Destroy; override;
    4446  end;
     47
     48  { TZ80Compiler }
    4549
    4650  TZ80Compiler = class
     
    5054    MachineCode: TMemoryStream;
    5155    procedure InitOpcodes;
     56    function FindOpcodeByName(Name: string): TOpcode;
     57    function ParseLine(var Text: string; Separator: string = ' '): string;
    5258  public
    5359    procedure Load(StringList: TStringList);
     
    101107end;
    102108
     109function TZ80Compiler.FindOpcodeByName(Name: string): TOpcode;
     110var
     111  I: Integer;
     112begin
     113  I := 0;
     114  while (I < Opcodes.Count) and (TOpcode(Opcodes[I]).Name <> Name) do Inc(I);
     115  if I < Opcodes.Count then Result := Opcodes[I]
     116    else Result := nil;
     117end;
     118
     119function TZ80Compiler.ParseLine(var Text: string; Separator: string = ' '): string;
     120begin
     121  Text := Trim(Text);
     122  Result := Copy(Text, 1, Pos(Separator, Text) - 1);
     123  if Result <> '' then
     124    Delete(Text, 1, Length(Result) + Length(Separator));
     125end;
     126
    103127procedure TZ80Compiler.Load(StringList: TStringList);
    104128var
    105129  I: Integer;
    106 begin
     130  Line: string;
     131  InstructionName: string;
     132  Instruction: TOpcode;
     133  Parameter: string;
     134  begin
    107135  for I := 0 to StringList.Count - 1 do begin
    108 
     136    Line := Trim(StringList[I]);
     137    Line := StringReplace(Line, #9, ' ', [rfReplaceAll]);
     138    if Length(Line) > 0 then begin
     139      if Line[1] = ';' then Continue; // Skip commented lines
     140      InstructionName := ParseLine(Line);
     141      Instruction := FindOpcodeByName(InstructionName);
     142      if Assigned(Instruction) then begin
     143        WriteLn(InstructionName);
     144        if Pos(',', Line) > 0 then Parameter := ParseLine(Line, ',')
     145          else Parameter := Line;
     146        WriteLn(Parameter);
     147      end else WriteLn('Unknown instruction name "' + InstructionName + '"');
     148    end;
    109149  end;
    110150end;
     
    145185end;
    146186
     187constructor TMaskedValue.Create;
     188begin
     189  Mask := TDynamicNumber.Create;
     190  Value := TDynamicNumber.Create;
     191end;
     192
     193destructor TMaskedValue.Destroy;
     194begin
     195  Mask.Destroy;
     196  Value.Destroy;
     197  inherited Destroy;
     198end;
     199
    147200{ TOpcode }
    148201
     
    150203begin
    151204  MaskedValue := TMaskedValue.Create;
     205  Operands := TList.Create;
    152206end;
    153207
Note: See TracChangeset for help on using the changeset viewer.