;constants of stuff that seem hard to remember at times.


.386
TRUE  EQU 1
FALSE EQU 0

ENABLED  EQU 1
DISABLED EQU 0

BIT0  EQU 1
BIT1  EQU 2
BIT2  EQU 4
BIT3  EQU 8
BIT4  EQU 10h
BIT5  EQU 20h
BIT6  EQU 40h
BIT7  EQU 80h
BIT8  EQU 100h
BIT9  EQU 200h
BIT10 EQU 400h
BIT11 EQU 800h
BIT12 EQU 1000h
BIT13 EQU 2000h
BIT14 EQU 4000h
BIT15 EQU 8000h
BIT16 EQU 10000h
BIT17 EQU 20000h
BIT18 EQU 40000h
BIT19 EQU 80000h
BIT20 EQU 100000h
BIT21 EQU 200000h
BIT22 EQU 400000h
BIT23 EQU 800000h
BIT24 EQU 1000000h
BIT25 EQU 2000000h
BIT26 EQU 4000000h
BIT27 EQU 8000000h
BIT28 EQU 10000000h
BIT29 EQU 20000000h
BIT30 EQU 40000000h
BIT31 EQU 80000000h


;colors for standard text mode
;
;                Bit# 76543210
;blinking text?ÄÄÄÄÄÄÄÙ///³\\\
;                 backgrnd³ text color
;                  color  Àhigh intensity (bright) color?
BLACK     EQU 0
BLUE      EQU 1
GREEN     EQU 2
CYAN      EQU 3
RED       EQU 4
MAGENTA   EQU 5
BROWN     EQU 6
WHITE     EQU 7


BRIGHT    EQU BIT3           ;Bit 3 set if text is high intensity (bright)
BLINKING  EQU BIT7           ;Bit 7 set if text is blinking
;Note: high intensity black = dark grey




;special characters
NUL     EQU 0
NULL    EQU 0
BELL    EQU 07
BS      EQU 08
TAB     EQU 09
LF      EQU 10
CR      EQU 13
ESCAPE  EQU 27           ;ESC is a reserved word....
PGUP    EQU "I"
PGDOWN  EQU "Q"   
RIGHT   EQU "M"
LEFT    EQU "K"    
DOWN    EQU "P"    
UP      EQU "H"


;file stuff
READONLY  EQU   BIT0
HIDDEN    EQU   BIT1
SYSTEM    EQU   BIT2
VOLUME    EQU   BIT3         ;ignored for file access
DIRECTORY EQU   BIT4         ;must be 0 for file access
ARCHIVE   EQU   BIT5
SHAREABLE EQU   BIT7         ;for novell networks

;===========================================================================
;Procedure: Hex2Bin
;Purpose:   Converts an 8 bit hex value to binary hex
;           
;Input:     AL      8 bit data to convert
;           
;Output:    EDX     Binary conversion in hex
;
;Processing: Test bits, set 0's or 1's in EDX 
;EXAMPLE:       Input  AL  = 12h
;               output EDX = 00010010h
;---------------------------------------------------------------------------
hex2bin proc
	push    cx
	push    bx
	xor     edx,edx
	mov     bl,BIT0
	mov     cx,8
loopit:
	test    al,bl
	jz      shiftit
	add     edx,1
shiftit:
	ror     edx,4
	shl     bl,1
	loop    loopit
	pop     bx
	pop     cx
	ret
hex2bin endp
;===========================================================================
;Procedure: ucase
;Purpose:   Converts character in AL to uppercase.
;           
;Input:     AL=character
;           
;Output:    AL=uppercase character (if a-z)
;           All other registers preserved.  (flags too)
;
;Processing: test valid range (a-z), set to upper, exit
;---------------------------------------------------------------------------
ucase   proc
	pushf
	cmp al,"a"                  ;if  it's not a-z, skipit
	jb noupper
	cmp al,"z"
	ja noupper
	and al,5fh                  ;strip off a few bits to make it upper
noupper:        
	popf
	ret
ucase   endp
;===========================================================================
;Procedure: lcase
;Purpose:   Converts character in AL to lowercase.
;           
;Input:     AL=character
;           
;Output:    AL=lowercase character (if a-z)
;           All other registers preserved.  (flags too)
;
;Processing: test valid range (a-z), set to lower, exit
;---------------------------------------------------------------------------
lcase   proc
        pushf
        cmp al, "A"
        jb nolower
        cmp al, "Z"
        ja nolower

        or al, BIT5
nolower:
        popf
        ret
lcase endp

;===========================================================================
;Procedure: ASCII2hex
;Purpose:   returns the value in hex of the ASCII word in AX
;           
;Input:     AX=ASCII hex number 
;           
;Output:    AL=hex value  AH is destroyed
;           
;Processing: convert AH and AL to hex,shift AH into AL, exit 
;---------------------------------------------------------------------------
ASCII2hex proc
	sub     ax,3030h
	cmp     ah,0fh
	jb      ok
	sub     ah,7
ok:        
	cmp     al,0fh
	jb      ok2
	sub     al,7
ok2:
	shl     ah,4
	add     al,ah
	ret
ASCII2hex endp
;===========================================================================
;Procedure: Hex2ASCII
;Purpose:   returns the ASCII value of a hex byte in AL
;           
;Input:     AL=hex value
;           
;Output:    AX=ASCII value
;Example:   AL=3Eh = AX=3345              
;
;Processing: Separate AL nibble into AH, add 30 or 37 to each
;---------------------------------------------------------------------------
hex2ascii       proc
		xor     ah,ah
		shl     ax,4                  ;separate upper nibble of
		shr     al,4                  ;AL into AH
		add     al,"0"
		cmp     al,"0"+10
		jb      alok      
		add     al,7
alok:
		add     ah,"0"
		cmp     ah,"0"+10
		jb      ohok
		add     ah,7
ohok:
		ret
hex2ascii       endp
