TITLE	A fancy 16-bit Editor (old DoS times :)
;
.MODEL	small	; memory model; code and data are in different segs
		; though, each are less than 64k
.STACK	64	; reserve 64k of memory

	org	100	; start @ ep:100

.DATA
attrib	db	?
lines	db	?
count	db	?
toprow	equ	01
botrow	equ	13
lefcol	equ	15
col	db	00
row	db	00
line	db	47
border	db	"旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴�"
	db	"�                                               �"
	db	"냐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴�"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"�                                               �"
	db	"읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴�"
tit	db	"          What do you wanna do today?          "
menu	db	"1. Search for a file in the current directory  "
	db	"2. Create a directory                          "
	db	"3. Remove a directory                          "
	db	"4. Copy a source file to destination           "
	db	"5. Read and display the contents of a text file"
	db	"6. Append some text to a file                  "
	db	"7. Delete a file                               "
	db	"8. Search for a word in a given file           "
	db	"9. Count number of words in a file             "
	db	"10. Exit                                       "

prompt	db	09, "To select an item, use up/down arrow and press Enter.", 13, 10
	db	09, "Press Esc to exit."

.CODE
main	PROC	FAR
InitData:
	mov	ax, @data
	mov	ds, ax
	mov	es, ax

ClearScreen:
	call	CLS

SetPrompt:
	mov	row, botrow+2
	mov	col, 0
	call	Cursor
	mov	ah, 40h
	mov	bx, 01h
	mov	cx, 75
	lea	dx, prompt
	int	21h

sLoop:
	call	SetBorder
	call	SetTitle
	call	SetMenu
	mov	row, toprow+3
	mov	col, lefcol+1
	call	Cursor
	;mov	row, toprow+1
	call	SetDisplay
	call	Input
	cmp	al, 0Dh
	je	sLoop
	mov	ax, 0600h
	call	CLS
	mov	ah, 4Ch
	int	21h
main	ENDP

;------------------------;
CLS	PROC	NEAR
	mov	ax, 0600h
	mov	bh, 07h
	mov	cx, 0000h
	mov	dx, 184Fh
	int	10h
	ret
CLS	ENDP
;------------------------;
Cursor	PROC	NEAR
	mov	ah, 02h
	mov	bh, 00h
	mov	dh, row
	mov	dl, col
	int	10h
	ret
Cursor	ENDP
;------------------------;
SetBorder	PROC	NEAR
	mov	row, toprow
	mov	lines, 13
	lea	si, border
b10:
	mov	col, lefcol
	mov	count, 49
b20:
	call	Cursor
	mov	ah, 09h
	mov	al, [si]
	mov	bh, 00h
	mov	bl, 08h
	mov	cx, 01h
	int	10h
	inc	col
	inc	si
	dec	count
	jne	b20
	inc	row
	dec	lines
	jne	b10
	ret
SetBorder	ENDP
;------------------------;
SetTitle	PROC	NEAR
	mov	row, toprow+2
	mov	col, lefcol+1
	call	Cursor
	mov	ah, 40h
	mov	bx, 01h
	mov	cx, 75
	lea	dx, tit
	int	21h
	ret
SetTitle	ENDP
;------------------------;
SetMenu	PROC	NEAR
	mov	row, toprow+3
	mov	lines, 10
	lea	si, menu
d10:
	mov	col, lefcol+1
	mov	count, 47
d20:
	call	Cursor
	mov	ah, 09h
	mov	al, [si]
	mov	bh, 00h
	mov	bl, 08h
	mov	cx, 01h
	int	10h
	inc	col
	inc	si
	dec	count
	jne	d20
	inc	row
	dec	lines
	jne	d10
	ret
SetMenu	ENDP
;------------------------;
Input	PROC	NEAR
	mov	ah, 0h
	int	16h
	cmp	ah, 50h
	je	i10
	cmp	ah, 48h
	je	i20
	cmp	al, 0Dh
	je	i50
	cmp	al, 1Bh
	je	i50
	jmp	Input
i10:
	mov	al, row
	mov	cl, 47
	mul	cl
	mov	di, ax
	lea	si, [menu+di]
	mov	count, 47
	inc	row
	cmp	row, 12
	ja	i60
	call	s10
	cmp	row, botrow-1
	jbe	i40
	mov	row, toprow+1
	jmp	i40
i20:
	lea	si, menu-47
	mov	count, 47
	dec	row
	cmp	row, 2
	jb	i60
	call	SetDisplay
	cmp	row, toprow+1
	jae	i40
	mov	row, toprow-1
i40:
	call	Cursor
	call	SetDisplay
	jmp	Input
i50:
	ret
i60:
	ret
Input	ENDP
;------------------------;
SetDisplay	PROC	NEAR
	lea	si, menu
	mov	count, 47
s10:
	call	Cursor
	mov	ah, 09h
	mov	al, [si]
	mov	bh, 00h
	mov	bl, 16h
	mov	cx, 01h
	int	10h
	inc	col
	inc	si
	dec	count
	jne	s10
	mov	col, lefcol+1
	call	Cursor
	ret
SetDisplay	ENDP
;------------------------;
end	main