source: branches/simple/Pin.pas

Last change on this file was 42, checked in by chronos, 8 months ago
  • Modified: Improved simple virtual machine.
File size: 1.0 KB
Line 
1unit Pin;
2
3interface
4
5uses
6 Classes, SysUtils;
7
8type
9 TWriteEvent = procedure (Data: Byte) of object;
10 TReadEvent = function: Byte of object;
11
12 { TPin }
13
14 TPin = class
15 private
16 FOnRead: TReadEvent;
17 FOnWrite: TWriteEvent;
18 FAnother: TPin;
19 public
20 procedure Write(Data: Byte);
21 function Read: Byte;
22 procedure Disconnect;
23 procedure Connect(Pin: TPin);
24 property OnWrite: TWriteEvent read FOnWrite write FOnWrite;
25 property OnRead: TReadEvent read FOnRead write FOnRead;
26 end;
27
28 TPin8 = class(TPin)
29 end;
30
31
32implementation
33
34{ TPin }
35
36procedure TPin.Write(Data: Byte);
37begin
38 if Assigned(FAnother) then FAnother.Write(Data);
39end;
40
41function TPin.Read: Byte;
42begin
43 if Assigned(FAnother) then Result := FAnother.Read
44 else Result := 0;
45end;
46
47procedure TPin.Disconnect;
48begin
49 if Assigned(FAnother) then begin
50 FAnother.FAnother := nil;
51 FAnother := nil;
52 end;
53end;
54
55procedure TPin.Connect(Pin: TPin);
56begin
57 if Assigned(FAnother) then Disconnect;
58 FAnother := Pin;
59 Pin.FAnother := Self;
60end;
61
62end.
63
Note: See TracBrowser for help on using the repository browser.