Bladeren bron

+ dosbox wrapper script replaced with a pascal implementation that is multiplatform and supports being run in multiple instances

git-svn-id: branches/i8086@24133 -
nickysn 12 jaren geleden
bovenliggende
commit
59dd5ee1d0
4 gewijzigde bestanden met toevoegingen van 150 en 16 verwijderingen
  1. 1 1
      .gitattributes
  2. 2 2
      tests/utils/dosbox/dosbox.conf
  3. 147 0
      tests/utils/dosbox/dosbox_wrapper.pas
  4. 0 13
      tests/utils/dosbox/dosbox_wrapper.sh

+ 1 - 1
.gitattributes

@@ -12004,7 +12004,7 @@ tests/utils/dbdigest.pp svneol=native#text/plain
 tests/utils/dbtests.pp svneol=native#text/plain
 tests/utils/dbtests.pp svneol=native#text/plain
 tests/utils/digest.pp svneol=native#text/plain
 tests/utils/digest.pp svneol=native#text/plain
 tests/utils/dosbox/dosbox.conf svneol=native#text/plain
 tests/utils/dosbox/dosbox.conf svneol=native#text/plain
-tests/utils/dosbox/dosbox_wrapper.sh svneol=native#text/plain
+tests/utils/dosbox/dosbox_wrapper.pas svneol=native#text/plain
 tests/utils/dosbox/exitcode.exe -text svneol=unset#application/x-dosexec
 tests/utils/dosbox/exitcode.exe -text svneol=unset#application/x-dosexec
 tests/utils/dosbox/exitcode.pas svneol=native#text/plain
 tests/utils/dosbox/exitcode.pas svneol=native#text/plain
 tests/utils/dotest.pp svneol=native#text/plain
 tests/utils/dotest.pp svneol=native#text/plain

+ 2 - 2
tests/utils/dosbox/dosbox.conf

@@ -72,7 +72,7 @@ scaler=normal2x
 #              'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails.
 #              'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails.
 #                              (Example: fixed 4000).
 #                              (Example: fixed 4000).
 #              'max'           will allocate as much cycles as your computer is able to handle.
 #              'max'           will allocate as much cycles as your computer is able to handle.
-#            
+#
 #            Possible values: auto, fixed, max.
 #            Possible values: auto, fixed, max.
 #   cycleup: Amount of cycles to decrease/increase with keycombo.(CTRL-F11/CTRL-F12)
 #   cycleup: Amount of cycles to decrease/increase with keycombo.(CTRL-F11/CTRL-F12)
 # cycledown: Setting it lower than 100 will be a percentage.
 # cycledown: Setting it lower than 100 will be a percentage.
@@ -244,7 +244,7 @@ ipx=false
 
 
 
 
 @echo off
 @echo off
-mount c /home/nickysn/dosbox_test/dosroot
+mount c $DosBoxDir
 c:
 c:
 exitcode test.exe
 exitcode test.exe
 exit
 exit

+ 147 - 0
tests/utils/dosbox/dosbox_wrapper.pas

@@ -0,0 +1,147 @@
+{$MODE objfpc}{$H+}
+
+uses
+  SysUtils, StrUtils;
+
+function GenerateTempDir: string;
+var
+  FileName: string;
+  TempDir: string;
+  Done: Boolean = False;
+begin
+  TempDir := GetTempDir(False);
+  repeat
+    try
+      FileName := TempDir + 'dosboxwrappertmp_' + IntToStr(Random(100000));
+      MkDir(FileName);
+      Done := True;
+    except
+      on E: EInOutError do
+      begin
+        { 5 = Access Denied, returned when a file is duplicated }
+        if E.ErrorCode <> 5 then
+          raise;
+      end;
+    end;
+  until Done;
+  Result := FileName + DirectorySeparator;
+end;
+
+procedure GenerateDosBoxConf(const ADosBoxDir: string);
+var
+  SourceConfFileName, TargetConfFileName: string;
+  SourceFile, TargetFile: TextFile;
+  S: string;
+begin
+  SourceConfFileName := ExtractFilePath(ParamStr(0)) + 'dosbox.conf';
+  TargetConfFileName := ADosBoxDir + 'dosbox.conf';
+  AssignFile(SourceFile, SourceConfFileName);
+  AssignFile(TargetFile, TargetConfFileName);
+  Reset(SourceFile);
+  try
+    Rewrite(TargetFile);
+    try
+      while not EoF(SourceFile) do
+      begin
+        Readln(SourceFile, S);
+        S := AnsiReplaceStr(S, '$DosBoxDir', ADosBoxDir);
+        Writeln(TargetFile, S);
+      end;
+    finally
+      CloseFile(TargetFile);
+    end;
+  finally
+    CloseFile(SourceFile);
+  end;
+end;
+
+procedure CopyFile(const ASrcFileName, ADestFileName: string);
+var
+  SrcF, DestF: File;
+  OldFileMode: Integer;
+  Buf: array [0..4095] of Byte;
+  BytesRead: Integer;
+begin
+  OldFileMode := FileMode;
+  try
+    AssignFile(SrcF, ASrcFileName);
+    AssignFile(DestF, ADestFileName);
+    FileMode := fmOpenRead;
+    Reset(SrcF, 1);
+    try
+      FileMode := fmOpenWrite;
+      try
+        Rewrite(DestF, 1);
+        repeat
+          BlockRead(SrcF, Buf, SizeOf(Buf), BytesRead);
+          BlockWrite(DestF, Buf, BytesRead);
+        until BytesRead < SizeOf(Buf);
+      finally
+        CloseFile(DestF);
+      end;
+    finally
+      CloseFile(SrcF);
+    end;
+  finally
+    FileMode := OldFileMode;
+  end;
+end;
+
+function ReadExitCode(const ADosBoxDir: string): Integer;
+var
+  F: TextFile;
+begin
+  AssignFile(F, ADosBoxDir + 'EXITCODE.TXT');
+  Reset(F);
+  try
+    Readln(F, Result);
+  finally
+    CloseFile(F);
+  end;
+end;
+
+procedure Cleanup(const ADosBoxDir: string);
+
+  procedure DeleteIfExists(const AFileName: string);
+  begin
+    if FileExists(AFileName) then
+      DeleteFile(AFileName);
+  end;
+
+begin
+  DeleteIfExists(ADosBoxDir + 'dosbox.conf');
+  DeleteIfExists(ADosBoxDir + 'EXITCODE.TXT');
+  DeleteIfExists(ADosBoxDir + 'EXITCODE.EXE');
+  DeleteIfExists(ADosBoxDir + 'TEST.EXE');
+  RmDir(ADosBoxDir);
+end;
+
+var
+  DosBoxDir: string;
+  ExitCode: Integer = 255;
+  DosBoxBinaryPath: string;
+begin
+  Randomize;
+  if ParamCount = 0 then
+  begin
+    Writeln('Usage: ' + ParamStr(0) + ' <executable>');
+    halt(1);
+  end;
+  DosBoxBinaryPath := GetEnvironmentVariable('DOSBOX');
+  if DosBoxBinaryPath = '' then
+  begin
+    Writeln('Please set the DOSBOX environment variable to the dosbox executable');
+    halt(1);
+  end;
+  DosBoxDir := GenerateTempDir;
+  try
+    GenerateDosBoxConf(DosBoxDir);
+    CopyFile(ExtractFilePath(ParamStr(0)) + 'exitcode.exe', DosBoxDir + 'EXITCODE.EXE');
+    CopyFile(ParamStr(1), DosBoxDir + 'TEST.EXE');
+    ExecuteProcess(DosBoxBinaryPath, '-conf ' + DosBoxDir + 'dosbox.conf');
+    ExitCode := ReadExitCode(DosBoxDir);
+  finally
+    Cleanup(DosBoxDir);
+  end;
+  halt(ExitCode);
+end.

+ 0 - 13
tests/utils/dosbox/dosbox_wrapper.sh

@@ -1,13 +0,0 @@
-#! /bin/sh
-
-DOSBOX_TEST=/home/nickysn/dosbox_test
-DOSBOX=dosbox
-
-# TODO: generate dosbox.conf with $DOSBOX_TEST/dosroot in the autoexec mount section
-
-rm -rf $DOSBOX_TEST/dosroot
-mkdir $DOSBOX_TEST/dosroot
-cp $1 $DOSBOX_TEST/dosroot/test.exe
-cp $DOSBOX_TEST/exitcode.exe $DOSBOX_TEST/dosroot/exitcode.exe
-$DOSBOX -exit -conf $DOSBOX_TEST/dosbox.conf
-exit `cat $DOSBOX_TEST/dosroot/EXITCODE.TXT`