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
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
236 jz msg_putcharnext ; Not there
240 ; Subroutine to initialize variables, also needed
241 ; after loading a graphics file
245 mov ah,03h ; Read cursor position
249 jmp short msg_putcharnext ; Initialize state machine
254 jmp short msg_putcharnext
257 ; write_serial: If serial output is enabled, write character on serial port
258 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
260 write_serial_displaymask:
261 test byte [DisplayMask], 04h
272 ; Wait for space in transmit register
273 lea dx,[bx+5] ; DX -> LSR
278 ; Wait for input flow control
286 xchg dx,bx ; DX -> THR
288 call slow_out ; Send data
294 ; write_serial_str: write_serial for strings
295 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
297 write_serial_str_displaymask:
298 test byte [DisplayMask], 04h
299 jz write_serial_str.end
310 ; pollchar: check if we have an input character pending (ZF = 0)
314 mov ah,11h ; Poll keyboard
316 jnz .done ; Keyboard response
319 jz .done ; No serial port -> no input
320 add dx,byte 5 ; DX -> LSR
322 test al,1 ; ZF = 0 if data pending
325 mov ah,[FlowIgnore] ; Required status bits
330 dec al ; Set ZF = 0 if equal
335 ; getchar: Read a character from keyboard or serial port
341 mov ah,11h ; Poll keyboard
343 jnz .kbd ; Keyboard input?
347 lea dx,[bx+5] ; DX -> LSR
357 .serial: xor ah,ah ; Avoid confusion
358 xchg dx,bx ; Data port
361 .kbd: mov ah,10h ; Get keyboard input
369 mov bx,KbdMap ; Convert character sets
375 ; debug hack to print a character with minimal code impact
380 mov bx,[bp+9*4] ; Get return address
381 mov al,[cs:bx] ; Get data byte
382 inc word [bp+9*4] ; Return to after data byte
387 %endif ; DEBUG_TRACERS
390 ; This is a word to pc_setint16 can set it
391 DisplayCon dw 01h ; Console display enabled
393 ScrollAttribute db 07h ; Grey on white (normal text color)
397 NextCharJump resw 1 ; Routine to interpret next print char
399 CursorCol resb 1 ; Cursor column for message file
400 CursorRow resb 1 ; Cursor row for message file
402 VidCols resb 1 ; Columns on screen-1
403 VidRows resb 1 ; Rows on screen-1
405 ; Serial console stuff...
406 BaudDivisor resw 1 ; Baud rate divisor
408 FlowOutput resb 1 ; Outputs to assert for serial flow
409 FlowInput resb 1 ; Input bits for serial flow
410 FlowIgnore resb 1 ; Ignore input unless these bits set
412 TextAttribute resb 1 ; Text attribute for message file
413 DisplayMask resb 1 ; Display modes mask