home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / VOL8N11.ZIP / EXTMEM.ASM < prev    next >
Assembly Source File  |  1989-02-03  |  4KB  |  144 lines

  1.         title   EXTMEM --- get/put extended memory
  2.         page    55,132
  3.  
  4. ; EXTMEM.ASM --- Routines to transfer data between
  5. ;                conventional and extended memory.
  6. ;                For use with small model C programs.
  7. ; Copyright (C) 1989 Ziff Davis Communications
  8. ; PC Magazine * Ray Duncan
  9. ;
  10. ; Assemble with: MASM /Zi /Mx EXTMEM;
  11.  
  12. DGROUP  group   _DATA
  13.  
  14. _DATA   segment word public 'DATA'
  15.  
  16. gdt     db      30h dup (0)     ; global descriptor table
  17.  
  18. _DATA   ends
  19.  
  20.  
  21. _TEXT   segment word public 'CODE'
  22.  
  23.         assume  cs:_TEXT,ds:DGROUP
  24.  
  25. args    equ     [bp+4]          ; offset of arguments, small model
  26. source  equ     word ptr args
  27. dest    equ     word ptr source+4
  28. len     equ     word ptr dest+4
  29.  
  30. ;
  31. ; GETXM copies data from extended memory to conventional memory.
  32. ; status = getxm(unsigned long source, void far *dest, unsigned len)
  33. ;
  34. ; Status is zero if move successful, nonzero if move failed:
  35. ; 1 = parity error, 2 = exception interrupt error, 3 = gate A20 failed
  36. ;
  37.         public  _getxm
  38. _getxm  proc    near
  39.  
  40.         push    bp              ; set up stack frame
  41.         mov     bp,sp
  42.         push    si              ; protect register variables
  43.         push    di
  44.  
  45.         push    ds              ; let ES:SI point to
  46.         pop     es              ; global descriptor table
  47.         mov     si,offset DGROUP:gdt
  48.  
  49.                                 ; store access rights bytes
  50.         mov     byte ptr es:[si+15h],93h
  51.         mov     byte ptr es:[si+1dh],93h
  52.  
  53.         mov     ax,source       ; store source address
  54.         mov     es:[si+12h],ax  ; into descriptor
  55.         mov     ax,source+2
  56.         mov     es:[si+14h],al
  57.  
  58.         mov     ax,dest+2       ; destination segment * 16
  59.         mov     dx,16
  60.         mul     dx
  61.         add     ax,dest         ; + offset -> linear address
  62.         adc     dx,0
  63.         mov     es:[si+1ah],ax  ; store destination address
  64.         mov     es:[si+1ch],dl  ; into descriptor
  65.  
  66.         mov     cx,len  ; store length into source
  67.         mov     es:[si+10h],cx  ; and destination descriptors
  68.         mov     es:[si+18h],cx 
  69.  
  70.         shr     cx,1            ; convert length to words
  71.         mov     ah,87h          ; Int 15H Fxn 87h = block move
  72.         int     15h             ; transfer to ROM BIOS 
  73.  
  74.         mov     al,ah           ; form status in AX     
  75.         cbw
  76.  
  77.         pop     di              ; restore registers
  78.         pop     si
  79.         pop     bp
  80.         ret                     ; back to caller
  81.  
  82. _getxm  endp
  83.  
  84. ;
  85. ; PUTXM copies data from conventional memory to extended memory.
  86. ; status = putxm(void far *source, unsigned long dest, unsigned len)
  87. ;
  88. ; Status is zero if move successful, nonzero if move failed:
  89. ; 1 = parity error, 2 = exception interrupt error, 3 = gate A20 failed
  90. ;
  91.         public  _putxm
  92. _putxm  proc    near
  93.  
  94.         push    bp              ; set up stack frame
  95.         mov     bp,sp
  96.         push    si              ; protect register variables
  97.         push    di
  98.  
  99.         push    ds              ; let ES:SI point to
  100.         pop     es              ; global descriptor table
  101.         mov     si,offset DGROUP:gdt
  102.  
  103.                                 ; store access rights bytes
  104.         mov     byte ptr es:[si+15h],93h
  105.         mov     byte ptr es:[si+1dh],93h
  106.  
  107.         mov     ax,dest         ; store destination address
  108.         mov     es:[si+1ah],ax  ; into descriptor
  109.         mov     ax,dest+2
  110.         mov     es:[si+1ch],al
  111.  
  112.         mov     ax,source+2     ; source segment * 16
  113.         mov     dx,16
  114.         mul     dx
  115.         add     ax,source       ; + offset -> linear address
  116.         adc     dx,0
  117.         mov     es:[si+12h],ax  ; store source address
  118.         mov     es:[si+14h],dl  ; into descriptor
  119.  
  120.         mov     cx,len          ; store length into source
  121.         mov     es:[si+10h],cx  ; and destination descriptors
  122.         mov     es:[si+18h],cx 
  123.  
  124.         shr     cx,1            ; convert length to words
  125.         mov     ah,87h          ; Int 15H Fxn 87h = block move
  126.         int     15h             ; transfer to ROM BIOS 
  127.  
  128.         mov     al,ah           ; form status in AX
  129.         cbw
  130.  
  131.         pop     di              ; restore registers
  132.         pop     si
  133.         pop     bp
  134.         ret                     ; back to caller
  135.  
  136. _putxm  endp
  137.  
  138. _TEXT   ends
  139.  
  140.         end
  141.  
  142.