1 ;; $Id: conio.inc,v 1.12 2005/01/04 22:17:17 hpa Exp $
2 ;; -----------------------------------------------------------------------
4 ;; Copyright 1994-2005 H. Peter Anvin - All Rights Reserved
6 ;; This program is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;; (at your option) any later version; incorporated herein by reference.
12 ;; -----------------------------------------------------------------------
17 ;; Console I/O code, except:
18 ;; writechr, writestr - module-dependent
19 ;; cwritestr, crlf - writestr.inc
20 ;; writehex* - writehex.inc
24 ; loadkeys: Load a LILO-style keymap; SI and DX:AX set by searchdir
29 and dx,dx ; Should be 256 bytes exactly
35 mov cx,1 ; 1 cluster should be >= 256 bytes
46 ; get_msg_file: Load a text file and write its contents to the screen,
47 ; interpreting color codes. Is called with SI and DX:AX
48 ; set by routine searchdir
52 shl edx,16 ; EDX <- DX:AX (length of file)
54 mov ax,xfer_buf_seg ; Use for temporary storage
57 mov byte [TextAttribute],07h ; Default grey on white
58 mov byte [DisplayMask],07h ; Display text in all modes
61 get_msg_chunk: push edx ; EDX = length of file
62 xor bx,bx ; == xbs_textbuf
66 push si ; Save current cluster
67 xor si,si ; == xbs_textbuf
68 mov cx,[BufSafeBytes] ; Number of bytes left in chunk
77 inc cl ; 01h = text mode, 02h = graphics
78 call [NextCharJump] ; Do what shall be done
86 jmp short get_msg_chunk
88 add sp,byte 6 ; Drop pushed EDX, CX
93 msg_putchar: ; Normal character
94 cmp al,0Fh ; ^O = color code follows
96 cmp al,0Dh ; Ignore <CR>
98 cmp al,0Ah ; <LF> = newline
100 cmp al,0Ch ; <FF> = clear screen
102 cmp al,19h ; <EM> = return to text mode
104 cmp al,18h ; <CAN> = VGA filename follows
107 cmp al,10h ; 10h to 17h are mode controls
111 msg_normal: call write_serial_displaymask ; Write to serial port
112 test [DisplayMask],cl
113 jz msg_ignore ; Not screen
114 test byte [DisplayCon],01h
116 mov bl,[TextAttribute]
118 mov ah,09h ; Write character/attribute
119 mov cx,1 ; One character only
120 int 10h ; Write to screen
124 ja msg_line_wrap ; Screen wraparound
127 msg_gotoxy: mov bh,[BIOS_page]
129 mov ah,02h ; Set cursor position
132 msg_ctrl_o: ; ^O = color code follows
133 mov word [NextCharJump],msg_setbg
135 msg_newline: ; Newline char or end of line
137 call write_serial_str_displaymask
138 msg_line_wrap: ; Screen wraparound
139 test [DisplayMask],cl
141 mov byte [CursorCol],0
148 msg_scroll: xor cx,cx ; Upper left hand corner
150 mov [CursorRow],dh ; New cursor at the bottom
151 mov bh,[ScrollAttribute]
152 mov ax,0601h ; Scroll up one line
155 msg_formfeed: ; Form feed character
157 call write_serial_str_displaymask
158 test [DisplayMask],cl
161 mov [CursorDX],cx ; Upper lefthand corner
163 mov bh,[TextAttribute]
164 mov ax,0600h ; Clear screen region
167 msg_setbg: ; Color background character
171 test [DisplayMask],cl
173 mov [TextAttribute],al
175 mov word [NextCharJump],msg_setfg
177 msg_setfg: ; Color foreground character
180 test [DisplayMask],cl
182 or [TextAttribute],al ; setbg set foreground to 0
184 jmp short msg_putcharnext
186 mov word [NextCharJump],msg_filename
188 jmp short msg_setvgafileptr
191 mov byte [TextAttribute],07h ; Default attribute
193 mov word [NextCharJump],msg_putchar
196 msg_filename: ; Getting VGA filename
197 cmp al,0Ah ; <LF> = end of filename
200 jbe msg_ret ; Ignore space/control char
204 mov [di],al ; Can't use stosb (DS:)
212 jmp short msg_initvars
225 jz msg_putcharnext ; Not there
229 ; Subroutine to initialize variables, also needed
230 ; after loading a graphics file
234 mov ah,03h ; Read cursor position
238 jmp short msg_putcharnext ; Initialize state machine
243 jmp short msg_putcharnext
246 ; write_serial: If serial output is enabled, write character on serial port
247 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
249 write_serial_displaymask:
250 test byte [DisplayMask], 04h
261 ; Wait for space in transmit register
262 lea dx,[bx+5] ; DX -> LSR
267 ; Wait for input flow control
275 xchg dx,bx ; DX -> THR
277 call slow_out ; Send data
283 ; write_serial_str: write_serial for strings
284 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
286 write_serial_str_displaymask:
287 test byte [DisplayMask], 04h
288 jz write_serial_str.end
299 ; pollchar: check if we have an input character pending (ZF = 0)
303 mov ah,11h ; Poll keyboard
305 jnz .done ; Keyboard response
308 jz .done ; No serial port -> no input
309 add dx,byte 5 ; DX -> LSR
311 test al,1 ; ZF = 0 if data pending
314 mov ah,[FlowIgnore] ; Required status bits
319 dec al ; Set ZF = 0 if equal
324 ; getchar: Read a character from keyboard or serial port
330 mov ah,11h ; Poll keyboard
332 jnz .kbd ; Keyboard input?
336 lea dx,[bx+5] ; DX -> LSR
346 .serial: xor ah,ah ; Avoid confusion
347 xchg dx,bx ; Data port
350 .kbd: mov ah,10h ; Get keyboard input
358 mov bx,KbdMap ; Convert character sets
364 ; debug hack to print a character with minimal code impact
369 mov bx,[bp+9*4] ; Get return address
370 mov al,[cs:bx] ; Get data byte
371 inc word [bp+9*4] ; Return to after data byte
376 %endif ; DEBUG_TRACERS
379 ; This is a word to pc_setint16 can set it
380 DisplayCon dw 01h ; Console display enabled
382 ScrollAttribute db 07h ; Grey on white (normal text color)
386 NextCharJump resw 1 ; Routine to interpret next print char
388 CursorCol resb 1 ; Cursor column for message file
389 CursorRow resb 1 ; Cursor row for message file
391 VidCols resb 1 ; Columns on screen-1
392 VidRows resb 1 ; Rows on screen-1
394 ; Serial console stuff...
395 BaudDivisor resw 1 ; Baud rate divisor
397 FlowOutput resb 1 ; Outputs to assert for serial flow
398 FlowInput resb 1 ; Input bits for serial flow
399 FlowIgnore resb 1 ; Ignore input unless these bits set
401 TextAttribute resb 1 ; Text attribute for message file
402 DisplayMask resb 1 ; Display modes mask