libdragon
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Enumerations | Functions
(Deprecated) Old RDP library

Interface to the hardware sprite/triangle rasterizer (RDP). More...

Files

file  rdp.c
 (Deprecated) Old RDP library
 
file  rdp.h
 RDP: Hardware Display Interface.
 

Data Structures

struct  sprite_cache
 Cached sprite structure. More...
 

Macros

#define DP_START   ((volatile uint32_t*)0xA4100000)
 DP start register.
 
#define DP_END   ((volatile uint32_t*)0xA4100004)
 DP end register.
 
#define DP_CURRENT   ((volatile uint32_t*)0xA4100008)
 DP current register.
 
#define DP_STATUS   ((volatile uint32_t*)0xA410000C)
 DP status register.
 
#define DP_CLOCK   ((volatile uint32_t*)0xA4100010)
 DP clock counter.
 
#define DP_BUSY   ((volatile uint32_t*)0xA4100014)
 DP command buffer busy.
 
#define DP_PIPE_BUSY   ((volatile uint32_t*)0xA4100018)
 DP pipe busy.
 
#define DP_TMEM_BUSY   ((volatile uint32_t*)0xA410001C)
 DP tmem busy.
 
#define DP_STATUS_DMEM_DMA   (1 << 0)
 DP is using DMEM DMA.
 
#define DP_STATUS_FREEZE   (1 << 1)
 DP is frozen.
 
#define DP_STATUS_FLUSH   (1 << 2)
 DP is flushed.
 
#define DP_STATUS_GCLK_ALIVE   (1 << 3)
 DP GCLK is alive.
 
#define DP_STATUS_TMEM_BUSY   (1 << 4)
 DP TMEM is busy.
 
#define DP_STATUS_PIPE_BUSY   (1 << 5)
 DP pipeline is busy.
 
#define DP_STATUS_BUSY   (1 << 6)
 DP command unit is busy.
 
#define DP_STATUS_BUFFER_READY   (1 << 7)
 DP command buffer is ready.
 
#define DP_STATUS_DMA_BUSY   (1 << 8)
 DP DMA is busy.
 
#define DP_STATUS_END_VALID   (1 << 9)
 DP command end register is valid.
 
#define DP_STATUS_START_VALID   (1 << 10)
 DP command start register is valid.
 
#define DP_WSTATUS_RESET_XBUS_DMEM_DMA   (1<<0)
 DP_STATUS write mask: clear DP_STATUS_DMEM_DMA bit.
 
#define DP_WSTATUS_SET_XBUS_DMEM_DMA   (1<<1)
 DP_STATUS write mask: set DP_STATUS_DMEM_DMA bit.
 
#define DP_WSTATUS_RESET_FREEZE   (1<<2)
 DP_STATUS write mask: clear DP_STATUS_FREEZE bit.
 
#define DP_WSTATUS_SET_FREEZE   (1<<3)
 DP_STATUS write mask: set DP_STATUS_FREEZE bit.
 
#define DP_WSTATUS_RESET_FLUSH   (1<<4)
 DP_STATUS write mask: clear DP_STATUS_FLUSH bit.
 
#define DP_WSTATUS_SET_FLUSH   (1<<5)
 DP_STATUS write mask: set DP_STATUS_FLUSH bit.
 
#define DP_WSTATUS_RESET_TMEM_COUNTER   (1<<6)
 DP_STATUS write mask: clear TMEM counter.
 
#define DP_WSTATUS_RESET_PIPE_COUNTER   (1<<7)
 DP_STATUS write mask: clear PIPE counter.
 
#define DP_WSTATUS_RESET_CMD_COUNTER   (1<<8)
 DP_STATUS write mask: clear CMD counter.
 
#define DP_WSTATUS_RESET_CLOCK_COUNTER   (1<<9)
 DP_STATUS write mask: clear CLOCK counter.
 

Enumerations

enum  mirror_t { MIRROR_DISABLED , MIRROR_X , MIRROR_Y , MIRROR_XY }
 Mirror settings for textures. More...
 
enum  flush_t { FLUSH_STRATEGY_NONE , FLUSH_STRATEGY_AUTOMATIC }
 Caching strategy for loaded textures. More...
 

Functions

uint32_t rdp_load_texture (uint32_t texslot, uint32_t texloc, mirror_t mirror, sprite_t *sprite)
 Load a sprite into RDP TMEM.
 
uint32_t rdp_load_texture_stride (uint32_t texslot, uint32_t texloc, mirror_t mirror, sprite_t *sprite, int offset)
 Load part of a sprite into RDP TMEM.
 
void rdp_draw_textured_rectangle_scaled (uint32_t texslot, int tx, int ty, int bx, int by, double x_scale, double y_scale, mirror_t mirror)
 Draw a textured rectangle with a scaled texture.
 
void rdp_draw_textured_rectangle (uint32_t texslot, int tx, int ty, int bx, int by, mirror_t mirror)
 Draw a textured rectangle.
 
void rdp_draw_sprite (uint32_t texslot, int x, int y, mirror_t mirror)
 Draw a texture to the screen as a sprite.
 
void rdp_draw_sprite_scaled (uint32_t texslot, int x, int y, double x_scale, double y_scale, mirror_t mirror)
 Draw a texture to the screen as a scaled sprite.
 
void rdp_set_blend_color (uint32_t color)
 Set the blend draw color for subsequent filled primitive operations.
 
void rdp_draw_filled_triangle (float x1, float y1, float x2, float y2, float x3, float y3)
 Draw a filled triangle.
 
void rdp_set_texture_flush (flush_t flush)
 Set the flush strategy for texture loads.
 

Detailed Description

Interface to the hardware sprite/triangle rasterizer (RDP).

This module contains an old API to draw using the RDP. The API was not extensible enough and in general did not provide a good enough foundation for RDP programming. So it has been deprecated in favor of the new RDPQ API, which is much more flexible.

All RDP functions are now implemented as wrappers of the RDPQ API. They continue to work just like before, but there will be no further work on them. Also, most of them are explicitly marked as deprecated, and will generate a warning at compile time. The warning suggests the alternative RDPQ API to use instead. In most cases, the change should be straightforward.

Functions not explicitly marked as deprecated do not have a direct equivalent in RDPQ API yet.


Data Structure Documentation

◆ sprite_cache

struct sprite_cache

Cached sprite structure.

Data Fields
uint32_t s S location of the top left of the texture relative to the original texture.
uint32_t t T location of the top left of the texture relative to the original texture.
uint32_t width Width of the texture.
uint32_t height Height of the texture.
uint16_t real_width Width of the texture rounded up to next power of 2.
uint16_t real_height Height of the texture rounded up to next power of 2.

Enumeration Type Documentation

◆ mirror_t

enum mirror_t

Mirror settings for textures.

Enumerator
MIRROR_DISABLED 

Disable texture mirroring.

MIRROR_X 

Enable texture mirroring on x axis.

MIRROR_Y 

Enable texture mirroring on y axis.

MIRROR_XY 

Enable texture mirroring on both x & y axis.

◆ flush_t

enum flush_t

Caching strategy for loaded textures.

Enumerator
FLUSH_STRATEGY_NONE 

Textures are assumed to be pre-flushed.

FLUSH_STRATEGY_AUTOMATIC 

Cache will be flushed on all incoming textures.

Function Documentation

◆ rdp_load_texture()

uint32_t rdp_load_texture ( uint32_t  texslot,
uint32_t  texloc,
mirror_t  mirror,
sprite_t sprite 
)

Load a sprite into RDP TMEM.

Parameters
[in]texslotThe RDP texture slot to load this sprite into (0-7)
[in]texlocThe RDP TMEM offset to place the texture at
[in]mirrorWhether the sprite should be mirrored when displaying past boundaries
[in]spritePointer to sprite structure to load the texture from
Returns
The number of bytes consumed in RDP TMEM by loading this sprite

◆ rdp_load_texture_stride()

uint32_t rdp_load_texture_stride ( uint32_t  texslot,
uint32_t  texloc,
mirror_t  mirror,
sprite_t sprite,
int  offset 
)

Load part of a sprite into RDP TMEM.

Given a sprite with vertical and horizontal slices defined, this function will load the slice specified in offset into texture memory. This is usefl for treating a large sprite as a tilemap.

Given a sprite with 3 horizontal slices and two vertical slices, the offsets are as follows:

*---*---*---*
| 0 | 1 | 2 |
*---*---*---*
| 3 | 4 | 5 |
*---*---*---*
Parameters
[in]texslotThe RDP texture slot to load this sprite into (0-7)
[in]texlocThe RDP TMEM offset to place the texture at
[in]mirrorWhether the sprite should be mirrored when displaying past boundaries
[in]spritePointer to sprite structure to load the texture from
[in]offsetOffset of the particular slice to load into RDP TMEM.
Returns
The number of bytes consumed in RDP TMEM by loading this sprite

◆ rdp_draw_textured_rectangle_scaled()

void rdp_draw_textured_rectangle_scaled ( uint32_t  texslot,
int  tx,
int  ty,
int  bx,
int  by,
double  x_scale,
double  y_scale,
mirror_t  mirror 
)

Draw a textured rectangle with a scaled texture.

Given an already loaded texture, this function will draw a rectangle textured with the loaded texture at a scale other than 1. This allows rectangles to be drawn with stretched or squashed textures. If the rectangle is larger than the texture after scaling, it will be tiled or mirrored based on the mirror setting given in the load texture command.

Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.

Parameters
[in]texslotThe texture slot that the texture was previously loaded into (0-7)
[in]txThe pixel X location of the top left of the rectangle
[in]tyThe pixel Y location of the top left of the rectangle
[in]bxThe pixel X location of the bottom right of the rectangle
[in]byThe pixel Y location of the bottom right of the rectangle
[in]x_scaleHorizontal scaling factor
[in]y_scaleVertical scaling factor
[in]mirrorWhether the texture should be mirrored

◆ rdp_draw_textured_rectangle()

void rdp_draw_textured_rectangle ( uint32_t  texslot,
int  tx,
int  ty,
int  bx,
int  by,
mirror_t  mirror 
)

Draw a textured rectangle.

Given an already loaded texture, this function will draw a rectangle textured with the loaded texture. If the rectangle is larger than the texture, it will be tiled or mirrored based on the* mirror setting given in the load texture command.

Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.

Parameters
[in]texslotThe texture slot that the texture was previously loaded into (0-7)
[in]txThe pixel X location of the top left of the rectangle
[in]tyThe pixel Y location of the top left of the rectangle
[in]bxThe pixel X location of the bottom right of the rectangle
[in]byThe pixel Y location of the bottom right of the rectangle
[in]mirrorWhether the texture should be mirrored

◆ rdp_draw_sprite()

void rdp_draw_sprite ( uint32_t  texslot,
int  x,
int  y,
mirror_t  mirror 
)

Draw a texture to the screen as a sprite.

Given an already loaded texture, this function will draw a rectangle textured with the loaded texture.

Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.

Parameters
[in]texslotThe texture slot that the texture was previously loaded into (0-7)
[in]xThe pixel X location of the top left of the sprite
[in]yThe pixel Y location of the top left of the sprite
[in]mirrorWhether the texture should be mirrored

◆ rdp_draw_sprite_scaled()

void rdp_draw_sprite_scaled ( uint32_t  texslot,
int  x,
int  y,
double  x_scale,
double  y_scale,
mirror_t  mirror 
)

Draw a texture to the screen as a scaled sprite.

Given an already loaded texture, this function will draw a rectangle textured with the loaded texture.

Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.

Parameters
[in]texslotThe texture slot that the texture was previously loaded into (0-7)
[in]xThe pixel X location of the top left of the sprite
[in]yThe pixel Y location of the top left of the sprite
[in]x_scaleHorizontal scaling factor
[in]y_scaleVertical scaling factor
[in]mirrorWhether the texture should be mirrored

◆ rdp_set_blend_color()

void rdp_set_blend_color ( uint32_t  color)

Set the blend draw color for subsequent filled primitive operations.

This function sets the color of all rdp_draw_filled_triangle operations that follow.

Parameters
[in]colorColor to draw primitives in

◆ rdp_draw_filled_triangle()

void rdp_draw_filled_triangle ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3 
)

Draw a filled triangle.

Given a color set with rdp_set_blend_color, this will draw a filled triangle to the screen. Vertex order is not important.

Before calling this function, make sure that the RDP is set to blend mode by calling rdp_enable_blend_fill.

Parameters
[in]x1Pixel X1 location of triangle
[in]y1Pixel Y1 location of triangle
[in]x2Pixel X2 location of triangle
[in]y2Pixel Y2 location of triangle
[in]x3Pixel X3 location of triangle
[in]y3Pixel Y3 location of triangle

◆ rdp_set_texture_flush()

void rdp_set_texture_flush ( flush_t  flush)

Set the flush strategy for texture loads.

If textures are guaranteed to be in uncached RDRAM or the cache is flushed before calling load operations, the RDP can be told to skip flushing the cache. This affords a good speedup. However, if you are changing textures in memory on the fly or otherwise do not want to deal with cache coherency, set the cache strategy to automatic to have the RDP flush cache before texture loads.

Parameters
[in]flushThe cache strategy, either FLUSH_STRATEGY_NONE or FLUSH_STRATEGY_AUTOMATIC.