28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/abi.h>
32 #include <sifteo/macros.h>
33 #include <sifteo/math.h>
59 _SYSAttachedVideoBuffer *sys;
70 uint16_t word = _SYS_TILE77(tile);
71 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].tile)/2 +
72 sizeof(_SYSSpriteInfo)/2 *
id );
73 _SYS_vbuf_poke(&sys->vbuf, addr, word);
89 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].mask_x) +
90 sizeof(_SYSSpriteInfo) *
id );
91 return -(int8_t)_SYS_vbuf_peekb(&sys->vbuf, addr);
98 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].mask_y) +
99 sizeof(_SYSSpriteInfo) *
id );
100 return -(int8_t)_SYS_vbuf_peekb(&sys->vbuf, addr);
107 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].mask_y)/2 +
108 sizeof(_SYSSpriteInfo)/2 *
id );
109 uint16_t word = _SYS_vbuf_peek(&sys->vbuf, addr);
110 return vec<uint8_t>(-(int8_t)(word >> 8), -(int8_t)word);
117 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].mask_x) +
118 sizeof(_SYSSpriteInfo) *
id );
119 _SYS_vbuf_pokeb(&sys->vbuf, addr, -(int8_t)pixels);
126 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].mask_y) +
127 sizeof(_SYSSpriteInfo) *
id );
128 _SYS_vbuf_pokeb(&sys->vbuf, addr, -(int8_t)pixels);
136 ASSERT((x & (x - 1)) == 0 && (y & (y - 1)) == 0);
138 _SYS_vbuf_spr_resize(&sys->vbuf,
id, x, y);
178 _SYS_vbuf_spr_move(&sys->vbuf,
id, x, y);
209 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].pos_x) +
210 sizeof(_SYSSpriteInfo) *
id );
211 return -(int8_t)_SYS_vbuf_peekb(&sys->vbuf, addr);
218 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].pos_y) +
219 sizeof(_SYSSpriteInfo) *
id );
220 return -(int8_t)_SYS_vbuf_peekb(&sys->vbuf, addr);
227 uint16_t addr = (
offsetof(_SYSVideoRAM, spr[0].pos_y)/2 +
228 sizeof(_SYSSpriteInfo)/2 *
id );
229 uint16_t word = _SYS_vbuf_peek(&sys->vbuf, addr);
230 return vec<int8_t>(-(int8_t)(word >> 8), -(int8_t)word);
240 SpriteRef operator++ (
int) {
241 SpriteRef result = *
this;
247 SpriteRef operator-- () {
253 SpriteRef operator-- (
int) {
254 SpriteRef result = *
this;
260 SpriteRef operator[] (
int index) {
261 SpriteRef result = *
this;
279 _SYSAttachedVideoBuffer sys;
281 static const unsigned NUM_SPRITES = _SYS_VRAM_SPRITES;
302 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_SPR / 2, 0,
303 sizeof(_SYSSpriteInfo) / 2 * NUM_SPRITES);
#define offsetof(t, m)
Definition: macros.h:368
UByte2 size() const
Get this sprite's current image size as a vector, in pixels.
Definition: sprite.h:106
Generalized two-element cartesian coordinate vector.
Definition: math.h:488
void resize(unsigned x, unsigned y) const
Set this sprite's size, in pixels.
Definition: sprite.h:134
void move(Float2 pos) const
Move this sprite to a new location, in pixels, passed as a Float2.
Definition: sprite.h:200
SpriteRef operator[](unsigned id)
Return a SpriteRef which references a single sprite on a single VideoBuffer.
Definition: sprite.h:292
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
Int2 pixelSize() const
The (width, height) vector of this image, in pixels.
Definition: image.h:149
Byte2 position() const
Get this sprite's current position as a vector, in pixels.
Definition: sprite.h:226
An AssetImage in which all tiles are stored sequentially in memory.
Definition: image.h:134
T x
Vector component X.
Definition: math.h:489
unsigned y() const
Get this sprite's current Y position, in pixels.
Definition: sprite.h:217
unsigned width() const
Get this sprite's current image width, in pixels.
Definition: sprite.h:88
A lightweight identifier for one Sifteo cube.
Definition: cube.h:85
void move(Int2 pos) const
Move this sprite to a new location, in pixels, passed as an Int2.
Definition: sprite.h:188
unsigned height() const
Get this sprite's current image height, in pixels.
Definition: sprite.h:97
void setImage(const PinnedAssetImage &asset, int frame=0) const
Set a sprite's image and size, given a PinnedAssetImage and optionally a frame number.
Definition: sprite.h:80
unsigned x() const
Get this sprite's current X position, in pixels.
Definition: sprite.h:208
uint16_t tile(unsigned i) const
Returns the index of the tile at linear position 'i' in the image.
Definition: image.h:160
bool isHidden() const
Is this sprite hidden?
Definition: sprite.h:156
void hide() const
Hide a sprite.
Definition: sprite.h:166
void move(int x, int y) const
Move this sprite to a new location, in pixels.
Definition: sprite.h:177
void resize(UInt2 size) const
Set this sprite's size, in pixels, from a UInt2.
Definition: sprite.h:144
CubeID cube() const
Return the CubeID associated with this drawable.
Definition: sprite.h:316
T y
Vector component Y.
Definition: math.h:490
void setWidth(unsigned pixels) const
Set this sprite's width, in pixels.
Definition: sprite.h:116
void setImage(uint16_t tile) const
Set the sprite's image, given the physical address of the first tile in a pinned asset.
Definition: sprite.h:69
void setHeight(unsigned pixels) const
Set this sprite's height, in pixels.
Definition: sprite.h:125
_SYSVideoBuffer & videoBuffer()
Return the VideoBuffer associated with this drawable.
Definition: sprite.h:309
void erase()
Reset all sprites to their default hidden state.
Definition: sprite.h:301
Vector2< int > round() const
Round a floating point vector to the nearest integer.
Definition: math.h:598
A SpriteLayer represents the VRAM attributes for the sprite rendering layer in BG0_SPR_BG1 mode...
Definition: sprite.h:278
SpriteRefs refer to a single sprite on a single cube.
Definition: sprite.h:58
Vector2< T > vec(T x, T y)
Create a Vector2, from a set of (x,y) coordinates.
Definition: math.h:658