format PE console

include 'include/win32ax.inc'

SYSTEM equ win32

include 'include/fasmlib/include/fasm/fasmlib-src.inc'
;include 'k2-mMacros.inc'

TEXT_SIZE = 1024

macro abort xString
{
	error xstring
}

macro emit xString
{
	push	xString
	push	stream.stdout
	call	text.write
	jc		fasmError
}

macro emitLn xString
{
	emit xString
}

macro error xString
{
	emitLn xString
}

macro expected xString
{

}

macro expression
{

}

macro getChar
{
	push	stream.read
	call	text.read.char
	jc		fasmError
}

macro getLine
{
	push	TEXT_SIZE
	push	text
	push	stream.stdin
	call 	text.read.line
	jc 		fasmError
}

macro getName
{

}

macro getNum char
{

}

macro init
{

}

macro initialize
{
	call	mem.init
	jc		fasmError
	call	stream.init
	jc		fasmError
}

macro isAlpha char
{

}

macro isDigit char
{

}

macro lookAhead char
{
}

macro match xString
{

}

macro prompt xString
{
	push	xString
	push	stream.stdout
	call	text.write
}

.data
	_error 	db 'fasm error: ',0
	_prompt	db 'k2-m> ',0
	_text	db 'After str.ins and str.cat: ',0
	_text2	db '(a)',0
	_text3	db '(i)',0
	z		db 'i',0
	IncludeIData
	IncludeUData
	
	text	rb	TEXT_SIZE
	
	
.code
	
start:
	; initialize modules 'mem' and 'stream'
	initialize

	prompt _prompt
	; get line of text
	
	getChar


	getLine
	; display line of text
	emit text


	; unititialize modules in 'reverse' order
	call	stream.uninit
	jc		fasmError
	call	mem.uninit
	jc		fasmError

	; exit without fasmError
	push	0
	call	process.exit


.end start




fasmError:
; eax holds fasmError code
; ebx = text of fasmError code in eax
push	eax
call	err.text
mov		ebx,eax

; display 'Error: '
push	_error
push	stream.stderr
call	text.write

; display fasmError message
push	ebx
push	stream.stderr
call	text.write

; unitialize modules
call	stream.uninit
call	mem.uninit

; exit with code '1'
push	1
call	process.exit