PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
video.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------
2 
3  Video registers and defines
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  2. Altered source versions must be plainly marked as such, and
21  must not be misrepresented as being the original software.
22  3. This notice may not be removed or altered from any source
23  distribution.
24 
25 ---------------------------------------------------------------------------------*/
26 
31 #ifndef SNES_VIDEO_INCLUDE
32 #define SNES_VIDEO_INCLUDE
33 
34 #include <snes/snestypes.h>
35 
37 typedef enum
38 {
41  VRAM_INCLOW = (0 << 7),
42  VRAM_INCHIGH = (1 << 7),
43  VRAM_ADRTR_0B = (0 << 2),
44  VRAM_ADRTR_8B = (1 << 2),
45  VRAM_ADRTR_9B = (2 << 2),
46  VRAM_ADRTR_10B = (3 << 2),
47  VRAM_ADRSTINC_1 = (0 << 0),
48  VRAM_ADRSTINC_32 = (1 << 0),
49  VRAM_ADRSTINC_128 = (2 << 0)
51 
52 #define FADE_IN 2
53 #define FADE_OUT 1
54 #define MOSAIC_IN 2
55 #define MOSAIC_OUT 1
56 #define MOSAIC_BG1 (1 << 0)
57 #define MOSAIC_BG2 (1 << 1)
58 #define MOSAIC_BG3 (1 << 2)
59 #define MOSAIC_BG4 (1 << 3)
60 
61 #define CM_DIRCOLOR (1 << 0)
62 #define CM_SUBBGOBJ_ENABLE (1 << 1)
63 #define CM_ALWAYS_ENABLE (0 << 4)
64 #define CM_MATWIN_ENABLE (1 << 4)
65 #define CM_NOMATWIN_ENABLE (2 << 4)
66 #define CM_NEVER_ENABLE (3 << 4)
67 #define CM_SCBLK_ALWAYS_ENABLE (0 << 6)
68 #define CM_SCBLK_MATWIN_ENABLE (1 << 6)
69 #define CM_SCBLK_NOMATWIN_ENABLE (2 << 6)
70 #define CM_SCBLK_NEVER_ENABLE (3 << 6)
71 
72 #define CM_SUB_MAINSUB (1 << 7)
73 #define CM_DIV2_DIVIDE (1 << 6)
74 #define CM_MSCR_BACK (1 << 5)
75 #define CM_MSCR_PAL47 (1 << 4)
76 #define CM_MSCR_BG4 (1 << 3)
77 #define CM_MSCR_BG3 (1 << 2)
78 #define CM_MSCR_BG2 (1 << 1)
79 #define CM_MSCR_BG1 (1 << 0)
80 
81 #define CM_APPLY_BLUE (1 << 7)
82 #define CM_APPLY_GREEN (1 << 6)
83 #define CM_APPLY_RED (1 << 5)
84 
85 #define M7_HFLIP (1 << 0)
86 #define M7_VFLIP (1 << 1)
87 #define M7_WRAP (1 << 6)
88 #define M7_OUTTRANS (2 << 6)
89 #define M7_OUTTILE (3 << 6)
91 #define PPU_50HZ (1 << 4)
110 #define REG_INIDISP (*(vuint8 *)0x2100)
111 
139 #define REG_VMAIN (*(vuint8 *)0x2115)
140 
155 #define REG_VMADDLH (*(vuint16 *)0x2116)
156 
157 /*
158  Writing to 2118h or 2119h does simply modify the LSB or MSB of the currently addressed VRAM
159  word (with optional Address Translation applied). Depending on the Increment Mode the address
160  does (or doesn't) get automatically incremented after the write.
161 */
162 #define REG_VMDATAL (*(vuint8 *)0x2118)
163 #define REG_VMDATAH (*(vuint8 *)0x2119)
164 #define REG_VMDATALH (*(vuint16 *)0x2118)
173 #define REG_CGADD (*(vuint8 *)0x2121)
174 
205 #define CGRAM_PALETTE ((u8 *)0x2122)
206 
215 #define REG_CGWSEL (*(vuint8 *)0x2130)
216 
229 #define REG_CGADSUB (*(vuint8 *)0x2131)
230 
240 #define REG_COLDATA (*(vuint8 *)0x2132)
241 
255 #define REG_M7SEL (*(vuint8 *)0x211A)
256 
257 /* 1st Write: Lower 8bit ;\1st/2nd write mechanism uses "M7_old"
258  2nd Write: Upper 8bit ;/
259 */
260 #define REG_M7A (*(vuint8 *)0x211B)
261 #define REG_M7B (*(vuint8 *)0x211C)
262 #define REG_M7C (*(vuint8 *)0x211D)
263 #define REG_M7D (*(vuint8 *)0x211E)
264 #define REG_M7HOFS (*(vuint8 *)0x210D)
265 #define REG_M7VOFS (*(vuint8 *)0x210E)
266 #define REG_M7X (*(vuint8 *)0x211F)
267 #define REG_M7Y (*(vuint8 *)0x2120)
269 /* After writing to 211Bh or 211Ch, the result can be read immediately from 2134h-2136h (the 21xxh Ports
270  are rapidly clocked by the PPU, there's no delay needed when reading via "MOV A,[211Ch]" or via
271  "MOV A,[1Ch]" (with D=2100h), both works even when the CPU runs at 3.5MHz).
272 */
273 #define REG_MPYL (*(vuint8 *)0x2134)
274 #define REG_MPYM (*(vuint8 *)0x2135)
275 #define REG_MPYH (*(vuint8 *)0x2136)
276 #define REG_MPYMH (*(vuint16 *)0x2135)
290 #define REG_STAT77 (*(vuint8 *)0x213E)
291 
300 #define REG_STAT78 (*(vuint8 *)0x213F)
301 
302 // macro creates a 15 bit color from 3x5 bit components
304 #define RGB8(r, g, b) (((r) >> 3) | (((g) >> 3) << 5) | (((b) >> 3) << 10))
305 #define RGB5(r, g, b) ((r) | ((g) << 5) | ((b) << 10))
306 
307 #define SCREEN_HEIGHT 224
308 #define SCREEN_WIDTH 256
310 extern u8 videoMode;
311 extern u8 videoModeSub;
313 extern u16 snes_frame_count;
319 void setBrightness(u8 level);
320 
336 void setMode(u8 mode, u8 size);
337 
341 void setScreenOn(void);
342 
346 void setScreenOff(void);
347 
352 void setFadeEffect(u8 mode);
353 
359 void setFadeEffectEx(u8 mode, u8 framesNumber);
360 
366 void setMosaicEffect(u8 mode, u8 bgNumbers);
367 
373 void setColorEffect(u8 colorMathA, u8 colorMathB);
374 
380 void setColorIntensity(u8 colorApply, u8 intensity);
381 
388 #define setPalette(palette, paletteEntry, paletteSize) dmaCopyCGram(palette, paletteEntry, paletteSize)
389 
395 #define setPaletteColor(paletteEntry, paletteColor) \
396  REG_CGADD = paletteEntry; \
397  *CGRAM_PALETTE = (paletteColor)&0xFF; \
398  *CGRAM_PALETTE = (paletteColor) >> 8;
399 
406 void getPalette(u8 paletteEntry, u8 paletteSize, u16 *paletteColors);
407 
413 void getPaletteColor(u8 paletteEntry, u16 *paletteColor);
414 
419 void setMode7(u8 mode);
420 
425 void setMode7Rot(u8 angle);
426 
432 
438 
443 void setMode7Angle(u8 angle);
444 
450 void setMode7Scale(u16 xscale, u16 yscale);
451 
456 unsigned short getFPScounter(void);
457 
458 #endif // SNES_VIDEO_INCLUDE
Custom types used by libsnes.
#define BIT(n)
bit field
Definition: snestypes.h:34
u8 videoMode
Current value of REG_TM.
void setMode7MoveForwardBack(u8 z8)
Change perspective view forward/backward in mode 7 without changing matrix.
void setBrightness(u8 level)
sets the screens brightness.
void setMode7Rot(u8 angle)
Change angle view in mode 7 with matrix transformation.
u8 videoModeSub
Current value of REG_TS.
void getPalette(u8 paletteEntry, u8 paletteSize, u16 *paletteColors)
Get a palette from CGRAM.
VideoControl
Bit defines for the video control registers.
Definition: video.h:38
@ VRAM_ADRTR_9B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition: video.h:45
@ VRAM_INCLOW
Increment VRAM Address after accessing High/Low byte (0=Low, 1=High)
Definition: video.h:41
@ VRAM_ADRTR_8B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition: video.h:44
@ VRAM_ADRSTINC_32
Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)
Definition: video.h:48
@ VRAM_ADRSTINC_128
Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)
Definition: video.h:49
@ VRAM_ADRTR_10B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition: video.h:46
@ VRAM_ADRTR_0B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition: video.h:43
@ DSP_FORCEVBL
Forced Blanking (0=Normal, 1=Screen Black)
Definition: video.h:39
@ VRAM_ADRSTINC_1
Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)
Definition: video.h:47
unsigned short getFPScounter(void)
Return number of frames per second.
void setMode7Scale(u16 xscale, u16 yscale)
Change scaling effect of screen in mode 7.
void setColorEffect(u8 colorMathA, u8 colorMathB)
Do addition or other color effects.
void setMosaicEffect(u8 mode, u8 bgNumbers)
Do a mosaic in or out effect.
void setScreenOff(void)
Put screen Off.
u16 snes_frame_count
Number of frame per second (need a call to videoGetFrames() once a frame)
void setScreenOn(void)
Put screen On.
void setFadeEffect(u8 mode)
Do a fadein or fadeout effect.
void setMode7Angle(u8 angle)
Change angle view in mode 7 without changing matrix.
void getPaletteColor(u8 paletteEntry, u16 *paletteColor)
Get a color palette from CGRAM.
void setFadeEffectEx(u8 mode, u8 framesNumber)
Do a fadein or fadeout effect.
void setMode7MoveLeftRight(u8 z8)
Change perspective view left/right in mode 7 without changing matrix.
void setColorIntensity(u8 colorApply, u8 intensity)
Change intensity for transparency.
void setMode7(u8 mode)
Put screen in mode 7 with generic init.
void setMode(u8 mode, u8 size)
Set the SNES hardware to operate in new display mode.