gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/include/nes/hardware.h
1 /** @file nes/hardware.h
2 Defines that let the NES hardware registers be accessed
3 from C.
4 */
5 #ifndef _HARDWARE_H
6 #define _HARDWARE_H
7
8 #include <types.h>
9 #include <stdint.h>
10
11 #define __SHADOW_REG extern volatile uint8_t
12 #define __REG(addr) volatile __at (addr) uint8_t
13
14 __REG(0x2000) PPUCTRL;
15 #define PPUCTRL_NMI 0b10000000
16 #define PPUCTRL_SPR_8X8 0b00000000
17 #define PPUCTRL_SPR_8X16 0b00100000
18 #define PPUCTRL_BG_CHR 0b00010000
19 #define PPUCTRL_SPR_CHR 0b00001000
20 #define PPUCTRL_INC32 0b00000100
21 __SHADOW_REG shadow_PPUCTRL;
22
23 __REG(0x2001) PPUMASK;
24 #define PPUMASK_BLUE 0b10000000
25 #define PPUMASK_RED 0b01000000
26 #define PPUMASK_GREEN 0b00100000
27 #define PPUMASK_SHOW_SPR 0b00010000
28 #define PPUMASK_SHOW_BG 0b00001000
29 #define PPUMASK_SHOW_SPR_LC 0b00000100
30 #define PPUMASK_SHOW_BG_LC 0b00000010
31 #define PPUMASK_MONOCHROME 0b00000001
32 __SHADOW_REG shadow_PPUMASK;
33
34 __REG(0x2002) PPUSTATUS;
35 __REG(0x2003) OAMADDR;
36 __REG(0x2004) OAMDATA;
37 __REG(0x2005) PPUSCROLL;
38 __REG(0x2006) PPUADDR;
39 __REG(0x2007) PPUDATA;
40 __REG(0x4014) OAMDMA;
41
42 #define DEVICE_SCREEN_X_OFFSET 0
43 #define DEVICE_SCREEN_Y_OFFSET 0
44 #define DEVICE_SCREEN_WIDTH 32
45 #define DEVICE_SCREEN_HEIGHT 30
46
47 #if defined(NES_TILEMAP_F)
48 // Full tilemap
49 #define DEVICE_SCREEN_BUFFER_WIDTH 64
50 #define DEVICE_SCREEN_BUFFER_HEIGHT 60
51 typedef uint16_t scroll_x_t;
52 typedef uint16_t scroll_y_t;
53 #elif defined(NES_TILEMAP_H)
54 // Horizontally arranged tilemap
55 #define DEVICE_SCREEN_BUFFER_WIDTH 64
56 #define DEVICE_SCREEN_BUFFER_HEIGHT 30
57 typedef uint16_t scroll_x_t;
58 typedef uint8_t scroll_y_t;
59 #elif defined(NES_TILEMAP_V)
60 // Vertically arranged tilemap
61 #define DEVICE_SCREEN_BUFFER_WIDTH 32
62 #define DEVICE_SCREEN_BUFFER_HEIGHT 60
63 typedef uint8_t scroll_x_t;
64 typedef uint16_t scroll_y_t;
65 #else
66 // Single-screen tilemap
67 #define DEVICE_SCREEN_BUFFER_WIDTH 32
68 #define DEVICE_SCREEN_BUFFER_HEIGHT 30
69 typedef uint8_t scroll_x_t;
70 typedef uint8_t scroll_y_t;
71 #endif
72
73 #define DEVICE_SCREEN_MAP_ENTRY_SIZE 1
74 #define DEVICE_SPRITE_PX_OFFSET_X 0
75 #define DEVICE_SPRITE_PX_OFFSET_Y -1
76 #define DEVICE_WINDOW_PX_OFFSET_X 0
77 #define DEVICE_WINDOW_PX_OFFSET_Y 0
78 #define DEVICE_SCREEN_PX_WIDTH (DEVICE_SCREEN_WIDTH * 8)
79 #define DEVICE_SCREEN_PX_HEIGHT (DEVICE_SCREEN_HEIGHT * 8)
80
81 // Scrolling coordinates (will be written to PPUSCROLL at end-of-vblank by NMI handler)
82 __SHADOW_REG bkg_scroll_x;
83 __SHADOW_REG bkg_scroll_y;
84 // LCD scanline - a software-driven version of GB's incrasing 'LY' scanline counter
85 __SHADOW_REG _lcd_scanline;
86
87 extern volatile UBYTE TIMA_REG;
88 extern volatile UBYTE TMA_REG;
89 extern volatile UBYTE TAC_REG;
90
91 // Compatibility defines for GB LY / LYC registers, to allow easier LCD ISR porting
92 #define SCY_REG bkg_scroll_y /**< Scroll Y */
93 #define rSCY SCY_REG
94 #define SCX_REG bkg_scroll_x /**< Scroll X */
95 #define rSCX SCX_REG
96 #define LY_REG _lcd_scanline /**< LCDC Y-coordinate */
97 #define rLY LY_REG
98 #define LYC_REG _lcd_scanline /**< LY compare */
99 #define rLYC LYC_REG
100
101 #if defined(NES_WINDOW_LAYER)
102 __SHADOW_REG win_pos_x;
103 __SHADOW_REG win_pos_y;
104 #define WX_REG win_pos_x
105 #define WY_REG win_pos_y
106 #endif
107
108 #endif
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.