PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
background.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------
2 
3  background.h -- definitions for SNES backgrounds
4 
5  Copyright (C) 2012-2017
6  Alekmaul
7 
8  This software is provided 'as-is', without any express or implied
9  warranty. In no event will the authors be held liable for any
10  damages arising from the use of this software.
11 
12  Permission is granted to anyone to use this software for any
13  purpose, including commercial applications, and to alter it and
14  redistribute it freely, subject to the following restrictions:
15 
16  1. The origin of this software must not be misrepresented; you
17  must not claim that you wrote the original software. If you use
18  this software in a product, an acknowledgment in the product
19  documentation would be appreciated but is not required.
20 
21  2. Altered source versions must be plainly marked as such, and
22  must not be misrepresented as being the original software.
23 
24  3. This notice may not be removed or altered from any source
25  distribution.
26 
27 ---------------------------------------------------------------------------------*/
33 #ifndef SNES_BACKGROUND_INCLUDE
34 #define SNES_BACKGROUND_INCLUDE
35 
36 #include <snes/snestypes.h>
37 
38 #include <snes/dma.h>
39 #include <snes/interrupt.h>
40 #include <snes/video.h>
41 
43 #define SC_BASE_SHIFT 2
44 
46 #define SC_TILE_BASE(base) ((base) << SC_BASE_SHIFT)
47 
48 /* Bit defines for the background control registers */
49 #define SC_32x32 (0 << 0)
50 #define SC_64x32 (1 << 0)
51 #define SC_32x64 (2 << 0)
52 #define SC_64x64 (3 << 0)
54 #define BG_MODE0 (0 << 0)
55 #define BG_MODE1 (1 << 0)
56 #define BG_MODE2 (2 << 0)
57 #define BG_MODE3 (3 << 0)
58 #define BG_MODE4 (4 << 0)
59 #define BG_MODE5 (5 << 0)
60 #define BG_MODE6 (6 << 0)
61 #define BG_MODE7 (7 << 0)
63 #define BG1_TSIZE8x8 (0 << 4)
64 #define BG2_TSIZE8x8 (0 << 5)
65 #define BG3_TSIZE8x8 (0 << 6)
66 #define BG4_TSIZE8x8 (0 << 7)
67 
68 #define BG1_TSIZE16x16 (1 << 4)
69 #define BG2_TSIZE16x16 (1 << 5)
70 #define BG3_TSIZE16x16 (1 << 6)
71 #define BG4_TSIZE16x16 (1 << 7)
72 
73 #define BG1_ENABLE (1 << 0)
74 #define BG2_ENABLE (1 << 1)
75 #define BG3_ENABLE (1 << 2)
76 #define BG4_ENABLE (1 << 3)
77 #define OBJ_ENABLE (1 << 4)
78 
79 #define BG_4COLORS0 32
80 #define BG_4COLORS 4
81 #define BG_16COLORS 16
82 #define BG_256COLORS 256
83 #define BG3_MODE1_PRIORITY_HIGH (1 << 3)
84 
110 #define REG_BGMODE (*(vuint8 *)0x2105)
111 
131 #define REG_MOSAIC (*(vuint8 *)0x2106)
132 
150 #define BG1SC_ADDR 0x2107
151 #define REG_BG1SC (*(vuint8 *)0x2107)
152 #define REG_BG2SC (*(vuint8 *)0x2108)
153 #define REG_BG3SC (*(vuint8 *)0x2109)
154 #define REG_BG4SC (*(vuint8 *)0x210A)
155 
165 #define REG_BG12NBA (*(vuint8 *)0x210B)
166 #define REG_BG34NBA (*(vuint8 *)0x210C)
167 
169 #define REG_BGxHOFS 0x210D
171 #define REG_BGxVOFS 0x210E
172 
174 #define REG_BG1HOFS (*(vuint8 *)0x210D)
176 #define REG_BG1VOFS (*(vuint8 *)0x210E)
178 #define REG_BG2HOFS (*(vuint8 *)0x210F)
180 #define REG_BG2VOFS (*(vuint8 *)0x2110)
182 #define REG_BG3HOFS (*(vuint8 *)0x2111)
184 #define REG_BG3VOFS (*(vuint8 *)0x2112)
186 #define REG_BG4HOFS (*(vuint8 *)0x2113)
188 #define REG_BG4VOFS (*(vuint8 *)0x2114)
189 
190 #define COLWIN_OB13W1ENABLEIN (1 << 0)
191 #define COLWIN_OB13W1ENABLEOUT (2 << 0)
192 #define COLWIN_OB13W2ENABLEIN (1 << 2)
193 #define COLWIN_OB13W2ENABLEOUT (2 << 2)
194 #define COLWIN_MB24W1ENABLEIN (1 << 4)
195 #define COLWIN_MB24W1ENABLEOUT (2 << 4)
196 #define COLWIN_MB24W2ENABLEIN (1 << 6)
197 #define COLWIN_MB24W2ENABLEOUT (2 << 6)
210 #define REG_W12SEL (*(vuint8 *)0x2123)
211 #define REG_W34SEL (*(vuint8 *)0x2124)
212 #define REG_WOBJSEL (*(vuint8 *)0x2125)
213 
229 #define REG_WH0 (*(vuint8 *)0x2126)
230 #define REG_WH1 (*(vuint8 *)0x2127)
231 #define REG_WH2 (*(vuint8 *)0x2128)
232 #define REG_WH3 (*(vuint8 *)0x2129)
233 
249 #define REG_WBGLOG (*(vuint8 *)0x212A)
250 #define REG_WOBJLOG (*(vuint8 *)0x212B)
251 
268 #define REG_TM (*(vuint8 *)0x212C)
269 #define REG_TS (*(vuint8 *)0x212D)
270 
284 #define REG_TMW (*(vuint8 *)0x212E)
285 #define REG_TSW (*(vuint8 *)0x212F)
286 
287 // background address
288 extern u16 bg0gfxaddr;
289 extern u16 bg1gfxaddr;
290 extern u16 bg2gfxaddr;
291 extern u16 bg3gfxaddr;
297 void bgSetGfxPtr(u8 bgNumber, u16 address);
298 
304 void bgSetMapPtr(u8 bgNumber, u16 address, u8 mapSize);
305 
316 void bgInitTileSet(u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 tileSize, u16 paletteSize, u16 colorMode, u16 address);
317 
327 void bgInitTileSetLz(u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 paletteSize, u16 colorMode, u16 address);
328 
335 void bgInitTileSetData(u8 bgNumber, u8 *tileSource, u16 tileSize, u16 address);
336 
344 void bgInitMapTileSet7(u8 *tileSource, u8 *mapSource, u8 *tilePalette, u16 tileSize, u16 address);
345 
353 void bgInitMapSet(u8 bgNumber, u8 *mapSource, u16 mapSize, u8 sizeMode, u16 address);
354 
360 void bgSetScroll(u8 bgNumber, u16 x, u16 y);
361 
365 void bgSetEnable(u8 bgNumber);
366 
370 void bgSetDisable(u8 bgNumber);
371 
375 void bgSetEnableSub(u8 bgNumber);
376 
380 void bgSetDisableSub(u8 bgNumber);
381 
388 void bgSetWindowsRegions(u8 bgNumber, u8 winNumber, u8 xLeft, u8 xRight);
389 
390 #endif // SNES_BACKGROUND_INCLUDE
void bgSetWindowsRegions(u8 bgNumber, u8 winNumber, u8 xLeft, u8 xRight)
Define a region on screen where map / sprite can be disable.
void bgSetGfxPtr(u8 bgNumber, u16 address)
Definition of each background address.
u16 bg3gfxaddr
Definition of each background address.
void bgSetEnableSub(u8 bgNumber)
Enable a BG from sub screen (translucent) in the actual SNES mode.
void bgInitTileSetLz(u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 paletteSize, u16 colorMode, u16 address)
Initializes a Tile Set and Loads the Tile GFX compressed with LZ algo into VRAM.
void bgSetDisable(u8 bgNumber)
Disable a BG in the actual SNES mode.
void bgInitTileSetData(u8 bgNumber, u8 *tileSource, u16 tileSize, u16 address)
Add some Tile Set and Loads the Tile GFX into VRAM.
void bgSetMapPtr(u8 bgNumber, u16 address, u8 mapSize)
Change Background Map address.
u16 bg2gfxaddr
Definition of each background address.
void bgSetEnable(u8 bgNumber)
Enable a BG in the actual SNES mode.
void bgSetScroll(u8 bgNumber, u16 x, u16 y)
Sets the scroll hardware to the specified location.
void bgInitMapSet(u8 bgNumber, u8 *mapSource, u16 mapSize, u8 sizeMode, u16 address)
Initializes a Map Set and loads it into SNES VRAM.
u16 bg1gfxaddr
Definition of each background address.
void bgInitTileSet(u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 tileSize, u16 paletteSize, u16 colorMode, u16 address)
Initializes a Tile Set and Loads the Tile GFX into VRAM.
void bgInitMapTileSet7(u8 *tileSource, u8 *mapSource, u8 *tilePalette, u16 tileSize, u16 address)
Initializes a Tile & Map Set and Loads the Tile & Map GFX into VRAM for Mode 7.
void bgSetDisableSub(u8 bgNumber)
Disable a BG from sub screen (translucent) in the actual SNES mode.
Wrapper functions for direct memory access hardware.
snes interrupt support.
Custom types used by libsnes.
contains the basic definitions for controlling the video hardware.