GBDK 2020 Docs  4.3.0
API Documentation for GBDK 2020
hardware.h
Go to the documentation of this file.
1 
7 #ifndef _HARDWARE_H
8 #define _HARDWARE_H
9 
10 #include <types.h>
11 
12 #define __BYTES extern UBYTE
13 #define __BYTE_REG extern volatile UBYTE
14 #define __REG extern volatile SFR
15 
31 
38 
42 #define rP1 P1_REG
43 
44 #define P1F_5 0b00100000
45 #define P1F_4 0b00010000
46 #define P1F_3 0b00001000
47 #define P1F_2 0b00000100
48 #define P1F_1 0b00000010
49 #define P1F_0 0b00000001
50 
51 #define P1F_GET_DPAD P1F_5
52 #define P1F_GET_BTN P1F_4
53 #define P1F_GET_NONE (P1F_4 | P1F_5)
54 
56 #define rSB SB_REG
58 #define rSC SC_REG
59 
60 #define SIOF_XFER_START 0b10000000
61 #define SIOF_CLOCK_INT 0b00000001
62 #define SIOF_CLOCK_EXT 0b00000000
63 #define SIOF_SPEED_1X 0b00000000
64 #define SIOF_SPEED_32X 0b00000010
65 #define SIOF_B_CLOCK 0
66 #define SIOF_B_SPEED 1
67 #define SIOF_B_XFER_START 7
68 #define SCF_START SIOF_XFER_START
69 #define SCF_SOURCE SIOF_CLOCK_INT
70 #define SCF_SPEED SIOF_SPEED_32X
71 
73 #define rDIV DIV_REG
75 #define rTIMA TIMA_REG
77 #define rTMA TMA_REG
79 #define rTAC TAC_REG
80 
81 #define TACF_START 0b00000100
82 #define TACF_STOP 0b00000000
83 #define TACF_4KHZ 0b00000000
84 #define TACF_16KHZ 0b00000011
85 #define TACF_65KHZ 0b00000010
86 #define TACF_262KHZ 0b00000001
87 
89 #define rIF IF_REG
90 
92 #define rAUD1SWEEP NR10_REG
93 #define AUD1SWEEP_UP 0b00000000
94 #define AUD1SWEEP_DOWN 0b00001000
95 #define AUD1SWEEP_TIME(x) ((x) << 4)
96 #define AUD1SWEEP_LENGTH(x) (x)
98 #define rAUD1LEN NR11_REG
100 #define rAUD1ENV NR12_REG
102 #define rAUD1LOW NR13_REG
104 #define rAUD1HIGH NR14_REG
107 #define rAUD2LEN NR21_REG
109 #define rAUD2ENV NR22_REG
111 #define rAUD2LOW NR23_REG
113 #define rAUD2HIGH NR24_REG
116 #define rAUD3ENA NR30_REG
118 #define rAUD3LEN NR31_REG
120 #define rAUD3LEVEL NR32_REG
122 #define rAUD3LOW NR33_REG
124 #define rAUD3HIGH NR34_REG
127 #define rAUD4LEN NR41_REG
129 #define rAUD4ENV NR42_REG
131 #define rAUD4POLY NR43_REG
132 #define AUD4POLY_WIDTH_15BIT 0x00
133 #define AUD4POLY_WIDTH_7BIT 0x08
135 #define rAUD4GO NR44_REG
138 #define rAUDVOL NR50_REG
140 #define AUDVOL_VOL_LEFT(x) ((x) << 4)
141 #define AUDVOL_VOL_RIGHT(x) ((x))
142 #define AUDVOL_VIN_LEFT 0b10000000
143 #define AUDVOL_VIN_RIGHT 0b00001000
146 #define rAUDTERM NR51_REG
148 #define AUDTERM_4_LEFT 0b10000000
149 #define AUDTERM_3_LEFT 0b01000000
150 #define AUDTERM_2_LEFT 0b00100000
151 #define AUDTERM_1_LEFT 0b00010000
152 #define AUDTERM_4_RIGHT 0b00001000
153 #define AUDTERM_3_RIGHT 0b00000100
154 #define AUDTERM_2_RIGHT 0b00000010
155 #define AUDTERM_1_RIGHT 0b00000001
158 #define rAUDENA NR52_REG
160 #define AUDENA_ON 0b10000000
161 #define AUDENA_OFF 0b00000000
165 
167 #define rLCDC LCDC_REG
168 
169 #if defined(__TARGET_ap)
170 #define LCDCF_OFF 0b00000000
171 #define LCDCF_ON 0b00000001
172 #define LCDCF_WIN9800 0b00000000
173 #define LCDCF_WIN9C00 0b00000010
174 #define LCDCF_WINOFF 0b00000000
175 #define LCDCF_WINON 0b00000100
176 #define LCDCF_BG8800 0b00000000
177 #define LCDCF_BG8000 0b00001000
178 #define LCDCF_BG9800 0b00000000
179 #define LCDCF_BG9C00 0b00010000
180 #define LCDCF_OBJ8 0b00000000
181 #define LCDCF_OBJ16 0b00100000
182 #define LCDCF_OBJOFF 0b00000000
183 #define LCDCF_OBJON 0b01000000
184 #define LCDCF_BGOFF 0b00000000
185 #define LCDCF_BGON 0b10000000
186 #define LCDCF_B_ON 0
187 #define LCDCF_B_WIN9C00 1
188 #define LCDCF_B_WINON 2
189 #define LCDCF_B_BG8000 3
190 #define LCDCF_B_BG9C00 4
191 #define LCDCF_B_OBJ16 5
192 #define LCDCF_B_OBJON 6
193 #define LCDCF_B_BGON 7
194 #elif defined(__TARGET_duck)
195 #define LCDCF_OFF 0b00000000
196 #define LCDCF_ON 0b10000000
197 #define LCDCF_WIN9800 0b00000000
198 #define LCDCF_WIN9C00 0b00001000
199 #define LCDCF_WINOFF 0b00000000
200 #define LCDCF_WINON 0b00100000
201 #define LCDCF_BG8800 0b00000000
202 #define LCDCF_BG8000 0b00010000
203 #define LCDCF_BG9800 0b00000000
204 #define LCDCF_BG9C00 0b00000100
205 #define LCDCF_OBJ8 0b00000000
206 #define LCDCF_OBJ16 0b00000010
207 #define LCDCF_OBJOFF 0b00000000
208 #define LCDCF_OBJON 0b00000001
209 #define LCDCF_BGOFF 0b00000000
210 #define LCDCF_BGON 0b01000000
211 #define LCDCF_B_ON 7
212 #define LCDCF_B_WIN9C00 3
213 #define LCDCF_B_WINON 5
214 #define LCDCF_B_BG8000 4
215 #define LCDCF_B_BG9C00 2
216 #define LCDCF_B_OBJ16 1
217 #define LCDCF_B_OBJON 0
218 #define LCDCF_B_BGON 6
219 #else
220 #define LCDCF_OFF 0b00000000
221 #define LCDCF_ON 0b10000000
222 #define LCDCF_WIN9800 0b00000000
223 #define LCDCF_WIN9C00 0b01000000
224 #define LCDCF_WINOFF 0b00000000
225 #define LCDCF_WINON 0b00100000
226 #define LCDCF_BG8800 0b00000000
227 #define LCDCF_BG8000 0b00010000
228 #define LCDCF_BG9800 0b00000000
229 #define LCDCF_BG9C00 0b00001000
230 #define LCDCF_OBJ8 0b00000000
231 #define LCDCF_OBJ16 0b00000100
232 #define LCDCF_OBJOFF 0b00000000
233 #define LCDCF_OBJON 0b00000010
234 #define LCDCF_BGOFF 0b00000000
235 #define LCDCF_BGON 0b00000001
236 #define LCDCF_B_ON 7
237 #define LCDCF_B_WIN9C00 6
238 #define LCDCF_B_WINON 5
239 #define LCDCF_B_BG8000 4
240 #define LCDCF_B_BG9C00 3
241 #define LCDCF_B_OBJ16 2
242 #define LCDCF_B_OBJON 1
243 #define LCDCF_B_BGON 0
244 #endif
245 
247 #define rSTAT STAT_REG
248 
249 #if defined(__TARGET_ap)
250 #define STATF_LYC 0b00000010
251 #define STATF_MODE10 0b00000100
252 #define STATF_MODE01 0b00001000
253 #define STATF_MODE00 0b00010000
254 #define STATF_LYCF 0b00100000
255 #define STATF_HBL 0b00000000
256 #define STATF_VBL 0b10000000
257 #define STATF_OAM 0b01000000
258 #define STATF_LCD 0b11000000
259 #define STATF_BUSY 0b01000000
260 #define STATF_B_LYC 1
261 #define STATF_B_MODE10 2
262 #define STATF_B_MODE01 3
263 #define STATF_B_MODE00 4
264 #define STATF_B_LYCF 5
265 #define STATF_B_VBL 7
266 #define STATF_B_OAM 6
267 #define STATF_B_BUSY 6
268 #else
269 #define STATF_LYC 0b01000000
270 #define STATF_MODE10 0b00100000
271 #define STATF_MODE01 0b00010000
272 #define STATF_MODE00 0b00001000
273 #define STATF_LYCF 0b00000100
274 #define STATF_HBL 0b00000000
275 #define STATF_VBL 0b00000001
276 #define STATF_OAM 0b00000010
277 #define STATF_LCD 0b00000011
278 #define STATF_BUSY 0b00000010
279 #define STATF_B_LYC 6
280 #define STATF_B_MODE10 5
281 #define STATF_B_MODE01 4
282 #define STATF_B_MODE00 3
283 #define STATF_B_LYCF 2
284 #define STATF_B_VBL 0
285 #define STATF_B_OAM 1
286 #define STATF_B_BUSY 1
287 #endif
288 
290 #define rSCY
292 #define rSCX SCX_REG
294 #define rLY LY_REG
296 #define rLYC LYC_REG
298 #define rDMA DMA_REG
300 #define rBGP BGP_REG
302 #define rOBP0 OBP0_REG
304 #define rOBP1 OBP1_REG
306 #define rWY WY_REG
308 #define rWX WX_REG
310 #define rKEY1 KEY1_REG
311 #define rSPD KEY1_REG
312 
313 #define KEY1F_DBLSPEED 0b10000000
314 #define KEY1F_PREPARE 0b00000001
315 
317 #define rVBK VBK_REG
318 
319 #define VBK_BANK_0 0
320 #define VBK_TILES 0
321 #define VBK_BANK_1 1
322 #define VBK_ATTRIBUTES 1
324 #define BKGF_PRI 0b10000000
325 #define BKGF_YFLIP 0b01000000
326 #define BKGF_XFLIP 0b00100000
327 #define BKGF_BANK0 0b00000000
328 #define BKGF_BANK1 0b00001000
330 #define BKGF_CGB_PAL0 0b00000000
331 #define BKGF_CGB_PAL1 0b00000001
332 #define BKGF_CGB_PAL2 0b00000010
333 #define BKGF_CGB_PAL3 0b00000011
334 #define BKGF_CGB_PAL4 0b00000100
335 #define BKGF_CGB_PAL5 0b00000101
336 #define BKGF_CGB_PAL6 0b00000110
337 #define BKGF_CGB_PAL7 0b00000111
340 #define rHDMA1 HDMA1_REG
342 #define rHDMA2 HDMA2_REG
344 #define rHDMA3 HDMA3_REG
346 #define rHDMA4 HDMA4_REG
348 #define rHDMA5 HDMA5_REG
349 
350 #define HDMA5F_MODE_GP 0b00000000
351 #define HDMA5F_MODE_HBL 0b10000000
352 
353 #define HDMA5F_BUSY 0b10000000
354 
356 #define rRP RP_REG
357 
358 #define RPF_ENREAD 0b11000000
359 #define RPF_DATAIN 0b00000010
360 #define RPF_WRITE_HI 0b00000001
361 #define RPF_WRITE_LO 0b00000000
362 
364 #define rBCPS BCPS_REG
365 
366 #define BCPSF_AUTOINC 0b10000000
368 #define rBCPD BCPD_REG
369 
371 #define rOCPS OCPS_REG
372 
373 #define OCPSF_AUTOINC 0b10000000
375 #define rOCPD OCPD_REG
377 #define rSVBK SVBK_REG
378 #define rSMBK SVBK_REG
379 
381 #define rPCM12 PCM12_REG
382 
384 #define rPCM34 PCM34_REG
385 
387 #define rIE IE_REG
388 
389 #define IEF_HILO 0b00010000
390 #define IEF_SERIAL 0b00001000
391 #define IEF_TIMER 0b00000100
392 #define IEF_STAT 0b00000010
393 #define IEF_VBLANK 0b00000001
396 /* Square wave duty cycle */
397 #define AUDLEN_DUTY_12_5 0b00000000
398 #define AUDLEN_DUTY_25 0b01000000
399 #define AUDLEN_DUTY_50 0b10000000
400 #define AUDLEN_DUTY_75 0b11000000
401 #define AUDLEN_LENGTH(x) (x)
402 
403 /* Audio envelope flags */
404 #define AUDENV_VOL(x) ((x) << 4)
405 #define AUDENV_UP 0b00001000
406 #define AUDENV_DOWN 0b00000000
407 #define AUDENV_LENGTH(x) (x)
408 
409 /* Audio trigger flags */
410 #define AUDHIGH_RESTART 0b10000000
411 #define AUDHIGH_LENGTH_ON 0b01000000
412 #define AUDHIGH_LENGTH_OFF 0b00000000
413 
414 /* OAM attributes flags */
415 #define OAMF_PRI 0b10000000
416 #define OAMF_YFLIP 0b01000000
417 #define OAMF_XFLIP 0b00100000
418 #define OAMF_PAL0 0b00000000
419 #define OAMF_PAL1 0b00010000
420 #define OAMF_BANK0 0b00000000
421 #define OAMF_BANK1 0b00001000
423 #define OAMF_CGB_PAL0 0b00000000
424 #define OAMF_CGB_PAL1 0b00000001
425 #define OAMF_CGB_PAL2 0b00000010
426 #define OAMF_CGB_PAL3 0b00000011
427 #define OAMF_CGB_PAL4 0b00000100
428 #define OAMF_CGB_PAL5 0b00000101
429 #define OAMF_CGB_PAL6 0b00000110
430 #define OAMF_CGB_PAL7 0b00000111
432 #define OAMF_PALMASK 0b00000111
434 #define DEVICE_SCREEN_X_OFFSET 0
435 #define DEVICE_SCREEN_Y_OFFSET 0
436 #define DEVICE_SCREEN_WIDTH 20
437 #define DEVICE_SCREEN_HEIGHT 18
438 #define DEVICE_SCREEN_BUFFER_WIDTH 32
439 #define DEVICE_SCREEN_BUFFER_HEIGHT 32
440 #define DEVICE_SCREEN_MAP_ENTRY_SIZE 1
441 #define DEVICE_SPRITE_PX_OFFSET_X 8
442 #define DEVICE_SPRITE_PX_OFFSET_Y 16
443 #define DEVICE_WINDOW_PX_OFFSET_X 7
444 #define DEVICE_WINDOW_PX_OFFSET_Y 0
445 #define DEVICE_SCREEN_PX_WIDTH (DEVICE_SCREEN_WIDTH * 8)
446 #define DEVICE_SCREEN_PX_HEIGHT (DEVICE_SCREEN_HEIGHT * 8)
448 #endif
__BYTE_REG rROMB1
Definition: hardware.h:36
__REG NR33_REG
Definition: hardware.h:121
__REG NR14_REG
Definition: hardware.h:103
__REG P1_REG
Definition: hardware.h:41
__BYTES _SRAM[]
Definition: hardware.h:24
#define __REG
Definition: hardware.h:14
__REG SC_REG
Definition: hardware.h:57
__BYTE_REG _IO[]
Definition: hardware.h:28
__REG OBP0_REG
Definition: hardware.h:301
__REG HDMA5_REG
Definition: hardware.h:347
__REG OCPS_REG
Definition: hardware.h:370
__REG WY_REG
Definition: hardware.h:305
__REG BCPD_REG
Definition: hardware.h:367
__REG SCY_REG
Definition: hardware.h:289
__REG NR32_REG
Definition: hardware.h:119
__BYTE_REG PCM_SAMPLE[16]
Definition: hardware.h:164
__REG BCPS_REG
Definition: hardware.h:363
__BYTES _RAMBANK[]
Definition: hardware.h:26
__BYTE_REG AUD3WAVE[16]
Definition: hardware.h:163
__REG WX_REG
Definition: hardware.h:307
__REG TMA_REG
Definition: hardware.h:76
__REG HDMA4_REG
Definition: hardware.h:345
#define __BYTE_REG
Definition: hardware.h:13
__REG NR13_REG
Definition: hardware.h:101
__REG PCM12_REG
Definition: hardware.h:380
__BYTE_REG _HRAM[]
Definition: hardware.h:30
__REG IF_REG
Definition: hardware.h:88
__REG NR43_REG
Definition: hardware.h:130
__REG NR41_REG
Definition: hardware.h:126
__REG HDMA3_REG
Definition: hardware.h:343
__REG LYC_REG
Definition: hardware.h:295
__REG VBK_REG
Definition: hardware.h:316
__REG SB_REG
Definition: hardware.h:55
__BYTE_REG rRAMG
Definition: hardware.h:34
__REG LCDC_REG
Definition: hardware.h:166
__REG TAC_REG
Definition: hardware.h:78
__REG NR24_REG
Definition: hardware.h:112
__BYTES _VRAM9000[]
Definition: hardware.h:21
__REG NR21_REG
Definition: hardware.h:106
__BYTES _OAMRAM[]
Definition: hardware.h:27
__BYTE_REG _AUD3WAVERAM[]
Definition: hardware.h:29
__REG KEY1_REG
Definition: hardware.h:309
__BYTES _VRAM8000[]
Definition: hardware.h:19
__REG RP_REG
Definition: hardware.h:355
__REG NR12_REG
Definition: hardware.h:99
__REG NR23_REG
Definition: hardware.h:110
__REG HDMA2_REG
Definition: hardware.h:341
__REG NR44_REG
Definition: hardware.h:134
__REG NR30_REG
Definition: hardware.h:115
__REG SCX_REG
Definition: hardware.h:291
__REG NR50_REG
Definition: hardware.h:137
__REG TIMA_REG
Definition: hardware.h:74
__REG OBP1_REG
Definition: hardware.h:303
__REG SVBK_REG
Definition: hardware.h:376
__REG IE_REG
Definition: hardware.h:386
__REG HDMA1_REG
Definition: hardware.h:339
#define __BYTES
Definition: hardware.h:12
__REG NR51_REG
Definition: hardware.h:145
__REG NR34_REG
Definition: hardware.h:123
__REG NR42_REG
Definition: hardware.h:128
__BYTES _RAM[]
Definition: hardware.h:25
__BYTE_REG rRAMB
Definition: hardware.h:37
__REG NR52_REG
Definition: hardware.h:157
__BYTES _SCRN0[]
Definition: hardware.h:22
__REG PCM34_REG
Definition: hardware.h:383
__REG STAT_REG
Definition: hardware.h:246
__REG NR11_REG
Definition: hardware.h:97
__REG NR10_REG
Definition: hardware.h:91
__BYTE_REG rROMB0
Definition: hardware.h:35
__REG DMA_REG
Definition: hardware.h:297
__REG OCPD_REG
Definition: hardware.h:374
__REG NR31_REG
Definition: hardware.h:117
__BYTES _VRAM[]
Definition: hardware.h:18
__REG LY_REG
Definition: hardware.h:293
__REG NR22_REG
Definition: hardware.h:108
__REG BGP_REG
Definition: hardware.h:299
__BYTES _VRAM8800[]
Definition: hardware.h:20
__REG DIV_REG
Definition: hardware.h:72
__BYTES _SCRN1[]
Definition: hardware.h:23