Generate sprite data.
This commit is contained in:
parent
60c320dfea
commit
b79d717f1a
|
@ -140,9 +140,9 @@ module Chalk
|
||||||
binary = instructions.map_with_index { |it, i| it.to_bin(table, instructions.size, i).to_u16 }
|
binary = instructions.map_with_index { |it, i| it.to_bin(table, instructions.size, i).to_u16 }
|
||||||
binary.each do |inst|
|
binary.each do |inst|
|
||||||
first = (inst >> 8).to_u8
|
first = (inst >> 8).to_u8
|
||||||
dest.write_byte(first)
|
dest << first
|
||||||
second = (inst & 0xff).to_u8
|
second = (inst & 0xff).to_u8
|
||||||
dest.write_byte(second)
|
dest << second
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -180,6 +180,15 @@ module Chalk
|
||||||
names = collect_calls(table)
|
names = collect_calls(table)
|
||||||
names.delete "main"
|
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!
|
main_entry = table.get_function?("main").not_nil!
|
||||||
all_instructions.concat create_code(main_entry.function.as(Trees::TreeFunction),
|
all_instructions.concat create_code(main_entry.function.as(Trees::TreeFunction),
|
||||||
table, Ir::JumpRelativeInstruction.new 0)
|
table, Ir::JumpRelativeInstruction.new 0)
|
||||||
|
@ -194,8 +203,12 @@ module Chalk
|
||||||
all_instructions << Ir::ReturnInstruction.new
|
all_instructions << Ir::ReturnInstruction.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
binary = [] of UInt8
|
||||||
file = File.open(@config.output, "w")
|
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
|
file.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,10 @@ module Chalk
|
||||||
end
|
end
|
||||||
|
|
||||||
class SpriteEntry
|
class SpriteEntry
|
||||||
getter sprite : Sprite
|
property sprite : Sprite
|
||||||
getter addr : Int32
|
property offset : Int32
|
||||||
|
|
||||||
def initialize(@sprite, @addr = -1)
|
def initialize(@sprite, @offset = -1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,6 +46,12 @@ module Chalk
|
||||||
class Table
|
class Table
|
||||||
# Gets the parent of this table.
|
# Gets the parent of this table.
|
||||||
getter parent
|
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)
|
def initialize(@parent : Table? = nil)
|
||||||
@functions = {} of String => FunctionEntry
|
@functions = {} of String => FunctionEntry
|
||||||
|
|
Loading…
Reference in New Issue
Block a user