gbtiles 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ead8106729b3a84988e0fec3f04c932a1aa870df
|
4
|
+
data.tar.gz: a0e02dfa4cca73ae5253ede1e000ab12311efcd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb813f183e1c213ff6b82991c49dd999c4179a5134a4a1e333f4e701a9bfc032decd53ea5fded7b17d023e027aa3693a76057b3575186fd78faaeda408fab8c9
|
7
|
+
data.tar.gz: 10b070b7f0ce28e32d00255517a1d1c1ac5e69385a2637930eefedf8382cfa127e919247dae4c04dde605743680c263eb76212b85633c7c0490cb8eb73d354a7
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Bashkim Isai
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# GBTiles
|
2
|
+
|
3
|
+
Version 0.0.1
|
4
|
+
|
5
|
+
Converts `.GBR` files created with
|
6
|
+
[Harry Mulder's Tile Designer (GBTD)](http://www.devrs.com/gb/hmgd/gbtd.html)
|
7
|
+
and `.GBM` files created with
|
8
|
+
[Harry Mulder's Map Builder (GBMB)](http://www.devrs.com/gb/hmgd/gbmb.html)
|
9
|
+
to different formats for use with the Game Boy and
|
10
|
+
[GBDK](http://gbdk.sourceforge.net/).
|
11
|
+
|
12
|
+
**N.B.: Not all of the functionality provided by Harry Mulder's GBR and GBM
|
13
|
+
file format specification have been implemented; however there is enough to
|
14
|
+
generate the basics for tiles and maps.**
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
gem install gbtiles
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Help
|
23
|
+
|
24
|
+
To view help information for the GBR or GBM commands, simply type one of the
|
25
|
+
following:
|
26
|
+
|
27
|
+
gbr --help
|
28
|
+
gbm --help
|
29
|
+
|
30
|
+
### GBR (GBTD files)
|
31
|
+
|
32
|
+
Converts a Tile Designer file `*.gbr` to an ASM file `*.s` and generates
|
33
|
+
a C file `*.h` for convenience.
|
34
|
+
|
35
|
+
gbr convert --output "sample.s" sample.gbr
|
36
|
+
|
37
|
+
### GBM (GBMB files)
|
38
|
+
|
39
|
+
Converts a Map Builder file `*.gbm` to an ASM file `*.s` and generates
|
40
|
+
a C file `*.h` for convenience.
|
41
|
+
|
42
|
+
gbm convert --output "sample.s" sample.gbm
|
43
|
+
|
44
|
+
## Contributors
|
45
|
+
|
46
|
+
* @bashaus -- [Bashkim Isai](http://www.bashkim.com.au/)
|
47
|
+
|
48
|
+
If you fork this project and create a pull request add your GitHub username, your full name and website to the end of list above.
|
data/bin/gbm
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "gli"
|
3
|
+
|
4
|
+
include GLI::App
|
5
|
+
|
6
|
+
require "gbtiles/version"
|
7
|
+
require "gbtiles/helpers/fixnum"
|
8
|
+
|
9
|
+
require "gbtiles/gbm/cli/convert"
|
10
|
+
|
11
|
+
program_desc "Converts .GBM files to different formats for the Game Boy"
|
12
|
+
|
13
|
+
version GBTiles::VERSION
|
14
|
+
|
15
|
+
pre do |global,command,options,args|
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
post do |global,command,options,args|
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
on_error do |exception|
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
exit run(ARGV)
|
data/bin/gbr
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "gli"
|
3
|
+
|
4
|
+
include GLI::App
|
5
|
+
|
6
|
+
require "gbtiles/version"
|
7
|
+
require "gbtiles/helpers/fixnum"
|
8
|
+
|
9
|
+
require "gbtiles/gbr/cli/convert"
|
10
|
+
|
11
|
+
program_desc "Converts .GBR files to different formats for the Game Boy"
|
12
|
+
|
13
|
+
version GBTiles::VERSION
|
14
|
+
|
15
|
+
pre do |global,command,options,args|
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
post do |global,command,options,args|
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
on_error do |exception|
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
exit run(ARGV)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module DataType
|
3
|
+
def self.string(src, length = nil)
|
4
|
+
if !length.nil? then
|
5
|
+
string = src.slice(0, length)
|
6
|
+
else
|
7
|
+
string = src
|
8
|
+
end
|
9
|
+
|
10
|
+
if !string.nil? then
|
11
|
+
string = string.split(/\0/).first
|
12
|
+
end
|
13
|
+
|
14
|
+
if !string.nil?
|
15
|
+
string = string.unpack("A*")[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
string
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.string!(src, length = nil)
|
22
|
+
if !length.nil? then
|
23
|
+
string = src.slice!(0, length)
|
24
|
+
else
|
25
|
+
string = src
|
26
|
+
end
|
27
|
+
|
28
|
+
self.string(string, length)
|
29
|
+
end
|
30
|
+
|
31
|
+
# WORD
|
32
|
+
# LITTLE ENDIAN
|
33
|
+
# 2 BYTES
|
34
|
+
def self.word(src)
|
35
|
+
src.slice(0, 2).unpack("v*")[0]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.word!(src)
|
39
|
+
self.word(src.slice!(0, 2))
|
40
|
+
end
|
41
|
+
|
42
|
+
# BYTE
|
43
|
+
# 1 BYTE
|
44
|
+
def self.byte(src)
|
45
|
+
src.slice(0, 1).unpack("C*")[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.byte!(src)
|
49
|
+
self.byte(src.slice!(0, 1))
|
50
|
+
end
|
51
|
+
|
52
|
+
# BOOLEAN
|
53
|
+
# 1 BYTE
|
54
|
+
def self.boolean(src)
|
55
|
+
src.slice!(0, 1).unpack("C")[0].eql? 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.boolean!(src)
|
59
|
+
self.boolean(src.slice!(0, 1))
|
60
|
+
end
|
61
|
+
|
62
|
+
# LITTLE ENDIAN
|
63
|
+
# 32 BIT INTEGER
|
64
|
+
# 4 BYTES
|
65
|
+
def self.long(src)
|
66
|
+
src.slice(0, 4).unpack("V*")[0]
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.long!(src)
|
70
|
+
self.long(src.slice!(0, 4))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "gbtiles/data_type"
|
2
|
+
|
3
|
+
require "gbtiles/gbm/import/gbm_file"
|
4
|
+
|
5
|
+
require "gbtiles/gbm/map/map_set"
|
6
|
+
|
7
|
+
require "gbtiles/gbm/map/object"
|
8
|
+
require "gbtiles/gbm/map/object_type"
|
9
|
+
|
10
|
+
require "gbtiles/gbm/map/objects/producer"
|
11
|
+
require "gbtiles/gbm/map/objects/map"
|
12
|
+
require "gbtiles/gbm/map/objects/map_tile_data"
|
13
|
+
require "gbtiles/gbm/map/objects/map_tile_data_record"
|
14
|
+
require "gbtiles/gbm/map/objects/map_settings"
|
15
|
+
require "gbtiles/gbm/map/objects/map_export_settings"
|
16
|
+
require "gbtiles/gbm/map/objects/unknown"
|
17
|
+
|
18
|
+
require "gbtiles/gbm/export/asm/asm"
|
19
|
+
|
20
|
+
desc "Convert a file from GBM format"
|
21
|
+
arg_name "input"
|
22
|
+
command :convert do |c|
|
23
|
+
|
24
|
+
c.desc "Output filename (*.s)"
|
25
|
+
c.flag :output
|
26
|
+
|
27
|
+
c.action do |global_options,options,args|
|
28
|
+
# Prepare input file
|
29
|
+
if !args[0].nil? then
|
30
|
+
# Use file
|
31
|
+
input_file = File.open(args[0], "rb")
|
32
|
+
else
|
33
|
+
# Use STDIN
|
34
|
+
input_file = $stdin
|
35
|
+
end
|
36
|
+
|
37
|
+
# Prepare output file
|
38
|
+
if !options[:output].nil? then
|
39
|
+
# Use file
|
40
|
+
output_file = File.open(options[:output], "w")
|
41
|
+
else
|
42
|
+
# Use STDOUT
|
43
|
+
output_file = $stdout
|
44
|
+
end
|
45
|
+
|
46
|
+
# Do import
|
47
|
+
import = GBTiles::GBM::Import::GBMFile.open(input_file)
|
48
|
+
input_file.close
|
49
|
+
|
50
|
+
# Do export
|
51
|
+
export = GBTiles::GBM::Export::ASM::ASM.new
|
52
|
+
export.map_set = import.map_set
|
53
|
+
export.write(output_file)
|
54
|
+
output_file.close
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<% map_export_settings = map_set.map_export_settings.first -%>
|
2
|
+
/**
|
3
|
+
* .H created with
|
4
|
+
* GBTiles Ruby Gem (v<%= GBTiles::VERSION %>) - GBM
|
5
|
+
*
|
6
|
+
* .GBM created with
|
7
|
+
* <%= map_set.producers.first.name %> (v<%= map_set.producers.first.version %>)
|
8
|
+
* <%= map_set.producers.first.info %>
|
9
|
+
*/
|
10
|
+
|
11
|
+
<% map_set.maps.each do |map| -%>
|
12
|
+
// Helper: Map dimensions
|
13
|
+
#define <%= map_export_settings.label_name %>Width <%= map.width %>
|
14
|
+
#define <%= map_export_settings.label_name %>Height <%= map.height %>
|
15
|
+
#define <%= map_export_settings.label_name %>Bank <%= map_export_settings.bank %>
|
16
|
+
|
17
|
+
// Extern: <%= map_export_settings.label_name %>
|
18
|
+
extern unsigned char <%= map_export_settings.label_name %>[];
|
19
|
+
<% end %>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
module GBTiles
|
4
|
+
module GBM
|
5
|
+
module Export
|
6
|
+
module ASM
|
7
|
+
class ASM
|
8
|
+
include ERB::Util
|
9
|
+
|
10
|
+
attr_accessor :map_set
|
11
|
+
@map_set
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
end
|
15
|
+
|
16
|
+
def prerender
|
17
|
+
if @map_set.nil? then
|
18
|
+
raise "Missing required map"
|
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,30 @@
|
|
1
|
+
<% map_export_settings = map_set.map_export_settings.first -%>
|
2
|
+
; .S created with
|
3
|
+
; GBTiles Ruby Gem (v<%= GBTiles::VERSION %>) - GBM
|
4
|
+
;
|
5
|
+
; .GBM created with
|
6
|
+
; <%= map_set.producers.first.name %> (v<%= map_set.producers.first.version %>)
|
7
|
+
; <%= map_set.producers.first.info %>
|
8
|
+
|
9
|
+
.area _CODE_<%= map_export_settings.bank -%>
|
10
|
+
|
11
|
+
<% map_set.maps.each do |map| -%>
|
12
|
+
<% map_tile_data = map_set.map_tile_data(map.master_id).first -%>
|
13
|
+
|
14
|
+
; Map <%= "(#{map.name})" unless map.name.nil? %>
|
15
|
+
|
16
|
+
.globl _<%= map_export_settings.label_name %>
|
17
|
+
.dw _<%= map_export_settings.label_name %>
|
18
|
+
|
19
|
+
_<%= map_export_settings.label_name %>:
|
20
|
+
<% (1..map.height).each do |row| -%>
|
21
|
+
<% row_tile_data = map_tile_data.row(map.width, row) -%>
|
22
|
+
<% if !row_tile_data.nil? -%>
|
23
|
+
.db <%= map_tile_data
|
24
|
+
.row(map.width, row)
|
25
|
+
.map {|x| sprintf("0x%02x", x.tile_number) }
|
26
|
+
.join(',')
|
27
|
+
%>
|
28
|
+
<% end -%>
|
29
|
+
<% end -%>
|
30
|
+
<% end %>
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module GBTiles
|
2
|
+
module GBM
|
3
|
+
module Import
|
4
|
+
class GBMFile
|
5
|
+
|
6
|
+
OBJECT_MARKER = "HPJMTL"
|
7
|
+
|
8
|
+
attr_accessor :version
|
9
|
+
@version
|
10
|
+
|
11
|
+
attr_accessor :map_set
|
12
|
+
@map_set
|
13
|
+
|
14
|
+
def initialize()
|
15
|
+
@map_set = GBTiles::GBM::Map::MapSet.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.open(file)
|
19
|
+
import = GBTiles::GBM::Import::GBMFile.new
|
20
|
+
|
21
|
+
# Check to see if this is a valid file type
|
22
|
+
if (file.read(3) != "GBO") then
|
23
|
+
raise "Invalid file, header does not start with GBO"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Version number
|
27
|
+
import.version = file.read(1)
|
28
|
+
|
29
|
+
if import.version != "1" then
|
30
|
+
raise "Invalid file, can only import version number 1"
|
31
|
+
end
|
32
|
+
|
33
|
+
# For each object
|
34
|
+
while !file.eof?
|
35
|
+
# Check the marker
|
36
|
+
marker = GBTiles::DataType.string(file.read(6))
|
37
|
+
|
38
|
+
if !OBJECT_MARKER.eql? marker then
|
39
|
+
raise "Malformed file, expected marker #{OBJECT_MARKER}, got #{marker}"
|
40
|
+
end
|
41
|
+
|
42
|
+
object_type = GBTiles::DataType.word(file.read(2))
|
43
|
+
object_id = GBTiles::DataType.word(file.read(2))
|
44
|
+
master_id = GBTiles::DataType.word(file.read(2))
|
45
|
+
object_crc = GBTiles::DataType.long(file.read(4))
|
46
|
+
object_len = GBTiles::DataType.long(file.read(4))
|
47
|
+
object_data = file.read(object_len)
|
48
|
+
|
49
|
+
case object_type
|
50
|
+
when GBTiles::GBM::Map::ObjectType::PRODUCER
|
51
|
+
object = GBTiles::GBM::Map::Objects::Producer.initFromBitString object_data
|
52
|
+
|
53
|
+
when GBTiles::GBM::Map::ObjectType::MAP
|
54
|
+
object = GBTiles::GBM::Map::Objects::Map.initFromBitString object_data
|
55
|
+
|
56
|
+
when GBTiles::GBM::Map::ObjectType::MAP_TILE_DATA
|
57
|
+
object = GBTiles::GBM::Map::Objects::MapTileData.initFromBitString object_data
|
58
|
+
|
59
|
+
when GBTiles::GBM::Map::ObjectType::MAP_SETTINGS
|
60
|
+
object = GBTiles::GBM::Map::Objects::MapSettings.initFromBitString object_data
|
61
|
+
|
62
|
+
when GBTiles::GBM::Map::ObjectType::MAP_EXPORT_SETTINGS
|
63
|
+
object = GBTiles::GBM::Map::Objects::MapExportSettings.initFromBitString object_data
|
64
|
+
|
65
|
+
else
|
66
|
+
object = GBTiles::GBM::Map::Objects::Unknown.new object_type
|
67
|
+
object.object_data = object_data
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
object.object_id = object_id
|
72
|
+
object.master_id = master_id
|
73
|
+
|
74
|
+
import.map_set.objects.push object
|
75
|
+
end
|
76
|
+
|
77
|
+
import
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|