home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / SFECACHE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  7KB  |  236 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 280 of 360
  3. From : Max Maischein                       2:249/6.17           29 May 93  21:24
  4. To   : Steven Tallent                      1:3811/210.0
  5. Subj : Hard/Cold Reboot //// Flushing the write behind cache
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  > Would PASCAL source to reproduce this program be off-topic, do you
  8.  > think,
  9.  
  10. Since this theme gets overhand, I repost my unit which flushes Smartdrive if
  11. included in your program.
  12.  
  13. The code is based on other code courtesy of Norbert Igl, and sorry for the
  14. german remarks :-)
  15.  
  16. -max}
  17.  
  18. Unit SfeCache;
  19. {
  20. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  21. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  22. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  23. ▓▓▓∙──                                                                 ──∙▓▓▓▓
  24. ▓▓▓│                                                                     │░░▓▓
  25. ▓▓▓   Max Maischein                                          2:249/6.17   ░░▓▓
  26. ▓▓▓                                                                       ░░▓▓
  27. ▓▓▓   Diese Unit  implementiert  einen  'tomatischen  Flush  Aufruf  an   ░░▓▓
  28. ▓▓▓   eventuell residente Caches  wie  zum  Bleistift  SmartDrive  oder   ░░▓▓
  29. ▓▓▓   Norton Cache. Sie ( dir Unit ) basiert auf Code von Norbert  Igl,   ░░▓▓
  30. ▓▓▓   ich habe die nötigen aufrufe  zum  Cache  flushing  eingebaut.Das   ░░▓▓
  31. ▓▓▓   Ganze Zeugs ist ungetestet,  sollte  aber  funktionieren,  da  es   ░░▓▓
  32. ▓▓▓   nicht viel gibt, was schiefgehen kann. Wenn  ihr  euch  aber  auf   ░░▓▓
  33. ▓▓▓   WriteCaches beim Programmieren voll  verlasst,  dann  Gnade  euch   ░░▓▓
  34. ▓▓▓   Gott !                                                              ░░▓▓
  35. ▓▓▓   Al says : "Save early, save often !"                                ░░▓▓
  36. ▓▓▓                                                                       ░░▓▓
  37. ▓▓▓   Die Function FlushCache wird von der Unit  auch  exportiert,  und   ░░▓▓
  38. ▓▓▓   kann auch vom Programm aus aufgerufen werden. Sie ist als Pointer   ░░▓▓
  39. ▓▓▓   auf eine  Procedure  implementiert,  und  dieser  zeigt  auf  die   ░░▓▓
  40. ▓▓▓   aktuelle ( anwendbare  )  Flush  Procedure  für  das  vorliegende   ░░▓▓
  41. ▓▓▓   Cache.                                                              ░░▓▓
  42. ▓▓▓                                                                       ░░▓▓
  43. ▓▓▓   This piece of code is donated to the public domain, but I request   ░░▓▓
  44. ▓▓▓   that, if you use this code, you mention me in the DOCs somewhere.   ░░▓▓
  45. ▓▓▓                                                                       ░░▓▓
  46. ▓▓▓                                                              -max     ░░▓▓
  47. ▓▓▓│                                                                     │░░▓▓
  48. ▓▓▓∙──                                                                 ──∙░░▓▓
  49. ▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓
  50. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  51. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  52. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  53. }
  54. Interface
  55. Implementation
  56. Uses DOS
  57.      ;
  58.  
  59. Const AktCache   : Byte = 0;
  60.  
  61. Type FlushProc = Procedure;
  62.  
  63. Var FlushCache : FlushProc;
  64.  
  65. Function SmartDrv_exe : Boolean;
  66. Var Found : Boolean;
  67. Begin
  68.   Found := False;
  69.   Asm
  70.         push    bp
  71.         stc
  72.         mov     ax, 4A10h
  73.         xor     bx, bx
  74.         int     2Fh
  75.         pop     bp
  76.         jc      @NoSmartDrive
  77.         cmp     ax, 0BABEh
  78.         jne     @NoSmartDrive
  79.         mov     Found, True
  80. @NoSmartDrive:
  81.   End;
  82.   SmartDrv_exe := Found;
  83. End;
  84.  
  85. Function CompaqPro : Boolean;
  86. Var OK : Boolean;
  87. Begin
  88.   CompaqPro := False;
  89.   OK := False;
  90.   Asm
  91.         mov     ax, 0F400h
  92.         int     16h
  93.         cmp     ah, 0E2h
  94.         jne     @NoCache
  95.         or      al, al
  96.         je      @NoCache
  97.         cmp     al, 2
  98.         ja      @NoCache
  99.         mov     OK, 1
  100. @NoCache:
  101.   End;
  102.   CompaqPro := OK;
  103. End;
  104.  
  105. Function PC6 : Boolean;   { PCTools v6, v5 }
  106. Var OK : Boolean;
  107. Begin
  108.   PC6 := False;
  109.   OK := False;
  110.   Asm
  111.         mov     ax, 0FFA5h
  112.         mov     cx, 01111h
  113.         int     16h
  114.         or      ch, ch
  115.         jne     @NoCache
  116.         mov     OK, 1
  117. @NoCache:
  118.   End;
  119.   PC6 := OK;
  120. End;
  121.  
  122. Function PC5 : Boolean;
  123. Var OK : Boolean;
  124. Begin
  125.   PC5 := False;
  126.   OK := False;
  127.   Asm
  128.         mov     ax, 02BFFh
  129.         mov     cx, 'CX';
  130.         int     21h
  131.         or      al, al
  132.         jne     @NoCache
  133.         mov     ok, 1
  134. @NoCache:
  135.   End;
  136.   PC5 := OK;
  137. End;
  138.  
  139. Function HyperDsk : Boolean;   { 4.20+ ... }
  140. Var OK : Boolean;
  141. Begin
  142.   Hyperdsk := False;
  143.   OK := False;
  144.   Asm
  145.         mov     ax, 0DF00h
  146.         mov     bx, 'DH'
  147.         int     02Fh
  148.         cmp     al, 0FFh
  149.         jne     @NoCache
  150.         cmp     cx, 05948h
  151.         jne     @NoCache
  152.         mov     OK, 1
  153. @NoCache:
  154.   End;
  155.   HyperDSK := OK;
  156. End;
  157.  
  158. Function QCache : Boolean;
  159. Var OK : Boolean;
  160. Begin
  161.   QCache := False;
  162.   OK := False;
  163.   Asm
  164.         mov     ah, 027h
  165.         xor     bx, bx
  166.         int     013h
  167.         or      bx, bx
  168.         je      @NoCache
  169.         mov     OK, 1
  170. @NoCache:
  171.   End;
  172.   QCache := OK;
  173. End;
  174.  
  175. Procedure FlushSD_sys; Far;
  176. Var F : File;
  177.     B : Byte;
  178. Begin
  179.   Assign( F, 'SMARTAAR' );
  180.   Reset( F );
  181.   B := 0;
  182.   Asm
  183.         push    ds
  184.         mov     ax, 04403h
  185.         mov     bx, FileRec( F ).Handle
  186.         mov     cx, 1
  187.         int     21h
  188.         pop     ds
  189.   End;
  190. End;
  191.  
  192. Procedure FlushSD_exe; Far;
  193. Begin
  194.   Asm
  195.         mov     ax, 04A10h
  196.         mov     bx, 1
  197.         int     2Fh
  198.   End;
  199. End;
  200.  
  201. Procedure FlushPC6; Far;
  202. Begin
  203.   Asm
  204.         mov     ax, 0F5A5h
  205.         mov     cx, -1
  206.         int     16h
  207.   End;
  208. End;
  209.  
  210. Procedure FlushPC5; Far;
  211. Begin
  212.   Asm
  213.         mov     ah, 0A1h
  214.         mov     si, 04358h
  215.         int     13h
  216.   End;
  217. End;
  218.  
  219. Procedure FlushNoCache; Far;
  220. Begin
  221. End;
  222.  
  223. Begin
  224.   Writeln( '■ DISK-CACHE-FUSH v1.00    Norbert Igl & Max Maischein  ''3/93');
  225.   If SmartDrv_exe
  226.     then FlushCache := FlushSD_exe
  227.     else
  228.   If PC6
  229.     then FlushCache := FlushPC6
  230.     else
  231.   If PC5
  232.     then FlushCache := FlushPC5
  233.     else FlushCache := FlushNoCache;
  234.  
  235.   FlushCache;
  236. End.