убрал лишние абстракции

This commit is contained in:
Дмитриев Odebe Михаил 2020-07-31 20:47:31 +03:00
parent 5111a36b03
commit 794ead8d74
5 changed files with 5 additions and 67 deletions

View file

@ -2,7 +2,4 @@
require "./vm/keyboard.cr"
require "./vm/stack.cr"
require "./vm/video.cr"
require "./vm/registers.cr"
require "./vm/opcode.cr"
require "./vm/memory.cr"
require "./vm/interpreter.cr"

View file

@ -29,11 +29,12 @@ class Vm::Interpreter
def initialize(@file : File, @debug : Bool = false)
@stack = Vm::Stack(UInt16).new
@registers = Vm::Registers(UInt8).new
@memory = Vm::Memory.new
@registers = Array(UInt8).new(16, 0)
@memory = Array(UInt8).new(4096, 0)
@keyboard = Vm::Keyboard.new
@video = Vm::Video.new
@audio_timer = 0_u8
@delay_timer = 0_u8
@i = 0_u16
@ -262,7 +263,7 @@ class Vm::Interpreter
end
def read_opcode
Vm::OpCode.new((@memory[@pc].to_u16 << 8) | @memory[@pc + 1])
(@memory[@pc].to_u16 << 8) | @memory[@pc + 1]
end
def next_code!

View file

@ -1,23 +0,0 @@
class Vm::Memory
getter values
def initialize
@values = Array(UInt8).new(4096, 0)
end
def size
@values.size
end
def [](i)
@values[i]
end
def [](r : Range(UInt16, UInt16))
@values[r]
end
def []=(i , v : UInt8)
@values[i] = v
end
end

View file

@ -1,14 +0,0 @@
struct Vm::OpCode
getter bytes
def initialize(@bytes : UInt16)
end
def to_s
bytes.to_s(16)
end
def &(i)
bytes & i
end
end

View file

@ -1,23 +0,0 @@
class Vm::Registers(T)
getter values
def initialize
@values = Array(T).new(16, 0)
end
def [](i)
@values[i]
end
def []=(i, v : T)
@values[i] = v
end
def [](r : Range(UInt8, UInt8))
@values[r]
end
def to_s
@values.map_with_index { |e, i| "v#{i}[#{e}]" }.join(", ")
end
end