home *** CD-ROM | disk | FTP | other *** search
/ The California Collection / TheCaliforniaCollection.cdr / his038 / qbints.lzh / INTERRUP.DOC < prev    next >
Encoding:
Text File  |  1989-04-23  |  8.9 KB  |  233 lines

  1.                  REMARKS ON THE USE OF INTERRUPTS
  2.                          David A. Wesson
  3.                          24 Fairview St.
  4.                       W. Hartford, CT 06119
  5.                            203-523-1873
  6.  
  7.  
  8. Here's everything I have pieced together to date about interrupts.
  9.  
  10. Interrupts are segments of memory where the various information is 
  11. stored that tells the computer what to do. These segments are 
  12. refered to in hex, example: INT &H21. Within these segments there 
  13. are subsegments named AX, BX, CX, DX and some other less frequently 
  14. used areas.  Thus, each interrupt is made up of these subsegments 
  15. which actually are the locations where information is stored.  
  16. Further, each subsegment has a high area and a low area. This means 
  17. that the AX register is made up of AH on the left and AL on the 
  18. right. The AH section is refered to by taking the value to be sent 
  19. to that register and multiplying it by 256 in decimal or 100 in hex.  
  20. For example, a value of 2 or &H2 sent to an AH register will be sent 
  21. as (2 * 256) or &H200. Using this system, an AH and an AL value can 
  22. be sent simultaneously by adding the AL value to the AH value.  
  23.  
  24. Example: AH = 2 and AL = 3 becomes &H200 + &H3  or (256 * 2) + 3 
  25.  
  26. Even more information can be packed into a register by making 
  27. reference to the individual binary bits that make up the register.
  28. When the AX register is set to zero, it would look like this:
  29. 00000000 00000000   with the left set being AH and the right AL.
  30. In binary, the number 1 looks like 00000001 and the number 257 is
  31. 10000001. This is how the entire register retains a number. However,
  32. each of the 8 places (or bits, refered to as number 0 through 7) can
  33. be used separately to hold information. For example, if the 4th bit
  34. is 1, then some state of the system is true, if 0 then false, such as
  35. whether the printer is turned on or off. 
  36.  
  37. The simplest example of the use of an interrupt is the Print Screen
  38. function which is activated by hitting [Shift]+[PrtSc] on the 
  39. keyboard. To activate the same response directly from within a 
  40. program, a call can be made to INT &H05. Any call of any setting seems 
  41. to activate the function. Thus the syntax for this call is just to 
  42. invoke the interrupt with 0s for each subsegment. This means that 
  43. the values for AX, BX etc are all set to 0 when the interrupt call 
  44. is made. When a call to an AX, BX etc register is specified, that 
  45. value is passed in the call statement. When an AH, AL, BH, BL etc is 
  46. to be passed, the formula (such as &H200 + &H3) is sent to its 
  47. respective AX, BX etc register.  
  48.  
  49. The syntax for setting up an interrupt call in QuickBasic 4.0+ is
  50. somewhat determined by how you define the data structures. The 
  51. following example uses a structure similar to the one recommended
  52. by Microsoft. 
  53.  
  54.  
  55. Please do not assume that these routines work without testing. I
  56. accept no responsibility for anything that happens. Generally, the
  57. worst you'll get is a hung system from running any of these.
  58.  
  59. '*****************************************************************************
  60. 'This routine sends an ASCII code to the printer buffer. The buffer does not
  61. 'print until a 10 (line feed) is received.
  62. '*****************************************************************************
  63.  
  64. TYPE RegType
  65.      ax    AS INTEGER
  66.      bx    AS INTEGER
  67.      cx    AS INTEGER
  68.      dx    AS INTEGER
  69.      bp    AS INTEGER
  70.      si    AS INTEGER
  71.      di    AS INTEGER
  72.      flags AS INTEGER
  73. END TYPE
  74.  
  75. DIM SHARED inregs AS RegType, outregs AS RegType
  76.  
  77. DECLARE SUB printout (code)
  78.  
  79. printout 10
  80.  
  81. SUB printout (code)
  82.      inregs.ax = code: inregs.bx = 0: inregs.cx = 0: inregs.dx = 0
  83.      CALL interrupt(&H17, inregs, outregs)
  84. END SUB
  85.  
  86. '******************************************************************* 
  87.  
  88. In this example, the TYPE section defines the data structure for the 
  89. values that are sent to the interrupt (INREGS) and are returned by 
  90. the interrupt (OUTREGS). Here, the AX register of INT &H17 is to be 
  91. sent the ASCII value defined here as "code". Code is sent to the 
  92. subroutine, where it is packed into the AX section of the INREGS 
  93. packet as INREGS.AX . This results in code being placed in the 
  94. printer buffer waiting to be printed when a code = 10 is received.  
  95. In this example, only a 10 is sent, which results in a Line Feed 
  96. being sent to the printer. This routine should facilitate sending 
  97. upper ASCII codes or some peculiar codes that would be inconvenient 
  98. to send otherwise. (Anyway, I figured out how to do it, that's all 
  99. that counts.) Other functions are more complex and can't be 
  100. approached in QB any other way.  
  101.  
  102. In the next example, the returned values of the registers are what
  103. are important.
  104.  
  105. '****************************************************************************
  106. 'This routine reads the current position of the cursor--row and column.
  107. '****************************************************************************
  108.  
  109. TYPE RegType
  110.      ax    AS INTEGER
  111.      bx    AS INTEGER
  112.      cx    AS INTEGER
  113.      dx    AS INTEGER
  114.      bp    AS INTEGER
  115.      si    AS INTEGER
  116.      di    AS INTEGER
  117.      flags AS INTEGER
  118. END TYPE
  119.  
  120. DIM SHARED inregs AS RegType, outregs AS RegType
  121.  
  122. DECLARE SUB readpos (row, col)
  123.  
  124. CLS
  125. LOCATE 9, 14
  126. readpos row, col
  127. PRINT row, col
  128.  
  129. SUB readpos (row, col)
  130.      inregs.ax = &H300: inregs.bx = 0: inregs.cx = 0: inregs.dx = 0
  131.      CALL interrupt(&H10, inregs, outregs)
  132.      dh = FIX(outregs.dx / 256)
  133.      dl = outregs.dx - (dh * 256))
  134.      row = dh + 1
  135.      col = dl + 1
  136. END SUB
  137.  
  138. '**************************************************************************** 
  139.  
  140. In this example, the value of &H3 is being sent to the AH register of
  141. INT &H10 as AX = &H300 (&H3 * 100). This causes the interrupt to send 
  142. back the cursor position contained in the DX register. The row value
  143. is contained in the DH section, column value in the DL section. 
  144. Thus, the math that seperates the DH and DL out of the DX register 
  145. is shown: 
  146.  
  147. dh equals the integer value of dx divided by 256.
  148. dl equals what's left in the dx register after the dh is removed.
  149.  
  150. Thus, if the cursor is at row 11, column 4, the dx register would
  151. return (10 * 265) + 3  or 2653. (The row and column are noted as
  152. beginning at LOCATE 0,0 which is impossible in QB, but means 
  153. LOCATE 1,1).
  154.  
  155. When the information you want is packed at the binary level, the 
  156. unpacking is more complex. In the following example, the individual 
  157. bits are seperated to see what each 0 or 1 value is:
  158.  
  159. '*****************************************************************************
  160. 'This routine checks to see if printer (assumes LPT1:) is turned on. If the
  161. 'returned value is 0 then the printer is OFF LINE, if 1 the printer is ON lINE
  162. '*****************************************************************************
  163.  
  164. TYPE RegType
  165.      ax    AS INTEGER
  166.      bx    AS INTEGER
  167.      cx    AS INTEGER
  168.      dx    AS INTEGER
  169.      bp    AS INTEGER
  170.      si    AS INTEGER
  171.      di    AS INTEGER
  172.      flags AS INTEGER
  173. END TYPE
  174.  
  175. DIM SHARED inregs AS RegType, outregs AS RegType
  176.  
  177. DECLARE FUNCTION printer ()
  178.  
  179. PRINT printer
  180.  
  181. FUNCTION printer
  182.      inregs.ax = 2 * 256: inregs.dx = 0
  183.      CALL interrupt(&H17, inregs, outregs)
  184.      ah = FIX(outregs.ax / 256)
  185.      bit7 = FIX(ah / 128)
  186.      bit6 = FIX((ah - (bit7 * 128)) / 64)
  187.      bit5 = FIX((ah - (bit7 * 128) - (bit6 * 64)) / 32)
  188.      bit4 = FIX((ah - (bit7 * 128) - (bit6 * 64) - (bit5 * 32)) / 16)
  189.      bit3 = FIX((ah - (bit7 * 128) - (bit6 * 64) - (bit5 * 32) - (bit4 * 16)) / 8)
  190.      bit2 = FIX((ah - (bit7 * 128) - (bit6 * 64) - (bit5 * 32) - (bit4 * 16) - (bit3 * 8)) / 4)
  191.      bit1 = FIX((ah - (bit7 * 128) - (bit6 * 64) - (bit5 * 32) - (bit4 * 16) - (bit3 * 8) - (bit2 * 4)) / 2)
  192.      bit0 = FIX((ah - (bit7 * 128) - (bit6 * 64) - (bit5 * 32) - (bit4 * 16) - (bit3 * 8) - (bit2 * 4) - (bit1 * 2)))
  193.      PRINT bit0; bit1; bit2; bit3; bit4; bit5; bit6; bit7
  194.      printer = ABS(bit6)
  195. END FUNCTION
  196.  
  197. In this value, bit 6 contains the clue as to whether the printer is 
  198. turned on.  This example sends the value of 2 to AH of INT &H17 and 
  199. then reads the bits in the AH section of OUTREGS.AX.  
  200.  
  201. '*******************************************************************
  202.  
  203. This archive contains a set of interrupt routines written in 
  204. QuickBasic 4.5. To use them, load the QB.QLB file when you enter the 
  205. editor.  
  206.  
  207. Example command line:  QB video /Lqb.qlb 
  208.  
  209. To compile from the DOS line, modify the link command as follows: 
  210.  
  211. LINK ,,,qb.lib, 
  212.  
  213.  
  214. The next piece of information you need is to know which interrupts 
  215. do what and what registers to use. Fortunately, a group of super-PD
  216. programmers have compiled a list of all the known interrupt calls.
  217. A summary of that file is in INTERRUP.SUM and a half subset of their
  218. full text is in INTERRUP.NEW. To get the full file, plus all the 
  219. rest of their information, look for their updates on EXEC-PC or 
  220. other major bulletin boards. This subset is included to get you 
  221. started.
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.