crt.s revision 89495
189495Snyan#
289495Snyan# Copyright (c) 1999 Global Technology Associates, Inc.
389495Snyan# All rights reserved.
489495Snyan#
589495Snyan# Redistribution and use in source and binary forms, with or without
689495Snyan# modification, are permitted provided that the following conditions
789495Snyan# are met:
889495Snyan# 1. Redistributions of source code must retain the above copyright
989495Snyan#    notice, this list of conditions and the following disclaimer.
1089495Snyan# 2. Redistributions in binary form must reproduce the above copyright
1189495Snyan#    notice, this list of conditions and the following disclaimer in the
1289495Snyan#    documentation and/or other materials provided with the distribution.
1389495Snyan#
1489495Snyan# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
1589495Snyan# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1689495Snyan# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1789495Snyan# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
1889495Snyan# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
1989495Snyan# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
2089495Snyan# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2189495Snyan# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2289495Snyan# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2389495Snyan# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
2489495Snyan# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2589495Snyan#
2689495Snyan#	From: btx.s 1.10 1999/02/25 16:27:41 rnordier
2789495Snyan# $FreeBSD: head/sys/boot/pc98/kgzldr/crt.s 89495 2002-01-18 09:00:38Z nyan $
2889495Snyan#
2989495Snyan
3089495Snyan# Screen defaults and assumptions.
3189495Snyan
3289495Snyan.`ifdef' PC98
3389495Snyan		.set SCR_MAT,0xe1		# Mode/attribute
3489495Snyan.else
3589495Snyan		.set SCR_MAT,0x7		# Mode/attribute
3689495Snyan.endif
3789495Snyan		.set SCR_COL,0x50		# Columns per row
3889495Snyan		.set SCR_ROW,0x19		# Rows per screen
3989495Snyan
4089495Snyan# BIOS Data Area locations.
4189495Snyan
4289495Snyan.`ifdef' PC98
4389495Snyan		.set BDA_POS,0x53e		# Cursor position
4489495Snyan.else
4589495Snyan		.set BDA_SCR,0x449		# Video mode
4689495Snyan		.set BDA_POS,0x450		# Cursor position
4789495Snyan.endif
4889495Snyan
4989495Snyan		.globl _(crt_putchr)
5089495Snyan
5189495Snyan# void crt_putchr(int c)
5289495Snyan
5389495Snyan_(crt_putchr): 	movb 0x4(%esp,1),%al		# Get character
5489495Snyan		pusha				# Save
5589495Snyan		xorl %ecx,%ecx			# Zero for loops
5689495Snyan		movb $SCR_MAT,%ah		# Mode/attribute
5789495Snyan		movl $BDA_POS,%ebx		# BDA pointer
5889495Snyan		movw (%ebx),%dx 		# Cursor position
5989495Snyan.`ifdef' PC98
6089495Snyan		movl $0xa0000,%edi
6189495Snyan.else
6289495Snyan		movl $0xb8000,%edi		# Regen buffer (color)
6389495Snyan		cmpb %ah,BDA_SCR-BDA_POS(%ebx)	# Mono mode?
6489495Snyan		jne crt_putchr.1		# No
6589495Snyan		xorw %di,%di			# Regen buffer (mono)
6689495Snyan.endif
6789495Snyancrt_putchr.1:	cmpb $0xa,%al			# New line?
6889495Snyan		je crt_putchr.2			# Yes
6989495Snyan.`ifdef' PC98
7089495Snyan		movw %dx,%cx
7189495Snyan		movb %al,(%edi,%ecx,1)		# Write char
7289495Snyan		addl $0x2000,%ecx
7389495Snyan		movb %ah,(%edi,%ecx,1)		# Write attr
7489495Snyan		addw $0x02,%dx
7589495Snyan		jmp putchr.3
7689495Snyanputchr.2:	movw %dx,%ax
7789495Snyan		movb $SCR_COL*2,%dl
7889495Snyan		div %dl
7989495Snyan		incb %al
8089495Snyan		mul %dl
8189495Snyan		movw %ax,%dx
8289495Snyanputchr.3:	cmpw $SCR_ROW*SCR_COL*2,%dx
8389495Snyan.else
8489495Snyan		xchgl %eax,%ecx 		# Save char
8589495Snyan		movb $SCR_COL,%al		# Columns per row
8689495Snyan		mulb %dh			#  * row position
8789495Snyan		addb %dl,%al			#  + column
8889495Snyan		adcb $0x0,%ah			#  position
8989495Snyan		shll %eax			#  * 2
9089495Snyan		xchgl %eax,%ecx 		# Swap char, offset
9189495Snyan		movw %ax,(%edi,%ecx,1)		# Write attr:char
9289495Snyan		incl %edx			# Bump cursor
9389495Snyan		cmpb $SCR_COL,%dl		# Beyond row?
9489495Snyan		jb crt_putchr.3			# No
9589495Snyancrt_putchr.2:	xorb %dl,%dl			# Zero column
9689495Snyan		incb %dh			# Bump row
9789495Snyancrt_putchr.3:	cmpb $SCR_ROW,%dh		# Beyond screen?
9889495Snyan.endif
9989495Snyan		jb crt_putchr.4			# No
10089495Snyan		leal 2*SCR_COL(%edi),%esi	# New top line
10189495Snyan		movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
10289495Snyan		rep				# Scroll
10389495Snyan		movsl				#  screen
10489495Snyan		movb $' ',%al			# Space
10589495Snyan.`ifdef' PC98
10689495Snyan		xorb %ah,%ah
10789495Snyan.endif
10889495Snyan		movb $SCR_COL,%cl		# Columns to clear
10989495Snyan		rep				# Clear
11089495Snyan		stosw				#  line
11189495Snyan.`ifdef' PC98
11289495Snyan		movw $(SCR_ROW-1)*SCR_COL*2,%dx
11389495Snyan.else
11489495Snyan		movb $SCR_ROW-1,%dh		# Bottom line
11589495Snyan.endif
11689495Snyancrt_putchr.4:	movw %dx,(%ebx) 		# Update position
11789495Snyan		popa				# Restore
11889495Snyan		ret				# To caller
119