home *** CD-ROM | disk | FTP | other *** search
- //▓▓ CLASE CDPMI ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- //
- // * Llamadas al DPMI. Es imprescindible llamar al DPMI, cuando trabajamos
- // en modo protegido y llamamos a funciones escritas en modo real.
- // * Añade las que consideres adecuadas ;)
- //
- // boolean ReservaMemReal (int Cantidad,word &Segmento,word &Selector);
- // boolean LiberaMemReal (word &Selector);
- // boolean ReservaSelector(word &Selector);
- // word HazSel (dword Base);
- // boolean LiberaSelector (word Selector);
- // dword Fisica2Lineal (dword Fisica, dword Limite);
- //
- // * Watcom C/C++ v.11
- //
- //▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ (c) Pedro Díez López ▓▓▓▓▓▓
-
- #include "dpmi.h"
-
- void CDPMI::LimpiaMemoria (void *Dir, dword Cantidad)
- {
- __asm
- {
- mov edi,[Dir]
- mov ecx,Cantidad
- mov ebx,ecx
- xor eax,eax
- shr ecx,2
- and ebx,3
- rep stosd
- mov ecx,ebx
- rep stosb
- }
- }
-
- void CDPMI::RegsCero()
- {
- LimpiaMemoria(&sregs,sizeof(sregs));
- LimpiaMemoria(&inregs,sizeof(inregs));
- segread(&sregs);
- }
-
- boolean CDPMI::ReservaMemReal (int Cantidad, word &Segmento, word &Selector)
- {
- RegsCero ();
- inregs.w.ax=0x0100; // Función 100h.. Rerserva memoria DOS.
- inregs.w.bx=(Cantidad+15)>>4; // BX = Número de párrafos (16 bytes).
- int386x( 0x31, &inregs, &outregs, &sregs);
- Segmento=outregs.w.ax; // Devuelve en AX el segmento del bloque.
- Selector=outregs.w.dx; // Devuelve en DX el selector del bloque.
- if (outregs.x.cflag&1) // Si hay CARRY -> Error
- {
- Segmento=outregs.w.bx; // Devuelve en BX máximo de parrafos.
- return(FALSE); // lo sacamos en "word Segmento" ;)
- }
- else return(TRUE);
- }
-
- boolean CDPMI::LiberaMemReal (word &Selector)
- {
- RegsCero();
- inregs.w.ax=0x0101; // Función 101h.. Libera memoria DOS
- inregs.w.dx=Selector; // DX = Selector del bloque.
- int386x( 0x31, &inregs, &outregs, &sregs);
- if (outregs.x.cflag&1) return(FALSE); // Si hay CARRY-> Error
- else return(TRUE);
- }
-
- word CDPMI::HazSel (dword Base)
- {
- dword Salida;
- __asm
- {
- xor eax,eax // Crea un descriptor.
- mov ecx,1 // Función 00h
- int 31h
- jc @mal
- mov ebx,eax // Establece direccion base
- mov edx,Base // Función 07h
- mov ecx,edx
- mov eax,7
- shr ecx,16
- int 31h
- jc @mal
- mov edx,0ffffh // Ponle el limite 00003F:FFFF
- mov eax,8 // Función 08h
- mov ecx,3fh
- int 31h
- jc @mal
- mov eax,ebx
- jmp @end
- @mal:
- mov Salida,0
- @end:
- mov Salida,eax
- }
- return ((word)Salida);
- }
-
- boolean CDPMI::LiberaSelector (word Selector)
- {
- boolean Ok;
- Ok = TRUE;
- __asm
- {
- mov bx, Selector
- mov eax,1
- int 31h
- jnc @@Fin
- mov Ok,0
- @@Fin:
- }
- return (Ok);
- }
-
- dword CDPMI::Fisica2Lineal (dword Fisica, dword Limite)
- {
- RegsCero();
- inregs.w.ax = 0x800;
- inregs.w.bx = (word)(Fisica >> 16);
- inregs.w.cx = (word)(Fisica&0xFFFF);
- inregs.w.si = (word)(Limite >> 16);
- inregs.w.di = (word)(Limite&0xFFFF);
- int386(0x31, &inregs, &outregs);
- if (outregs.x.cflag) return (FALSE);
- else return ((long) outregs.w.bx << 16) + outregs.w.cx;
- }
-