Module: ByteCompiler

Included in:
Gen3PokemonSaveLoader, Gen3PokemonStruct
Defined in:
lib/gen3_pokeedit/ByteCompiler.rb

Instance Method Summary collapse

Instance Method Details

#compile_bytes(*dat) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/gen3_pokeedit/ByteCompiler.rb', line 2

def compile_bytes(*dat)
  total_value = 0
  dat = dat[0]
  dat.each_index do |i|
    total_value += dat[i] << (8*i)
  end
  return total_value
end

#decompile_bytes(value, num_bytes) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/gen3_pokeedit/ByteCompiler.rb', line 11

def decompile_bytes(value, num_bytes)
  total_array = Array.new
  num_bytes.times do |i|
    total_array << ((value & (0xFF << 8*i)) >> 8*i)
  end
  return total_array
end

#set_bit(value, bit) ⇒ Object



19
20
21
# File 'lib/gen3_pokeedit/ByteCompiler.rb', line 19

def set_bit(value, bit)
  value = value | (1 << bit)
end

#unset_bit(value, bit) ⇒ Object



23
24
25
# File 'lib/gen3_pokeedit/ByteCompiler.rb', line 23

def unset_bit(value, bit)
  value = value & !(1 << bit)
end