Ignore:
Timestamp:
May 17, 2019, 10:06:59 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Redraw output form content only if output instruction was used in interpretter mode.
  • Modified: Redraw memory form content only if memory was written in interpretter mode.
  • Fixed: Replace windows newlines by unix newlines in interpretter output under Linux.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetInterpretter.pas

    r96 r112  
    66
    77uses
    8   Classes, SysUtils, Dialogs, Forms, UTarget, UBFTarget;
     8  Classes, SysUtils, Dialogs, Forms, UTarget, UBFTarget, Math;
    99
    1010type
     
    5555    Memory: array of Integer;
    5656    MemoryPosition: Integer;
     57    MemoryChanged: Boolean;
    5758    Output: string;
    5859    OutputPosition: Integer;
     60    OutputChanged: Boolean;
    5961    Input: string;
    6062    InputPosition: Integer;
     
    185187
    186188procedure TTargetInterpretter.CommandInput;
    187 begin
     189var
     190  Addr: Integer;
     191begin
     192  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
    188193  while (InputPosition > Length(Input)) and (FState <> rsStopped) do begin
    189194    Sleep(1);
    190195  end;
    191196  if InputPosition <= Length(Input) then begin
    192     Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] :=
    193       Ord(Input[InputPosition]);
     197    Memory[Addr] := Ord(Input[InputPosition]);
    194198    Inc(InputPosition);
     199    MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr);
     200    MemoryChanged := True;
    195201  end;
    196202end;
     
    199205begin
    200206  if OutputPosition > Length(Output) then
    201     SetLength(Output, Length(Output) + 1 + Length(Output) div 4);
     207    SetLength(Output, Length(Output) + 1);
    202208  Output[OutputPosition] := Char(Memory[MemoryPosition +
    203209    FProgram[FProgramIndex].RelIndex]);
    204210  Inc(OutputPosition);
     211  OutputChanged := True;
    205212end;
    206213
     
    218225
    219226procedure TTargetInterpretter.CommandInc;
    220 begin
    221   Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] :=
    222     ((Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] +
    223     FProgram[FProgramIndex].Parameter) mod CellSize);
     227var
     228  Addr: Integer;
     229begin
     230  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     231  Memory[Addr] := ((Memory[Addr] + FProgram[FProgramIndex].Parameter) mod CellSize);
     232  MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr);
     233  MemoryChanged := True;
    224234end;
    225235
    226236procedure TTargetInterpretter.CommandDec;
    227 begin
    228   Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] :=
    229     ((Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] -
    230     FProgram[FProgramIndex].Parameter) mod CellSize);
     237var
     238  Addr: Integer;
     239begin
     240  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     241  Memory[Addr] := ((Memory[Addr] - FProgram[FProgramIndex].Parameter) mod CellSize);
     242  MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr);
     243  MemoryChanged := True;
    231244end;
    232245
     
    235248  if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter)
    236249    else raise Exception.Create(SProgramUpperLimit);
    237   if (MemoryPosition + 1) > MemoryMaxUsed then
    238     MemoryMaxUsed := MemoryPosition + 1;
    239250end;
    240251
     
    246257
    247258procedure TTargetInterpretter.CommandSet;
    248 begin
    249   Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] :=
    250     FProgram[FProgramIndex].Parameter mod CellSize;
     259var
     260  Addr: Integer;
     261begin
     262  Addr := MemoryPosition + FProgram[FProgramIndex].RelIndex;
     263  Memory[Addr] := FProgram[FProgramIndex].Parameter mod CellSize;
     264  MemoryMaxUsedAddr := Max(Addr, MemoryMaxUsedAddr);
     265  MemoryChanged := True;
    251266end;
    252267
    253268procedure TTargetInterpretter.CommandMultiply;
    254 begin
    255   Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] :=
    256     (Memory[MemoryPosition + FProgram[FProgramIndex].RelIndex] +
    257     Memory[MemoryPosition] * FProgram[FProgramIndex].Parameter) mod CellSize;
     269var
     270  Addr: Integer;
     271begin
     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;
    258277end;
    259278
     
    270289  OutputPosition := 1;
    271290  MemoryPosition := 0;
    272   MemoryMaxUsed := 1;
     291  MemoryMaxUsedAddr := 0;
    273292  //FillChar(Pointer(Memory)^, Length(Memory), 0);
    274293  for I := 0 to Length(Memory) - 1 do
    275294    Memory[I] := 0;
     295  MemoryChanged := True;
    276296  FStepCount := 0;
    277297  PrepareBreakPoints;
Note: See TracChangeset for help on using the changeset viewer.