; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
; ³ (c) Lord Julus - 2000		 Vxtasy #1 - Magazine source code ³
; ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

;========( The next few routines are used to display the scrollbar )=========
;========( and the percentage of the view			   )=========

updatescrollbar proc near		     ;
	   pusha			     ;
	   push es			     ;
	   mov bx, scrollbar		     ;
	   cmp bx, TRUE 		     ; do we have a scrollbar ?
	   jne no_scroll		     ;
					     ;
	   mov ax, 0b800h		     ; video seg
	   mov es, ax			     ;
	   mov ax, 1			     ; al=horiz inc. / ah=vert. inc.
	   mov di, scrollbarv		     ;
	   cmp di, TRUE 		     ; vertical scroll bar ?
	   jne vertical 		     ;
	   xchg al, ah			     ; if so exchange increment
					     ; values
vertical:				     ;
	   mov vertical_inc, al 	     ; save increment values
	   mov orizontal_inc, ah	     ;
	   mov cx, scrollbarl		     ; scrollbar line
	   mov ax, scrollbars		     ; scrollbar start
	   cmp di, TRUE 		     ;
	   jne vertical2		     ;
	   xchg ax, cx			     ; exchange if orizontal
					     ;
vertical2:				     ;
	   mov dh, al			     ; initial row
	   mov dl, cl			     ; initial column
	   mov cx, scrollbarlen 	     ; the entire scrollbar length
					     ; Now calculate viewed percent
	   finit			     ; initiate FPU
	   fild crtdispline		     ;
	   fild _100			     ;
	   fmul 			     ; multiply by 100
	   fild linesinfile		     ;
	   fdiv 			     ; and divide with the filesize
	   frndint			     ; round
	   fistp dword ptr ds:[percent]      ; and store percentage
	   lea di, percent		     ;
	   mov di, word ptr ds:[di]	     ;
	   finit			     ;
					     ;
	   mov word ptr [temp1], cx	     ;
	   mov word ptr [temp2], di	     ;
					     ;
	   fild dword ptr [temp1]	     ; now calculate where is the
	   fild dword ptr [temp2]	     ; position off the scroll char
	   fmul 			     ; inside the scroll bar
	   fild _100			     ;
	   fdiv 			     ;
	   frndint			     ;
	   fistp dword ptr ds:[temp]	     ;
	   lea si, temp 		     ;
	   mov si, word ptr ds:[si]	     ; and put it in SI
					     ;
	   pusha			     ;
	   push ax			     ;
	   push dx			     ;
	   mov dx, percplace		     ;
	   lea di, percent		     ;
	   mov di, word ptr ds:[di]	     ;
	   mov ax, di			     ;
	   call printdecimal		     ; display percentage
	   mov al, '%'			     ;
	   call print_char		     ;
	   call move_one		     ;
	   mov al, ' '			     ;
	   call print_char		     ;
	   call move_one		     ;
	   mov al, ' '			     ;
	   call print_char		     ;
					     ;
	   mov dx, linesplace		     ;
	   mov ax, crtdispline		     ;
	   call convertdecimal		     ;
	   mov bl, linesattr		     ;
	   lea bp, converted_string	     ;
	   mov cx, 4			     ;
	   call print_string		     ;
	   add dl, 5			     ;
	   call move_one		     ;
	   inc dl			     ;
	   mov al, '/'			     ;
	   call print_char		     ;
	   call move_one		     ;
	   inc dl			     ;
	   mov ax, linesinfile		     ;
	   call convertdecimal		     ;
	   mov bl, linesattr		     ;
	   lea bp, converted_string	     ;
	   mov cx, 4			     ;
	   call print_string		     ;
					     ;
	   pop dx			     ;
	   pop ax			     ;
	   popa 			     ;
					     ;
	   mov bx, cx			     ;
					     ;
repeat_scroll:				     ;
	   push dx			     ; dx holds the address
	   mov cs:saveddx, dx		     ;
	   call computeaddress		     ; calculate video address
	   mov di, dx			     ;
					     ;
	   push bx			     ; what do we print ?
	   sub bx, si			     ;
	   cmp bx, 0			     ;
	   jne kix			     ; scroller vanish fix-up
	   cmp cx, 1			     ;
	   pop bx			     ;
	   jne trail			     ;
	   jmp normal			     ;
					     ;
kix:					     ;
	   cmp bx, cx			     ;
	   pop bx			     ;
	   je normal			     ;
	   ja empty			     ;
	   jb trail			     ;
					     ;
   normal:				     ; the scroll character
	   mov ax, cs:saveddx		     ;
	   mov scroll_pos, ax		     ;
	   mov ax, scrollchar		     ;
	   shl ax, 8			     ;
	   add ax, scrollattr		     ;
	   xchg al, ah			     ;
	   jmp store			     ;
					     ;
   empty:				     ; the empty character
	   mov ax, emptychar		     ;
	   shl ax, 8			     ;
	   add ax, emptyattr		     ;
	   xchg al, ah			     ;
	   jmp store			     ;
					     ;
   trail:				     ; the trail character
	   mov ax, trailchar		     ;
	   shl ax, 8			     ;
	   add ax, trailattr		     ;
	   xchg al, ah			     ;
	   jmp store			     ;
					     ;
					     ;
store:					     ;
	   stosw			     ; store it!
	   pop dx			     ;
	   add dl, orizontal_inc	     ; increase coordinates
	   add dh, vertical_inc 	     ;
	   loop repeat_scroll		     ;
					     ;
no_scroll:				     ;
	   pop es			     ;
	   popa 			     ;
	   ret				     ;
updatescrollbar endp			     ;
orizontal_inc db 0			     ;
vertical_inc db 0			     ;

;=========( This prints on the screen decimal number held by AX )============

printdecimal proc near			     ;
	   pusha			     ;
	   push es			     ;
	   push ax			     ;
	   mov ah, 02h			     ; set cursor position
	   mov bx, 0			     ;
	   int 10h			     ;
	   pop ax			     ;
	   call print_decimal		     ; print it!
	   pop es			     ;
	   popa 			     ;
	   ret				     ;
					     ;
print_decimal:				     ;
	   xor dx, dx			     ;
	   div cs:ten			     ; get a unit
	   or ax, ax			     ;
	   jz db_display		     ; display it!
	   push dx			     ;
	   call print_decimal		     ; reentry
	   pop dx			     ;
					     ;
db_display:				     ;
	   add dl, 30h			     ; adjust to '0'
	   mov al, dl			     ;
	   call print_char		     ;
	   call move_one		     ;
	   ret				     ;
printdecimal endp			     ;
ten	dw 10				     ;
					     ;
convertdecimal proc near		     ;
	   pusha			     ; converts decimal no. in AX
	   push es			     ;
	   push ds			     ;
	   pop es			     ;
	   lea di, converted_string	     ;
	   call convert_decimal 	     ;
	   mov al, 0			     ;
	   stosb			     ;
	   stosb			     ;
	   stosb			     ;
	   pop es			     ;
	   popa 			     ;
	   ret				     ;
					     ;
convert_decimal:			     ;
	   xor dx, dx			     ;
	   div cs:ten			     ; get a unit
	   or ax, ax			     ;
	   jz flush_string		     ; display it!
	   push dx			     ;
	   call convert_decimal 	     ; reentry
	   pop dx			     ;
					     ;
flush_string:				     ;
	   add dl, 30h			     ; adjust to '0'
	   mov al, dl			     ;
	   stosb			     ;
	   ret				     ;
convertdecimal endp			     ;

;==========( This prints a character on the screen )=========================

print_char proc near			     ;
	   push cx			     ;
	   push bx			     ;
	   mov ah, 09h			     ; print one character
	   mov bl, percattr		     ;
	   mov cx, 1			     ;
	   int 10h			     ;
	   pop bx			     ;
	   pop cx			     ;
	   ret				     ;
print_char endp 			     ;

;==========( Procedure to increment cursor position on screen )==============

move_one proc near			     ;
	  pusha 			     ; increment cursor position
	  mov ah, 03h			     ;
	  mov bx, 0			     ;
	  int 10h			     ;
	  inc dl			     ;
	  mov ah, 02h			     ;
	  int 10h			     ;
	  popa				     ;
	  ret				     ;
move_one endp				     ;

;==========( Display an asciiz string on screen from row, column )===========

print_string proc near			     ; prints an ASCIIZ string
	  pusha 			     ; at DH,DL (row, column)
	  push es			     ;
	  push ds			     ;
	  pop es			     ;
	  mov ax, 1301h 		     ; from ES:BP
	  mov bh, 0			     ; length CX
	  int 10h			     ; attribute in BL
	  pop es			     ;
	  popa				     ;
	  ret				     ;
print_string endp			     ;

;============================================================================
put_char proc near			     ;
	   push cx			     ;
	   push bx			     ;
	   mov ah, 09h			     ; print one character
	   mov cx, 1			     ;
	   int 10h			     ;
	   pop bx			     ;
	   pop cx			     ;
	   ret				     ;
put_char endp				     ;
					     ;
saveddx dw 0				     ;
tempnr dd 0				     ;
