|
Last change
on this file was 42, checked in by chronos, 2 years ago |
- Modified: Improved simple virtual machine.
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 1 | unit Pin;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 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 |
|
|---|
| 32 | implementation
|
|---|
| 33 |
|
|---|
| 34 | { TPin }
|
|---|
| 35 |
|
|---|
| 36 | procedure TPin.Write(Data: Byte);
|
|---|
| 37 | begin
|
|---|
| 38 | if Assigned(FAnother) then FAnother.Write(Data);
|
|---|
| 39 | end;
|
|---|
| 40 |
|
|---|
| 41 | function TPin.Read: Byte;
|
|---|
| 42 | begin
|
|---|
| 43 | if Assigned(FAnother) then Result := FAnother.Read
|
|---|
| 44 | else Result := 0;
|
|---|
| 45 | end;
|
|---|
| 46 |
|
|---|
| 47 | procedure TPin.Disconnect;
|
|---|
| 48 | begin
|
|---|
| 49 | if Assigned(FAnother) then begin
|
|---|
| 50 | FAnother.FAnother := nil;
|
|---|
| 51 | FAnother := nil;
|
|---|
| 52 | end;
|
|---|
| 53 | end;
|
|---|
| 54 |
|
|---|
| 55 | procedure TPin.Connect(Pin: TPin);
|
|---|
| 56 | begin
|
|---|
| 57 | if Assigned(FAnother) then Disconnect;
|
|---|
| 58 | FAnother := Pin;
|
|---|
| 59 | Pin.FAnother := Self;
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | end.
|
|---|
| 63 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.