Skip to content

Commit e3629e0

Browse files
authored
Update Hello World Part II and Cheatsheet to hardware.inc v5.3 (#140)
* docs (p1): update hardware.inc to v5.3 * docs (misc): update cheatsheet to hardware.inc v5.3 * docs (pt2): update getting-started to hardware.inc v5.3.0 * docs (pt2): update objects to hardware.inc v5.3.0 * docs (pt2): update functions to hardware.inc v5.3.0 * docs (pt2): update input to hardware.inc v5.3.0 * docs (pt2): update collision to hardware.inc v5.3.0 * docs (pt2): update bricks to hardware.inc v5.3.0 * docs (pt2): update bcd to hardware.inc v5.3.0 * docs (pt2): update audio to hardware.inc v5.3.0 * docs (pt1): clarify version in link * docs (pt2): clarify version in link * docs (*): version number prettier * docs (pt3): add note about v4.0 usage
1 parent 31f2637 commit e3629e0

File tree

26 files changed

+9410
-8692
lines changed

26 files changed

+9410
-8692
lines changed

src/assets/hello-world.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CopyTilemap:
5656
jp nz, CopyTilemap
5757

5858
; Turn the LCD on
59-
ld a, LCDCF_ON | LCDCF_BGON
59+
ld a, LCDC_ON | LCDCF_BG_ON
6060
ld [rLCDC], a
6161

6262
; During the first (blank) frame, initialize display registers

src/cheatsheet.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ WaitUntilVerticalBlankStart:
6464

6565
### Turn on/off the LCD
6666

67-
You can turn the LCD on and off by altering the most significant bit of the `rLCDC` register. hardware.inc a constant for this: `LCDCF_ON` .
67+
You can turn the LCD on and off by altering the most significant bit of the `rLCDC` register. hardware.inc a constant for this: `LCDC_ON` .
6868

6969
**To turn the LCD on:**
7070

7171
```rgbasm,linenos
72-
ld a, LCDCF_ON
72+
ld a, LCDC_ON
7373
ldh [rLCDC], a
7474
```
7575

@@ -83,20 +83,20 @@ Do not turn the LCD off outside of the Vertical Blank Phase. See "[Wait for the
8383

8484
```rgbasm,linenos
8585
; Turn the LCD off
86-
ld a, LCDCF_OFF
86+
ld a, LCDC_OFF
8787
ldh [rLCDC], a
8888
```
8989

9090
### Turn on/off the background
9191

92-
To turn the background layer on and off, alter the least significant bit of the `rLCDC` register. You can use the `LCDCF_BGON` constant for this.
92+
To turn the background layer on and off, alter the least significant bit of the `rLCDC` register. You can use the `LCDC_BG_ON` constant for this.
9393

9494
**To turn the background on:**
9595

9696
```rgbasm,linenos
9797
; Turn the background on
9898
ldh a, [rLCDC]
99-
or a, LCDCF_BGON
99+
or a, LCDC_BG_ON
100100
ldh [rLCDC], a
101101
```
102102

@@ -105,20 +105,20 @@ ldh [rLCDC], a
105105
```rgbasm,linenos
106106
; Turn the background off
107107
ldh a, [rLCDC]
108-
and a, ~LCDCF_BGON
108+
and a, ~LCDC_BG_ON
109109
ldh [rLCDC], a
110110
```
111111

112112
### Turn on/off the window
113113

114-
To turn the window layer on and off, alter the least significant bit of the `rLCDC` register. You can use the `LCDCF_WINON` and `LCDCF_WINOFF` constants for this.
114+
To turn the window layer on and off, alter the least significant bit of the `rLCDC` register. You can use the `LCDC_WIN_ON` and `LCDC_WIN_OFF` constants for this.
115115

116116
**To turn the window on:**
117117

118118
```rgbasm,linenos
119119
; Turn the window on
120120
ldh a, [rLCDC]
121-
or a, LCDCF_WINON
121+
or a, LCDC_WIN_ON
122122
ldh [rLCDC], a
123123
```
124124

@@ -127,7 +127,7 @@ ldh [rLCDC], a
127127
```rgbasm,linenos
128128
; Turn the window off
129129
ldh a, [rLCDC]
130-
and a, LCDCF_WINOFF
130+
and a, LCDC_WIN_OFF
131131
ldh [rLCDC], a
132132
```
133133

@@ -141,10 +141,10 @@ Which region the background uses is controlled by the 4th bit of the `rLCDC` reg
141141

142142
You can use one of the 4 constants to specify which layer uses which region:
143143

144-
- LCDCF_WIN9800
145-
- LCDCF_WIN9C00
146-
- LCDCF_BG9800
147-
- LCDCF_BG9C00
144+
- LCDC_WIN_9800
145+
- LCDC_WIN_9C00
146+
- LCDC_BG_9800
147+
- LCDC_BG_9C00
148148

149149
:::tip Note
150150

@@ -154,14 +154,14 @@ You still need to make sure the window and background are turned on when using t
154154

155155
### Turn on/off sprites
156156

157-
Sprites (or objects) can be toggled on and off using the 2nd bit of the `rLCDC` register. You can use the `LCDCF_OBJON` and `LCDCF_OBJOFF` constants for this.
157+
Sprites (or objects) can be toggled on and off using the 2nd bit of the `rLCDC` register. You can use the `LCDC_OBJ_ON` and `LCDC_OBJ_OFF` constants for this.
158158

159159
**To turn sprite objects on:**
160160

161161
```rgbasm,linenos
162162
; Turn the sprites on
163163
ldh a, [rLCDC]
164-
or a, LCDCF_OBJON
164+
or a, LCDC_OBJ_ON
165165
ldh [rLCDC], a
166166
```
167167

@@ -170,7 +170,7 @@ ldh [rLCDC], a
170170
```rgbasm,linenos
171171
; Turn the sprites off
172172
ldh a, [rLCDC]
173-
and a, LCDCF_OBJOFF
173+
and a, LCDC_OBJ_OFF
174174
ldh [rLCDC], a
175175
```
176176

@@ -182,7 +182,7 @@ Sprites are in 8x8 mode by default.
182182

183183
### Turn on/off tall (8x16) sprites
184184

185-
Once sprites are enabled, you can enable tall sprites using the 3rd bit of the `rLCDC` register: `LCDCF_OBJ16`
185+
Once sprites are enabled, you can enable tall sprites using the 3rd bit of the `rLCDC` register: `LCDC_OBJ_16`
186186

187187
:::tip
188188

@@ -193,15 +193,15 @@ You can not have some 8x8 sprites and some 8x16 sprites. All sprites must be of
193193
```rgbasm,linenos
194194
; Turn tall sprites on
195195
ldh a, [rLCDC]
196-
or a, LCDCF_OBJ16
196+
or a, LCDC_OBJ_16
197197
ldh [rLCDC], a
198198
```
199199

200200
## Backgrounds
201201

202202
### Put background/window tile data into VRAM
203203

204-
The region in VRAM dedicated for the background/window tilemaps is from $9000 to $97FF. hardware.inc defines a `_VRAM9000` constant you can use for that.
204+
The region in VRAM dedicated for the background/window tilemaps is from $9000 to $97FF. The assembly language defines a `STARTOF` function you can use that will help to determine the value at link time.
205205

206206
```rgbasm, lineno
207207
MyBackground:
@@ -211,7 +211,7 @@ MyBackground:
211211
CopyBackgroundWindowTileDataIntoVram:
212212
; Copy the tile data
213213
ld de, myBackground
214-
ld hl, \_VRAM
214+
ld hl, STARTOF(VRAM) + $1000
215215
ld bc, MyBackground.end - MyBackground
216216
.loop:
217217
ld a, [de]
@@ -328,20 +328,20 @@ call UpdateKeys
328328

329329
You can check if a button is down using any of the following constants from hardware.inc:
330330

331-
- PADF_DOWN
332-
- PADF_UP
333-
- PADF_LEFT
334-
- PADF_RIGHT
335-
- PADF_START
336-
- PADF_SELECT
337-
- PADF_B
338-
- PADF_A
331+
- PAD_DOWN
332+
- PAD_UP
333+
- PAD_LEFT
334+
- PAD_RIGHT
335+
- PAD_START
336+
- PAD_SELECT
337+
- PAD_B
338+
- PAD_A
339339

340340
You can check if the associataed button is down using the `wCurKeys` variable:
341341

342342
```rgbasm,linenos
343343
ld a, [wCurKeys]
344-
and a, PADF_LEFT
344+
and a, PAD_LEFT
345345
jp nz, LeftIsPressedDown
346346
```
347347

@@ -351,7 +351,7 @@ You can tell if a button was JUST pressed using the `wNewKeys` variable
351351

352352
```rgbasm,linenos
353353
ld a, [wNewKeys]
354-
and a, PADF_A
354+
and a, PAD_A
355355
jp nz, AWasJustPressed
356356
```
357357

@@ -374,7 +374,7 @@ This will halt all other logic (outside of interrupts), be careful if you need a
374374
```rgbasm, linenos
375375
WaitForAButtonToBePressed:
376376
ld a, [wNewKeys]
377-
and a, PADF_A
377+
and a, PAD_A
378378
ret nz
379379
WaitUntilVerticalBlankStart:
380380
ld a, [rLY]
@@ -515,7 +515,7 @@ Sprites will still show over the window. To fully prevent that, you can use STAT
515515

516516
### Put sprite tile data in VRAM
517517

518-
The region in VRAM dedicated for sprites is from `$8000` to `$87F0`. Hardware.inc defines a `_VRAM` constant you can use for that. To copy sprite tile data into VRAM, you can use a loop to copy the bytes.
518+
The region in VRAM dedicated for sprites is from `$8000` to `$87F0`. The assembly language defines a `STARTOF` function you can use for that. To copy sprite tile data into VRAM, you can use a loop to copy the bytes.
519519

520520
```rgbasm,linenos
521521
mySprite: INCBIN "src/path/to/my/sprite.2bpp"
@@ -524,7 +524,7 @@ mySpriteEnd:
524524
CopySpriteTileDataIntoVram:
525525
; Copy the tile data
526526
ld de, Paddle
527-
ld hl, _VRAM
527+
ld hl, STARTOF(VRAM)
528528
ld bc, mySpriteEnd - mySprite
529529
CopySpriteTileDataIntoVram_Loop:
530530
ld a, [de]
@@ -547,29 +547,29 @@ Each hardware sprite has 4 bytes: (in this order)
547547

548548
Check out the Pan Docs page on [Object Attribute Memory (OAM)](https://gbdev.io/pandocs/OAM.html) for more info.
549549

550-
The bytes controlling hardware OAM sprites start at `$FE00`, for which hardware.inc has defined a constant as `_OAMRAM`.
550+
The bytes controlling hardware OAM sprites start at `$FE00`, for which the assembly language has a section type `OAM`.
551551

552552
**Moving (the first) OAM sprite, one pixel downwards:**
553553

554554
```rgbasm, linenos
555-
ld a, [_OAMRAM]
555+
ld a, [STARTOF(OAM)]
556556
inc a
557-
ld [_OAMRAM], a
557+
ld [STARTOF(OAM)], a
558558
```
559559

560560
**Moving (the first) OAM sprite, one pixel to the right:**
561561

562562
```rgbasm, linenos
563-
ld a, [_OAMRAM + 1]
563+
ld a, [ + 1]
564564
inc a
565-
ld [_OAMRAM + 1], a
565+
ld [STARTOF(OAM) + 1], a
566566
```
567567

568568
**Setting the tile for the first OAM sprite:**
569569

570570
```rgbasm, linenos
571571
ld a, 3
572-
ld [_OAMRAM+2], a
572+
ld [STARTOF(OAM)+2], a
573573
```
574574

575575
**Moving (the fifth) OAM sprite, one pixel downwards:**
@@ -605,7 +605,7 @@ The library is relatively simple to get set up. First, put the following in your
605605
; Reset hardware OAM
606606
xor a, a
607607
ld b, 160
608-
ld hl, _OAMRAM
608+
ld hl, STARTOF(OAM)
609609
.resetOAM
610610
ld [hli], a
611611
dec b
@@ -623,7 +623,7 @@ call hOAMDMA
623623

624624
### Manipulate Shadow OAM OAM sprites
625625

626-
Once you've set up @eievui5's Sprite Object Library, you can manipulate shadow OAM sprites the exact same way you would manipulate normal hardware OAM sprites. Except, this time you would use the library's `wShadowOAM` constant instead of the `_OAMRAM` register.
626+
Once you've set up @eievui5's Sprite Object Library, you can manipulate shadow OAM sprites the exact same way you would manipulate normal hardware OAM sprites. Except, this time you would use the library's `wShadowOAM` constant instead of the `OAM` register.
627627

628628
**Moving (the first) OAM sprite, one pixel downwards:**
629629

@@ -656,13 +656,13 @@ wCurrentLevel:: db
656656
657657
```
658658

659-
To access SRAM, you need to write `CART_SRAM_ENABLE` to the `rRAMG` register. When done, you can disable SRAM using the `CART_SRAM_DISABLE` constant.
659+
To access SRAM, you need to write `RAMG_SRAM_ENABLE` to the `rRAMG` register. When done, you can disable SRAM using the `RAMG_SRAM_DISABLE` constant.
660660

661661
**To enable read/write access to SRAM:**
662662

663663
```rgbasm, linenos
664664
665-
ld a, CART_SRAM_ENABLE
665+
ld a, RAMG_SRAM_ENABLE
666666
ld [rRAMG], a
667667
668668
```
@@ -671,7 +671,7 @@ ld [rRAMG], a
671671

672672
```rgbasm, linenos
673673
674-
ld a, CART_SRAM_DISABLE
674+
ld a, RAMG_SRAM_DISABLE
675675
ld [rRAMG], a
676676
677677
```
@@ -703,7 +703,7 @@ When initializing your save data, you'll need to
703703
;; Setup our save data
704704
InitSaveData::
705705
706-
ld a, CART_SRAM_ENABLE
706+
ld a, RAMG_SRAM_ENABLE
707707
ld [rRAMG], a
708708
709709
ld a, 123
@@ -718,7 +718,7 @@ InitSaveData::
718718
ld a, 0
719719
ld [wCurrentLevel], a
720720
721-
ld a, CART_SRAM_DISABLE
721+
ld a, RAMG_SRAM_DISABLE
722722
ld [rRAMG], a
723723
724724
ret
@@ -731,14 +731,14 @@ Once your save file has been initialized, you can access any variable normally o
731731
;; Setup our save data
732732
StartNextLevel::
733733
734-
ld a, CART_SRAM_ENABLE
734+
ld a, RAMG_SRAM_ENABLE
735735
ld [rRAMG], a
736736
737737
ld a, [wCurrentLevel]
738738
cp a, 3
739739
call z, StartLevel3
740740
741-
ld a, CART_SRAM_DISABLE
741+
ld a, RAMG_SRAM_DISABLE
742742
ld [rRAMG], a
743743
744744
ret

src/part1/hello_world.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ It's a good idea to create a new directory (`mkdir gb_hello_world`, for example,
88

99
Grab the following files (right-click each link, "Save Link As..."), and place them all in this new directory:
1010
- [`hello-world.asm`](../assets/hello-world.asm)
11-
- [`hardware.inc`](https://raw.githubusercontent.com/gbdev/hardware.inc/v4.0/hardware.inc)
11+
- [`hardware.inc v5.3.0`](https://raw.githubusercontent.com/gbdev/hardware.inc/v5.3.0/hardware.inc)
1212

1313
Then, still from a terminal within that directory, run the following three commands.
1414

src/part2/bricks.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ It should go right **before** the momentum is modified.
3232
BounceOnTop:
3333
; Remember to offset the OAM position!
3434
; (8, 16) in OAM coordinates is (0, 0) on the screen.
35-
ld a, [_OAMRAM + 4]
35+
ld a, [STARTOF(OAM) + 4]
3636
sub a, 16 + 1
3737
ld c, a
38-
ld a, [_OAMRAM + 5]
38+
ld a, [STARTOF(OAM) + 5]
3939
sub a, 8
4040
ld b, a
4141
call GetTileByPixel ; Returns tile address in hl
@@ -47,10 +47,10 @@ BounceOnTop:
4747
ld [wBallMomentumY], a
4848
4949
BounceOnRight:
50-
ld a, [_OAMRAM + 4]
50+
ld a, [STARTOF(OAM) + 4]
5151
sub a, 16
5252
ld c, a
53-
ld a, [_OAMRAM + 5]
53+
ld a, [STARTOF(OAM) + 5]
5454
sub a, 8 - 1
5555
ld b, a
5656
call GetTileByPixel
@@ -62,10 +62,10 @@ BounceOnRight:
6262
ld [wBallMomentumX], a
6363
6464
BounceOnLeft:
65-
ld a, [_OAMRAM + 4]
65+
ld a, [STARTOF(OAM) + 4]
6666
sub a, 16
6767
ld c, a
68-
ld a, [_OAMRAM + 5]
68+
ld a, [STARTOF(OAM) + 5]
6969
sub a, 8 + 1
7070
ld b, a
7171
call GetTileByPixel
@@ -77,10 +77,10 @@ BounceOnLeft:
7777
ld [wBallMomentumX], a
7878
7979
BounceOnBottom:
80-
ld a, [_OAMRAM + 4]
80+
ld a, [STARTOF(OAM) + 4]
8181
sub a, 16 - 1
8282
ld c, a
83-
ld a, [_OAMRAM + 5]
83+
ld a, [STARTOF(OAM) + 5]
8484
sub a, 8
8585
ld b, a
8686
call GetTileByPixel

0 commit comments

Comments
 (0)