code 'emit', emit

section .text

	push esi			; emit
	push edi			;  Store a few registers
	push ecx
	push edx
	call ?cr			;  Wrap to a new line?
.0	and eax,0xff			;  Filter byte
	imul eax,ih*iw/8		;  byte/char in FONT
	lea esi,[font+eax]		;  Load byte from FONT
	call clip			;  Clip the drawing region
	mov edx,[fore] 			;  color (2 = green)
	mov ecx,ih		;  Height of character

	push eax
	mov eax,iw
	call store_and_lock
	pop eax

.line	
	push ecx			;  Store height
	lodsb			 	;  al=font line
	mov ecx,iw			;  Width of character
.pix	
	shl al,1			;  Begin drawing the character
	jnc .1
	mov [edi],dl			;  Store a pixel
.1	
	inc edi
	loop .pix			;  Is this line done?

	add edi,dword [hp]
	sub edi, iw			;  Yes? Then do next line
	pop ecx				;  Restore height/width
	loop .line			;  Are we done?

	pop edx				;  Yes!
	pop ecx				;  Restore the registers
	pop edi
	pop esi
	drop				; drop the character from stack
      add [xy],dword (iw<<16)		; And advance one space

	call unlock_and_flip

next
