;**************************************************************************** ;* ;* ;*** Binary File I/O ;* By Brian Fisher ;* ;* last modified July 12, 1999 - fixed Readarray .286 Ideal Model Small Public SetEndian, Openbin, Closebin, Writebyte, Readbyte, Writeword, Readword, Writedword, Readdword, Writestring, Readstring, Writearray, Readarray, Setpointer, Readpointer CodeSeg Tempseg dw 0 Tempoff dw 0 Tempsize dw 0 Templw dw 0 temphw dw 0 swaplw dw 0 swaphw dw 0 isbig dw 0 Proc SetEndian ;isbig push bp mov bp,sp mov ax,[ss:bp+06] mov [cs:isbig],ax pop bp retf 2 endp setendian Proc Openbin ;fname push bp mov bp,sp push si mov si,[ss:bp+06] add si,2 mov dx,[ds:si] mov ax,03d02h int 21h jnc opengood mov ax,03c00h xor cx,cx int 21h jnc opengood mov ax,-1 opengood: pop si bp retf 2 endp openbin Proc Closebin ;handle push bp mov bp,sp mov bx,[ss:bp+06] mov ax,03e00h int 21h jc closebad xor ax,ax closebad: pop bp retf 2 endp closebin Proc Writebyte ;handle place byte push bp mov bp,sp push ds mov bx,[ss:bp+12] mov cx,[ss:bp+10] mov dx,[ss:bp+08] call setfpointer mov ax,[ss:bp+06] and ax,255 mov [cs:templw],ax mov cx,1 mov ax,cs mov ds,ax lea dx,[cs:templw] mov ax,04000h int 21h jc badbyte xor ax,ax badbyte: pop ds bp retf 8 endp writebyte Proc Readbyte ;handle place push bp mov bp,sp push ds mov bx,[ss:bp+10] mov cx,[ss:bp+08] mov dx,[ss:bp+06] call setfpointer mov cx,1 mov ax,cs mov ds,ax lea dx,[cs:templw] mov ax,03f00h int 21h xor ax,ax jc badreadbyte mov ax,[cs:templw] and ax,255 badreadbyte: pop ds bp retf 6 endp readbyte Proc Writeword ;handle place word push bp mov bp,sp push ds mov bx,[ss:bp+12] mov cx,[ss:bp+10] mov dx,[ss:bp+08] call setfpointer mov ax,[ss:bp+06] mov [cs:templw],ax mov cx,2 mov ax,cs mov ds,ax lea dx,[cs:templw] call swapendian mov ax,04000h int 21h jc badword xor ax,ax badword: pop ds bp retf 8 endp writeword Proc Readword ;handle place push bp mov bp,sp push ds mov bx,[ss:bp+10] mov cx,[ss:bp+08] mov dx,[ss:bp+06] call setfpointer mov cx,2 mov ax,cs mov ds,ax lea dx,[cs:templw] mov ax,03f00h int 21h xor ax,ax jc badreadword call swapendian mov ax,[cs:templw] badreadword: pop ds bp retf 6 endp readword Proc Writedword ;handle place dword push bp mov bp,sp push ds mov bx,[ss:bp+14] mov cx,[ss:bp+12] mov dx,[ss:bp+10] call setfpointer mov ax,[ss:bp+06] mov [cs:templw],ax mov ax,[ss:bp+08] mov [cs:temphw],ax mov cx,4 mov ax,cs mov ds,ax lea dx,[cs:templw] call swapendian mov ax,04000h int 21h jc baddword xor ax,ax baddword: pop ds bp retf 10 endp writedword Proc Readdword ;handle place push bp mov bp,sp push ds mov bx,[ss:bp+10] mov cx,[ss:bp+08] mov dx,[ss:bp+06] call setfpointer mov cx,4 mov ax,cs mov ds,ax lea dx,[cs:templw] mov ax,03f00h int 21h jc badreaddword call swapendian mov ax,[cs:templw] mov dx,[cs:temphw] jmp goodreaddword badreaddword: xor ax,ax xor dx,dx goodreaddword: pop ds bp retf 6 endp readdword Proc Writestring ;handle place string push bp mov bp,sp push ds si mov bx,[ss:bp+12] mov cx,[ss:bp+10] mov dx,[ss:bp+08] call setfpointer mov si,[ss:bp+06] mov cx,[ds:si] add si,2 mov dx,[ds:si] mov ax,04000h int 21h jc badstring xor ax,ax badstring: pop si ds bp retf 8 endp writestring Proc Readstring ;handle place string push bp mov bp,sp push ds si mov bx,[ss:bp+12] mov cx,[ss:bp+10] mov dx,[ss:bp+08] call setfpointer mov si,[ss:bp+06] mov cx,[ds:si] add si,2 mov dx,[ds:si] mov ax,03f00h int 21h xor ax,ax jc badreadstring mov ax,[cs:templw] badreadstring: pop si ds bp retf 8 endp readstring Proc Writearray ;handle place array start bytes push bp mov bp,sp push ds mov bx,[ss:bp+16] mov cx,[ss:bp+14] mov dx,[ss:bp+12] call setfpointer mov bx,[ss:bp+10] mov dx,[ds:bx+0ah] mov ax,[ds:bx+02h] mov ds,ax add dx,[ss:bp+08] mov cx,[ss:bp+06] mov bx,[ss:bp+16] mov ax,04000h int 21h jc badarray xor ax,ax badarray: pop ds bp retf 12 endp writearray Proc Readarray ;handle place array start bytes push bp mov bp,sp push ds mov bx,[ss:bp+16] mov cx,[ss:bp+14] mov dx,[ss:bp+12] call setfpointer mov bx,[ss:bp+10] mov dx,[ds:bx+0ah] mov ax,[ds:bx+02h] mov ds,ax add dx,[ss:bp+08] mov cx,[ss:bp+06] mov bx,[ss:bp+16] mov ax,3f00h int 21h xor ax,ax jc badreadarray mov ax,[cs:templw] badreadarray: pop ds bp retf 12 endp readarray Proc setpointer ;handle location push bp mov bp,sp mov bx,[ss:bp+10] mov cx,[ss:bp+08] mov dx,[ss:bp+06] call setfpointer pop bp retf 6 endp setpointer proc readpointer ;handle push bp mov bp,sp mov bx,[ss:bp+06] call getfpointer pop bp retf 2 endp readpointer Proc Setfpointer mov ax,cx and ax,dx cmp ax,0ffffh jz usepointer mov ax,04200h int 21h usepointer: retn endp setfpointer Proc GetfPointer mov ax,04201h xor cx,cx xor dx,dx int 21h retn endp getfPointer Proc swapendian cmp [cs:isbig],0 jz noswap push ax bx si cx mov si,dx lea bx,[cs:swaplw] push cx storem: lodsb mov [ds:bx],al inc bx loop storem pop cx mov si,dx writem: dec bx mov al,[ds:bx] mov [ds:si],al inc si loop writem pop cx si bx ax noswap: retn endp swapendian end