;----------------------------------------------------------------------
; Simple boot program that prints: "Hello,World! I am Shadab Tahvildary :D"
; Then if user presses key "1" , 1.com shoul be executed.
; If user user presses key "r" , the system restarts.
; If user presses any key except "1" or "r" the os prints the charecter

; Shadab Tahvildary 2011
;
; Disclaimer: I am not responsible for any results of the use of the contents
;   of this file

; --------------------------------------------
;  Boot OS code begins here
; --------------------------------------------
begin:

	mov	ax, cs		; Get the current segment
	mov	ds, ax		; The data is in this segment
	cli			; disable interrupts while changing stack
	mov	ss, ax		; We'll use this segment for the stack too
	mov	sp, 0xfffe	; Start the stack at the top of the segment
	sti

	mov si, newline
	call putstr

	mov si, msg
	call putstr
	
	mov si,newline
	call putstr
loop1:		
	mov si,msg2			;please enter 1 to open file 
	call putstr	

	xor ah, ah
	int 0x16
	
	mov si,newline
	call putstr

	mov si, charmsg
	call putstr	
	
	mov ah, 0x0e
	mov bl, 0x07
	int 0x10
	
	cmp al,31h				 ;1=31h
	jne error
	call Exec
	mov si, execmsg
	call putstr	
	jmp loop1
error:call errormsg

;---------------------------------------------
;Error Message
;---------------------------------------------
errormsg:
	mov si, newline
	call putstr
	mov si, msg3	;Error
	call putstr
	mov si, resetmsg
	call putstr
	xor ah, ah
	int 0x16
	cmp al, 72h
	jne errormsg
	mov si, newline
	call putstr
reset:int 18h		;go to the main os of the system
	retn

;---------------------------------------------
;Execute a program
;---------------------------------------------

Exec:
	push ss
	push sp
	mov ah, 4Bh		;EXEC DOS opcode
	mov al, 0		;load and execute
	mov dx, PathName
	mov ds, dx
	lea dx, [PathName]
	mov bx, ParmBlock
	mov es, bx		;block.
	lea bx, [ParmBlock]
	int 21h
	pop sp
	pop ss
	retn
;---------------------------------------------
; Print a Null-Terminated String
;---------------------------------------------
putstr:
	push ax
putstr1:
	lodsb
	or al, al
	jz putstrd
	mov ah, 0x0e
	mov bx, 0x0007
	int 0x10
	jmp putstr1
putstrd:
	pop ax
	retn

;---------------------------------------------
; data for our program
;----------------------------------------------

msg db 'Hello,World! I am Shadab Tahvildary :D',0
msg2 db 'please enter 1 to open file ',0
msg3 db 'Error',0
msg4 db 'File h5.bin is opened!',0
newline db 13,10,0
charmsg db 'Your Charecter is: ',0
resetmsg db 'Press any r to restart...',0
execmsg db 'execution of program 1 is finished.',0
filename db "1  com"
PathName DB 'a:\1.com ',0
	ParmBlock db 0 ;Default environment
	CmdLine db 3,' A:',0dh

;------------------------------------------------
