Changeset 42 for branches/simple/Devices


Ignore:
Timestamp:
Sep 8, 2023, 11:20:27 PM (15 months ago)
Author:
chronos
Message:
  • Modified: Improved simple virtual machine.
Location:
branches/simple/Devices
Files:
2 added
3 moved

Legend:

Unmodified
Added
Removed
  • branches/simple/Devices/Console.pas

    r41 r42  
    44
    55uses
    6   Classes, SysUtils, Device, DeviceMapper;
     6  Classes, SysUtils, Device, DeviceManager, Channel;
    77
    88type
    9   { TConsole }
    109
    11   TConsole = class(TDevice16)
     10  { TConsole8 }
     11
     12  TConsole8 = class(TDevice8)
    1213  private
    1314    FOnRead: TReadEvent8;
     
    1617    function Read8: Byte;
    1718  public
    18     procedure RegisterMapper8(Mapper: TDeviceMapper8); override;
    19     procedure RegisterMapper16(Mapper: TDeviceMapper16); override;
     19    function GetHandlerCount: Integer; override;
     20    function GetHandler(Address: Integer): TChannel8; override;
     21    property OnWrite: TWriteEvent8 read FOnWrite write FOnWrite;
     22    property OnRead: TReadEvent8 read FOnRead write FOnRead;
     23  end;
     24
     25  { TConsole16 }
     26
     27  TConsole16 = class(TDevice16)
     28  private
     29    FOnRead: TReadEvent8;
     30    FOnWrite: TWriteEvent8;
     31    procedure Write8(Data: Byte);
     32    function Read8: Byte;
     33  public
     34    function GetHandlerCount: Integer; override;
     35    function GetHandler(Address: Integer): TChannel16; override;
    2036    property OnWrite: TWriteEvent8 read FOnWrite write FOnWrite;
    2137    property OnRead: TReadEvent8 read FOnRead write FOnRead;
     
    2541implementation
    2642
    27 { TConsole }
     43{ TConsole8 }
    2844
    29 procedure TConsole.RegisterMapper8(Mapper: TDeviceMapper8);
    30 begin
    31   Mapper.RegisterReadHandler(Read8);
    32   Mapper.RegisterWriteHandler(Write8);
    33 end;
    34 
    35 procedure TConsole.RegisterMapper16(Mapper: TDeviceMapper16);
    36 begin
    37   Mapper.RegisterReadHandler(Read8, nil);
    38   Mapper.RegisterWriteHandler(Write8, nil);
    39 end;
    40 
    41 procedure TConsole.Write8(Data: Byte);
     45procedure TConsole8.Write8(Data: Byte);
    4246begin
    4347  if Assigned(FOnWrite) then FOnWrite(Data);
    4448end;
    4549
    46 function TConsole.Read8: Byte;
     50function TConsole8.Read8: Byte;
    4751begin
    4852  if Assigned(FOnRead) then Result := FOnRead
     
    5054end;
    5155
     56function TConsole8.GetHandlerCount: Integer;
     57begin
     58  Result := 1;
     59end;
     60
     61function TConsole8.GetHandler(Address: Integer): TChannel8;
     62begin
     63  if Address = 0 then begin
     64    Result := TChannel8.Create;
     65    Result.Read8 := Read8;
     66    Result.Write8 := Write8;
     67  end;
     68end;
     69
     70{ TConsole16 }
     71
     72procedure TConsole16.Write8(Data: Byte);
     73begin
     74  if Assigned(FOnWrite) then FOnWrite(Data);
     75end;
     76
     77function TConsole16.Read8: Byte;
     78begin
     79  if Assigned(FOnRead) then Result := FOnRead
     80    else Result := 0;
     81end;
     82
     83function TConsole16.GetHandlerCount: Integer;
     84begin
     85  Result := 1;
     86end;
     87
     88function TConsole16.GetHandler(Address: Integer): TChannel16;
     89begin
     90  if Address = 0 then begin
     91    Result := TChannel16.Create;
     92    Result.Read8 := Read8;
     93    Result.Write8 := Write8;
     94  end;
     95end;
    5296
    5397end.
  • branches/simple/Devices/Device.pas

    r41 r42  
    44
    55uses
    6   Classes, SysUtils, DeviceMapper;
     6  Classes, SysUtils, Channel, Generics.Collections, Forms;
    77
    88type
     9  TDeviceClass = (dcNone, dcKeyboard, dcMouse, dcStorage, dcScreen, dcConsole,
     10    dcTimer);
     11  TDeviceClassSet = set of TDeviceClass;
     12
    913  { TDevice8 }
    1014
    1115  TDevice8 = class
    12     procedure RegisterMapper8(Mapper: TDeviceMapper8); virtual; abstract;
     16    BaseAddress: Byte;
     17    procedure SetDataBus(Channel: TAddressableChannel8); virtual;
     18    function GetHandlerCount: Integer; virtual;
     19    function GetHandler(Address: Integer): TChannel8; virtual;
    1320  end;
    1421
     
    1623
    1724  TDevice16 = class
    18     procedure RegisterMapper8(Mapper: TDeviceMapper8); virtual; abstract;
    19     procedure RegisterMapper16(Mapper: TDeviceMapper16); virtual; abstract;
     25    BaseAddress: Word;
     26    procedure SetDataBus(Channel: TAddressableChannel16); virtual;
     27    function GetHandlerCount: Integer; virtual;
     28    function GetHandler(Address: Integer): TChannel16; virtual;
    2029  end;
     30
     31  { TDevice32 }
     32
     33  TDevice32 = class
     34    BaseAddress: DWord;
     35    procedure SetDataBus(Channel: TAddressableChannel32); virtual;
     36    function GetHandlerCount: Integer; virtual;
     37    function GetHandler(Address: Integer): TChannel32; virtual;
     38  end;
     39
     40  { TDevice64 }
     41
     42  TDevice64 = class
     43    BaseAddress: QWord;
     44    procedure SetDataBus(Channel: TAddressableChannel64); virtual;
     45    function GetHandlerCount: Integer; virtual;
     46    function GetHandler(Address: Integer): TChannel64; virtual;
     47  end;
     48
     49  TDevice = class;
     50
     51  { TFormDevice }
     52
     53  TFormDevice = class(TForm)
     54  protected
     55    function GetDevice: TDevice; virtual;
     56    procedure SetDevice(AValue: TDevice); virtual;
     57  public
     58    property Device: TDevice read GetDevice write SetDevice;
     59  end;
     60
     61  TFormDeviceClass = class of TFormDevice;
     62
     63  { TDevice }
     64
     65  TDevice = class
     66    Name: string;
     67    DeviceClass: TDeviceClass;
     68    Form: TFormDevice;
     69  end;
     70
     71  { TDevices }
     72
     73  TDevices = class(TObjectList<TDevice>)
     74    function GetDevicesCountByClass(DeviceClass: TDeviceClass): Integer;
     75    function GetDevicesByClass(DeviceClass: TDeviceClass): TDevices;
     76    function GetClasses: TDeviceClassSet;
     77  end;
     78
     79const
     80  DeviceClassText: array[TDeviceClass] of string = ('None', 'Keyboard', 'Mouse', 'Storage', 'Screen', 'Console', 'Timer');
    2181
    2282
    2383implementation
    2484
     85{ TFormDevice }
     86
     87function TFormDevice.GetDevice: TDevice;
     88begin
     89  Result := nil;
     90end;
     91
     92procedure TFormDevice.SetDevice(AValue: TDevice);
     93begin
     94end;
     95
     96{ TDevices }
     97
     98function TDevices.GetDevicesCountByClass(DeviceClass: TDeviceClass): Integer;
     99var
     100  I: Integer;
     101begin
     102  Result := 0;
     103  for I := 0 to Count - 1 do
     104    if Items[I].DeviceClass = DeviceClass then Inc(Result);
     105end;
     106
     107function TDevices.GetDevicesByClass(DeviceClass: TDeviceClass): TDevices;
     108var
     109  I: Integer;
     110begin
     111  Result := TDevices.Create(False);
     112  for I := 0 to Count - 1 do
     113    if Items[I].DeviceClass = DeviceClass then Result.Add(Items[I])
     114end;
     115
     116function TDevices.GetClasses: TDeviceClassSet;
     117var
     118  I: Integer;
     119begin
     120  Result := [];
     121  for I := 0 to Count - 1 do
     122    if not (Items[I].DeviceClass in Result) then
     123      Result := Result + [Items[I].DeviceClass];
     124end;
     125
     126{ TDevice32 }
     127
     128procedure TDevice32.SetDataBus(Channel: TAddressableChannel32);
     129begin
     130end;
     131
     132function TDevice32.GetHandlerCount: Integer;
     133begin
     134  Result := 0;
     135end;
     136
     137function TDevice32.GetHandler(Address: Integer): TChannel32;
     138begin
     139end;
     140
     141{ TDevice64 }
     142
     143procedure TDevice64.SetDataBus(Channel: TAddressableChannel64);
     144begin
     145end;
     146
     147function TDevice64.GetHandlerCount: Integer;
     148begin
     149  Result := 0;
     150end;
     151
     152function TDevice64.GetHandler(Address: Integer): TChannel64;
     153begin
     154end;
     155
     156{ TDevice8 }
     157
     158procedure TDevice8.SetDataBus(Channel: TAddressableChannel8);
     159begin
     160end;
     161
     162function TDevice8.GetHandlerCount: Integer;
     163begin
     164  Result := 0;
     165end;
     166
     167function TDevice8.GetHandler(Address: Integer): TChannel8;
     168begin
     169end;
     170
     171{ TDevice16 }
     172
     173procedure TDevice16.SetDataBus(Channel: TAddressableChannel16);
     174begin
     175end;
     176
     177function TDevice16.GetHandlerCount: Integer;
     178begin
     179  Result := 0;
     180end;
     181
     182function TDevice16.GetHandler(Address: Integer): TChannel16;
     183begin
     184end;
     185
    25186end.
    26187
  • branches/simple/Devices/Screen.pas

    r41 r42  
    44
    55uses
    6   Classes, SysUtils, Device, DeviceMapper, Memory;
     6  Classes, SysUtils, Device, DeviceManager, Memory, Channel;
    77
    88type
     
    3131    constructor Create;
    3232    destructor Destroy; override;
    33     procedure RegisterMapper8(Mapper: TDeviceMapper8); override;
     33    function GetHandlerCount: Integer; override;
     34    function GetHandler(Address: Integer): TChannel8; override;
    3435    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    3536  end;
     
    5960    constructor Create;
    6061    destructor Destroy; override;
    61     procedure RegisterMapper8(Mapper: TDeviceMapper8); override;
    62     procedure RegisterMapper16(Mapper: TDeviceMapper16); override;
     62    function GetHandlerCount: Integer; override;
     63    function GetHandler(Address: Integer): TChannel16; override;
    6364    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    6465  end;
    6566
     67  TScreen = class(TDevice)
     68    BitWidth: TBitWidth;
     69    Screen8: TScreen8;
     70    Screen16: TScreen16;
     71    constructor Create(BitWidth: TBitWidth; Screen8: TScreen8; Screen16: TScreen16);
     72  end;
     73
    6674
    6775implementation
     76
     77{ TScreen }
     78
     79constructor TScreen.Create(BitWidth: TBitWidth; Screen8: TScreen8;
     80  Screen16: TScreen16);
     81begin
     82  Self.BitWidth := BitWidth;
     83  Self.Screen8 := Screen8;
     84  Self.Screen16 := Screen16;
     85end;
    6886
    6987{ TScreen16 }
     
    149167end;
    150168
    151 procedure TScreen16.RegisterMapper8(Mapper: TDeviceMapper8);
    152 begin
    153 end;
    154 
    155 procedure TScreen16.RegisterMapper16(Mapper: TDeviceMapper16);
    156 begin
    157   Mapper.RegisterReadHandler(ReadData8, ReadData16);
    158   Mapper.RegisterWriteHandler(WriteData8, WriteData16);
    159   Mapper.RegisterReadHandler(nil, ReadAddr16);
    160   Mapper.RegisterWriteHandler(nil, WriteAddr16);
    161   Mapper.RegisterReadHandler(nil, ReadWidth16);
    162   Mapper.RegisterWriteHandler(nil, WriteWidth16);
    163   Mapper.RegisterReadHandler(nil, ReadHeight16);
    164   Mapper.RegisterWriteHandler(nil, WriteHeight16);
     169function TScreen16.GetHandlerCount: Integer;
     170begin
     171  Result := 4;
     172end;
     173
     174function TScreen16.GetHandler(Address: Integer): TChannel16;
     175begin
     176  if Address = 0 then begin
     177    Result := TChannel16.Create;
     178    Result.Read16 := ReadData16;
     179    Result.Write16 := WriteData16;
     180  end else
     181  if Address = 1 then begin
     182    Result := TChannel16.Create;
     183    Result.Read16 := ReadAddr16;
     184    Result.Write16 := WriteAddr16;
     185  end else
     186  if Address = 2 then begin
     187    Result := TChannel16.Create;
     188    Result.Read16 := ReadWidth16;
     189    Result.Write16 := WriteWidth16;
     190  end else
     191  if Address = 3 then begin
     192    Result := TChannel16.Create;
     193    Result.Read16 := ReadHeight16;
     194    Result.Write16 := WriteHeight16;
     195  end;
    165196end;
    166197
     
    236267end;
    237268
    238 procedure TScreen8.RegisterMapper8(Mapper: TDeviceMapper8);
    239 begin
    240   Mapper.RegisterReadHandler(ReadData8);
    241   Mapper.RegisterWriteHandler(WriteData8);
    242   Mapper.RegisterReadHandler(ReadAddr8);
    243   Mapper.RegisterWriteHandler(WriteAddr8);
    244   Mapper.RegisterReadHandler(ReadWidth8);
    245   Mapper.RegisterWriteHandler(WriteWidth8);
    246   Mapper.RegisterReadHandler(ReadHeight8);
    247   Mapper.RegisterWriteHandler(WriteHeight8);
     269function TScreen8.GetHandlerCount: Integer;
     270begin
     271  Result := 4;
     272end;
     273
     274function TScreen8.GetHandler(Address: Integer): TChannel8;
     275begin
     276  if Address = 0 then begin
     277    Result := TChannel8.Create;
     278    Result.Read8 := ReadData8;
     279    Result.Write8 := WriteData8;
     280  end else
     281  if Address = 1 then begin
     282    Result := TChannel8.Create;
     283    Result.Read8 := ReadAddr8;
     284    Result.Write8 := WriteAddr8;
     285  end else
     286  if Address = 2 then begin
     287    Result := TChannel8.Create;
     288    Result.Read8 := ReadWidth8;
     289    Result.Write8 := WriteWidth8;
     290  end else
     291  if Address = 3 then begin
     292    Result := TChannel8.Create;
     293    Result.Read8 := ReadHeight8;
     294    Result.Write8 := WriteHeight8;
     295  end;
    248296end;
    249297
Note: See TracChangeset for help on using the changeset viewer.