164123Skato# Copyright (c) KATO Takenori, 1999, 2000. 264123Skato# 364123Skato# All rights reserved. Unpublished rights reserved under the copyright 464123Skato# laws of Japan. 564123Skato# 664123Skato# Redistribution and use in source and binary forms, with or without 764123Skato# modification, are permitted provided that the following conditions 864123Skato# are met: 964123Skato# 1064123Skato# 1. Redistributions of source code must retain the above copyright 1164123Skato# notice, this list of conditions and the following disclaimer as 1264123Skato# the first lines of this file unmodified. 1364123Skato# 2. Redistributions in binary form must reproduce the above copyright 1464123Skato# notice, this list of conditions and the following disclaimer in the 1564123Skato# documentation and/or other materials provided with the distribution. 1664123Skato# 1764123Skato# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1864123Skato# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1964123Skato# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2064123Skato# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2164123Skato# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2264123Skato# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2364123Skato# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2464123Skato# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2564123Skato# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2664123Skato# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2764123Skato# 2864123Skato# $FreeBSD$ 2964123Skato# 3064123Skato 3164123Skato .code16 3264123Skato 3364123Skato .text 3464123Skato# 3564123Skato# %al character code 3664123Skato# destroyed: %al, %bx 3764123Skato# 3864123Skatoput_character: 3964123Skato movw $0xe000, %bx 4064123Skato movb ishireso, %ah 4164123Skato orb %ah, %ah 4264123Skato jne hireso_ch 4364123Skato movw $0xa000, %bx 4464123Skatohireso_ch: 4564123Skato movw %bx, %es 4664123Skato xorb %ah, %ah 4764123Skato movw curpos, %bx 4864123Skato movw %ax, %es:(%bx) 4964123Skato xorw %ax, %ax 5064123Skato movw %ax, %es 5164123Skato ret 5264123Skato 5364123Skato# 5464123Skato# %al attribute 5564123Skato# destroyed: %ah, %cx 5664123Skato# 5764123Skatoset_attribute: 5864123Skato movw $0xe200, %bx 5964123Skato movb ishireso, %ah 6064123Skato orb %ah, %ah 6164123Skato jne hireso_ch 6264123Skato movw $0xa200, %bx 6364123Skatohireso_attr: 6464123Skato movw %bx, %es 6564123Skato xorb %ah, %ah 6664123Skato movw curpos, %bx 6764123Skato movw %ax, %es:(%bx) 6864123Skato xorw %bx, %bx 6964123Skato movw %bx, %es 7064123Skato ret 7164123Skato 7264123Skato# 7364123Skato# Put a character 7464123Skato# %al: character code 7564123Skato# destroyed: %ah, %bx, %cx 7664123Skato# 7764123Skato .global sc_putc 7864123Skatosc_putc: 7964123Skato call put_character 8064123Skato incw curpos 8164123Skato incw curpos 8264123Skato cmpw $4000, curpos 8364123Skato jng putc_end 8464123Skato movw $0, curpos 8564123Skatoputc_end: 8664123Skato ret 8764123Skato 8864123Skato# 8964123Skato# Put a null terminated string 9064123Skato# %di: pointer to string 9164123Skato# destroyed: %ah, %cx, %di 9264123Skato# 9364123Skato .global sc_puts 9464123Skatosc_puts: 9564123Skato movb (%di), %al 9664123Skato orb %al, %al 9764123Skato jz puts_end 9864123Skato call sc_putc 9964123Skato incw %di 10064123Skato jmp sc_puts 10164123Skatoputs_end: 10264123Skato ret 10364123Skato 10464123Skato# 10564123Skato# Change the current cursor position 10664123Skato# %cx: X 10764123Skato# %dx: Y 10864123Skato# destroyed: %ax, %bx 10964123Skato# 11064123Skato .global sc_goto 11164123Skatosc_goto: 11264123Skato movw %dx, %ax # AX=Y 11364123Skato shlw %ax # AX=Y*64 11464123Skato shlw %ax 11564123Skato shlw %ax 11664123Skato shlw %ax 11764123Skato shlw %ax 11864123Skato shlw %ax 11964123Skato movw %dx, %bx # BX=Y 12064123Skato shlw %bx # BX=Y*16 12164123Skato shlw %bx 12264123Skato shlw %bx 12364123Skato shlw %bx 12464123Skato addw %bx, %ax # AX=Y*64+Y*16=Y*80 12564123Skato addw %cx, %ax 12664123Skato shlw %ax 12764123Skato movw %ax, curpos 12864123Skato ret 12964123Skato 13064123Skato# 13164123Skato# Clear screen 13264123Skato# destroyed: %ax, %bx 13364123Skato# 13464123Skato .global sc_clean 13564123Skatosc_clean: 13664123Skato movb $0x16, %ah 13764123Skato movw $0xe120, %dx 13864123Skato int $0x18 # KBD/CRT BIOS 13964123Skato movw $0, curpos 14064123Skato ret 14164123Skato 14264123Skato# 14364123Skato# Set sttribute code 14464123Skato# %al: attribute 14564123Skato# %cx: count 14664123Skato# destroyed: %ax, %bx, %cx 14764123Skato# 14864123Skato .global sc_setattr 14964123Skatosc_setattr: 15064123Skato call set_attribute 15164123Skato incw curpos 15264123Skato incw curpos 15364123Skato loop sc_setattr 15464123Skato 15564123Skato# 15664123Skato# Sense the state of shift key 15764123Skato# destroyed: %ax 15864123Skato# 15964123Skato .global sc_getshiftkey 16064123Skatosc_getshiftkey: 16164123Skato movb $2, %ah # Sense KB_SHIFT_COD 16264123Skato int $0x18 # KBD/CRT BIOS 16364123Skato xorb %ah, %ah 16464123Skato ret 16564123Skato 16664123Skato# 16764123Skato# Check KBD buffer 16864123Skato# 16964123Skato .global sc_iskeypress 17064123Skatosc_iskeypress: 17164123Skato mov $1, %ah 17264123Skato int $0x18 # KBD/CRT BIOS 17364123Skato testb $1, %bh 17464123Skato jz no_key 17564123Skato movw $1, %ax 17664123Skato ret 17764123Skatono_key: 17864123Skato xorw %ax, %ax 17964123Skato ret 18064123Skato 18164123Skato# 18264123Skato# Read from KBD 18364123Skato# 18464123Skato .global sc_getc 18564123Skatosc_getc: 18664123Skato xorb %ah, %ah 18764123Skato int $0x18 18864123Skato ret 18964123Skato 19064123Skato# 19164123Skato# Initialize CRT (normal mode) 19264123Skato# 19364123Skatoinit_screen_normal: 19464123Skato # Disable graphic screen 19564123Skato movb $0x41, %ah 19664123Skato int $0x18 19764123Skato # Init graphic screen 19864123Skato movb $0x42, %al 19964123Skato movb $0xc0, %ch 20064123Skato int $0x18 20164123Skato # 80x25 mode 20264123Skato movw $0x0a00, %ax 20364123Skato int $0x18 20464123Skato ret 20564123Skato 20664123Skato# 20764123Skato# Initialize CRT (hireso mode) 20864123Skato# 20964123Skatoinit_screen_hireso: 21064123Skato # Init RAM window 21164123Skato movb $8, %al 21264123Skato outb %al, $0x91 21364123Skato movb $0x0a, %al 21464123Skato outb %al, $0x93 21564123Skato # 80x31 mode 21664123Skato movw $0x0a00, %ax 21764123Skato int $0x18 21864123Skato ret 21964123Skato 22064123Skato# 22164123Skato# Initialize screen (internal) 22264123Skato# 22364123Skatoinit_screen: 22464123Skato movb ishireso, %ah 22564123Skato orb %ah, %ah 22664123Skato jne hireso_ini 22764123Skato call init_screen_normal 22864123Skato jmp init_next 22964123Skatohireso_ini: 23064123Skato call init_screen_hireso 23164123Skatoinit_next: 23264123Skato movb $0x0c, %ah 23364123Skato int $0x18 23464123Skato # cursor home and off 23564123Skato xorw %dx, %dx 23664123Skato movb $0x13, %ah 23764123Skato int $0x18 23864123Skato movb $0x12, %ah 23964123Skato int $0x18 24064123Skato ret 24164123Skato 24264123Skato# 24364123Skato# Initialize screeen 24464123Skato# 24564123Skato .global sc_init 24664123Skatosc_init: 24764123Skato call init_screen 24864123Skato call sc_clean 24964123Skato movw $0, curpos 25064123Skato ret 25164123Skato 25264123Skato .data 25364123Skatocurpos: .word 0 # Current cursor position 254