Advertisement
uaa

binary 2 IchigoJam (bin2ij.pl) test

uaa
Jun 13th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. # display help message when no argument
  7. if (@ARGV < 2) {
  8. print "usage: $0 [binary] [line] [(step)]\n";
  9. exit;
  10. }
  11.  
  12. my $filename = $ARGV[0];
  13. my $line = $ARGV[1];
  14. my $step = 0;
  15. my $filesize = -s $filename;
  16. my $column = 16;
  17. my $address = 0x700;
  18. my $buf;
  19. my $j;
  20.  
  21. #check arguments
  22. if (@ARGV >= 3) {
  23. $step = $ARGV[2];
  24. }
  25. if ($step <= 0) {
  26. $step = 10;
  27. }
  28.  
  29. # load file
  30. open (FILE, '<' . $filename) or die "$!";
  31. binmode FILE;
  32. read (FILE, $buf, $filesize) or die "$!";
  33. close(FILE);
  34.  
  35. # convert
  36. my @data = unpack('C' . $filesize, $buf);
  37. for (my $i = 0; $i < $filesize; $i += $column) {
  38. printf("%d POKE #%03X,#%02X", $line, $address + $i, $data[$i]);
  39.  
  40. my $remain = $filesize - $i;
  41. if ($remain > $column) {
  42. $remain = $column;
  43. }
  44.  
  45. for (my $j = 1; $j < $remain; $j++) {
  46. printf(",#%02X", $data[$i + $j]);
  47. }
  48.  
  49. printf("\n");
  50. $line += $step;
  51. }
  52.  
  53. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement