diff --git a/src/chalk/compiler.cr b/src/chalk/compiler.cr index 843edd7..c028df4 100644 --- a/src/chalk/compiler.cr +++ b/src/chalk/compiler.cr @@ -46,6 +46,9 @@ module Chalk table["draw"] = FunctionEntry.new InlineDrawFunction.new table["get_key"] = FunctionEntry.new InlineAwaitKeyFunction.new + table["get_font"] = FunctionEntry.new InlineGetFontFunction.new + table["set_delay"] = FunctionEntry.new InlineSetDelayFunction.new + table["get_delay"] = FunctionEntry.new InlineGetDelayFunction.new return table end diff --git a/src/chalk/inline.cr b/src/chalk/inline.cr index b971fbd..5988204 100644 --- a/src/chalk/inline.cr +++ b/src/chalk/inline.cr @@ -23,4 +23,37 @@ module Chalk emitter.instructions << AwaitKeyInstruction.new target end end + + class InlineGetFontFunction < InlineFunction + def initialize + @param_count = 1 + end + + def generate!(emitter, params, table, target, free) + emitter.generate! params[0], table, free, free + 1 + emitter.instructions << GetFontInstruction.new free + + end + end + + class InlineSetDelayFunction < InlineFunction + def initialize + @param_count = 1 + end + + def generate!(emitter, params, table, target, free) + emitter.generate! params[0], table, free, free + 1 + emitter.instructions << SetDelayTimerInstruction.new free + end + end + + class InlineGetDelayFunction < InlineFunction + def initialize + @param_count = 0 + end + + def generate!(emitter, params, table, target, free) + emitter.instructions << GetDelayTimerInstruction.new target + end + end end diff --git a/src/chalk/ir.cr b/src/chalk/ir.cr index 4252768..12ac53a 100644 --- a/src/chalk/ir.cr +++ b/src/chalk/ir.cr @@ -317,5 +317,57 @@ module Chalk io << "getk R" @into.to_s(16, io) end + + def to_bin(i, index) + return 0xf00a | (@into << 8) + end + end + + class GetFontInstruction < Instruction + property from : Int32 + + def initialize(@from) + end + + def to_s(io) + io << "font R" + @from.to_s(16, io) + end + + def to_bin(i, index) + return 0xf029 | (@from << 8) + end + end + + class SetDelayTimerInstruction < Instruction + property from : Int32 + + def initialize(@from) + end + + def to_s(io) + io << "set_delay R" + @from.to_s(16, io) + end + + def to_bin(i, index) + return 0xf015 | (@from << 8) + end + end + + class GetDelayTimerInstruction < Instruction + property into : Int32 + + def initialize(@into) + end + + def to_s(io) + io << "get_delay R" + @into.to_s(16, io) + end + + def to_bin(i, index) + return 0xf007 | (@into << 8) + end end end