1 // EmuScan routines for Pico, also simple text and shape drawing routines.
\r
3 // (c) Copyright 2006, notaz
\r
4 // All Rights Reserved
\r
7 #include "../Engine.h"
\r
8 #include "../../../pico/picoInt.h"
\r
14 extern TPicoConfig *currentConfig;
\r
15 extern TPicoAreaConfigEntry areaConfig[];
\r
16 extern const char *actionNames[];
\r
19 static void *screenbuff = 0; // pointer to real device video memory
\r
21 extern "C" { unsigned char *framebuff = 0; } // temporary buffer
\r
22 const int framebuffsize = (8+320)*(8+240+8)*2+8*2; // actual framebuffer size (in bytes+to support new rendering mode)
\r
24 // drawer function pointers
\r
25 static void (*drawTextFps)(const char *text) = 0;
\r
26 static void (*drawTextNotice)(const char *text) = 0;
\r
29 static void (*vidBlit)(int full) = 0;
\r
32 const unsigned short color_red = 0x022F;
\r
33 const unsigned short color_red_dim = 0x0004;
\r
34 const unsigned short color_green = 0x01F1;
\r
35 const unsigned short color_blue = 0x0F11;
\r
36 const unsigned short color_grey = 0x0222;
\r
39 int txtheight_fit = 138;
\r
42 static const unsigned long mask_numbers[] = {
\r
43 0x12244800, // 47 2F /
\r
44 0x69999600, // 48 30 0
\r
45 0x26222200, // 49 31 1
\r
46 0x69168F00, // 50 32 2
\r
47 0x69219600, // 51 33 3
\r
48 0x266AF200, // 52 34 4
\r
49 0xF8E11E00, // 53 35 5
\r
50 0x68E99600, // 54 36 6
\r
51 0x71222200, // 55 37 7
\r
52 0x69699600, // 56 38 8
\r
53 0x69719600, // 57 39 9
\r
54 0x04004000, // 58 3A :
\r
55 0x04004400, // 59 3B ;
\r
56 0x01242100, // 60 3C <
\r
57 0x00707000, // 61 3D =
\r
58 0x04212400, // 62 3E >
\r
59 0x69240400, // 63 3F ?
\r
60 0x00000000, // 64 40 @ [used instead of space for now]
\r
61 0x22579900, // 65 41 A
\r
62 0xE9E99E00, // 66 42 B
\r
63 0x69889600, // 67 43 C
\r
64 0xE9999E00, // 68 44 D
\r
65 0xF8E88F00, // 69 45 E
\r
66 0xF8E88800, // 70 46 F
\r
67 0x698B9700, // 71 47 G
\r
68 0x99F99900, // 72 48 H
\r
69 0x44444400, // 73 49 I
\r
70 0x11119600, // 74 4A J
\r
71 0x9ACCA900, // 75 4B K
\r
72 0x88888F00, // 76 4C L
\r
73 0x9F999900, // 77 4D M
\r
74 0x9DDBB900, // 78 4E N
\r
75 0x69999600, // 79 4F O
\r
76 0xE99E8800, // 80 50 P
\r
77 0x6999A500, // 81 51 Q
\r
78 0xE99E9900, // 82 52 R
\r
79 0x69429600, // 83 53 S
\r
80 0x72222200, // 84 54 T
\r
81 0x99999600, // 85 55 U
\r
82 0x55552200, // 86 56 V
\r
83 0x9999F900, // 87 57 W
\r
84 0x55225500, // 88 58 X
\r
85 0x55222200, // 89 59 Y
\r
86 0xF1248F00, // 90 5A Z
\r
90 ////////////////////////////////
\r
93 static int EmuCramNull(int cram)
\r
95 User::Panic(_L("Cram called!!"), 0);
\r
100 ////////////////////////////////
\r
101 // PicoScan functions
\r
103 static int EmuScan8(unsigned int num, void *sdata)
\r
105 DrawLineDest = framebuff + 328*(num+1) + 328*8 + 8;
\r
111 static int EmuScanFit0(unsigned int num, void *sdata)
\r
115 static int u = 0, num2 = 0;
\r
116 if(!num) u = num2 = 0;
\r
118 DrawLineDest = framebuff + 328*(++num2) + 328*8 + 8;
\r
133 ////////////////////////////////
\r
135 // warning: text must be at least 1px away from screen borders
\r
137 static void drawTextM2(int x, int y, const char *text)
\r
139 unsigned char *vidmem = framebuff + 328*8 + 8;
\r
140 int charmask, i, cx = x, cy;
\r
141 unsigned char *l, *le;
\r
143 // darken the background (left border)
\r
144 for(l=vidmem+(cx-1)+(y-1)*328, le=l+8*328; l < le; l+=328) *l = 0xE0;
\r
146 for(const char *p=text; *p; p++) {
\r
148 charmask = *(mask_numbers + (*p - 0x2F));
\r
150 for(l = vidmem+cx+(y-1)*328, le = l+8*328; l < le; l+=328-4) {
\r
151 *l = 0xE0; l++; *l = 0xE0; l++;
\r
152 *l = 0xE0; l++; *l = 0xE0; l++;
\r
156 for(i=0; i < 24; i++) {
\r
157 if(charmask&0x80000000) *( vidmem + (cx+(i&3)) + (cy+(i>>2))*328 ) = 0xf0;
\r
165 static void drawTextM2Fat(int x, int y, const char *text)
\r
167 unsigned char *vidmem = framebuff + 328*8 + 8;
\r
168 int charmask, i, cx = x&~1, cy;
\r
169 unsigned short *l, *le;
\r
171 // darken the background (left border)
\r
172 for(l=(unsigned short *)(vidmem+(cx-2)+(y-1)*328), le=l+8*328/2; l < le; l+=328/2) *l = 0xE0;
\r
174 for(const char *p=text; *p; p++) {
\r
176 for(l = (unsigned short *)(vidmem+cx+(y-1)*328), le = l+8*328/2; l < le; l+=328/2) {
\r
178 *l-- = 0xe0e0; *l-- = 0xe0e0; *l-- = 0xe0e0; *l-- = 0xe0e0; *l = 0xe0e0;
\r
181 charmask = *(mask_numbers + (*p - 0x2F));
\r
183 for(i=0; i < 24; i++) {
\r
184 if(charmask&0x80000000) *(unsigned short *)( vidmem + cx+(i&3)*2 + (cy+(i>>2))*328 ) = 0xf0f0;
\r
192 static void drawTextFpsCenter0(const char *text)
\r
195 drawTextM2(214, 216, text);
\r
198 static void drawTextFpsFit0(const char *text)
\r
201 drawTextM2Fat((Pico.video.reg[12]&1) ? 256-32 : 224-32, 160, text);
\r
204 static void drawTextFpsFit2_0(const char *text)
\r
207 drawTextM2Fat((Pico.video.reg[12]&1) ? 256-32 : 224-32, 216, text);
\r
210 static void drawTextFps0(const char *text)
\r
213 drawTextM2((Pico.video.reg[12]&1) ? 256 : 224, 216, text);
\r
216 static void drawTextNoticeCenter0(const char *text)
\r
219 drawTextM2(2, 216, text);
\r
222 static void drawTextNoticeFit0(const char *text)
\r
225 drawTextM2Fat(2, 160, text);
\r
228 static void drawTextNoticeFit2_0(const char *text)
\r
231 drawTextM2Fat(2, 216, text);
\r
234 static void drawTextNotice0(const char *text)
\r
237 drawTextM2(2, 216, text);
\r
241 // -----------------------------------------------------------------
\r
243 static int localPal[0x100];
\r
245 static void fillLocalPal(void)
\r
247 Pico.m.dirtyPal = 0;
\r
249 if (PicoOpt&0x10) {
\r
250 // 8bit fast renderer
\r
251 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
255 // 8bit accurate renderer
\r
256 if(Pico.video.reg[0xC]&8) { // shadow/hilight mode
\r
257 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
258 vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);
\r
259 vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);
\r
260 blockcpy(localPal+0xc0, localPal+0x40, 0x40*4);
\r
261 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
262 localPal[0xf0] = 0x00ee0000;
\r
263 } else if (rendstatus & 0x20) { // mid-frame palette changes
\r
264 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
265 vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);
\r
266 vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);
\r
268 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
273 // note: the internal 8 pixel border is taken care by asm code
\r
274 static void vidBlit_90(int full)
\r
276 unsigned char *ps = framebuff+328*8;
\r
277 unsigned long *pd = (unsigned long *) screenbuff;
\r
279 if (Pico.m.dirtyPal) fillLocalPal();
\r
281 if(Pico.video.reg[12]&1)
\r
282 vidConvCpy_90(pd, ps, localPal, 320/8);
\r
284 if(full) vidClear(pd, 32);
\r
286 vidConvCpy_90(pd, ps, localPal, 256/8);
\r
287 if(full) vidClear(pd + 256*256, 32);
\r
292 static void vidBlit_270(int full)
\r
294 unsigned char *ps = framebuff+328*8;
\r
295 unsigned long *pd = (unsigned long *) screenbuff;
\r
297 if (Pico.m.dirtyPal) fillLocalPal();
\r
299 if(Pico.video.reg[12]&1)
\r
300 vidConvCpy_270(pd, ps, localPal, 320/8);
\r
302 if(full) vidClear(pd, 32);
\r
304 ps -= 64; // the blitter starts copying from the right border, so we need to adjust
\r
305 vidConvCpy_270(pd, ps, localPal, 256/8);
\r
306 if(full) vidClear(pd + 256*256, 32);
\r
311 static void vidBlitCenter_0(int full)
\r
313 unsigned char *ps = framebuff+328*8+8;
\r
314 unsigned long *pd = (unsigned long *) screenbuff;
\r
316 if (Pico.m.dirtyPal) fillLocalPal();
\r
318 if(Pico.video.reg[12]&1) ps += 32;
\r
319 vidConvCpy_center_0(pd, ps, localPal);
\r
320 if(full) vidClear(pd + 224*256, 96);
\r
324 static void vidBlitCenter_180(int full)
\r
326 unsigned char *ps = framebuff+328*8+8;
\r
327 unsigned long *pd = (unsigned long *) screenbuff;
\r
329 if (Pico.m.dirtyPal) fillLocalPal();
\r
331 if(Pico.video.reg[12]&1) ps += 32;
\r
332 vidConvCpy_center_180(pd, ps, localPal);
\r
333 if(full) vidClear(pd + 224*256, 96);
\r
337 static void vidBlitFit_0(int full)
\r
339 if (Pico.m.dirtyPal) fillLocalPal();
\r
341 if(Pico.video.reg[12]&1)
\r
342 vidConvCpy_center2_40c_0(screenbuff, framebuff+328*8, localPal, 168);
\r
343 else vidConvCpy_center2_32c_0(screenbuff, framebuff+328*8, localPal, 168);
\r
344 if(full) vidClear((unsigned long *)screenbuff + 168*256, 320-168);
\r
348 static void vidBlitFit_180(int full)
\r
350 if (Pico.m.dirtyPal) fillLocalPal();
\r
352 if(Pico.video.reg[12]&1)
\r
353 vidConvCpy_center2_40c_180(screenbuff, framebuff+328*8, localPal, 168);
\r
354 else vidConvCpy_center2_32c_180(screenbuff, framebuff+328*8-64, localPal, 168);
\r
355 if(full) vidClear((unsigned long *)screenbuff + 168*256, 320-168);
\r
359 static void vidBlitFit2_0(int full)
\r
361 if (Pico.m.dirtyPal) fillLocalPal();
\r
363 if(Pico.video.reg[12]&1)
\r
364 vidConvCpy_center2_40c_0(screenbuff, framebuff+328*8, localPal, 224);
\r
365 else vidConvCpy_center2_32c_0(screenbuff, framebuff+328*8, localPal, 224);
\r
366 if(full) vidClear((unsigned long *)screenbuff + 224*256, 96);
\r
370 static void vidBlitFit2_180(int full)
\r
372 if (Pico.m.dirtyPal) fillLocalPal();
\r
374 if(Pico.video.reg[12]&1)
\r
375 vidConvCpy_center2_40c_180(screenbuff, framebuff+328*8, localPal, 224);
\r
376 else vidConvCpy_center2_32c_180(screenbuff, framebuff+328*8-64, localPal, 224);
\r
377 if(full) vidClear((unsigned long *)screenbuff + 224*256, 96);
\r
381 static void vidBlitCfg(void)
\r
383 unsigned short *ps = (unsigned short *) framebuff;
\r
384 unsigned long *pd = (unsigned long *) screenbuff;
\r
387 // hangs randomly (due to repeated ldms/stms?)
\r
388 //for (int i = 1; i < 320; i++, ps += 240, pd += 256)
\r
389 // vidConvCpyRGB32(pd, ps, 240);
\r
391 for (i = 0; i < 320; i++, pd += 16)
\r
392 for (int u = 0; u < 240; u++, ps++, pd++)
\r
393 *pd = ((*ps & 0xf) << 20) | ((*ps & 0xf0) << 8) | ((*ps & 0xf00) >> 4);
\r
397 ////////////////////////////////
\r
400 int vidInit(void *vidmem, int reinit)
\r
403 // prepare framebuffer
\r
404 screenbuff = vidmem;
\r
405 framebuff = (unsigned char *) malloc(framebuffsize);
\r
407 if(!screenbuff) return KErrNotSupported;
\r
408 if(!framebuff) return KErrNoMemory;
\r
410 memset(framebuff, 0, framebuffsize);
\r
412 // Cram function: go and hack Pico so it never gets called
\r
413 PicoCram = EmuCramNull;
\r
416 // select suitable blitters
\r
417 vidBlit = vidBlit_270;
\r
418 PicoScan = EmuScan8;
\r
419 drawTextFps = drawTextFps0;
\r
420 drawTextNotice = drawTextNotice0;
\r
422 memset(localPal, 0, 0x100*4);
\r
423 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
424 localPal[0xf0] = 0x00ee0000;
\r
426 // setup all orientation related stuff
\r
427 if(currentConfig->iScreenRotation == TPicoConfig::PRot0) {
\r
428 if(currentConfig->iScreenMode == TPicoConfig::PMCenter) {
\r
429 vidBlit = vidBlitCenter_0;
\r
430 drawTextFps = drawTextFpsCenter0;
\r
431 drawTextNotice = drawTextNoticeCenter0;
\r
432 } else if(currentConfig->iScreenMode == TPicoConfig::PMFit2) {
\r
433 vidBlit = vidBlitFit2_0;
\r
434 drawTextFps = drawTextFpsFit2_0;
\r
435 drawTextNotice = drawTextNoticeFit2_0;
\r
437 vidBlit = vidBlitFit_0;
\r
438 drawTextFps = drawTextFpsFit0;
\r
439 drawTextNotice = drawTextNoticeFit0;
\r
440 PicoScan = EmuScanFit0;
\r
442 } else if(currentConfig->iScreenRotation == TPicoConfig::PRot90) {
\r
443 vidBlit = vidBlit_90;
\r
444 } else if(currentConfig->iScreenRotation == TPicoConfig::PRot180) {
\r
445 if(currentConfig->iScreenMode == TPicoConfig::PMCenter) {
\r
446 vidBlit = vidBlitCenter_180;
\r
447 drawTextFps = drawTextFpsCenter0;
\r
448 drawTextNotice = drawTextNoticeCenter0;
\r
449 } else if(currentConfig->iScreenMode == TPicoConfig::PMFit2) {
\r
450 vidBlit = vidBlitFit2_180;
\r
451 drawTextFps = drawTextFpsFit2_0;
\r
452 drawTextNotice = drawTextNoticeFit2_0;
\r
454 vidBlit = vidBlitFit_180;
\r
455 drawTextFps = drawTextFpsFit0;
\r
456 drawTextNotice = drawTextNoticeFit0;
\r
457 PicoScan = EmuScanFit0;
\r
459 } else if(currentConfig->iScreenRotation == TPicoConfig::PRot270) {
\r
460 vidBlit = vidBlit_270;
\r
465 Pico.m.dirtyPal = 1;
\r
476 void vidDrawFrame(char *noticeStr, char *fpsStr, int num)
\r
478 DrawLineDest = framebuff + 328*8 + 8;
\r
480 // PicoFrame(); // moved to main loop
\r
481 if(currentConfig->iFlags & 2)
\r
482 drawTextFps(fpsStr);
\r
483 drawTextNotice(noticeStr);
\r
485 vidBlit(!num); // copy full frame once a second
\r
488 // -----------------------------------------------------------------
\r
490 static void drawText0(int x, int y, const char *text, long color)
\r
492 unsigned short *vidmem=(unsigned short *)framebuff;
\r
493 int charmask, i, cx = x, cy;
\r
494 unsigned short *l, *le, dmask=0x0333;
\r
496 // darken the background (left border)
\r
497 for(l=vidmem+(cx-1)+(y-1)*240, le=vidmem+(cx-1)+(y+7)*240; l < le; l+=240)
\r
498 *l = (*l >> 2) & dmask;
\r
500 for(const char *p=text; *p; p++) {
\r
502 charmask = *(mask_numbers + (*p - 0x2F));
\r
504 for(l = vidmem+cx+(y-1)*240, le = vidmem+cx+(y+7)*240; l < le; l+=240-4) {
\r
505 *l = (*l >> 2) & dmask; l++; *l = (*l >> 2) & dmask; l++;
\r
506 *l = (*l >> 2) & dmask; l++; *l = (*l >> 2) & dmask; l++;
\r
507 *l = (*l >> 2) & dmask;
\r
510 for(i=0; i < 24; i++) {
\r
511 // draw dot. Is this fast?
\r
512 if(charmask&0x80000000) *( vidmem + (cx+(i&3)) + (cy+(i>>2))*240 ) = color;
\r
519 // draws rect with width - 1 and height - 1
\r
520 static void drawRect(const TRect &rc, unsigned short color)
\r
522 unsigned short *vidmem=(unsigned short *)framebuff;
\r
524 if(rc.iTl.iX - rc.iBr.iX && rc.iTl.iY - rc.iBr.iY) {
\r
525 int stepX = rc.iTl.iX < rc.iBr.iX ? 1 : -1;
\r
526 int stepY = rc.iTl.iY < rc.iBr.iY ? 1 : -1;
\r
528 for(int x = rc.iTl.iX;; x += stepX) {
\r
529 *(vidmem + rc.iTl.iY*240 + x) = *(vidmem + (rc.iBr.iY - stepY)*240 + x) = color;
\r
530 if(x == rc.iBr.iX - stepX) break;
\r
533 for(int y = rc.iTl.iY;; y += stepY) {
\r
534 *(vidmem + y*240 + rc.iTl.iX) = *(vidmem + y*240 + rc.iBr.iX - stepX) = color;
\r
535 if(y == rc.iBr.iY - stepY) break;
\r
540 // draws fullsize filled rect
\r
541 static void drawRectFilled(const TRect rc, unsigned short color)
\r
543 unsigned short *vidmem=(unsigned short *)framebuff;
\r
545 if(rc.iTl.iX - rc.iBr.iX && rc.iTl.iY - rc.iBr.iY) {
\r
546 int stepX = rc.iTl.iX < rc.iBr.iX ? 1 : -1;
\r
547 int stepY = rc.iTl.iY < rc.iBr.iY ? 1 : -1;
\r
549 for(int y = rc.iTl.iY;; y += stepY) {
\r
550 for(int x = rc.iTl.iX;; x += stepX) {
\r
551 *(vidmem + y*240 + x) = *(vidmem + y*240 + x) = color;
\r
552 if(x == rc.iBr.iX) break;
\r
554 if(y == rc.iBr.iY) break;
\r
559 // direction: -1 left, 1 right
\r
560 static void drawArrow0(TPoint p, int direction, unsigned short color)
\r
562 unsigned short *vidmem=(unsigned short *)framebuff;
\r
567 for(; width > 0; x+=direction, y++, width -=2)
\r
568 for(int i=0; i < width; i++)
\r
569 *(vidmem + x + y*240 + i*240) = color;
\r
572 static char *vidGetScanName(int scan)
\r
574 static char buff[32];
\r
576 if((scan >= '0' && scan <= '9') || (scan >= 'A' && scan <= 'Z')) {
\r
577 buff[0] = (char) scan; buff[1] = 0;
\r
580 case 0x01: strcpy(buff, "BSPACE"); break;
\r
581 case 0x03: strcpy(buff, "OK"); break;
\r
582 case 0x05: strcpy(buff, "SPACE"); break;
\r
583 case 0x0e: strcpy(buff, "AST"); break;
\r
584 case 0x0f: strcpy(buff, "HASH"); break;
\r
585 case 0x12: strcpy(buff, "SHIFT"); break;
\r
586 case 0x19: strcpy(buff, "ALT"); break;
\r
587 case 0x79: strcpy(buff, "PLUS"); break;
\r
588 case 0x7a: strcpy(buff, "DOT"); break;
\r
589 case 0xa5: strcpy(buff, "JOG@UP"); break;
\r
590 case 0xa6: strcpy(buff, "JOG@DOWN"); break;
\r
591 case 0xb5: strcpy(buff, "INET"); break;
\r
592 case 0xd4: strcpy(buff, "JOG@PUSH"); break;
\r
593 case 0xd5: strcpy(buff, "BACK"); break;
\r
594 default: sprintf(buff, "KEY@%02X", scan); break;
\r
601 void vidKeyConfigFrame(const TUint whichAction)
\r
604 char buttonNames[128];
\r
605 buttonNames[0] = 0;
\r
606 memset(framebuff, 0, framebuffsize);
\r
608 unsigned long currentActCode = 1 << whichAction;
\r
610 // draw all "buttons" in reverse order
\r
611 const TPicoAreaConfigEntry *e = areaConfig + 1; i = 0;
\r
612 while(e->rect != TRect(0,0,0,0)) { e++; i++; }
\r
613 for(e--, i--; e->rect != TRect(0,0,0,0); e--, i--)
\r
614 drawRect(e->rect, (currentConfig->iAreaBinds[i] & currentActCode) ? color_red : color_red_dim);
\r
616 // action name control
\r
617 drawRectFilled(TRect(72, 2, 168, 20), color_grey); // 96x14
\r
618 drawArrow0(TPoint(80, 3), -1, color_green);
\r
619 drawArrow0(TPoint(160, 3), 1, color_green);
\r
621 drawText0(86, 9, actionNames[whichAction], color_red);
\r
623 // draw active button names if there are any
\r
624 for(i = 0; i < 256; i++) {
\r
625 if(currentConfig->iKeyBinds[i] & currentActCode) {
\r
626 if(buttonNames[0]) strcat(buttonNames, ";@");
\r
627 strcat(buttonNames, vidGetScanName(i));
\r
631 if(buttonNames[0]) {
\r
632 buttonNames[61] = 0; // only 60 chars fit
\r
633 drawText0(6, 48, buttonNames, color_blue);
\r
639 void vidDrawNotice(const char *txt)
\r
642 drawTextNotice(txt);
\r