PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
dma.h File Reference

Wrapper functions for direct memory access hardware. More...

#include <snes/snestypes.h>
#include <snes/background.h>
#include <snes/sprite.h>
#include <snes/video.h>

Go to the source code of this file.

Macros

#define DMA_ENABLE   1
 Bit defines for the DMA control registers.
 
#define HDMA_CHANNEL0   (1 << 0)
 Bit defines for the HDMA channels.
 
#define MSWIN1_BG1MSKENABLE   (2 << 0)
 Window 1 area BG1 enable.
 
#define MSWIN1_BG1MSKOUT   (1 << 0)
 Window 1 area BG1 inside (0) outside(1)
 
#define MSWIN1_BG2MSKENABLE   (2 << 4)
 Window 1 area BG2 enable.
 
#define MSWIN1_BG2MSKOUT   (1 << 4)
 Window 1 area BG2 inside (0) outside(1)
 
#define MSWIN1_BG3MSKENABLE   (2 << 0)
 Window 1 area BG3 enable.
 
#define MSWIN1_BG3MSKOUT   (1 << 0)
 Window 1 area BG3 inside (0) outside(1)
 
#define MSWIN1_BG4MSKENABLE   (2 << 4)
 Window 1 area BG4 enable.
 
#define MSWIN1_BG4MSKOUT   (1 << 4)
 Window 1 area BG4 inside (0) outside(1)
 
#define MSWIN2_BG1MSKENABLE   (2 << 2)
 Window 2 area BG1 enable.
 
#define MSWIN2_BG1MSKOUT   (1 << 2)
 Window 2 area BG1 inside (0) outside(1)
 
#define MSWIN2_BG2MSKENABLE   (2 << 4)
 Window 2 area BG2 enable.
 
#define MSWIN2_BG2MSKOUT   (1 << 4)
 Window 2 area BG2 inside (0) outside(1)
 
#define MSWIN2_BG3MSKENABLE   (2 << 2)
 Window 2 area BG3 enable.
 
#define MSWIN2_BG3MSKOUT   (1 << 2)
 Window 2 area BG3 inside (0) outside(1)
 
#define MSWIN2_BG4MSKENABLE   (2 << 4)
 Window 2 area BG4 enable.
 
#define MSWIN2_BG4MSKOUT   (1 << 4)
 Window 2 area BG4 inside (0) outside(1)
 
#define MSWIN_BG1   (1 << 0)
 Bit defines for the window area main screen effect. More...
 
#define MSWIN_BG2   (1 << 1)
 Main Screen BG2 disable background.
 
#define MSWIN_BG3   (1 << 2)
 Main Screen BG3 disable background.
 
#define MSWIN_BG4   (1 << 3)
 Main Screen BG4 disable background.
 
#define REG_A1B7   (*(vuint8 *)0x4374)
 A1TxL - HDMA Table Start Address (low) / DMA Current Addr (low) (R/W) A1TxH - HDMA Table Start Address (hi) / DMA Current Addr (hi) (R/W) A1Bx - HDMA Table Start Address (bank) / DMA Current Addr (bank) (R/W) More...
 
#define REG_BBAD7   (*(vuint8 *)0x4371)
 DMA/HDMA I/O-Bus Address (PPU-Bus aka B-Bus) (R/W) For both DMA and HDMA: 7-0 B-Bus Address (selects an I/O Port which is mapped to 2100h-21FFh)
 
#define REG_DAS7LH   (*(vuint16 *)0x4375)
 Indirect HDMA Address (low) / DMA Byte-Counter (low) (R/W) DASxL - Indirect HDMA Address (low) / DMA Byte-Counter (low) (R/W) DASxH - Indirect HDMA Address (hi) / DMA Byte-Counter (hi) (R/W) 43x7h - DASBx - Indirect HDMA Address (bank) (R/W) More...
 
#define REG_HDMAEN   (*(vuint8 *)0x420C)
 Select H-Blank DMA (H-DMA) Channel(s) (W) 7-0 H-DMA Channel 7-0 Enable (0=Disable, 1=Enable)
 
#define REG_MDMAEN   (*(vuint8 *)0x420B)
 Select General Purpose DMA Channel(s) and Start Transfer (W) 7-0 General Purpose DMA Channel 7-0 Enable (0=Disable, 1=Enable) More...
 

Functions

void dmaClearVram (void)
 clear all vram data with #0
 
void dmaCopyCGram (u8 *source, u16 address, u16 size)
 copy data from source to destination using channel 0 of DMA available channels in half words More...
 
void dmaCopyOAram (u8 *source, u16 address, u16 size)
 copies Sprites from source to destination using channel 0 of DMA available channels in half words More...
 
void dmaCopySpr16Vram (u8 *source, u16 address)
 copy sprite 16pix size data from source to destination using channel 0 of DMA available channels in half words More...
 
void dmaCopySpr32Vram (u8 *source, u16 address)
 copy sprite 32pix size data from source to destination using channel 0 of DMA available channels in half words More...
 
void dmaCopyVram (u8 *source, u16 address, u16 size)
 copy data from source to destination using channel 0 of DMA available channels in half words More...
 
void dmaCopyVram7 (u8 *source, u16 address, u16 size, u8 vrammodeinc, u16 dmacontrol)
 copies data from source to destination using channel 0 of DMA available channels in half words with VMAIN value More...
 
void dmaFillVram (u8 *source, u16 address, u16 size)
 fill the source data to destination using channel 0 of DMA available channels in half words More...
 
void setModeHdmaColor (u8 *hdmatable)
 Do a color gradient effect on screen (with color 0). Use HDMA Channels 6. More...
 
void setModeHdmaGradient (u8 maxLevels)
 Do a brightness gradient on screen. Use HDMA Channels 3. More...
 
void setModeHdmaReset (u8 channels)
 Reset or Set HDMA channels. More...
 
void setModeHdmaShadeUpDown (void)
 Do a brightness gradient from up/down to center of the screen. Use HDMA Channels 3.
 
void setModeHdmaShading (unsigned char mode)
 Do a shading effect on screen. Use HDMA Channels 0 to 2. More...
 
void setModeHdmaWaves (u8 bgrnd)
 Do a waves effect on screen (init function). Use HDMA Channels 6. More...
 
void setModeHdmaWavesMove (void)
 Animate the waves effect. Must be called during each frame.
setModeHdmaWaves must have been done to init it.
 
void setModeHdmaWindowReset (u8 channels)
 Reset or Set HDMA channels and remove WINDOW effect. More...
 
void setParallaxScrolling (u8 bgrnd)
 Do a parallax scrolling effect on screen. Use HDMA Channels 3. More...
 

Variables

u8 HDMATable16 [224+1]
 HDMA table accessible to change values.
 

Detailed Description

Wrapper functions for direct memory access hardware.

Macro Definition Documentation

◆ MSWIN_BG1

#define MSWIN_BG1   (1 << 0)

Bit defines for the window area main screen effect.

Main Screen BG1 disable background

Examples
graphics/Effects/Window/Window.c.

◆ REG_A1B7

#define REG_A1B7   (*(vuint8 *)0x4374)

A1TxL - HDMA Table Start Address (low) / DMA Current Addr (low) (R/W) A1TxH - HDMA Table Start Address (hi) / DMA Current Addr (hi) (R/W) A1Bx - HDMA Table Start Address (bank) / DMA Current Addr (bank) (R/W)

For normal DMA: 23-16 CPU-Bus Data Address Bank (constant, not incremented/decremented) 15-0 CPU-Bus Data Address (incremented/decremented/fixed, as selected)

For HDMA: 23-16 CPU-Bus Table Address Bank (constant, bank number for 43x8h/43x9h) 15-0 CPU-Bus Table Address (constant, reload value for 43x8h/43x9h)

◆ REG_DAS7LH

#define REG_DAS7LH   (*(vuint16 *)0x4375)

Indirect HDMA Address (low) / DMA Byte-Counter (low) (R/W) DASxL - Indirect HDMA Address (low) / DMA Byte-Counter (low) (R/W) DASxH - Indirect HDMA Address (hi) / DMA Byte-Counter (hi) (R/W) 43x7h - DASBx - Indirect HDMA Address (bank) (R/W)

For normal DMA: 23-16 Not used 15-0 Number of bytes to be transferred (1..FFFFh=1..FFFFh, or 0=10000h) (This is really a byte-counter; with a 4-byte "Transfer Unit", len=5 would transfer one whole Unit, plus the first byte of the second Unit.) (The 16bit value is decremented during transfer, and contains 0000h on end.)

◆ REG_MDMAEN

#define REG_MDMAEN   (*(vuint8 *)0x420B)

Select General Purpose DMA Channel(s) and Start Transfer (W) 7-0 General Purpose DMA Channel 7-0 Enable (0=Disable, 1=Enable)

When writing a non-zero value to this register, general purpose DMA will be started immediately (after a few clk cycles). The CPU is paused during the transfer. The transfer can be interrupted by H-DMA transfers. If more than 1 bit is set in MDMAEN, then the separate transfers will be executed in WHICH? priority order. The MDMAEN bits are cleared automatically at transfer completion. Do not use channels for GP-DMA which are activated as H-DMA in HDMAEN.

Function Documentation

◆ dmaCopyCGram()

dmaCopyCGram ( u8 *  source,
u16  address,
u16  size 
)

copy data from source to destination using channel 0 of DMA available channels in half words

Parameters
sourcethe source to copy from
addresscgram address to copy
sizethe size in bytes of the data to copy.
Examples
games/breakout/breakout.c, and graphics/Sprites/ObjectSize/ObjectSize.c.

◆ dmaCopyOAram()

dmaCopyOAram ( u8 *  source,
u16  address,
u16  size 
)

copies Sprites from source to destination using channel 0 of DMA available channels in half words

Parameters
sourcethe source to copy from
addressvram address to copy
sizethe size in bytes of the data to copy.
Examples
graphics/Backgrounds/Mode1ContinuosScroll/Mode1ContinuosScroll.c, and graphics/Sprites/DynamicSprite/DynamicSprite.c.

◆ dmaCopySpr16Vram()

dmaCopySpr16Vram ( u8 *  source,
u16  address 
)

copy sprite 16pix size data from source to destination using channel 0 of DMA available channels in half words

Parameters
sourcethe source to copy from
addressvram address to copy

◆ dmaCopySpr32Vram()

dmaCopySpr32Vram ( u8 *  source,
u16  address 
)

copy sprite 32pix size data from source to destination using channel 0 of DMA available channels in half words

Parameters
sourcethe source to copy from
addressvram address to copy

◆ dmaCopyVram()

dmaCopyVram ( u8 *  source,
u16  address,
u16  size 
)

copy data from source to destination using channel 0 of DMA available channels in half words

Parameters
sourcethe source to copy from
addressvram address to copy
sizethe size in bytes of the data to copy.
Examples
games/breakout/breakout.c, graphics/Backgrounds/Mode1BG3HighPriority/Mode1BG3HighPriority.c, graphics/Backgrounds/Mode1ContinuosScroll/Mode1ContinuosScroll.c, graphics/Backgrounds/Mode3/Mode3.c, graphics/Effects/HDMAGradient/HDMAGradient.c, graphics/Sprites/DynamicSprite/DynamicSprite.c, graphics/Sprites/ObjectSize/ObjectSize.c, and input/mouse/mouse.c.

◆ dmaCopyVram7()

dmaCopyVram7 ( u8 *  source,
u16  address,
u16  size,
u8  vrammodeinc,
u16  dmacontrol 
)

copies data from source to destination using channel 0 of DMA available channels in half words with VMAIN value

Parameters
sourcethe source to copy from
addressvram address to copy
sizethe size in bytes of the data to copy.
vrammodeincthe value of REG_VMAIN (incr or not incr).
dmacontrolthe value of DMA control register (incr or not incr, $18 or $19, and so on).

◆ dmaFillVram()

dmaFillVram ( u8 *  source,
u16  address,
u16  size 
)

fill the source data to destination using channel 0 of DMA available channels in half words

Parameters
sourcethe value of source to copy from
addressvram address to copy
sizethe size in bytes of the data to copy.
Examples
input/mouse/mouse.c, and input/superscope/superscope.c.

◆ setModeHdmaColor()

setModeHdmaColor ( u8 *  hdmatable)

Do a color gradient effect on screen (with color 0). Use HDMA Channels 6.

Parameters
hdmatabletable with gradient colors
Examples
graphics/Effects/GradientColors/GradientColors.c.

◆ setModeHdmaGradient()

setModeHdmaGradient ( u8  maxLevels)

Do a brightness gradient on screen. Use HDMA Channels 3.

Parameters
maxLevelsvalue between 1..15 for the maximum level of brightness (15=light, 1=near dark)
Examples
graphics/Effects/HDMAGradient/HDMAGradient.c.

◆ setModeHdmaReset()

setModeHdmaReset ( u8  channels)

Reset or Set HDMA channels.

Parameters
channelschannels from HDMA_CHANNEL0 to HDMA_CHANNEL7. HDMA_CHANNELALL for all channels
Examples
graphics/Effects/GradientColors/GradientColors.c, and graphics/Effects/Waves/Waves.c.

◆ setModeHdmaShading()

setModeHdmaShading ( unsigned char  mode)

Do a shading effect on screen. Use HDMA Channels 0 to 2.

Parameters
modevalue 0 disactivate 1, other value activate it

◆ setModeHdmaWaves()

setModeHdmaWaves ( u8  bgrnd)

Do a waves effect on screen (init function). Use HDMA Channels 6.

Parameters
bgrndbackground for the wave effect (value 0..1)
Examples
graphics/Effects/Waves/Waves.c.

◆ setModeHdmaWindowReset()

void setModeHdmaWindowReset ( u8  channels)

Reset or Set HDMA channels and remove WINDOW effect.

Parameters
channelschannels from HDMA_CHANNEL0 to HDMA_CHANNEL7. HDMA_CHANNELALL for all channels

◆ setParallaxScrolling()

setParallaxScrolling ( u8  bgrnd)

Do a parallax scrolling effect on screen. Use HDMA Channels 3.

use HDMATable16 variable to store scrolling value

each entry is number of lines (8bits) and scrolling value 16 bits (low & high)

WARNING : no more than 112 values and last value MUST be $0000

Parameters
bgrndbackground for the parallax scrolling (value 0..2)
Examples
graphics/Effects/ParallaxScrolling/ParallaxScrolling.c.