=================================================================== RCS file: /cvs/funnyos/dev/fcons/fcons.c,v retrieving revision 1.1.1.1 retrieving revision 1.5 diff -u -r1.1.1.1 -r1.5 --- funnyos/dev/fcons/fcons.c 2007/10/16 09:41:04 1.1.1.1 +++ funnyos/dev/fcons/fcons.c 2008/01/11 15:36:01 1.5 @@ -1,47 +1,54 @@ /* - * $Id: fcons.c,v 1.1.1.1 2007/10/16 08:41:04 init Exp $ + * $Id: fcons.c,v 1.5 2008/01/11 15:36:01 nbrk Exp $ */ #include #include #include #include +#include /* * funnyOS console. * 80x25, monochrome. */ -struct fcons_devdata fcons_dd[NFCONS]; - /* current console device */ -struct device *curcons; +struct fcons_dd *curcons; extern void (*putchar)(char); -int fcons_attach(struct device *); -void fcons_putchar(struct device *, char); -char fcons_getchar(struct device *); +int fcons_attach(struct device *, uint32_t loc, uint8_t flags); +void fcons_putchar(void *ddp, char); +char fcons_getchar(void *ddp); void fcons_dfltputchar(char); int fcons_devctl(struct device *, uint8_t, void *); +struct driver fcons_dr = { + sizeof(struct fcons_dd), + fcons_attach, + NULL, + NULL +}; + int -fcons_attach(struct device *self) +fcons_attach(struct device *self, uint32_t loc, uint8_t size) { - /* - * Attach fcons abstraction using parent's getc & putc. - */ - /* associate dev data */ - self->dv_devdata = &fcons_dd[self->dv_minor]; + struct fcons_dd *ddp = self->dv_devdata; - fcons_dd[self->dv_minor].currow = 0; - fcons_dd[self->dv_minor].curcol = 0; + /* link our parent's dv_aux (fcons_handle) to us */ + ddp->fd_fh = self->dv_parent->dv_aux; - /* make cureent console default */ - curcons = self; + ddp->fd_currow = 0; + ddp->fd_curcol = 0; - /* - * XXX Register system printf's , etc.. - */ + /* initialize iqueue */ +// ddp->fd_iqhead = SIMPLEQ_HEAD_INITIALIZER(ddp->fd_iqhead); + SIMPLEQ_INIT(ddp->head); + ddp->fd_iqlength = 0; + + /* make current console default */ + curcons = ddp; + /* override early putchar */ putchar = fcons_dfltputchar; @@ -52,33 +59,34 @@ void -fcons_putchar(struct device *devp, char ch) +fcons_putchar(void *ddp, char ch) { - struct consoleops *copsp; + struct fcons_dd *fdp = ddp; + struct fcons_handle *fhp = fdp->fd_fh; - copsp = devp->dv_parent->dv_devdata; - - if (fcons_dd[devp->dv_minor].curcol == (FCONS_WIDTH - 1)) { + /* if we reach screen width */ + if (fdp->fd_curcol == (FCONS_WIDTH - 1)) { /* CRLF */ - fcons_dd[devp->dv_minor].curcol = 0; - fcons_dd[devp->dv_minor].currow++; + fdp->fd_curcol = 0; + fdp->fd_currow++; /* XXX pass \n to lower level (not all devices work this way) */ - copsp->putc(devp->dv_parent, '\n'); + fhp->putc(fhp->fh_ownerdd, '\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; + /* if we reach the bottom of the screen */ + if (fdp->fd_currow == FCONS_HEIGHT) { + /* XXX tmp hack; should really follow clrscr */ + fdp->fd_currow = 0; } - copsp->putc(devp->dv_parent, ch); + fhp->putc(fhp->fh_ownerdd, ch); } char -fcons_getchar(struct device *devp) +fcons_getchar(void *ddp) { /* TODO */ return ' '; @@ -97,6 +105,42 @@ } +void +fcons_ienqueue(char ch) +{ + /* + * Enqueue character into the input data queue. + */ + struct fcons_dd *ddp; + struct fcons_char *curfc; + uint32_t i; + + /* XXX will use curcons devdata */ + ddp = curcons; + +#if 0 + if (ddp->fd_iqueue == NULL) { + /* first insertion */ + curfc = kmalloc(sizeof(struct fcons_char)); + + if(curfc == NULL) + panic("fcons_ienqueue: can't allocate memory for new element\n"); + } else { + curfc = ddp->fd_iqueue; + + /* locate last element */ + for(i = 0; i < ddp->fd_iqlength - 1; i++) + curfc = curfc->fc_next; + } +#endif + curfc = kmalloc(sizeof(struct fcons_char)); + if(curfc == NULL) + panic("fcons_ienqueue: can't allocate memory for new element\n"); + + SIMPLEQ_INSERT_TAIL(ddp->fd_iqhead, curfc, fc_next); +} + +#if 0 int fcons_devctl(struct device *devp, uint8_t ctl, void *data) { @@ -126,4 +170,5 @@ } } +#endif /* not 0 */