home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qbslice.zip / QBSLICE.BAS next >
BASIC Source File  |  1995-05-23  |  3KB  |  102 lines

  1. DEFINT A-Z
  2. DEFSNG S
  3. '
  4. ' QBSLICE - a simple routine to illustrate how a BASIC program can
  5. '           give up time slices under OS/2 Warp.
  6. '
  7. ' Usage:  Under the QuickBasic 4.5 "environment":
  8. '             qb.exe qbslice.bas /L qb.qlb
  9. '         Under MS BASIC 7.1 PDS "environment":
  10. '             qbx.exe qbslice.bas /L qbx.qlb
  11. '
  12. ' by: D. Scott Katzer - katzer@estd.nrl.navy.mil
  13. '     20 May 1995
  14.  
  15. ' Define the CPU registers
  16.  
  17. TYPE RegType
  18.     ax AS INTEGER
  19.     bx AS INTEGER
  20.     cx AS INTEGER
  21.     dx AS INTEGER
  22.     bp AS INTEGER
  23.     si AS INTEGER
  24.     di AS INTEGER
  25.     flags AS INTEGER
  26. END TYPE
  27.  
  28. ' The Interrupt subroutine is loaded via the QuickLibrary QB.QLB or QBX.QLB
  29.  
  30. DECLARE SUB Interrupt (intnum%, inreg AS RegType, outreg AS RegType)
  31.  
  32. DECLARE FUNCTION DOSVersion! () ' Checks the OS - OS/2 or DOS
  33. DECLARE SUB SliceMe ()          ' Gives up a timeslice to the OS
  34.  
  35. COLOR 15, 1               ' white text on a blue screen
  36. CLS                       ' clear the screen
  37. LOCATE 3, 5
  38. PRINT "QBSlice - Demonstrates giving up time slices to OS/2 Warp"
  39. LOCATE 4, 25
  40. PRINT "from a QuickBasic program"
  41. LOCATE 6, 5
  42. PRINT "This is DOS Version: "; DOSVersion!
  43. LOCATE 8, 5
  44. PRINT "Hit a key to Quit the following tests...."
  45. LOCATE 11, 58
  46. PRINT "Counts      Time (s)"
  47. LOCATE 12, 5
  48. PRINT "Counting without giving up time slices: ";
  49. i = 1
  50. StartTime = TIMER
  51. DO
  52.    i = i + 1
  53.    LOCATE 12, 57
  54.    PRINT USING "#####.##   "; i; TIMER - StartTime
  55. LOOP WHILE INKEY$ = "" AND i < 10000
  56.  
  57. LOCATE 14, 5
  58. PRINT "Counting with giving up time slices every 50 steps: ";
  59. i = 1
  60. StartTime = TIMER
  61. DO
  62.    i = i + 1
  63.    LOCATE 14, 57
  64.    PRINT USING "#####.##   "; i; TIMER - StartTime
  65.    IF i MOD 50 = 0 THEN SliceMe ' give up a slice every 50 steps.
  66. LOOP WHILE INKEY$ = "" AND i < 10000
  67.  
  68. LOCATE 23, 5
  69. PRINT "Done!  Hit any key to exit..."
  70. DO
  71.    SliceMe ' give up time slices while waiting...
  72. LOOP WHILE INKEY$ = ""
  73. END
  74.  
  75. DEFSNG A-R, T-Z
  76. FUNCTION DOSVersion! STATIC
  77.  
  78. ' This routine determines the OS version that the program is runing under.
  79. ' Needed, e.g., in case we are running graphics in a window in OS/2 (many
  80. ' graphics modes aren't virtualized in a window if runing WPS in high
  81. ' resolution)
  82.  
  83. DIM reg AS RegType
  84. reg.ax = &H3000
  85. Interrupt &H21, reg, reg
  86. major% = reg.ax MOD 256
  87. minor% = reg.ax \ 256
  88. DOSVersion! = major% + minor% / 100
  89. END FUNCTION
  90.  
  91. SUB SliceMe
  92.  
  93. ' This subroutine gives up a time slice to Warp.
  94. ' It is documented in IBM's OS/2 Virtual Device Driver manual, part
  95. ' of the OS/2 Technical Library.
  96.  
  97. DIM reg AS RegType
  98. reg.ax = &H1680
  99. Interrupt &H2F, reg, reg ' Give up the time slice to OS/2
  100. END SUB
  101.  
  102.