1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009 Intel Corporation; author: H. Peter Anvin
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_early - module-dependent
19 ;; writestr, crlf - writestr.inc
20 ;; writehex* - writehex.inc
24 ; loadkeys: Load a LILO-style keymap; file is open on the top of the
33 jc .done ; EOF already?
35 ; Make sure we are at EOF now...
37 jnc .done ; We should be at EOF now!
39 ; It was okay, we can now move it into the KbdMap
50 ; get_msg_file: Load a text file and write its contents to the screen,
51 ; interpreting color codes. Call with the file already
52 ; on the top of the open/getc stack.
54 ; Assumes CS == DS == ES.
57 mov byte [TextAttribute],07h ; Default grey on white
58 mov byte [DisplayMask],07h ; Display text in all modes
67 movzx cx,byte [UsingVGA]
69 inc cx ; CL <- 01h = text mode,
71 call [NextCharJump] ; Do what shall be done
76 msg_putchar: ; Normal character
77 cmp al,0Fh ; ^O = color code follows
79 cmp al,0Dh ; Ignore <CR>
81 cmp al,0Ah ; <LF> = newline
83 cmp al,0Ch ; <FF> = clear screen
85 cmp al,07h ; <BEL> = beep
87 cmp al,19h ; <EM> = return to text mode
89 cmp al,18h ; <CAN> = VGA filename follows
92 cmp al,10h ; 10h to 17h are mode controls
96 msg_normal: call write_serial_displaymask ; Write to serial port
98 jz msg_ignore ; Not screen
99 test byte [DisplayCon],01h
101 mov bl,[TextAttribute]
103 mov ah,09h ; Write character/attribute
104 mov cx,1 ; One character only
105 int 10h ; Write to screen
109 ja msg_line_wrap ; Screen wraparound
112 msg_gotoxy: mov bh,[BIOS_page]
114 mov ah,02h ; Set cursor position
118 msg_beep: mov ax,0E07h ; Beep
123 msg_ctrl_o: ; ^O = color code follows
124 mov word [NextCharJump],msg_setbg
126 msg_newline: ; Newline char or end of line
128 call write_serial_str_displaymask
129 msg_line_wrap: ; Screen wraparound
130 test [DisplayMask],cl
132 mov byte [CursorCol],0
139 msg_scroll: xor cx,cx ; Upper left hand corner
141 mov [CursorRow],dh ; New cursor at the bottom
142 mov bh,[ScrollAttribute]
143 mov ax,0601h ; Scroll up one line
146 msg_formfeed: ; Form feed character
148 call write_serial_str_displaymask
149 test [DisplayMask],cl
152 mov [CursorDX],cx ; Upper lefthand corner
154 mov bh,[TextAttribute]
155 mov ax,0600h ; Clear screen region
158 msg_setbg: ; Color background character
162 test [DisplayMask],cl
164 mov [TextAttribute],al
166 mov word [NextCharJump],msg_setfg
168 msg_setfg: ; Color foreground character
171 test [DisplayMask],cl
173 or [TextAttribute],al ; setbg set foreground to 0
175 jmp short msg_putcharnext
177 mov word [NextCharJump],msg_filename
179 jmp short msg_setvgafileptr
182 mov byte [TextAttribute],07h ; Default attribute
184 mov word [NextCharJump],msg_putchar
187 msg_filename: ; Getting VGA filename
188 cmp al,0Ah ; <LF> = end of filename
191 jbe msg_ret ; Ignore space/control char
195 mov [di],al ; Can't use stosb (DS:)
203 jmp short msg_initvars
207 mov byte [si],0 ; Zero-terminate filename
210 pm_call pm_mangle_name
212 jz msg_putcharnext ; Not there
216 ; Subroutine to initialize variables, also needed
217 ; after loading a graphics file
221 mov ah,03h ; Read cursor position
225 jmp short msg_putcharnext ; Initialize state machine
230 jmp short msg_putcharnext
233 ; write_serial: If serial output is enabled, write character on serial port
234 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
236 write_serial_displaymask:
237 test byte [DisplayMask], 04h
248 ; Wait for space in transmit register
249 lea dx,[bx+5] ; DX -> LSR
254 ; Wait for input flow control
262 xchg dx,bx ; DX -> THR
264 slow_out dx,al ; Send data
270 ; write_serial_str: write_serial for strings
271 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
273 write_serial_str_displaymask:
274 test byte [DisplayMask], 04h
275 jz write_serial_str.end
286 ; pollchar: check if we have an input character pending (ZF = 0)
290 mov ah,11h ; Poll keyboard
292 jnz .done ; Keyboard response
295 jz .done ; No serial port -> no input
296 mov ax,[SerialTail] ; Already-queued input?
299 jne .done_sti ; If so, return ZF = 0
302 test al,1 ; ZF = 0 if data pending
305 mov ah,[FlowIgnore] ; Required status bits
310 dec al ; Set ZF = 0 if equal
316 ; getchar: Read a character from keyboard or serial port
323 mov ah,11h ; Poll keyboard
325 jnz .kbd ; Keyboard input?
333 lea dx,[bx+5] ; DX -> LSR
343 .serial: xor ah,ah ; Avoid confusion
344 mov dx,bx ; Data port
349 sti ; We already know we'll consume data
352 mov ax,aux_seg + (aux.serial >> 4)
357 and bx,serial_buf_size-1
361 .kbd: mov ah,10h ; Get keyboard input
369 mov bx,KbdMap ; Convert character sets
373 jmp reset_idle ; Character received
377 ; debug hack to print a character with minimal code impact
382 mov bx,[bp+9*4] ; Get return address
383 mov al,[cs:bx] ; Get data byte
384 inc word [bp+9*4] ; Return to after data byte
389 %endif ; DEBUG_TRACERS
392 %if IS_ISOLINUX == 0 ; Defined elsewhere for ISOLINUX
396 crff_msg db CR, FF, 0
399 ; This is a word to pc_setint16 can set it
400 DisplayCon dw 01h ; Console display enabled
402 ScrollAttribute db 07h ; Grey on white (normal text color)
406 NextCharJump resw 1 ; Routine to interpret next print char
408 CursorCol resb 1 ; Cursor column for message file
409 CursorRow resb 1 ; Cursor row for message file
411 VidCols resb 1 ; Columns on screen-1
412 VidRows resb 1 ; Rows on screen-1
414 ; Serial console stuff; don't put this in .config becasue we don't want
415 ; loading a new config file to undo this setting.
418 SerialPort dw 0 ; Serial port base (or 0 for no serial port)
419 BaudDivisor dw 115200/9600 ; Baud rate divisor
421 FlowOutput db 0 ; Outputs to assert for serial flow
422 FlowInput db 0 ; Input bits for serial flow
423 FlowIgnore db 0 ; Ignore input unless these bits set
424 FlowDummy db 0 ; Unused
427 TextAttribute resb 1 ; Text attribute for message file
428 DisplayMask resb 1 ; Display modes mask
431 %include "serirq.inc"