rubygb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/Gemfile.lock +13 -1
  4. data/README.md +3 -3
  5. data/lib/galp/memory.inc +153 -0
  6. data/lib/rgbds/LICENSE +32 -0
  7. data/lib/rubygb/cli.rb +26 -2
  8. data/lib/rubygb/template/template.rb +99 -0
  9. data/lib/rubygb/version.rb +1 -1
  10. data/lib/rubygb.rb +1 -0
  11. data/rubygb.gemspec +2 -0
  12. data/scrap/example/gbhw.inc +645 -0
  13. data/{lib/galp/EXAMPLE1.TXT → scrap/example/hello-world-with-comments.asm} +123 -113
  14. data/scrap/example/hello-world-with-comments.gb +0 -0
  15. data/scrap/example/hello-world-with-comments.map +65 -0
  16. data/scrap/example/hello-world-with-comments.obj +0 -0
  17. data/scrap/example/hello-world-with-comments.sym +12 -0
  18. data/scrap/example/ibmpc1.inc +2400 -0
  19. data/scrap/test/lib/gbhw.inc +645 -0
  20. data/scrap/test/lib/ibmpx1.inc +2400 -0
  21. data/scrap/test/lib/memory.inc +153 -0
  22. data/scrap/test/test.gb +0 -0
  23. data/scrap/test/test.map +65 -0
  24. data/scrap/test/test.obj +0 -0
  25. data/scrap/test/test.s +91 -0
  26. data/scrap/test/test.sym +12 -0
  27. metadata +37 -31
  28. data/lib/galp/AND.GIF +0 -0
  29. data/lib/galp/ARROW.GIF +0 -0
  30. data/lib/galp/C.BAT +0 -5
  31. data/lib/galp/CHANGES.TXT +0 -5
  32. data/lib/galp/EXAMPLE.LNK +0 -7
  33. data/lib/galp/GBSPEC.TXT +0 -1761
  34. data/lib/galp/INDEX.HTM +0 -23
  35. data/lib/galp/INSTR.HTM +0 -563
  36. data/lib/galp/MEM1.HTM +0 -199
  37. data/lib/galp/OPCODES.HTM +0 -351
  38. data/lib/galp/OR.GIF +0 -0
  39. data/lib/galp/README.TXT +0 -4
  40. data/lib/galp/REGS.HTM +0 -77
  41. data/lib/galp/RL.GIF +0 -0
  42. data/lib/galp/RLC.GIF +0 -0
  43. data/lib/galp/RR.GIF +0 -0
  44. data/lib/galp/RRC.GIF +0 -0
  45. data/lib/galp/SETUP.BAT +0 -7
  46. data/lib/galp/SLA.GIF +0 -0
  47. data/lib/galp/SRA.GIF +0 -0
  48. data/lib/galp/SRL.GIF +0 -0
  49. data/lib/galp/START.HTM +0 -24
  50. data/lib/galp/SWAP.GIF +0 -0
  51. data/lib/galp/VID1.HTM +0 -34
  52. data/lib/galp/XOR.GIF +0 -0
  53. /data/lib/galp/{GBHW.TXT → gbhw.inc} +0 -0
  54. /data/lib/galp/{IBMPC1.TXT → ibmpx1.inc} +0 -0
  55. /data/{lib/galp/MEMORY.TXT → scrap/example/memory.asm} +0 -0
@@ -1,27 +1,27 @@
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
1
+ ; Hello World
2
+ ; John Harrison
3
+ ; With lots o' code borrowed from all over the place
4
+ ; some tutorial-like comments stolen from "hello world" by GABY
5
+
6
+ ; VERSIONS
7
+ ; 1.01 02/09/07
8
+ ; fixed typos and clarified a few things in the comments
9
+ ; 1.00 02/02/07
10
+
11
+ ; Most GameBoy assemblers (and most other assembly
12
12
  ; language assemblers) use a semicolon to indicate
13
13
  ; that everything following it on a particular line
14
14
  ; is to be ignored and be treated purely as comments
15
15
  ; rather than code.
16
- ;
17
- ; The first thing we want to do is include the
16
+
17
+ ; gbhw.inc contains the
18
18
  ; 'Hardware Defines' for our program. This has
19
19
  ; address location labels for all of the GameBoy
20
20
  ; Hardware I/O registers. We can 'insert' this file
21
21
  ; into the present EXAMPLE1.ASM file by using the
22
22
  ; assembler INCLUDE command:
23
23
 
24
- INCLUDE "gbhw.inc"
24
+ INCLUDE "gbhw.inc" ; standard hardware definitions from devrs.com
25
25
 
26
26
  ; Next we want to include a file that contains a font
27
27
  ; macro. A macro is a portion of code or data that
@@ -31,14 +31,23 @@
31
31
  ; inserted into a program until you invoke a macro which
32
32
  ; we will do later. For now, we are just making the macro
33
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
34
 
41
- INCLUDE "ibmpc1.inc"
35
+ INCLUDE "ibmpc1.inc" ; ASCII character set from devrs.com
36
+
37
+ ; We are going to keep interrupts disabled for this program.
38
+ ; However, it is good practice to leave the reserved memory locations for interrupts with
39
+ ; executable code. It make for a nice template as well to fill in code when we use interrupts
40
+ ; in the future
41
+ SECTION "Vblank",HOME[$0040]
42
+ reti
43
+ SECTION "LCDC",HOME[$0048]
44
+ reti
45
+ SECTION "Timer_Overflow",HOME[$0050]
46
+ reti
47
+ SECTION "Serial",HOME[$0058]
48
+ reti
49
+ SECTION "p1thru4",HOME[$0060]
50
+ reti
42
51
 
43
52
  ; Next we need to include the standard GameBoy ROM header
44
53
  ; information that goes at location $0100 in the ROM. (The
@@ -55,10 +64,9 @@
55
64
  ; start at address $100 by using the following SECTION assembler
56
65
  ; command:
57
66
 
58
- SECTION "Org $100",HOME[$100]
59
-
60
- nop
61
- jp begin
67
+ SECTION "start",HOME[$0100]
68
+ nop
69
+ jp begin
62
70
 
63
71
  ; To include the standard ROM header information we
64
72
  ; can just use the macro ROM_HEADER. We defined this macro
@@ -71,12 +79,15 @@
71
79
  ; Next we indicate the cart ROM size and then the cart RAM size.
72
80
  ; We don't need any cart RAM for this program so we set this to 0K.
73
81
 
74
- ROM_HEADER ROM_NOMBC, ROM_SIZE_32KBYTE, RAM_SIZE_0KBYTE
82
+ ; ****************************************************************************************
83
+ ; ROM HEADER and ASCII character set
84
+ ; ****************************************************************************************
85
+ ; ROM header
86
+ ROM_HEADER ROM_NOMBC, ROM_SIZE_32KBYTE, RAM_SIZE_0KBYTE
75
87
 
76
88
  ; Next we need to include some code for doing
77
89
  ; RAM copy, RAM fill, etc.
78
-
79
- INCLUDE "memory.asm"
90
+ INCLUDE "memory.asm"
80
91
 
81
92
  ; Next, let's actually include font tile data into the ROM
82
93
  ; that we are building. We do this by invoking the chr_IBMPC1
@@ -86,85 +97,57 @@
86
97
  ; whole IBM-PC font set and not just parts of it.
87
98
  ;
88
99
  ; 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.
100
+ ; TileData. Whenever a label is defined with a colon
92
101
  ; As a result, TileData now has a memory location value that
93
102
  ; is the same as the first byte of the font data that we are
94
103
  ; including. We shall use the label TileData as a "handle" or
95
104
  ; "reference" for locating our font data.
96
105
 
97
106
  TileData:
98
- chr_IBMPC1 1,8
107
+ chr_IBMPC1 1,8 ; LOAD ENTIRE CHARACTER SET
99
108
 
100
109
  ; The NOP and then JP located at $100 in ROM are executed
101
110
  ; which causes the the following code to be executed next.
102
111
 
112
+ ; ****************************************************************************************
113
+ ; Main code Initialization:
114
+ ; set the stack pointer, enable interrupts, set the palette, set the screen relative to the window
115
+ ; copy the ASCII character table, clear the screen
116
+ ; ****************************************************************************************
103
117
  begin:
104
-
105
118
  ; First, it's a good idea to Disable Interrupts
106
119
  ; using the following command. We won't be using
107
120
  ; interrupts in this example so we can leave them off.
108
121
 
109
- di
122
+ di
110
123
 
111
124
  ; Next, we should initialize our stack pointer. The
112
125
  ; stack pointer holds return addresses (among other things)
113
126
  ; when we use the CALL command so the stack is important to us.
114
127
  ;
115
- ; The CALL command is similar to the GOSUB command
116
- ; in the BASIC language and it is similar to executing
128
+ ; The CALL command is similar to executing
117
129
  ; a procedure in the C & PASCAL languages.
118
130
  ;
119
131
  ; 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
132
  ;
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
133
+ ld sp, $ffff ; set the stack pointer to highest mem location we can use + 1
152
134
 
153
135
  ; Here we are going to setup the background tile
154
136
  ; palette so that the tiles appear in the proper
155
137
  ; shades of grey.
156
138
  ;
157
- ; To do this, we need to write the value $e4 to the
139
+ ; To do this, we need to write the value %11100100 to the
158
140
  ; memory location $ff47. In the 'gbhw.inc' file we
159
141
  ; INCLUDEd there is a definition that rBGP=$ff47 so
160
142
  ; we can use the rGBP label to do this
161
143
  ;
162
- ; The first instruction loads the value $e4 into the
144
+ ; The first instruction loads the value %11100100 into the
163
145
  ; 8-bit register A and the second instruction writes
164
146
  ; the value of register A to memory location $ff47.
165
147
 
166
- ld a,$e4
167
- ld [rBGP],a ; Setup the default background palette
148
+ init:
149
+ ld a, %11100100 ; Window palette colors, from darkest to lightest
150
+ ld [rBGP], a ; CLEAR THE SCREEN
168
151
 
169
152
  ; Here we are setting the X/Y scroll registers
170
153
  ; for the tile background to 0 so that we can see
@@ -178,10 +161,31 @@ begin:
178
161
  ; We set the scroll registers to 0 so that we can
179
162
  ; view the upper left corner of the 'canvas'.
180
163
 
181
- ld a,0
182
- ld [rSCX],a
183
- ld [rSCY],a
164
+ ld a,0 ; SET SCREEN TO TO UPPER RIGHT HAND CORNER
165
+ ld [rSCX], a
166
+ ld [rSCY], a
167
+
168
+ ; Next we shall turn the Liquid Crystal Display (LCD)
169
+ ; off so that we can copy data to video RAM. We can
170
+ ; copy data to video RAM while the LCD is on but it
171
+ ; is a little more difficult to do and takes a little
172
+ ; bit longer. Video RAM is not always available for
173
+ ; reading or writing when the LCD is on so it is
174
+ ; easier to write to video RAM with the screen off.
175
+ ;
176
+ ; To turn off the LCD we do a CALL to the StopLCD
177
+ ; subroutine at the bottom of this file. The reason
178
+ ; we use a subroutine is because it takes more than
179
+ ; just writing to a memory location to turn the
180
+ ; LCD display off. The LCD display should be in
181
+ ; Vertical Blank (or VBlank) before we turn the display
182
+ ; off. Weird effects can occur if you don't wait until
183
+ ; VBlank to do this and code written for the Super
184
+ ; GameBoy won't work sometimes you try to turn off
185
+ ; the LCD outside of VBlank.
184
186
 
187
+ call StopLCD ; YOU CAN NOT LOAD $8000 WITH LCD ON
188
+
185
189
  ; In order to display any text on our 'canvas'
186
190
  ; we must have tiles which resemble letters that
187
191
  ; we can use for 'painting'. In order to setup
@@ -195,52 +199,62 @@ begin:
195
199
  ; location, DE is used as a destination memory location,
196
200
  ; and BC is used as a data length indicator.
197
201
 
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
-
202
+ ld hl, TileData
203
+ ld de, _VRAM ; $8000
204
+ ld bc, 8*256 ; the ASCII character set: 256 characters, each with 8 bytes of display data
205
+ call mem_CopyMono ; load tile data
206
+
207
+ ; We turn the LCD on. Parameters are explained in the I/O registers section of The GameBoy reference under I/O register LCDC
208
+ ld a, LCDCF_ON|LCDCF_BG8000|LCDCF_BG9800|LCDCF_BGON|LCDCF_OBJ16|LCDCF_OBJOFF
209
+ ld [rLCDC], a
210
+
203
211
  ; Next, we clear our 'canvas' to all white by
204
212
  ; 'setting' the canvas to ascii character $20
205
213
  ; which is a white space.
206
214
 
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
215
+ ld a, 32 ; ASCII FOR BLANK SPACE
216
+ ld hl, _SCRN0
217
+ ld bc, SCRN_VX_B * SCRN_VY_B
218
+ call mem_SetVRAM
219
+
220
+
221
+ ; ****************************************************************************************
222
+ ; Main code:
223
+ ; Print a character string in the middle of the screen
224
+ ; ****************************************************************************************
225
+ ; Now we need to paint the message
213
226
  ; " Hello World !" onto our 'canvas'. We do this with
214
227
  ; 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
228
 
229
+ ld hl,Title
230
+ ld de, _SCRN0+3+(SCRN_VY_B*7) ;
231
+ ld bc, TitleEnd-Title
232
+ call mem_CopyVRAM
233
+
234
+ ; ****************************************************************************************
235
+ ; Prologue
236
+ ; Wait patiently 'til somebody kills you
237
+ ; ****************************************************************************************
231
238
  ; Since we have accomplished our goal, we now have nothing
232
239
  ; else to do. As a result, we just Jump to a label that
233
240
  ; causes an infinite loop condition to occur.
234
-
235
- .wait:
236
- jp .wait
237
-
241
+ wait:
242
+ halt
243
+ nop
244
+ jr wait
245
+
246
+ ; ****************************************************************************************
247
+ ; hard-coded data
248
+ ; ****************************************************************************************
238
249
  Title:
239
- DB "Hello World !"
240
-
241
-
242
- ; *** Turn off the LCD display ***
243
-
250
+ DB "Hello World !"
251
+ TitleEnd:
252
+
253
+ ; ****************************************************************************************
254
+ ; StopLCD:
255
+ ; turn off LCD if it is on
256
+ ; and wait until the LCD is off
257
+ ; ****************************************************************************************
244
258
  StopLCD:
245
259
  ld a,[rLCDC]
246
260
  rlca ; Put the high bit of LCDC into the Carry flag
@@ -260,7 +274,3 @@ StopLCD:
260
274
  ld [rLCDC],a
261
275
 
262
276
  ret
263
-
264
-
265
- ;* End of File *
266
-
@@ -0,0 +1,65 @@
1
+ ROM Bank #0 (HOME):
2
+ SECTION: $0040-$0040 ($0001 bytes)
3
+ SECTION: $0048-$0048 ($0001 bytes)
4
+ SECTION: $0050-$0050 ($0001 bytes)
5
+ SECTION: $0058-$0058 ($0001 bytes)
6
+ SECTION: $0060-$0060 ($0001 bytes)
7
+ SECTION: $0100-$09AC ($08AD bytes)
8
+ $0952 = begin
9
+ $099C = StopLCD
10
+ $0150 = TileData
11
+ $098F = Title
12
+ $099C = TitleEnd
13
+ SECTION: $0061-$00B6 ($0056 bytes)
14
+ $007B = mem_CopyMono
15
+ $008B = mem_SetVRAM
16
+ $00A1 = mem_CopyVRAM
17
+ $0061 = mem_Set
18
+ $006D = mem_Copy
19
+ SLACK: $36F8 bytes
20
+
21
+ WRAM Bank #0:
22
+ EMPTY
23
+
24
+ WRAM Bank #1:
25
+ EMPTY
26
+
27
+ WRAM Bank #2:
28
+ EMPTY
29
+
30
+ WRAM Bank #3:
31
+ EMPTY
32
+
33
+ WRAM Bank #4:
34
+ EMPTY
35
+
36
+ WRAM Bank #5:
37
+ EMPTY
38
+
39
+ WRAM Bank #6:
40
+ EMPTY
41
+
42
+ WRAM Bank #7:
43
+ EMPTY
44
+
45
+ VRAM Bank #0:
46
+ EMPTY
47
+
48
+ VRAM Bank #1:
49
+ EMPTY
50
+
51
+ HRAM:
52
+ EMPTY
53
+
54
+ SRAM Bank #0:
55
+ EMPTY
56
+
57
+ SRAM Bank #1:
58
+ EMPTY
59
+
60
+ SRAM Bank #2:
61
+ EMPTY
62
+
63
+ SRAM Bank #3:
64
+ EMPTY
65
+
@@ -0,0 +1,12 @@
1
+ ;File generated by rgblink
2
+
3
+ 00:0952 begin
4
+ 00:099C StopLCD
5
+ 00:0150 TileData
6
+ 00:098F Title
7
+ 00:099C TitleEnd
8
+ 00:007B mem_CopyMono
9
+ 00:008B mem_SetVRAM
10
+ 00:00A1 mem_CopyVRAM
11
+ 00:0061 mem_Set
12
+ 00:006D mem_Copy