- Timestamp:
- Oct 25, 2023, 12:33:07 AM (13 months ago)
- Location:
- branches/ByteArray
- Files:
-
- 78 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ByteArray/BigInt.pas
r46 r47 9 9 TArrayOfByte = array of Byte; 10 10 11 TBigIntSize = Byte; 12 11 13 { TBigInt } 12 14 13 15 TBigInt = record 14 16 private 15 function GetSize: Byte; 16 procedure SetSize(AValue: Byte); 17 FData: array of Byte; 18 function GetData(Index: TBigIntSize): Byte; 19 function GetSize: TBigIntSize; 20 procedure SetData(Index: TBigIntSize; AValue: Byte); 21 procedure SetSize(AValue: TBigIntSize); 17 22 public 18 Data: array of Byte;19 23 class operator Implicit(A: Byte): TBigInt; 20 24 class operator Implicit(A: Word): TBigInt; … … 33 37 class operator Implicit(A: TBigInt): PByte; 34 38 class operator Inc(A: TBigInt) : TBigInt; 39 class operator Dec(A: TBigInt) : TBigInt; 35 40 class operator Add(A, B: TBigInt): TBigInt; 36 41 class operator Subtract(A, B: TBigInt): TBigInt; … … 42 47 class operator GreaterThanOrEqual(A, B: TBigInt): Boolean; 43 48 procedure Shrink; 44 procedure SetByteArray(AData: TArrayOfByte; ASize: Byte);45 procedure GetByteArray(var AData: TArrayOfByte; ASize: Byte);46 function Copy(Size: Byte): TBigInt;49 procedure SetByteArray(AData: TArrayOfByte; ASize: TBigIntSize); 50 procedure GetByteArray(var AData: TArrayOfByte; ASize: TBigIntSize); 51 function Copy(Size: TBigIntSize): TBigInt; 47 52 property Size: Byte read GetSize write SetSize; 48 end; 49 50 function TryStrToBigInt(const S: string; Out I: TBigInt): Boolean; 53 property Data[Index: TBigIntSize]: Byte read GetData write SetData; 54 end; 55 56 function TryStrToBigInt(const S: string; out I: TBigInt): Boolean; 57 51 58 52 59 implementation 53 60 54 function TryStrToBigInt(const S: string; Out I: TBigInt): Boolean; 61 resourcestring 62 SUnsupportedByteSize = 'Unsupported byte size'; 63 64 function TryStrToBigInt(const S: string; out I: TBigInt): Boolean; 55 65 var 56 66 Value: Int64; … … 62 72 { TBigInt } 63 73 64 function TBigInt.GetSize: Byte; 65 begin 66 Result := Length(Data); 67 end; 68 69 procedure TBigInt.SetSize(AValue: Byte); 70 var 71 LastSize: Byte; 74 function TBigInt.GetSize: TBigIntSize; 75 begin 76 Result := Length(FData); 77 end; 78 79 function TBigInt.GetData(Index: TBigIntSize): Byte; 80 begin 81 if Index < Size then Result := FData[Index] 82 else Result := 0; 83 end; 84 85 procedure TBigInt.SetData(Index: TBigIntSize; AValue: Byte); 86 begin 87 if Index > Size - 1 then Size := Index + 1; 88 FData[Index] := AValue; 89 end; 90 91 procedure TBigInt.SetSize(AValue: TBigIntSize); 92 var 93 LastSize: TBigIntSize; 72 94 begin 73 95 LastSize := GetSize; 74 SetLength( Data, AValue);96 SetLength(FData, AValue); 75 97 if AValue > LastSize then 76 FillChar( Data[LastSize], AValue - LastSize, 0);98 FillChar(FData[LastSize], AValue - LastSize, 0); 77 99 end; 78 100 … … 80 102 begin 81 103 Result.Size := 1; 82 Result. Data[0] := A;104 Result.FData[0] := A; 83 105 end; 84 106 … … 86 108 begin 87 109 Result.Size := 2; 88 PWord(@Result. Data[0])^ := A;110 PWord(@Result.FData[0])^ := A; 89 111 Result.Shrink; 90 112 end; … … 93 115 begin 94 116 Result.Size := 1; 95 PByte(@Result. Data[0])^ := A;117 PByte(@Result.FData[0])^ := A; 96 118 Result.Shrink; 97 119 end; … … 100 122 begin 101 123 Result.Size := 4; 102 PInteger(@Result. Data[0])^ := A;124 PInteger(@Result.FData[0])^ := A; 103 125 Result.Shrink; 104 126 end; … … 107 129 begin 108 130 Result.Size := 8; 109 PQWord(@Result. Data[0])^ := A;131 PQWord(@Result.FData[0])^ := A; 110 132 Result.Shrink; 111 133 end; … … 114 136 begin 115 137 Result.Size := 8; 116 PInt64(@Result. Data[0])^ := A;138 PInt64(@Result.FData[0])^ := A; 117 139 Result.Shrink; 118 140 end; … … 120 142 class operator TBigInt.Implicit(A: TBigInt): UInt8; 121 143 begin 122 if A.Size = 1 then Result := A. Data[0]123 else raise Exception.Create( 'x');144 if A.Size = 1 then Result := A.FData[0] 145 else raise Exception.Create(SUnsupportedByteSize); 124 146 end; 125 147 126 148 class operator TBigInt.Implicit(A: TBigInt): Int8; 127 149 begin 128 if A.Size = 1 then Result := A. Data[0]129 else raise Exception.Create( 'x');150 if A.Size = 1 then Result := A.FData[0] 151 else raise Exception.Create(SUnsupportedByteSize); 130 152 end; 131 153 132 154 class operator TBigInt.Implicit(A: TBigInt): UInt16; 133 155 begin 134 if A.Size = 2 then Result := PUInt16(@A. Data[0])^135 else raise Exception.Create( 'x');156 if A.Size = 2 then Result := PUInt16(@A.FData[0])^ 157 else raise Exception.Create(SUnsupportedByteSize); 136 158 end; 137 159 138 160 class operator TBigInt.Implicit(A: TBigInt): Int16; 139 161 begin 140 if A.Size = 2 then Result := PInt16(@A. Data[0])^141 else raise Exception.Create( 'x');162 if A.Size = 2 then Result := PInt16(@A.FData[0])^ 163 else raise Exception.Create(SUnsupportedByteSize); 142 164 end; 143 165 … … 145 167 begin 146 168 case A.Size of 147 1: Result := PByte(@A.Data[0])^; 148 2: Result := PWord(@A.Data[0])^; 149 4: Result := PDWord(@A.Data[0])^; 150 8: Result := PQWord(@A.Data[0])^; 151 else raise Exception.Create('x'); 169 1: Result := PByte(@A.FData[0])^; 170 2: Result := PWord(@A.FData[0])^; 171 3: Result := PWord(@A.FData[0])^ or (PByte(@A.FData[2])^ shl 16); 172 4: Result := PDWord(@A.FData[0])^; 173 8: Result := PQWord(@A.FData[0])^; 174 else raise Exception.Create(SUnsupportedByteSize); 152 175 end; 153 176 end; … … 155 178 class operator TBigInt.Implicit(A: TBigInt): UInt32; 156 179 begin 157 if A.Size = 4 then Result := PInt32(@A. Data[0])^158 else raise Exception.Create( 'x');180 if A.Size = 4 then Result := PInt32(@A.FData[0])^ 181 else raise Exception.Create(SUnsupportedByteSize); 159 182 end; 160 183 161 184 class operator TBigInt.Implicit(A: TBigInt): UInt64; 162 185 begin 163 if A.Size = 8 then Result := PUInt64(@A. Data[0])^164 else raise Exception.Create( 'x');186 if A.Size = 8 then Result := PUInt64(@A.FData[0])^ 187 else raise Exception.Create(SUnsupportedByteSize); 165 188 end; 166 189 167 190 class operator TBigInt.Implicit(A: TBigInt): Int64; 168 191 begin 169 if A.Size = 8 then Result := PInt64(@A. Data[0])^170 else raise Exception.Create( 'x');192 if A.Size = 8 then Result := PInt64(@A.FData[0])^ 193 else raise Exception.Create(SUnsupportedByteSize); 171 194 end; 172 195 173 196 class operator TBigInt.Implicit(A: TBigInt): PByte; 174 197 begin 175 if A.Size = 4 then Result := PByte(@PInteger(@A. Data[0])^)176 else raise Exception.Create( 'x');198 if A.Size = 4 then Result := PByte(@PInteger(@A.FData[0])^) 199 else raise Exception.Create(SUnsupportedByteSize); 177 200 end; 178 201 179 202 class operator TBigInt.Inc(A: TBigInt): TBigInt; 180 203 begin 204 Result := A + 1; 205 end; 206 207 class operator TBigInt.Dec(A: TBigInt): TBigInt; 208 begin 209 Result := A - 1; 210 end; 211 212 class operator TBigInt.Add(A, B: TBigInt): TBigInt; 213 var 214 I: Integer; 215 V: SmallInt; 216 Carry: Byte; 217 begin 218 Result.Size := Max(A.Size, B.Size); 219 Carry := 0; 220 I := 0; 221 while (I < Result.Size) or (Carry > 0) do begin 222 V := A.Data[I] + B.Data[I] + Carry; 223 if V >= 256 then begin 224 Carry := 1; 225 end else Carry := 0; 226 Result.Data[I] := V and $ff; 227 Inc(I); 228 end; 229 end; 230 231 class operator TBigInt.Subtract(A, B: TBigInt): TBigInt; 232 var 233 I: Integer; 234 V: SmallInt; 235 Carry: Byte; 236 begin 181 237 Result.Size := A.Size; 182 case Result.Size of 183 1: PByte(@Result.Data[0])^ := PByte(@A.Data[0])^ + 1; 184 2: PWord(@Result.Data[0])^ := PWord(@A.Data[0])^ + 1; 185 4: PDWord(@Result.Data[0])^ := PDWord(@A.Data[0])^ + 1; 186 8: PQWord(@Result.Data[0])^ := PQWord(@A.Data[0])^ + 1; 187 end; 188 end; 189 190 class operator TBigInt.Add(A, B: TBigInt): TBigInt; 191 var 192 CommonSize: Byte; 193 begin 194 CommonSize := Max(A.Size, B.Size); 195 A.Size := CommonSize; 196 B.Size := CommonSize; 197 Result.Size := CommonSize; 198 case Result.Size of 199 1: PByte(@Result.Data[0])^ := PByte(@A.Data[0])^ + PByte(@B.Data[0])^; 200 2: PWord(@Result.Data[0])^ := PWord(@A.Data[0])^ + PWord(@B.Data[0])^; 201 4: PDWord(@Result.Data[0])^ := PDWord(@A.Data[0])^ + PDWord(@B.Data[0])^; 202 8: PQWord(@Result.Data[0])^ := PQWord(@A.Data[0])^ + PQWord(@B.Data[0])^; 203 end; 204 end; 205 206 class operator TBigInt.Subtract(A, B: TBigInt): TBigInt; 207 var 208 CommonSize: Byte; 209 begin 210 CommonSize := Max(A.Size, B.Size); 211 A.Size := CommonSize; 212 B.Size := CommonSize; 213 Result.Size := CommonSize; 214 case Result.Size of 215 1: PByte(@Result.Data[0])^ := PByte(@A.Data[0])^ - PByte(@B.Data[0])^; 216 2: PWord(@Result.Data[0])^ := PWord(@A.Data[0])^ - PWord(@B.Data[0])^; 217 4: PDWord(@Result.Data[0])^ := PDWord(@A.Data[0])^ - PDWord(@B.Data[0])^; 218 8: PQWord(@Result.Data[0])^ := PQWord(@A.Data[0])^ - PQWord(@B.Data[0])^; 238 Carry := 0; 239 I := 0; 240 while (I < Result.Size) or (Carry > 0) do begin 241 V := A.Data[I] - B.Data[I] - Carry; 242 if V < 0 then begin 243 Carry := 1; 244 end else Carry := 0; 245 Result.Data[I] := V and $ff; 246 Inc(I); 219 247 end; 220 248 end; 221 249 222 250 class operator TBigInt.Equal(A, B: TBigInt): Boolean; 223 begin 224 251 var 252 I: Byte; 253 begin 254 Result := A.Size = B.Size; 255 for I := 0 to A.Size - 1 do 256 if A.FData[I] <> B.FData[I] then begin 257 Result := False; 258 Break; 259 end; 225 260 end; 226 261 227 262 class operator TBigInt.NotEqual(A, B: TBigInt): Boolean; 228 begin 229 263 var 264 I: Byte; 265 begin 266 Result := A.Size = B.Size; 267 for I := 0 to A.Size - 1 do 268 if A.FData[I] <> B.FData[I] then begin 269 Result := False; 270 Break; 271 end; 272 Result := not Result; 230 273 end; 231 274 … … 255 298 begin 256 299 I := Size - 1; 257 while (I > 0) and ( Data[I] = 0) do300 while (I > 0) and (FData[I] = 0) do 258 301 Dec(I); 259 302 Size := I + 1; 260 303 end; 261 304 262 procedure TBigInt.SetByteArray(AData: TArrayOfByte; ASize: Byte);305 procedure TBigInt.SetByteArray(AData: TArrayOfByte; ASize: TBigIntSize); 263 306 begin 264 307 Size := ASize; 265 Move(AData[0], Data[0], Size);266 end; 267 268 procedure TBigInt.GetByteArray(var AData: TArrayOfByte; ASize: Byte);308 Move(AData[0], FData[0], Size); 309 end; 310 311 procedure TBigInt.GetByteArray(var AData: TArrayOfByte; ASize: TBigIntSize); 269 312 begin 270 313 SetLength(AData, ASize); 271 Move( Data[0], AData[0], Size);272 end; 273 274 function TBigInt.Copy(Size: Byte): TBigInt;314 Move(FData[0], AData[0], Size); 315 end; 316 317 function TBigInt.Copy(Size: TBigIntSize): TBigInt; 275 318 begin 276 319 Result.Size := Size; 277 320 case Result.Size of 278 1: PByte(@Result. Data[0])^ := PByte(@Data[0])^;279 2: PWord(@Result. Data[0])^ := PWord(@Data[0])^;280 4: PDWord(@Result. Data[0])^ := PDWord(@Data[0])^;281 8: PQWord(@Result. Data[0])^ := PQWord(@Data[0])^;321 1: PByte(@Result.FData[0])^ := PByte(@FData[0])^; 322 2: PWord(@Result.FData[0])^ := PWord(@FData[0])^; 323 4: PDWord(@Result.FData[0])^ := PDWord(@FData[0])^; 324 8: PQWord(@Result.FData[0])^ := PQWord(@FData[0])^; 282 325 end; 283 326 end; -
branches/ByteArray/ByteArray.lpi
r46 r47 26 26 <RequiredPackages> 27 27 <Item> 28 <PackageName Value="Common"/> 29 <DefaultFilename Value="Packages/Common/Common.lpk" Prefer="True"/> 30 </Item> 31 <Item> 28 32 <PackageName Value="SynEdit"/> 29 33 </Item> … … 163 167 <HasResources Value="True"/> 164 168 <ResourceBaseClass Value="Form"/> 169 </Unit> 170 <Unit> 171 <Filename Value="Forms/Project.pas"/> 172 <IsPartOfProject Value="True"/> 165 173 </Unit> 166 174 </Units> -
branches/ByteArray/Channel.pas
r45 r47 9 9 TChannel = class 10 10 type 11 TRead = function (Address: TBigInt; DataSize: Byte): TBigInt of object;12 TWrite = procedure (Address: TBigInt; DataSize: Byte; Value: TBigInt) of object;11 TRead = function (Address: TBigInt; DataSize: TBigIntSize): TBigInt of object; 12 TWrite = procedure (Address: TBigInt; DataSize: TBigIntSize; Value: TBigInt) of object; 13 13 TGetSize = function : TBigInt of object; 14 14 var -
branches/ByteArray/Cpu.pas
r46 r47 7 7 8 8 type 9 TBitWidth = Byte;10 11 9 TInstruction = (inNop, inHalt, 12 10 inLoadConst, inLoadConstSize, … … 49 47 private 50 48 Instructions: array[TInstruction] of TInstructionEvent; 51 procedure Push(Value: TBigInt; Size: Byte);52 function Pop(Size: Byte): TBigInt;49 procedure Push(Value: TBigInt; Size: TBigIntSize); 50 function Pop(Size: TBigIntSize): TBigInt; 53 51 procedure InstructionNop; 54 52 procedure InstructionHalt; … … 91 89 SP: TBigInt; 92 90 Terminated: Boolean; 93 DataWidth: TBi tWidth;94 AddressWidth: TBi tWidth;91 DataWidth: TBigIntSize; 92 AddressWidth: TBigIntSize; 95 93 Memory: TChannel; 96 94 IO: TChannel; 97 function Read(Size: Byte): TBigInt;95 function Read(Size: TBigIntSize): TBigInt; 98 96 function ReadRegIndex: TRegIndex; 99 procedure Write(Size: Byte; Value: TBigInt);97 procedure Write(Size: TBigIntSize; Value: TBigInt); 100 98 procedure WriteInstruction(Instruction: TInstruction); 101 99 procedure WriteRegister(Reg: TRegIndex); … … 111 109 { TCpu } 112 110 113 procedure TCpu.Push(Value: TBigInt; Size: Byte);111 procedure TCpu.Push(Value: TBigInt; Size: TBigIntSize); 114 112 begin 115 113 SP := SP - Size; … … 117 115 end; 118 116 119 function TCpu.Pop(Size: Byte): TBigInt;117 function TCpu.Pop(Size: TBigIntSize): TBigInt; 120 118 begin 121 119 Result := Memory.Read(SP, Size); … … 144 142 var 145 143 RegIndex: TRegIndex; 146 DataSize: Byte;147 begin 148 DataSize := Read( 1);144 DataSize: TBigIntSize; 145 begin 146 DataSize := Read(SizeOf(TBigIntSize)); 149 147 RegIndex := ReadRegIndex; 150 148 Regs[RegIndex] := Read(DataSize); … … 163 161 procedure TCpu.InstructionLoadSize; 164 162 var 165 DataSize: Byte;163 DataSize: TBigIntSize; 166 164 RegIndex: TRegIndex; 167 165 RegIndex2: TRegIndex; 168 166 begin 169 DataSize := Read( 1);167 DataSize := Read(SizeOf(TBigIntSize)); 170 168 RegIndex := ReadRegIndex; 171 169 RegIndex2 := ReadRegIndex; … … 185 183 procedure TCpu.InstructionLoadMemSize; 186 184 var 187 DataSize: Byte;188 AddressSize: Byte;189 Address: TBigInt; 190 RegIndex: TRegIndex; 191 begin 192 DataSize := Read( 1);193 AddressSize := Read( 1);185 DataSize: TBigIntSize; 186 AddressSize: TBigIntSize; 187 Address: TBigInt; 188 RegIndex: TRegIndex; 189 begin 190 DataSize := Read(SizeOf(TBigIntSize)); 191 AddressSize := Read(SizeOf(TBigIntSize)); 194 192 RegIndex := ReadRegIndex; 195 193 Address := Read(AddressSize); … … 209 207 procedure TCpu.InstructionStoreMemSize; 210 208 var 211 DataSize: Byte;212 AddressSize: Byte;213 Address: TBigInt; 214 RegIndex: TRegIndex; 215 begin 216 DataSize := Read( 1);217 AddressSize := Read( 1);209 DataSize: TBigIntSize; 210 AddressSize: TBigIntSize; 211 Address: TBigInt; 212 RegIndex: TRegIndex; 213 begin 214 DataSize := Read(SizeOf(TBigIntSize)); 215 AddressSize := Read(SizeOf(TBigIntSize)); 218 216 Address := Read(AddressSize); 219 217 RegIndex := ReadRegIndex; … … 228 226 procedure TCpu.InstructionJumpSize; 229 227 var 230 AddressSize: Byte;231 begin 232 AddressSize := Read( 1);228 AddressSize: TBigIntSize; 229 begin 230 AddressSize := Read(SizeOf(TBigIntSize)); 233 231 PC := Read(AddressSize); 234 232 end; … … 249 247 RegIndex: TRegIndex; 250 248 Address: TBigInt; 251 DataSize: Byte;252 AddressSize: Byte;253 begin 254 DataSize := Read( 1);255 AddressSize := Read( 1);249 DataSize: TBigIntSize; 250 AddressSize: TBigIntSize; 251 begin 252 DataSize := Read(SizeOf(TBigIntSize)); 253 AddressSize := Read(SizeOf(TBigIntSize)); 256 254 RegIndex := ReadRegIndex; 257 255 Address := Read(AddressSize); … … 275 273 RegIndex: TRegIndex; 276 274 Address: TBigInt; 277 DataSize: Byte;278 AddressSize: Byte;279 begin 280 DataSize := Read( 1);281 AddressSize := Read( 1);275 DataSize: TBigIntSize; 276 AddressSize: TBigIntSize; 277 begin 278 DataSize := Read(SizeOf(TBigIntSize)); 279 AddressSize := Read(SizeOf(TBigIntSize)); 282 280 RegIndex := ReadRegIndex; 283 281 Address := Read(AddressSize); … … 293 291 procedure TCpu.InstructionJumpRelSize; 294 292 var 295 AddressSize: Byte;296 begin 297 AddressSize := Read( 1);293 AddressSize: TBigIntSize; 294 begin 295 AddressSize := Read(SizeOf(TBigIntSize)); 298 296 PC := PC + Read(AddressSize); 299 297 end; … … 307 305 procedure TCpu.InstructionCallSize; 308 306 var 309 AddressSize: Byte;310 begin 311 AddressSize := Read( 1);307 AddressSize: TBigIntSize; 308 begin 309 AddressSize := Read(SizeOf(TBigIntSize)); 312 310 Push(PC, AddressSize); 313 311 PC := Read(AddressSize); … … 321 319 procedure TCpu.InstructionRetSize; 322 320 var 323 AddressSize: Byte;324 begin 325 AddressSize := Read( 1);321 AddressSize: TBigIntSize; 322 begin 323 AddressSize := Read(SizeOf(TBigIntSize)); 326 324 PC := Pop(AddressSize); 327 325 end; … … 337 335 procedure TCpu.InstructionPushSize; 338 336 var 339 DataSize: Byte;340 RegIndex: TRegIndex; 341 begin 342 DataSize := Read( 1);337 DataSize: TBigIntSize; 338 RegIndex: TRegIndex; 339 begin 340 DataSize := Read(SizeOf(TBigIntSize)); 343 341 RegIndex := ReadRegIndex; 344 342 Push(Regs[RegIndex], DataSize); … … 355 353 procedure TCpu.InstructionPopSize; 356 354 var 357 DataSize: Byte;358 RegIndex: TRegIndex; 359 begin 360 DataSize := Read( 1);355 DataSize: TBigIntSize; 356 RegIndex: TRegIndex; 357 begin 358 DataSize := Read(SizeOf(TBigIntSize)); 361 359 RegIndex := ReadRegIndex; 362 360 Regs[RegIndex] := Pop(DataSize); … … 377 375 RegIndex: TRegIndex; 378 376 RegIndex2: TRegIndex; 379 DataSize: Byte;380 begin 381 DataSize := Read( 1);377 DataSize: TBigIntSize; 378 begin 379 DataSize := Read(SizeOf(TBigIntSize)); 382 380 RegIndex := ReadRegIndex; 383 381 RegIndex2 := ReadRegIndex; … … 399 397 RegIndex: TRegIndex; 400 398 RegIndex2: TRegIndex; 401 DataSize: Byte;402 begin 403 DataSize := Read( 1);399 DataSize: TBigIntSize; 400 begin 401 DataSize := Read(SizeOf(TBigIntSize)); 404 402 RegIndex := ReadRegIndex; 405 403 RegIndex2 := ReadRegIndex; … … 418 416 var 419 417 RegIndex: TRegIndex; 420 DataSize: Byte;421 begin 422 DataSize := Read( 1);418 DataSize: TBigIntSize; 419 begin 420 DataSize := Read(SizeOf(TBigIntSize)); 423 421 RegIndex := ReadRegIndex; 424 422 Regs[RegIndex] := Regs[RegIndex].Copy(DataSize) + 1; … … 436 434 var 437 435 RegIndex: TRegIndex; 438 DataSize: Byte;439 begin 440 DataSize := Read( 1);436 DataSize: TBigIntSize; 437 begin 438 DataSize := Read(SizeOf(TBigIntSize)); 441 439 RegIndex := ReadRegIndex; 442 440 Regs[RegIndex] := Regs[RegIndex].Copy(DataSize) - 1; … … 481 479 end; 482 480 483 function TCpu.Read(Size: Byte): TBigInt;481 function TCpu.Read(Size: TBigIntSize): TBigInt; 484 482 begin 485 483 Result := Memory.Read(PC, Size); … … 492 490 end; 493 491 494 procedure TCpu.Write(Size: Byte; Value: TBigInt);492 procedure TCpu.Write(Size: TBigIntSize; Value: TBigInt); 495 493 begin 496 494 Memory.Write(PC, Size, Value); … … 517 515 Regs[I] := 0; 518 516 PC := 0; 517 SP := 0; 519 518 Terminated := False; 520 519 end; -
branches/ByteArray/Devices/DeviceMapper.pas
r45 r47 25 25 procedure RegisterDevice(Device: TDevice); 26 26 procedure UnregisterDevice(Device: TDevice); 27 function Read(Address: TBigInt; Size: Byte): TBigInt;28 procedure Write(Address: TBigInt; Size: Byte; Value: TBigInt);27 function Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 28 procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 29 29 procedure SetChannel(Channel: TChannel); 30 30 constructor Create; … … 74 74 end; 75 75 76 function TDeviceMapper.Read(Address: TBigInt; Size: Byte): TBigInt;76 function TDeviceMapper.Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 77 77 var 78 78 I: Integer; … … 85 85 end; 86 86 87 procedure TDeviceMapper.Write(Address: TBigInt; Size: Byte; Value: TBigInt);87 procedure TDeviceMapper.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 88 88 var 89 89 I: Integer; -
branches/ByteArray/Devices/FrameBuffer.pas
r45 r47 22 22 Mode: TScreenMode; 23 23 procedure UpdateMode; 24 function Read(Address: TBigInt; Size: Byte): TBigInt;25 procedure Write(Address: TBigInt; Size: Byte; Value: TBigInt);24 function Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 25 procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 26 26 function GetAddressCount: Integer; override; 27 27 procedure SetChannel(Channel: TChannel); override; … … 47 47 end; 48 48 49 function TFrameBuffer.Read(Address: TBigInt; Size: Byte): TBigInt;49 function TFrameBuffer.Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 50 50 begin 51 51 case Integer(Address) of … … 61 61 end; 62 62 63 procedure TFrameBuffer.Write(Address: TBigInt; Size: Byte; Value: TBigInt);63 procedure TFrameBuffer.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 64 64 begin 65 65 case Integer(Address) of -
branches/ByteArray/Devices/Memory.pas
r46 r47 17 17 public 18 18 Position: Integer; 19 function Read(Address: TBigInt; Size: Byte): TBigInt;20 function ReadPos( Size: Byte): TBigInt;21 procedure Write(Address: TBigInt; Size: Byte; Value: TBigInt);22 procedure WritePos( Size: Byte; Value: TBigInt);19 function Read(Address: TBigInt; ASize: TBigIntSize): TBigInt; 20 function ReadPos(ASize: Byte): TBigInt; 21 procedure Write(Address: TBigInt; ASize: TBigIntSize; Value: TBigInt); 22 procedure WritePos(ASize: Byte; Value: TBigInt); 23 23 procedure WriteStringPos(Value: string); 24 24 function GetAddressCount: Integer; override; … … 30 30 31 31 implementation 32 33 resourcestring 34 SOutOfRange = 'Out of range'; 32 35 33 36 { TMemory } … … 43 46 end; 44 47 45 function TMemory.Read(Address: TBigInt; Size: Byte): TBigInt;48 function TMemory.Read(Address: TBigInt; ASize: TBigIntSize): TBigInt; 46 49 begin 47 case Size of 50 if Address + ASize >= Size then raise Exception.Create(SOutOfRange); 51 case ASize of 48 52 1: Result := PByte(FData + Integer(Address))^; 49 53 2: Result := PWord(FData + Integer(Address))^; … … 53 57 end; 54 58 55 function TMemory.ReadPos( Size: Byte): TBigInt;59 function TMemory.ReadPos(ASize: Byte): TBigInt; 56 60 begin 57 Result := Read(Position, Size);61 Result := Read(Position, ASize); 58 62 end; 59 63 60 procedure TMemory.Write(Address: TBigInt; Size: Byte; Value: TBigInt);64 procedure TMemory.Write(Address: TBigInt; ASize: TBigIntSize; Value: TBigInt); 61 65 begin 62 case Size of 66 if Address + ASize >= Size then raise Exception.Create(SOutOfRange); 67 case ASize of 63 68 1: PByte(FData + Integer(Address))^ := Value; 64 69 2: PWord(FData + Integer(Address))^ := Value; … … 68 73 end; 69 74 70 procedure TMemory.WritePos( Size: Byte; Value: TBigInt);75 procedure TMemory.WritePos(ASize: Byte; Value: TBigInt); 71 76 begin 72 Write(Position, Size, Value);77 Write(Position, ASize, Value); 73 78 end; 74 79 -
branches/ByteArray/Devices/Serial.pas
r45 r47 17 17 FOnWrite: TWriteEvent; 18 18 public 19 function Read(Address: TBigInt; Size: Byte): TBigInt;20 procedure Write(Address: TBigInt; Size: Byte; Value: TBigInt);19 function Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 20 procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 21 21 function GetAddressCount: Integer; override; 22 22 procedure SetChannel(Channel: TChannel); override; … … 30 30 { TSerial } 31 31 32 function TSerial.Read(Address: TBigInt; Size: Byte): TBigInt;32 function TSerial.Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 33 33 begin 34 34 case Integer(Address) of … … 37 37 end; 38 38 39 procedure TSerial.Write(Address: TBigInt; Size: Byte; Value: TBigInt);39 procedure TSerial.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 40 40 begin 41 41 case Integer(Address) of -
branches/ByteArray/Devices/Storage.pas
r45 r47 17 17 FFile: TFileStream; 18 18 Position: Integer; 19 function Read(Address: TBigInt; Size: Byte): TBigInt;20 procedure Write(Address: TBigInt; Size: Byte; Value: TBigInt);19 function Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 20 procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 21 21 function GetAddressCount: Integer; override; 22 22 procedure SetChannel(Channel: TChannel); override; … … 42 42 end; 43 43 44 function TStorage.Read(Address: TBigInt; Size: Byte): TBigInt;44 function TStorage.Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 45 45 var 46 46 Buffer: array of Byte; … … 59 59 end; 60 60 61 procedure TStorage.Write(Address: TBigInt; Size: Byte; Value: TBigInt);61 procedure TStorage.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 62 62 var 63 63 Buffer: array of Byte; -
branches/ByteArray/Forms/FormSourceEditor.lfm
r46 r47 5 5 Width = 926 6 6 Caption = 'Source editor' 7 ClientHeight = 6 817 ClientHeight = 647 8 8 ClientWidth = 926 9 9 DesignTimePPI = 144 10 Menu = MainMenu1 10 11 OnCreate = FormCreate 11 12 OnDestroy = FormDestroy … … 14 15 object PanelCenter: TPanel 15 16 Left = 0 16 Height = 51317 Height = 479 17 18 Top = 0 18 19 Width = 926 … … 25 26 Left = 0 26 27 Height = 8 27 Top = 51328 Top = 479 28 29 Width = 926 29 30 Align = alBottom … … 33 34 Left = 0 34 35 Height = 160 35 Top = 52136 Top = 487 36 37 Width = 926 37 38 Align = alBottom … … 39 40 TabOrder = 2 40 41 end 42 object MainMenu1: TMainMenu 43 Left = 472 44 Top = 144 45 object MenuItem1: TMenuItem 46 Caption = 'File' 47 object MenuItem2: TMenuItem 48 Action = ANew 49 end 50 object MenuItem3: TMenuItem 51 Action = AOpen 52 end 53 object MenuItem4: TMenuItem 54 Action = AOpenRecent 55 end 56 object MenuItem5: TMenuItem 57 Action = ASave 58 end 59 object MenuItem6: TMenuItem 60 Action = ASaveAs 61 end 62 object MenuItem7: TMenuItem 63 Action = AClose 64 end 65 object Separator1: TMenuItem 66 Caption = '-' 67 end 68 object MenuItem8: TMenuItem 69 Action = AExit 70 end 71 end 72 end 73 object ActionList1: TActionList 74 Left = 618 75 Top = 147 76 object AExit: TAction 77 Caption = 'Exit' 78 OnExecute = AExitExecute 79 end 80 object ANew: TAction 81 Caption = 'New' 82 OnExecute = ANewExecute 83 end 84 object AOpen: TAction 85 Caption = 'Open' 86 OnExecute = AOpenExecute 87 ShortCut = 16463 88 end 89 object AOpenRecent: TAction 90 Caption = 'Open recent' 91 end 92 object ASave: TAction 93 Caption = 'Save' 94 OnExecute = ASaveExecute 95 ShortCut = 16467 96 end 97 object ASaveAs: TAction 98 Caption = 'Save as...' 99 OnExecute = ASaveAsExecute 100 end 101 object AClose: TAction 102 Caption = 'Close' 103 OnExecute = ACloseExecute 104 end 105 end 41 106 end -
branches/ByteArray/Forms/FormSourceEditor.pas
r46 r47 4 4 5 5 uses 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, FormMessages,7 FormAssembler;6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Menus, 7 ActnList, FormMessages, FormAssembler, Project; 8 8 9 9 type … … 12 12 13 13 TFormSourceEditor = class(TForm) 14 AClose: TAction; 15 ANew: TAction; 16 ASaveAs: TAction; 17 ASave: TAction; 18 AOpenRecent: TAction; 19 AOpen: TAction; 20 AExit: TAction; 21 ActionList1: TActionList; 22 MainMenu1: TMainMenu; 23 MenuItem1: TMenuItem; 24 MenuItem2: TMenuItem; 25 MenuItem3: TMenuItem; 26 MenuItem4: TMenuItem; 27 MenuItem5: TMenuItem; 28 MenuItem6: TMenuItem; 29 MenuItem7: TMenuItem; 30 MenuItem8: TMenuItem; 31 Separator1: TMenuItem; 14 32 PanelBottom: TPanel; 15 33 PanelCenter: TPanel; 16 34 Splitter1: TSplitter; 35 procedure ACloseExecute(Sender: TObject); 36 procedure AExitExecute(Sender: TObject); 37 procedure ANewExecute(Sender: TObject); 38 procedure AOpenExecute(Sender: TObject); 39 procedure ASaveAsExecute(Sender: TObject); 40 procedure ASaveExecute(Sender: TObject); 17 41 procedure FormCreate(Sender: TObject); 18 42 procedure FormDestroy(Sender: TObject); 19 43 procedure FormShow(Sender: TObject); 20 private21 22 44 public 23 45 FormMessages: TFormMessages; 24 46 FormAssembler: TFormAssembler; 47 Project: TProject; 25 48 procedure DockInit; 49 procedure UpdateInterface; 26 50 end; 27 51 … … 41 65 FormAssembler := TFormAssembler.Create(nil); 42 66 FormMessages.OnSelect := FormAssembler.Select; 67 end; 68 69 procedure TFormSourceEditor.AExitExecute(Sender: TObject); 70 begin 71 Close; 72 end; 73 74 procedure TFormSourceEditor.ANewExecute(Sender: TObject); 75 begin 76 Project.New; 77 end; 78 79 procedure TFormSourceEditor.ACloseExecute(Sender: TObject); 80 begin 81 Project.Close; 82 end; 83 84 procedure TFormSourceEditor.AOpenExecute(Sender: TObject); 85 var 86 OpenDialog: TOpenDialog; 87 begin 88 OpenDialog := TOpenDialog.Create(nil); 89 try 90 if OpenDialog.Execute then 91 Project.Open(OpenDialog.FileName); 92 finally 93 OpenDialog.Free; 94 end; 95 end; 96 97 procedure TFormSourceEditor.ASaveAsExecute(Sender: TObject); 98 var 99 SaveDialog: TSaveDialog; 100 begin 101 SaveDialog := TSaveDialog.Create(nil); 102 try 103 if SaveDialog.Execute then 104 Project.SaveAs(SaveDialog.FileName); 105 finally 106 SaveDialog.Free; 107 end; 108 end; 109 110 procedure TFormSourceEditor.ASaveExecute(Sender: TObject); 111 begin 112 Project.Save; 43 113 end; 44 114 … … 62 132 end; 63 133 134 procedure TFormSourceEditor.UpdateInterface; 135 begin 136 137 end; 138 64 139 end. 65 140
Note:
See TracChangeset
for help on using the changeset viewer.