lib/haxor/vm/os.rb in haxor-0.3.0 vs lib/haxor/vm/os.rb in haxor-0.4.0

- old
+ new

@@ -1,17 +1,16 @@ module Haxor module Vm class Os < Subsystem TABLE = { - 0x01 => :sys_exit, - 0x02 => :sys_printf, - 0x03 => :sys_scanf, - 0x04 => :sys_rand + 0x01 => :sys_printf, + 0x02 => :sys_scanf, + 0x03 => :sys_rand } def syscall - func = subsystem(:mem).read 'sc' + func = subsystem(:cpu).reg(Vm::Cpu::Core::REG_SYSCALL) send(TABLE[func]) end def collect_string(addr) i = 0 @@ -48,18 +47,12 @@ end types end - def sys_exit - code = subsystem(:stack).pop_value - exit code - end - def sys_printf fd = subsystem(:stack).pop_value - x = subsystem(:stack).pop_value fmt = collect_string x args = [] parse_format(fmt).each do |type| case type @@ -83,11 +76,11 @@ file = IO.new(fd, 'r') result = file.scanf fmt if result.size != types.size - subsystem(:mem).write 'sc', -1 + subsystem(:cpu).reg Vm::Cpu::Core::REG_SYSCALL, -1 return end types.each do |type| value = result.shift @@ -106,10 +99,11 @@ def sys_rand min = subsystem(:stack).pop_value max = subsystem(:stack).pop_value prng = Random.new - subsystem(:stack).push_value prng.rand(min..max) + v = prng.rand(min..max) + subsystem(:stack).push_value v end end end end