PVSnesLib  4.7.1
Documentation to code in C or ASM for the Nintendo SNES
Loading...
Searching...
No Matches
video.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------------------
2
3 Video registers and defines
4
5 Copyright (C) 2012-2026
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#include <snes/snestypes.h>
34
36typedef enum
37{
39 VRAM_INCLOW = (0 << 7),
40 VRAM_INCHIGH = (1 << 7),
41 VRAM_ADRTR_0B = (0 << 2),
42 VRAM_ADRTR_8B = (1 << 2),
43 VRAM_ADRTR_9B = (2 << 2),
44 VRAM_ADRTR_10B = (3 << 2),
45 VRAM_ADRSTINC_1 = (0 << 0),
46 VRAM_ADRSTINC_32 = (1 << 0),
47 VRAM_ADRSTINC_128 = (2 << 0)
49
50#define FADE_IN 2
51#define FADE_OUT 1
52#define MOSAIC_IN 2
53#define MOSAIC_OUT 1
54#define MOSAIC_BG1 (1 << 0)
55#define MOSAIC_BG2 (1 << 1)
56#define MOSAIC_BG3 (1 << 2)
57#define MOSAIC_BG4 (1 << 3)
58#define CM_DIRCOLOR (1 << 0)
59#define CM_SUBBGOBJ_ENABLE (1 << 1)
60#define CM_ALWAYS_ENABLE (0 << 4)
61#define CM_MATWIN_ENABLE (1 << 4)
62#define CM_NOMATWIN_ENABLE (2 << 4)
63#define CM_NEVER_ENABLE (3 << 4)
64#define CM_SCBLK_ALWAYS_ENABLE (0 << 6)
65#define CM_SCBLK_MATWIN_ENABLE (1 << 6)
66#define CM_SCBLK_NOMATWIN_ENABLE (2 << 6)
67#define CM_SCBLK_NEVER_ENABLE (3 << 6)
68#define CM_SUB_MAINSUB (1 << 7)
69#define CM_DIV2_DIVIDE (1 << 6)
70#define CM_MSCR_BACK (1 << 5)
71#define CM_MSCR_PAL47 (1 << 4)
72#define CM_MSCR_BG4 (1 << 3)
73#define CM_MSCR_BG3 (1 << 2)
74#define CM_MSCR_BG2 (1 << 1)
75#define CM_MSCR_BG1 (1 << 0)
76
77#define CM_APPLY_BLUE (1 << 7)
78#define CM_APPLY_GREEN (1 << 6)
79#define CM_APPLY_RED (1 << 5)
80#define M7_HFLIP (1 << 0)
81#define M7_VFLIP (1 << 1)
82#define M7_WRAP (1 << 6)
83#define M7_OUTTRANS (2 << 6)
84#define M7_OUTTILE (3 << 6)
85#define PPU_50HZ (1 << 4)
102#define REG_INIDISP (*(vuint8 *)0x2100)
103
128#define REG_VMAIN (*(vuint8 *)0x2115)
129
143#define REG_VMADDLH (*(vuint16 *)0x2116)
144
145/*
146 Writing to 2118h or 2119h does simply modify the LSB or MSB of the currently addressed VRAM
147 word (with optional Address Translation applied). Depending on the Increment Mode the address
148 does (or doesn't) get automatically incremented after the write.
149 */
150#define REG_VMDATAL (*(vuint8 *)0x2118)
151#define REG_VMDATAH (*(vuint8 *)0x2119)
152#define REG_VMDATALH (*(vuint16 *)0x2118)
161#define REG_CGADD (*(vuint8 *)0x2121)
162
190#define CGRAM_PALETTE ((u8 *)0x2122)
191
200#define REG_CGWSEL (*(vuint8 *)0x2130)
201
214#define REG_CGADSUB (*(vuint8 *)0x2131)
215
225#define REG_COLDATA (*(vuint8 *)0x2132)
226
239#define REG_M7SEL (*(vuint8 *)0x211A)
240
241/* 1st Write: Lower 8bit ;\1st/2nd write mechanism uses "M7_old"
242 2nd Write: Upper 8bit ;/
243 */
244#define REG_M7A (*(vuint8 *)0x211B)
245#define REG_M7B (*(vuint8 *)0x211C)
246#define REG_M7C (*(vuint8 *)0x211D)
247#define REG_M7D (*(vuint8 *)0x211E)
248#define REG_M7HOFS (*(vuint8 *)0x210D)
249#define REG_M7VOFS (*(vuint8 *)0x210E)
250#define REG_M7X (*(vuint8 *)0x211F)
251#define REG_M7Y (*(vuint8 *)0x2120)
253/* After writing to 211Bh or 211Ch, the result can be read immediately from 2134h-2136h (the 21xxh Ports
254 are rapidly clocked by the PPU, there's no delay needed when reading via "MOV A,[211Ch]" or via
255 "MOV A,[1Ch]" (with D=2100h), both works even when the CPU runs at 3.5MHz).
256 */
257#define REG_MPYL (*(vuint8 *)0x2134)
258#define REG_MPYM (*(vuint8 *)0x2135)
259#define REG_MPYH (*(vuint8 *)0x2136)
260#define REG_MPYMH (*(vuint16 *)0x2135)
273#define REG_STAT77 (*(vuint8 *)0x213E)
274
283#define REG_STAT78 (*(vuint8 *)0x213F)
284
285// macro creates a 15 bit color from 3x5 bit components
287#define RGB8(r, g, b) (((r) >> 3) | (((g) >> 3) << 5) | (((b) >> 3) << 10))
288#define RGB5(r, g, b) ((r) | ((g) << 5) | ((b) << 10))
289#define SCREEN_HEIGHT 224
290#define SCREEN_WIDTH 256
292extern u8 videoMode;
293extern u8 videoModeSub;
295extern u16 snes_frame_count;
297extern u8 mirrorINIDISP;
303void setBrightness(u8 level);
304
320void setMode(u8 mode, u8 size);
321
328void setScreenOn(void);
329
333void setScreenOff(void);
334
343void setFadeEffect(u8 mode);
344
352void setFadeEffectEx(u8 mode, u8 framesNumber);
353
360
371
378
385
396void setFadeEffectSpeed(u8 speed);
397
405
414
420void setMosaicEffect(u8 mode, u8 bgNumbers);
421
427void setMosaicInit(void);
428
439
446
452void setMosaicEffectSpeed(u8 speed);
453
460void setMosaicTo(u8 size, u8 bgMask);
461
462
468void setColorEffect(u8 colorMathA, u8 colorMathB);
469
475void setColorIntensity(u8 colorApply, u8 intensity);
476
483#define setPalette(palette, paletteEntry, paletteSize) dmaCopyCGram(palette, paletteEntry, paletteSize)
484
490#define setPaletteColor(paletteEntry, paletteColor) \
491 REG_CGADD = paletteEntry; \
492 *CGRAM_PALETTE = (paletteColor)&0xFF; \
493 *CGRAM_PALETTE = (paletteColor) >> 8;
494
501void getPalette(u8 paletteEntry, u8 paletteSize, u16 *paletteColors);
502
508void getPaletteColor(u8 paletteEntry, u16 *paletteColor);
509
514void setMode7(u8 mode);
515
520void setMode7Rot(u8 angle);
521
527
533
538void setMode7Angle(u8 angle);
539
545void setMode7Scale(u16 xscale, u16 yscale);
546
551unsigned short getFPScounter(void);
552
556void showFPScounter(void);
557
558#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 in RAM.
void updateMosaicEffect(void)
Update the software mosaic effect.
void setFadeEffectSpeed(u8 speed)
Set the update speed of the software fade effect.
void setMode7MoveForwardBack(u8 z8)
Change perspective view forward/backward in mode 7 without changing matrix.
void setBrightness(u8 level)
Sets the screen brightness.
void setMode7Rot(u8 angle)
Change angle view in mode 7 with matrix transformation.
u8 videoModeSub
Current value of REG_TS in RAM.
void getPalette(u8 paletteEntry, u8 paletteSize, u16 *paletteColors)
Get a palette from CGRAM.
void setMosaicEffectSpeed(u8 speed)
Set the update speed of the software mosaic effect.
void setFadeEffectInit(void)
Initialize the software fade effect state.
VideoControl
Bit defines for the video control registers.
Definition video.h:37
@ VRAM_ADRTR_9B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition video.h:43
@ VRAM_INCLOW
Increment VRAM Address after accessing High/Low byte (0=Low, 1=High)
Definition video.h:39
@ VRAM_ADRTR_8B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition video.h:42
@ VRAM_ADRSTINC_32
Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)
Definition video.h:46
@ VRAM_ADRSTINC_128
Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)
Definition video.h:47
@ VRAM_ADRTR_10B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition video.h:44
@ VRAM_ADRTR_0B
Address Translation (0..3 = 0bit/None, 8bit, 9bit, 10bit)
Definition video.h:41
@ DSP_FORCEVBL
Forced Blanking (0=Normal, 1=Screen Black)
Definition video.h:38
@ VRAM_ADRSTINC_1
Address Increment Step (0..3 = Increment Word-Address by 1,32,128,128)
Definition video.h:45
u8 isMosaicActive(void)
Check whether the software mosaic effect is active.
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 setFadeEffectIn(void)
Start a non-blocking fade-in effect.
void setMosaicEffect(u8 mode, u8 bgNumbers)
Do a mosaic in or out effect.
u8 getFadeEffectLevel(void)
Return the current software fade level.
void showFPScounter(void)
Show on current text BG, at location 1,1 the number of frames per second.
void setScreenOff(void)
Put screen off.
void setMosaicTo(u8 size, u8 bgMask)
Set the mosaic size and mask.
u16 snes_frame_count
Number of frame per second (need a call to videoGetFrames() once a frame)
void setFadeEffectOut(void)
Start a non-blocking fade-out effect.
void setScreenOn(void)
Put screen on.
void setFadeEffect(u8 mode)
Perform a blocking fade-in or fade-out effect.
void setMode7Angle(u8 angle)
Change angle view in mode 7 without changing matrix.
void setMosaicInit(void)
Initialize the software mosaic effect state.
void getPaletteColor(u8 paletteEntry, u16 *paletteColor)
Get a color palette from CGRAM.
void setFadeEffectEx(u8 mode, u8 framesNumber)
Perform a blocking fade-in or fade-out effect with a configurable step delay.
void updateFadeEffect(void)
Update the software fade effect.
void setMode7MoveLeftRight(u8 z8)
Change perspective view left/right in mode 7 without changing matrix.
u8 mirrorINIDISP
Current value of REG_INIDISP in RAM to know if screen is on or not.
u8 isFadeEffectActive(void)
Check whether the software fade effect is active.
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.