rubygb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +5 -0
  4. data/.travis.yml +20 -0
  5. data/CHANGELOG.md +6 -0
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +23 -0
  8. data/MIT-LICENSE.txt +53 -0
  9. data/README.md +30 -0
  10. data/Rakefile +30 -0
  11. data/bin/rubygb +5 -0
  12. data/lib/galp/AND.GIF +0 -0
  13. data/lib/galp/ARROW.GIF +0 -0
  14. data/lib/galp/C.BAT +5 -0
  15. data/lib/galp/CHANGES.TXT +5 -0
  16. data/lib/galp/EXAMPLE.LNK +7 -0
  17. data/lib/galp/EXAMPLE1.TXT +266 -0
  18. data/lib/galp/GBHW.TXT +645 -0
  19. data/lib/galp/GBSPEC.TXT +1761 -0
  20. data/lib/galp/IBMPC1.TXT +2400 -0
  21. data/lib/galp/INDEX.HTM +23 -0
  22. data/lib/galp/INSTR.HTM +563 -0
  23. data/lib/galp/MEM1.HTM +199 -0
  24. data/lib/galp/MEMORY.TXT +160 -0
  25. data/lib/galp/OPCODES.HTM +351 -0
  26. data/lib/galp/OR.GIF +0 -0
  27. data/lib/galp/README.TXT +4 -0
  28. data/lib/galp/REGS.HTM +77 -0
  29. data/lib/galp/RL.GIF +0 -0
  30. data/lib/galp/RLC.GIF +0 -0
  31. data/lib/galp/RR.GIF +0 -0
  32. data/lib/galp/RRC.GIF +0 -0
  33. data/lib/galp/SETUP.BAT +7 -0
  34. data/lib/galp/SLA.GIF +0 -0
  35. data/lib/galp/SRA.GIF +0 -0
  36. data/lib/galp/SRL.GIF +0 -0
  37. data/lib/galp/START.HTM +24 -0
  38. data/lib/galp/SWAP.GIF +0 -0
  39. data/lib/galp/VID1.HTM +34 -0
  40. data/lib/galp/XOR.GIF +0 -0
  41. data/lib/rgbds/rgbasm +0 -0
  42. data/lib/rgbds/rgbfix +0 -0
  43. data/lib/rgbds/rgblink +0 -0
  44. data/lib/rubygb/cli.rb +11 -0
  45. data/lib/rubygb/rubygb.rb +15 -0
  46. data/lib/rubygb/version.rb +4 -0
  47. data/lib/rubygb.rb +7 -0
  48. data/rubygb.gemspec +23 -0
  49. data/scrap/basic.gb +0 -0
  50. data/scrap/basic.map +55 -0
  51. data/scrap/basic.obj +0 -0
  52. data/scrap/basic.s +176 -0
  53. data/scrap/basic.sym +8 -0
  54. data/spec/basic.s +176 -0
  55. data/spec/rubygb_spec.rb +19 -0
  56. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3dd7fa09adc216340304dd6680d2081184b570a1
4
+ data.tar.gz: 8f99e04afc723055a64f76450a6901f27a757fb8
5
+ SHA512:
6
+ metadata.gz: ac40dd65075a0ba6d53b7b4f674e7544caeab46e81cdc4623f12e7387c1866128cc1df2faf8da355b226e95afa3dfe1664a720654e80e682595e01249b68c7fe
7
+ data.tar.gz: 5191b4f9e58316e51c7b08a29c0691b96a0558e231fbe98c74bde35f6ad0e5861d0667f12f57e3b27003e9d3906fb5b6548860cb1f3a239739b1ffdcf77f21a5
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ Gemfile.lock
2
+ /pkg
3
+ .idea/
4
+ scrap/
5
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ script: bundle exec ruby spec/rubygb_spec.rb
5
+
6
+ rvm:
7
+ - 2.3
8
+ - 2.2
9
+ - 2.1
10
+ - 2.0
11
+ - ruby-head
12
+ - rbx-2
13
+ - jruby-head
14
+ - jruby-9000
15
+
16
+ cache:
17
+ - bundler
18
+
19
+ # matrix:
20
+ # fast_finish: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## CHANGELOG
2
+
3
+ ### 0.1.0
4
+
5
+ * Inital release
6
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'minitest'
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubygb (0.1.0)
5
+ thor (~> 0.19)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.8.4)
11
+ rake (10.5.0)
12
+ thor (0.19.1)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ minitest
19
+ rake
20
+ rubygb!
21
+
22
+ BUNDLED WITH
23
+ 1.11.2
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,53 @@
1
+ Copyright (c) 2016 Donald Hutchison, git@toastymofo.net
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ rgbasm and rgblink are derived from Justin Lloyd's RGBDS, which is
23
+ released under the following license:
24
+
25
+ DO WHATEVER PUBLIC LICENSE*
26
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
27
+
28
+ 0. You can do whatever you want to with the work.
29
+ 1. You cannot stop anybody from doing whatever they want to with the work.
30
+ 2. You cannot revoke anybody elses DO WHATEVER PUBLIC LICENSE in the work.
31
+
32
+ This program is free software. It comes without any warranty, to
33
+ the extent permitted by applicable law. You can redistribute it
34
+ and/or modify it under the terms of the DO WHATEVER PUBLIC LICENSE
35
+
36
+ Software originally created by Justin Lloyd @ http://otakunozoku.com/
37
+
38
+
39
+ rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
40
+ under the ISC license; see the source file for the text of the license.
41
+
42
+ The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
43
+ released under the MIT license. The remainder of charmap.c was written by
44
+ stag019, and is released under the ISC license.
45
+
46
+ extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
47
+ and is released under the MIT license.
48
+
49
+ extern/reallocarray.c is derived from the OpenBSD Project,
50
+ http://www.openbsd.org, and is released under the ISC license.
51
+
52
+ extern/strl.c is derived from the OpenBSD Project, http://www.openbsd.org,
53
+ and is released under the BSD license.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # rubygb [![[version]](https://badge.fury.io/rb/rubygb.svg)](http://badge.fury.io/rb/rubygb) [![[travis]](https://travis-ci.org/rkachowski/rubygb.png)](https://travis-ci.org/rkachowski/rubygb)
2
+
3
+ Bundles the [rgbds-linux](https://github.com/bentley/rgbds) compiler (for OSX) along with some helpful libs from galp to create and build gameboy roms in a quick and stupid way.
4
+
5
+
6
+ ## Setup
7
+
8
+ Add to your `Gemfile`:
9
+
10
+ ```ruby
11
+ gem 'rubygb'
12
+ ```
13
+
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ ```
19
+
20
+ ## Awesomeness
21
+
22
+ All the cool parts are from other people
23
+
24
+ * [rgbds-linux](https://github.com/bentley/rgbds)
25
+ * [gameboy assembly language primer (galp)](http://www.devrs.com/gb/docs.php) - devrs.com
26
+
27
+
28
+ ## MIT License
29
+
30
+ Copyright (C) 2016 Donald Hutchison <donaldhutchison.info>. Released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ # # #
2
+ # Get gemspec info
3
+
4
+ gemspec_file = Dir['*.gemspec'].first
5
+ gemspec = eval File.read(gemspec_file), binding, gemspec_file
6
+ info = "#{gemspec.name} | #{gemspec.version} | " \
7
+ "#{gemspec.runtime_dependencies.size} dependencies | " \
8
+ "#{gemspec.files.size} files"
9
+
10
+
11
+ # # #
12
+ # Gem build and install task
13
+
14
+ desc info
15
+ task :gem do
16
+ puts info + "\n\n"
17
+ print " "; sh "gem build #{gemspec_file}"
18
+ FileUtils.mkdir_p 'pkg'
19
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
20
+ puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
21
+ end
22
+
23
+
24
+ # # #
25
+ # Start an IRB session with the gem loaded
26
+
27
+ desc "#{gemspec.name} | IRB"
28
+ task :irb do
29
+ sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
30
+ end
data/bin/rubygb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygb'
4
+
5
+ Rubygb::CLI.start ARGV
data/lib/galp/AND.GIF ADDED
Binary file
Binary file
data/lib/galp/C.BAT ADDED
@@ -0,0 +1,5 @@
1
+ rgbasm -oexample.obj example.asm
2
+ rgblink -mmap example.lnk
3
+ rgbfix -v example
4
+ del *.obj
5
+
@@ -0,0 +1,5 @@
1
+ GALP History
2
+ ------------
3
+
4
+ V1.0 - Original version
5
+
@@ -0,0 +1,7 @@
1
+ # Linkfile for Pan Library Demo
2
+
3
+ [Objects]
4
+ example.obj
5
+
6
+ [Output]
7
+ example.gb
@@ -0,0 +1,266 @@
1
+ ;
2
+ ; EXAMPLE1.ASM - Print "Hello World!" to the screen.
3
+ ; by GABY
4
+ ; Last edit: 24-Nov-98
5
+ ;
6
+ ; The quickest way to learn something, probably,
7
+ ; is to jump in with both feet so here we go.
8
+ ; You are actually looking at the source code for
9
+ ; example #1. As you may have noticed there is a
10
+ ; semicolon at the beginning of each line. Most
11
+ ; GameBoy assemblers (and most other assembly
12
+ ; language assemblers) use a semicolon to indicate
13
+ ; that everything following it on a particular line
14
+ ; is to be ignored and be treated purely as comments
15
+ ; rather than code.
16
+ ;
17
+ ; The first thing we want to do is include the
18
+ ; 'Hardware Defines' for our program. This has
19
+ ; address location labels for all of the GameBoy
20
+ ; Hardware I/O registers. We can 'insert' this file
21
+ ; into the present EXAMPLE1.ASM file by using the
22
+ ; assembler INCLUDE command:
23
+
24
+ INCLUDE "gbhw.inc"
25
+
26
+ ; Next we want to include a file that contains a font
27
+ ; macro. A macro is a portion of code or data that
28
+ ; gets 'inserted' into your program. At this point,
29
+ ; we are not actually inserting anything but a macro
30
+ ; definition into our file. Code or data isn't physically
31
+ ; inserted into a program until you invoke a macro which
32
+ ; we will do later. For now, we are just making the macro
33
+ ; name recognizable by our program.
34
+ ;
35
+ ; This is but just one method for including a font into
36
+ ; a program. Many different methods may be used including
37
+ ; using the INCBIN command. The INCBIN command allows
38
+ ; including raw font data or any type of raw binary data
39
+ ; into a program.
40
+
41
+ INCLUDE "ibmpc1.inc"
42
+
43
+ ; Next we need to include the standard GameBoy ROM header
44
+ ; information that goes at location $0100 in the ROM. (The
45
+ ; $ before a number indicates that the number is a hex value.)
46
+ ;
47
+ ; ROM location $0100 is also the code execution starting point
48
+ ; for user written programs. The standard first two commands
49
+ ; are usually always a NOP (NO Operation) and then a JP (Jump)
50
+ ; command. This JP command should 'jump' to the start of user
51
+ ; code. It jumps over the ROM header information as well that
52
+ ; is located at $104.
53
+ ;
54
+ ; First, we indicate that the following code & data should
55
+ ; start at address $100 by using the following SECTION assembler
56
+ ; command:
57
+
58
+ SECTION "Org $100",HOME[$100]
59
+
60
+ nop
61
+ jp begin
62
+
63
+ ; To include the standard ROM header information we
64
+ ; can just use the macro ROM_HEADER. We defined this macro
65
+ ; earlier when we INCLUDEd "gbhw.inc".
66
+ ;
67
+ ; The ROM_NOMBC just suggests to the complier that we are
68
+ ; not using a Memory Bank Controller because we don't need one
69
+ ; since our ROM won't be larger than 32K bytes.
70
+ ;
71
+ ; Next we indicate the cart ROM size and then the cart RAM size.
72
+ ; We don't need any cart RAM for this program so we set this to 0K.
73
+
74
+ ROM_HEADER ROM_NOMBC, ROM_SIZE_32KBYTE, RAM_SIZE_0KBYTE
75
+
76
+ ; Next we need to include some code for doing
77
+ ; RAM copy, RAM fill, etc.
78
+
79
+ INCLUDE "memory.asm"
80
+
81
+ ; Next, let's actually include font tile data into the ROM
82
+ ; that we are building. We do this by invoking the chr_IBMPC1
83
+ ; macro that was defined earlier when we INCLUDEd "ibmpc1.inc".
84
+ ;
85
+ ; The 1 & 8 parameters define that we want to include the
86
+ ; whole IBM-PC font set and not just parts of it.
87
+ ;
88
+ ; Right before invoking this macro we define the label
89
+ ; TileData. Whenever a label is defined with nothing following
90
+ ; it (except possibly a colon) it is given the value of the
91
+ ; current ROM location.
92
+ ; As a result, TileData now has a memory location value that
93
+ ; is the same as the first byte of the font data that we are
94
+ ; including. We shall use the label TileData as a "handle" or
95
+ ; "reference" for locating our font data.
96
+
97
+ TileData:
98
+ chr_IBMPC1 1,8
99
+
100
+ ; The NOP and then JP located at $100 in ROM are executed
101
+ ; which causes the the following code to be executed next.
102
+
103
+ begin:
104
+
105
+ ; First, it's a good idea to Disable Interrupts
106
+ ; using the following command. We won't be using
107
+ ; interrupts in this example so we can leave them off.
108
+
109
+ di
110
+
111
+ ; Next, we should initialize our stack pointer. The
112
+ ; stack pointer holds return addresses (among other things)
113
+ ; when we use the CALL command so the stack is important to us.
114
+ ;
115
+ ; The CALL command is similar to the GOSUB command
116
+ ; in the BASIC language and it is similar to executing
117
+ ; a procedure in the C & PASCAL languages.
118
+ ;
119
+ ; We shall set the stack to the top of high ram + 1.
120
+ ; (For more information on the Stack Pointer register
121
+ ; read the section on Registers.)
122
+ ;
123
+
124
+ ld sp,$ffff
125
+
126
+ ; Next we shall turn the Liquid Crystal Display (LCD)
127
+ ; off so that we can copy data to video RAM. We can
128
+ ; copy data to video RAM while the LCD is on but it
129
+ ; is a little more difficult to do and takes a little
130
+ ; bit longer. Video RAM is not always available for
131
+ ; reading or writing when the LCD is on so it is
132
+ ; easier to write to video RAM with the screen off.
133
+ ; ( In future examples, writing to video RAM while the
134
+ ; screen is on will be covered.)
135
+ ;
136
+ ; To turn off the LCD we do a CALL to the StopLCD
137
+ ; subroutine at the bottom of this file. The reason
138
+ ; we use a subroutine is because it takes more than
139
+ ; just writing to a memory location to turn the
140
+ ; LCD display off. The LCD display should be in
141
+ ; Vertical Blank (or VBlank) before we turn the display
142
+ ; off. Weird effects can occur if you don't wait until
143
+ ; VBlank to do this and code written for the Super
144
+ ; GameBoy won't work sometimes you try to turn off
145
+ ; the LCD outside of VBlank.
146
+ ;
147
+ ; The StopLCD routine is terminated by a RET command.
148
+ ; The RET command is similar to the RETURN command in
149
+ ; BASIC.
150
+
151
+ call StopLCD
152
+
153
+ ; Here we are going to setup the background tile
154
+ ; palette so that the tiles appear in the proper
155
+ ; shades of grey.
156
+ ;
157
+ ; To do this, we need to write the value $e4 to the
158
+ ; memory location $ff47. In the 'gbhw.inc' file we
159
+ ; INCLUDEd there is a definition that rBGP=$ff47 so
160
+ ; we can use the rGBP label to do this
161
+ ;
162
+ ; The first instruction loads the value $e4 into the
163
+ ; 8-bit register A and the second instruction writes
164
+ ; the value of register A to memory location $ff47.
165
+
166
+ ld a,$e4
167
+ ld [rBGP],a ; Setup the default background palette
168
+
169
+ ; Here we are setting the X/Y scroll registers
170
+ ; for the tile background to 0 so that we can see
171
+ ; the upper left corner of the tile background.
172
+ ;
173
+ ; Think of the tile background RAM (which we usually call
174
+ ; the tile map RAM) as a large canvas. We draw on this
175
+ ; 'canvas' using 'paints' which consist of tiles and
176
+ ; sprites (we will cover sprites in another example.)
177
+ ;
178
+ ; We set the scroll registers to 0 so that we can
179
+ ; view the upper left corner of the 'canvas'.
180
+
181
+ ld a,0
182
+ ld [rSCX],a
183
+ ld [rSCY],a
184
+
185
+ ; In order to display any text on our 'canvas'
186
+ ; we must have tiles which resemble letters that
187
+ ; we can use for 'painting'. In order to setup
188
+ ; tile memory we will need to copy our font data
189
+ ; to tile memory using the routine 'mem_CopyMono'
190
+ ; found in the 'memory.asm' library we INCLUDEd
191
+ ; earlier.
192
+ ;
193
+ ; For the purposes of the 'mem_CopyMono' routine,
194
+ ; the 16-bit HL register is used as a source memory
195
+ ; location, DE is used as a destination memory location,
196
+ ; and BC is used as a data length indicator.
197
+
198
+ ld hl,TileData
199
+ ld de,$8000
200
+ ld bc,8*256 ; length (8 bytes per tile) x (256 tiles)
201
+ call mem_CopyMono ; Copy tile data to memory
202
+
203
+ ; Next, we clear our 'canvas' to all white by
204
+ ; 'setting' the canvas to ascii character $20
205
+ ; which is a white space.
206
+
207
+ ld a,$20 ; Clear tile map memory
208
+ ld hl,$9800
209
+ ld bc,SCRN_VX_B * SCRN_VY_B
210
+ call mem_Set
211
+
212
+ ; We are almost done. Now we need to paint the message
213
+ ; " Hello World !" onto our 'canvas'. We do this with
214
+ ; one final memory copy routine call.
215
+ ;
216
+ ; The routine 'mem_Copy' is a 'true' memory copying routine.
217
+ ; The routine 'mem_CopyMono' used above served two functions:
218
+ ; One was to unpack the font tile data and the other was
219
+ ; to copy this data to tile RAM.
220
+
221
+ ld hl,Title ; Draw title
222
+ ld de,$9800+3+(SCRN_VY_B*7)
223
+ ld bc,13
224
+ call mem_Copy
225
+
226
+ ; Now we turn on the LCD display to view the results!
227
+
228
+ ld a,LCDCF_ON|LCDCF_BG8000|LCDCF_BG9800|LCDCF_BGON|LCDCF_OBJ16|LCDCF_OBJOFF
229
+ ld [rLCDC],a ; Turn screen on
230
+
231
+ ; Since we have accomplished our goal, we now have nothing
232
+ ; else to do. As a result, we just Jump to a label that
233
+ ; causes an infinite loop condition to occur.
234
+
235
+ .wait:
236
+ jp .wait
237
+
238
+ Title:
239
+ DB "Hello World !"
240
+
241
+
242
+ ; *** Turn off the LCD display ***
243
+
244
+ StopLCD:
245
+ ld a,[rLCDC]
246
+ rlca ; Put the high bit of LCDC into the Carry flag
247
+ ret nc ; Screen is off already. Exit.
248
+
249
+ ; Loop until we are in VBlank
250
+
251
+ .wait:
252
+ ld a,[rLY]
253
+ cp 145 ; Is display on scan line 145 yet?
254
+ jr nz,.wait ; no, keep waiting
255
+
256
+ ; Turn off the LCD
257
+
258
+ ld a,[rLCDC]
259
+ res 7,a ; Reset bit 7 of LCDC
260
+ ld [rLCDC],a
261
+
262
+ ret
263
+
264
+
265
+ ;* End of File *
266
+