comparison exporters.pde @ 91:892a06169bb5

Refactor machine program and source exporting.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Jul 2018 00:42:06 +0300
parents dffafe05d520
children 4161d798cb64
comparison
equal deleted inserted replaced
90:dffafe05d520 91:892a06169bb5
386 386
387 return g_template; 387 return g_template;
388 } 388 }
389 389
390 390
391 void machine_export(String fname, int sorsa) { 391 byte[] mpExportMachinePRG(bool sorsa)
392 int yy, xx, x, y2, y, checksum; 392 {
393 int xp, yp;
394 int valu, valu2;
395 int val1, val2, val3;
396 int ad, by;
397 int bri, skyp;
398 g_sorsaa = sorsa; //aargh another global
399
400 if (sorsa == 1) {
401 exwriter = createWriter(fname);
402 }
403
404 // any common text headers 393 // any common text headers
405 by = 0; 394 String src = ";machine=" + str(machine) + " (" + g_name + ")\n";
406 skyp = 0;
407 outputter(";machine=" + str(machine) + " (" + g_name + ")", true);
408 395
409 if (machine == C64) { //C64 HIRES 396 if (machine == C64) { //C64 HIRES
410 397
411 mpLoadTemplate("c64show.prg"); 398 mpLoadTemplate("c64show.prg");
412 mpSetDataOffs(0X0227); 399 mpSetDataOffs(0x0227);
413 mpExportBitmapData(40, 25); 400 src += mpExportBitmapData(40, 25);
414 mpSetDataOffs(0X2167); 401 mpSetDataOffs(0x2167);
415 mpWriteByte(g_map[0]); //=border 402 mpWriteByte(g_map[0]); //=border
416 mpSetDataOffs(0X2168); 403 mpSetDataOffs(0x2168);
417 mpWriteByte(g_map[1]); //=background mutta ei tarvita 404 mpWriteByte(g_map[1]); //=background mutta ei tarvita
418 mpSetDataOffs(0X2169); 405 mpSetDataOffs(0x2169);
419 outputter("; The following two first values are border and background", true); 406 src += "; The following two first values are border and background\n";
420 mpExportColorData(40, 25, 65536, 0); 407 mpExportColorData(40, 25, 65536, 0);
421 export_program(fname);
422 408
423 //c64show.prg 409 //c64show.prg
424 //offsets 410 //offsets
425 //0x0227->bitmappi (40x25 x 8 bytee) 411 //0x0227->bitmappi (40x25 x 8 bytee)
426 //0x2167:borderi väri 412 //0x2167:borderi väri
427 //0x2169->värikartta (40x25 bytee, nyppelit foreg/backg) 413 //0x2169->värikartta (40x25 bytee, nyppelit foreg/backg)
428 } 414 }
429 415 else
430 if (machine == C64M) { //C64 MULTICOLOR 416 if (machine == C64M) { //C64 MULTICOLOR
431 417
432 mpLoadTemplate("c64mshow.prg"); 418 mpLoadTemplate("c64mshow.prg");
433 mpSetDataOffs(0x0239); 419 mpSetDataOffs(0x0239);
434 mpExportBitmapData(40, 25); 420 src += mpExportBitmapData(40, 25);
435 421
436 // first color information 422 // first color information
437 mpSetDataOffs(0x2179); 423 mpSetDataOffs(0x2179);
438 mpWriteByte(g_map[0]); 424 mpWriteByte(g_map[0]);
439 mpSetDataOffs(0x217A); 425 mpSetDataOffs(0x217A);
440 mpWriteByte(g_map[1]); 426 mpWriteByte(g_map[1]);
441 mpSetDataOffs(0x217B); 427 mpSetDataOffs(0x217B);
442 outputter("; The following two first values are border and background", true); 428 src += "; The following two first values are border and background\n";
443 mpExportColorData(40, 25, 65536, 1); 429 mpExportColorData(40, 25, 65536, 1);
444 430
445 // second color information 431 // second color information
446 mpSetDataOffs(0x2563); 432 mpSetDataOffs(0x2563);
447 outputter("; The following goes to $D800 onwards", true); 433 src += "; The following goes to $D800 onwards\n";
448 mpExportColorData(40, 25, 65536 + 2000, 2); 434 mpExportColorData(40, 25, 65536 + 2000, 2);
449 export_program(fname);
450 435
451 //c64 multicolor 436 //c64 multicolor
452 //offsets 437 //offsets
453 //0x0239->bitmappi (40x25 x 8 bytee) 438 //0x0239->bitmappi (40x25 x 8 bytee)
454 //0x2179:borderi väri 439 //0x2179:borderi väri
455 //0x217A:bäkkis väri 440 //0x217A:bäkkis väri
456 //0x217B->värikartta 1 (40x25 bytee, nyppelit foreg/backg ilmeisesti) 441 //0x217B->värikartta 1 (40x25 bytee, nyppelit foreg/backg ilmeisesti)
457 //0x2563->värikartta 2 (40x25 bytee, nyppeli 3-väri nepan osoitteessa $d800-) 442 //0x2563->värikartta 2 (40x25 bytee, nyppeli 3-väri nepan osoitteessa $d800-)
458 } 443 }
459 444 else
460 if (machine == PLUS4M) { //PLUS4 MULTICOLOR 445 if (machine == PLUS4M) { //PLUS4 MULTICOLOR
461 mpLoadTemplate("showpfourm.prg"); 446 mpLoadTemplate("showpfourm.prg");
462 outputter(" .global _bitmap", true); 447 src += " .global _bitmap\n";
463 outputter(" .global _color1", true); 448 src += " .global _color1\n";
464 outputter(" .global _color2", true); 449 src += " .global _color2\n";
465 outputter(" .global _border", true); 450 src += " .global _border\n";
466 outputter(" .global _back1", true); 451 src += " .global _back1\n";
467 outputter(" .global _back2", true); 452 src += " .global _back2\n";
468 outputter("_bitmap:", true); 453 src += "_bitmap:\n";
469 mpSetDataOffs(0x013e); 454 mpSetDataOffs(0x013e);
470 mpExportBitmapData(40, 25); 455 src += mpExportBitmapData(40, 25);
471 outputter("_border:", true); 456 src += "_border:\n";
472 val1 = getpluscolor(int(g_map[0])); 457 val1 = getpluscolor(int(g_map[0]));
473 val2 = getplusluminance(int(g_map[0])); 458 val2 = getplusluminance(int(g_map[0]));
474 val3 = val2 * 16 + val1; 459 val3 = val2 * 16 + val1;
475 mpSetDataOffs(0x207e); 460 mpSetDataOffs(0x207e);
476 mpWriteByte(val3); 461 mpWriteByte(val3);
477 outputter(" .byte " + val3, true); 462 src += " .byte " + val3 +"\n";
478 outputter("_back1:", true); 463 src += "_back1:\n";
479 val1 = getpluscolor(int(g_map[1])); 464 val1 = getpluscolor(int(g_map[1]));
480 val2 = getplusluminance(int(g_map[1])); 465 val2 = getplusluminance(int(g_map[1]));
481 val3 = val2 * 16 + val1; 466 val3 = val2 * 16 + val1;
482 mpSetDataOffs(0x207f); 467 mpSetDataOffs(0x207f);
483 mpWriteByte(val3); 468 mpWriteByte(val3);
484 outputter(" .byte " + val3, true); 469 src += " .byte " + val3 +"\n";
485 outputter("_back2:", true); 470 src += "_back2:\n";
486 val1 = getpluscolor(int(g_map[2])); 471 val1 = getpluscolor(int(g_map[2]));
487 val2 = getplusluminance(int(g_map[2])); 472 val2 = getplusluminance(int(g_map[2]));
488 val3 = val2 * 16 + val1; 473 val3 = val2 * 16 + val1;
489 mpSetDataOffs(0x2080); 474 mpSetDataOffs(0x2080);
490 mpWriteByte(val3); 475 mpWriteByte(val3);
491 outputter(" .byte " + val3, true); 476 src += " .byte " + val3 +"\n";
492 outputter("_color1:", true); 477 src += "_color1:\n";
493 mpSetDataOffs(0x2081); 478 mpSetDataOffs(0x2081);
494 mpExportColorData(40, 25, 65536, 6); 479 mpExportColorData(40, 25, 65536, 6);
495 outputter("_color2:", true); 480 src += "_color2:\n";
496 mpSetDataOffs(0x2469); 481 mpSetDataOffs(0x2469);
497 mpExportColorData(40, 25, 65536, 7); 482 mpExportColorData(40, 25, 65536, 7);
498 export_program(fname);
499 //plus4 multic 483 //plus4 multic
500 //0x013e bitmap (40 x 25 x 8) 484 //0x013e bitmap (40 x 25 x 8)
501 //0x207e border 485 //0x207e border
502 //0x207f background 1 486 //0x207f background 1
503 //0x2080 background 2 487 //0x2080 background 2
504 //0x2081 colors (40 x 25) 488 //0x2081 colors (40 x 25)
505 //0x2469 luminance (40 x 25) 489 //0x2469 luminance (40 x 25)
506 } 490 }
507 491 else
508 if (machine == PLUS4) { // Plus 4 hires 492 if (machine == PLUS4) { // Plus 4 hires
509 mpLoadTemplate("showpfour.prg"); 493 mpLoadTemplate("showpfour.prg");
510 outputter(" .global _bitmap", true); 494 src += " .global _bitmap\n";
511 outputter(" .global _color", true); 495 src += " .global _color\n";
512 outputter(" .global _lumi", true); 496 src += " .global _lumi\n";
513 outputter(" .global _border", true); 497 src += " .global _border\n";
514 outputter("_bitmap:", true); 498 src += "_bitmap:\n";
515 mpSetDataOffs(0x0137); 499 mpSetDataOffs(0x0137);
516 mpExportBitmapData(40, 25); 500 src += mpExportBitmapData(40, 25);
517 val1 = getpluscolor(int(g_map[0])); 501 val1 = getpluscolor(int(g_map[0]));
518 val2 = getplusluminance(int(g_map[0])); 502 val2 = getplusluminance(int(g_map[0]));
519 val3 = val2 * 16 + val1; 503 val3 = val2 * 16 + val1;
520 mpSetDataOffs(0x2077); 504 mpSetDataOffs(0x2077);
521 mpWriteByte(val3); //border 505 mpWriteByte(val3); //border
522 506
523 mpSetDataOffs(0x2078); 507 mpSetDataOffs(0x2078);
524 mpExportColorData(40, 25, 65536, 4); //colors 508 mpExportColorData(40, 25, 65536, 4); //colors
525 mpSetDataOffs(0x2460); 509 mpSetDataOffs(0x2460);
526 mpExportColorData(40, 25, 65536, 5); //lumis 510 mpExportColorData(40, 25, 65536, 5); //lumis
527 export_program(fname);
528 //plus4 hires 511 //plus4 hires
529 //0x0137 bitmap (40 x 25 x 8) 512 //0x0137 bitmap (40 x 25 x 8)
530 //0x2077 borderi 513 //0x2077 borderi
531 //0x2078 colors (40 x 25) 514 //0x2078 colors (40 x 25)
532 //0x2460 luminance (40 x 25) 515 //0x2460 luminance (40 x 25)
533 } 516 }
534 517 else
535 if (machine == MSX) { // MSX 518 if (machine == MSX) { // MSX
536 mpLoadTemplate("msxshow.com"); 519 mpLoadTemplate("msxshow.com");
537 mpSetDataOffs(0x00f9); 520 mpSetDataOffs(0x00f9);
538 outputter(char(9) + ".globl _nimi1,_nimi2", true); 521 src += "\t.globl _nimi1,_nimi2\n";
539 outputter(char(9) + ".area _CODE", true); 522 src += "\t.area _CODE\n";
540 outputter("_nimi1:", true); 523 src += "_nimi1:\n";
541 mpExportBitmapData(32, 24); 524 src += mpExportBitmapData(32, 24);
542 mpSetDataOffs(0x18f9); 525 mpSetDataOffs(0x18f9);
543 //mpWriteByte(g_map[1]); //backg 526 //mpWriteByte(g_map[1]); //backg
544 //outputter("; The first following value is background", true); 527 //src += "; The first following value is background\n";
545 outputter("_nimi2:", true); 528 src += "_nimi2:\n";
546 mpExportColorData(32, 24, 65536, 3); //there's an exception for msx-style 529 src += mpExportColorData(32, 24, 65536, 3); //there's an exception for msx-style
547 export_program(fname);
548 //msx comm 530 //msx comm
549 //0x00f9 bitmap (32x24 x 8 bytes) 531 //0x00f9 bitmap (32x24 x 8 bytes)
550 //0x18f9 background color 532 //0x18f9 background color
551 //0x18fa colors (32*24 bytes) 533 //0x18fa colors (32*24 bytes)
552 } 534 }
553 535 else
554 if (machine == SPECTRUM) { // ZX Spectrum 536 if (machine == SPECTRUM) { // ZX Spectrum
555 537
556 //would need some cleaning up 538 //would need some cleaning up
557 539
558 // outputter(" .area _DATA",true); 540 // src += " .area _DATA\n";
559 // outputter(" .globl _taustakuva",true); 541 // src += " .globl _taustakuva\n\n";
560 // outputter("",true); 542 // src += "_taustakuva:\n";
561 // outputter("_taustakuva:",true);
562 mpLoadTemplate("specshow.tap"); 543 mpLoadTemplate("specshow.tap");
563 int stad; 544
564 545 int checksum = 0xc9;
565 checksum = 0xc9;
566 for (y = 0x1d24; y <= 0x1d3d; y++) { //1d3e 546 for (y = 0x1d24; y <= 0x1d3d; y++) { //1d3e
567 checksum = checksum ^ int(g_template[y]); 547 checksum = checksum ^ int(g_template[y]);
568 } 548 }
549
569 //TAP requires fiddling with the checksum 550 //TAP requires fiddling with the checksum
570 //println("Checksum:"+hex(checksum,2)); 551 //println("Checksum:"+hex(checksum,2));
571 mpSetDataOffs(0x0223); 552 mpSetDataOffs(0x0223);
572 outputter(".byte " + (str(g_map[0])) + " ;border", true); 553 src += ".byte " + (str(g_map[0])) + " ;border\n";
573 mpWriteByte(int(g_map[0])); 554 mpWriteByte(g_map[0]);
574 checksum = checksum ^ int(g_map[0]); 555 checksum = checksum ^ int(g_map[0]);
575 for (y = 0; y <= 2; y++) 556
576 for (y2 = 0; y2 <= 7; y2++) 557 for (int y = 0; y <= 2; y++)
577 for (yy = 0; yy <= 7; yy++) 558 for (int y2 = 0; y2 <= 7; y2++)
578 { 559 for (int yy = 0; yy <= 7; yy++)
579 outputter(".byte ", false); 560 {
580 for (x = 0; x <= 31; x++) 561 src += ".byte ";
562 for (int x = 0; x <= 31; x++)
581 { 563 {
582 yp = y * 64 + yy * 8 + y2; 564 int yp = y * 64 + yy * 8 + y2,
583 xp = x; 565 ad = 1024 + yp * 256 + x * 8,
584 ad = 1024 + yp * 256 + x * 8; 566 valu = g_map[ad + 0] * 128 + g_map[ad + 1] * 64 + g_map[ad + 2] * 32 + g_map[ad + 3] * 16 + g_map[ad + 4] * 8 + g_map[ad + 5] * 4 + g_map[ad + 6] * 2 + g_map[ad + 7] * 1;
585 valu = g_map[ad + 0] * 128 + g_map[ad + 1] * 64 + g_map[ad + 2] * 32 + g_map[ad + 3] * 16 + g_map[ad + 4] * 8 + g_map[ad + 5] * 4 + g_map[ad + 6] * 2 + g_map[ad + 7] * 1; 567
586 outputter(str(int(valu)), false); 568 src += str(valu);
587 by++; 569 mpWriteByte(valu);
588 mpWriteByte(int(valu));
589 checksum = checksum ^ int(valu); 570 checksum = checksum ^ int(valu);
590 if (x <= 30) { 571 if (x <= 30) {
591 outputter(",", false); 572 src += ",";
592 } 573 }
593 } 574 }
594 outputter("", true); 575 src += "\n";
595 } 576 }
596 577
597 outputter("; attributes", true); 578 src += "; attributes\n";
598 for (y = 0; y <= 24; y++) 579 for (int y = 0; y < 24; y++)
599 { 580 {
600 outputter(".byte ", false); 581 src += ".byte ";
601 for (x = 0; x <= 31; x++) 582 for (int x = 0; x < 32; x++)
602 { 583 {
603 ad = 65536 + x + y * 256; 584 int ad = 65536 + x + y * 256,
604 valu = int(g_map[ad]); 585 valu = int(g_map[ad]),
605 valu2 = int(g_map[ad + MX * MY * 8]); 586 valu2 = int(g_map[ad + MX * MY * 8]),
606 bri = 0; 587 bri = 0;
607 if (valu >= 8) { 588
589 if (valu >= 8)
590 {
608 bri = 1; 591 bri = 1;
609 valu = valu - 8; 592 valu = valu - 8;
610 valu2 = valu2 - 8; 593 valu2 = valu2 - 8;
611 if (valu2 <= 0) { 594 if (valu2 <= 0) {
612 valu2 = 0; 595 valu2 = 0;
613 } 596 }
614 } 597 }
615 if (bri == 1) { 598 if (bri == 1) {
616 valu = valu + 64; 599 valu = valu + 64;
617 } 600 }
618 outputter(str(valu + valu2 * 8), false); 601
619 by++; 602 src += str(valu + valu2 * 8);
620 mpWriteByte(int(valu + valu2 * 8)); 603 mpWriteByte(valu + valu2 * 8);
621 checksum = checksum ^ int(valu + valu2 * 8); 604 checksum = checksum ^ int(valu + valu2 * 8);
622 if (x <= 30) { 605 if (x <= 30) {
623 outputter(",", false); 606 src += ",";
624 } 607 }
625 } 608 }
626 outputter("", true); 609 src += "\n";
627 } 610 }
628 //println("checksum:"+hex(checksum,2)); 611 //println("checksum:"+hex(checksum,2));
629 mpSetDataOffs(0x1d3e); 612 mpSetDataOffs(0x1d3e);
630 mpWriteByte(int(checksum)); 613 mpWriteByte(int(checksum));
631 export_program(fname); 614 }
632 } 615 else
633
634 if (machine == CPC) { 616 if (machine == CPC) {
617 int val1, val2, val3, valu;
635 mpLoadTemplate("cpc-mode0.bin"); 618 mpLoadTemplate("cpc-mode0.bin");
636 619
637 mpSetDataOffs(69); //bitmap offset 620 mpSetDataOffs(69); //bitmap offset
638 mpExportBitmapData_CPC(160, 200); 621 src += mpExportBitmapData_CPC(160, 200);
639 mpSetDataOffs(16453); 622 mpSetDataOffs(16453);
640 outputter(";palette", true); 623 src += ";palette\n";
641 outputter(".byte ", false); 624 src += ".byte ";
625
642 //fixed # of palette entries, just trying to be generic 626 //fixed # of palette entries, just trying to be generic
643 for (int i = 0; i < g_maxcolors; i++) 627 for (int i = 0; i < g_maxcolors; i++)
644 { 628 {
645 val1 = int(g_g[i] / (256 / g_palsteps)); 629 val1 = int(g_g[i] / (256 / g_palsteps));
646 val2 = int(g_r[i] / (256 / g_palsteps)); 630 val2 = int(g_r[i] / (256 / g_palsteps));
647 val3 = int(g_b[i] / (256 / g_palsteps)); 631 val3 = int(g_b[i] / (256 / g_palsteps));
632
648 mpWriteByte(val1 * 9 + val2 * 3 + val3); 633 mpWriteByte(val1 * 9 + val2 * 3 + val3);
649 outputter(str(val1 * 9 + val2 * 3 + val3), false); 634 src += str(val1 * 9 + val2 * 3 + val3);
650 if (i < g_maxcolors - 1) { 635 if (i < g_maxcolors - 1) {
651 outputter(",", false); 636 src += ",";
652 } 637 }
653 } 638 }
654 outputter("", true); 639
655 outputter(";border", true);
656 outputter(".byte ", false);
657 mpSetDataOffs(16469);
658 valu = int(g_map[0]); 640 valu = int(g_map[0]);
659 val1 = int(g_g[valu] / (256 / g_palsteps)); 641 val1 = int(g_g[valu] / (256 / g_palsteps));
660 val2 = int(g_r[valu] / (256 / g_palsteps)); 642 val2 = int(g_r[valu] / (256 / g_palsteps));
661 val3 = int(g_b[valu] / (256 / g_palsteps)); 643 val3 = int(g_b[valu] / (256 / g_palsteps));
644
645 src += "\n";
646 src += ";border\n";
647 src += ".byte ";
648
649 mpSetDataOffs(16469);
650
662 mpWriteByte(val1 * 9 + val2 * 3 + val3); 651 mpWriteByte(val1 * 9 + val2 * 3 + val3);
663 outputter(str(val1 * 9 + val2 * 3 + val3), false); 652 src += str(val1 * 9 + val2 * 3 + val3);
664 //cpc 653 //cpc
665 //69 bitmap 16384 bytes 654 //69 bitmap 16384 bytes
666 //16453 palette 16 bytes (0..26) 655 //16453 palette 16 bytes (0..26)
667 //16469 border color (0..26) 656 //16469 border color (0..26)
668 export_program(fname); 657 }
669 } 658 else
659 return null;
670 660
671 // any common lead-outs 661 // any common lead-outs
672 662 if (sorsa)
673 if (sorsa == 1) { 663 return src;
674 exwriter.flush(); 664 else
675 exwriter.close(); 665 return g_template;
676 } 666 }
677 } 667
678 668
679 669 String mpExportBitmapData_CPC(int xwid, int yy)
680 void mpExportBitmapData_CPC(int xwid, int yy)
681 { 670 {
682 int x, y, ad, val1, val2, y2; 671 int x, y, ad, val1, val2, y2;
683 int pix0b0, pix0b1, pix0b2, pix0b3; 672 int pix0b0, pix0b1, pix0b2, pix0b3;
684 int pix1b0, pix1b1, pix1b2, pix1b3; 673 int pix1b0, pix1b1, pix1b2, pix1b3;
685 int pp; 674 String src = ";bitmap\n";
686 pp = 0; 675
687 outputter(";bitmap", true); 676 for (y2 = 0; y2 < 8; y2++)
688 for (y2 = 0; y2 <= 7; y2++) { 677 {
689 for (y = 0; y < 25; y++) { 678 for (y = 0; y < 25; y++)
690 outputter(" .byte ", false); 679 {
680 src += " .byte ";
691 for (x = 0; x < int(xwid / 2); x++) { 681 for (x = 0; x < int(xwid / 2); x++) {
692 ad = 1024 + (y * 8) * X + (y2 * X) + x * 4; 682 ad = 1024 + (y * 8) * X + (y2 * X) + x * 4;
693 683
694 val1 = int(g_map[ad]); 684 val1 = int(g_map[ad]);
695 pix0b0 = 0; 685 pix0b0 = 0;
711 if ((val1 & 2) != 0) pix1b1 = 1; 701 if ((val1 & 2) != 0) pix1b1 = 1;
712 if ((val1 & 4) != 0) pix1b2 = 1; 702 if ((val1 & 4) != 0) pix1b2 = 1;
713 if ((val1 & 8) != 0) pix1b3 = 1; 703 if ((val1 & 8) != 0) pix1b3 = 1;
714 704
715 val2 = pix1b3 + pix0b3 * 2 + pix1b1 * 4 + pix0b1 * 8 + pix1b2 * 16 + pix0b2 * 32 + pix1b0 * 64 + pix0b0 * 128; 705 val2 = pix1b3 + pix0b3 * 2 + pix1b1 * 4 + pix0b1 * 8 + pix1b2 * 16 + pix0b2 * 32 + pix1b0 * 64 + pix0b0 * 128;
716 outputter(str(int(val2)), false); 706
707 src += str(int(val2));
717 mpWriteByte(val2); 708 mpWriteByte(val2);
718 pp++; 709
719 if (x < int(xwid / 2) - 1) { 710 if (x < int(xwid / 2) - 1) {
720 outputter(",", false); 711 src += ",";
721 } 712 }
722 } 713 }
723 outputter("", true); 714 src += "\n";
724 } 715 }
725 outputter(" .byte ", false); 716 src += " .byte ";
726 for (int j = 0; j <= 47; j++) { 717
718 for (int j = 0; j <= 47; j++)
719 {
727 mpWriteByte(0); 720 mpWriteByte(0);
728 outputter(str(int(0)), false); 721 src += str(int(0));
729 pp++;
730 if (j < 47) { 722 if (j < 47) {
731 outputter(",", false); 723 src += ",";
732 } 724 }
733 } 725 }
734 outputter("", true); 726 src += "\n";
735 } 727 }
736 outputter("", true); 728 src += "\n";
737 } 729 return src;
738 730 }
739 731
740 void mpExportBitmapData(int xx, int yy) 732
733 String mpExportBitmapData(int xx, int yy)
741 { 734 {
742 int xwid, ywid, x, y, y2, value, ad, linep; 735 String src = "";
743 linep = 0; 736 //String src = "unsigned char img[]={";
744 xwid = xx * 8; 737
745 ywid = yy * 8; 738 int linep = 0,
746 //outputter("unsigned char img[]={",false); 739 xwid = xx * 8,
747 740 ywid = yy * 8;
748 for (y = 0; y < yy; y++) { 741
749 for (x = 0; x < xx; x++) { 742 for (int y = 0; y < yy; y++)
750 // outputter(" .byte ", false); 743 for (int x = 0; x < xx; x++)
751 outputter(char(9) + ".db ", false); 744 {
752 for (y2 = 0; y2 <= 7; y2++) { 745 // src += " .byte ";
753 ad = 1024 + y * (xwid * 8) + (y2 * xwid) + x * 8; 746 src += "\t.db ";
754 value = g_map[ad + 0] * 128 + g_map[ad + 1] * 64 + g_map[ad + 2] * 32 + g_map[ad + 3] * 16 + g_map[ad + 4] * 8 + g_map[ad + 5] * 4 + g_map[ad + 6] * 2 + g_map[ad + 7] * 1; 747 for (int y2 = 0; y2 < 8; y2++)
755 outputter(str(int(value)), false); 748 {
756 mpWriteByte(int(value)); 749 int ad = 1024 + y * (xwid * 8) + (y2 * xwid) + x * 8;
757 if (y2 <= 6) { 750 int value =
758 outputter(",", false); 751 g_map[ad + 0] * 128 +
759 } 752 g_map[ad + 1] * 64 +
760 } 753 g_map[ad + 2] * 32 +
761 outputter("", true); 754 g_map[ad + 3] * 16 +
762 linep++; 755 g_map[ad + 4] * 8 +
763 if (linep == xx) { 756 g_map[ad + 5] * 4 +
764 linep = 0; 757 g_map[ad + 6] * 2 +
765 outputter("", true); 758 g_map[ad + 7] * 1;
766 } 759
767 } 760 src += str(int(value));
768 } 761 mpWriteByte(int(value));
769 outputter("", true); 762
770 } 763 if (y2 <= 6) {
771 764 src += ",";
772 765 }
773 int convertlumi(int l, int f) { 766 }
767 src += "\n";
768 if (++linep == xx)
769 {
770 linep = 0;
771 src += "\n";
772 }
773 }
774 src += "\n";
775
776 return src;
777 }
778
779
780 int convertluminance(int l, int f)
781 {
774 int res = 0; 782 int res = 0;
775 if (f == 0) return 0; 783 if (f == 0) return 0;
776 if (l == 0) res = 0 + f; 784 if (l == 0) res = 0 + f;
777 if (l == 1) res = 15 + f; 785 if (l == 1) res = 15 + f;
778 if (l == 2) res = 30 + f; 786 if (l == 2) res = 30 + f;
782 if (l == 6) res = 90 + f; 790 if (l == 6) res = 90 + f;
783 if (l == 7) res = 105 + f; 791 if (l == 7) res = 105 + f;
784 return res; 792 return res;
785 } 793 }
786 794
787 int getplusluminance(int c) { 795
796 int getplusluminance(int c)
797 {
788 int res = 0; 798 int res = 0;
789 if (c == 0) res = 0; 799 if (c == 0) res = 0;
790 if (c >= 1 && c <= 15) res = 0; 800 if (c >= 1 && c <= 15) res = 0;
791 if (c >= 16 && c <= 30) res = 1; 801 if (c >= 16 && c <= 30) res = 1;
792 if (c >= 31 && c <= 45) res = 2; 802 if (c >= 31 && c <= 45) res = 2;
796 if (c >= 91 && c <= 105) res = 6; 806 if (c >= 91 && c <= 105) res = 6;
797 if (c >= 106 && c <= 120) res = 7; 807 if (c >= 106 && c <= 120) res = 7;
798 return res; 808 return res;
799 } 809 }
800 810
801 int getpluscolor(int c) { 811
812 int getpluscolor(int c)
813 {
802 int res = 0; 814 int res = 0;
803 if (c == 0) res = 0; 815 if (c == 0) res = 0;
804 if (c >= 1 && c <= 15) res = c; 816 if (c >= 1 && c <= 15) res = c;
805 if (c >= 16 && c <= 30) res = c - 15; 817 if (c >= 16 && c <= 30) res = c - 15;
806 if (c >= 31 && c <= 45) res = c - 30; 818 if (c >= 31 && c <= 45) res = c - 30;
810 if (c >= 91 && c <= 105) res = c - 90; 822 if (c >= 91 && c <= 105) res = c - 90;
811 if (c >= 106 && c <= 120) res = c - 105; 823 if (c >= 106 && c <= 120) res = c - 105;
812 return res; 824 return res;
813 } 825 }
814 826
815 void mpExportColorData(int xx, int yy, int source, int param) { 827
816 int x, y, y2, valu, valu2, kalu, muista, ad, linep, xwid, ywid, xoor, yline, myrpsi; 828 String mpExportColorData(int xx, int yy, int source, int param)
829 {
830 int valu, valu2, kalu, muista, ad, linep, xwid, ywid, xoor, yline, myrpsi;
831 String src = "";
832
817 xwid = xx * 8; 833 xwid = xx * 8;
818 ywid = yy * 8; 834 ywid = yy * 8;
819 valu = 0; 835
820 valu2 = 0;
821 myrpsi = 0; 836 myrpsi = 0;
822 xoor = xx; 837 xoor = xx;
838
823 if (param == 0 || param == 4 || param == 5) { 839 if (param == 0 || param == 4 || param == 5) {
824 xoor = xx * 8; 840 xoor = xx * 8;
825 } 841 }
826 if (machine == MSX) { 842 if (machine == MSX) {
827 myrpsi = 7; 843 myrpsi = 7;
828 } 844 }
829 if (param < 2) { 845 if (param < 2) {
830 outputter("colora:", true); 846 src += "colora:\n";
831 } 847 }
832 if (param == 2) { 848 if (param == 2) {
833 outputter("colorb:", true); 849 src += "colorb:\n";
834 } 850 }
835 if (param < 2) { 851 if (param < 2) {
836 outputter(" .byte " + int(g_map[0]) + "," + int(g_map[1]), true); 852 src += " .byte " + int(g_map[0]) + "," + int(g_map[1]) +"\n";
837 } 853 }
838 if (param == 3) { 854 if (param == 3) {
839 // outputter("color:", true); 855 // src += "color:\n";
840 // outputter(" .byte ", false); 856 // src += " .byte ";
841 // outputter(g_map[0]+" ", true); 857 // src += g_map[0]+" \n";
842 xoor = xx * 8; 858 xoor = xx * 8;
843 } 859 }
844 if (param == 4) { 860 if (param == 4) {
845 outputter("_border:", true); 861 src += "_border:\n";
846 outputter(" .byte ", false); 862 src += " .byte ";
847 kalu = getpluscolor(int(g_map[0])); 863 kalu = getpluscolor(int(g_map[0]));
848 valu2 = getplusluminance(int(g_map[0])); 864 valu2 = getplusluminance(int(g_map[0]));
849 valu = valu2 * 16 + kalu; 865 valu = valu2 * 16 + kalu;
850 outputter(valu + " ", true); 866 src += valu + " \n";
851 outputter("_color:", true); 867 src += "_color:\n";
852 } 868 }
853 if (param == 5) { 869 if (param == 5) {
854 outputter("_lumi:", true); 870 src += "_lumi:\n";
855 } 871 }
856 for (y = 0; y < yy; y++) { 872
857 //outputter(" .byte ", false); 873 for (int y = 0; y < yy; y++)
858 outputter(char(9) + ".db ", false); 874 {
859 for (x = 0; x < xx; x++) { 875 //src += " .byte ";
860 for (yline = 0; yline <= myrpsi; yline++) { 876 src += "\t.db ";
861 ad = source + x + y * xoor + yline * xx; 877 for (int x = 0; x < xx; x++)
862 if (param == 0) { 878 for (yline = 0; yline <= myrpsi; yline++)
879 {
880 ad = source + x + y * xoor + yline * xx;
881
882 switch (param)
883 {
884 case 0:
863 valu = int(g_map[ad]); 885 valu = int(g_map[ad]);
864 valu2 = int(g_map[ad + MX * MY * 8]); 886 valu2 = int(g_map[ad + MX * MY * 8]);
865 } 887 break;
866 if (param == 1) { 888
889 case 1:
867 valu2 = int(g_map[ad]); 890 valu2 = int(g_map[ad]);
868 valu = int(g_map[ad + 1000]); 891 valu = int(g_map[ad + 1000]);
869 } 892 break;
870 if (param == 2) { 893
894 case 2:
871 valu2 = int(g_map[ad]); 895 valu2 = int(g_map[ad]);
872 valu = 0; 896 valu = 0;
873 } 897 break;
874 if (param == 3) { 898
899 case 3:
875 valu = int(g_map[ad]); 900 valu = int(g_map[ad]);
876 valu2 = int(g_map[ad + MX * MY * 8]); 901 valu2 = int(g_map[ad + MX * MY * 8]);
877 } 902 break;
878 903
879 if (param == 4) { //plus4 colortable 904 case 4:
880 kalu = int(g_map[ad]); 905 //plus4 colortable
881 valu = getpluscolor(kalu); 906 valu = getpluscolor(int(g_map[ad]));
882 kalu = int(g_map[ad + MX * MY * 8]); 907 valu2 = getpluscolor(int(g_map[ad + MX * MY * 8]));
883 valu2 = getpluscolor(kalu); 908 break;
884 } 909
885 910 case 5:
886 if (param == 5) { //plus4 lumitable 911 //plus4 lumitable
887 kalu = int(g_map[ad]); 912 valu = getplusluminance(int(g_map[ad + MX * MY * 8]));
888 valu2 = getplusluminance(kalu); 913 valu2 = getplusluminance(int(g_map[ad]));
889 kalu = int(g_map[ad + MX * MY * 8]); 914 break;
890 valu = getplusluminance(kalu); 915
891 } 916 case 6:
892 917 //plus4 multic1
893 if (param == 6) { //plus4 multic1
894 valu2 = getpluscolor(int(g_map[ad])); 918 valu2 = getpluscolor(int(g_map[ad]));
895 valu = getpluscolor(int(g_map[ad + 1000])); 919 valu = getpluscolor(int(g_map[ad + 1000]));
896 } 920 break;
897 921
898 if (param == 7) { //plus4 multic2 922 case 7:
923 //plus4 multic2
899 valu = getplusluminance(int(g_map[ad])); 924 valu = getplusluminance(int(g_map[ad]));
900 valu2 = getplusluminance(int(g_map[ad + 1000])); 925 valu2 = getplusluminance(int(g_map[ad + 1000]));
901 } 926 break;
902 927
903 outputter(str(valu * 16 + valu2), false); 928 default:
904 mpWriteByte(int(valu * 16 + valu2)); 929 return null;
905 if (x < (xx - 1) || yline < myrpsi) { 930 }
906 outputter(",", false); 931
907 } 932 src += str(valu * 16 + valu2);
908 } 933 mpWriteByte(valu * 16 + valu2);
909 } 934 if (x < (xx - 1) || yline < myrpsi)
910 outputter("", true); 935 {
911 } 936 src += ",";
912 outputter("", true); 937 }
913 } 938 }
914 939 src += "\n";
915 void import_program(String fname) { 940 }
916 g_template = mpLoadBinaryFile(fname); 941 src += "\n";
917 }
918
919 void export_program(String fname) {
920 if (g_sorsaa != 1)
921 mpSaveBinaryFile(fname, g_template);
922 }
923
924 void outputter(String oput, boolean eol) {
925 if (g_sorsaa == 0) return;
926 if (eol == false) exwriter.print(oput);
927 if (eol == true) exwriter.println(oput);
928 } 942 }
929 943
930 944
931 void import_image(String name) { 945 void import_image(String name) {
932 PImage image; 946 PImage image;