2 ;; -----------------------------------------------------------------------
4 ;; Copyright 1994-2004 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 mov bl,[TextAttribute]
116 mov ah,09h ; Write character/attribute
117 mov cx,1 ; One character only
118 int 10h ; Write to screen
122 ja msg_line_wrap ; Screen wraparound
125 msg_gotoxy: mov bh,[BIOS_page]
127 mov ah,02h ; Set cursor position
130 msg_ctrl_o: ; ^O = color code follows
131 mov word [NextCharJump],msg_setbg
133 msg_newline: ; Newline char or end of line
135 call write_serial_str_displaymask
136 msg_line_wrap: ; Screen wraparound
137 test [DisplayMask],cl
139 mov byte [CursorCol],0
146 msg_scroll: xor cx,cx ; Upper left hand corner
148 mov [CursorRow],dh ; New cursor at the bottom
149 mov bh,[ScrollAttribute]
150 mov ax,0601h ; Scroll up one line
153 msg_formfeed: ; Form feed character
155 call write_serial_str_displaymask
156 test [DisplayMask],cl
159 mov [CursorDX],cx ; Upper lefthand corner
161 mov bh,[TextAttribute]
162 mov ax,0600h ; Clear screen region
165 msg_setbg: ; Color background character
169 test [DisplayMask],cl
171 mov [TextAttribute],al
173 mov word [NextCharJump],msg_setfg
175 msg_setfg: ; Color foreground character
178 test [DisplayMask],cl
180 or [TextAttribute],al ; setbg set foreground to 0
182 jmp short msg_putcharnext
184 mov word [NextCharJump],msg_filename
186 jmp short msg_setvgafileptr
189 mov byte [TextAttribute],07h ; Default attribute
191 mov word [NextCharJump],msg_putchar
194 msg_filename: ; Getting VGA filename
195 cmp al,0Ah ; <LF> = end of filename
198 jbe msg_ret ; Ignore space/control char
202 mov [di],al ; Can't use stosb (DS:)
210 jmp short msg_initvars
223 jz msg_putcharnext ; Not there
227 ; Subroutine to initialize variables, also needed
228 ; after loading a graphics file
232 mov ah,03h ; Read cursor position
236 jmp short msg_putcharnext ; Initialize state machine
241 jmp short msg_putcharnext
244 ; write_serial: If serial output is enabled, write character on serial port
245 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
247 write_serial_displaymask:
248 test byte [DisplayMask], 04h
259 ; Wait for space in transmit register
260 lea dx,[bx+5] ; DX -> LSR
265 ; Wait for input flow control
273 xchg dx,bx ; DX -> THR
275 call slow_out ; Send data
281 ; write_serial_str: write_serial for strings
282 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
284 write_serial_str_displaymask:
285 test byte [DisplayMask], 04h
286 jz write_serial_str.end
297 ; pollchar: check if we have an input character pending (ZF = 0)
301 mov ah,11h ; Poll keyboard
303 jnz .done ; Keyboard response
306 jz .done ; No serial port -> no input
307 add dx,byte 5 ; DX -> LSR
309 test al,1 ; ZF = 0 if data pending
312 mov ah,[FlowIgnore] ; Required status bits
317 dec al ; Set ZF = 0 if equal
322 ; getchar: Read a character from keyboard or serial port
328 mov ah,11h ; Poll keyboard
330 jnz .kbd ; Keyboard input?
334 lea dx,[bx+5] ; DX -> LSR
344 .serial: xor ah,ah ; Avoid confusion
345 xchg dx,bx ; Data port
348 .kbd: mov ah,10h ; Get keyboard input
356 mov bx,KbdMap ; Convert character sets
362 ; debug hack to print a character with minimal code impact
367 mov bx,[bp+9*4] ; Get return address
368 mov al,[cs:bx] ; Get data byte
369 inc word [bp+9*4] ; Return to after data byte
374 %endif ; DEBUG_TRACERS
377 ScrollAttribute db 07h ; Grey on white (normal text color)
381 NextCharJump resw 1 ; Routine to interpret next print char
383 CursorCol resb 1 ; Cursor column for message file
384 CursorRow resb 1 ; Cursor row for message file
386 VidCols resb 1 ; Columns on screen-1
387 VidRows resb 1 ; Rows on screen-1
389 ; Serial console stuff...
390 BaudDivisor resw 1 ; Baud rate divisor
392 FlowOutput resb 1 ; Outputs to assert for serial flow
393 FlowInput resb 1 ; Input bits for serial flow
394 FlowIgnore resb 1 ; Ignore input unless these bits set
396 TextAttribute resb 1 ; Text attribute for message file
397 DisplayMask resb 1 ; Display modes mask