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

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

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

CVSweb