851 ; HEAPLOAD.ASM (FILE.LIB) ; Allm„n rutin f”r att ladda in en fil i heap. ; ; int heap_load(char *fname); ; int heap_load2(char *fname, unsigned seg); ; Returv„rde: 0 vid fel, annars filens segment (offset alltid 0) ; w EQU word ptr INCLUDE DOS.INC INCLUDE BIOS.INC .DOSSEG .MODEL SMALL .386 .DATA? handle word ? fsize dword ? fseg word ? .CODE PUBLIC _heap_load _heap_load PROC push bp mov bp,sp push si mov dx,[bp+4] @OpenFile dx,0 jc abort mov handle,ax @GetFileSize handle mov w[fsize[2]],dx mov w[fsize[0]],ax mov eax,fsize add eax,15 shr eax,4 @GetBlock ax jc abort mov fseg,ax mov si,fseg l1: push ds @Read 0,8000h,handle,si pop ds cmp ax,8000h jnz l2 add si,800h jmp l1 l2: @CloseFile handle mov ax,fseg ;Returnera filens segment i AX jmp no_err abort: mov ax,0 no_err: pop si pop bp ret _heap_load ENDP PUBLIC _heap_load2 _heap_load2 PROC push bp mov bp,sp push si mov dx,[bp+4] @OpenFile dx,0 jc abort mov handle,ax mov si, [bp+6] ; Get segment l1: push ds @Read 0,8000h,handle,si pop ds cmp ax,8000h jnz l2 add si,800h jmp l1 l2: @CloseFile handle mov ax,1 jmp no_err abort: mov ax,0 no_err: pop si pop bp ret _heap_load2 ENDP ;================================================================== ; ; Writefile ; int writefile(int handle,int bufseg,unsigned long datalen); ; ;================================================================== .DATA? datalen dd ? bufseg dw ? .CODE PUBLIC _writefile _writefile PROC push bp mov bp,sp push si mov ax,[bp+4] mov handle,ax mov ax,[bp+6] mov bufseg,ax mov eax,[bp+8] mov datalen,eax mov si,bufseg writelp: cmp datalen,00008000h jb lastchunk push ds @Write 0,8000h,handle,si pop ds sub datalen,00008000h add si,0800h jmp writelp lastchunk: push ds @Write 0,word ptr[datalen],handle,si pop ds pop si pop bp ret _writefile ENDP END . 0