1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: 18: 19: 20: 21: 22: 23: 24:
25: #include "screen.h"
26:
27: #include <sys/segment.h>
28: #include <device/videomode.h>
29: #include <tcode.h>
30:
31: EXPORT VideoInf Vinf;
32:
33: IMPORT FUNCP VideoFunc[];
34:
35: LOCAL CONST UB *OEMName = "T-Engine Video Device";
36:
37:
38: EXPORT UW Cmap[256] = {
39: 0x10ffffff, 0x1000009f, 0x1000ef00, 0x1000efef,
40: 0x10ff0000, 0x10ef00ff, 0x10dfdf00, 0x107f7f9f,
41: 0x10dfdfdf, 0x107f9fff, 0x10bfffaf, 0x10cfffff,
42: 0x10ff6f6f, 0x10ef8fff, 0x10efff9f, 0x10010101,
43: 0x10ffffcc, 0x10ffff66, 0x10ffff33, 0x10ffff00,
44: 0x10ffccff, 0x10ffcccc, 0x10ffcc99, 0x10ffcc66,
45: 0x10ffcc33, 0x10ffcc00, 0x10ff99cc, 0x10ff9999,
46: 0x10ff9966, 0x10ff9933, 0x10ff9900, 0x10ff66ff,
47: 0x10ff66cc, 0x10ff6699, 0x10ff6633, 0x10ff6600,
48: 0x10ff33ff, 0x10ff33cc, 0x10ff3399, 0x10ff3366,
49: 0x10ff3333, 0x10ff3300, 0x10ff00cc, 0x10ff0099,
50: 0x10ff0066, 0x10ff0033, 0x10ccff99, 0x10ccff66,
51: 0x10ccff33, 0x10ccff00, 0x10ccccff, 0x10cccc99,
52: 0x10cccc66, 0x10cccc33, 0x10cc99ff, 0x10cc99cc,
53: 0x10cc9999, 0x10cc9966, 0x10cc9933, 0x10cc9900,
54: 0x10cc66ff, 0x10cc66cc, 0x10cc6699, 0x10cc6666,
55: 0x10cc6633, 0x10cc6600, 0x10cc33ff, 0x10cc33cc,
56: 0x10cc3399, 0x10cc3366, 0x10cc3333, 0x10cc3300,
57: 0x10cc00ff, 0x10cc00cc, 0x10cc0099, 0x10cc0066,
58: 0x10cc0033, 0x10cc0000, 0x1099ffff, 0x1099ffcc,
59: 0x1099ff99, 0x1099ff66, 0x1099ff33, 0x1099ff00,
60: 0x1099ccff, 0x1099cccc, 0x1099cc99, 0x1099cc66,
61: 0x1099cc33, 0x1099cc00, 0x109999ff, 0x109999cc,
62: 0x10999999, 0x10999966, 0x10999933, 0x10999900,
63: 0x109966ff, 0x109966cc, 0x10996699, 0x10996666,
64: 0x10996633, 0x10996600, 0x109933ff, 0x109933cc,
65: 0x10993399, 0x10993366, 0x10993333, 0x10993300,
66: 0x109900ff, 0x109900cc, 0x10990099, 0x10990066,
67: 0x10990033, 0x10990000, 0x1066ffff, 0x1066ffcc,
68: 0x1066ff99, 0x1066ff66, 0x1066ff33, 0x1066ff00,
69: 0x1066ccff, 0x1066cccc, 0x1066cc99, 0x1066cc66,
70: 0x1066cc33, 0x1066cc00, 0x106699cc, 0x10669999,
71: 0x10669966, 0x10669933, 0x10669900, 0x106666ff,
72: 0x106666cc, 0x10666666, 0x10666633, 0x10666600,
73: 0x106633ff, 0x106633cc, 0x10663399, 0x10663366,
74: 0x10663333, 0x10663300, 0x106600ff, 0x106600cc,
75: 0x10660099, 0x10660066, 0x10660033, 0x10660000,
76: 0x1033ffff, 0x1033ffcc, 0x1033ff99, 0x1033ff66,
77: 0x1033ff33, 0x1033ff00, 0x1033ccff, 0x1033cccc,
78: 0x1033cc99, 0x1033cc66, 0x1033cc33, 0x1033cc00,
79: 0x103399ff, 0x103399cc, 0x10339999, 0x10339966,
80: 0x10339933, 0x10339900, 0x103366ff, 0x103366cc,
81: 0x10336699, 0x10336666, 0x10336633, 0x10336600,
82: 0x103333ff, 0x103333cc, 0x10333399, 0x10333366,
83: 0x10333333, 0x10333300, 0x103300ff, 0x103300cc,
84: 0x10330099, 0x10330066, 0x10330033, 0x10330000,
85: 0x1000ffcc, 0x1000ff99, 0x1000ff66, 0x1000ff33,
86: 0x1000ff00, 0x1000ccff, 0x1000cccc, 0x1000cc99,
87: 0x1000cc66, 0x1000cc33, 0x1000cc00, 0x100099ff,
88: 0x100099cc, 0x10009999, 0x10009966, 0x10009933,
89: 0x10009900, 0x100066ff, 0x100066cc, 0x10006699,
90: 0x10006666, 0x10006633, 0x10006600, 0x100033ff,
91: 0x100033cc, 0x10003399, 0x10003366, 0x10003333,
92: 0x10003300, 0x100000ff, 0x100000cc, 0x10000066,
93: 0x10000033, 0x10ee0000, 0x10dd0000, 0x10bb0000,
94: 0x10aa0000, 0x10880000, 0x10770000, 0x10550000,
95: 0x10440000, 0x10220000, 0x10110000, 0x1000dd00,
96: 0x1000bb00, 0x1000aa00, 0x10008800, 0x10007700,
97: 0x10005500, 0x10004400, 0x10002200, 0x10001100,
98: 0x100000ee, 0x100000dd, 0x100000bb, 0x100000aa,
99: 0x10000088, 0x10000077, 0x10000055, 0x10000044,
100: 0x10000022, 0x10eeeeee, 0x10cccccc, 0x10bbbbbb,
101: 0x10aaaaaa, 0x10888888, 0x10777777, 0x10555555,
102: 0x10444444, 0x10222222, 0x10111111, 0x10000000,
103: };
104:
105: 106: 107:
108: LOCAL W getMblkSz(W size)
109: {
110: T_RSMB msts;
111:
112: if (tk_ref_smb(&msts) < E_OK) return -1;
113: return (size - 1) / msts.blksz + 1;
114: }
115: 116: 117: 118: 119:
120: EXPORT ER getMemory(W size, void **ptr)
121: {
122: W nblk;
123: LOCAL UINT attr[] = {TA_RNG0, TA_RNG1, TA_RNG2, TA_RNG3};
124:
125: if ((nblk = getMblkSz(size)) > 0) {
126: if (tk_get_smb(ptr, nblk, attr[Vinf.vramrng]) >= E_OK)
127: return E_OK;
128: }
129: return E_NOMEM;
130: }
131: 132: 133:
134: EXPORT void* getPhyMemory(W size, void **phyaddr)
135: {
136: ER err;
137: UINT attr;
138: void* la;
139:
140:
141: attr = allowUserVRAM ? MM_USER : MM_SYSTEM;
142:
143: err = MapMemory(NULL, size,
144: attr | MM_READ | MM_WRITE | MM_CDIS, &la);
145:
146: return (err < E_OK ||
147: CnvPhysicalAddr(la, size, phyaddr) < size) ? NULL : la;
148: }
149: 150: 151:
152: EXPORT ER mapFrameBuf(void *paddr, W len, void **laddr)
153: {
154: UINT attr;
155:
156:
157: attr = allowUserVRAM ? MM_USER : MM_SYSTEM;
158:
159: return MapMemory(paddr, len,
160: attr | MM_READ | MM_WRITE | MM_CDIS, laddr);
161: }
162: 163: 164:
165: EXPORT ER initSCREEN(void)
166: {
167: W i, n;
168: W v[L_DEVCONF_VAL];
169:
170:
171: MEMSET(&Vinf, 0, sizeof(VideoInf));
172:
173:
174: Vinf.pciaddr = -1;
175:
176:
177: if (GetDevConf("VIDEOATTR", v) > 0 && v[0] > 0) {
178: Vinf.attr |= v[0] << 12;
179: }
180:
181:
182: n = 0;
183:
184:
185: v[2] = v[3] = 0;
186: if (GetDevConf("VIDEOMODE", v) > 0 && v[0] > 0) {
187: if (VALID_VIDEO_MODE(v[0] - 1)) n = v[0] - 1;
188: }
189:
190: Vinf.reqmode = n;
191:
192:
193: Vinf.rotate = 0;
194:
195:
196: if (GetDevConf("LCDPANELTYPE", v) > 0 && v[0] > 0) {
197: Vinf.paneltype = v[0];
198: }
199:
200:
201: if (GetDevConf("VIDEOPROT", v) > 0) {
202: Vinf.vramrng = v[0] & 3;
203: }
204:
205:
206: Vinf.banksize = 0;
207: Vinf.bankshift = 0;
208: Vinf.cmap = Cmap;
209: STRNCPY(Vinf.oemname, OEMName, L_OEMNAME);
210:
211: 212: 213: 214: 215: 216:
217:
218:
219: for (i = 0; VideoFunc[i] != NULL &&
220: (n = (*VideoFunc[i])()) == 0; i++);
221:
222: if (n < 0) return E_NOEXS;
223:
224:
225: Vinf.width = Vinf.fb_width = VideoHsize(Vinf.curmode);
226: Vinf.height = Vinf.fb_height = VideoVsize(Vinf.curmode);
227: Vinf.pixbits = VideoPixBits(Vinf.curmode);
228: Vinf.rowbytes = Vinf.framebuf_rowb;
229: Vinf.vramsz = Vinf.framebuf_rowb * Vinf.fb_height;
230: if (Vinf.framebuf_total > 0 &&
231: Vinf.vramsz > Vinf.framebuf_total) return E_OBJ;
232:
233:
234: Vinf.act_width = (v[2] >= 160 && v[2] < Vinf.width) ?
235: v[2] : Vinf.width;
236: Vinf.act_height = (v[3] >= 160 && v[3] < Vinf.height) ?
237: v[3] : Vinf.height;
238:
239:
240: if (GetDevConf("VIDEOVFREQ", v) > 0 && v[0] > 0) {
241: if ((Vinf.vfreq = v[0]) < MIN_VFREQ) Vinf.vfreq = MIN_VFREQ;
242: else if (Vinf.vfreq > MAX_VFREQ) Vinf.vfreq = MAX_VFREQ;
243: }
244:
245:
246: (*Vinf.fn_setmode)(1);
247:
248:
249: Vinf.baseaddr = Vinf.f_addr;
250:
251:
252: Vinf.cmapent = VideoCmapEnt(Vinf.curmode);
253: if (Vinf.cmapent > 0) {
254:
255: (*Vinf.fn_setcmap)(Vinf.cmap + 1, 1, Vinf.cmapent - 1);
256:
257: if (Vinf.v_addr == NULL) {
258: MEMSET(Vinf.baseaddr, 0xFF, Vinf.vramsz);
259: } else {
260:
261: (*Vinf.fn_updscr)(0, 0, Vinf.width, Vinf.height);
262: }
263:
264: (*Vinf.fn_setcmap)(Vinf.cmap, 0, 1);
265: }
266:
267: return E_OK;
268: }
269: 270: 271:
272: EXPORT ER finishSCREEN(void)
273: {
274:
275: return E_OK;
276: }
277: 278: 279:
280: EXPORT ER suspendSCREEN(void)
281: {
282: if (Vinf.attr & NEED_SUSRESPROC) (*Vinf.fn_susres)(TRUE);
283: return E_OK;
284: }
285: 286: 287:
288: EXPORT ER resumeSCREEN(void)
289: {
290: if (Vinf.attr & NEED_SUSRESPROC) (*Vinf.fn_susres)(FALSE);
291:
292: return E_OK;
293: }
294: 295: 296:
297: EXPORT ER getSCRXSPEC(DEV_SPEC *spec, W mode)
298: {
299: ER er;
300:
301: if (mode >= MAX_VIDEO_MODE || !(Vinf.modemap & (1 << mode))) {
302: er = E_NOSPT;
303: goto fin0;
304: }
305:
306: spec->planes = 1;
307: spec->pixbits = VideoPixBits(mode);
308: spec->hpixels = VideoHsize(mode);
309: spec->vpixels = VideoVsize(mode);
310: spec->hres = 0;
311: spec->vres = 0;
312: if (VideoCmapEnt(mode) > 0) {
313: spec->attr = DA_COLOR_RGB | DA_HAVECMAP | DA_HAVEBMP;
314: spec->color[0] = spec->color[1] = spec->color[2] = 8;
315: } else {
316: spec->attr = DA_COLOR_RGB | DA_HAVEBMP;
317: spec->color[0] = VideoRedInf(mode);
318: spec->color[1] = VideoGreenInf(mode);
319: spec->color[2] = VideoBlueInf(mode);
320: }
321: er = E_OK;
322:
323: fin0:
324: return er;
325: }
326: 327: 328:
329: EXPORT ER getSCRSPEC(DEV_SPEC *spec)
330: {
331: spec->planes = 1;
332: spec->pixbits = Vinf.pixbits;
333: spec->hpixels = Vinf.act_width;
334: spec->vpixels = Vinf.act_height;
335: spec->hres = 0;
336: spec->vres = 0;
337: if (Vinf.cmapent > 0) {
338: spec->attr = DA_COLOR_RGB | DA_HAVECMAP | DA_HAVEBMP;
339: spec->color[0] = spec->color[1] = spec->color[2] = 8;
340: } else {
341: spec->attr = DA_COLOR_RGB | DA_HAVEBMP;
342: spec->color[0] = VideoRedInf(Vinf.curmode);
343: spec->color[1] = VideoGreenInf(Vinf.curmode);
344: spec->color[2] = VideoBlueInf(Vinf.curmode);
345: }
346: return E_OK;
347: }
348: 349: 350:
351: EXPORT W setModeStr(W mode, TC *str, W pos, W x, W y, W bpp, TC *desc)
352: {
353: #define MODESTR_SIZE 16
354: #define TK_MULT 0x215f
355: #define putTC(x, y, z) (x)[(y)] = (z)
356:
357: W n;
358:
359:
360:
361:
362:
363:
364:
365:
366:
367: if (str == NULL) goto fin0;
368:
369:
370: str = &str[pos];
371: n = 0;
372:
373:
374: putTC(str, n++, mode + 1);
375:
376:
377: if (x >= 1000) putTC(str, n++, TK_0 + (x / 1000) % 10);
378: if (x >= 100) putTC(str, n++, TK_0 + (x / 100) % 10);
379: if (x >= 10) putTC(str, n++, TK_0 + (x / 10) % 10);
380: putTC(str, n++, TK_0 + x % 10);
381:
382: putTC(str, n++, TK_MULT);
383:
384:
385: if (y >= 1000) putTC(str, n++, TK_0 + (y / 1000) % 10);
386: if (y >= 100) putTC(str, n++, TK_0 + (y / 100) % 10);
387: if (y >= 10) putTC(str, n++, TK_0 + (y / 10) % 10);
388: putTC(str, n++, TK_0 + y % 10);
389:
390: putTC(str, n++, TK_COLN);
391:
392:
393: if (bpp == 4) {
394: putTC(str, n++, TK_1);
395: putTC(str, n++, TK_6);
396: putTC(str, n++, TK_C);
397: } else if (bpp == 8) {
398: putTC(str, n++, TK_2);
399: putTC(str, n++, TK_5);
400: putTC(str, n++, TK_6);
401: putTC(str, n++, TK_C);
402: } else if (bpp == 16) {
403: putTC(str, n++, TK_6);
404: putTC(str, n++, TK_4);
405: putTC(str, n++, TK_K);
406: putTC(str, n++, TK_C);
407: } else if (bpp == 24 || bpp == 32) {
408: putTC(str, n++, TK_1);
409: putTC(str, n++, TK_6);
410: putTC(str, n++, TK_M);
411: putTC(str, n++, TK_C);
412: }
413:
414:
415: if (desc != NULL) {
416: for (; n < MODESTR_SIZE && *desc != TC_NULL; n++, desc++) {
417: putTC(str, n, *desc);
418: }
419: }
420:
421:
422: for (; n < MODESTR_SIZE; n++) putTC(str, n, TK_KSP);
423: fin0:
424: return pos + MODESTR_SIZE;
425: }
426: 427: 428:
429: EXPORT INT getSCRLIST(TC *str)
430: {
431: W pos, m;
432:
433: pos = 0;
434:
435:
436: for(m = 0; m < MAX_VIDEO_MODE; m++) {
437: if(Vinf.modemap & (1 << m)) {
438: pos = setModeStr(m, str, pos,
439: VideoHsize(m), VideoVsize(m),
440: VideoPixBits(m) & 0xff, NULL);
441: }
442: }
443:
444: if (str != NULL) str[pos] = TNULL;
445: return (pos + 1) * sizeof(TC);
446: }
447: 448: 449:
450: EXPORT ER getsetSCRNO(W *scnum, BOOL suspend, BOOL set)
451: {
452: if (set) return E_NOSPT;
453: *scnum = Vinf.curmode + 1;
454: return E_OK;
455: }
456: 457: 458:
459: EXPORT INT getsetSCRCOLOR(COLOR *cmap, BOOL set)
460: {
461: if (Vinf.cmapent <= 0) return E_OBJ;
462:
463: if (cmap != NULL) {
464: if (set) {
465: MEMCPY(Vinf.cmap, cmap, Vinf.cmapent * sizeof(COLOR));
466: (*Vinf.fn_setcmap)(Vinf.cmap, 0, Vinf.cmapent);
467: } else {
468: MEMCPY(cmap, Vinf.cmap, Vinf.cmapent * sizeof(COLOR));
469: }
470: }
471: return Vinf.cmapent * sizeof(COLOR);
472: }
473: 474: 475:
476: EXPORT ER getSCRBMP(BMP *bmp)
477: {
478: bmp->planes = 1;
479: bmp->pixbits = Vinf.pixbits;
480: bmp->rowbytes = Vinf.rowbytes;
481: bmp->bounds.c.left = 0;
482: bmp->bounds.c.top = 0;
483: bmp->bounds.c.right = Vinf.act_width;
484: bmp->bounds.c.bottom = Vinf.act_height;
485: bmp->baseaddr[0] = Vinf.baseaddr;
486: return E_OK;
487: }
488: 489: 490:
491: EXPORT ER getsetSCRBRIGHT(W *brightness, BOOL set)
492: {
493: if (Vinf.fn_bright) return (*Vinf.fn_bright)(brightness, set);
494: return E_NOSPT;
495: }
496: 497: 498:
499: EXPORT ER getSCRUPDFN(FP *updfn)
500: {
501: *updfn = (FP)Vinf.fn_updscr;
502: return E_OK;
503: }
504: 505: 506:
507: EXPORT ER setSCRUPDRECT(RECT *rp)
508: {
509: if (! Vinf.fn_updscr) return E_NOSPT;
510: (*Vinf.fn_updscr)(rp->c.left, rp->c.top, rp->c.right - rp->c.left,
511: rp->c.bottom - rp->c.top);
512: return E_OK;
513: }
514: 515: 516:
517: EXPORT ER getsetSCRVFREQ(W *vfreq, BOOL set)
518: {
519: if ((Vinf.attr & SUPPORT_VFREQ) == 0) return E_NOSPT;
520:
521: if (set) {
522: if ((Vinf.vfreq = *vfreq) <= 0) Vinf.vfreq = 0;
523: else if (Vinf.vfreq < MIN_VFREQ) Vinf.vfreq = MIN_VFREQ;
524: else if (Vinf.vfreq > MAX_VFREQ) Vinf.vfreq = MAX_VFREQ;
525: (*Vinf.fn_setmode)(0);
526: } else {
527: *vfreq = Vinf.vfreq;
528: }
529: return E_OK;
530: }
531: 532: 533:
534: EXPORT ER getsetSCRADJUST(ScrAdjust *adj, BOOL set)
535: {
536:
537: return E_NOSPT;
538: }
539: 540: 541:
542: EXPORT ER getSCRDEVINFO(ScrDevInfo *inf)
543: {
544: MEMSET((void*)inf, 0, sizeof(ScrDevInfo));
545: MEMCPY(inf->name1, Vinf.oemname, L_OEMNAME);
546: MEMCPY(inf->name3, Vinf.chipinf, L_CHIPINF);
547:
548: inf->framebuf_addr = (Vinf.attr & BPP_24) ? NULL : Vinf.framebuf_addr;
549: inf->framebuf_size = Vinf.framebuf_total;
550: inf->mainmem_size = (Vinf.v_addr != NULL) ? Vinf.vramsz : 0;
551:
552: return E_OK;
553: }
554: 555: 556:
557: EXPORT ER setSCRWRITE(W kind, void *buf, W size)
558: {
559: if (Vinf.fn_write) return (*Vinf.fn_write)(kind, buf, size);
560: return E_NOSPT;
561: }