1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2005 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
76 inc cl ; 01h = text mode, 02h = graphics
77 call [NextCharJump] ; Do what shall be done
85 jmp short get_msg_chunk
87 add sp,byte 6 ; Drop pushed EDX, CX
92 msg_putchar: ; Normal character
93 cmp al,0Fh ; ^O = color code follows
95 cmp al,0Dh ; Ignore <CR>
97 cmp al,0Ah ; <LF> = newline
99 cmp al,0Ch ; <FF> = clear screen
101 cmp al,07h ; <BEL> = beep
103 cmp al,19h ; <EM> = return to text mode
105 cmp al,18h ; <CAN> = VGA filename follows
108 cmp al,10h ; 10h to 17h are mode controls
112 msg_normal: call write_serial_displaymask ; Write to serial port
113 test [DisplayMask],cl
114 jz msg_ignore ; Not screen
115 test byte [DisplayCon],01h
117 mov bl,[TextAttribute]
119 mov ah,09h ; Write character/attribute
120 mov cx,1 ; One character only
121 int 10h ; Write to screen
125 ja msg_line_wrap ; Screen wraparound
128 msg_gotoxy: mov bh,[BIOS_page]
130 mov ah,02h ; Set cursor position
134 msg_beep: mov ax,0E07h ; Beep
139 msg_ctrl_o: ; ^O = color code follows
140 mov word [NextCharJump],msg_setbg
142 msg_newline: ; Newline char or end of line
144 call write_serial_str_displaymask
145 msg_line_wrap: ; Screen wraparound
146 test [DisplayMask],cl
148 mov byte [CursorCol],0
155 msg_scroll: xor cx,cx ; Upper left hand corner
157 mov [CursorRow],dh ; New cursor at the bottom
158 mov bh,[ScrollAttribute]
159 mov ax,0601h ; Scroll up one line
162 msg_formfeed: ; Form feed character
164 call write_serial_str_displaymask
165 test [DisplayMask],cl
168 mov [CursorDX],cx ; Upper lefthand corner
170 mov bh,[TextAttribute]
171 mov ax,0600h ; Clear screen region
174 msg_setbg: ; Color background character
178 test [DisplayMask],cl
180 mov [TextAttribute],al
182 mov word [NextCharJump],msg_setfg
184 msg_setfg: ; Color foreground character
187 test [DisplayMask],cl
189 or [TextAttribute],al ; setbg set foreground to 0
191 jmp short msg_putcharnext
193 mov word [NextCharJump],msg_filename
195 jmp short msg_setvgafileptr
198 mov byte [TextAttribute],07h ; Default attribute
200 mov word [NextCharJump],msg_putchar
203 msg_filename: ; Getting VGA filename
204 cmp al,0Ah ; <LF> = end of filename
207 jbe msg_ret ; Ignore space/control char
211 mov [di],al ; Can't use stosb (DS:)
219 jmp short msg_initvars
226 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 ; This is a word to pc_setint16 can set it
389 DisplayCon dw 01h ; Console display enabled
391 ScrollAttribute db 07h ; Grey on white (normal text color)
395 NextCharJump resw 1 ; Routine to interpret next print char
397 CursorCol resb 1 ; Cursor column for message file
398 CursorRow resb 1 ; Cursor row for message file
400 VidCols resb 1 ; Columns on screen-1
401 VidRows resb 1 ; Rows on screen-1
403 ; Serial console stuff...
404 BaudDivisor resw 1 ; Baud rate divisor
406 FlowOutput resb 1 ; Outputs to assert for serial flow
407 FlowInput resb 1 ; Input bits for serial flow
408 FlowIgnore resb 1 ; Ignore input unless these bits set
410 TextAttribute resb 1 ; Text attribute for message file
411 DisplayMask resb 1 ; Display modes mask