| 1 | unit FormMain;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Cpu;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | UInt24 = DWord;
|
|---|
| 10 |
|
|---|
| 11 | TCpu8 = TCpu<Byte,Byte,Byte>;
|
|---|
| 12 | TCpu8A16 = TCpu<Byte,Word,Word>;
|
|---|
| 13 | TCpu8A32 = TCpu<Byte,DWord,DWord>;
|
|---|
| 14 | TCpu8A64 = TCpu<Byte,QWord,QWord>;
|
|---|
| 15 | TCpu16 = TCpu<Word,Word,Word>;
|
|---|
| 16 | TCpu16A32 = TCpu<Word,DWord,DWord>;
|
|---|
| 17 | TCpu16A64 = TCpu<Word,QWord,QWord>;
|
|---|
| 18 | TCpu24 = TCpu<UInt24,UInt24,UInt24>;
|
|---|
| 19 | TCpu64 = TCpu<QWord,QWord,QWord>;
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | { TFormMain }
|
|---|
| 23 |
|
|---|
| 24 | TFormMain = class(TForm)
|
|---|
| 25 | Memo1: TMemo;
|
|---|
| 26 | procedure FormCreate(Sender: TObject);
|
|---|
| 27 | procedure FormDestroy(Sender: TObject);
|
|---|
| 28 | procedure FormShow(Sender: TObject);
|
|---|
| 29 | private
|
|---|
| 30 | Buffer: Word;
|
|---|
| 31 | procedure CpuOutput(Addr: Word; Data: Word; Count: Byte);
|
|---|
| 32 | function CpuInput(Addr: Word; Count: Byte): Word;
|
|---|
| 33 | public
|
|---|
| 34 | Cpu: TCpu16;
|
|---|
| 35 | end;
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | var
|
|---|
| 39 | FormMain: TFormMain;
|
|---|
| 40 |
|
|---|
| 41 | implementation
|
|---|
| 42 |
|
|---|
| 43 | {$R *.lfm}
|
|---|
| 44 |
|
|---|
| 45 | { TFormMain }
|
|---|
| 46 |
|
|---|
| 47 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 48 | begin
|
|---|
| 49 | Cpu := TCpu16.Create;
|
|---|
| 50 | Cpu.OnInput := CpuInput;
|
|---|
| 51 | Cpu.OnOutput := CpuOutput;
|
|---|
| 52 | end;
|
|---|
| 53 |
|
|---|
| 54 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 55 | begin
|
|---|
| 56 | FreeAndNil(Cpu);
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 60 | begin
|
|---|
| 61 | with Cpu do begin
|
|---|
| 62 | AddConstN(2, 0, $abcd);
|
|---|
| 63 | AddOutputN(2, 0, 0);
|
|---|
| 64 | AddHalt;
|
|---|
| 65 | Run;
|
|---|
| 66 | Memo1.Lines.Add(IntToHex(Buffer));
|
|---|
| 67 | end;
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 | procedure TFormMain.CpuOutput(Addr: Word; Data: Word; Count: Byte);
|
|---|
| 71 | begin
|
|---|
| 72 | case Addr of
|
|---|
| 73 | 0: Buffer := Data;
|
|---|
| 74 | end;
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | function TFormMain.CpuInput(Addr: Word; Count: Byte): Word;
|
|---|
| 78 | begin
|
|---|
| 79 | case Addr of
|
|---|
| 80 | 0: Result := Buffer;
|
|---|
| 81 | end;
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | end.
|
|---|
| 85 |
|
|---|