; *****************************************************************************
;
; DEVATTR.ASM (get dos device driver attributes)
;
; Copyright (C) 2011  Erdogan TAN  [ 06/11/2011 ]
;
; *****************************************************************************
Present segment Para 'code'
		assume CS:Present, DS:Present, ES:Present, SS:Present
                org 100h
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
;±
;±              PROCEDURE proc_start
;±
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
proc_start      proc    near

start:         
                xor bh, bh
                mov si, offset 80h                      ; PSP command tail
                mov cl, byte ptr [ si ]
                or cl, cl                               
                jz short device_handle_zero             ; jump if zer

@@:
                inc si
                mov bl, byte ptr [ si ]
                cmp bl, ' '                             ; is it SPACE ?
                jnz short @f

                dec cl                                  
                jnz short @b              
                jmp short device_handle_zero

@@:
                cmp bl, '0'                             ; 0 - 9
                jna short device_handle_zero
                cmp bl, '9'
                ja short device_handle_zero                
               
                sub bl, '0'

get_device_information:
                mov ax, 4400h ; get device information
                int 21h
                jc short @f

                call proc_print_device_attrib
                int 20h
   

device_handle_zero:
                xor bl, bl
                jmp short get_device_information

@@:
                call proc_print_error
                int 20h               
                  
proc_start      endp

proc_print_device_attrib proc near
                ; INPUT ->  none
                ;  Dx = Device information/attributes
                  
                mov ax, dx
 
                push ax
		call proc_hex
                mov word ptr [DevAttribStr]+2, ax                 
		pop ax
                mov al, ah
                call proc_hex
                mov word ptr [DevAttribStr], ax

                mov si, offset msg_DeviceAttrib
                call proc_printmsg  

                retn 

msg_DeviceAttrib: 
                db "Device Attributes: " 
DevAttribStr:   dd 30303030                 
                db "h"
                db 0Dh, 0ah, 0

proc_print_device_attrib endp

proc_print_error proc near
                ; INPUT ->  none
                ;  Ax = Error code
                  
                push ax
		call proc_hex
                mov word ptr [ErrorCodeStr]+2, ax                 
		pop ax
                mov al, ah
                call proc_hex
                mov word ptr [ErrorCodeStr], ax

                mov si, offset msg_error
                call proc_printmsg  

                retn 
msg_error:
                db "Error code: " 
ErrorCodeStr:   dd 30303030                 
                db "h"
                db 0Dh, 0ah, 0

proc_print_error endp

proc_printmsg   proc near
loc_print:          
		lodsb                           ; Load byte at DS:SI to AL
		and     AL,AL            
		je      short loc_return        ; If AL = 00h then return
		mov     AH,0Eh                  
		mov     BX,07h             
		int     10h                     ; BIOS Service func ( ah ) = 0Eh
						; Write char as TTY
						;AL-char BH-page BL-color
		jmp     short loc_print           
loc_return:
		retn
proc_printmsg   endp

;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; From binary (byte) to hexadecimal (character) converter    ;
;                                                            ;
; input -> AL = byte (binary number) to be converted         ;
; output -> AH = First character of hexadecimal number       ;
; output -> AL = Second character of hexadecimal number      ;
;                                                            ;
; (c) Erdogan TAN  1998 - 1999                               ;
;............................................................;
; 1998
proc_hex        proc    near
		db 0D4h,10h                     ; Undocumented inst. AAM
						; AH = AL / 10h
						; AL = AL MOD 10h
		or AX,'00'                      ; Make it ZERO (ASCII) based
		xchg AH,AL
; 1999
		cmp AL,'9'
		jna pass_cc_al
		add AL,7
pass_cc_al:
		cmp AH,'9'
		jna pass_cc_ah
		add AH,7
pass_cc_ah:
; 1998
		retn
proc_hex        endp

Present         ends
                end  start
