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. Is called with SI and DX:AX
47 ; set by routine searchdir
51 shl edx,16 ; EDX <- DX:AX (length of file)
53 mov ax,xfer_buf_seg ; Use for temporary storage
56 mov byte [TextAttribute],07h ; Default grey on white
57 mov byte [DisplayMask],07h ; Display text in all modes
60 get_msg_chunk: push edx ; EDX = length of file
61 xor bx,bx ; == xbs_textbuf
65 push si ; Save current cluster
66 xor si,si ; == xbs_textbuf
67 mov cx,[BufSafeBytes] ; Number of bytes left in chunk
77 inc cx ; CL <- 01h = text mode,
79 call [NextCharJump] ; Do what shall be done
87 jmp short get_msg_chunk
89 add sp,byte 6 ; Drop pushed EDX, CX
94 msg_putchar: ; Normal character
95 cmp al,0Fh ; ^O = color code follows
97 cmp al,0Dh ; Ignore <CR>
99 cmp al,0Ah ; <LF> = newline
101 cmp al,0Ch ; <FF> = clear screen
103 cmp al,07h ; <BEL> = beep
105 cmp al,19h ; <EM> = return to text mode
107 cmp al,18h ; <CAN> = VGA filename follows
110 cmp al,10h ; 10h to 17h are mode controls
114 msg_normal: call write_serial_displaymask ; Write to serial port
115 test [DisplayMask],cl
116 jz msg_ignore ; Not screen
117 test byte [DisplayCon],01h
119 mov bl,[TextAttribute]
121 mov ah,09h ; Write character/attribute
122 mov cx,1 ; One character only
123 int 10h ; Write to screen
127 ja msg_line_wrap ; Screen wraparound
130 msg_gotoxy: mov bh,[BIOS_page]
132 mov ah,02h ; Set cursor position
136 msg_beep: mov ax,0E07h ; Beep
141 msg_ctrl_o: ; ^O = color code follows
142 mov word [NextCharJump],msg_setbg
144 msg_newline: ; Newline char or end of line
146 call write_serial_str_displaymask
147 msg_line_wrap: ; Screen wraparound
148 test [DisplayMask],cl
150 mov byte [CursorCol],0
157 msg_scroll: xor cx,cx ; Upper left hand corner
159 mov [CursorRow],dh ; New cursor at the bottom
160 mov bh,[ScrollAttribute]
161 mov ax,0601h ; Scroll up one line
164 msg_formfeed: ; Form feed character
166 call write_serial_str_displaymask
167 test [DisplayMask],cl
170 mov [CursorDX],cx ; Upper lefthand corner
172 mov bh,[TextAttribute]
173 mov ax,0600h ; Clear screen region
176 msg_setbg: ; Color background character
180 test [DisplayMask],cl
182 mov [TextAttribute],al
184 mov word [NextCharJump],msg_setfg
186 msg_setfg: ; Color foreground character
189 test [DisplayMask],cl
191 or [TextAttribute],al ; setbg set foreground to 0
193 jmp short msg_putcharnext
195 mov word [NextCharJump],msg_filename
197 jmp short msg_setvgafileptr
200 mov byte [TextAttribute],07h ; Default attribute
202 mov word [NextCharJump],msg_putchar
205 msg_filename: ; Getting VGA filename
206 cmp al,0Ah ; <LF> = end of filename
209 jbe msg_ret ; Ignore space/control char
213 mov [di],al ; Can't use stosb (DS:)
221 jmp short msg_initvars
228 mov byte [si],0 ; Zero-terminate filename
234 jz msg_putcharnext ; Not there
238 ; Subroutine to initialize variables, also needed
239 ; after loading a graphics file
243 mov ah,03h ; Read cursor position
247 jmp short msg_putcharnext ; Initialize state machine
252 jmp short msg_putcharnext
255 ; write_serial: If serial output is enabled, write character on serial port
256 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
258 write_serial_displaymask:
259 test byte [DisplayMask], 04h
270 ; Wait for space in transmit register
271 lea dx,[bx+5] ; DX -> LSR
276 ; Wait for input flow control
284 xchg dx,bx ; DX -> THR
286 call slow_out ; Send data
292 ; write_serial_str: write_serial for strings
293 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
295 write_serial_str_displaymask:
296 test byte [DisplayMask], 04h
297 jz write_serial_str.end
308 ; pollchar: check if we have an input character pending (ZF = 0)
312 mov ah,11h ; Poll keyboard
314 jnz .done ; Keyboard response
317 jz .done ; No serial port -> no input
318 add dx,byte 5 ; DX -> LSR
320 test al,1 ; ZF = 0 if data pending
323 mov ah,[FlowIgnore] ; Required status bits
328 dec al ; Set ZF = 0 if equal
333 ; getchar: Read a character from keyboard or serial port
339 mov ah,11h ; Poll keyboard
341 jnz .kbd ; Keyboard input?
345 lea dx,[bx+5] ; DX -> LSR
355 .serial: xor ah,ah ; Avoid confusion
356 xchg dx,bx ; Data port
359 .kbd: mov ah,10h ; Get keyboard input
367 mov bx,KbdMap ; Convert character sets
373 ; debug hack to print a character with minimal code impact
378 mov bx,[bp+9*4] ; Get return address
379 mov al,[cs:bx] ; Get data byte
380 inc word [bp+9*4] ; Return to after data byte
385 %endif ; DEBUG_TRACERS
388 %if IS_ISOLINUX == 0 ; Defined elsewhere for ISOLINUX
392 crff_msg db CR, FF, 0
395 ; This is a word to pc_setint16 can set it
396 DisplayCon dw 01h ; Console display enabled
398 ScrollAttribute db 07h ; Grey on white (normal text color)
402 NextCharJump resw 1 ; Routine to interpret next print char
404 CursorCol resb 1 ; Cursor column for message file
405 CursorRow resb 1 ; Cursor row for message file
407 VidCols resb 1 ; Columns on screen-1
408 VidRows resb 1 ; Rows on screen-1
410 ; Serial console stuff...
411 BaudDivisor resw 1 ; Baud rate divisor
413 FlowOutput resb 1 ; Outputs to assert for serial flow
414 FlowInput resb 1 ; Input bits for serial flow
415 FlowIgnore resb 1 ; Ignore input unless these bits set
417 TextAttribute resb 1 ; Text attribute for message file
418 DisplayMask resb 1 ; Display modes mask