
%macro cpush 1
	mov [temp_word],word 0
	mov [temp_word],%1
	mov ax,[temp_word]
	push ax
%endmacro

%macro cpop 1
	pop ax
	mov [temp_word],ax
	mov %1,[temp_word]
%endmacro


%define N_bytes 60
%define F_MODE 0

_readfile:
	push bp
	mov bp,sp

	mov ax,[bp+6]
	mov [buffer],ax

	push C100
	call _printf
	add sp,2

	mov al,F_MODE          ; access and sharing model
	mov dx,filename        ; file name
	mov ah,3Dh             ; open file
	int 21h
	mov [file],ax

	push C101
	call _printf
	add sp,2

	mov bx,[file]          ; file handle
	mov cx,N_bytes         ; number of bytes to read
	mov dx,[buffer]        ; data buffer
	mov ah,3Fh             ; read file
	int 21h

	push C102
	call _printf
	add sp,2

	mov bx,[file]          ; file handle
	mov ah,3Eh             ; close file
	int 21h

	mov ax,0
	leave
	ret

_putc:
	pusha
	mov bp,sp
	;mov ah,0Eh
	;mov al,[bp+18]
	;int 10h

	mov al,[bp+18]
	cpush al
	cpop dl
	mov ah,02h
	int 21h

	popa
	mov ax,0
	ret

_exit:
	mov al,0
	mov ah,4Ch
	int 21h
	ret

_getchar:
	pusha
	mov ah,01h
        int 21h
	mov [the_ch],word 0
	mov [the_ch],al
	popa
        mov ax,[the_ch]
	ret

_getch:
	pusha
	mov ah,07h
	int 21h
	mov [the_ch],word 0
	mov [the_ch],al
	popa
	mov ax,[the_ch]
	ret


_tohex:
        ;pusha
        push bp
        mov bp,sp
        ;mov dx, [bp+18]
        mov dx, [bp+4]

        mov cx,4
        mov si,hexc
        mov di,hex+2

        stor:

        rol dx,4
        mov bx,15
        and bx,dx
        mov al, [si+bx]
        stosb
        loop stor
        push hex
        call _printf
        mov sp,bp
        ;popa
        pop bp
        ret

;temp_word: dw 0
;hex db "0x0000",10,13,0
;hexc db "0123456789ABCDEF"

;LC0:    resb 12
;LC2:    resb 13
