7ef IFNDEF model model EQU ENDIF .DOSSEG .MODEL model, C .386 .CODE ; Dos_Malloc ; Allocates memory using the standard DOS alloc function ; Returns a far pointer to the allocated memory, or NULL on error ; ; void far *dos_malloc(unsigned long len); dos_malloc PROC C, len:DWORD mov ah, 48h mov ebx, len add ebx, 15 shr ebx, 4 int 21h jnc no_error mov dx, 0 mov ax, 0 jmp over_no_error no_error: mov dx, ax mov ax, 0 over_no_error: ret dos_malloc ENDP ; Align ; Aligns a far pointer to aval bytes boundary, useful for optimizing 386 ; stores and fetches. Returns the new updated pointer. ; ; void char far* align_mem(void far* p, unsigned aval) PUBLIC align_mem align_mem PROC C, pt:DWORD, aval:WORD mov ax, aval dec ax align_lp: test word ptr[pt], ax jz aligned_ok inc word ptr[pt] jmp align_lp aligned_ok: mov dx, word ptr[pt + 2] mov ax, word ptr[pt] ret align_mem ENDP ; 386 optimized fmemcpy ; ; _fmemcpy386(char far *dest, char far *src, unsigned len) ; ; Noticeable speed increase IF source and destination data are paragraph ; aligned. If not, it is actually SLOWER than the original _fmemcpy routine! PUBLIC _fmemcpy386 _fmemcpy386 PROC USES DS ES SI DI, dest:DWORD, src:DWORD, len:WORD les di, dest lds si, src mov cx, len mov ax, cx and ax, 3 shr cx, 2 cld rep movsd mov cx, ax rep movsb ret _fmemcpy386 ENDP ; 386 optimized fmemset ; ; _fmemset386(char far *dest, int c, unsigned int len) ; ; Noticeable speed increase IF source and destination data are paragraph ; aligned. If not, it is actually SLOWER than the original _fmemset routine! PUBLIC _fmemset386 _fmemset386 PROC USES ES DI, dest:DWORD, chr:WORD, len:WORD les di, dest mov ax, chr mov ah, al mov dx, ax shl eax, 16 mov ax, dx mov cx, len mov bx, cx and bx, 3 shr cx, 2 cld rep stosd mov cx, bx rep stosb ret _fmemset386 ENDP END . 0