[BACK]Return to fcons.c CVS log [TXT][DIR] Up to [local] / funnyos / dev / fcons

File: [local] / funnyos / dev / fcons / fcons.c (download)

Revision 1.1, Tue Oct 16 08:41:04 2007 UTC (16 years, 7 months ago) by init
Branch: MAIN

Initial revision

/*
 * $Id: fcons.c,v 1.1 2007/10/16 08:41:04 init Exp $
 */
#include <sys/types.h>
#include <sys/device.h>
#include <dev/fcons/fconsvar.h>
#include <libkern/printf.h>

/*
 * funnyOS console.
 * 80x25, monochrome.
 */

struct fcons_devdata 	fcons_dd[NFCONS];

/* current console device */
struct device *curcons;

extern void (*putchar)(char);

int 	fcons_attach(struct device *);
void 	fcons_putchar(struct device *, char);
char 	fcons_getchar(struct device *);
void 	fcons_dfltputchar(char);
int 	fcons_devctl(struct device *, uint8_t, void *);

int
fcons_attach(struct device *self)
{
	/*
	 * Attach fcons abstraction using parent's getc & putc.
	 */
	/* associate dev data */
	self->dv_devdata = &fcons_dd[self->dv_minor];

	fcons_dd[self->dv_minor].currow = 0;
	fcons_dd[self->dv_minor].curcol = 0;

	/* make cureent console default */
	curcons = self;

	/*
	 * XXX Register system printf's , etc..
	 */
	/* override early putchar */
	putchar = fcons_dfltputchar;

	printf("system console (80x25, monochrome, no video buffer)\n");

	return(0);
}


void
fcons_putchar(struct device *devp, char ch)
{
	struct consoleops *copsp;

	copsp = devp->dv_parent->dv_devdata;

	if (fcons_dd[devp->dv_minor].curcol == (FCONS_WIDTH - 1)) {
		/* CRLF */
		fcons_dd[devp->dv_minor].curcol = 0;
		fcons_dd[devp->dv_minor].currow++;

		/* XXX pass \n to lower level (not all devices work this way) */
		copsp->putc(devp->dv_parent, '\n');
	}
	/* XXX do something if col == FCONS_HEIGHT; console buffer? */

	if (fcons_dd[devp->dv_minor].currow == FCONS_HEIGHT) {
		/* tmp hack; should really follow clrscr */
		fcons_dd[devp->dv_minor].currow = 0;
	}

	copsp->putc(devp->dv_parent, ch);
}


char
fcons_getchar(struct device *devp)
{
	/* TODO */
	return ' ';
}


void
fcons_dfltputchar(char ch)
{
	/*
	 * Put a character into default (current) console.
	 */
	fcons_putchar(curcons, ch);

	return;
}


int
fcons_devctl(struct device *devp, uint8_t ctl, void *data)
{
	/*
	 * Devctl support for fcons device.
	 */
	switch(ctl) {
		case DCFCONS_GETCURROW:
			/* return cursor's row  */
			data = &fcons_dd[devp->dv_minor].currow;
			return(0);
		case DCFCONS_GETCURCOL:
			/* return cursor's column */
			data = &fcons_dd[devp->dv_minor].curcol;
			return(0);
		case DCFCONS_PUTCHAR:
			/* put a character to the device */
			fcons_putchar(devp, *(char*)data);
			return(0);
		case DCFCONS_GETCHAR:
			/* get a character from the device */
			/* TODO */
			return(-1);
		default:
			/* unknown devctl */
			return(-1);
	}

}