summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-11-16 22:59:28 +0000
committerJens Arnold <amiconn@rockbox.org>2005-11-16 22:59:28 +0000
commit59825952f3d98d29e03b094642655968d7abcc02 (patch)
tree5648bd1ec26aca707755221b7c8a058d6a2aeffb
parent32877021a5f72984117d059b461a561b3439b47b (diff)
downloadrockbox-59825952f3d98d29e03b094642655968d7abcc02.tar.gz
rockbox-59825952f3d98d29e03b094642655968d7abcc02.zip
Rockboy: adapted to colour LCD (but no colours for gameboy color games yet). Some cleanup; killed a ton of TABs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7915 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/rockboy/lcd-gb.h10
-rw-r--r--apps/plugins/rockboy/lcd.c878
-rw-r--r--apps/plugins/rockboy/main.c5
-rw-r--r--apps/plugins/rockboy/sys_rockbox.c76
4 files changed, 483 insertions, 486 deletions
diff --git a/apps/plugins/rockboy/lcd-gb.h b/apps/plugins/rockboy/lcd-gb.h
index 0b863b6eea..14d7ee49e0 100644
--- a/apps/plugins/rockboy/lcd-gb.h
+++ b/apps/plugins/rockboy/lcd-gb.h
@@ -16,10 +16,12 @@ struct scan
16{ 16{
17 int bg[64]; 17 int bg[64];
18 int wnd[64]; 18 int wnd[64];
19#if LCD_DEPTH == 2 19#if LCD_DEPTH == 1
20 byte buf[4][256]; 20 byte buf[8][256];
21#else 21#elif LCD_DEPTH == 2
22 byte buf[8][256]; 22 byte buf[4][256];
23#elif LCD_DEPTH > 4
24 byte buf[1][256];
23#endif 25#endif
24 byte pal1[128]; 26 byte pal1[128];
25 un16 pal2[64]; 27 un16 pal2[64];
diff --git a/apps/plugins/rockboy/lcd.c b/apps/plugins/rockboy/lcd.c
index 872311d0e6..a8f8c695da 100644
--- a/apps/plugins/rockboy/lcd.c
+++ b/apps/plugins/rockboy/lcd.c
@@ -99,21 +99,21 @@ static byte *vdest;
99#ifndef ASM_UPDATEPATPIX 99#ifndef ASM_UPDATEPATPIX
100void updatepatpix(void) 100void updatepatpix(void)
101{ 101{
102 int i, j; 102 int i, j;
103#if ((CONFIG_CPU != SH7034) && (CONFIG_CPU != MCF5249)) || defined(SIMULATOR) 103#if ((CONFIG_CPU != SH7034) && (CONFIG_CPU != MCF5249)) || defined(SIMULATOR)
104 int k, a, c; 104 int k, a, c;
105#endif 105#endif
106 byte *vram = lcd.vbank[0]; 106 byte *vram = lcd.vbank[0];
107 107
108 if (!anydirty) return; 108 if (!anydirty) return;
109 for (i = 0; i < 1024; i++) 109 for (i = 0; i < 1024; i++)
110 { 110 {
111 if (i == 384) i = 512; 111 if (i == 384) i = 512;
112 if (i == 896) break; 112 if (i == 896) break;
113 if (!patdirty[i]) continue; 113 if (!patdirty[i]) continue;
114 patdirty[i] = 0; 114 patdirty[i] = 0;
115 for (j = 0; j < 8; j++) 115 for (j = 0; j < 8; j++)
116 { 116 {
117#if CONFIG_CPU == SH7034 && !defined(SIMULATOR) 117#if CONFIG_CPU == SH7034 && !defined(SIMULATOR)
118 asm volatile ( 118 asm volatile (
119 "mov.w @%2,r1 \n" 119 "mov.w @%2,r1 \n"
@@ -248,18 +248,18 @@ void updatepatpix(void)
248 "d0", "d1", "d2" 248 "d0", "d1", "d2"
249 ); 249 );
250#else 250#else
251 a = ((i<<4) | (j<<1)); 251 a = ((i<<4) | (j<<1));
252 for (k = 0; k < 8; k++) 252 for (k = 0; k < 8; k++)
253 { 253 {
254 c = vram[a] & (1<<k) ? 1 : 0; 254 c = vram[a] & (1<<k) ? 1 : 0;
255 c |= vram[a+1] & (1<<k) ? 2 : 0; 255 c |= vram[a+1] & (1<<k) ? 2 : 0;
256 patpix[i+1024][j][k] = c; 256 patpix[i+1024][j][k] = c;
257 } 257 }
258 for (k = 0; k < 8; k++) 258 for (k = 0; k < 8; k++)
259 patpix[i][j][k] = 259 patpix[i][j][k] =
260 patpix[i+1024][j][7-k]; 260 patpix[i+1024][j][7-k];
261#endif 261#endif
262 } 262 }
263#if CONFIG_CPU == SH7034 && !defined(SIMULATOR) 263#if CONFIG_CPU == SH7034 && !defined(SIMULATOR)
264 asm volatile ( 264 asm volatile (
265 "mov.l @%0,r0 \n" 265 "mov.l @%0,r0 \n"
@@ -386,19 +386,19 @@ void updatepatpix(void)
386 "d0", "d1", "d2", "d3", "d4", "d5" 386 "d0", "d1", "d2", "d3", "d4", "d5"
387 ); 387 );
388#else 388#else
389 for (j = 0; j < 8; j++) 389 for (j = 0; j < 8; j++)
390 { 390 {
391 for (k = 0; k < 8; k++) 391 for (k = 0; k < 8; k++)
392 { 392 {
393 patpix[i+2048][j][k] = 393 patpix[i+2048][j][k] =
394 patpix[i][7-j][k]; 394 patpix[i][7-j][k];
395 patpix[i+3072][j][k] = 395 patpix[i+3072][j][k] =
396 patpix[i+1024][7-j][k]; 396 patpix[i+1024][7-j][k];
397 } 397 }
398 } 398 }
399#endif 399#endif
400 } 400 }
401 anydirty = 0; 401 anydirty = 0;
402} 402}
403#endif /* ASM_UPDATEPATPIX */ 403#endif /* ASM_UPDATEPATPIX */
404 404
@@ -406,99 +406,99 @@ void updatepatpix(void)
406 406
407void tilebuf(void) 407void tilebuf(void)
408{ 408{
409 int i, cnt; 409 int i, cnt;
410 int base; 410 int base;
411 byte *tilemap, *attrmap; 411 byte *tilemap, *attrmap;
412 int *tilebuf; 412 int *tilebuf;
413 int *wrap; 413 int *wrap;
414 static int wraptable[64] = 414 static int wraptable[64] =
415 { 415 {
416 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 416 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
417 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,-32 417 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,-32
418 }; 418 };
419 419
420 base = ((R_LCDC&0x08)?0x1C00:0x1800) + (T<<5) + S; 420 base = ((R_LCDC&0x08)?0x1C00:0x1800) + (T<<5) + S;
421 tilemap = lcd.vbank[0] + base; 421 tilemap = lcd.vbank[0] + base;
422 attrmap = lcd.vbank[1] + base; 422 attrmap = lcd.vbank[1] + base;
423 tilebuf = BG; 423 tilebuf = BG;
424 wrap = wraptable + S; 424 wrap = wraptable + S;
425 cnt = ((WX + 7) >> 3) + 1; 425 cnt = ((WX + 7) >> 3) + 1;
426 426
427 if (hw.cgb) { 427 if (hw.cgb) {
428 if (R_LCDC & 0x10) 428 if (R_LCDC & 0x10)
429 for (i = cnt; i > 0; i--) 429 for (i = cnt; i > 0; i--)
430 { 430 {
431 *(tilebuf++) = *tilemap 431 *(tilebuf++) = *tilemap
432 | (((int)*attrmap & 0x08) << 6) 432 | (((int)*attrmap & 0x08) << 6)
433 | (((int)*attrmap & 0x60) << 5); 433 | (((int)*attrmap & 0x60) << 5);
434 *(tilebuf++) = (((int)*attrmap & 0x07) << 2); 434 *(tilebuf++) = (((int)*attrmap & 0x07) << 2);
435 attrmap += *wrap + 1; 435 attrmap += *wrap + 1;
436 tilemap += *(wrap++) + 1; 436 tilemap += *(wrap++) + 1;
437 } 437 }
438 else 438 else
439 for (i = cnt; i > 0; i--) 439 for (i = cnt; i > 0; i--)
440 { 440 {
441 *(tilebuf++) = (256 + ((n8)*tilemap)) 441 *(tilebuf++) = (256 + ((n8)*tilemap))
442 | (((int)*attrmap & 0x08) << 6) 442 | (((int)*attrmap & 0x08) << 6)
443 | (((int)*attrmap & 0x60) << 5); 443 | (((int)*attrmap & 0x60) << 5);
444 *(tilebuf++) = (((int)*attrmap & 0x07) << 2); 444 *(tilebuf++) = (((int)*attrmap & 0x07) << 2);
445 attrmap += *wrap + 1; 445 attrmap += *wrap + 1;
446 tilemap += *(wrap++) + 1; 446 tilemap += *(wrap++) + 1;
447 } 447 }
448 } 448 }
449 else 449 else
450 { 450 {
451 if (R_LCDC & 0x10) 451 if (R_LCDC & 0x10)
452 for (i = cnt; i > 0; i--) 452 for (i = cnt; i > 0; i--)
453 { 453 {
454 *(tilebuf++) = *(tilemap++); 454 *(tilebuf++) = *(tilemap++);
455 tilemap += *(wrap++); 455 tilemap += *(wrap++);
456 } 456 }
457 else 457 else
458 for (i = cnt; i > 0; i--) 458 for (i = cnt; i > 0; i--)
459 { 459 {
460 *(tilebuf++) = (256 + ((n8)*(tilemap++))); 460 *(tilebuf++) = (256 + ((n8)*(tilemap++)));
461 tilemap += *(wrap++); 461 tilemap += *(wrap++);
462 } 462 }
463 } 463 }
464 464
465 if (WX >= 160) return; 465 if (WX >= 160) return;
466 466
467 base = ((R_LCDC&0x40)?0x1C00:0x1800) + (WT<<5); 467 base = ((R_LCDC&0x40)?0x1C00:0x1800) + (WT<<5);
468 tilemap = lcd.vbank[0] + base; 468 tilemap = lcd.vbank[0] + base;
469 attrmap = lcd.vbank[1] + base; 469 attrmap = lcd.vbank[1] + base;
470 tilebuf = WND; 470 tilebuf = WND;
471 cnt = ((160 - WX) >> 3) + 1; 471 cnt = ((160 - WX) >> 3) + 1;
472 472
473 if (hw.cgb) 473 if (hw.cgb)
474 { 474 {
475 if (R_LCDC & 0x10) 475 if (R_LCDC & 0x10)
476 for (i = cnt; i > 0; i--) 476 for (i = cnt; i > 0; i--)
477 { 477 {
478 *(tilebuf++) = *(tilemap++) 478 *(tilebuf++) = *(tilemap++)
479 | (((int)*attrmap & 0x08) << 6) 479 | (((int)*attrmap & 0x08) << 6)
480 | (((int)*attrmap & 0x60) << 5); 480 | (((int)*attrmap & 0x60) << 5);
481 *(tilebuf++) = (((int)*(attrmap++)&7) << 2); 481 *(tilebuf++) = (((int)*(attrmap++)&7) << 2);
482 } 482 }
483 else 483 else
484 for (i = cnt; i > 0; i--) 484 for (i = cnt; i > 0; i--)
485 { 485 {
486 *(tilebuf++) = (256 + ((n8)*(tilemap++))) 486 *(tilebuf++) = (256 + ((n8)*(tilemap++)))
487 | (((int)*attrmap & 0x08) << 6) 487 | (((int)*attrmap & 0x08) << 6)
488 | (((int)*attrmap & 0x60) << 5); 488 | (((int)*attrmap & 0x60) << 5);
489 *(tilebuf++) = (((int)*(attrmap++)&7) << 2); 489 *(tilebuf++) = (((int)*(attrmap++)&7) << 2);
490 } 490 }
491 } 491 }
492 else 492 else
493 493
494 { 494 {
495 if (R_LCDC & 0x10) 495 if (R_LCDC & 0x10)
496 for (i = cnt; i > 0; i--) 496 for (i = cnt; i > 0; i--)
497 *(tilebuf++) = *(tilemap++); 497 *(tilebuf++) = *(tilemap++);
498 else 498 else
499 for (i = cnt; i > 0; i--) 499 for (i = cnt; i > 0; i--)
500 *(tilebuf++) = (256 + ((n8)*(tilemap++))); 500 *(tilebuf++) = (256 + ((n8)*(tilemap++)));
501 } 501 }
502} 502}
503 503
504 504
@@ -507,318 +507,318 @@ void tilebuf(void)
507// U = start...something...thingy... 7 at most 507// U = start...something...thingy... 7 at most
508void bg_scan(void) 508void bg_scan(void)
509{ 509{
510 int cnt; 510 int cnt;
511 byte *src, *dest; 511 byte *src, *dest;
512 int *tile; 512 int *tile;
513 513
514 if (WX <= 0) return; 514 if (WX <= 0) return;
515 cnt = WX; 515 cnt = WX;
516 tile = BG; 516 tile = BG;
517 dest = BUF; 517 dest = BUF;
518 518
519 src = patpix[*(tile++)][V] + U; 519 src = patpix[*(tile++)][V] + U;
520 memcpy(dest, src, 8-U); 520 memcpy(dest, src, 8-U);
521 dest += 8-U; 521 dest += 8-U;
522 cnt -= 8-U; 522 cnt -= 8-U;
523 if (cnt <= 0) return; 523 if (cnt <= 0) return;
524 while (cnt >= 8) 524 while (cnt >= 8)
525 { 525 {
526 src = patpix[*(tile++)][V]; 526 src = patpix[*(tile++)][V];
527 MEMCPY8(dest, src); 527 MEMCPY8(dest, src);
528 dest += 8; 528 dest += 8;
529 cnt -= 8; 529 cnt -= 8;
530 } 530 }
531 src = patpix[*tile][V]; 531 src = patpix[*tile][V];
532 while (cnt--) 532 while (cnt--)
533 *(dest++) = *(src++); 533 *(dest++) = *(src++);
534} 534}
535 535
536void wnd_scan(void) 536void wnd_scan(void)
537{ 537{
538 int cnt; 538 int cnt;
539 byte *src, *dest; 539 byte *src, *dest;
540 int *tile; 540 int *tile;
541 541
542 if (WX >= 160) return; 542 if (WX >= 160) return;
543 cnt = 160 - WX; 543 cnt = 160 - WX;
544 tile = WND; 544 tile = WND;
545 dest = BUF + WX; 545 dest = BUF + WX;
546 546
547 while (cnt >= 8) 547 while (cnt >= 8)
548 { 548 {
549 src = patpix[*(tile++)][WV]; 549 src = patpix[*(tile++)][WV];
550 MEMCPY8(dest, src); 550 MEMCPY8(dest, src);
551 dest += 8; 551 dest += 8;
552 cnt -= 8; 552 cnt -= 8;
553 } 553 }
554 src = patpix[*tile][WV]; 554 src = patpix[*tile][WV];
555 while (cnt--) 555 while (cnt--)
556 *(dest++) = *(src++); 556 *(dest++) = *(src++);
557} 557}
558 558
559static void blendcpy(byte *dest, byte *src, byte b, int cnt) 559static void blendcpy(byte *dest, byte *src, byte b, int cnt)
560{ 560{
561 while (cnt--) *(dest++) = *(src++) | b; 561 while (cnt--) *(dest++) = *(src++) | b;
562} 562}
563 563
564static int priused(void *attr) 564static int priused(void *attr)
565{ 565{
566 un32 *a = attr; 566 un32 *a = attr;
567 return (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080); 567 return (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080);
568} 568}
569 569
570void bg_scan_pri(void) 570void bg_scan_pri(void)
571{ 571{
572 int cnt, i; 572 int cnt, i;
573 byte *src, *dest; 573 byte *src, *dest;
574 574
575 if (WX <= 0) return; 575 if (WX <= 0) return;
576 i = S; 576 i = S;
577 cnt = WX; 577 cnt = WX;
578 dest = PRI; 578 dest = PRI;
579 src = lcd.vbank[1] + ((R_LCDC&0x08)?0x1C00:0x1800) + (T<<5); 579 src = lcd.vbank[1] + ((R_LCDC&0x08)?0x1C00:0x1800) + (T<<5);
580 580
581 if (!priused(src)) 581 if (!priused(src))
582 { 582 {
583 memset(dest, 0, cnt); 583 memset(dest, 0, cnt);
584 return; 584 return;
585 } 585 }
586 586
587 memset(dest, src[i++&31]&128, 8-U); 587 memset(dest, src[i++&31]&128, 8-U);
588 dest += 8-U; 588 dest += 8-U;
589 cnt -= 8-U; 589 cnt -= 8-U;
590 if (cnt <= 0) return; 590 if (cnt <= 0) return;
591 while (cnt >= 8) 591 while (cnt >= 8)
592 { 592 {
593 memset(dest, src[i++&31]&128, 8); 593 memset(dest, src[i++&31]&128, 8);
594 dest += 8; 594 dest += 8;
595 cnt -= 8; 595 cnt -= 8;
596 } 596 }
597 memset(dest, src[i&31]&128, cnt); 597 memset(dest, src[i&31]&128, cnt);
598} 598}
599 599
600void wnd_scan_pri(void) 600void wnd_scan_pri(void)
601{ 601{
602 int cnt, i; 602 int cnt, i;
603 byte *src, *dest; 603 byte *src, *dest;
604 604
605 if (WX >= 160) return; 605 if (WX >= 160) return;
606 i = 0; 606 i = 0;
607 cnt = 160 - WX; 607 cnt = 160 - WX;
608 dest = PRI + WX; 608 dest = PRI + WX;
609 src = lcd.vbank[1] + ((R_LCDC&0x40)?0x1C00:0x1800) + (WT<<5); 609 src = lcd.vbank[1] + ((R_LCDC&0x40)?0x1C00:0x1800) + (WT<<5);
610 610
611 if (!priused(src)) 611 if (!priused(src))
612 { 612 {
613 memset(dest, 0, cnt); 613 memset(dest, 0, cnt);
614 return; 614 return;
615 } 615 }
616 616
617 while (cnt >= 8) 617 while (cnt >= 8)
618 { 618 {
619 memset(dest, src[i++]&128, 8); 619 memset(dest, src[i++]&128, 8);
620 dest += 8; 620 dest += 8;
621 cnt -= 8; 621 cnt -= 8;
622 } 622 }
623 memset(dest, src[i]&128, cnt); 623 memset(dest, src[i]&128, cnt);
624} 624}
625 625
626void bg_scan_color(void) 626void bg_scan_color(void)
627{ 627{
628 int cnt; 628 int cnt;
629 byte *src, *dest; 629 byte *src, *dest;
630 int *tile; 630 int *tile;
631 631
632 if (WX <= 0) return; 632 if (WX <= 0) return;
633 cnt = WX; 633 cnt = WX;
634 tile = BG; 634 tile = BG;
635 dest = BUF; 635 dest = BUF;
636 636
637 src = patpix[*(tile++)][V] + U; 637 src = patpix[*(tile++)][V] + U;
638 blendcpy(dest, src, *(tile++), 8-U); 638 blendcpy(dest, src, *(tile++), 8-U);
639 dest += 8-U; 639 dest += 8-U;
640 cnt -= 8-U; 640 cnt -= 8-U;
641 if (cnt <= 0) return; 641 if (cnt <= 0) return;
642 while (cnt >= 8) 642 while (cnt >= 8)
643 { 643 {
644 src = patpix[*(tile++)][V]; 644 src = patpix[*(tile++)][V];
645 blendcpy(dest, src, *(tile++), 8); 645 blendcpy(dest, src, *(tile++), 8);
646 dest += 8; 646 dest += 8;
647 cnt -= 8; 647 cnt -= 8;
648 } 648 }
649 src = patpix[*(tile++)][V]; 649 src = patpix[*(tile++)][V];
650 blendcpy(dest, src, *(tile++), cnt); 650 blendcpy(dest, src, *(tile++), cnt);
651} 651}
652 652
653void wnd_scan_color(void) 653void wnd_scan_color(void)
654{ 654{
655 int cnt; 655 int cnt;
656 byte *src, *dest; 656 byte *src, *dest;
657 int *tile; 657 int *tile;
658 658
659 if (WX >= 160) return; 659 if (WX >= 160) return;
660 cnt = 160 - WX; 660 cnt = 160 - WX;
661 tile = WND; 661 tile = WND;
662 dest = BUF + WX; 662 dest = BUF + WX;
663 663
664 while (cnt >= 8) 664 while (cnt >= 8)
665 { 665 {
666 src = patpix[*(tile++)][WV]; 666 src = patpix[*(tile++)][WV];
667 blendcpy(dest, src, *(tile++), 8); 667 blendcpy(dest, src, *(tile++), 8);
668 dest += 8; 668 dest += 8;
669 cnt -= 8; 669 cnt -= 8;
670 } 670 }
671 src = patpix[*(tile++)][WV]; 671 src = patpix[*(tile++)][WV];
672 blendcpy(dest, src, *(tile++), cnt); 672 blendcpy(dest, src, *(tile++), cnt);
673} 673}
674 674
675static void recolor(byte *buf, byte fill, int cnt) 675static void recolor(byte *buf, byte fill, int cnt)
676{ 676{
677 while (cnt--) *(buf++) |= fill; 677 while (cnt--) *(buf++) |= fill;
678} 678}
679 679
680void spr_count(void) 680void spr_count(void)
681{ 681{
682 int i; 682 int i;
683 struct obj *o; 683 struct obj *o;
684 684
685 NS = 0; 685 NS = 0;
686 if (!(R_LCDC & 0x02)) return; 686 if (!(R_LCDC & 0x02)) return;
687 687
688 o = lcd.oam.obj; 688 o = lcd.oam.obj;
689 689
690 for (i = 40; i; i--, o++) 690 for (i = 40; i; i--, o++)
691 { 691 {
692 if (L >= o->y || L + 16 < o->y) 692 if (L >= o->y || L + 16 < o->y)
693 continue; 693 continue;
694 if (L + 8 >= o->y && !(R_LCDC & 0x04)) 694 if (L + 8 >= o->y && !(R_LCDC & 0x04))
695 continue; 695 continue;
696 if (++NS == 10) break; 696 if (++NS == 10) break;
697 } 697 }
698} 698}
699 699
700void spr_enum(void) 700void spr_enum(void)
701{ 701{
702 int i, j; 702 int i, j;
703 struct obj *o; 703 struct obj *o;
704 struct vissprite ts[10]; 704 struct vissprite ts[10];
705 int v, pat; 705 int v, pat;
706 int l, x; 706 int l, x;
707 707
708 NS = 0; 708 NS = 0;
709 if (!(R_LCDC & 0x02)) return; 709 if (!(R_LCDC & 0x02)) return;
710 710
711 o = lcd.oam.obj; 711 o = lcd.oam.obj;
712 712
713 for (i = 40; i; i--, o++) 713 for (i = 40; i; i--, o++)
714 { 714 {
715 if (L >= o->y || L + 16 < o->y) 715 if (L >= o->y || L + 16 < o->y)
716 continue; 716 continue;
717 if (L + 8 >= o->y && !(R_LCDC & 0x04)) 717 if (L + 8 >= o->y && !(R_LCDC & 0x04))
718 continue; 718 continue;
719 VS[NS].x = (int)o->x - 8; 719 VS[NS].x = (int)o->x - 8;
720 v = L - (int)o->y + 16; 720 v = L - (int)o->y + 16;
721 if (hw.cgb) 721 if (hw.cgb)
722 { 722 {
723 pat = o->pat | (((int)o->flags & 0x60) << 5) 723 pat = o->pat | (((int)o->flags & 0x60) << 5)
724 | (((int)o->flags & 0x08) << 6); 724 | (((int)o->flags & 0x08) << 6);
725 VS[NS].pal = 32 + ((o->flags & 0x07) << 2); 725 VS[NS].pal = 32 + ((o->flags & 0x07) << 2);
726 } 726 }
727 else 727 else
728 { 728 {
729 pat = o->pat | (((int)o->flags & 0x60) << 5); 729 pat = o->pat | (((int)o->flags & 0x60) << 5);
730 VS[NS].pal = 32 + ((o->flags & 0x10) >> 2); 730 VS[NS].pal = 32 + ((o->flags & 0x10) >> 2);
731 } 731 }
732 VS[NS].pri = (o->flags & 0x80) >> 7; 732 VS[NS].pri = (o->flags & 0x80) >> 7;
733 if ((R_LCDC & 0x04)) 733 if ((R_LCDC & 0x04))
734 { 734 {
735 pat &= ~1; 735 pat &= ~1;
736 if (v >= 8) 736 if (v >= 8)
737 { 737 {
738 v -= 8; 738 v -= 8;
739 pat++; 739 pat++;
740 } 740 }
741 if (o->flags & 0x40) pat ^= 1; 741 if (o->flags & 0x40) pat ^= 1;
742 } 742 }
743 VS[NS].buf = patpix[pat][v]; 743 VS[NS].buf = patpix[pat][v];
744 if (++NS == 10) break; 744 if (++NS == 10) break;
745 } 745 }
746 if (!sprsort||hw.cgb) return; 746 if (!sprsort||hw.cgb) return;
747 /* not quite optimal but it finally works! */ 747 /* not quite optimal but it finally works! */
748 for (i = 0; i < NS; i++) 748 for (i = 0; i < NS; i++)
749 { 749 {
750 l = 0; 750 l = 0;
751 x = VS[0].x; 751 x = VS[0].x;
752 for (j = 1; j < NS; j++) 752 for (j = 1; j < NS; j++)
753 { 753 {
754 if (VS[j].x < x) 754 if (VS[j].x < x)
755 { 755 {
756 l = j; 756 l = j;
757 x = VS[j].x; 757 x = VS[j].x;
758 } 758 }
759 } 759 }
760 ts[i] = VS[l]; 760 ts[i] = VS[l];
761 VS[l].x = 160; 761 VS[l].x = 160;
762 } 762 }
763 memcpy(VS, ts, sizeof VS); 763 memcpy(VS, ts, sizeof VS);
764} 764}
765 765
766void spr_scan(void) 766void spr_scan(void)
767{ 767{
768 int i, x; 768 int i, x;
769 byte pal, b, ns = NS; 769 byte pal, b, ns = NS;
770 byte *src, *dest, *bg, *pri; 770 byte *src, *dest, *bg, *pri;
771 struct vissprite *vs; 771 struct vissprite *vs;
772 static byte bgdup[256]; 772 static byte bgdup[256];
773 773
774 if (!ns) return; 774 if (!ns) return;
775 775
776 memcpy(bgdup, BUF, 256); 776 memcpy(bgdup, BUF, 256);
777 vs = &VS[ns-1]; 777 vs = &VS[ns-1];
778 778
779 for (; ns; ns--, vs--) 779 for (; ns; ns--, vs--)
780 { 780 {
781 x = vs->x; 781 x = vs->x;
782 if (x >= 160) continue; 782 if (x >= 160) continue;
783 if (x <= -8) continue; 783 if (x <= -8) continue;
784 if (x < 0) 784 if (x < 0)
785 { 785 {
786 src = vs->buf - x; 786 src = vs->buf - x;
787 dest = BUF; 787 dest = BUF;
788 i = 8 + x; 788 i = 8 + x;
789 } 789 }
790 else 790 else
791 { 791 {
792 src = vs->buf; 792 src = vs->buf;
793 dest = BUF + x; 793 dest = BUF + x;
794 if (x > 152) i = 160 - x; 794 if (x > 152) i = 160 - x;
795 else i = 8; 795 else i = 8;
796 } 796 }
797 pal = vs->pal; 797 pal = vs->pal;
798 if (vs->pri) 798 if (vs->pri)
799 { 799 {
800 bg = bgdup + (dest - BUF); 800 bg = bgdup + (dest - BUF);
801 while (i--) 801 while (i--)
802 { 802 {
803 b = src[i]; 803 b = src[i];
804 if (b && !(bg[i]&3)) dest[i] = pal|b; 804 if (b && !(bg[i]&3)) dest[i] = pal|b;
805 } 805 }
806 } 806 }
807 else if (hw.cgb) 807 else if (hw.cgb)
808 { 808 {
809 bg = bgdup + (dest - BUF); 809 bg = bgdup + (dest - BUF);
810 pri = PRI + (dest - BUF); 810 pri = PRI + (dest - BUF);
811 while (i--) 811 while (i--)
812 { 812 {
813 b = src[i]; 813 b = src[i];
814 if (b && (!pri[i] || !(bg[i]&3))) 814 if (b && (!pri[i] || !(bg[i]&3)))
815 dest[i] = pal|b; 815 dest[i] = pal|b;
816 } 816 }
817 } 817 }
818 else while (i--) if (src[i]) dest[i] = pal|src[i]; 818 else while (i--) if (src[i]) dest[i] = pal|src[i];
819 /* else while (i--) if (src[i]) dest[i] = 31 + ns; */ 819 /* else while (i--) if (src[i]) dest[i] = 31 + ns; */
820 } 820 }
821// if (sprdebug) for (i = 0; i < NS; i++) BUF[i<<1] = 36; 821// if (sprdebug) for (i = 0; i < NS; i++) BUF[i<<1] = 36;
822} 822}
823 823
824 824
@@ -828,43 +828,45 @@ void spr_scan(void)
828 828
829void lcd_begin(void) 829void lcd_begin(void)
830{ 830{
831/* if (fb.indexed) 831/* if (fb.indexed)
832 { 832 {
833 if (rgb332) pal_set332(); 833 if (rgb332) pal_set332();
834 else pal_expire(); 834 else pal_expire();
835 } 835 }
836 while (scale * 160 > fb.w || scale * 144 > fb.h) scale--; */ 836 while (scale * 160 > fb.w || scale * 144 > fb.h) scale--; */
837 vdest = fb.ptr + ((fb.w*fb.pelsize)>>1) 837 vdest = fb.ptr + ((fb.w*fb.pelsize)>>1)
838 - (80*fb.pelsize) 838 - (80*fb.pelsize)
839 + ((fb.h>>1) - 72) * fb.pitch; 839 + ((fb.h>>1) - 72) * fb.pitch;
840 WY = R_WY; 840 WY = R_WY;
841} 841}
842 842
843void lcd_refreshline(void) 843void lcd_refreshline(void)
844{ 844{
845 if (!fb.enabled) return; 845 if (!fb.enabled) return;
846 if(!insync) { 846 if(!insync) {
847 if(R_LY!=0) 847 if(R_LY!=0)
848 return; 848 return;
849 else 849 else
850 insync=1; 850 insync=1;
851 } 851 }
852 852
853 if (!(R_LCDC & 0x80)) 853 if (!(R_LCDC & 0x80))
854 return; /* should not happen... */ 854 return; /* should not happen... */
855 855
856 if ( (fb.mode==0&&(R_LY >= 128)) || 856#if LCD_HEIGHT < 144
857 (fb.mode==1&&(R_LY < 16)) || 857 if ( (fb.mode==0&&(R_LY >= 128)) ||
858 (fb.mode==2&&(R_LY<8||R_LY>=136)) || 858 (fb.mode==1&&(R_LY < 16)) ||
859 (fb.mode==3&&((R_LY%9)==8)) 859 (fb.mode==2&&(R_LY<8||R_LY>=136)) ||
860 860 (fb.mode==3&&((R_LY%9)==8))
861
861#if LCD_HEIGHT == 64 862#if LCD_HEIGHT == 64
862 || (R_LY & 1) /* calculate only even lines */ 863 || (R_LY & 1) /* calculate only even lines */
864#endif
865 )
866 return;
863#endif 867#endif
864 )
865 return;
866 868
867 updatepatpix(); 869 updatepatpix();
868 870
869 L = R_LY; 871 L = R_LY;
870 X = R_SCX; 872 X = R_SCX;
@@ -901,25 +903,25 @@ void lcd_refreshline(void)
901 recolor(BUF+WX, 0x04, 160-WX); 903 recolor(BUF+WX, 0x04, 160-WX);
902 } 904 }
903 spr_scan(); 905 spr_scan();
904#if LCD_DEPTH == 2 906#if LCD_DEPTH == 1
905 if (scanline_ind == 3)
906#else
907 if (scanline_ind == 7) 907 if (scanline_ind == 7)
908#elif LCD_DEPTH == 2
909 if (scanline_ind == 3)
908#endif 910#endif
909 { 911 {
912#if LCD_HEIGHT < 144
910 if(fb.mode!=3) 913 if(fb.mode!=3)
911 vid_update(L); 914 vid_update(L);
912 else 915 else
913 vid_update(L-((int)(L/9))); 916 vid_update(L-((int)(L/9)));
917#else
918 vid_update(L);
919#endif
914 } 920 }
915#if LCD_HEIGHT == 64 921#if LCD_DEPTH == 1
916 scanline_ind = (scanline_ind+1) % 8; 922 scanline_ind = (scanline_ind+1) % 8;
917#else 923#elif LCD_DEPTH == 2
918#if LCD_DEPTH == 2
919 scanline_ind = (scanline_ind+1) % 4; 924 scanline_ind = (scanline_ind+1) % 4;
920#else
921 scanline_ind = (scanline_ind+1) % 8;
922#endif
923#endif 925#endif
924} 926}
925 927
diff --git a/apps/plugins/rockboy/main.c b/apps/plugins/rockboy/main.c
index 175ae78d86..6a99f6aa88 100644
--- a/apps/plugins/rockboy/main.c
+++ b/apps/plugins/rockboy/main.c
@@ -84,6 +84,11 @@ int gnuboy_main(char *rom)
84 PUTS("Emu reset"); 84 PUTS("Emu reset");
85 emu_reset(); 85 emu_reset();
86 PUTS("Emu run"); 86 PUTS("Emu run");
87#if (LCD_HEIGHT > 144) || (LCD_WIDTH > 160)
88 rb->lcd_clear_display();
89 rb->lcd_drawrect((LCD_WIDTH-160)/2-1, (LCD_HEIGHT-144)/2-1, 162, 146);
90 rb->lcd_update();
91#endif
87 emu_run(); 92 emu_run();
88 93
89 // never reached 94 // never reached
diff --git a/apps/plugins/rockboy/sys_rockbox.c b/apps/plugins/rockboy/sys_rockbox.c
index e8a4923eee..b6408d53dc 100644
--- a/apps/plugins/rockboy/sys_rockbox.c
+++ b/apps/plugins/rockboy/sys_rockbox.c
@@ -36,12 +36,9 @@ rcvar_t vid_exports[] =
36}; 36};
37 37
38struct fb fb; 38struct fb fb;
39byte *video_base_buf;
40 39
41extern int debug_trace; 40extern int debug_trace;
42 41
43static byte frameb[145][160];
44
45void vid_settitle(char *title) 42void vid_settitle(char *title)
46{ 43{
47 rb->splash(HZ*2, true, title); 44 rb->splash(HZ*2, true, title);
@@ -124,7 +121,7 @@ void ev_poll(void)
124 ev_postevent(&ev); 121 ev_postevent(&ev);
125 } 122 }
126 if(pressed & ROCKBOY_MENU) { 123 if(pressed & ROCKBOY_MENU) {
127#if CONFIG_KEYPAD == IRIVER_H100_PAD 124#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
128 if (do_user_menu() == USER_MENU_QUIT) 125 if (do_user_menu() == USER_MENU_QUIT)
129#endif 126#endif
130 { 127 {
@@ -156,38 +153,32 @@ void vid_init(void)
156 fb.pitch=160; 153 fb.pitch=160;
157 fb.enabled=1; 154 fb.enabled=1;
158 fb.dirty=0; 155 fb.dirty=0;
159 video_base_buf=fb.ptr=(byte *)frameb;
160 fb.mode=3; 156 fb.mode=3;
161} 157}
162 158
159#ifdef HAVE_LCD_COLOR
160static const fb_data my_pal[4] = {
161 LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY, LCD_BLACK
162};
163#endif
164
163void vid_update(int scanline) 165void vid_update(int scanline)
164{ 166{
165 int cnt=0,scanline_remapped; 167 int cnt=0,scanline_remapped;
166 byte *frameb; 168 fb_data *frameb;
167#if LCD_HEIGHT == 64 /* Archos */ 169#if (LCD_HEIGHT == 64) && (LCD_DEPTH == 1) /* Archos */
168 int balance = 0; 170 int balance = 0;
169 if (fb.mode==1) 171 if (fb.mode==1)
170 scanline-=16; 172 scanline-=16;
171 else if (fb.mode==2) 173 else if (fb.mode==2)
172 scanline-=8; 174 scanline-=8;
173 scanline_remapped = scanline / 16; 175 scanline_remapped = scanline / 16;
174 frameb = rb->lcd_framebuffer + scanline_remapped * LCD_WIDTH; 176 frameb = rb->lcd_framebuffer + scanline_remapped * LCD_WIDTH;
175 while (cnt < 160) { 177 while (cnt < 160) {
176 balance += LCD_WIDTH; 178 balance += LCD_WIDTH;
177 if (balance > 0) 179 if (balance > 0)
178 { 180 {
179#ifdef SIMULATOR /* simulator uses C */ 181#if (CONFIG_CPU == SH7034) && !defined(SIMULATOR)
180 register unsigned scrbyte = 0;
181 if (scan.buf[0][cnt] & 0x02) scrbyte |= 0x01;
182 if (scan.buf[1][cnt] & 0x02) scrbyte |= 0x02;
183 if (scan.buf[2][cnt] & 0x02) scrbyte |= 0x04;
184 if (scan.buf[3][cnt] & 0x02) scrbyte |= 0x08;
185 if (scan.buf[4][cnt] & 0x02) scrbyte |= 0x10;
186 if (scan.buf[5][cnt] & 0x02) scrbyte |= 0x20;
187 if (scan.buf[6][cnt] & 0x02) scrbyte |= 0x40;
188 if (scan.buf[7][cnt] & 0x02) scrbyte |= 0x80;
189 *(frameb++) = scrbyte;
190#else
191 asm volatile ( 182 asm volatile (
192 "mov.b @%0,r0 \n" 183 "mov.b @%0,r0 \n"
193 "add %1,%0 \n" 184 "add %1,%0 \n"
@@ -234,25 +225,31 @@ void vid_update(int scanline)
234 : /* clobbers */ 225 : /* clobbers */
235 "r0", "r1" 226 "r0", "r1"
236 ); 227 );
228#else
229 register unsigned scrbyte = 0;
230 if (scan.buf[0][cnt] & 0x02) scrbyte |= 0x01;
231 if (scan.buf[1][cnt] & 0x02) scrbyte |= 0x02;
232 if (scan.buf[2][cnt] & 0x02) scrbyte |= 0x04;
233 if (scan.buf[3][cnt] & 0x02) scrbyte |= 0x08;
234 if (scan.buf[4][cnt] & 0x02) scrbyte |= 0x10;
235 if (scan.buf[5][cnt] & 0x02) scrbyte |= 0x20;
236 if (scan.buf[6][cnt] & 0x02) scrbyte |= 0x40;
237 if (scan.buf[7][cnt] & 0x02) scrbyte |= 0x80;
238 *(frameb++) = scrbyte;
237#endif 239#endif
238 balance -= 160; 240 balance -= 160;
239 } 241 }
240 cnt ++; 242 cnt ++;
241 } 243 }
242 rb->lcd_update_rect(0, (scanline/2) & ~7, LCD_WIDTH, 8); 244 rb->lcd_update_rect(0, (scanline/2) & ~7, LCD_WIDTH, 8);
243#else /* LCD_HEIGHT != 64, iRiver */ 245#elif (LCD_HEIGHT == 128) && (LCD_DEPTH == 2) /* iriver H1x0 */
244 if (fb.mode==1) 246 if (fb.mode==1)
245 scanline-=16; 247 scanline-=16;
246 else if (fb.mode==2) 248 else if (fb.mode==2)
247 scanline-=8; 249 scanline-=8;
248#if LCD_DEPTH == 2
249 scanline_remapped = scanline / 4; 250 scanline_remapped = scanline / 4;
250#else
251 scanline_remapped = scanline / 8;
252#endif
253 frameb = rb->lcd_framebuffer + scanline_remapped * LCD_WIDTH; 251 frameb = rb->lcd_framebuffer + scanline_remapped * LCD_WIDTH;
254 while (cnt < 160) { 252 while (cnt < 160) {
255#if LCD_DEPTH == 2
256 *(frameb++) = (scan.buf[0][cnt]&0x3) | 253 *(frameb++) = (scan.buf[0][cnt]&0x3) |
257 ((scan.buf[1][cnt]&0x3)<<2) | 254 ((scan.buf[1][cnt]&0x3)<<2) |
258 ((scan.buf[2][cnt]&0x3)<<4) | 255 ((scan.buf[2][cnt]&0x3)<<4) |
@@ -260,21 +257,12 @@ void vid_update(int scanline)
260 cnt++; 257 cnt++;
261 } 258 }
262 rb->lcd_update_rect(0, scanline & ~3, LCD_WIDTH, 4); 259 rb->lcd_update_rect(0, scanline & ~3, LCD_WIDTH, 4);
263#else 260#elif (LCD_HEIGHT >= 144) && defined(HAVE_LCD_COLOR) /* iriver H3x0, colour iPod */
264 register unsigned scrbyte = 0; 261 scanline_remapped = scanline + (LCD_HEIGHT-144)/2;
265 if (scan.buf[0][cnt] & 0x02) scrbyte |= 0x01; 262 frameb = rb->lcd_framebuffer + scanline_remapped * LCD_WIDTH + (LCD_WIDTH-160)/2;
266 if (scan.buf[1][cnt] & 0x02) scrbyte |= 0x02; 263 while (cnt < 160)
267 if (scan.buf[2][cnt] & 0x02) scrbyte |= 0x04; 264 *frameb++ = my_pal[scan.buf[0][cnt++]&0x3];
268 if (scan.buf[3][cnt] & 0x02) scrbyte |= 0x08; 265 rb->lcd_update_rect((LCD_WIDTH-160)/2, scanline_remapped, 160, 1);
269 if (scan.buf[4][cnt] & 0x02) scrbyte |= 0x10;
270 if (scan.buf[5][cnt] & 0x02) scrbyte |= 0x20;
271 if (scan.buf[6][cnt] & 0x02) scrbyte |= 0x40;
272 if (scan.buf[7][cnt] & 0x02) scrbyte |= 0x80;
273 *(frameb++) = scrbyte;
274 cnt++;
275 }
276 rb->lcd_update_rect(0, scanline & ~7, LCD_WIDTH, 8);
277#endif /* LCD_DEPTH */
278#endif /* LCD_HEIGHT */ 266#endif /* LCD_HEIGHT */
279} 267}
280 268