home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / Generate / vdpdraw.pl < prev   
Encoding:
Perl Script  |  2006-10-19  |  1.1 KB  |  66 lines

  1. #!/usr/bin/perl -w
  2.  
  3. print "#include \"16bit.h\"\n";
  4. print "#if __i386__ || __INTEL__\n";
  5.  
  6. $big = 0;
  7. while ($big < 2) {
  8.   $i = 0;
  9.   while ($i < 256) {
  10.       # for each byte, try to write two longs
  11.       # in the form:
  12.       #  *(u32 *)o = 0x01010001*f | 0x00000100*b;
  13.  
  14.     print "static void drawrow$i(u8 *o,u8 f,u8 b)\n{\n";
  15.  
  16.     $j = 0;
  17.     while ($j < 8) {
  18.         if ($j == 0 || $j == 4) {
  19.             $f = "0x";
  20.             $b = "0x";
  21.         }
  22.         if (!$big) {
  23.             if ($i & (1 << $j))  {
  24.                 $f .= "01" ; $b .= "00";
  25.             } else {
  26.                 $b .= "01" ; $f .= "00";
  27.             }
  28.         } else {
  29.             if ($i & (0x80 >> $j)) {
  30.                 $f .= "01" ; $b .= "00";
  31.             } else {
  32.                 $b .= "01" ; $f .= "00";
  33.             }
  34.         }
  35.         $j++;
  36.  
  37.         # half done, write a long
  38.         if ($j == 4) {
  39.             print "\t*(u32 *)o = ($f * f) | ($b * b);\n";
  40.             
  41.         } elsif ($j == 8) {
  42.             print "\t*(u32 *)(o+4) = ($f * f) | ($b * b);\n";
  43.         }
  44.     }
  45.  
  46.     print "}\n";
  47.     $i++;
  48.   }
  49.   $big++;
  50.   if ($big == 1) {
  51.       print "\n#else /* big-endian */\n";
  52.   }
  53. }
  54. print "\n#endif /* endianness */\n";
  55.  
  56. print "\nvoid (*vdpdrawrow[])(u8 *,u8,u8)=\n{\n";
  57. $i = 0;
  58. while ($i < 256) {
  59.     print "drawrow$i,";
  60.     if ($i % 6 == 5) {
  61.         print "\n";
  62.     }
  63.     $i++;
  64. }
  65. print "};\n";
  66.