home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / SHARE / prog / prograf.exe / dpmi.cpp next >
Encoding:
C/C++ Source or Header  |  1998-04-29  |  3.4 KB  |  128 lines

  1. //▓▓ CLASE CDPMI ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  2. // 
  3. // * Llamadas al DPMI. Es imprescindible llamar al DPMI, cuando trabajamos
  4. //   en modo protegido y llamamos a funciones escritas en modo real.
  5. // * Añade las que consideres adecuadas ;)
  6. // 
  7. //  boolean  ReservaMemReal (int   Cantidad,word &Segmento,word &Selector);
  8. //  boolean  LiberaMemReal  (word &Selector);
  9. //  boolean  ReservaSelector(word &Selector);
  10. //  word     HazSel         (dword Base);
  11. //  boolean  LiberaSelector (word  Selector);
  12. //  dword    Fisica2Lineal  (dword Fisica, dword Limite);
  13. //
  14. // * Watcom C/C++ v.11
  15. //
  16. //▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ (c) Pedro Díez López ▓▓▓▓▓▓
  17.  
  18. #include "dpmi.h"
  19.  
  20. void    CDPMI::LimpiaMemoria   (void *Dir, dword Cantidad)
  21. {
  22.   __asm
  23.   {
  24.     mov  edi,[Dir]
  25.     mov  ecx,Cantidad
  26.     mov  ebx,ecx
  27.     xor  eax,eax
  28.     shr  ecx,2
  29.     and  ebx,3
  30.     rep  stosd
  31.     mov  ecx,ebx
  32.     rep  stosb
  33.   }
  34. }
  35.  
  36. void    CDPMI::RegsCero()
  37. {
  38.   LimpiaMemoria(&sregs,sizeof(sregs));
  39.   LimpiaMemoria(&inregs,sizeof(inregs));
  40.   segread(&sregs);
  41. }
  42.  
  43. boolean CDPMI::ReservaMemReal (int Cantidad, word &Segmento, word &Selector)
  44. {
  45.   RegsCero ();
  46.   inregs.w.ax=0x0100;           // Función 100h.. Rerserva memoria DOS.
  47.   inregs.w.bx=(Cantidad+15)>>4; // BX = Número de párrafos (16 bytes).
  48.   int386x( 0x31, &inregs, &outregs, &sregs);
  49.   Segmento=outregs.w.ax;        // Devuelve en AX el segmento del bloque.
  50.   Selector=outregs.w.dx;        // Devuelve en DX el selector del bloque.
  51.   if (outregs.x.cflag&1)        // Si hay CARRY -> Error
  52.   {
  53.     Segmento=outregs.w.bx;      // Devuelve en BX máximo de parrafos.
  54.     return(FALSE);              // lo sacamos en "word Segmento" ;)
  55.   }
  56.   else return(TRUE);
  57. }
  58.  
  59. boolean CDPMI::LiberaMemReal (word &Selector)
  60. {
  61.    RegsCero();
  62.    inregs.w.ax=0x0101;                        // Función 101h.. Libera memoria DOS
  63.    inregs.w.dx=Selector;                      // DX = Selector del bloque.
  64.    int386x( 0x31, &inregs, &outregs, &sregs);
  65.    if (outregs.x.cflag&1) return(FALSE);      // Si hay CARRY-> Error
  66.    else return(TRUE);
  67. }
  68.  
  69. word    CDPMI::HazSel (dword Base)
  70. {
  71.   dword Salida;
  72.   __asm
  73.   {
  74.     xor   eax,eax            // Crea un descriptor.
  75.     mov   ecx,1              // Función 00h
  76.     int   31h 
  77.     jc    @mal
  78.     mov   ebx,eax            // Establece direccion base
  79.     mov   edx,Base           // Función 07h
  80.     mov   ecx,edx
  81.     mov   eax,7
  82.     shr   ecx,16
  83.     int   31h 
  84.     jc    @mal
  85.     mov   edx,0ffffh         // Ponle el limite 00003F:FFFF
  86.     mov   eax,8              // Función 08h
  87.     mov   ecx,3fh
  88.     int   31h 
  89.     jc    @mal
  90.     mov   eax,ebx
  91.     jmp   @end
  92.   @mal:
  93.     mov   Salida,0
  94.   @end:
  95.     mov   Salida,eax
  96.   }
  97.   return ((word)Salida);    
  98. }  
  99.  
  100. boolean CDPMI::LiberaSelector (word Selector)
  101. {
  102.   boolean Ok;
  103.   Ok    = TRUE;
  104.   __asm
  105.   {
  106.     mov   bx, Selector
  107.     mov   eax,1
  108.     int   31h
  109.     jnc   @@Fin
  110.     mov   Ok,0
  111.   @@Fin:  
  112.   }
  113.   return (Ok);
  114. }
  115.  
  116. dword CDPMI::Fisica2Lineal (dword Fisica, dword Limite)
  117. {
  118.    RegsCero();
  119.    inregs.w.ax = 0x800;
  120.    inregs.w.bx = (word)(Fisica  >> 16);
  121.    inregs.w.cx = (word)(Fisica&0xFFFF);
  122.    inregs.w.si = (word)(Limite  >> 16);
  123.    inregs.w.di = (word)(Limite&0xFFFF);
  124.    int386(0x31, &inregs, &outregs);
  125.    if (outregs.x.cflag) return (FALSE);
  126.    else return ((long) outregs.w.bx << 16) + outregs.w.cx;
  127. }
  128.