home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 11 / labnotes / peekpoke.asm < prev    next >
Assembly Source File  |  1992-02-24  |  3KB  |  70 lines

  1. ;PeekPoke.ASM
  2. ;Copyright (c) 1992 Jay Munro
  3. ;First published in PC Magazine June 16,1992
  4.  
  5. ;Syntax
  6. ;  Declare Function Peek%(Byval SegSelector%, Byval Offset%)
  7. ;  LptPortAddress% = Peek%(GetAbs%(&h0040),&h0) + (256 * Peek%(GetAbs%(&h0040),&h1)
  8. ;
  9. ;  Declare Sub Poke(Byval SegSelector%, Byval Offset%, Byval DataByte%)
  10. ;  Call Poke(GetAbs%(&hB800),0,65)              ;put an A on a second monitor.
  11. ;
  12. ;----------------------------------------------------------------------------
  13. ;  Peek and Poke are replacements (or add ons) for Visual Basic and operate
  14. ;  in a similar way to QuickBasic.  The difference is that VB doesn't have a
  15. ;  Def Seg, so we must pass the segment ( or selector) to the routine.   The
  16. ;  routines check the selector to see if it has read or write privileges to
  17. ;  avoid getting a trap 13 error (or UAE) in Windows.  The Peek routine
  18. ;  returns an 2 byte integer, but only one byte is used to remain compatible
  19. ;  with QuickBasic.  To modify it to return a full word, delete the Xor AH,AH
  20. ;  near the end of the routine.
  21.  
  22. ;  Poke takes an integer parameter, but only uses the low byte portion in
  23. ;  storing the byte.  The AL register can be modified to AX for word storage.
  24. ;----------------------------------------------------------------------------
  25.  
  26. .286P
  27. .Model Medium
  28.     Include LabNotes.Inc
  29.     Public Peek, Poke
  30.     
  31. .Code
  32.  
  33. Peek Proc Far
  34.     ShortWinProlog              ;DS not used
  35.     Verr Word Ptr [BP+8]                 ;check selector for readability
  36.     Jz   @F                     ;yes, continue
  37.     Mov  AX,-1                  ;no, exit with -1
  38.     Jmp  Exit
  39. @@:
  40.     Push DS                     ;save DS
  41.     Lds  BX,[BP+6]              ;get segment:offset to Peek
  42.     Mov  AL,[BX]                ;get byte from memory
  43.     Pop  DS                     ;restore DS
  44.     Xor  AH,AH                  ;clear AH to return 1 byte
  45. Exit:
  46.     ShortWinEpilog              ;restore stack to original
  47.     Ret  4                      ;
  48. Peek EndP
  49.  
  50. Poke Proc Far
  51.     ShortWinProlog              ;DS not used
  52.     Verw Word Ptr [BP+10]       ;check segment for writability
  53.     Jz   @F                     ;zero set, must be good
  54.     Mov  AX,-1                  ;zero not, jump out with -1
  55.     Jmp  PokeExit
  56. @@:
  57.     Push DS                     ;save DS
  58.     Lds  BX,[BP+8]              ;get address to poke
  59.     Mov  AX,[BP+6]              ;get data byte
  60.     Mov  [BX],AL                ;store byte
  61.     Pop  DS                     ;retrieve DS
  62.  
  63. PokeExit:
  64.     ShortWinProlog
  65.     Ret  6
  66. Poke EndP
  67.  
  68. End
  69.     
  70.