;---------------------------------------------------------------------
no_echo dd 0
buffer  dd 0

code 'bye',bye
        sys.exit 0x00
        	
code 'cr',cr
	upsh 10
	call emit
	
	ret

code 'emit',emit
	upsh [no_echo]
	cmp eax, 1
	drop
	jz .1
	
	push eax, ebx, ecx, edx
        mov [buffer], eax       ; Put top of datastack in buffer
        push 0x01               ; Number of characters to write
        push buffer             ; The address of the buffer
        push stdout             ; Write to stdout
        system sys_write
        add esp, byte 3*4
        pop eax, ebx, ecx, edx
        
.1	drop
	upsh 0
	upop [no_echo]
	ret
	
code 'key',key
	upsh 1
	upop [no_echo]
	dup

	push ebx, ecx, edx
        push 0x01               ; Number of characters to read
        push buffer             ; The address of the buffer
        push stdin              ; Read from stdin
        system sys_read
        add esp, byte 3*4
	pop ebx, ecx, edx
	mov eax, [buffer]       ; Put read character on top of dstack
        
	ret
	
;---------------------------------------------------------------------

section .bss
tib  resb   200h
sp0  resb   300h
d0   resb 10000h
h0   resb 80000h
section .text
;---------------------------------------------------------------------
