OSDN Git Service

追加してありませんでした
authoryamat0jp <yamat0jp@yahoo.co.jp>
Sat, 3 Nov 2018 13:11:45 +0000 (22:11 +0900)
committeryamat0jp <yamat0jp@yahoo.co.jp>
Sat, 3 Nov 2018 13:11:45 +0000 (22:11 +0900)
contrl.pas [new file with mode: 0644]
wand.dpr
wand.dproj

diff --git a/contrl.pas b/contrl.pas
new file mode 100644 (file)
index 0000000..5203ee1
--- /dev/null
@@ -0,0 +1,227 @@
+unit contrl;
+
+interface
+
+uses System.Classes, bootpack;
+
+type
+  TTimer = class
+  private
+    timeout: integer;
+    data: integer;
+    procedure settime(timeout: integer);
+  public
+    constructor Create(data0: integer);
+  end;
+
+  TSS32 = record
+    backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3: integer;
+    eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi: integer;
+    es, cs, ss, ds, fs, gs: integer;
+    ldtr, iomap: integer;
+  end;
+
+  TTask = class
+  public
+    sel, flags: integer;
+    tss: TSS32;
+    constructor Create;
+  end;
+
+  TCtl = class
+  private
+    list: TList;
+    task: TList;
+    count: integer;
+    next: integer;
+    top: integer;
+    mt_timer: TTimer;
+    ts: integer;
+    procedure inthandler20(var esp: integer);
+  public
+    fifo: TFifo;
+    constructor Create(fifo: TFifo);
+    destructor Destroy; override;
+    procedure run;
+    procedure taskswitch;
+    function settime(data: integer; timeout: integer): Boolean;
+  end;
+
+procedure init_pit(timerctl: TCtl);
+
+implementation
+
+uses asmhead, func;
+
+const
+  PIT_CTRL = $0043;
+  PIT_CNT0 = $0040;
+  MAX_TIMER = 500;
+
+procedure init_pit(timerctl: TCtl);
+begin
+
+end;
+
+{ TTimer }
+
+constructor TTimer.Create(data0: integer);
+begin
+  inherited Create;
+  io_out8(PIT_CTRL, $34);
+  io_out8(PIT_CNT0, $9C);
+  io_out8(PIT_CNT0, $2E);
+  data := data0;
+  timeout := 0;
+end;
+
+procedure TTimer.settime(timeout: integer);
+begin
+  Self.timeout := timeout;
+end;
+
+{ TCtl }
+
+procedure TCtl.inthandler20(var esp: integer);
+var
+  i: integer;
+  s: TTimer;
+begin
+  io_out8(PIC0_OCW2, $60);
+  inc(count);
+  ts := 0;
+  if next > count then
+    Exit;
+  for i := 0 to list.count - 1 do
+  begin
+    s := list[i];
+    if s.timeout > count then
+    begin
+      s.Free;
+      list.Delete(i);
+      break;
+    end;
+    if s <> mt_timer then
+      fifo.Put(s.data)
+    else
+      ts := 1;
+  end;
+  next := TTimer(list[0]).timeout;
+  if ts <> 0 then
+    taskswitch;
+end;
+
+procedure TCtl.run;
+begin
+
+end;
+
+constructor TCtl.Create(fifo: TFifo);
+begin
+  inherited Create;
+  list := TList.Create;
+  task := TList.Create;
+  Self.fifo := fifo;
+  settime(2, 2);
+  mt_timer := list[0];
+end;
+
+destructor TCtl.Destroy;
+var
+  i: integer;
+  s: TObject;
+begin
+  for i := 0 to list.count - 1 do
+  begin
+    s := list[i];
+    s.Free;
+  end;
+  for i := 0 to task.count - 1 do
+  begin
+    s := task[i];
+    s.Free;
+  end;
+  list.Free;
+  task.Free;
+  inherited;
+end;
+
+function TCtl.settime(data: integer; timeout: integer): Boolean;
+var
+  eflags: integer;
+  s, timer: TTimer;
+  i: integer;
+begin
+  if list.count < MAX_TIMER then
+  begin
+    result:=true;
+    eflags := io_load_eflags;
+    io_cli;
+    timer := TTimer.Create(data);
+    timer.settime(timeout + count);
+    for i := 0 to list.count - 1 do
+    begin
+      s := TTimer(list[i]);
+      if s.timeout >= timer.timeout then
+      begin
+        list.Insert(i, timer);
+        next := s.timeout;
+        io_store_eflags(eflags);
+        Exit;
+      end;
+    end;
+    list.Add(timer);
+    io_store_eflags(eflags);
+  end
+  else
+    result := false;
+end;
+
+procedure TCtl.taskswitch;
+begin
+  mt_timer.settime(2);
+  if top >= 2 then
+  begin
+    inc(top);
+    if top >= task.count then
+      top := 0;
+    farjump(0, TTask(task[top]).sel);
+  end;
+end;
+
+{ TTask }
+
+constructor TTask.Create;
+var
+  task_esp: integer;
+begin
+  with tss do
+  begin
+    ldtr := 0;
+    iomap := $40000000;
+    ldtr := 0;
+    iomap := $40000000;
+    set_segmdesc(gdt + 3, 103, Self, AR_TSS32);
+    load_tr(3 * 8);
+    task_esp := integer(Self);
+    Pointer(eip) := @main;
+    eflags := $00000202; // * IF = 1; */
+    eax := 0;
+    ecx := 0;
+    edx := 0;
+    ebx := 0;
+    esp := task_esp;
+    ebp := 0;
+    esi := 0;
+    edi := 0;
+    es := 1 * 8;
+    cs := 2 * 8;
+    ss := 1 * 8;
+    ds := 1 * 8;
+    fs := 1 * 8;
+    gs := 1 * 8;
+  end;
+  task_esp := sht_back - 4;
+end;
+
+end.
index c8629ec..7da7b8e 100644 (file)
--- a/wand.dpr
+++ b/wand.dpr
@@ -8,7 +8,7 @@ uses
   bootpack in 'bootpack.pas',
   asmhead in 'asmhead.pas',
   graphic in 'graphic.pas',
-  timer in 'timer.pas',
+  contrl in 'contrl.pas',
   func in 'func.pas';
 
 const
index 56195f6..315e8de 100644 (file)
         <DCCReference Include="bootpack.pas"/>
         <DCCReference Include="asmhead.pas"/>
         <DCCReference Include="graphic.pas"/>
-        <DCCReference Include="timer.pas"/>
+        <DCCReference Include="contrl.pas"/>
         <DCCReference Include="func.pas"/>
         <RcItem Include="hankaku.bin">
             <ContainerId>ResourceItem</ContainerId>
                         <Operation>1</Operation>
                     </Platform>
                 </DeployClass>
-                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
+                <ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
                 <ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
                 <ProjectRoot Platform="iOSDevice" Name="$(PROJECTNAME).app"/>
                 <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                 <ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
                 <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                 <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>
-                <ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
+                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
             </Deployment>
             <Platforms>
                 <Platform value="Android">False</Platform>