*** boothead.s# Sun Jan 23 13:50:57 2005
--- boothead.s Mon Mar 14 04:44:05 2005
***************
*** 505,525 ****
  !	Read a character from the keyboard, or just look if there is one.
  !	A carriage return is changed into a linefeed for UNIX compatibility.
  .define _getchar, _peekchar
! _peekchar:
! 	movb	ah, #0x01	! Keyboard status
! 	int	0x16
! 	jnz	getc		! Keypress?
! 	mov	ax, #-1		! No key
! 	ret
! _getchar:
! 	xorb	ah, ah		! Read character from keyboard
! 	int	0x16
! getc:	cmpb	al, #0x0D	! Carriage return?
  	jnz	nocr
  	movb	al, #0x0A	! Change to linefeed
  nocr:	xorb	ah, ah		! ax = al
  	ret
  
  ! int putchar(int c);
  !	Write a character in teletype mode.  The putc and putk synonyms
  !	are for the kernel printk function that uses one of them.
--- 505,562 ----
  !	Read a character from the keyboard, or just look if there is one.
  !	A carriage return is changed into a linefeed for UNIX compatibility.
  .define _getchar, _peekchar
! !! SERIAL CONSOLE
! _peekchar:
! 	movb	al, rs_rxbuf	! If we have RX data in buffer,
! 	orb	al, al		! just return it.
! 	jnz	crlf
! 	mov	ax, #0x0300	! GET PORT STATUS
! 	mov	dx, #0		! Port 0
! 	int	0x14		! BIOS CALL SERIAL_IO
! 	testb	ah, #0x01	! Receive data ready?
! 	jnz	dorx
! 	mov	ax, #-1		! No RX data
! 	ret
! dorx:	mov	ax, #0x0200	! READ CHARACTER FROM PORT
! 	mov	dx, #0		! Port 0
! 	int	0x14		! BIOS CALL SERIAL_IO
! 	movb	rs_rxbuf, al	! Save RX data into buffer
! 	jmp	crlf
! _getchar:
! 	movb	al, rs_rxbuf
! 	orb	al, al		! RX buffer is empty?
! 	jz	getrx
! 	movb	rs_rxbuf, #0	! Clear RX buffer
! 	jmp	crlf
! getrx:	mov	ax, #0x0200	! READ CHARACTER FROM PORT
! 	mov	dx, #0		! Port 0
! 	int	0x14		! BIOS CALL SERIAL_IO
! 	testb	ah, #0x80	! Timeout?
! 	jnz	getrx
! 	orb	al, al		! Invalid data? (QEMU bug?)
! 	jz	getrx
! crlf:	cmpb	al, #0x0D	! Carriage return?
  	jnz	nocr
  	movb	al, #0x0A	! Change to linefeed
  nocr:	xorb	ah, ah		! ax = al
  	ret
  
+ !! VGA CONSOLE
+ !_peekchar:
+ !	movb	ah, #0x01	! Keyboard status
+ !	int	0x16
+ !	jnz	getc		! Keypress?
+ !	mov	ax, #-1		! No key
+ !	ret
+ !_getchar:
+ !	xorb	ah, ah		! Read character from keyboard
+ !	int	0x16
+ !getc:	cmpb	al, #0x0D	! Carriage return?
+ !	jnz	nocr
+ !	movb	al, #0x0A	! Change to linefeed
+ !nocr:	xorb	ah, ah		! ax = al
+ !	ret
+ 
  ! int putchar(int c);
  !	Write a character in teletype mode.  The putc and putk synonyms
  !	are for the kernel printk function that uses one of them.
***************
*** 537,545 ****
  	movb	al, #0x0D
  	call	putc		! putc('\r')
  	movb	al, #0x0A	! Restore the '\n' and print it
! putc:	movb	ah, #0x0E	! Print character in teletype mode
! 	mov	bx, #0x0001	! Page 0, foreground color
! 	int	0x10		! Call BIOS VIDEO_IO
  nulch:	ret
  
  ! void reset_video(unsigned mode);
--- 574,587 ----
  	movb	al, #0x0D
  	call	putc		! putc('\r')
  	movb	al, #0x0A	! Restore the '\n' and print it
! !! SERIAL CONSOLE
! putc:	movb	ah, #0x01	! Send one byte
! 	mov	dx, #0		! Port 0
! 	int	0x14		! Call BIOS SERIAL_IO
! !! VGA CONSOLE
! !putc:	movb	ah, #0x0E	! Print character in teletype mode
! !	mov	bx, #0x0001	! Page 0, foreground color
! !	int	0x10		! Call BIOS VIDEO_IO
  nulch:	ret
  
  ! void reset_video(unsigned mode);
***************
*** 1006,1011 ****
--- 1048,1056 ----
  	.data2	0xFFFF, UNSET
  	.data1	UNSET, 0x9A, 0x00, 0x00
  
+ rs_rxbuf:	! RSCONS: RX buffer for peekchar
+ 	.data1	0
+ 
  .bss
  	.comm	old_vid_mode, 2		! Video mode at startup
  	.comm	cur_vid_mode, 2		! Current video mode
