gbtiles 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +48 -0
- data/bin/gbm +27 -0
- data/bin/gbr +27 -0
- data/lib/gbtiles/data_type.rb +73 -0
- data/lib/gbtiles/gbm/cli/convert.rb +56 -0
- data/lib/gbtiles/gbm/export/asm/asm.h.erb +19 -0
- data/lib/gbtiles/gbm/export/asm/asm.rb +52 -0
- data/lib/gbtiles/gbm/export/asm/asm.s.erb +30 -0
- data/lib/gbtiles/gbm/import/gbm_file.rb +82 -0
- data/lib/gbtiles/gbm/map/map_set.rb +55 -0
- data/lib/gbtiles/gbm/map/object.rb +21 -0
- data/lib/gbtiles/gbm/map/object_type.rb +14 -0
- data/lib/gbtiles/gbm/map/objects/map.rb +49 -0
- data/lib/gbtiles/gbm/map/objects/map_export_settings.rb +77 -0
- data/lib/gbtiles/gbm/map/objects/map_settings.rb +73 -0
- data/lib/gbtiles/gbm/map/objects/map_tile_data.rb +40 -0
- data/lib/gbtiles/gbm/map/objects/map_tile_data_record.rb +40 -0
- data/lib/gbtiles/gbm/map/objects/producer.rb +33 -0
- data/lib/gbtiles/gbm/map/objects/unknown.rb +14 -0
- data/lib/gbtiles/gbr/cli/convert.rb +58 -0
- data/lib/gbtiles/gbr/export/asm/asm.h.erb +15 -0
- data/lib/gbtiles/gbr/export/asm/asm.rb +52 -0
- data/lib/gbtiles/gbr/export/asm/asm.s.erb +17 -0
- data/lib/gbtiles/gbr/import/gbr_file.rb +70 -0
- data/lib/gbtiles/gbr/tile_set/color_set.rb +12 -0
- data/lib/gbtiles/gbr/tile_set/export_type.rb +13 -0
- data/lib/gbtiles/gbr/tile_set/object.rb +18 -0
- data/lib/gbtiles/gbr/tile_set/object_type.rb +16 -0
- data/lib/gbtiles/gbr/tile_set/objects/palettes.rb +41 -0
- data/lib/gbtiles/gbr/tile_set/objects/producer.rb +33 -0
- data/lib/gbtiles/gbr/tile_set/objects/tile_data.rb +82 -0
- data/lib/gbtiles/gbr/tile_set/objects/tile_export.rb +105 -0
- data/lib/gbtiles/gbr/tile_set/objects/tile_import.rb +57 -0
- data/lib/gbtiles/gbr/tile_set/objects/tile_pal.rb +41 -0
- data/lib/gbtiles/gbr/tile_set/objects/tile_settings.rb +65 -0
- data/lib/gbtiles/gbr/tile_set/objects/unknown.rb +14 -0
- data/lib/gbtiles/gbr/tile_set/sgb_palettes.rb +13 -0
- data/lib/gbtiles/gbr/tile_set/split_order.rb +13 -0
- data/lib/gbtiles/gbr/tile_set/tile_set.rb +57 -0
- data/lib/gbtiles/helpers/fixnum.rb +6 -0
- data/lib/gbtiles/version.rb +3 -0
- metadata +104 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
<% tile_export = tile_set.tile_export.first -%>
|
2
|
+
/**
|
3
|
+
* .H created with
|
4
|
+
* GBTiles Ruby Gem (v<%= GBTiles::VERSION %>) - GBR
|
5
|
+
*
|
6
|
+
* .GBR created with
|
7
|
+
* <%= tile_set.producers.first.name %> (v<%= tile_set.producers.first.version %>)
|
8
|
+
* <%= tile_set.producers.first.info %>
|
9
|
+
*/
|
10
|
+
|
11
|
+
// Helper: The bank the tiles were saved as
|
12
|
+
#define <%= tile_export.label_name %>Bank <%= tile_export.bank %>
|
13
|
+
|
14
|
+
// Extern: A placeholder for the data
|
15
|
+
extern unsigned char <%= tile_export.label_name %>[];
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
module GBTiles
|
4
|
+
module GBR
|
5
|
+
module Export
|
6
|
+
module ASM
|
7
|
+
class ASM
|
8
|
+
include ERB::Util
|
9
|
+
|
10
|
+
attr_accessor :tile_set
|
11
|
+
@tile_set
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
end
|
15
|
+
|
16
|
+
def prerender
|
17
|
+
if @tile_set.nil? then
|
18
|
+
raise "Missing required tile set"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_s
|
23
|
+
prerender
|
24
|
+
|
25
|
+
template = File.open(File.join(__dir__, "asm.s.erb"), "r").read
|
26
|
+
|
27
|
+
ERB.new(template, nil, "-").result(binding)
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_h
|
31
|
+
prerender
|
32
|
+
|
33
|
+
template = File.open(File.join(__dir__, "asm.h.erb"), "r").read
|
34
|
+
|
35
|
+
ERB.new(template, nil, "-").result(binding)
|
36
|
+
end
|
37
|
+
|
38
|
+
def write output_stream
|
39
|
+
output_stream.write(render_s)
|
40
|
+
|
41
|
+
if output_stream.is_a? File then
|
42
|
+
header_path = "#{File.basename(output_stream.path, ".s")}.h"
|
43
|
+
header_stream = File.open(header_path, "w")
|
44
|
+
header_stream.write(render_h)
|
45
|
+
header_stream.close
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% tile_export = tile_set.tile_export.first -%>
|
2
|
+
; .S created with
|
3
|
+
; GBTiles Ruby Gem (v<%= GBTiles::VERSION %>) - GBR
|
4
|
+
;
|
5
|
+
; .GBR created with
|
6
|
+
; <%= tile_set.producers.first.name %> (v<%= tile_set.producers.first.version %>)
|
7
|
+
; <%= tile_set.producers.first.info %>
|
8
|
+
|
9
|
+
.area _CODE_<%= tile_export.bank %>
|
10
|
+
|
11
|
+
.globl _<%= tile_export.label_name %>
|
12
|
+
.dw _<%= tile_export.label_name %>
|
13
|
+
|
14
|
+
_<%= tile_export.label_name %>:
|
15
|
+
<% (tile_export.from..tile_export.upto).each do |i| -%>
|
16
|
+
.db <%= tile_set.tile_data.first.render_tile(i) %>
|
17
|
+
<% end %>
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module Import
|
4
|
+
class GBRFile
|
5
|
+
attr_accessor :version, :tile_set
|
6
|
+
|
7
|
+
@version
|
8
|
+
@tile_set
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@tile_set = GBTiles::GBR::TileSet::TileSet.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.open(file)
|
15
|
+
import = GBTiles::GBR::Import::GBRFile.new
|
16
|
+
|
17
|
+
# Check to see if this is a valid file type
|
18
|
+
if (file.read(3) != "GBO") then
|
19
|
+
raise "Invalid file, header does not start with GBO"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Version number
|
23
|
+
import.version = file.read(1)
|
24
|
+
|
25
|
+
# For each object
|
26
|
+
while !file.eof?
|
27
|
+
object_type = GBTiles::DataType.word(file.read(2))
|
28
|
+
object_id = GBTiles::DataType.word(file.read(2))
|
29
|
+
object_len = GBTiles::DataType.long(file.read(4))
|
30
|
+
object_data = file.read(object_len)
|
31
|
+
|
32
|
+
case object_type
|
33
|
+
when GBTiles::GBR::TileSet::ObjectType::PRODUCER
|
34
|
+
object = GBTiles::GBR::TileSet::Objects::Producer.initFromBitString object_data
|
35
|
+
|
36
|
+
when GBTiles::GBR::TileSet::ObjectType::TILE_DATA
|
37
|
+
object = GBTiles::GBR::TileSet::Objects::TileData.initFromBitString object_data
|
38
|
+
|
39
|
+
when GBTiles::GBR::TileSet::ObjectType::TILE_SETTINGS
|
40
|
+
object = GBTiles::GBR::TileSet::Objects::TileSettings.initFromBitString object_data
|
41
|
+
|
42
|
+
when GBTiles::GBR::TileSet::ObjectType::TILE_EXPORT
|
43
|
+
object = GBTiles::GBR::TileSet::Objects::TileExport.initFromBitString object_data
|
44
|
+
|
45
|
+
when GBTiles::GBR::TileSet::ObjectType::TILE_IMPORT
|
46
|
+
object = GBTiles::GBR::TileSet::Objects::TileImport.initFromBitString object_data
|
47
|
+
|
48
|
+
when GBTiles::GBR::TileSet::ObjectType::PALETTES
|
49
|
+
object = GBTiles::GBR::TileSet::Objects::Palettes.initFromBitString object_data
|
50
|
+
|
51
|
+
when GBTiles::GBR::TileSet::ObjectType::TILE_PAL
|
52
|
+
object = GBTiles::GBR::TileSet::Objects::TilePal.initFromBitString object_data
|
53
|
+
|
54
|
+
else
|
55
|
+
object = GBTiles::GBR::TileSet::Objects::Unknown.new object_type
|
56
|
+
object.object_data = object_data
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
object.object_id = object_id
|
61
|
+
|
62
|
+
import.tile_set.objects.push object
|
63
|
+
end
|
64
|
+
|
65
|
+
import
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module TileSet
|
4
|
+
class Object
|
5
|
+
|
6
|
+
attr_accessor :object_id
|
7
|
+
@object_id
|
8
|
+
|
9
|
+
attr_accessor :object_type
|
10
|
+
@object_type
|
11
|
+
|
12
|
+
def initialize object_type
|
13
|
+
@object_type = object_type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module TileSet
|
4
|
+
module ObjectType
|
5
|
+
PRODUCER = 0x01
|
6
|
+
TILE_DATA = 0x02
|
7
|
+
TILE_SETTINGS = 0x03
|
8
|
+
TILE_EXPORT = 0x04
|
9
|
+
TILE_IMPORT = 0x05
|
10
|
+
PALETTES = 0x0D
|
11
|
+
TILE_PAL = 0x0E
|
12
|
+
DELETED = 0xFF
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module TileSet
|
4
|
+
module Objects
|
5
|
+
class Palettes < GBTiles::GBR::TileSet::Object
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
@id
|
9
|
+
|
10
|
+
attr_accessor :count
|
11
|
+
@count
|
12
|
+
|
13
|
+
attr_accessor :colors
|
14
|
+
@colors
|
15
|
+
|
16
|
+
attr_accessor :sgb_count
|
17
|
+
@sgb_count
|
18
|
+
|
19
|
+
attr_accessor :sgb_colors
|
20
|
+
@sgb_colors
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
super GBTiles::GBR::TileSet::ObjectType::PALETTES
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.initFromBitString src
|
27
|
+
object = GBTiles::GBR::TileSet::Objects::Palettes.new
|
28
|
+
|
29
|
+
object.id = GBTiles::DataType.word!(src)
|
30
|
+
object.count = GBTiles::DataType.word!(src)
|
31
|
+
object.colors = src.slice!(0, object.count)
|
32
|
+
object.sgb_count = GBTiles::DataType.word!(src)
|
33
|
+
object.sgb_colors = src.slice!(0, object.sgb_count)
|
34
|
+
|
35
|
+
object
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module TileSet
|
4
|
+
module Objects
|
5
|
+
class Producer < GBTiles::GBR::TileSet::Object
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
@name
|
9
|
+
|
10
|
+
attr_accessor :version
|
11
|
+
@version
|
12
|
+
|
13
|
+
attr_accessor :info
|
14
|
+
@info
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super GBTiles::GBR::TileSet::ObjectType::PRODUCER
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.initFromBitString src
|
21
|
+
object = GBTiles::GBR::TileSet::Objects::Producer.new
|
22
|
+
|
23
|
+
object.name = GBTiles::DataType.string!(src, 30)
|
24
|
+
object.version = GBTiles::DataType.string!(src, 10)
|
25
|
+
object.info = GBTiles::DataType.string!(src, 80)
|
26
|
+
|
27
|
+
object
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module TileSet
|
4
|
+
module Objects
|
5
|
+
class TileData < GBTiles::GBR::TileSet::Object
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
@name
|
9
|
+
|
10
|
+
attr_accessor :width
|
11
|
+
@width
|
12
|
+
|
13
|
+
attr_accessor :height
|
14
|
+
@height
|
15
|
+
|
16
|
+
attr_accessor :count
|
17
|
+
@count
|
18
|
+
|
19
|
+
attr_accessor :color_set
|
20
|
+
@color_set
|
21
|
+
|
22
|
+
attr_accessor :data
|
23
|
+
@data
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
super GBTiles::GBR::TileSet::ObjectType::TILE_DATA
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.initFromBitString src
|
30
|
+
object = GBTiles::GBR::TileSet::Objects::TileData.new
|
31
|
+
|
32
|
+
object.name = GBTiles::DataType.string!(src, 30)
|
33
|
+
object.width = GBTiles::DataType.word!(src)
|
34
|
+
object.height = GBTiles::DataType.word!(src)
|
35
|
+
object.count = GBTiles::DataType.word!(src)
|
36
|
+
object.color_set = src.slice!(0, 4)
|
37
|
+
object.data = src
|
38
|
+
|
39
|
+
object
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_tile(tile_index)
|
43
|
+
tile = []
|
44
|
+
|
45
|
+
tile_data = @data.slice(
|
46
|
+
tile_index * @width * @height,
|
47
|
+
@width * @height
|
48
|
+
)
|
49
|
+
|
50
|
+
(1..@height).each do |row|
|
51
|
+
byte_0 = 0x00
|
52
|
+
byte_1 = 0x00
|
53
|
+
|
54
|
+
bitmask = 0x80
|
55
|
+
|
56
|
+
(1..@width).each do |col|
|
57
|
+
pixel = tile_data[(row - 1) * @height + col - 1]
|
58
|
+
|
59
|
+
case pixel.unpack("C")[0]
|
60
|
+
when 0 # Black
|
61
|
+
when 1 # Dark Grey
|
62
|
+
byte_0 |= bitmask
|
63
|
+
when 2 # Light Grey
|
64
|
+
byte_1 |= bitmask
|
65
|
+
when 3 # White
|
66
|
+
byte_0 |= bitmask
|
67
|
+
byte_1 |= bitmask
|
68
|
+
end
|
69
|
+
|
70
|
+
bitmask >>= 1
|
71
|
+
end
|
72
|
+
|
73
|
+
tile.push(sprintf("0x%02x,0x%02x", byte_0, byte_1))
|
74
|
+
end
|
75
|
+
|
76
|
+
tile.join(",")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBR
|
3
|
+
module TileSet
|
4
|
+
module Objects
|
5
|
+
class TileExport < GBTiles::GBR::TileSet::Object
|
6
|
+
|
7
|
+
attr_accessor :tile_id
|
8
|
+
@tile_id
|
9
|
+
|
10
|
+
attr_accessor :file_name
|
11
|
+
@file_name
|
12
|
+
|
13
|
+
attr_accessor :file_type
|
14
|
+
@file_type
|
15
|
+
|
16
|
+
attr_accessor :section_name
|
17
|
+
@section_name
|
18
|
+
|
19
|
+
attr_accessor :label_name
|
20
|
+
@label_name
|
21
|
+
|
22
|
+
attr_accessor :bank
|
23
|
+
@bank
|
24
|
+
|
25
|
+
attr_accessor :tile_array
|
26
|
+
@tile_array
|
27
|
+
|
28
|
+
attr_accessor :format
|
29
|
+
@format
|
30
|
+
|
31
|
+
attr_accessor :counter
|
32
|
+
@counter
|
33
|
+
|
34
|
+
attr_accessor :from
|
35
|
+
@from
|
36
|
+
|
37
|
+
attr_accessor :upto
|
38
|
+
@upto
|
39
|
+
|
40
|
+
attr_accessor :compression
|
41
|
+
@compression
|
42
|
+
|
43
|
+
attr_accessor :include_colors
|
44
|
+
@include_colors
|
45
|
+
|
46
|
+
attr_accessor :sgb_palettes
|
47
|
+
@sgb_palettes
|
48
|
+
|
49
|
+
attr_accessor :gbc_palettes
|
50
|
+
@gbc_palettes
|
51
|
+
|
52
|
+
attr_accessor :make_meta_tiles
|
53
|
+
@make_meta_tiles
|
54
|
+
|
55
|
+
attr_accessor :meta_offset
|
56
|
+
@meta_offset
|
57
|
+
|
58
|
+
attr_accessor :meta_counter
|
59
|
+
@meta_counter
|
60
|
+
|
61
|
+
attr_accessor :split
|
62
|
+
@split
|
63
|
+
|
64
|
+
attr_accessor :block_size
|
65
|
+
@block_size
|
66
|
+
|
67
|
+
attr_accessor :sel_tab
|
68
|
+
@sel_tab
|
69
|
+
|
70
|
+
def initialize
|
71
|
+
super GBTiles::GBR::TileSet::ObjectType::TILE_EXPORT
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.initFromBitString src
|
75
|
+
object = GBTiles::GBR::TileSet::Objects::TileExport.new
|
76
|
+
|
77
|
+
object.tile_id = GBTiles::DataType.word!(src)
|
78
|
+
object.file_name = GBTiles::DataType.string!(src, 128)
|
79
|
+
object.file_type = GBTiles::DataType.byte!(src)
|
80
|
+
object.section_name = GBTiles::DataType.string!(src, 20)
|
81
|
+
object.label_name = GBTiles::DataType.string!(src, 20)
|
82
|
+
object.bank = GBTiles::DataType.byte!(src)
|
83
|
+
object.tile_array = GBTiles::DataType.byte!(src)
|
84
|
+
object.format = GBTiles::DataType.byte!(src)
|
85
|
+
object.counter = GBTiles::DataType.byte!(src)
|
86
|
+
object.from = GBTiles::DataType.word!(src)
|
87
|
+
object.upto = GBTiles::DataType.word!(src)
|
88
|
+
object.compression = GBTiles::DataType.byte!(src)
|
89
|
+
object.include_colors = GBTiles::DataType.boolean!(src)
|
90
|
+
object.sgb_palettes = GBTiles::DataType.byte!(src)
|
91
|
+
object.gbc_palettes = GBTiles::DataType.byte!(src)
|
92
|
+
object.make_meta_tiles = GBTiles::DataType.boolean!(src)
|
93
|
+
object.meta_offset = GBTiles::DataType.long!(src)
|
94
|
+
object.meta_counter = GBTiles::DataType.byte!(src)
|
95
|
+
object.split = GBTiles::DataType.boolean!(src)
|
96
|
+
object.block_size = GBTiles::DataType.long!(src)
|
97
|
+
object.sel_tab = GBTiles::DataType.byte!(src)
|
98
|
+
|
99
|
+
object
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|