Changeset 112 for trunk/Target
- Timestamp:
- May 17, 2019, 10:06:59 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetInterpretter.pas
r96 r112 6 6 7 7 uses 8 Classes, SysUtils, Dialogs, Forms, UTarget, UBFTarget ;8 Classes, SysUtils, Dialogs, Forms, UTarget, UBFTarget, Math; 9 9 10 10 type … … 55 55 Memory: array of Integer; 56 56 MemoryPosition: Integer; 57 MemoryChanged: Boolean; 57 58 Output: string; 58 59 OutputPosition: Integer; 60 OutputChanged: Boolean; 59 61 Input: string; 60 62 InputPosition: Integer; … … 185 187 186 188 procedure TTargetInterpretter.CommandInput; 187 begin 189 var 190 Addr: Integer; 191 begin 192 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 188 193 while (InputPosition > Length(Input)) and (FState <> rsStopped) do begin 189 194 Sleep(1); 190 195 end; 191 196 if InputPosition <= Length(Input) then begin 192 Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] := 193 Ord(Input[InputPosition]); 197 Memory[Addr] := Ord(Input[InputPosition]); 194 198 Inc(InputPosition); 199 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); 200 MemoryChanged := True; 195 201 end; 196 202 end; … … 199 205 begin 200 206 if OutputPosition > Length(Output) then 201 SetLength(Output, Length(Output) + 1 + Length(Output) div 4);207 SetLength(Output, Length(Output) + 1); 202 208 Output[OutputPosition] := Char(Memory[MemoryPosition + 203 209 FProgram[FProgramIndex].RelIndex]); 204 210 Inc(OutputPosition); 211 OutputChanged := True; 205 212 end; 206 213 … … 218 225 219 226 procedure TTargetInterpretter.CommandInc; 220 begin 221 Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] := 222 ((Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] + 223 FProgram[FProgramIndex].Parameter) mod CellSize); 227 var 228 Addr: Integer; 229 begin 230 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 231 Memory[Addr] := ((Memory[Addr] + FProgram[FProgramIndex].Parameter) mod CellSize); 232 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); 233 MemoryChanged := True; 224 234 end; 225 235 226 236 procedure TTargetInterpretter.CommandDec; 227 begin 228 Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] := 229 ((Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] - 230 FProgram[FProgramIndex].Parameter) mod CellSize); 237 var 238 Addr: Integer; 239 begin 240 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 241 Memory[Addr] := ((Memory[Addr] - FProgram[FProgramIndex].Parameter) mod CellSize); 242 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); 243 MemoryChanged := True; 231 244 end; 232 245 … … 235 248 if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter) 236 249 else raise Exception.Create(SProgramUpperLimit); 237 if (MemoryPosition + 1) > MemoryMaxUsed then238 MemoryMaxUsed := MemoryPosition + 1;239 250 end; 240 251 … … 246 257 247 258 procedure TTargetInterpretter.CommandSet; 248 begin 249 Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] := 250 FProgram[FProgramIndex].Parameter mod CellSize; 259 var 260 Addr: Integer; 261 begin 262 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 263 Memory[Addr] := FProgram[FProgramIndex].Parameter mod CellSize; 264 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); 265 MemoryChanged := True; 251 266 end; 252 267 253 268 procedure TTargetInterpretter.CommandMultiply; 254 begin 255 Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] := 256 (Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] + 257 Memory[MemoryPosition] * FProgram[FProgramIndex].Parameter) mod CellSize; 269 var 270 Addr: Integer; 271 begin 272 Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex; 273 Memory[Addr] := (Memory[Addr] + Memory[MemoryPosition] * 274 FProgram[FProgramIndex].Parameter) mod CellSize; 275 MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr); 276 MemoryChanged := True; 258 277 end; 259 278 … … 270 289 OutputPosition := 1; 271 290 MemoryPosition := 0; 272 MemoryMaxUsed := 1;291 MemoryMaxUsedAddr := 0; 273 292 //FillChar(Pointer(Memory)^, Length(Memory), 0); 274 293 for I := 0 to Length(Memory) - 1 do 275 294 Memory[I] := 0; 295 MemoryChanged := True; 276 296 FStepCount := 0; 277 297 PrepareBreakPoints;
Note:
See TracChangeset
for help on using the changeset viewer.