;===========================================================================
;Procedure: PrintReg
;Purpose:   Displays the contents of a register. 
;           Displays data at current cursor location 
;Input:     EAX  Register to print
;           CL   Length of output (8 for full EAX, 4 for AX, 2 for AL...)
;           
;Output:    Data written to screen using Stdout 
;Processing: Move nibble into output register, display it, loop til finished 
;---------------------------------------------------------------------------
printreg proc   

	push    cx
        push    dx
        
	push    cx
        xor     ch, ch
        mov     dx, 8
        sub     dx, cx
        mov     cx, dx
        shl     cx, 2                   ; multply by 4 for shift#
        rol     eax, cl
        pop     cx


nextchar:
	rol     eax,4                      ;print next character
	mov     dl,al                      ;
	and     dl,0fh                     ;strip out upper 4 bits
        call    display_hex_char
	loop    nextchar
	pop	dx	
	pop     cx
	ret
printreg endp
;===========================================================================
;Procedure: Display_hex_char
;Purpose:   Displays the hex value in DL as ASCII
;           Displays data at current cursor location 
;Input:     DL = hex value to print
;           
;Output:    Data printed to screen using Stdout 
;Processing: add 30 or 37 to character, display to screen using int 10
;---------------------------------------------------------------------------
display_hex_char proc        
        push    dx
        add     dl,30h
        cmp     dl,3ah
        jb      charok
        add     dl,7
charok:
        push    ax
        push    bx
        push    cx
        mov     ah,2
        int     21h
        pop     cx
        pop     bx
        pop     ax
        pop     dx
        ret
display_hex_char endp
;===========================================================================
;procedure: cls
;
;purpose:   clears the screen
;
;requires:  AL=screen attribute, AH=Color
;
;returns:   nothing
;
;notes:     clears up to an 80x50 screen, assumes video segment is b800
;----------------------------------------------------------------------------
cls     PROC    NEAR

        push    es
        push    di                                 
        push    ax                                 

        mov     ax, 0B800h
        mov     es, ax                              
        pop     ax                                 
        xor     di, di                            
        push    cx
        mov     cx, (80 * 50)			; 80x50 screen clear
        repz    stosw
        pop     cx
        pop     di
        pop     es                                 

        push    ax
        push    bx                                 
        push    dx                                 

	mov     ah, 02                          ; relocate cursor to 0,0
        xor     bl, bl                              
        xor     dx, dx                              
        int     10h                                 

        pop     dx
        pop     bx                                 
        pop     ax                                 
        ret
cls     ENDP
;===========================================================================
;procedure: mode50
;
;purpose:   puts the screen in 80x50 line mode
;
;requires:  nothing
;
;returns:   nothing, all registers preserved
;
;notes:     Requires VGA
;----------------------------------------------------------------------------
mode50 proc near
	
        push    ax
        push    bx
        mov     bx, 0                     
        mov     ax, 3
        int     10h
        mov     ax, 1112h                 ;load 8x8 font
        int     10h                       ;
        push	ds
	xor	bx, bx
	mov	ds, bx
        mov     byte ptr ds:[484h], 49
	pop	ds	
	pop     bx
        pop     ax
        ret
	

mode50 endp

