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 ;; Bostom 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
27 and dx,dx ; Should be 256 bytes exactly
33 mov cx,1 ; 1 cluster should be >= 256 bytes
44 ; get_msg_file: Load a text file and write its contents to the screen,
45 ; interpreting color codes. Is called with SI and DX:AX
46 ; set by routine searchdir
50 shl edx,16 ; EDX <- DX:AX (length of file)
52 mov ax,xfer_buf_seg ; Use for temporary storage
55 mov byte [TextAttribute],07h ; Default grey on white
56 mov byte [DisplayMask],07h ; Display text in all modes
59 get_msg_chunk: push edx ; EDX = length of file
60 xor bx,bx ; == xbs_textbuf
64 push si ; Save current cluster
65 xor si,si ; == xbs_textbuf
66 mov cx,[BufSafeBytes] ; Number of bytes left in chunk
75 inc cl ; 01h = text mode, 02h = graphics
76 call [NextCharJump] ; Do what shall be done
84 jmp short get_msg_chunk
86 add sp,byte 6 ; Drop pushed EDX, CX
91 msg_putchar: ; Normal character
92 cmp al,0Fh ; ^O = color code follows
94 cmp al,0Dh ; Ignore <CR>
96 cmp al,0Ah ; <LF> = newline
98 cmp al,0Ch ; <FF> = clear screen
100 cmp al,19h ; <EM> = return to text mode
102 cmp al,18h ; <CAN> = VGA filename follows
105 cmp al,10h ; 10h to 17h are mode controls
109 msg_normal: call write_serial_displaymask ; Write to serial port
110 test [DisplayMask],cl
111 jz msg_ignore ; Not screen
112 mov bl,[TextAttribute]
114 mov ah,09h ; Write character/attribute
115 mov cx,1 ; One character only
116 int 10h ; Write to screen
120 ja msg_line_wrap ; Screen wraparound
123 msg_gotoxy: mov bh,[BIOS_page]
125 mov ah,02h ; Set cursor position
128 msg_ctrl_o: ; ^O = color code follows
129 mov word [NextCharJump],msg_setbg
131 msg_newline: ; Newline char or end of line
133 call write_serial_str_displaymask
134 msg_line_wrap: ; Screen wraparound
135 test [DisplayMask],cl
137 mov byte [CursorCol],0
144 msg_scroll: xor cx,cx ; Upper left hand corner
146 mov [CursorRow],dh ; New cursor at the bottom
147 mov bh,[ScrollAttribute]
148 mov ax,0601h ; Scroll up one line
151 msg_formfeed: ; Form feed character
153 call write_serial_str_displaymask
154 test [DisplayMask],cl
157 mov [CursorDX],cx ; Upper lefthand corner
159 mov bh,[TextAttribute]
160 mov ax,0600h ; Clear screen region
163 msg_setbg: ; Color background character
167 test [DisplayMask],cl
169 mov [TextAttribute],al
171 mov word [NextCharJump],msg_setfg
173 msg_setfg: ; Color foreground character
176 test [DisplayMask],cl
178 or [TextAttribute],al ; setbg set foreground to 0
180 jmp short msg_putcharnext
182 mov word [NextCharJump],msg_filename
184 jmp short msg_setvgafileptr
187 mov byte [TextAttribute],07h ; Default attribute
189 mov word [NextCharJump],msg_putchar
192 msg_filename: ; Getting VGA filename
193 cmp al,0Ah ; <LF> = end of filename
196 jbe msg_ret ; Ignore space/control char
200 mov [di],al ; Can't use stosb (DS:)
208 jmp short msg_initvars
221 jz msg_putcharnext ; Not there
225 ; Subroutine to initialize variables, also needed
226 ; after loading a graphics file
230 mov ah,03h ; Read cursor position
234 jmp short msg_putcharnext ; Initialize state machine
239 jmp short msg_putcharnext
242 ; write_serial: If serial output is enabled, write character on serial port
243 ; write_serial_displaymask: d:o, but ignore if DisplayMask & 04h == 0
245 write_serial_displaymask:
246 test byte [DisplayMask], 04h
257 ; Wait for space in transmit register
258 lea dx,[bx+5] ; DX -> LSR
263 ; Wait for input flow control
271 xchg dx,bx ; DX -> THR
273 call slow_out ; Send data
279 ; write_serial_str: write_serial for strings
280 ; write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
282 write_serial_str_displaymask:
283 test byte [DisplayMask], 04h
284 jz write_serial_str.end
295 ; pollchar: check if we have an input character pending (ZF = 0)
299 mov ah,1 ; Poll keyboard
301 jnz .done ; Keyboard response
304 jz .done ; No serial port -> no input
305 add dx,byte 5 ; DX -> LSR
307 test al,1 ; ZF = 0 if data pending
310 mov ah,[FlowIgnore] ; Required status bits
315 dec al ; Set ZF = 0 if equal
320 ; getchar: Read a character from keyboard or serial port
326 mov ah,1 ; Poll keyboard
328 jnz .kbd ; Keyboard input?
332 lea dx,[bx+5] ; DX -> LSR
342 .serial: xor ah,ah ; Avoid confusion
343 xchg dx,bx ; Data port
346 .kbd: xor ax,ax ; Get keyboard input
350 mov bx,KbdMap ; Convert character sets
356 ; debug hack to print a character with minimal code impact
361 mov bx,[bp+9*4] ; Get return address
362 mov al,[cs:bx] ; Get data byte
363 inc word [bp+9*4] ; Return to after data byte
368 %endif ; DEBUG_TRACERS