- Timestamp:
- Jul 16, 2015, 9:20:40 AM (9 years ago)
- Location:
- branches
- Files:
-
- 8 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Machine/UMachine.pas
r86 r87 9 9 10 10 type 11 //TAddrInt = Int8; 12 TAddrInt = Int16; 13 //TAddrInt = Int32; 14 //TAddrInt = Int64; 15 TDataInt = Int16; 16 //TDataInt = Int16; 17 //TDataInt = Int32; 18 //TDataInt = Int64; 19 11 20 TOpcode = (opNop, opHalt, opCopy, opAdd, opSub, opMul, opDiv, opSet, 12 21 opParamClearAll, opParamSelect, opParamSet, opParamIndirect, opParamNext, 13 opSkip, opSign );22 opSkip, opSign, opParamSize); 14 23 15 24 TAreaType = (atAddress, atMemory, atIOPort, atRegister, atSysRegister); 16 25 26 TSysAddr = (saInstructionPointer, saAddrWidth, saDataWidth, saRegisterCount); 27 17 28 TParameter = record 18 Number: Integer;29 Number: TAddrInt; 19 30 Area: Integer; 31 Size: Integer; 20 32 Defined: Boolean; 21 33 end; … … 42 54 procedure OpcodeParamIndirect; 43 55 procedure OpcodeParamClearAll; 56 procedure OpcodeParamSize; 44 57 procedure OpcodeSkip; 45 58 procedure OpcodeSign; 46 59 function ReadNext: Integer; 47 60 public 48 Memory: array of Integer;49 Registers: array of Integer;50 IP: Integer;61 Memory: array of Byte; 62 Registers: array of TAddrInt; 63 IP: TAddrInt; 51 64 Params: array of TParameter; 52 65 Terminated: Boolean; 53 function ReadPort(Address: Integer): Integer; 54 procedure WritePort(Address: Integer; Value: Integer); 55 function ReadArea(AreaIndex: Integer; Address: Integer): Integer; 56 procedure WriteArea(AreaIndex: Integer; Address: Integer; Value: Integer); 66 function ReadPort(Address: Integer): TDataInt; 67 procedure WritePort(Address: TAddrInt; Value: TDataInt); 68 function ReadArea(AreaIndex: Integer; Address: TAddrInt): TDataInt; 69 procedure WriteArea(AreaIndex: Integer; Address: TAddrInt; Value: TDataInt); 70 function ReadSys(Address: TAddrInt): TDataInt; 57 71 procedure Run; 58 72 constructor Create; … … 74 88 procedure TMachine.OpcodeCopy; 75 89 begin 76 WriteArea(Params[0].Area, Params[0].Number, ReadArea(Params[1].Area, Params[1].Number)); 90 // for I := 0 to Params[0].Size - 1 do begin 91 WriteArea(Params[0].Area, Params[0].Number, ReadArea(Params[1].Area, Params[1].Number)); 77 92 end; 78 93 … … 144 159 Params[I].Area := Integer(atAddress); 145 160 Params[I].Defined := False; 161 Params[I].Size := 1; 146 162 end; 147 163 CurrentParam := 0; 164 end; 165 166 procedure TMachine.OpcodeParamSize; 167 begin 168 Params[CurrentParam].Size := ReadNext; 148 169 end; 149 170 … … 169 190 end; 170 191 171 function TMachine.ReadPort(Address: Integer): Integer;192 function TMachine.ReadPort(Address: Integer): TDataInt; 172 193 begin 173 194 Result := 0; 174 195 end; 175 196 176 procedure TMachine.WritePort(Address: Integer; Value: Integer);177 begin 178 179 end; 180 181 function TMachine.ReadArea(AreaIndex: Integer; Address: Integer): Integer;197 procedure TMachine.WritePort(Address: TAddrInt; Value: TDataInt); 198 begin 199 200 end; 201 202 function TMachine.ReadArea(AreaIndex: Integer; Address: TAddrInt): TDataInt; 182 203 begin 183 204 if AreaIndex = Integer(atAddress) then Result := Address … … 185 206 else if AreaIndex = Integer(atIOPort) then Result := ReadPort(Address) 186 207 else if AreaIndex = Integer(atRegister) then Result := Registers[Address] 187 else if AreaIndex = Integer(atSysRegister) then begin 188 if Address = 0 then Result := IP 189 else Result := 0; 190 end else raise Exception.Create('Unsupported area number ' + IntToStr(AreaIndex)); 191 end; 192 193 procedure TMachine.WriteArea(AreaIndex: Integer; Address: Integer; 194 Value: Integer); 208 else if AreaIndex = Integer(atSysRegister) then Result := ReadSys(Address) 209 else raise Exception.Create('Unsupported area number ' + IntToStr(AreaIndex)); 210 end; 211 212 procedure TMachine.WriteArea(AreaIndex: Integer; Address: TAddrInt; 213 Value: TDataInt); 195 214 begin 196 215 if AreaIndex = Integer(atAddress) then … … 201 220 if Address = 0 then IP := Value 202 221 end else raise Exception.Create('Unsupported area number ' + IntToStr(AreaIndex)); 222 end; 223 224 function TMachine.ReadSys(Address: TAddrInt): TDataInt; 225 begin 226 if Address = Integer(saInstructionPointer) then Result := IP 227 else if Address = Integer(saAddrWidth) then Result := SizeOf(TAddrInt) 228 else if Address = Integer(saDataWidth) then Result := SizeOf(TDataInt) 229 else if Address = Integer(saRegisterCount) then Result := Length(Registers) 230 else Result := 0; 203 231 end; 204 232 … … 244 272 OpcodeTable[opSign] := OpcodeSign; 245 273 OpcodeTable[opParamNext] := OpcodeParamNext; 274 OpcodeTable[opParamSize] := OpcodeParamSize; 246 275 end; 247 276 -
branches/Machine/project1.lpi
r86 r87 44 44 <HasResources Value="True"/> 45 45 <ResourceBaseClass Value="Form"/> 46 <UnitName Value="UFormMain"/>47 46 </Unit1> 48 47 <Unit2> 49 48 <Filename Value="UMachine.pas"/> 50 49 <IsPartOfProject Value="True"/> 51 <UnitName Value="UMachine"/>52 50 </Unit2> 53 51 <Unit3> 54 52 <Filename Value="UCompiler.pas"/> 55 53 <IsPartOfProject Value="True"/> 56 <UnitName Value="UCompiler"/>57 54 </Unit3> 58 55 </Units>
Note:
See TracChangeset
for help on using the changeset viewer.