; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
; ³ (c) Lord Julus - 2000		 Vxtasy #1 - Magazine source code ³
; ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

;========( This proc counts the lines in the file )==========================

count_lines proc near			   ;
	xor ax, ax			   ;
	xor dx, dx			   ;
	lea di, firstlinepos		   ; make firstlinepos = 0
	call fill_axdx			   ;
	xor cx, cx			   ;
	xor dx, dx			   ;
	call move_from_0		   ; move to beginning of file
					   ;
	mov bx, handle			   ;
	mov linesinfile, 0		   ;
	mov ok, 0			   ;
					   ;
count_loop:				   ;
      lea dx, buffer			   ;
      mov cx, buffer_len		   ;
      mov ah, 3fh			   ;
      int 21h				   ;
      cmp ax, cx			   ;
      je not_finished			   ;
      mov ok, 1 			   ;
					   ;
not_finished:				   ;
      xchg cx, ax			   ;
      lea si, buffer			   ;
					   ;
buffer_loop:				   ;
      lodsb				   ;
      cmp al, 0dh			   ;
      jne not____1			   ;
      inc linesinfile			   ;
					   ;
not____1:				   ;
       cmp al, 0ah			   ;
       jne not____2			   ;
       inc linesinfile			   ;
					   ;
not____2:				   ;
       loop buffer_loop 		   ;
					   ;
       cmp ok, 1			   ;
       jne count_loop			   ;
					   ;
       mov ax, linesinfile		   ;
       shr ax, 1			   ;
       inc ax				   ;
       mov linesinfile, ax		   ;
					   ;
       xor cx, cx			   ;
       xor dx, dx			   ;
       call move_from_0 		   ; move to beginning of file
       ret				   ;
count_lines endp			   ;

;========( This proc moves the dword at DX:AX to the [DI] address )==========

fill_axdx proc near			   ;
   mov word ptr [di], ax		   ;
   mov word ptr [di+2], dx		   ;
   ret					   ;
fill_axdx endp				   ;

;========( This proc moves the dword at [DI] address to DX:CX )==============

fill_dxcx proc near			   ;
   xor cx, cx				   ;
   xor dx, dx				   ;
   add dx, word ptr [di]		   ;
   adc cx, word ptr [di+2]		   ;
   ret					   ;
fill_dxcx endp				   ;

;========( Compare a double word at [DI] with 0 )============================

comp_dword_zero proc near		   ;
   cmp word ptr [di], 0 		   ;
   jne sure_not_zero			   ;
   cmp word ptr [di+2], 0		   ;
   jne sure_not_zero			   ;
   stc					   ;
   ret					   ;
					   ;
sure_not_zero:				   ;
   clc					   ;
   ret					   ;
comp_dword_zero endp			   ;
;============================================================================