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,07h ; <BEL> = beep
104 cmp al,19h ; <EM> = return to text mode
106 cmp al,18h ; <CAN> = VGA filename follows
109 cmp al,10h ; 10h to 17h are mode controls
113 msg_normal: call write_serial_displaymask ; Write to serial port
114 test [DisplayMask],cl
115 jz msg_ignore ; Not screen
116 test byte [DisplayCon],01h
118 mov bl,[TextAttribute]
120 mov ah,09h ; Write character/attribute
121 mov cx,1 ; One character only
122 int 10h ; Write to screen
126 ja msg_line_wrap ; Screen wraparound
129 msg_gotoxy: mov bh,[BIOS_page]
131 mov ah,02h ; Set cursor position
135 msg_beep: mov ax,0E07h ; Beep
140 msg_ctrl_o: ; ^O = color code follows
141 mov word [NextCharJump],msg_setbg
143 msg_newline: ; Newline char or end of line
145 call write_serial_str_displaymask
146 msg_line_wrap: ; Screen wraparound
147 test [DisplayMask],cl
149 mov byte [CursorCol],0
156 msg_scroll: xor cx,cx ; Upper left hand corner
158 mov [CursorRow],dh ; New cursor at the bottom
159 mov bh,[ScrollAttribute]
160 mov ax,0601h ; Scroll up one line
163 msg_formfeed: ; Form feed character
165 call write_serial_str_displaymask
166 test [DisplayMask],cl
169 mov [CursorDX],cx ; Upper lefthand corner
171 mov bh,[TextAttribute]
172 mov ax,0600h ; Clear screen region
175 msg_setbg: ; Color background character
179 test [DisplayMask],cl
181 mov [TextAttribute],al
183 mov word [NextCharJump],msg_setfg
185 msg_setfg: ; Color foreground character
188 test [DisplayMask],cl
190 or [TextAttribute],al ; setbg set foreground to 0
192 jmp short msg_putcharnext
194 mov word [NextCharJump],msg_filename
196 jmp short msg_setvgafileptr
199 mov byte [TextAttribute],07h ; Default attribute
201 mov word [NextCharJump],msg_putchar
204 msg_filename: ; Getting VGA filename
205 cmp al,0Ah ; <LF> = end of filename
208 jbe msg_ret ; Ignore space/control char
212 mov [di],al ; Can't use stosb (DS:)
220 jmp short msg_initvars
227 mov byte [si],0 ; Zero-terminate filename
235 jz msg_putcharnext ; Not there
239 ; Subroutine to initialize variables, also needed
240 ; after loading a graphics file
244 mov ah,03h ; Read cursor position
248 jmp short msg_putcharnext ; Initialize state machine
253 jmp short msg_putcharnext
256 ; write_serial: If serial output is enabled, write character on serial port
257 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
259 write_serial_displaymask:
260 test byte [DisplayMask], 04h
271 ; Wait for space in transmit register
272 lea dx,[bx+5] ; DX -> LSR
277 ; Wait for input flow control
285 xchg dx,bx ; DX -> THR
287 call slow_out ; Send data
293 ; write_serial_str: write_serial for strings
294 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
296 write_serial_str_displaymask:
297 test byte [DisplayMask], 04h
298 jz write_serial_str.end
309 ; pollchar: check if we have an input character pending (ZF = 0)
313 mov ah,11h ; Poll keyboard
315 jnz .done ; Keyboard response
318 jz .done ; No serial port -> no input
319 add dx,byte 5 ; DX -> LSR
321 test al,1 ; ZF = 0 if data pending
324 mov ah,[FlowIgnore] ; Required status bits
329 dec al ; Set ZF = 0 if equal
334 ; getchar: Read a character from keyboard or serial port
340 mov ah,11h ; Poll keyboard
342 jnz .kbd ; Keyboard input?
346 lea dx,[bx+5] ; DX -> LSR
356 .serial: xor ah,ah ; Avoid confusion
357 xchg dx,bx ; Data port
360 .kbd: mov ah,10h ; Get keyboard input
368 mov bx,KbdMap ; Convert character sets
374 ; debug hack to print a character with minimal code impact
379 mov bx,[bp+9*4] ; Get return address
380 mov al,[cs:bx] ; Get data byte
381 inc word [bp+9*4] ; Return to after data byte
386 %endif ; DEBUG_TRACERS
389 ; This is a word to pc_setint16 can set it
390 DisplayCon dw 01h ; Console display enabled
392 ScrollAttribute db 07h ; Grey on white (normal text color)
396 NextCharJump resw 1 ; Routine to interpret next print char
398 CursorCol resb 1 ; Cursor column for message file
399 CursorRow resb 1 ; Cursor row for message file
401 VidCols resb 1 ; Columns on screen-1
402 VidRows resb 1 ; Rows on screen-1
404 ; Serial console stuff...
405 BaudDivisor resw 1 ; Baud rate divisor
407 FlowOutput resb 1 ; Outputs to assert for serial flow
408 FlowInput resb 1 ; Input bits for serial flow
409 FlowIgnore resb 1 ; Ignore input unless these bits set
411 TextAttribute resb 1 ; Text attribute for message file
412 DisplayMask resb 1 ; Display modes mask