Generate sprite data.

This commit is contained in:
Danila Fedorin 2018-08-06 23:43:46 -07:00
parent 60c320dfea
commit b79d717f1a
2 changed files with 25 additions and 6 deletions

View File

@ -140,9 +140,9 @@ module Chalk
binary = instructions.map_with_index { |it, i| it.to_bin(table, instructions.size, i).to_u16 }
binary.each do |inst|
first = (inst >> 8).to_u8
dest.write_byte(first)
dest << first
second = (inst & 0xff).to_u8
dest.write_byte(second)
dest << second
end
end
@ -180,6 +180,15 @@ module Chalk
names = collect_calls(table)
names.delete "main"
sprite_bytes = [] of UInt8
offset = 0
table.sprites.each do |k, v|
data = v.sprite.encode
v.offset = offset
offset += data.size
sprite_bytes.concat data
end
main_entry = table.get_function?("main").not_nil!
all_instructions.concat create_code(main_entry.function.as(Trees::TreeFunction),
table, Ir::JumpRelativeInstruction.new 0)
@ -194,8 +203,12 @@ module Chalk
all_instructions << Ir::ReturnInstruction.new
end
binary = [] of UInt8
file = File.open(@config.output, "w")
generate_binary(table, all_instructions, file)
generate_binary(table, all_instructions, binary)
binary.each do |byte|
file.write_byte byte
end
file.close
end

View File

@ -35,10 +35,10 @@ module Chalk
end
class SpriteEntry
getter sprite : Sprite
getter addr : Int32
property sprite : Sprite
property offset : Int32
def initialize(@sprite, @addr = -1)
def initialize(@sprite, @offset = -1)
end
end
@ -46,6 +46,12 @@ module Chalk
class Table
# Gets the parent of this table.
getter parent
# Gets the functions hash.
getter functions
# Gets the variables hash.
getter vars
# Gets the sprites hash.
getter sprites
def initialize(@parent : Table? = nil)
@functions = {} of String => FunctionEntry