Module: Haxor::Utils
- Defined in:
- lib/haxor/utils.rb
Class Method Summary collapse
- .decode_opcode(opcode) ⇒ Object
- .encode_opcode(cmd = 0, flags = 0, reg1 = 0, reg2 = 0, reg3 = 0, imm = 0) ⇒ Object
Class Method Details
.decode_opcode(opcode) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/haxor/utils.rb', line 13 def self.decode_opcode(opcode) r = OpenStruct.new r.cmd = opcode & 0x7f r.flags = (opcode >> 7) & 0x03 r.reg1 = (opcode >> 9) & 0x3f r.reg2 = (opcode >> 15) & 0x3f r.reg3 = (opcode >> 21) & 0x3f r.imm = (opcode >> 27) r end |
.encode_opcode(cmd = 0, flags = 0, reg1 = 0, reg2 = 0, reg3 = 0, imm = 0) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/haxor/utils.rb', line 3 def self.encode_opcode(cmd = 0, flags = 0, reg1 = 0, reg2 = 0, reg3 = 0, imm = 0) result = cmd result |= flags << 7 result |= reg1 << 9 result |= reg2 << 15 result |= reg3 << 21 result |= imm << 27 result end |