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

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

1.1       init        1: /*
1.3     ! init        2:  * $Id: fcons.c,v 1.2 2007/10/16 21:41:36 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>
                      8:
                      9: /*
                     10:  * funnyOS console.
                     11:  * 80x25, monochrome.
                     12:  */
                     13:
                     14: /* current console device */
1.2       init       15: struct fcons_dd *curcons;
1.1       init       16:
                     17: extern void (*putchar)(char);
                     18:
1.2       init       19: int    fcons_attach(struct device *, uint32_t loc, uint8_t flags);
                     20: void   fcons_putchar(void *ddp, char);
                     21: char   fcons_getchar(void *ddp);
1.1       init       22: void   fcons_dfltputchar(char);
                     23: int    fcons_devctl(struct device *, uint8_t, void *);
                     24:
1.2       init       25: struct driver fcons_dr = {
                     26:        sizeof(struct fcons_dd),
                     27:        fcons_attach,
                     28:        NULL
                     29: };
                     30:
1.1       init       31: int
1.2       init       32: fcons_attach(struct device *self, uint32_t loc, uint8_t size)
1.1       init       33: {
1.2       init       34:        struct fcons_dd *ddp = self->dv_devdata;
1.1       init       35:
1.3     ! init       36:        /* link our parent's dv_aux (fcons_handle) to us */
        !            37:        ddp->fd_fh = self->dv_parent->dv_aux;
        !            38:
1.2       init       39:        ddp->fd_currow = 0;
                     40:        ddp->fd_curcol = 0;
1.1       init       41:
1.2       init       42:        /* make current console default */
                     43:        curcons = ddp;
1.1       init       44:
                     45:        /* override early putchar */
                     46:        putchar = fcons_dfltputchar;
                     47:
                     48:        printf("system console (80x25, monochrome, no video buffer)\n");
                     49:
                     50:        return(0);
                     51: }
                     52:
                     53:
                     54: void
1.2       init       55: fcons_putchar(void *ddp, char ch)
1.1       init       56: {
1.2       init       57:        struct fcons_dd *fdp = ddp;
1.3     ! init       58:        struct fcons_handle *fhp = fdp->fd_fh;
1.1       init       59:
1.2       init       60:        /* if we reach screen width */
                     61:        if (fdp->fd_curcol == (FCONS_WIDTH - 1)) {
1.1       init       62:                /* CRLF */
1.2       init       63:                fdp->fd_curcol = 0;
                     64:                fdp->fd_currow++;
1.1       init       65:
                     66:                /* XXX pass \n to lower level (not all devices work this way) */
1.2       init       67:                fhp->putc(fhp->fh_ownerdd, '\n');
1.1       init       68:        }
                     69:        /* XXX do something if col == FCONS_HEIGHT; console buffer? */
                     70:
1.2       init       71:        /* if we reach the bottom of the screen */
                     72:        if (fdp->fd_currow == FCONS_HEIGHT) {
                     73:                /* XXX tmp hack; should really follow clrscr */
                     74:                fdp->fd_currow = 0;
1.1       init       75:        }
                     76:
1.2       init       77:        fhp->putc(fhp->fh_ownerdd, ch);
1.1       init       78: }
                     79:
                     80:
                     81: char
1.2       init       82: fcons_getchar(void *ddp)
1.1       init       83: {
                     84:        /* TODO */
                     85:        return ' ';
                     86: }
                     87:
                     88:
                     89: void
                     90: fcons_dfltputchar(char ch)
                     91: {
                     92:        /*
                     93:         * Put a character into default (current) console.
                     94:         */
                     95:        fcons_putchar(curcons, ch);
                     96:
                     97:        return;
                     98: }
                     99:
1.2       init      100: #if 0
1.1       init      101: int
                    102: fcons_devctl(struct device *devp, uint8_t ctl, void *data)
                    103: {
                    104:        /*
                    105:         * Devctl support for fcons device.
                    106:         */
                    107:        switch(ctl) {
                    108:                case DCFCONS_GETCURROW:
                    109:                        /* return cursor's row  */
                    110:                        data = &fcons_dd[devp->dv_minor].currow;
                    111:                        return(0);
                    112:                case DCFCONS_GETCURCOL:
                    113:                        /* return cursor's column */
                    114:                        data = &fcons_dd[devp->dv_minor].curcol;
                    115:                        return(0);
                    116:                case DCFCONS_PUTCHAR:
                    117:                        /* put a character to the device */
                    118:                        fcons_putchar(devp, *(char*)data);
                    119:                        return(0);
                    120:                case DCFCONS_GETCHAR:
                    121:                        /* get a character from the device */
                    122:                        /* TODO */
                    123:                        return(-1);
                    124:                default:
                    125:                        /* unknown devctl */
                    126:                        return(-1);
                    127:        }
                    128:
                    129: }
1.2       init      130: #endif /* not 0 */
1.1       init      131:

CVSweb