.xlist
.radix 16

;WOLF assembly macro routines by Black Wolf.

;alloc          size[WORD]
;changealloc    size[WORD], segment[WORD]
;cls            screen_mode[BYTE]
;fclose         handle[WORD]
;fopen          mode[BYTE], filename_off[WORD], filename_seg[WORD] 
;gets           string_offset[WORD], string_seg[WORD], max_len[BYTE]
;get_int        int_no[BYTE]
;set_int        int_no[BYTE], new_offset[WORD], new_segment[WORD]
;keyhit
;terminate      error_code[BYTE]

alloc   macro   size
	mov     ah,48
	ifdif   <bx>,<size>
	mov     bx,size
	endif
	int     21
	endm

changealloc macro size, segment
	mov     ah,4a
	ifdif   <es>,<segment>
	push    bx
	mov     bx,segment
	mov     es,bx
	pop     bx
	endif
	ifdif   <bx>,<size>
	mov     bx,size
	endif
	int     21
	endm
	

cls macro screen_mode
	ifnb    <screen_mode>
	mov     al,screen_mode
	else
	mov     al,3
	endif
	xor     ah,ah
	int     10
	endm

terminate macro error_code
	ifnb    <error_code>
	mov     al, error_code
	mov     ah,4c
	int     21
	else
	mov     ax,4c00
	int     21
	endif
	endm

keyhit macro
	xor     ax,ax
	int     16
	endm

gets macro string_offset, string_seg, max_len
	ifdif   <string_seg>,<ds>
	push    ax
	mov     ax,string_seg
	mov     ds,ax
	pop     ax
	endif
	ifdif   <string_offset>,<dx>
	mov     dx,offset string_offset
	endif
	ifdif   <max_len>, <al>
	mov     al,max_len
	endif
	mov     ah,0a
	push    bx
	mov     bx,dx
	mov     byte ptr ds:[bx],al
	int     21
	mov     al, byte ptr ds:[bx+1]
	add     bl, al
	adc     bh,0
	mov     byte ptr ds:[bx+2],0
	pop     bx
	endm

fopen   macro  mode, filename_off, filename_seg
	ifdif   <filename_off>, <dx>
	mov     dx,offset filename_off
	endif
	ifdif   <filename_seg>,<ds>
	push    dx
	mov     dx,filename_seg
	mov     ds,dx
	pop     dx
	endif
	mov     al,mode
	mov     ah,3dh
	int     21
	jc      done_fopen
	xchg    bx,ax
    done_fopen:
	endm

fclose  macro   handle
	ifdif   <handle>,<bx>
	mov     bx,handle
	endif
	mov     ah,3e
	int     21
	endm


fread   macro   handle, size, dest_seg, dest_off
	ifdif   <bx>, <handle>
	mov     bx,handle
	endif
	ifdif   <size>,<cx>
	mov     cx,size
	endif
	ifdif   <dest_seg>,<dx>
	mov     dx,offset dest_seg
	endif
	ifdif   <dest_off>, <ds>
	push    dx
	mov     dx,dest_off
	mov     ds,dx
	pop     dx
	endif
	mov     ah,3f
	int     21
	endm

printf  macro   string_off, string_seg, length
	ifdif   <string_off>, <dx>
	mov     dx,offset string_off
	endif
	ifdif   <string_seg>, <ds>
	push    dx
	mov     dx,string_seg
	mov     ds,dx
	pop     dx
	endif
	ifnb    <length>
	mov     cx,length
	
	else
	
	push    es di
	push    ds
	pop     es
	mov     di,dx
	mov     cx,0ffff
	cld
	xor     al,al
	repnz   scasb
	mov     cx,di
	sub     cx,dx
	dec     cx
	pop     di es
	endif

	mov     ah,40
	xor     bx,bx
	int     21
	endm

get_int macro   int_no
	mov     ah,35
	mov     al,int_no
	int     21
	endm

set_int macro   int_no, new_offset, new_segment
	ifdif   <new_segment>,<ds>
	mov     ax,new_segment
	mov     ds,ax
	endif
	mov     ah,25
	mov     al,int_no
	mov     dx,offset new_offset
	int     21
	endm
set_trap macro
	push    ax
	pushf
	pop     ax
	or      ax,100
	push    ax
	popf
	pop     ax
	endm

clear_trap macro
	push    ax
	pushf
	pop     ax
	and     ax,0feff
	push    ax
	popf
	pop     ax
	endm



.list

