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

Annotation of funnyos/dev/fcons/fcons.c, Revision 1.5

1.1       init        1: /*
1.5     ! nbrk        2:  * $Id: fcons.c,v 1.4 2007/10/29 21:10:02 init Exp $
1.1       init        3:  */
                      4: #include <sys/types.h>
                      5: #include <sys/device.h>
                      6: #include <dev/fcons/fconsvar.h>
                      7: #include <libkern/printf.h>
1.5     ! nbrk        8: #include <libkern/queue.h>
1.1       init        9:
                     10: /*
                     11:  * funnyOS console.
                     12:  * 80x25, monochrome.
                     13:  */
                     14:
                     15: /* current console device */
1.2       init       16: struct fcons_dd *curcons;
1.1       init       17:
                     18: extern void (*putchar)(char);
                     19:
1.2       init       20: int    fcons_attach(struct device *, uint32_t loc, uint8_t flags);
                     21: void   fcons_putchar(void *ddp, char);
                     22: char   fcons_getchar(void *ddp);
1.1       init       23: void   fcons_dfltputchar(char);
                     24: int    fcons_devctl(struct device *, uint8_t, void *);
                     25:
1.2       init       26: struct driver fcons_dr = {
                     27:        sizeof(struct fcons_dd),
                     28:        fcons_attach,
1.4       init       29:        NULL,
1.2       init       30:        NULL
                     31: };
                     32:
1.1       init       33: int
1.2       init       34: fcons_attach(struct device *self, uint32_t loc, uint8_t size)
1.1       init       35: {
1.2       init       36:        struct fcons_dd *ddp = self->dv_devdata;
1.1       init       37:
1.3       init       38:        /* link our parent's dv_aux (fcons_handle) to us */
                     39:        ddp->fd_fh = self->dv_parent->dv_aux;
                     40:
1.2       init       41:        ddp->fd_currow = 0;
                     42:        ddp->fd_curcol = 0;
1.1       init       43:
1.5     ! nbrk       44:        /* initialize iqueue */
        !            45: //     ddp->fd_iqhead = SIMPLEQ_HEAD_INITIALIZER(ddp->fd_iqhead);
        !            46:        SIMPLEQ_INIT(ddp->head);
        !            47:        ddp->fd_iqlength = 0;
        !            48:
1.2       init       49:        /* make current console default */
                     50:        curcons = ddp;
1.1       init       51:
                     52:        /* override early putchar */
                     53:        putchar = fcons_dfltputchar;
                     54:
                     55:        printf("system console (80x25, monochrome, no video buffer)\n");
                     56:
                     57:        return(0);
                     58: }
                     59:
                     60:
                     61: void
1.2       init       62: fcons_putchar(void *ddp, char ch)
1.1       init       63: {
1.2       init       64:        struct fcons_dd *fdp = ddp;
1.3       init       65:        struct fcons_handle *fhp = fdp->fd_fh;
1.1       init       66:
1.2       init       67:        /* if we reach screen width */
                     68:        if (fdp->fd_curcol == (FCONS_WIDTH - 1)) {
1.1       init       69:                /* CRLF */
1.2       init       70:                fdp->fd_curcol = 0;
                     71:                fdp->fd_currow++;
1.1       init       72:
                     73:                /* XXX pass \n to lower level (not all devices work this way) */
1.2       init       74:                fhp->putc(fhp->fh_ownerdd, '\n');
1.1       init       75:        }
                     76:        /* XXX do something if col == FCONS_HEIGHT; console buffer? */
                     77:
1.2       init       78:        /* if we reach the bottom of the screen */
                     79:        if (fdp->fd_currow == FCONS_HEIGHT) {
                     80:                /* XXX tmp hack; should really follow clrscr */
                     81:                fdp->fd_currow = 0;
1.1       init       82:        }
                     83:
1.2       init       84:        fhp->putc(fhp->fh_ownerdd, ch);
1.1       init       85: }
                     86:
                     87:
                     88: char
1.2       init       89: fcons_getchar(void *ddp)
1.1       init       90: {
                     91:        /* TODO */
                     92:        return ' ';
                     93: }
                     94:
                     95:
                     96: void
                     97: fcons_dfltputchar(char ch)
                     98: {
                     99:        /*
                    100:         * Put a character into default (current) console.
                    101:         */
                    102:        fcons_putchar(curcons, ch);
                    103:
                    104:        return;
1.5     ! nbrk      105: }
        !           106:
        !           107:
        !           108: void
        !           109: fcons_ienqueue(char ch)
        !           110: {
        !           111:        /*
        !           112:         * Enqueue character into the input data queue.
        !           113:         */
        !           114:        struct fcons_dd *ddp;
        !           115:        struct fcons_char *curfc;
        !           116:        uint32_t i;
        !           117:
        !           118:        /* XXX will use curcons devdata */
        !           119:        ddp = curcons;
        !           120:
        !           121: #if 0
        !           122:        if (ddp->fd_iqueue == NULL) {
        !           123:                /* first insertion */
        !           124:                curfc = kmalloc(sizeof(struct fcons_char));
        !           125:
        !           126:                if(curfc == NULL)
        !           127:                        panic("fcons_ienqueue: can't allocate memory for new element\n");
        !           128:        } else {
        !           129:                curfc = ddp->fd_iqueue;
        !           130:
        !           131:                /* locate last element */
        !           132:                for(i = 0; i < ddp->fd_iqlength - 1; i++)
        !           133:                        curfc = curfc->fc_next;
        !           134:        }
        !           135: #endif
        !           136:        curfc = kmalloc(sizeof(struct fcons_char));
        !           137:        if(curfc == NULL)
        !           138:                panic("fcons_ienqueue: can't allocate memory for new element\n");
        !           139:
        !           140:        SIMPLEQ_INSERT_TAIL(ddp->fd_iqhead, curfc, fc_next);
1.1       init      141: }
                    142:
1.2       init      143: #if 0
1.1       init      144: int
                    145: fcons_devctl(struct device *devp, uint8_t ctl, void *data)
                    146: {
                    147:        /*
                    148:         * Devctl support for fcons device.
                    149:         */
                    150:        switch(ctl) {
                    151:                case DCFCONS_GETCURROW:
                    152:                        /* return cursor's row  */
                    153:                        data = &fcons_dd[devp->dv_minor].currow;
                    154:                        return(0);
                    155:                case DCFCONS_GETCURCOL:
                    156:                        /* return cursor's column */
                    157:                        data = &fcons_dd[devp->dv_minor].curcol;
                    158:                        return(0);
                    159:                case DCFCONS_PUTCHAR:
                    160:                        /* put a character to the device */
                    161:                        fcons_putchar(devp, *(char*)data);
                    162:                        return(0);
                    163:                case DCFCONS_GETCHAR:
                    164:                        /* get a character from the device */
                    165:                        /* TODO */
                    166:                        return(-1);
                    167:                default:
                    168:                        /* unknown devctl */
                    169:                        return(-1);
                    170:        }
                    171:
                    172: }
1.2       init      173: #endif /* not 0 */
1.1       init      174:

CVSweb