You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/cheatsheet.md
+48-48Lines changed: 48 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,12 +64,12 @@ WaitUntilVerticalBlankStart:
64
64
65
65
### Turn on/off the LCD
66
66
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` .
68
68
69
69
**To turn the LCD on:**
70
70
71
71
```rgbasm,linenos
72
-
ld a, LCDCF_ON
72
+
ld a, LCDC_ON
73
73
ldh [rLCDC], a
74
74
```
75
75
@@ -83,20 +83,20 @@ Do not turn the LCD off outside of the Vertical Blank Phase. See "[Wait for the
83
83
84
84
```rgbasm,linenos
85
85
; Turn the LCD off
86
-
ld a, LCDCF_OFF
86
+
ld a, LCDC_OFF
87
87
ldh [rLCDC], a
88
88
```
89
89
90
90
### Turn on/off the background
91
91
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.
93
93
94
94
**To turn the background on:**
95
95
96
96
```rgbasm,linenos
97
97
; Turn the background on
98
98
ldh a, [rLCDC]
99
-
or a, LCDCF_BGON
99
+
or a, LCDC_BG_ON
100
100
ldh [rLCDC], a
101
101
```
102
102
@@ -105,20 +105,20 @@ ldh [rLCDC], a
105
105
```rgbasm,linenos
106
106
; Turn the background off
107
107
ldh a, [rLCDC]
108
-
and a, ~LCDCF_BGON
108
+
and a, ~LCDC_BG_ON
109
109
ldh [rLCDC], a
110
110
```
111
111
112
112
### Turn on/off the window
113
113
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.
115
115
116
116
**To turn the window on:**
117
117
118
118
```rgbasm,linenos
119
119
; Turn the window on
120
120
ldh a, [rLCDC]
121
-
or a, LCDCF_WINON
121
+
or a, LCDC_WIN_ON
122
122
ldh [rLCDC], a
123
123
```
124
124
@@ -127,7 +127,7 @@ ldh [rLCDC], a
127
127
```rgbasm,linenos
128
128
; Turn the window off
129
129
ldh a, [rLCDC]
130
-
and a, LCDCF_WINOFF
130
+
and a, LCDC_WIN_OFF
131
131
ldh [rLCDC], a
132
132
```
133
133
@@ -141,10 +141,10 @@ Which region the background uses is controlled by the 4th bit of the `rLCDC` reg
141
141
142
142
You can use one of the 4 constants to specify which layer uses which region:
143
143
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
148
148
149
149
:::tip Note
150
150
@@ -154,14 +154,14 @@ You still need to make sure the window and background are turned on when using t
154
154
155
155
### Turn on/off sprites
156
156
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.
158
158
159
159
**To turn sprite objects on:**
160
160
161
161
```rgbasm,linenos
162
162
; Turn the sprites on
163
163
ldh a, [rLCDC]
164
-
or a, LCDCF_OBJON
164
+
or a, LCDC_OBJ_ON
165
165
ldh [rLCDC], a
166
166
```
167
167
@@ -170,7 +170,7 @@ ldh [rLCDC], a
170
170
```rgbasm,linenos
171
171
; Turn the sprites off
172
172
ldh a, [rLCDC]
173
-
and a, LCDCF_OBJOFF
173
+
and a, LCDC_OBJ_OFF
174
174
ldh [rLCDC], a
175
175
```
176
176
@@ -182,7 +182,7 @@ Sprites are in 8x8 mode by default.
182
182
183
183
### Turn on/off tall (8x16) sprites
184
184
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`
186
186
187
187
:::tip
188
188
@@ -193,15 +193,15 @@ You can not have some 8x8 sprites and some 8x16 sprites. All sprites must be of
193
193
```rgbasm,linenos
194
194
; Turn tall sprites on
195
195
ldh a, [rLCDC]
196
-
or a, LCDCF_OBJ16
196
+
or a, LCDC_OBJ_16
197
197
ldh [rLCDC], a
198
198
```
199
199
200
200
## Backgrounds
201
201
202
202
### Put background/window tile data into VRAM
203
203
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.
205
205
206
206
```rgbasm, lineno
207
207
MyBackground:
@@ -211,7 +211,7 @@ MyBackground:
211
211
CopyBackgroundWindowTileDataIntoVram:
212
212
; Copy the tile data
213
213
ld de, myBackground
214
-
ld hl, \_VRAM
214
+
ld hl, STARTOF(VRAM) + $1000
215
215
ld bc, MyBackground.end - MyBackground
216
216
.loop:
217
217
ld a, [de]
@@ -328,20 +328,20 @@ call UpdateKeys
328
328
329
329
You can check if a button is down using any of the following constants from hardware.inc:
330
330
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
339
339
340
340
You can check if the associataed button is down using the `wCurKeys` variable:
341
341
342
342
```rgbasm,linenos
343
343
ld a, [wCurKeys]
344
-
and a, PADF_LEFT
344
+
and a, PAD_LEFT
345
345
jp nz, LeftIsPressedDown
346
346
```
347
347
@@ -351,7 +351,7 @@ You can tell if a button was JUST pressed using the `wNewKeys` variable
351
351
352
352
```rgbasm,linenos
353
353
ld a, [wNewKeys]
354
-
and a, PADF_A
354
+
and a, PAD_A
355
355
jp nz, AWasJustPressed
356
356
```
357
357
@@ -374,7 +374,7 @@ This will halt all other logic (outside of interrupts), be careful if you need a
374
374
```rgbasm, linenos
375
375
WaitForAButtonToBePressed:
376
376
ld a, [wNewKeys]
377
-
and a, PADF_A
377
+
and a, PAD_A
378
378
ret nz
379
379
WaitUntilVerticalBlankStart:
380
380
ld a, [rLY]
@@ -515,7 +515,7 @@ Sprites will still show over the window. To fully prevent that, you can use STAT
515
515
516
516
### Put sprite tile data in VRAM
517
517
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.
519
519
520
520
```rgbasm,linenos
521
521
mySprite: INCBIN "src/path/to/my/sprite.2bpp"
@@ -524,7 +524,7 @@ mySpriteEnd:
524
524
CopySpriteTileDataIntoVram:
525
525
; Copy the tile data
526
526
ld de, Paddle
527
-
ld hl, _VRAM
527
+
ld hl, STARTOF(VRAM)
528
528
ld bc, mySpriteEnd - mySprite
529
529
CopySpriteTileDataIntoVram_Loop:
530
530
ld a, [de]
@@ -547,29 +547,29 @@ Each hardware sprite has 4 bytes: (in this order)
547
547
548
548
Check out the Pan Docs page on [Object Attribute Memory (OAM)](https://gbdev.io/pandocs/OAM.html) for more info.
549
549
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`.
551
551
552
552
**Moving (the first) OAM sprite, one pixel downwards:**
553
553
554
554
```rgbasm, linenos
555
-
ld a, [_OAMRAM]
555
+
ld a, [STARTOF(OAM)]
556
556
inc a
557
-
ld [_OAMRAM], a
557
+
ld [STARTOF(OAM)], a
558
558
```
559
559
560
560
**Moving (the first) OAM sprite, one pixel to the right:**
561
561
562
562
```rgbasm, linenos
563
-
ld a, [_OAMRAM + 1]
563
+
ld a, [ + 1]
564
564
inc a
565
-
ld [_OAMRAM + 1], a
565
+
ld [STARTOF(OAM) + 1], a
566
566
```
567
567
568
568
**Setting the tile for the first OAM sprite:**
569
569
570
570
```rgbasm, linenos
571
571
ld a, 3
572
-
ld [_OAMRAM+2], a
572
+
ld [STARTOF(OAM)+2], a
573
573
```
574
574
575
575
**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
605
605
; Reset hardware OAM
606
606
xor a, a
607
607
ld b, 160
608
-
ld hl, _OAMRAM
608
+
ld hl, STARTOF(OAM)
609
609
.resetOAM
610
610
ld [hli], a
611
611
dec b
@@ -623,7 +623,7 @@ call hOAMDMA
623
623
624
624
### Manipulate Shadow OAM OAM sprites
625
625
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.
627
627
628
628
**Moving (the first) OAM sprite, one pixel downwards:**
629
629
@@ -656,13 +656,13 @@ wCurrentLevel:: db
656
656
657
657
```
658
658
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.
660
660
661
661
**To enable read/write access to SRAM:**
662
662
663
663
```rgbasm, linenos
664
664
665
-
ld a, CART_SRAM_ENABLE
665
+
ld a, RAMG_SRAM_ENABLE
666
666
ld [rRAMG], a
667
667
668
668
```
@@ -671,7 +671,7 @@ ld [rRAMG], a
671
671
672
672
```rgbasm, linenos
673
673
674
-
ld a, CART_SRAM_DISABLE
674
+
ld a, RAMG_SRAM_DISABLE
675
675
ld [rRAMG], a
676
676
677
677
```
@@ -703,7 +703,7 @@ When initializing your save data, you'll need to
703
703
;; Setup our save data
704
704
InitSaveData::
705
705
706
-
ld a, CART_SRAM_ENABLE
706
+
ld a, RAMG_SRAM_ENABLE
707
707
ld [rRAMG], a
708
708
709
709
ld a, 123
@@ -718,7 +718,7 @@ InitSaveData::
718
718
ld a, 0
719
719
ld [wCurrentLevel], a
720
720
721
-
ld a, CART_SRAM_DISABLE
721
+
ld a, RAMG_SRAM_DISABLE
722
722
ld [rRAMG], a
723
723
724
724
ret
@@ -731,14 +731,14 @@ Once your save file has been initialized, you can access any variable normally o
0 commit comments