/*
 *  linux/drivers/char/console.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 */
/*
 *	console.c
 *
 * This module exports the console io functions:
 *
 *     'void do_keyboard_interrupt(void)'
 *
 *     'int vc_allocate(unsigned int console)'
 *     'int vc_cons_allocated(unsigned int console)'
 *     'int vc_resize(unsigned long lines, unsigned long cols)'
 *     'int vc_resize_con(unsigned long lines, unsigned long cols,
 *			  unsigned int currcons)'
 *     'void vc_disallocate(unsigned int currcons)'
 *
 *     'unsigned long con_init(unsigned long)'
 *     'int con_open(struct tty_struct *tty, struct file * filp)'
 *     'void con_write(struct tty_struct * tty)'
 *     'void console_print(const char * b)'
 *     'void update_screen(int new_console)'
 *
 *     'void do_blank_screen(int)'
 *     'void do_unblank_screen(void)'
 *     'void poke_blanked_console(void)'
 *
 *     'unsigned short *screen_pos(int currcons, int w_offset, int viewed)'
 *     'void complement_pos(int currcons, int offset)'
 *     'void invert_screen(int currcons, int offset, int count, int shift)'
 *
 *     'void scrollback(int lines)'
 *     'void scrollfront(int lines)'
 *
 *     'int con_get_font(char *)' 
 *     'int con_set_font(char *)'
 * 
 *     'void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry)'
 *     'int mouse_reporting(void)'
 *
 *     'unsigned long get_video_num_lines(unsigned int console)'
 *     'unsigned long get_video_num_columns(unsigned int console)'
 *     'unsigned long get_video_size_row(unsigned int console)'
 *
 * Hopefully this will be a rather complete VT102 implementation.
 *
 * Beeping thanks to John T Kohl.
 *
 * Virtual Consoles, Screen Blanking, Screen Dumping, Color, Graphics
 *   Chars, and VT100 enhancements by Peter MacDonald.
 *
 * Copy and paste function by Andrew Haylett,
 *   some enhancements by Alessandro Rubini.
 *
 * User definable mapping table and font loading by Eugene G. Crosser,
 * <crosser@pccross.msk.su>
 *
 * Code to check for different video-cards mostly by Galen Hunt,
 * <g-hunt@ee.utah.edu>
 *
 * Rudimentary ISO 10646/Unicode/UTF-8 character set support by
 * Markus Kuhn, <mskuhn@immd4.informatik.uni-erlangen.de>.
 *
 * Dynamic allocation of consoles, aeb@cwi.nl, May 1994
 * Resizing of consoles, aeb, 940926
 *
 * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94
 * <poe@daimi.aau.dk>
 *
 * 680x0 LINUX support by Arno Griffioen (arno@usn.nl)
 *
 * 9-Apr-94:  Arno Griffioen: fixed scrolling and delete-char bug.
 *            Scrolling code moved to amicon.c
 *
 * 18-Apr-94: David Carter [carter@cs.bris.ac.uk]. 680x0 LINUX modified 
 *            Integrated support for new low level driver `amicon_ocs.c'
 *
 */

#define BLANK 0x0020
#undef CAN_LOAD_EGA_FONTS    /* undefine if the user must not do this */

/* A bitmap for codes <32. A bit of 1 indicates that the code
 * corresponding to that bit number invokes some special action
 * (such as cursor movement) and should not be displayed as a
 * glyph unless the disp_ctrl mode is explicitly enabled.
 */
#define CTRL_ACTION 0x0d00ff81
#define CTRL_ALWAYS 0x0800f501	/* Cannot be overridden by disp_ctrl */

/*
 * Here is the default bell parameters: 750HZ, 1/8th of a second
 */
#define DEFAULT_BELL_PITCH	750
#define DEFAULT_BELL_DURATION	(HZ/8)

/*
 *  NOTE!!! We sometimes disable and enable interrupts for a short while
 * (to put a word in video IO), but this will work even for keyboard
 * interrupts. We know interrupts aren't enabled when getting a keyboard
 * interrupt, as we use trap-gates. Hopefully all is well.
 */

#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/console.h>
#include <linux/kd.h>
#include <linux/malloc.h>
#include <linux/major.h>
#include <linux/mm.h>
#include <linux/ioport.h>

#include <asm/io.h>
#include <asm/segment.h>
#include <asm/system.h>
#include <asm/bitops.h>

#include "../../../drivers/char/kbd_kern.h"
#include "../../../drivers/char/vt_kern.h"
#include "../../../drivers/char/consolemap.h"
#include "../../../drivers/char/selection.h"


#ifndef MIN
#define MIN(a,b)	((a) < (b) ? (a) : (b))
#endif

struct tty_driver console_driver;
static int console_refcount;
static struct tty_struct *console_table[MAX_NR_CONSOLES];
static struct termios *console_termios[MAX_NR_CONSOLES];
static struct termios *console_termios_locked[MAX_NR_CONSOLES];

static void vc_init(unsigned int console, int do_clear);

static void update_attr(int currcons);
static void gotoxy(int currcons, int new_x, int new_y);
static void save_cur(int currcons);
static void blank_screen(void);
static void unblank_screen(void);
extern void change_console(unsigned int);
static inline void set_cursor(int currcons);
static void reset_terminal(int currcons, int do_clear);
extern void reset_vc(unsigned int new_console);
extern void vt_init(void);
extern void register_console(void (*proc)(const char *));
extern void vesa_blank(void);
extern void vesa_unblank(void);
extern void compute_shiftstate(void);
void poke_blanked_console(void);
void do_blank_screen(int);

unsigned long	video_num_lines;
unsigned long	video_num_columns;
unsigned long	video_size_row;

static int printable = 0;			/* Is console ready for printing? */
unsigned long video_font_height;	/* Height of current screen font */
unsigned long video_scan_lines;		/* Number of scan lines on screen */
unsigned long default_font_height;      /* Height of default screen font */
int	      video_mode_512ch = 0;	/* 512-character mode */
static unsigned short console_charmask = 0x0ff;

static unsigned short *vc_scrbuf[MAX_NR_CONSOLES];

/* used by kbd_bh - set by keyboard_interrupt */
       int do_poke_blanked_console = 0;
       int console_blanked = 0;
static int blankinterval = 10*60*HZ;

static struct vc {
	struct vc_data *d;

	/* might add  scrmem, vt_struct, kbd  at some time,
	   to have everything in one place - the disadvantage
	   would be that vc_cons etc can no longer be static */
} vc_cons [MAX_NR_CONSOLES];
struct consw *conswitchp;

#define cols            (vc_cons[currcons].d->vc_cols)
#define rows            (vc_cons[currcons].d->vc_rows)
#define size_row        (vc_cons[currcons].d->vc_size_row)
#define screenbuf_size	(vc_cons[currcons].d->vc_screenbuf_size)
#define cons_num	(vc_cons[currcons].d->vc_num)
#define origin		(vc_cons[currcons].d->vc_origin)
#define scr_end		(vc_cons[currcons].d->vc_scr_end)
#define pos		(vc_cons[currcons].d->vc_pos)
#define top		(vc_cons[currcons].d->vc_top)
#define bottom		(vc_cons[currcons].d->vc_bottom)
#define x		(vc_cons[currcons].d->vc_x)
#define y		(vc_cons[currcons].d->vc_y)
#define vc_state	(vc_cons[currcons].d->vc_state)
#define npar		(vc_cons[currcons].d->vc_npar)
#define par		(vc_cons[currcons].d->vc_par)
#define ques		(vc_cons[currcons].d->vc_ques)
#define attr		(vc_cons[currcons].d->vc_attr)
#define saved_x		(vc_cons[currcons].d->vc_saved_x)
#define saved_y		(vc_cons[currcons].d->vc_saved_y)
#define translate	(vc_cons[currcons].d->vc_translate)
#define G0_charset	(vc_cons[currcons].d->vc_G0_charset)
#define G1_charset	(vc_cons[currcons].d->vc_G1_charset)
#define saved_G0	(vc_cons[currcons].d->vc_saved_G0)
#define saved_G1	(vc_cons[currcons].d->vc_saved_G1)
#define utf		(vc_cons[currcons].d->vc_utf)
#define utf_count	(vc_cons[currcons].d->vc_utf_count)
#define utf_char	(vc_cons[currcons].d->vc_utf_char)
#define video_mem_start	(vc_cons[currcons].d->vc_video_mem_start)
#define video_mem_end	(vc_cons[currcons].d->vc_video_mem_end)
#define video_erase_char (vc_cons[currcons].d->vc_video_erase_char)	
#define disp_ctrl	(vc_cons[currcons].d->vc_disp_ctrl)
#define toggle_meta	(vc_cons[currcons].d->vc_toggle_meta)
#define decscnm		(vc_cons[currcons].d->vc_decscnm)
#define decom		(vc_cons[currcons].d->vc_decom)
#define decawm		(vc_cons[currcons].d->vc_decawm)
#define deccm		(vc_cons[currcons].d->vc_deccm)
#define decim		(vc_cons[currcons].d->vc_decim)
#define deccolm	 	(vc_cons[currcons].d->vc_deccolm)
#define need_wrap	(vc_cons[currcons].d->vc_need_wrap)
#define has_scrolled	(vc_cons[currcons].d->vc_has_scrolled)
#define kmalloced	(vc_cons[currcons].d->vc_kmalloced)
#define report_mouse	(vc_cons[currcons].d->vc_report_mouse)
#define can_do_color	(vc_cons[currcons].d->vc_can_do_color)
#define color		(vc_cons[currcons].d->vc_color)
#define s_color		(vc_cons[currcons].d->vc_s_color)
#define def_color	(vc_cons[currcons].d->vc_def_color)
#define	foreground	(color & 0x0f)
#define background	(color & 0xf0)
#define charset		(vc_cons[currcons].d->vc_charset)
#define s_charset	(vc_cons[currcons].d->vc_s_charset)
#define	intensity	(vc_cons[currcons].d->vc_intensity)
#define	underline	(vc_cons[currcons].d->vc_underline)
#define	blink		(vc_cons[currcons].d->vc_blink)
#define	reverse		(vc_cons[currcons].d->vc_reverse)
#define	s_intensity	(vc_cons[currcons].d->vc_s_intensity)
#define	s_underline	(vc_cons[currcons].d->vc_s_underline)
#define	s_blink		(vc_cons[currcons].d->vc_s_blink)
#define	s_reverse	(vc_cons[currcons].d->vc_s_reverse)
#define	ulcolor		(vc_cons[currcons].d->vc_ulcolor)
#define	halfcolor	(vc_cons[currcons].d->vc_halfcolor)
#define tab_stop	(vc_cons[currcons].d->vc_tab_stop)
#define bell_pitch	(vc_cons[currcons].d->vc_bell_pitch)
#define bell_duration	(vc_cons[currcons].d->vc_bell_duration)
#define sw		(vc_cons[currcons].d->vc_sw)

#define vcmode		(vt_cons[currcons]->vc_mode)
#if 0 /* XXX */
#define	vtmode		(vt_cons[currcons]->vt_mode)
#define	vtpid		(vt_cons[currcons]->vt_pid)
#define	vtnewvt		(vt_cons[currcons]->vt_newvt)
#endif

#define structsize	(sizeof(struct vc_data) + sizeof(struct vt_struct))

int vc_cons_allocated(unsigned int i)
{
  return 0;
}

int vc_allocate(unsigned int currcons)		/* return 0 on success */
{
  return 0;
}

/*
 * Change # of rows and columns (0 means the size of fg_console)
 * [this is to be used together with some user program
 * like resize that changes the hardware videomode]
 */
int vc_resize(unsigned long lines, unsigned long columns)
{
  return 0;
}

/*
 * ++Geert: Change # of rows and columns for one specific console.
 * Of course it's not messy to have all consoles of potentially different sizes,
 * except on PCish hardware :-)
 *
 * This is called by the low level console driver (arch/m68k/console/fbcon.c or
 * arch/m68k/console/txtcon.c)
 */
void vc_resize_con(unsigned long lines, unsigned long columns,
		   unsigned int currcons)
{
}

void vc_disallocate(unsigned int currcons)
{
}


#define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x)
#define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x)
#define is_kbd(x) vc_kbd_mode(kbd_table+currcons,x)

#define decarm		VC_REPEAT
#define decckm		VC_CKMODE
#define kbdapplic	VC_APPLIC
#define lnm		VC_CRLF

/*
 * this is what the terminal answers to a ESC-Z or csi0c query.
 */
#define VT100ID "\033[?1;2c"
#define VT102ID "\033[?6c"

static unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
				       8,12,10,14, 9,13,11,15 };

/*
 * gotoxy() must verify all boundaries, because the arguments
 * might also be negative. If the given position is out of
 * bounds, the cursor is placed at the nearest margin.
 */
static void gotoxy(int currcons, int new_x, int new_y)
{
}

static void hide_cursor(int currcons)
{
}

static void set_cursor(int currcons)
{
}

void no_scroll(char *str, int *ints)
{
  /*
   * no_scroll currently does nothing on the m68k.
   */
}

/*
 * Arno:
 * Why do we need these? The keyboard code doesn't seem to do anything
 * with them either...
 */
void scrollfront(int l)
{
	return;
}

void scrollback(int l)
{
	return;
}

static void scrup(int currcons, unsigned int t, unsigned int b,
		  int nr)
{
}

static void scrdown(int currcons, unsigned int t, unsigned int b,
		    int nr)
{
}

static void lf(int currcons)
{
}

static void ri(int currcons)
{
}

static inline void cr(int currcons)
{
}

static inline void bs(int currcons)
{
}

static inline void del(int currcons)
{
	/* ignored */
}

static void csi_J(int currcons, int vpar)
{
}

static void csi_K(int currcons, int vpar)
{
}

static void csi_X(int currcons, int vpar) /* erase the following vpar positions */
{					  /* not vt100? */
}

/*
 * Arno: 
 * On 680x0 attributes are currently not used. This piece of code
 * seems hardware independent, but uses the EGA/VGA way of representing
 * attributes. 
 * TODO: modify for 680x0 and add attribute processing to putc code.
 *
 * ++roman: I completely changed the attribute format for monochrome
 * mode (!can_do_color). The formerly used MDA (monochrome display
 * adapter) format didn't allow the combination of certain effects.
 * Now the attribute is just a bit vector:
 *  Bit 0..1: intensity (0..2)
 *  Bit 2   : underline
 *  Bit 3   : reverse
 *  Bit 7   : blink
 */
static void update_attr(int currcons)
{
}

static void default_attr(int currcons)
{
}

static void csi_m(int currcons)
{
}

static void respond_string(const char * p, struct tty_struct * tty)
{
}

static void cursor_report(int currcons, struct tty_struct * tty)
{
}

static inline void status_report(struct tty_struct * tty)
{
}

static inline void respond_ID(struct tty_struct * tty)
{
}

void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry)
{
}

/* invoked via ioctl(TIOCLINUX) */
int mouse_reporting(void)
{
  return 0;
}

static inline unsigned short *screenpos(int currcons, int offset, int viewed)
{
}

/* Note: inverting the screen twice should revert to the original state */
void invert_screen(int currcons, int offset, int count, int viewed)
{
}

/* used by selection: complement pointer position */
void complement_pos(int currcons, int offset)
{
}

/* used by selection */
unsigned short screen_word(int currcons, int offset, int viewed)
{
  return 0;
}

/* used by selection - convert a screen word to a glyph number */
int scrw2glyph(unsigned short scr_word)
{
  return 0;
}

/* used by vcs - note the word offset */
unsigned short *screen_pos(int currcons, int w_offset, int viewed)
{
  return 0;
}

void getconsxy(int currcons, char *p)
{
}

void putconsxy(int currcons, char *p)
{
}

static void set_mode(int currcons, int on_off)
{
}

static void insert_char(int currcons)
{
}

static void csi_at(int currcons, unsigned int nr)
{
}

static void csi_L(int currcons, unsigned int nr)
{
}

static void csi_P(int currcons, unsigned int nr)
{
}

static void csi_M(int currcons, unsigned int nr)
{
}

static void save_cur(int currcons)
{
}

static void restore_cur(int currcons)
{
}

enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey, 
	EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,
	ESpalette };

static void reset_terminal(int currcons, int do_clear)
{
}

/*
 * Turn the Scroll-Lock LED on when the tty is stopped
 */
static void con_stop(struct tty_struct *tty)
{
}

/*
 * Turn the Scroll-Lock LED off when the console is started
 */
static void con_start(struct tty_struct *tty)
{
}

static int con_write(struct tty_struct * tty, int from_user,
		     const unsigned char *buf, int count)
{
  return 0;
}

static int con_write_room(struct tty_struct *tty)
{
  return 0;
}

static int con_chars_in_buffer(struct tty_struct *tty)
{
  return 0;		/* we're not buffering */
}

void poke_blanked_console(void)
{
}

/* DPC: New version of console_print using putcs */

void console_print(const char * b)
{
}


/*
 * con_throttle and con_unthrottle are only used for
 * paste_selection(), which has to stuff in a large number of
 * characters...
 */
static void con_throttle(struct tty_struct *tty)
{
}

static void con_unthrottle(struct tty_struct *tty)
{
}

static void vc_init(unsigned int currcons, int do_clear)
{
}

/*
 * This is the console switching bottom half handler.
 *
 * Doing console switching in a bottom half handler allows
 * us to do the switches asynchronously (needed when we want
 * to switch due to a keyboard interrupt), while still giving
 * us the option to easily disable it to avoid races when we
 * need to write to the console.
 */
static void console_bh(void)
{
}

/*
 *  unsigned long con_init(unsigned long);
 *
 * This routine initializes console interrupts, and does nothing
 * else. If you want the screen to clear, call tty_write with
 * the appropriate escape-sequence.
 *
 * Reads the information preserved by setup.s to determine the current display
 * type and sets everything accordingly.
 */
unsigned long con_init(unsigned long kmem_start)
{
  return 0;
}

void do_blank_screen(int nopowersave)
{
}

void do_unblank_screen(void)
{
}

void update_screen(int new_console)
{
}

/*
 * If a blank_screen is due to a timer, then a power save is allowed.
 * If it is related to console_switching, then avoid vesa_blank().
 */
static void blank_screen(void)
{
}

static void unblank_screen(void)
{
}

/*
 * Allocate the console screen memory.
 */
int con_open(struct tty_struct *tty, struct file * filp)
{
  return 0;
}

/*
 * PIO_FONT support.
 *
 * The font loading code goes back to the codepage package by
 * Joel Hoffman (joel@wam.umd.edu). (He reports that the original
 * reference is: "From: p. 307 of _Programmer's Guide to PC & PS/2
 * Video Systems_ by Richard Wilton. 1987.  Microsoft Press".)
 *
 * Change for certain monochrome monitors by Yury Shevchuck
 * (sizif@botik.yaroslavl.su).
 */

#define colourmap ((char *)0xa0000)
/* Pauline Middelink <middelin@polyware.iaf.nl> reports that we
   should use 0xA0000 for the bwmap as well.. */
#define blackwmap ((char *)0xa0000)
#define cmapsz 8192
#define seq_port_reg (0x3c4)
#define seq_port_val (0x3c5)
#define gr_port_reg (0x3ce)
#define gr_port_val (0x3cf)

static int set_get_font(char * arg, int set)
{
  return 0;
}

/*
 * Load palette into the EGA/VGA DAC registers. arg points to a colour
 * map, 3 bytes per colour, 16 colours, range from 0 to 255.
 */

int con_set_cmap (unsigned char *arg)
{
  return 0;
}

int con_get_cmap (unsigned char *arg)
{
  return 0;
}

void reset_palette(int currcons)
{
}

void set_palette(void)
{
}

/*
 * Load font into the EGA/VGA character generator. arg points to a 8192
 * byte map, 32 bytes per character. Only first H of them are used for
 * 8xH fonts (0 < H <= 32).
 */

int con_set_font (char *arg)
{
  return 0;
}

int con_get_font (char *arg)
{
  return 0;
}

/*
 * Adjust the screen to fit a font of a certain height
 *
 * Returns < 0 for error, 0 if nothing changed, and the number
 * of lines on the adjusted console if changed.
 */
int con_adjust_height(unsigned long fontheight)
{
  return 0;
}

void set_vesa_blanking(int arg)
{
}

unsigned long get_video_num_lines(unsigned int currcons)
{
  return 0;
}

unsigned long get_video_num_columns(unsigned int currcons)
{
  return 0;
}

unsigned long get_video_size_row(unsigned int currcons)
{
  return 0;
}
