home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY5 / DEFSEG.ZIP / DEFSEG.BAS
BASIC Source File  |  1990-06-13  |  3KB  |  80 lines

  1.       goto EXAMPLE
  2.  
  3. function CurDefSeg%
  4. 'author......| Michael E. Flenniken
  5. 'version.....| 1.00  6/13/90     for PowerBASIC v2.00b
  6. 'parameters..| None
  7. 'success.....| Returns segment of the most recent DEF SEG
  8. 'notes.......| This is a two part function.  sub GetDefSeg() must be present.
  9. '            | function CurDefSeg% must be initiallized.  The first call to
  10. '            | CurDefSeg% intiallizes it and returns PB's data segment.
  11. '            | Subsequent calls returns the current DEF SEG
  12. 'warnings....| Use at your own risk.
  13.     local  CurDataSeg%
  14.     static DefDataSeg%
  15.  
  16. if DefDataSeg% = 0 then        ' If this is the first time called
  17.     def seg                    '   initiallize with PB data segment
  18.     DefDataSeg% = peeki(26)
  19.     CurDefSeg% = DefDataSeg%
  20. else                           ' Otherwise get and return the current def seg
  21.     call GetDefSeg (DefDataSeg%, CurDataSeg%)
  22.     CurDefSeg% = CurDataSeg%
  23. end if
  24.  
  25. end function
  26.  
  27.  
  28. sub GetDefSeg inline   ' (PBDataSeg%, CurSeg%)
  29.  
  30. $inline &h55               ' PUSH BP           ; Save BP
  31. $inline &h89, &hE5         ' MOV  BP, SP       ; Move SP to BP
  32. $inline &h1E               ' PUSH DS           ; Save DS
  33. $inline &hC4, &h7E, &h0A   ' LES  DI, [BP+0A]  ; ES:DI is ptr to PBDataSeg%
  34. $inline &h26, &h8E, &h1D   ' MOV  DS, ES:[DI]  ; set DS to PB data segment
  35. $inline &hBE, &h1A, &h00   ' MOV  SI, 1A       ; Current def seg @ offset 26
  36. $inline &hAD               ' LODSW             ; Load current def seg to AX
  37. $inline &hC4, &h7E, &h06   ' LES  DI, [BP+06]  ; ES:DI is ptr to CurSeg%
  38. $inline &hAB               ' STOWSW            ; Store AX to CurSeg%
  39. $inline &h1F               ' POP  DS           ; Restore DS
  40. $inline &h5D               ' POP  BP           ; Restore BP
  41.  
  42. end sub
  43.  
  44.  
  45.  
  46.  
  47. EXAMPLE:
  48. cls
  49. ? "The PB data segment is"; CurDefSeg%     ' Initiallize function CurDefSeg%
  50. def seg = 1000                             ' Change def seg for demo
  51. ? : ? "The `def seg' is"; CurDefSeg%       ' Show def seg
  52. call CheckKeyboardStatus                   ' Call routine that changes def seg
  53. ?: ? "The `def seg' is still"; CurDefSeg%  ' Show that def seg was preserved
  54.  
  55. sub CheckKeyboardStatus
  56.  
  57. CurrentDefSeg% = CurDefSeg%                ' Preserve current def seg
  58. def seg = &h40                             ' Change def seg to BIOS data seg
  59. KeyStatus% = peek(&h17)                    ' Get the keyboard status byte
  60. def seg = CurrentDefSeg%                   ' Reset def seg
  61.  
  62. ?                                          ' Display status of keyboard
  63. if (KeyStatus% and &b01000000) <> 0 then
  64.     ? "CapsLock is on"
  65. else
  66.     ? "CapsLock is off"
  67. end if
  68. if (KeyStatus% and &b00100000) <> 0 then
  69.     ? "NumLock is on"
  70. else
  71.     ? "NumLock is off"
  72. end if
  73. if (KeyStatus% and &b00010000) <> 0 then
  74.     ? "ScrollLock is on"
  75. else
  76.     ? "ScrollLock is off"
  77. end if
  78.  
  79. end sub
  80.