source: branches/virtualcpu4/UMemory.pas

Last change on this file was 180, checked in by chronos, 5 years ago
  • Modified: Memory dump, CPU state, screen, console moved to separate forms.
  • Added: Dissasembler form.
File size: 1.5 KB
Line 
1unit UMemory;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils;
9
10type
11
12 { TMemory }
13
14 TMemory = class
15 private
16 FData: Pointer;
17 FOwner: Boolean;
18 FSize: Integer;
19 procedure SetData(AValue: Pointer);
20 procedure SetSize(AValue: Integer);
21 public
22 property Owner: Boolean read FOwner write FOwner;
23 property Data: Pointer read FData write SetData;
24 property Size: Integer read FSize write SetSize;
25 end;
26
27 { TMemoryStream }
28
29 TMemoryPos = class(TMemory)
30 Position: Pointer;
31 function ReadByte: Byte;
32 function ReadWord: Word;
33 procedure WriteByte(Value: Byte);
34 procedure WriteWord(Value: Word);
35 end;
36
37implementation
38
39{ TMemoryStream }
40
41function TMemoryPos.ReadByte: Byte;
42begin
43 Result := PByte(Position)^;
44 Inc(Position, SizeOf(Byte));
45end;
46
47function TMemoryPos.ReadWord: Word;
48begin
49 Result := PWord(Position)^;
50 Inc(Position, SizeOf(Word));
51end;
52
53procedure TMemoryPos.WriteByte(Value: Byte);
54begin
55 PByte(Position)^ := Value;
56 Inc(Position, SizeOf(Byte));
57end;
58
59procedure TMemoryPos.WriteWord(Value: Word);
60begin
61 PWord(Position)^ := Value;
62 Inc(Position, SizeOf(Word));
63end;
64
65{ TMemory }
66
67procedure TMemory.SetSize(AValue: Integer);
68begin
69 if FSize = AValue then Exit;
70 FSize := AValue;
71 FData := ReAllocMem(FData, FSize);
72end;
73
74procedure TMemory.SetData(AValue: Pointer);
75begin
76 if FData = AValue then Exit;
77 if FOwner then FreeMem(FData);
78 FData := AValue;
79 if Assigned(FData) then FSize := MemSize(FData)
80 else FSize := 0;
81end;
82
83end.
84
Note: See TracBrowser for help on using the repository browser.