home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_03 / v6n3040a.txt < prev    next >
Text File  |  1989-09-28  |  2KB  |  125 lines

  1. ;
  2. ; peekpoke.asm -- peek and poke functions for Eco-C88 which function
  3. ; like those in the Datalight library instead of those in the
  4. ; Ecosoft library.
  5. ;
  6.  
  7. Include amodel.h
  8. Include c:\headers\pro.h
  9.  
  10. If BIGCODE
  11.     ARG    Equ    6        ; offset of first argument
  12. else
  13.     ARG    Equ    4
  14. endif
  15.  
  16. ; put the code in $b$prog even though it is big code
  17. ; to save segments
  18.  
  19. $b$prog    Segment    'code'
  20.  
  21. ;
  22. ; peekbuf -- peek and return in buffer.  Peek at the location
  23. ; specified by segment seg and offset off for numbytes bytes.
  24. ; Place the data found in the buffer pointed to by buf.
  25. ;
  26. ; The C declration would look like:
  27. ;
  28. ;    void peekbuf(seg, off, buf, numbytes)
  29. ;    int seg, off, numbytes;
  30. ;    char *buf;
  31. ;
  32.  
  33.     Public    _peekbuf
  34. If    BIGCODE
  35. _peekbuf    Proc    Far
  36. else
  37. _peekbuf    Proc    Near
  38. endif
  39.  
  40.     PUSH    BP
  41.     MOV    BP,SP
  42.     PUSH    DS
  43.     PUSH    ES
  44.     MOV    DS,[BP][ARG]        ; source segment
  45.     MOV    SI,[BP][ARG+2]        ; source pointer in DS:SI
  46. If    BIGDATA
  47.     LES    DI,[BP][ARG+4]        ; get pointer to buf in ES:DI
  48.     MOV    CX,[BP][ARG+8]
  49. else
  50.     MOV    AX,SS
  51.     MOV    ES,AX
  52.     MOV    DI,[BP][ARG+4]        ; get pointer to buf in ES:DI
  53.     MOV    CX,[BP][ARG+6]        ; get byte count
  54. endif
  55.  
  56.     SHR    CX,1        ; convert bytes to words
  57.     JZ    mla        ; jump if no full words to move
  58. REP    MOVSW            ; move the words
  59. mla:    JNC    mlfin        ; no bytes to move
  60.     MOVSB            ; move the left over byte
  61. mlfin:
  62.  
  63.     POP    ES            ; restore es
  64.     POP    DS            ; restore ds
  65.     POP    BP
  66.     RET
  67. _peekbuf    EndP
  68.  
  69.  
  70. ;
  71. ; pokebuf -- poke from buffer into memory.  Poke the contents of
  72. ; buf into memory at the location specified by segment seg and
  73. ; offset off for numbytes bytes.
  74. ;
  75. ; The C declaration would look like:
  76. ;
  77. ;    void pokebuf(seg, off, buf, numbytes)
  78. ;    int seg, off, numbytes;
  79. ;    char *buf;
  80. ;
  81.  
  82.     Public    _pokebuf
  83. If    BIGCODE
  84. _pokebuf    Proc    Far
  85. else
  86. _pokebuf    Proc    Near
  87. endif
  88.  
  89.     PUSH    BP
  90.     MOV    BP,SP
  91.  
  92. If    BIGDATA
  93.     PUSH    DS
  94.     MOV    ES,[BP][ARG]    ;segment of destination
  95.     MOV    DI,[BP][ARG+2]    ;ES:DI -> destination
  96.     LDS    SI,[BP][ARG+4]    ;DS:SI -> buf (source pointer)
  97.     MOV    CX,[BP][ARG+8]    ;# of bytes to move
  98. else
  99.     PUSH    ES
  100.     MOV    ES,[BP][ARG]    ;segment of destination
  101.     MOV    DI,[BP][ARG+2]    ;offset of destination
  102.     MOV    SI,[BP][ARG+4]    ;buf (source offset)
  103.     MOV    CX,[BP][ARG+6]    ;# of bytes to move
  104. endif
  105.  
  106.     SHR    CX,1        ; convert bytes to words
  107.     JZ    mlb        ; jump if no full words to move
  108. REP    MOVSW            ; move the words
  109. mlb:    JNC    mldone        ; no bytes to move
  110.     MOVSB            ; move the left over byte
  111. mldone:
  112.  
  113. If    BIGDATA
  114.     POP    DS
  115. else
  116.     POP    ES
  117. endif
  118.  
  119.     POP    BP
  120.     RET
  121. _pokebuf    EndP
  122.  
  123. $b$prog    EndS
  124.     End
  125.