From ecbe84134d49c35e7440dc64dcd9feef77e7d1f4 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 3 Aug 2018 14:31:00 -0700 Subject: [PATCH] Add additional instructions. --- src/chalk/ir.cr | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/chalk/ir.cr b/src/chalk/ir.cr index 71d38cc..7f543fa 100644 --- a/src/chalk/ir.cr +++ b/src/chalk/ir.cr @@ -12,6 +12,33 @@ module Chalk end end + # Instruction to clear the screen + class ClearInstruction < Instruction + def to_s(io) + io << "clear" + end + + def to_bin(table, stack, index) + return 0x00e0 + end + end + + # Instruction to assign a random value to a register. + class RandomInstruction < Instruction + def initialize(@register : Int32, @value : Int32) + end + + def to_s(io) + io << "rand R" + @register.to_s(16, io) + io << " " << @value + end + + def to_bin(table, stack, index) + return 0xc000 | (@register << 8) | (@value) + end + end + # Instruction to load a value into a register. class LoadInstruction < Instruction def initialize(@register : Int32, @value : Int32) @@ -367,5 +394,34 @@ module Chalk return 0xf007 | (@into << 8) end end + + # Instruction to set the sound timer to a value. + class SetSoundTimerInstruction < Instruction + def initialize(@from : Int32) + end + + def to_s(io) + io << "set_sound R" + @from.to_s(16, io) + end + + def to_bin(table, stack, index) + return 0xf018 | (@from << 8) + end + end + + class BCDInstruction < Instruction + def initialize(@from : Int32) + end + + def to_s(io) + io << "bcd R" + @from.to_s(16, io) + end + + def to_bin(table, stack, index) + return 0xf033 | (@from << 8) + end + end end end