Changeset 31 for branches/UltimatOS


Ignore:
Timestamp:
Jul 6, 2022, 1:05:27 AM (2 years ago)
Author:
chronos
Message:
  • Modified: Code parsing and execution improvements.
Location:
branches/UltimatOS
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/UltimatOS/Graphics.asm

    r30 r31  
     1ColorText: .dd $ffffff
     2ColorBackground: .dd 0
     3
    14Rectangle: ; R0 - Color, R1 - X, R2 - Y, R3 - Width, R4 - Height   
    25  PUSH R5 ; loop X
     
    1720  COPY R5, R3
    1821Line:
    19   OUT  ScreenWriteData, R7
     22  OUT  (ScreenWriteData), R7
    2023  DEC  R5
    2124  JPNZ R5, Line
     
    3437SetPixelAddr: ; R0 - X, R1 - Y
    3538  PUSH R2
    36   IN   R2, ScreenGetWidth
     39  IN   R2, (ScreenGetWidth)
    3740  SHL  R2, 2 ; multiply by 4
    38   SHL  R0, 2
     41  SHL  R0, 2 ; multiply by 4
    3942  MUL  R1, R2
    4043  ADD  R0, R1
    41   OUT  ScreenSetAddr, R0
     44  OUT  (ScreenSetAddr), R0
    4245  POP  R2
    4346  RET
     
    5760  PUSH R11 ; Background color
    5861  PUSH R12 ; temp value
    59   PUSH R13 ; bit mask
    6062  COPY R5, R1
    6163  COPY R6, R2
     
    6365  SHL  R0, 3
    6466  ADD  R3, R0
    65   IN   R8, ScreenGetWidth
     67  IN   R8, (ScreenGetWidth)
    6668  SET  R4, CharHeight
    67   SET  R10, $ffffff
    68   SET  R11, 5
    69   SET  R13, 1
     69  LDI  R10, (ColorText)
     70  LDI  R11, (ColorBackground)
    7071WriteCharLoopY:
    7172  COPY R0, R5
     
    7677WriteCharLoopX:
    7778  COPY R12, R7
    78   AND  R12, R13
     79  ANDI R12, 1
    7980  JPZ  R12, WriteCharNext
    80   OUT  ScreenWriteData, R10
     81  OUT  (ScreenWriteData), R10
    8182  JP   WriteCharNext2
    8283WriteCharNext:
    83   OUT  ScreenWriteData, R11
     84  OUT  (ScreenWriteData), R11
    8485WriteCharNext2:
    8586  DEC  R9
     
    9091  INC  R3
    9192  JPNZ R4, WriteCharLoopY
    92   POP  R13
    9393  POP  R12
    9494  POP  R11
     
    106106  PUSH R3 ; loop variable
    107107  PUSH R4 ; character width
    108   PUSH R5 ; byte mask
    109108  PUSH R6 ; X
    110109  PUSH R7 ; Y
     
    115114  COPY R7, R2
    116115  COPY R3, R0
    117   SET  R5, $ff
    118116  SET  R4, CharWidth 
    119117TextOutLoop:
    120118  LD   R0, (R3)
    121   AND  R0, R5
     119  ANDI R0, $ff
    122120  JPZ  R0, TextOutLoop2
    123121  COPY R1, R6
     
    133131  POP  R7
    134132  POP  R6
    135   POP  R5
    136133  POP  R4
    137134  POP  R3
  • branches/UltimatOS/UCpu.pas

    r30 r31  
    99  TInstruction = (inNop, inHalt, inSet, inInput, inOutput, inInc, inDec, inJp,
    1010    inJpz, inJpnz, inAdd, inSub, inCall, inRet, inPush, inPop, inCopy,
    11     inShl, inShr, inLoad, inStore, inMul, inAnd, inOr, inXor);
     11    inShl, inShr, inLoad, inLoadi, inStore, inMul, inAnd, inAndi, inOr, inXor);
    1212  TAddress = Integer;
    1313  PAddress = ^TAddress;
     
    107107      R[RegIndex] := PData(@Memory.Data[R[RegIndex2]])^;
    108108    end;
     109    inLoadi: begin
     110      RegIndex := ReadByte;
     111      Address := ReadAddress;
     112      R[RegIndex] := PData(@Memory.Data[Address])^;
     113    end;
    109114    inStore: begin
    110115      RegIndex := ReadByte;
     
    194199      RegIndex2 := ReadByte;
    195200      R[RegIndex] := R[RegIndex] and R[RegIndex2];
     201    end;
     202    inAndi: begin
     203      RegIndex := ReadByte;
     204      R[RegIndex] := R[RegIndex] and ReadData;
    196205    end;
    197206    inOr: begin
  • branches/UltimatOS/UInstructionWriter.pas

    r29 r31  
    88type
    99  TInstructionParam = (ipNone, ipRegIndex, ipAddress, ipData, ipIndex,
    10     ipRegIndexRel);
     10    ipRegIndexRel, ipAddressRel);
    1111
    1212  TInstructionDef = class
     
    7272    procedure WriteReg(Index: Byte);
    7373    procedure WriteByte(Value: Byte);
     74    procedure WriteWord(Value: Word);
     75    procedure WriteCardinal(Value: Cardinal);
    7476    constructor Create;
    7577    destructor Destroy; override;
     
    190192        end;
    191193      end;
     194    end;
     195    ipAddressRel: begin
     196      Address := Trim(ParseText(Text, ','));
     197      if Address.StartsWith('(') and Address.EndsWith(')') then begin
     198        Address := Copy(Address, 2, Length(Address) - 2);
     199        if TryStrToInt(Address, Value) then begin
     200          WriteAddress(Value);
     201        end else begin
     202          FoundConstant := Constants.SearchByName(UpperCase(Address));
     203          if Assigned(FoundConstant) then begin
     204            WriteAddress(FoundConstant.Value);
     205            Exit;
     206          end;
     207          FoundLabel := Labels.SearchByName(UpperCase(Address));
     208          if Assigned(FoundLabel) then begin
     209            // Existing label
     210            WriteAddress(FoundLabel.Address);
     211          end else begin
     212            // Forward label reference
     213            with Labels.AddNew(UpperCase(Address), -1) do begin
     214              SetLength(ForwardRefs, Length(ForwardRefs) + 1);
     215              ForwardRefs[Length(ForwardRefs) - 1] := IP;
     216            end;
     217            WriteAddress(0);
     218          end;
     219        end;
     220      end else Error('Expected indirect address ' + Address);
    192221    end;
    193222    ipRegIndex: begin
     
    333362        end else WriteByte(StrToInt(Param));
    334363      end;
     364    end else
     365    if InstructionName = 'dw' then begin
     366      while Text <> '' do begin
     367        Param := ParseText(Text, ',');
     368        if Param.StartsWith('"') and Param.EndsWith('"') then begin
     369          Param := Copy(Param, 2, Length(Param) - 2);
     370          for I := 1 to Length(Param) do
     371            WriteWord(Ord(Param[I]));
     372        end else WriteWord(StrToInt(Param));
     373      end;
     374    end else
     375    if InstructionName = 'dd' then begin
     376      while Text <> '' do begin
     377        Param := ParseText(Text, ',');
     378        if Param.StartsWith('"') and Param.EndsWith('"') then begin
     379          Param := Copy(Param, 2, Length(Param) - 2);
     380          for I := 1 to Length(Param) do
     381            WriteCardinal(Ord(Param[I]));
     382        end else WriteCardinal(StrToInt(Param));
     383      end;
    335384    end else Error('Unsupported directive name ' + InstructionName);
    336385  end else begin
     
    383432end;
    384433
     434procedure TInstructionWriter.WriteWord(Value: Word);
     435begin
     436  PWord(@Memory.Data[IP])^ := Value;
     437  Inc(IP, SizeOf(Word));
     438end;
     439
     440procedure TInstructionWriter.WriteCardinal(Value: Cardinal);
     441begin
     442  PCardinal(@Memory.Data[IP])^ := Value;
     443  Inc(IP, SizeOf(Cardinal));
     444end;
     445
    385446constructor TInstructionWriter.Create;
    386447begin
     
    392453    AddNew(inHalt, 'HALT');
    393454    AddNew(inSet, 'SET', ipRegIndex, ipData);
    394     AddNew(inInput, 'IN', ipRegIndex, ipAddress);
    395     AddNew(inOutput, 'OUT', ipAddress, ipRegIndex);
     455    AddNew(inInput, 'IN', ipRegIndex, ipAddressRel);
     456    AddNew(inOutput, 'OUT', ipAddressRel, ipRegIndex);
    396457    AddNew(inInc, 'INC', ipRegIndex);
    397458    AddNew(inDec, 'DEC', ipRegIndex);
     
    409470    AddNew(inShr, 'SHR', ipRegIndex, ipIndex);
    410471    AddNew(inLoad, 'LD', ipRegIndex, ipRegIndexRel);
     472    AddNew(inLoadi, 'LDI', ipRegIndex, ipAddressRel);
    411473    AddNew(inStore, 'ST', ipRegIndexRel, ipRegIndex);
    412474    AddNew(inMul, 'MUL', ipRegIndex, ipRegIndex);
    413475    AddNew(inAnd, 'AND', ipRegIndex, ipRegIndex);
     476    AddNew(inAndi, 'ANDI', ipRegIndex, ipData);
    414477    AddNew(inOr, 'OR', ipRegIndex, ipRegIndex);
    415478    AddNew(inXor, 'XOR', ipRegIndex, ipRegIndex);
  • branches/UltimatOS/UMachine.pas

    r30 r31  
    2727    function GetSize: TPoint;
    2828    procedure SetSize(AValue: TPoint);
    29     procedure Reset; override;
    3029  public
    3130    Memory: TMemory;
    3231    PendingRefresh: Boolean;
     32    procedure Reset; override;
    3333    procedure SetPointer(Value: Integer);
    3434    procedure WriteData(Value: Integer);
     
    8181implementation
    8282
    83 uses
    84   UInstructionWriter;
    85 
    8683{ TDevice }
    8784
Note: See TracChangeset for help on using the changeset viewer.