home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #6 / Datatid_1999-06.iso / internet / Tango352Promo / P.SQL / PTKPKG.1 / BMEMCOPY.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-04-12  |  11.2 KB  |  582 lines

  1. ;/*************************************************************************
  2. ;**
  3. ;**  Copyright 1982-1995 Btrieve Technologies, Inc. All Rights Reserved
  4. ;**
  5. ;*************************************************************************/
  6. ;/*************************************************************************
  7. ;   BMEMCOPY.ASM
  8. ;     You need the object for this module if your application uses
  9. ;     the Borland Powerpack 32-Bit DOS Extender (BTI_DOS_32B) or the
  10. ;     Phar Lap TNT 32-Bit DOS Extender (BTI_DOS_32P).  We provide
  11. ;     this source for your reference needs.  You don't need it if
  12. ;     you use 'bmemcopy.obj', which is already assembled.
  13. ;
  14. ;     IMPORTANT
  15. ;     ---------
  16. ;     Btrieve Technologies, Inc., invites you to modify this file
  17. ;     if you find it necessary for your particular situation.  However,
  18. ;     we cannot provide technical support for this module if you
  19. ;     do modify it.
  20. ;
  21. ;*************************************************************************/
  22. .386                            ; must have .386 otherwise masm
  23.                                 ; will try to generate 16-bit code
  24.         TITLE   Functions to copy data to/from DOS real memory
  25.         _TEXT   SEGMENT
  26.         ASSUME  CS:_TEXT
  27.         PUBLIC  _getLowMemByte
  28.         PUBLIC  _setLowMemByte
  29.         PUBLIC  _getLowMemWord
  30.         PUBLIC  _setLowMemWord
  31.         PUBLIC  _getLowMemLong
  32.         PUBLIC  _setLowMemLong
  33.         PUBLIC  _copyToLow
  34.         PUBLIC  _copyFromLow
  35. ;
  36. ;*
  37. ;****************************************************************************
  38. ;*
  39. ;*  Prototype:
  40. ;*
  41. ;*        BTI_CHAR  cdecl getLowMemByte(
  42. ;*                           BTI_WORD  sel,
  43. ;*                           BTI_ULONG selOffset);
  44. ;*
  45. ;*  Description:
  46. ;*
  47. ;*      Returns a byte from low memory using the given 
  48. ;*      selector and offset.
  49. ;*
  50. ;*  Preconditions:
  51. ;*
  52. ;*      None.
  53. ;*
  54. ;*  Parameters:
  55. ;*
  56. ;*      sel:               Protected mode selector                   
  57. ;*        <input>
  58. ;*
  59. ;*      selOffset:         Protected mode offset
  60. ;*        <input>
  61. ;*
  62. ;*
  63. ;*  Return value:
  64. ;*
  65. ;*      a byte
  66. ;*
  67. ;*  Globals:
  68. ;*
  69. ;*      None.
  70. ;*
  71. ;*  Called Functions:
  72. ;*
  73. ;*      None.
  74. ;*
  75. ;*  Comments:
  76. ;*
  77. ;*      None.
  78. ;*
  79. ;****************************************************************************
  80. ;*
  81. ;
  82. _getLowMemByte   PROC    NEAR
  83.    push ebp
  84.    mov  ebp,esp
  85.    push ebx
  86.    mov  ebx,[ebp+12] ; selOffset
  87.    push ds
  88.    mov  ds, [ebp+8]  ; sel
  89.    mov  al, ds:[ebx]
  90.    pop  ds
  91.    xor  ah, ah
  92.    pop  ebx
  93.    pop  ebp
  94.    ret
  95.  
  96. _getLowMemByte ENDP
  97.  
  98. ;
  99. ;*
  100. ;****************************************************************************
  101. ;*
  102. ;*  Prototype:
  103. ;*
  104. ;*      BTI_CHAR setLowMemByte(
  105. ;*                  BTI_WORD  sel,
  106. ;*                  BTI_ULONG selOffset,
  107. ;*                  BTI_BYTE  src )
  108. ;*
  109. ;*  Description:
  110. ;*
  111. ;*      Copy a byte to low memory at the given address
  112. ;*
  113. ;*  Preconditions:
  114. ;*
  115. ;*      None.
  116. ;*
  117. ;*  Parameters:
  118. ;*
  119. ;*      sel:            Selector of destination address 
  120. ;*        <input>
  121. ;*
  122. ;*      selOffset:      Offset of destination address
  123. ;*        <input>
  124. ;*
  125. ;*      src:            Byte to be copied.
  126. ;*        <input>
  127. ;*
  128. ;*
  129. ;*  Return value:
  130. ;*
  131. ;*      None.
  132. ;*
  133. ;*  Globals:
  134. ;*
  135. ;*      None.
  136. ;*
  137. ;*  Called Functions:
  138. ;*
  139. ;*      None.
  140. ;*
  141. ;*  Comments:
  142. ;*
  143. ;*      None.
  144. ;*
  145. ;****************************************************************************
  146. ;*
  147. _setLowMemByte  PROC    NEAR
  148.    push ebp
  149.    mov  ebp, esp
  150.    push ebx
  151.    mov  ebx, [ebp+12]
  152.    mov  al, [ebp+16]
  153.    push es
  154.    mov  es, [ebp+8]
  155.    mov  es:[ebx], al
  156.    pop  es
  157.    xor  ah, ah
  158.    pop  ebx
  159.    pop  ebp
  160.    ret
  161. _setLowMemByte ENDP
  162.  
  163. ;*
  164. ;****************************************************************************
  165. ;*
  166. ;*  Prototype:
  167. ;*
  168. ;*      BTI_WORD getLowMemWord( BTI_WORD sel, BTI_ULONG selOffset )
  169. ;*
  170. ;*  Description:
  171. ;*
  172. ;*      Return the word at location given by sel:selOffset
  173. ;*
  174. ;*  Preconditions:
  175. ;*
  176. ;*      None.
  177. ;*
  178. ;*  Parameters:
  179. ;*
  180. ;*      sel:            Selector of source address
  181. ;*        <input>
  182. ;*
  183. ;*      selOffset:      Offset of source address
  184. ;*        <input>       
  185. ;*
  186. ;*
  187. ;*  Return value:
  188. ;*
  189. ;*      The word that resides in low memory at sel:selOffset
  190. ;*
  191. ;*  Globals:
  192. ;*
  193. ;*      None.
  194. ;*
  195. ;*  Called Functions:
  196. ;*
  197. ;*      None.
  198. ;*
  199. ;*  Comments:
  200. ;*
  201. ;*      None.
  202. ;*
  203. ;****************************************************************************
  204. ;*
  205. _getLowMemWord  PROC    NEAR
  206.    push ebp
  207.    mov  ebp, esp
  208.    push ebx
  209.    mov  ebx, [ebp + 12]
  210.    push ds
  211.    mov  ds, [ebp+8]
  212.    mov  ax, ds:[ebx]
  213.    pop  ds
  214.    pop  ebx
  215.    pop  ebp
  216.    ret
  217. _getLowMemWord ENDP
  218.  
  219. ;
  220. ;*
  221. ;****************************************************************************
  222. ;*
  223. ;*  Prototype:
  224. ;*
  225. ;*      BTI_WORD setLowMemWord(
  226. ;*                  BTI_WORD sel,
  227. ;*                  BTI_ULONG selOffset,
  228. ;*                  BTI_WORD src )
  229. ;*
  230. ;*  Description:
  231. ;*
  232. ;*      Copy the src value to low memory at sel:selOffset
  233. ;*
  234. ;*  Preconditions:
  235. ;*
  236. ;*      None.
  237. ;*
  238. ;*  Parameters:
  239. ;*
  240. ;*      sel:            Selector of destination address
  241. ;*        <input>
  242. ;*
  243. ;*      selOffset:      Offset of destination address
  244. ;*        <input>
  245. ;*
  246. ;*      src:            Value to be copied.
  247. ;*        <input>
  248. ;*
  249. ;*
  250. ;*  Return value:
  251. ;*
  252. ;*      None.
  253. ;*
  254. ;*  Globals:
  255. ;*
  256. ;*      None.
  257. ;*
  258. ;*  Called Functions:
  259. ;*
  260. ;*      None.
  261. ;*
  262. ;*  Comments:
  263. ;*
  264. ;*      None.
  265. ;*
  266. ;****************************************************************************
  267. ;*
  268. ;
  269. _setLowMemWord  PROC NEAR
  270.    push ebp
  271.    mov  ebp, esp
  272.    push ebx
  273.    mov  ebx, [ebp+12]           ; offset
  274.    mov  ax, [ebp+16]            ; data value
  275.    push es
  276.    mov  es, [ebp+8]             ; selector
  277.    mov  es:[ebx], ax
  278.    pop  es
  279.    pop  ebx
  280.    pop  ebp
  281.    ret
  282. _setLowMemWord  ENDP
  283.  
  284. ;
  285. ;*
  286. ;****************************************************************************
  287. ;*
  288. ;*  Prototype:
  289. ;*
  290. ;*      BTI_ULONG getLowMemLong( BTI_WORD sel, BTI_ULONG selOffset )
  291. ;*
  292. ;*  Description:
  293. ;*
  294. ;*      Copy 4 bytes from sel:selOffset
  295. ;*
  296. ;*  Preconditions:
  297. ;*
  298. ;*      None.
  299. ;*
  300. ;*  Parameters:
  301. ;*
  302. ;*      sel:                    selector of source address
  303. ;*        <input>
  304. ;*
  305. ;*      selOffset:              offset of source address
  306. ;*        <input>
  307. ;*
  308. ;*
  309. ;*  Return value:
  310. ;*
  311. ;*      Long value is returned in AX register
  312. ;*
  313. ;*  Globals:
  314. ;*
  315. ;*      None.
  316. ;*
  317. ;*  Called Functions:
  318. ;*
  319. ;*      None.
  320. ;*
  321. ;*  Comments:
  322. ;*
  323. ;*      None.
  324. ;*
  325. ;****************************************************************************
  326. ;*
  327. ;
  328. _getLowMemLong  PROC    NEAR
  329.    push ebp
  330.    mov  ebp,esp  
  331.    push ebx
  332.    mov  ebx, [ebp+12]                   ; offset
  333.    push ds
  334.    mov  ds, [ebp+8]                     ; selector
  335.    mov  eax, ds:[ebx]
  336.    pop  ds
  337.    pop  ebx
  338.    pop  ebp
  339.    ret
  340. _getLowMemLong  ENDP
  341.  
  342.  
  343. ;
  344. ;*
  345. ;****************************************************************************
  346. ;*
  347. ;*  Prototype:
  348. ;*
  349. ;*      BTI_ULONG setLowMemLong(
  350. ;*                   BTI_WORD  sel,
  351. ;*                   BTI_ULONG selOffset,
  352. ;*                   BTI_ULONG src )
  353. ;*
  354. ;*  Description:
  355. ;*
  356. ;*      Copy 4 bytes from src to sel:selOffset in low memory
  357. ;*
  358. ;*  Preconditions:
  359. ;*
  360. ;*      None.
  361. ;*
  362. ;*  Parameters:
  363. ;*
  364. ;*      sel:                    selector of source address
  365. ;*        <input>
  366. ;*
  367. ;*      selOffset:              offset of source address
  368. ;*        <input>
  369. ;*
  370. ;*      src:                    source to copy
  371. ;*        <input>
  372. ;*
  373. ;*
  374. ;*  Return value:
  375. ;*
  376. ;*      None.
  377. ;*
  378. ;*  Globals:
  379. ;*
  380. ;*      None.
  381. ;*
  382. ;*  Called Functions:
  383. ;*
  384. ;*      None.
  385. ;*
  386. ;*  Comments:
  387. ;*
  388. ;*      None.
  389. ;*
  390. ;****************************************************************************
  391. ;*
  392. ;
  393. _setLowMemLong  PROC NEAR
  394.    push ebp
  395.    mov  ebp,esp
  396.    push ebx
  397.    mov  ebx, [ebp+12]    ;selOffset
  398.    mov  eax, [ebp+16]    ;src
  399.    push es
  400.    mov  es, [ebp+8]      ;sel
  401.    mov  es:[ebx], eax
  402.    pop  es
  403.    pop  ebx
  404.    pop  ebp
  405.    ret
  406. _setLowMemLong ENDP
  407.  
  408.  
  409. ;
  410. ;*
  411. ;****************************************************************************
  412. ;*
  413. ;*  Prototype:
  414. ;*
  415. ;*      void    copyToLow(
  416. ;*                 unsigned short dst_sel,
  417. ;*                 unsigned dst_offset,
  418. ;*                 void * src,
  419. ;*                 unsigned int size)
  420. ;*
  421. ;*  Description:
  422. ;*
  423. ;*      Copies a block to a specified real mode address from
  424. ;*      a 32-bit flat address.
  425. ;*
  426. ;*  Preconditions:
  427. ;*
  428. ;*      None.
  429. ;*
  430. ;*  Parameters:
  431. ;*
  432. ;*      dst_sel:                Destination selector
  433. ;*        <input>
  434. ;*
  435. ;*      dst_offset:             Destination offset
  436. ;*        <input>
  437. ;*
  438. ;*      src:                    32-bit pointer to source 
  439. ;*        <input>
  440. ;*
  441. ;*      size:                   Length of source
  442. ;*        <input>
  443. ;*
  444. ;*
  445. ;*  Return value:
  446. ;*
  447. ;*      None.
  448. ;*
  449. ;*  Globals:
  450. ;*
  451. ;*      None.
  452. ;*
  453. ;*  Called Functions:
  454. ;*
  455. ;*      None.
  456. ;*
  457. ;*  Comments:
  458. ;*
  459. ;*      None.
  460. ;*
  461. ;****************************************************************************
  462. ;*
  463. ;
  464. _copyToLow      PROC NEAR
  465.    push ebp
  466.    mov  ebp, esp
  467.    push ebx
  468.    push edi
  469.    push esi
  470.    push es
  471.    mov  es , [ebp+8]    ; dst_sel
  472.    mov  edi, [ebp+12]   ; dst_offset
  473.    mov  esi, [ebp+16]   ; src
  474.    cld
  475.    mov  ecx, [ebp+20]   ; size
  476.    shr  ecx, 2          ; move double words
  477.    rep  movsd
  478.    mov  ecx, [ebp+20]
  479.    and  ecx, 3          ; move extra bytes
  480.    jcxz no_copy_to
  481.    rep  movsb
  482. no_copy_to:
  483.    pop  es
  484.    pop  esi
  485.    pop  edi
  486.    pop  ebx
  487.    pop  ebp
  488.    ret
  489. _copyToLow ENDP
  490.  
  491. ;
  492. ;*
  493. ;****************************************************************************
  494. ;*
  495. ;*  Prototype:
  496. ;*
  497. ;*      void copyFromLow(
  498. ;*              void * dst,
  499. ;*              unsigned short src_sel,
  500. ;*              unsigned src_offset,
  501. ;*              unsigned int size)
  502. ;*
  503. ;*  Description:
  504. ;*
  505. ;*      copies a block from a specified real mode address to
  506. ;*      a 32-bit flat address.
  507. ;*
  508. ;*  Preconditions:
  509. ;*
  510. ;*      None.
  511. ;*
  512. ;*  Parameters:
  513. ;*
  514. ;*      dst:            32-bit destination address
  515. ;*        <input>
  516. ;*
  517. ;*      src_sel:        Selector of source address
  518. ;*        <input>
  519. ;*
  520. ;*      src_offset:     Offset of source address
  521. ;*        <input>
  522. ;*
  523. ;*      size:           Size to copy
  524. ;*        <input>
  525. ;*
  526. ;*
  527. ;*  Return value:
  528. ;*
  529. ;*      None.
  530. ;*
  531. ;*  Globals:
  532. ;*
  533. ;*      None.
  534. ;*
  535. ;*  Called Functions:
  536. ;*
  537. ;*      None.
  538. ;*
  539. ;*  Comments:
  540. ;*
  541. ;*      None.
  542. ;*
  543. ;****************************************************************************
  544. ;*
  545. ;
  546. _copyFromLow    PROC NEAR
  547.       push ebp
  548.       mov  ebp,esp
  549.       push ebx
  550.       push edi
  551.       push esi
  552.       push es
  553.       push ds
  554.  
  555.       push ds
  556.       pop  es
  557.       mov  edi, [ebp+8]         ; dst
  558.       mov  ds , [ebp+12]        ; src_sel
  559.       mov  esi, [ebp+16]        ; src_offset
  560.       cld
  561.       mov  ecx, [ebp+20]        ; size
  562.       shr  ecx, 2               ; move double words
  563.       rep  movsd
  564.       mov  ecx, [ebp+20]
  565.       and  ecx, 3               ; move extra bytes
  566.       jcxz no_copy_from
  567.       rep  movsb
  568.  
  569. no_copy_from:
  570.       pop  ds
  571.       pop  es
  572.       pop  esi
  573.       pop  edi
  574.       pop  ebx
  575.       pop  ebp
  576.       ret
  577. _copyFromLow ENDP
  578.  
  579.  
  580. _TEXT   ENDS
  581.         END
  582.