

#include "vgadef.h"	

/*
	20 %x
	16 %y
	12  %buf
	8  %eip
	4  %ebp
*/

X =	8
Y =	12
BUF=	16
COLOR=  20

.text	
.globl _asm_draw_ctext,_asm_draw_text
.comm _graph_mem,4	
.align 4
_asm_draw_text:
	
	# calculate the base address
	pushl	%ebp
	movl	%esp,%ebp
	pushl	%edi
	pushl	%esi
	pushl	%ecx
	
	movl	Y(%ebp),%edi
	leal	0(%edi,%edi,4),%edi
	sall	$4,%edi
	addl	X(%ebp),%edi
	addl	_graph_mem,%edi
	movl	BUF(%ebp),%esi
		
	# setup video graphic registers
	mov	$GRA_I,%dx
	movw	$0x0a05,%ax
	outw	%ax,%dx
	movw	$7,%ax
	outw	%ax,%dx
	mov	$0x03,%ax
	outw	%ax,%dx
	movl	$15,%ecx
	movb	$8,%al
	outb	%al,%dx
	inc	%dx
	mov	COLOR(%ebp),%ebx
	cmpb	$255,_vga_screenmask
	jnz	L01
	xchg	%bl,%bh
L01:	movb	(%esi),%al
	outb	%al,%dx
	andb	%bl,(%edi)
	not	%al
	outb	%al,%dx
	andb	%bh,(%edi)	
	addl	$80,%edi
	incl	%esi
	decl	%ecx
	jnz	L01
	cmpb	$1,_vga_isunderline
	jne	L04
	movb	$0xff,%al
	outb	%al,%dx
	andb	%bl,(%edi)
L04:
	mov	$GRA_I,%dx
	mov	$3,%ax
	outw	%ax,%dx
	mov	$0x0805,%ax
	outw	%ax,%dx
	popl	%ecx
	popl	%esi
	popl	%edi
	movl	%ebp,%esp
	popl	%ebp
	ret
.align 4
_asm_draw_ctext:
	
	# calculate the base address
	pushl	%ebp
	movl	%esp,%ebp
	pushl	%edi
	pushl	%esi
	pushl	%ecx
	
	movl	Y(%ebp),%edi
	leal	0(%edi,%edi,4),%edi
	sall	$4,%edi
	addl	X(%ebp),%edi
	addl	_graph_mem,%edi
	movl	BUF(%ebp),%esi
		
	# setup video graphic registers
	movw	$GRA_I,%dx
	movw	$0x0a05,%ax
	outw	%ax,%dx
	movw	$7,%ax
	outw	%ax,%dx
	movw	$03,%ax
	outw	%ax,%dx
	movl	$15,%ecx
	movb	$8,%al
	outb	%al,%dx
	incw	%dx
	mov	COLOR(%ebp),%ebx
	cmpb	$255,_vga_screenmask
	jne	L02
	xchg	%bl,%bh
L02:	movb	(%esi),%al
	outb	%al,%dx
	andb	%bl,(%edi)
	not	%al
	outb	%al,%dx
	andb	%bh,(%edi)
	incl	%esi
	incl	%edi
	movb	(%esi),%al
	outb	%al,%dx
	andb	%bl,(%edi)
	not	%al
	outb	%al,%dx
	andb	%bh,(%edi)
L9:	
	addl	$79,%edi
	incl	%esi
	decl	%ecx
	jne	L02
	cmpb	$1,_vga_isunderline
	jne	L10
	movb	$0xff,%al
	out	%al,%dx
	andb	%bl,(%edi)
	incl	%edi
	andb	%bl,(%edi)
		
L10:		
	movw	$GRA_I,%dx
	movw	$3,%ax
	outw	%ax,%dx
	movw    $0x0805,%ax
	outw	%ax,%dx
	popl	%ecx
	popl	%esi
	popl	%edi
	movl	%ebp,%esp
	popl	%ebp
	ret

	
	









