Annotation of funnyos/dev/fcons/fcons.c, Revision 1.1.1.1
1.1 init 1: /*
2: * $Id: fcons.c,v 1.1.1.1 2007/10/12 08:40:38 init Exp $
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: struct fcons_devdata fcons_dd[NFCONS];
15:
16: /* current console device */
17: struct device *curcons;
18:
19: extern void (*putchar)(char);
20:
21: int fcons_attach(struct device *);
22: void fcons_putchar(struct device *, char);
23: char fcons_getchar(struct device *);
24: void fcons_dfltputchar(char);
25: int fcons_devctl(struct device *, uint8_t, void *);
26:
27: int
28: fcons_attach(struct device *self)
29: {
30: /*
31: * Attach fcons abstraction using parent's getc & putc.
32: */
33: /* associate dev data */
34: self->dv_devdata = &fcons_dd[self->dv_minor];
35:
36: fcons_dd[self->dv_minor].currow = 0;
37: fcons_dd[self->dv_minor].curcol = 0;
38:
39: /* make cureent console default */
40: curcons = self;
41:
42: /*
43: * XXX Register system printf's , etc..
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
55: fcons_putchar(struct device *devp, char ch)
56: {
57: struct consoleops *copsp;
58:
59: copsp = devp->dv_parent->dv_devdata;
60:
61: if (fcons_dd[devp->dv_minor].curcol == (FCONS_WIDTH - 1)) {
62: /* CRLF */
63: fcons_dd[devp->dv_minor].curcol = 0;
64: fcons_dd[devp->dv_minor].currow++;
65:
66: /* XXX pass \n to lower level (not all devices work this way) */
67: copsp->putc(devp->dv_parent, '\n');
68: }
69: /* XXX do something if col == FCONS_HEIGHT; console buffer? */
70:
71: if (fcons_dd[devp->dv_minor].currow == FCONS_HEIGHT) {
72: /* tmp hack; should really follow clrscr */
73: fcons_dd[devp->dv_minor].currow = 0;
74: }
75:
76: copsp->putc(devp->dv_parent, ch);
77: }
78:
79:
80: char
81: fcons_getchar(struct device *devp)
82: {
83: /* TODO */
84: return ' ';
85: }
86:
87:
88: void
89: fcons_dfltputchar(char ch)
90: {
91: /*
92: * Put a character into default (current) console.
93: */
94: fcons_putchar(curcons, ch);
95:
96: return;
97: }
98:
99:
100: int
101: fcons_devctl(struct device *devp, uint8_t ctl, void *data)
102: {
103: /*
104: * Devctl support for fcons device.
105: */
106: switch(ctl) {
107: case DCFCONS_GETCURROW:
108: /* return cursor's row */
109: data = &fcons_dd[devp->dv_minor].currow;
110: return(0);
111: case DCFCONS_GETCURCOL:
112: /* return cursor's column */
113: data = &fcons_dd[devp->dv_minor].curcol;
114: return(0);
115: case DCFCONS_PUTCHAR:
116: /* put a character to the device */
117: fcons_putchar(devp, *(char*)data);
118: return(0);
119: case DCFCONS_GETCHAR:
120: /* get a character from the device */
121: /* TODO */
122: return(-1);
123: default:
124: /* unknown devctl */
125: return(-1);
126: }
127:
128: }
129:
CVSweb