Class: Haxor::Vm::Cpu::Core
- Defined in:
- lib/haxor/vm/cpu/core.rb
Instance Attribute Summary collapse
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Attributes inherited from Subsystem
Instance Method Summary collapse
- #bind_opcode(opcode, object, method) ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #iterate ⇒ Object
- #operand ⇒ Object
- #operands ⇒ Object
- #register_unit(unit) ⇒ Object
- #reserved_mem ⇒ Object
Methods inherited from Subsystem
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/haxor/vm/cpu/core.rb', line 8 def initialize @units = [] @opcodes = {} register_unit Unit::Arithmetic.new register_unit Unit::Jumps.new register_unit Unit::Logical.new register_unit Unit::Transfer.new register_unit Unit::Various.new build_struct end |
Instance Attribute Details
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
6 7 8 |
# File 'lib/haxor/vm/cpu/core.rb', line 6 def labels @labels end |
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
5 6 7 |
# File 'lib/haxor/vm/cpu/core.rb', line 5 def struct @struct end |
Instance Method Details
#bind_opcode(opcode, object, method) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/haxor/vm/cpu/core.rb', line 21 def bind_opcode(opcode, object, method) fail "OpCode already defined - #{opcode}." if @opcodes.key? opcode @opcodes[opcode] = { object: object, method: method } end |
#iterate ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/haxor/vm/cpu/core.rb', line 29 def iterate opcode = subsystem(:mem).next_cell cmd = opcode & Consts::OPCODE_CMD_MASK subsystem(:mem).write 'op', opcode fail "Call to not existing opcode #{cmd}." unless @opcodes.key? cmd # puts 'cmd = ' + cmd.to_s(16) # puts flg.to_s(16) @opcodes[cmd][:object].send(@opcodes[cmd][:method]) end |
#operand ⇒ Object
50 51 52 53 54 55 |
# File 'lib/haxor/vm/cpu/core.rb', line 50 def operand flg = (subsystem(:mem).read 'op') & Consts::OPCODE_FLG_MASK a = subsystem(:mem).next_cell a = subsystem(:mem).read a if (flg & Consts::OPCODE_FLG_DA != 0) a end |
#operands ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/haxor/vm/cpu/core.rb', line 57 def operands flg = (subsystem(:mem).read 'op') & Consts::OPCODE_FLG_MASK a = subsystem(:mem).next_cell a = subsystem(:mem).read a if (flg & Consts::OPCODE_FLG_DA != 0) b = subsystem(:mem).next_cell b = subsystem(:mem).read b if (flg & Consts::OPCODE_FLG_DB != 0) [a, b] end |
#register_unit(unit) ⇒ Object
44 45 46 47 48 |
# File 'lib/haxor/vm/cpu/core.rb', line 44 def register_unit(unit) @units << unit unit.vm = self unit.register end |
#reserved_mem ⇒ Object
40 41 42 |
# File 'lib/haxor/vm/cpu/core.rb', line 40 def reserved_mem 1024 end |