Changeset 12 for trunk/Packages
- Timestamp:
- Sep 6, 2017, 6:47:49 PM (7 years ago)
- Location:
- trunk/Packages/Kernel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Kernel/UAPI.pas
r9 r12 10 10 11 11 type 12 13 { TAPI } 14 15 TAPI = class 12 TApiCommand = (acNone, acWriteText, acDrawText, acDrawLine, acDrawRect, acSleep, 13 acReadMessage, acWindowCreate, acWindowSetAttr); 14 15 TDrawTextParams = record 16 P: TPoint; 17 Text: string; 18 Color: TColor; 19 end; 20 21 TDrawLineParams = record 22 P1: TPoint; 23 P2: TPoint; 24 Color: TColor; 25 end; 26 27 TWindowSetAttrParams = record 28 Size: TPoint; 29 Visible: Boolean; 30 end; 31 32 TDrawRectParams = record 33 Rect: TRect; 34 Color: TColor; 35 end; 36 37 { TKernelApi } 38 39 TKernelApi = class 16 40 Kernel: TObject; //TKernel; 41 function Call(Command: TApiCommand; Data: Pointer): Pointer; 17 42 procedure WriteText(Text: string); 18 43 procedure DrawText(P: TPoint; Text: string; Color: TColor); … … 22 47 procedure ReadMessage(Message: TIPCMessage); 23 48 function WindowCreate: Integer; 24 procedure WindowSetAttr(SizeX, SizeY: Integer; Visible: Boolean); 49 procedure WindowSetAttr(Size: TPoint; Visible: Boolean); 50 end; 51 52 TApiCall = function (Command: TApiCommand; Data: Pointer): Pointer of object; 53 54 { TUserApi } 55 56 TUserApi = class 57 KernelApiCallback: TApiCall; 58 function Call(Command: TApiCommand; Data: Pointer): Pointer; 59 procedure WriteText(Text: string); 60 procedure DrawText(P: TPoint; Text: string; Color: TColor); 61 procedure DrawLine(P1, P2: TPoint; Color: TColor); 62 procedure DrawRect(Rect: TRect; Color: TColor); 63 procedure Sleep(Time: TDateTime); 64 procedure ReadMessage(Message: TIPCMessage); 65 function WindowCreate: Integer; 66 procedure WindowSetAttr(Size: TPoint; Visible: Boolean); 25 67 end; 26 68 … … 31 73 UKernel; 32 74 33 { TAPI } 34 35 procedure TAPI.WriteText(Text: string); 75 { TUserApi } 76 77 function TUserApi.Call(Command: TApiCommand; Data: Pointer 78 ): Pointer; 79 begin 80 Result := KernelApiCallback(Command, Data); 81 end; 82 83 procedure TUserApi.WriteText(Text: string); 84 begin 85 Call(acWriteText, Pointer(Text)); 86 end; 87 88 procedure TUserApi.DrawText(P: TPoint; Text: string; Color: TColor); 89 var 90 Params: TDrawTextParams; 91 begin 92 Params.P := P; 93 Params.Text := Text; 94 Params.Color := Color; 95 Call(acDrawText, @Params); 96 end; 97 98 procedure TUserApi.DrawLine(P1, P2: TPoint; Color: TColor); 99 var 100 Params: TDrawLineParams; 101 begin 102 Params.P1 := P1; 103 Params.P2 := P2; 104 Params.Color := Color; 105 Call(acDrawLine, @Params); 106 end; 107 108 procedure TUserApi.DrawRect(Rect: TRect; Color: TColor); 109 var 110 Params: TDrawRectParams; 111 begin 112 Params.Rect := Rect; 113 Params.Color := Color; 114 Call(acDrawRect, @Params); 115 end; 116 117 procedure TUserApi.Sleep(Time: TDateTime); 118 begin 119 Call(acSleep, @Time); 120 end; 121 122 procedure TUserApi.ReadMessage(Message: TIPCMessage); 123 begin 124 Call(acReadMessage, Message); 125 end; 126 127 function TUserApi.WindowCreate: Integer; 128 begin 129 Call(acWindowCreate, nil); 130 end; 131 132 procedure TUserApi.WindowSetAttr(Size: TPoint; Visible: Boolean); 133 var 134 Params: TWindowSetAttrParams; 135 begin 136 Params.Size := Size; 137 Params.Visible := Visible; 138 Call(acWindowSetAttr, @Params); 139 end; 140 141 { TKernelApi } 142 143 function TKernelApi.Call(Command: TApiCommand; Data: Pointer 144 ): Pointer; 145 begin 146 case Command of 147 acDrawLine: DrawLine(TDrawLineParams(Data^).P1, TDrawLineParams(Data^).P2, 148 TDrawLineParams(Data^).Color); 149 acDrawRect: DrawRect(TDrawRectParams(Data^).Rect, TDrawRectParams(Data^).Color); 150 acDrawText: DrawText(TDrawTextParams(Data^).P, TDrawTextParams(Data^).Text, 151 TDrawTextParams(Data^).Color); 152 acSleep: Sleep(TDateTime(Data^)); 153 acWindowCreate: Result := Pointer(WindowCreate); 154 acWindowSetAttr: WindowSetAttr(TWindowSetAttrParams(Data^).Size, 155 TWindowSetAttrParams(Data^).Visible); 156 acWriteText: WriteText(string(Data)); 157 acReadMessage: ReadMessage(Data); 158 end; 159 end; 160 161 procedure TKernelApi.WriteText(Text: string); 36 162 var 37 163 Device: TDeviceSerial; … … 43 169 end; 44 170 45 procedure T API.DrawText(P: TPoint; Text: string; Color: TColor);171 procedure TKernelApi.DrawText(P: TPoint; Text: string; Color: TColor); 46 172 var 47 173 Screen: TScreen; … … 51 177 end; 52 178 53 procedure T API.DrawLine(P1, P2: TPoint; Color: TColor);179 procedure TKernelApi.DrawLine(P1, P2: TPoint; Color: TColor); 54 180 var 55 181 Screen: TScreen; … … 59 185 end; 60 186 61 procedure T API.DrawRect(Rect: TRect; Color: TColor);187 procedure TKernelApi.DrawRect(Rect: TRect; Color: TColor); 62 188 var 63 189 Screen: TScreen; … … 67 193 end; 68 194 69 procedure T API.Sleep(Time: TDateTime);195 procedure TKernelApi.Sleep(Time: TDateTime); 70 196 var 71 197 Task: TTask; … … 75 201 end; 76 202 77 procedure T API.ReadMessage(Message: TIPCMessage);203 procedure TKernelApi.ReadMessage(Message: TIPCMessage); 78 204 var 79 205 Task: TTask; … … 83 209 end; 84 210 85 function T API.WindowCreate: Integer;86 begin 87 88 end; 89 90 procedure T API.WindowSetAttr(SizeX, SizeY: Integer; Visible: Boolean);211 function TKernelApi.WindowCreate: Integer; 212 begin 213 214 end; 215 216 procedure TKernelApi.WindowSetAttr(Size: TPoint; Visible: Boolean); 91 217 begin 92 218 -
trunk/Packages/Kernel/UApp.pas
r9 r12 12 12 13 13 TApp = class(TNamedObject) 14 API: T API;14 API: TUserApi; 15 15 Terminated: Boolean; 16 16 constructor Create; virtual; … … 27 27 begin 28 28 inherited Create; 29 API := T API.Create;29 API := TUserApi.Create; 30 30 end; 31 31 -
trunk/Packages/Kernel/UKernel.pas
r10 r12 7 7 uses 8 8 Classes, Math, SysUtils, UList, Contnrs, UFileSystem, UMemory, UScreen, UDevice, 9 fgl, UApp, UScheduler ;9 fgl, UApp, UScheduler, UApi; 10 10 11 11 type … … 26 26 TKernel = class 27 27 private 28 Api: TKernelApi; 28 29 procedure InitVideo; 30 function KernelApiExecute(Command: TApiCommand; Data: Pointer): Pointer; 29 31 public 30 32 Apps: TNamedObjectList<TApp>; … … 88 90 end; 89 91 92 function TKernel.KernelApiExecute(Command: TApiCommand; 93 Data: Pointer): Pointer; 94 begin 95 Result := Api.Call(Command, Data); 96 end; 97 90 98 procedure TKernel.AppExecute(AFile: TFile); 91 99 var … … 94 102 App := TApp(Apps.FindByName(AFile.Name)); 95 103 if Assigned(App) then begin 96 App.API.Kernel := Self;104 App.API.KernelApiCallback := KernelApiExecute; 97 105 Scheduler.AddTask(App.Name, App.Run); 98 106 end else raise Exception.Create('Application ''' + AFile.Name + ''' no found'); … … 119 127 NewFile.Name := 'Clock2'; 120 128 NewDrive.FileSystem.TopDirectory.Items.Add(NewFile); 121 InitVideo;129 InitVideo; 122 130 end; 123 131 … … 149 157 Scheduler := TScheduler.Create; 150 158 Screens := TFPGObjectList<TScreen>.Create; 159 Api := TKernelApi.Create; 160 Api.Kernel := Self; 151 161 end; 152 162 153 163 destructor TKernel.Destroy; 154 164 begin 155 Screens.Free; 156 Scheduler.Free; 157 Apps.Free; 158 Drives.Free; 159 Devices.Free; 165 FreeAndNil(Api); 166 FreeAndNil(Screens); 167 FreeAndNil(Scheduler); 168 FreeAndNil(Apps); 169 FreeAndNil(Drives); 170 FreeAndNil(Devices); 160 171 inherited Destroy; 161 172 end;
Note:
See TracChangeset
for help on using the changeset viewer.