Changeset 3 for branches/Z80/UZ80Compiler.pas
- Timestamp:
- Nov 6, 2009, 2:10:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Z80/UZ80Compiler.pas
r2 r3 17 17 Mask: TDynamicNumber; 18 18 property Size: Integer read GetSize write SetSize; 19 constructor Create; 20 destructor Destroy; override; 19 21 end; 20 22 … … 43 45 destructor Destroy; override; 44 46 end; 47 48 { TZ80Compiler } 45 49 46 50 TZ80Compiler = class … … 50 54 MachineCode: TMemoryStream; 51 55 procedure InitOpcodes; 56 function FindOpcodeByName(Name: string): TOpcode; 57 function ParseLine(var Text: string; Separator: string = ' '): string; 52 58 public 53 59 procedure Load(StringList: TStringList); … … 101 107 end; 102 108 109 function TZ80Compiler.FindOpcodeByName(Name: string): TOpcode; 110 var 111 I: Integer; 112 begin 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; 117 end; 118 119 function TZ80Compiler.ParseLine(var Text: string; Separator: string = ' '): string; 120 begin 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)); 125 end; 126 103 127 procedure TZ80Compiler.Load(StringList: TStringList); 104 128 var 105 129 I: Integer; 106 begin 130 Line: string; 131 InstructionName: string; 132 Instruction: TOpcode; 133 Parameter: string; 134 begin 107 135 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; 109 149 end; 110 150 end; … … 145 185 end; 146 186 187 constructor TMaskedValue.Create; 188 begin 189 Mask := TDynamicNumber.Create; 190 Value := TDynamicNumber.Create; 191 end; 192 193 destructor TMaskedValue.Destroy; 194 begin 195 Mask.Destroy; 196 Value.Destroy; 197 inherited Destroy; 198 end; 199 147 200 { TOpcode } 148 201 … … 150 203 begin 151 204 MaskedValue := TMaskedValue.Create; 205 Operands := TList.Create; 152 206 end; 153 207
Note:
See TracChangeset
for help on using the changeset viewer.