; ****************************************************************************
; FINDFILE.ASM (by Erdogan Tan)
;
; 01/02/2011
;
; ****************************************************************************

; DTA (PSP+80h= Offset 128)
DTA_Attribute equ 149 ; DTA+21
DTA_Time equ 150 ; DTA+22
DTA_Date equ 152 ; DTA+24
DTA_FileSize equ 154 ; DTA + 26
DTA_FileName equ 158 ; DTA + 30

PSP_CommandTail equ 80h

.8086

SINGLIXBOOT     SEGMENT PUBLIC 'CODE'
                assume cs:SINGLIXBOOT,ds:SINGLIXBOOT,es:SINGLIXBOOT,ss:SINGLIXBOOT

                org 100h
START_CODE:

proc_start      proc near
                xor bh, bh
               
                mov si, PSP_CommandTail
                mov bl, byte ptr [SI]
                or bl, bl                               
                jnz short loc_find_file       ; jump if not zero

                int 20h

loc_find_file:
                inc si
                mov byte ptr [SI][BX], bh     ; 0 
loc_find_file_next:
                inc si
                mov al, byte ptr [SI]
                cmp al, 20h                   ; is it SPACE ?
                ja short loc_find_first_file_int21h

                dec bl                                  
                jnz short loc_find_file_next              
                
                int 20h

loc_find_first_file_int21h:
push si
                call SINGLIX_PRINTMSG
pop si
                mov dx, si
                mov cx, 27h ; File Attributes
                mov ah, 4Eh ; MS Dos Function = Find First File
                int 21h
                jc short loc_file_not_found

loc_print_file_name:
                mov si, offset DTA_FileName
                mov di, offset Msg_File_Name
                mov cx, 12
                rep movsb

loc_display_startup_file_name:
                mov si, offset Msg_File_Name_Hdr
                call SINGLIX_PRINTMSG

                int 20h
                
loc_file_not_found:
                mov si, Msg_File_Not_Found
                call SINGLIX_PRINTMSG

                int 20h

proc_start      endp


SINGLIX_PRINTMSG     proc near
 
SINGLIX_PRINTMSG_LOOP:
                lodsb                           ; Load byte at DS:SI to AL
                and     AL,AL            
                jz      short SINGLIX_PRINTMSG_OK       
                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 SINGLIX_PRINTMSG_LOOP           

SINGLIX_PRINTMSG_OK:
                retn

SINGLIX_PRINTMSG     endp

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  messages
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Msg_File_Name_Hdr:
                db 0Dh, 0Ah
                db "File Name : "

Msg_File_Name:  db 12 dup (0)
                db 0Dh, 0Ah
                db 0

Msg_File_Not_Found:
                db 0Dh, 0Ah
                db 'File not found !', 0Dh, 0Ah, 0
               
SINGLIXBOOT     ends

                end     START_CODE
