1 | unit Kernel.Core;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Kernel.List, Kernel.FileSystem, Kernel.Memory,
|
---|
7 | Kernel.Screen, Kernel.Device, Kernel.App, Kernel.Scheduler, Kernel.Api,
|
---|
8 | Kernel.Graphics, Generics.Collections, Kernel.IPC;
|
---|
9 |
|
---|
10 | type
|
---|
11 | { TDrive }
|
---|
12 |
|
---|
13 | TDrive = class(TNamedObject)
|
---|
14 | FileSystem: TFileSystem;
|
---|
15 | constructor Create;
|
---|
16 | destructor Destroy; override;
|
---|
17 | end;
|
---|
18 |
|
---|
19 | // TTimer = class
|
---|
20 | // Period: TDateTime;
|
---|
21 | // end;
|
---|
22 |
|
---|
23 | { TKernel }
|
---|
24 |
|
---|
25 | TKernel = class
|
---|
26 | private
|
---|
27 | Api: TSystemApi;
|
---|
28 | procedure InitVideo;
|
---|
29 | function KernelApiExecute(Command: TApiCommand; Data: Pointer): Pointer;
|
---|
30 | public
|
---|
31 | Apps: TNamedObjects<TApp>;
|
---|
32 | Drives: TNamedObjects<TDrive>;
|
---|
33 | Scheduler: TScheduler;
|
---|
34 | SchedulerClass: TSchedulerClass;
|
---|
35 | FileSystemClass: TFileSystemClass;
|
---|
36 | Devices: TNamedObjects<TDevice>;
|
---|
37 | Screens: TObjectList<TScreen>;
|
---|
38 | Desktop: TDesktop;
|
---|
39 | procedure AppExecute(AFile: TFile);
|
---|
40 | procedure Init;
|
---|
41 | procedure Run;
|
---|
42 | procedure Terminate;
|
---|
43 | constructor Create;
|
---|
44 | destructor Destroy; override;
|
---|
45 | end;
|
---|
46 |
|
---|
47 |
|
---|
48 | implementation
|
---|
49 |
|
---|
50 | uses
|
---|
51 | Kernel.KernelAPI;
|
---|
52 |
|
---|
53 | { TDrive }
|
---|
54 |
|
---|
55 | constructor TDrive.Create;
|
---|
56 | begin
|
---|
57 | end;
|
---|
58 |
|
---|
59 | destructor TDrive.Destroy;
|
---|
60 | begin
|
---|
61 | FreeAndNil(FileSystem);
|
---|
62 | inherited;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | { TKernel }
|
---|
66 |
|
---|
67 | procedure TKernel.InitVideo;
|
---|
68 | var
|
---|
69 | NewScreen: TScreen;
|
---|
70 | VideoDevice: TDeviceVideo;
|
---|
71 | VideoMode: TVideoMode;
|
---|
72 | Modes: TVideoModes;
|
---|
73 | begin
|
---|
74 | VideoDevice := TDeviceVideo(Devices.FindByName('Video0'));
|
---|
75 | if Assigned(VideoDevice) then begin
|
---|
76 | NewScreen := TScreen.Create;
|
---|
77 | Modes := TVideoModes.Create;
|
---|
78 | VideoDevice.GetSupportedModes(Modes);
|
---|
79 | if Modes.Count > 0 then begin
|
---|
80 | VideoMode := TVideoMode(Modes.Last);
|
---|
81 | VideoDevice.VideoMode := VideoMode;
|
---|
82 | NewScreen.Size := VideoMode.Size;
|
---|
83 | NewScreen.ColorFormat := VideoMode.ColorFormat;
|
---|
84 | NewScreen.Device := VideoDevice;
|
---|
85 | NewScreen.Canvas := TScreenCanvas.Create;
|
---|
86 | TScreenCanvas(NewScreen.Canvas).Screen := NewScreen;
|
---|
87 | Screens.Add(NewScreen);
|
---|
88 | Desktop.ParentCanvas := Screens.First.Canvas;
|
---|
89 | end;
|
---|
90 | Modes.Free;
|
---|
91 | end;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | function TKernel.KernelApiExecute(Command: TApiCommand;
|
---|
95 | Data: Pointer): Pointer;
|
---|
96 | begin
|
---|
97 | Result := Api.Call(Command, Data);
|
---|
98 | end;
|
---|
99 |
|
---|
100 | procedure TKernel.AppExecute(AFile: TFile);
|
---|
101 | var
|
---|
102 | App: TApp;
|
---|
103 | begin
|
---|
104 | App := TApp(Apps.FindByName(AFile.Name));
|
---|
105 | if Assigned(App) then begin
|
---|
106 | App.API.KernelApiCallback := KernelApiExecute;
|
---|
107 | Scheduler.AddTask(App.Name, App.Run);
|
---|
108 | end else raise Exception.Create('Application ''' + AFile.Name + ''' no found');
|
---|
109 | end;
|
---|
110 |
|
---|
111 | procedure TKernel.Init;
|
---|
112 | var
|
---|
113 | NewDrive: TDrive;
|
---|
114 | NewFile: TFile;
|
---|
115 | begin
|
---|
116 | Scheduler.Free;
|
---|
117 | Scheduler := SchedulerClass.Create;
|
---|
118 |
|
---|
119 | NewDrive := TDrive.Create;
|
---|
120 | NewDrive.Name := 'System';
|
---|
121 | NewDrive.FileSystem := FileSystemClass.Create;
|
---|
122 | Drives.Add(NewDrive);
|
---|
123 |
|
---|
124 | NewFile := TFile.Create;
|
---|
125 | NewFile.Name := 'Clock';
|
---|
126 | NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
|
---|
127 |
|
---|
128 | NewFile := TFile.Create;
|
---|
129 | NewFile.Name := 'Clock2';
|
---|
130 | NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
|
---|
131 | InitVideo;
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TKernel.Run;
|
---|
135 | var
|
---|
136 | SystemDrive: TDrive;
|
---|
137 | SystemFileSystem: TFileSystem;
|
---|
138 | AppFile: TFile;
|
---|
139 | begin
|
---|
140 | Init;
|
---|
141 | SystemDrive := TDrive(Drives.FindByName('System'));
|
---|
142 | if Assigned(SystemDrive) then begin
|
---|
143 | SystemFileSystem := SystemDrive.FileSystem;
|
---|
144 | AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock'));
|
---|
145 | if Assigned(AppFile) then AppExecute(AppFile)
|
---|
146 | else raise Exception.Create('Cannot start first application');
|
---|
147 | AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock2'));
|
---|
148 | if Assigned(AppFile) then AppExecute(AppFile)
|
---|
149 | else raise Exception.Create('Cannot start first application');
|
---|
150 | Scheduler.Start;
|
---|
151 | end else raise Exception.Create('Missing System drive');
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TKernel.Terminate;
|
---|
155 | begin
|
---|
156 | if Scheduler.Running then Scheduler.Stop;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | constructor TKernel.Create;
|
---|
160 | begin
|
---|
161 | Devices := TNamedObjects<TDevice>.Create;
|
---|
162 | Drives := TNamedObjects<TDrive>.Create;
|
---|
163 | Apps := TNamedObjects<TApp>.Create;
|
---|
164 | Scheduler := TScheduler.Create;
|
---|
165 | Screens := TObjectList<TScreen>.Create;
|
---|
166 | Api := TKernelApi.Create;
|
---|
167 | TKernelApi(Api).Kernel := Self;
|
---|
168 | Desktop := TDesktop.Create;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | destructor TKernel.Destroy;
|
---|
172 | begin
|
---|
173 | Terminate;
|
---|
174 | FreeAndNil(Desktop);
|
---|
175 | FreeAndNil(Api);
|
---|
176 | FreeAndNil(Screens);
|
---|
177 | FreeAndNil(Scheduler);
|
---|
178 | FreeAndNil(Apps);
|
---|
179 | FreeAndNil(Drives);
|
---|
180 | FreeAndNil(Devices);
|
---|
181 | inherited;
|
---|
182 | end;
|
---|
183 |
|
---|
184 | end.
|
---|
185 |
|
---|