; ****************************************************************************
; DELFILE.ASM (by Erdogan Tan)
;
; TRDOS Kernel Test program for
; INT 21h Function 41h, DeleteFile,
;
; 10/04/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_get_file_name   ; jump if not zero

                int 20h

loc_get_file_name:
                inc si
                mov byte ptr [SI][BX], bh     ; 0 
loc_get_file_name_next:
                inc si
                mov al, byte ptr [SI]
                cmp al, 20h                   ; is it SPACE ?
                ja short loc_delete_file

                dec bl                                  
                jnz short loc_get_file_name_next              
                
                int 20h

loc_delete_file:
                mov dx, si
                mov ah, 41h ; MS Dos Function = Delete File
                int 21h
                jc short loc_check_error_number

loc_display_startup_file_name:
                mov si, offset Msg_Deleted
                call SINGLIX_PRINTMSG

                int 20h
                
loc_check_error_number:
                cmp al, 02h
                je short loc_file_not_found
                cmp al, 05h
                je short loc_access_denied  

                call proc_hex 
                mov word ptr [Error_Number], ax

                mov si, Offset Msg_Error
                call SINGLIX_PRINTMSG
                
                int 20h   

loc_file_not_found:
                mov si, Msg_File_Not_Found
                call SINGLIX_PRINTMSG

                int 20h

loc_access_denied:
                mov si, Msg_Access_Denied
                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

;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; 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

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  messages
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Msg_Deleted:
                db 0Dh, 0Ah
                db "Deleted ...", 0Dh, 0Ah, 0

Msg_Access_Denied:
                db 0Dh, 0Ah
                db "Access denied !", 0Dh, 0Ah, 0

Msg_File_Not_Found:
                db 0Dh, 0Ah
                db 'File not found !', 0Dh, 0Ah, 0
               
Msg_Error:      db 0Dh, 0Ah
                db "Error Number: "
Error_Number:
		dw  0
                db "h"
		db  0Dh, 0Ah, 0

SINGLIXBOOT     ends

                end     START_CODE
