1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;; (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
16 ;; Console I/O code, except:
17 ;; writechr, writestr - module-dependent
18 ;; cwritestr, crlf - writestr.inc
19 ;; writehex* - writehex.inc
23 ; loadkeys: Load a LILO-style keymap; SI and DX:AX set by searchdir
28 and dx,dx ; Should be 256 bytes exactly
34 mov cx,1 ; 1 cluster should be >= 256 bytes
45 ; get_msg_file: Load a text file and write its contents to the screen,
46 ; interpreting color codes. Call with the file already
47 ; on the top of the open/getc stack.
49 ; Assumes CS == DS == ES.
52 mov byte [TextAttribute],07h ; Default grey on white
53 mov byte [DisplayMask],07h ; Display text in all modes
62 movzx cx,byte [UsingVGA]
64 inc cx ; CL <- 01h = text mode,
66 call [NextCharJump] ; Do what shall be done
71 msg_putchar: ; Normal character
72 cmp al,0Fh ; ^O = color code follows
74 cmp al,0Dh ; Ignore <CR>
76 cmp al,0Ah ; <LF> = newline
78 cmp al,0Ch ; <FF> = clear screen
80 cmp al,07h ; <BEL> = beep
82 cmp al,19h ; <EM> = return to text mode
84 cmp al,18h ; <CAN> = VGA filename follows
87 cmp al,10h ; 10h to 17h are mode controls
91 msg_normal: call write_serial_displaymask ; Write to serial port
93 jz msg_ignore ; Not screen
94 test byte [DisplayCon],01h
96 mov bl,[TextAttribute]
98 mov ah,09h ; Write character/attribute
99 mov cx,1 ; One character only
100 int 10h ; Write to screen
104 ja msg_line_wrap ; Screen wraparound
107 msg_gotoxy: mov bh,[BIOS_page]
109 mov ah,02h ; Set cursor position
113 msg_beep: mov ax,0E07h ; Beep
118 msg_ctrl_o: ; ^O = color code follows
119 mov word [NextCharJump],msg_setbg
121 msg_newline: ; Newline char or end of line
123 call write_serial_str_displaymask
124 msg_line_wrap: ; Screen wraparound
125 test [DisplayMask],cl
127 mov byte [CursorCol],0
134 msg_scroll: xor cx,cx ; Upper left hand corner
136 mov [CursorRow],dh ; New cursor at the bottom
137 mov bh,[ScrollAttribute]
138 mov ax,0601h ; Scroll up one line
141 msg_formfeed: ; Form feed character
143 call write_serial_str_displaymask
144 test [DisplayMask],cl
147 mov [CursorDX],cx ; Upper lefthand corner
149 mov bh,[TextAttribute]
150 mov ax,0600h ; Clear screen region
153 msg_setbg: ; Color background character
157 test [DisplayMask],cl
159 mov [TextAttribute],al
161 mov word [NextCharJump],msg_setfg
163 msg_setfg: ; Color foreground character
166 test [DisplayMask],cl
168 or [TextAttribute],al ; setbg set foreground to 0
170 jmp short msg_putcharnext
172 mov word [NextCharJump],msg_filename
174 jmp short msg_setvgafileptr
177 mov byte [TextAttribute],07h ; Default attribute
179 mov word [NextCharJump],msg_putchar
182 msg_filename: ; Getting VGA filename
183 cmp al,0Ah ; <LF> = end of filename
186 jbe msg_ret ; Ignore space/control char
190 mov [di],al ; Can't use stosb (DS:)
198 jmp short msg_initvars
202 mov byte [si],0 ; Zero-terminate filename
207 jz msg_putcharnext ; Not there
211 ; Subroutine to initialize variables, also needed
212 ; after loading a graphics file
216 mov ah,03h ; Read cursor position
220 jmp short msg_putcharnext ; Initialize state machine
225 jmp short msg_putcharnext
228 ; write_serial: If serial output is enabled, write character on serial port
229 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
231 write_serial_displaymask:
232 test byte [DisplayMask], 04h
243 ; Wait for space in transmit register
244 lea dx,[bx+5] ; DX -> LSR
249 ; Wait for input flow control
257 xchg dx,bx ; DX -> THR
259 call slow_out ; Send data
265 ; write_serial_str: write_serial for strings
266 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
268 write_serial_str_displaymask:
269 test byte [DisplayMask], 04h
270 jz write_serial_str.end
281 ; pollchar: check if we have an input character pending (ZF = 0)
285 mov ah,11h ; Poll keyboard
287 jnz .done ; Keyboard response
290 jz .done ; No serial port -> no input
291 add dx,byte 5 ; DX -> LSR
293 test al,1 ; ZF = 0 if data pending
296 mov ah,[FlowIgnore] ; Required status bits
301 dec al ; Set ZF = 0 if equal
306 ; getchar: Read a character from keyboard or serial port
312 mov ah,11h ; Poll keyboard
314 jnz .kbd ; Keyboard input?
318 lea dx,[bx+5] ; DX -> LSR
328 .serial: xor ah,ah ; Avoid confusion
329 xchg dx,bx ; Data port
332 .kbd: mov ah,10h ; Get keyboard input
340 mov bx,KbdMap ; Convert character sets
346 ; debug hack to print a character with minimal code impact
351 mov bx,[bp+9*4] ; Get return address
352 mov al,[cs:bx] ; Get data byte
353 inc word [bp+9*4] ; Return to after data byte
358 %endif ; DEBUG_TRACERS
361 %if IS_ISOLINUX == 0 ; Defined elsewhere for ISOLINUX
365 crff_msg db CR, FF, 0
368 ; This is a word to pc_setint16 can set it
369 DisplayCon dw 01h ; Console display enabled
371 ScrollAttribute db 07h ; Grey on white (normal text color)
375 NextCharJump resw 1 ; Routine to interpret next print char
377 CursorCol resb 1 ; Cursor column for message file
378 CursorRow resb 1 ; Cursor row for message file
380 VidCols resb 1 ; Columns on screen-1
381 VidRows resb 1 ; Rows on screen-1
383 ; Serial console stuff...
384 BaudDivisor resw 1 ; Baud rate divisor
386 FlowOutput resb 1 ; Outputs to assert for serial flow
387 FlowInput resb 1 ; Input bits for serial flow
388 FlowIgnore resb 1 ; Ignore input unless these bits set
390 TextAttribute resb 1 ; Text attribute for message file
391 DisplayMask resb 1 ; Display modes mask