Advertisement
Narzew

Unpack Byte v 1.0 and 2.0

Mar 24th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.37 KB | None | 0 0
  1. #===========================================================
  2. #**Moje metody z 2011 roku (nie wzorować się!!!)
  3. #**Narzew
  4. #===========================================================
  5.  
  6. class NRGSS
  7.  
  8.   #===========================================================
  9.   #**unpack_byte
  10.   #**Unpacks byte to letter
  11.   #**Odpakowuje bajt do litery
  12.   #**Narzew
  13.   #===========================================================
  14.  
  15.   def unpack_byte(byte)
  16.     result  = []
  17.     case byte
  18.     when 0 then result << '$NULL$'
  19.     when 1 then result << '$SOH$'
  20.     when 2 then result << '$STX$'
  21.     when 3 then result << '$ETX$'
  22.     when 4 then result << '$EOT$'
  23.     when 5 then result << '$ENQ$'
  24.     when 6 then result << '$ACK$'
  25.     when 7 then result << '$BEL$'
  26.     when 8 then result << '$BS$'
  27.     when 9 then result << '$TAB$'
  28.     when 10 then result << '$LF$'
  29.     when 11 then result << '$VT$'
  30.     when 12 then result << '$FF$'
  31.     when 13 then result << '$CR$'
  32.     when 14 then result << '$SO$'
  33.     when 15 then result << '$SI$'
  34.     when 16 then result << '$DLE$'
  35.     when 17 then result << '$DC1$'
  36.     when 18 then result << '$DC2$'
  37.     when 19 then result << '$DC3$'
  38.     when 20 then result << '$DC4$'
  39.     when 21 then result << '$NAK$'
  40.     when 22 then result << '$SYN$'
  41.     when 23 then result << '$ETB$'
  42.     when 24 then result << '$CAN$'
  43.     when 25 then result << '$EN$'
  44.     when 26 then result << '$SUB$'
  45.     when 27 then result << '$ESC$'
  46.     when 28 then result << '$FS$'
  47.     when 29 then result << '$GS$'
  48.     when 30 then result << '$RS$'
  49.     when 31 then result << '$US$'
  50.     when 32 then result << ' '
  51.     when 33 then result << '!'
  52.     when 34 then result << '\"'
  53.     when 35 then result << '#'
  54.     when 36 then result << '$'
  55.     when 37 then result << '%'
  56.     when 38 then result << '&'
  57.     when 39 then result << '\''
  58.     when 40 then result << '('
  59.     when 41 then result << ')'
  60.     when 42 then result << '*'
  61.     when 43 then result << '+'
  62.     when 44 then result << ','
  63.     when 45 then result << '-'
  64.     when 46 then result << '.'
  65.     when 47 then result << '/'
  66.     when 48 then result << '0'
  67.     when 49 then result << '1'
  68.     when 50 then result << '2'
  69.     when 51 then result << '3'
  70.     when 52 then result << '4'
  71.     when 53 then result << '5'
  72.     when 54 then result << '6'
  73.     when 55 then result << '7'
  74.     when 56 then result << '8'
  75.     when 57 then result << '9'
  76.     when 58 then result << ':'
  77.     when 59 then result << ';'
  78.     when 60 then result << '<'
  79.     when 61 then result << '='
  80.     when 62 then result << '>'
  81.     when 63 then result << '?'
  82.     when 64 then result << '@'
  83.     when 65 then result << 'A'
  84.     when 66 then result << 'B'
  85.     when 67 then result << 'C'
  86.     when 68 then result << 'D'
  87.     when 69 then result << 'E'
  88.     when 70 then result << 'F'
  89.     when 71 then result << 'G'
  90.     when 72 then result << 'H'
  91.     when 73 then result << 'I'
  92.     when 74 then result << 'J'
  93.     when 75 then result << 'K'
  94.     when 76 then result << 'L'
  95.     when 77 then result << 'M'
  96.     when 78 then result << 'N'
  97.     when 79 then result << 'O'
  98.     when 80 then result << 'P'
  99.     when 81 then result << 'Q'
  100.     when 82 then result << 'R'
  101.     when 83 then result << 'S'
  102.     when 84 then result << 'T'
  103.     when 85 then result << 'U'
  104.     when 86 then result << 'V'
  105.     when 87 then result << 'W'
  106.     when 88 then result << 'X'
  107.     when 89 then result << 'Y'
  108.     when 90 then result << 'Z'
  109.     when 91 then result << '['
  110.     when 92 then result << '\\'
  111.     when 93 then result << ']'
  112.     when 94 then result << '^'
  113.     when 95 then result << '_'
  114.     when 96 then result << '`'
  115.     when 97 then result << 'a'
  116.     when 98 then result << 'b'
  117.     when 99 then result << 'c'
  118.     when 100 then result << 'd'
  119.     when 101 then result << 'e'
  120.     when 102 then result << 'f'
  121.     when 103 then result << 'g'
  122.     when 104 then result << 'h'
  123.     when 105 then result << 'i'
  124.     when 106 then result << 'j'
  125.     when 107 then result << 'k'
  126.     when 108 then result << 'l'
  127.     when 109 then result << 'm'
  128.     when 110 then result << 'n'
  129.     when 111 then result << 'o'
  130.     when 112 then result << 'p'
  131.     when 113 then result << 'q'
  132.     when 114 then result << 'r'
  133.     when 115 then result << 's'
  134.     when 116 then result << 't'
  135.     when 117 then result << 'u'
  136.     when 118 then result << 'v'
  137.     when 119 then result << 'w'
  138.     when 120 then result << 'x'
  139.     when 121 then result << 'y'
  140.     when 122 then result << 'z'
  141.     when 123 then result << '{'
  142.     when 124 then result << '|'
  143.     when 125 then result << '}'
  144.     when 126 then result << '~'
  145.     when 127 then result << '$DEL$'
  146.     else
  147.       result << '$NOT$'
  148.     end
  149.     return result
  150.   end
  151.  
  152.   #===========================================================
  153.   #**unpack_clear_byte
  154.   #**Unpacks clear (>32) byte
  155.   #**Depakowuje czysty (>32) bajt
  156.   #**Narzew
  157.   #===========================================================
  158.  
  159.   def unpack_clear_byte(byte)
  160.     if byte <= 31
  161.       byte = 32
  162.     end
  163.     $nrgss.unpack_byte(byte)
  164.   end
  165.  
  166. end
  167.  
  168. #===========================================================
  169. #**Poprawne metody :D
  170. #**Działanie takie samo, ale ile mniej kodu ! :D
  171. #**Wzorować się jak najbardziej :D
  172. #===========================================================
  173.  
  174. def unpack_byte(x)
  175.   return x.chr
  176. end
  177.  
  178. def unpack_clear_byte(x)
  179.   return x.chr if x >= 32
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement