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>
34 #include <sifteo/asset.h>
35 #include <sifteo/memory.h>
36 #include <sifteo/cube.h>
69 template <
unsigned tW,
unsigned tH,
unsigned tF = 1>
75 uint16_t tiles[tW * tH * tF];
90 operator const _SYSAssetImage& ()
const {
return sys.image; }
91 operator _SYSAssetImage& () {
return sys.image; }
92 operator const _SYSAssetImage* ()
const {
return sys.image; }
93 operator _SYSAssetImage* () {
return sys.image; }
99 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
120 sys.cube = _SYS_CUBE_ID_INVALID;
122 sys.image.width = tW;
123 sys.image.height = tH;
124 sys.image.frames = tF;
125 sys.image.format = _SYS_AIF_FLAT;
126 sys.image.pData =
reinterpret_cast<uint32_t
>(&tiles[0]);
238 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
256 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
266 void plot(
unsigned i, uint16_t tileIndex) {
267 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
269 tiles[i] = tileIndex;
278 void plot(
UInt2 pos, uint16_t tileIndex,
unsigned frame = 0) {
279 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
281 tiles[
tileAddr(pos, frame)] = tileIndex;
287 uint16_t
tile(
unsigned i)
const {
288 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
298 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
309 void span(
UInt2 pos,
unsigned width,
unsigned tileIndex,
unsigned frame = 0)
311 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
324 span(pos, width, image.
tile(sys.cube, 0), frame);
336 span(topLeft, size.
x, tileIndex, frame);
350 fill(topLeft, size, image.
tile(sys.cube, 0), frame);
364 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
368 _SYS_image_memDraw(&tiles[
tileAddr(pos, destFrame)], sys.cube, image,
tileWidth(), srcFrame);
381 unsigned srcFrame = 0,
unsigned destFrame = 0)
383 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
387 _SYS_image_memDrawRect(&tiles[
tileAddr(destXY, destFrame)], sys.cube,
388 image,
tileWidth(), srcFrame, (_SYSInt2*) &srcXY, (_SYSInt2*) &size);
398 unsigned destFrame = 0,
char firstChar =
' ')
400 ASSERT(sys.cube != _SYS_CUBE_ID_INVALID);
401 uint16_t *addr = &tiles[
tileAddr(topLeft, destFrame)];
402 uint16_t *lineAddr = addr;
411 _SYS_image_memDraw(addr, sys.cube, font,
tileWidth(), c - firstChar);
447 template <
unsigned tW,
unsigned tH,
unsigned tF = 1>
450 uint16_t tiles[tW * tH * tF];
455 operator const AssetImage* ()
const {
return reinterpret_cast<const AssetImage*
>(&sys); }
456 operator AssetImage* () {
return reinterpret_cast<AssetImage*
>(&sys); }
461 operator const FlatAssetImage* ()
const {
return reinterpret_cast<const FlatAssetImage*
>(&sys); }
462 operator FlatAssetImage* () {
return reinterpret_cast<FlatAssetImage*
>(&sys); }
465 operator const _SYSAssetImage& ()
const {
return sys; }
466 operator _SYSAssetImage& () {
return sys; }
467 operator const _SYSAssetImage* ()
const {
return sys; }
468 operator _SYSAssetImage* () {
return sys; }
481 sys.format = _SYS_AIF_FLAT;
482 sys.pData =
reinterpret_cast<uint32_t
>(&tiles[0]);
575 uint32_t pAssetGroup =
reinterpret_cast<uint32_t
>(&group.sys);
576 ASSERT(sys.pAssetGroup == 0 || sys.pAssetGroup == pAssetGroup);
577 sys.pAssetGroup = pAssetGroup;
612 void plot(
unsigned i, uint16_t tileIndex) {
614 tiles[i] = tileIndex;
623 void plot(
UInt2 pos, uint16_t tileIndex,
unsigned frame = 0) {
625 tiles[
tileAddr(pos, frame)] = tileIndex;
631 uint16_t
tile(
unsigned i)
const {
651 void span(
UInt2 pos,
unsigned width,
unsigned tileIndex,
unsigned frame = 0)
666 span(pos, width, image.
tile(0), frame);
678 span(topLeft, size.
x, tileIndex, frame);
693 fill(topLeft, size, image.
tile(0), frame);
711 _SYS_image_memDraw(&tiles[
tileAddr(pos, destFrame)],
712 _SYS_CUBE_ID_INVALID, image,
tileWidth(), srcFrame);
725 unsigned srcFrame = 0,
unsigned destFrame = 0)
731 _SYS_image_memDrawRect(&tiles[
tileAddr(destXY, destFrame)],
732 _SYS_CUBE_ID_INVALID, image,
tileWidth(), srcFrame,
733 (_SYSInt2*) &srcXY, (_SYSInt2*) &size);
743 unsigned destFrame = 0,
char firstChar =
' ')
746 uint16_t *addr = &tiles[
tileAddr(topLeft, destFrame)];
747 uint16_t *lineAddr = addr;
756 _SYS_image_memDraw(addr, _SYS_CUBE_ID_INVALID, font,
tileWidth(), c - firstChar);
static unsigned pixelWidth()
Return the width, in pixels, of this mode.
Definition: tilebuffer.h:180
void image(UInt2 pos, const AssetImage &image, unsigned srcFrame=0, unsigned destFrame=0)
Draw a full AssetImage frame, with its top-left corner at the specified location. ...
Definition: tilebuffer.h:705
void fill(UInt2 topLeft, UInt2 size, const PinnedAssetImage &image, unsigned frame=0)
Fill a rectangle of identical tiles, using the first tile of a pinned asset.
Definition: tilebuffer.h:348
void init()
Initialize the TileBuffer's AssetImage header.
Definition: tilebuffer.h:119
static unsigned pixelHeight()
Return the height, in pixel, of this mode.
Definition: tilebuffer.h:187
TileBuffer()
Initialize a TileBuffer.
Definition: tilebuffer.h:135
A bundle of compressed tile data, for use by AssetImages.
Definition: group.h:54
static unsigned tileHeight()
Return the height, in tiles, of this mode.
Definition: tilebuffer.h:166
Generalized two-element cartesian coordinate vector.
Definition: math.h:488
AssetGroup & assetGroup() const
Access the AssetGroup instance associated with this AssetImage.
Definition: image.h:73
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
void plot(UInt2 pos, uint16_t tileIndex, unsigned frame=0)
Plot a single tile, by relative tile index, at location 'pos' in tile units, on the given frame...
Definition: tilebuffer.h:623
static unsigned tileWidth()
Return the width, in tiles, of this mode.
Definition: tilebuffer.h:159
void fill(UInt2 topLeft, UInt2 size, unsigned tileIndex, unsigned frame=0)
Fill a rectangle of identical tiles, specified as a top-left corner location and a size...
Definition: tilebuffer.h:675
static UInt2 tileSize()
Return the size of this mode as a vector, in tiles.
Definition: tilebuffer.h:509
void erase(const PinnedAssetImage &image)
Erase the buffer, filling it with the first tile from the specified PinnedAssetImage.
Definition: tilebuffer.h:246
int tileWidth() const
The width of this image, in tiles.
Definition: image.h:90
void erase(const PinnedAssetImage &image)
Erase the buffer, filling it with the first tile from the specified PinnedAssetImage.
Definition: tilebuffer.h:592
static UInt2 tileSize()
Return the size of this mode as a vector, in tiles.
Definition: tilebuffer.h:173
A drawable that's backed by plain memory, usable with multiple cubes.
Definition: tilebuffer.h:448
void span(UInt2 pos, unsigned width, const PinnedAssetImage &image, unsigned frame=0)
Plot a horizontal span of tiles, using the first tile of a pinned asset.
Definition: tilebuffer.h:322
An AssetImage in which all tiles are stored sequentially in memory.
Definition: image.h:134
void bzero(void *s, unsigned count)
Write 'n' zero bytes to memory.
Definition: memory.h:114
void erase(uint16_t index=0)
Erase the buffer, filling it with the specified relative tile index value.
Definition: tilebuffer.h:584
static int numTilesPerFrame()
Return the number of tiles in each frame of the image.
Definition: tilebuffer.h:544
AssetGroup & assetGroup() const
Access the AssetGroup instance associated with this AssetImage.
Definition: image.h:140
void plot(UInt2 pos, uint16_t tileIndex, unsigned frame=0)
Plot a single tile, by absolute tile index, at location 'pos' in tile units, on the given frame...
Definition: tilebuffer.h:278
uint16_t tile(unsigned i) const
Returns the index of the tile at linear position 'i' in the image.
Definition: tilebuffer.h:287
uint16_t tileAddr(UInt2 pos, unsigned frame=0) const
Calculate the video buffer address of a particular tile.
Definition: tilebuffer.h:255
void setCube(CubeID cube)
Change the CubeID associated with this drawable.
Definition: tilebuffer.h:112
T x
Vector component X.
Definition: math.h:489
void span(UInt2 pos, unsigned width, unsigned tileIndex, unsigned frame=0)
Plot a horizontal span of tiles, by relative tile index, given the position of the leftmost tile and ...
Definition: tilebuffer.h:651
static UInt2 pixelSize()
Return the size of this mode as a vector, in pixels.
Definition: tilebuffer.h:194
int tileHeight() const
The height of this image, in tiles.
Definition: image.h:93
uint16_t tileAddr(UInt2 pos, unsigned frame=0)
Calculate the video buffer address of a particular tile.
Definition: tilebuffer.h:602
void image(UInt2 destXY, UInt2 size, const AssetImage &image, UInt2 srcXY, unsigned srcFrame=0, unsigned destFrame=0)
Draw part of an AssetImage frame, with its top-left corner at the specified location.
Definition: tilebuffer.h:724
void span(UInt2 pos, unsigned width, const PinnedAssetImage &image, unsigned frame=0)
Plot a horizontal span of tiles, using the first tile of a pinned asset.
Definition: tilebuffer.h:663
A lightweight identifier for one Sifteo cube.
Definition: cube.h:85
static unsigned pixelWidth()
Return the width, in pixels, of this mode.
Definition: tilebuffer.h:516
uint16_t tile(unsigned i) const
Returns the index of the tile at linear position 'i' in the image.
Definition: image.h:160
Any kind of asset image, as defined in your stir script.
Definition: image.h:67
void span(UInt2 pos, unsigned width, unsigned tileIndex, unsigned frame=0)
Plot a horizontal span of tiles, by absolute tile index, given the position of the leftmost tile and ...
Definition: tilebuffer.h:309
void setAssetGroup(AssetGroup &group)
Set the AssetGroup associated with this buffer.
Definition: tilebuffer.h:574
static unsigned sizeInBytes()
Returns the size of this drawable's tile data, in bytes.
Definition: tilebuffer.h:222
static unsigned sizeInWords()
Returns the size of this drawable's tile data, in 16-bit words.
Definition: tilebuffer.h:229
uint16_t tile(UInt2 pos, unsigned frame=0) const
Return the relative index of the tile at the specified (x, y) tile coordinates, and optionally on the...
Definition: tilebuffer.h:640
void plot(unsigned i, uint16_t tileIndex)
Plot a single tile, by relative tile index, at linear position 'i'.
Definition: tilebuffer.h:612
static UInt2 pixelSize()
Return the size of this mode as a vector, in pixels.
Definition: tilebuffer.h:530
void plot(unsigned i, uint16_t tileIndex)
Plot a single tile, by absolute tile index, at linear position 'i'.
Definition: tilebuffer.h:266
T y
Vector component Y.
Definition: math.h:490
static int numFrames()
Return the number of frames in this image.
Definition: tilebuffer.h:201
void fill(UInt2 topLeft, UInt2 size, unsigned tileIndex, unsigned frame=0)
Fill a rectangle of identical tiles, specified as a top-left corner location and a size...
Definition: tilebuffer.h:333
static int numTiles()
Return the total number of tiles in every frame of the image.
Definition: tilebuffer.h:551
void memset16(uint16_t *dest, uint16_t value, unsigned count)
memset(), with an explicit 16-bit data width
Definition: memory.h:49
void image(UInt2 pos, const AssetImage &image, unsigned srcFrame=0, unsigned destFrame=0)
Draw a full AssetImage frame, with its top-left corner at the specified location. ...
Definition: tilebuffer.h:362
A drawable that's backed by plain memory, instead of by a VideoBuffer.
Definition: tilebuffer.h:70
TileBuffer(CubeID cube)
Initialize a TileBuffer for use.
Definition: tilebuffer.h:150
static unsigned tileHeight()
Return the height, in tiles, of this mode.
Definition: tilebuffer.h:502
uint16_t tile(unsigned i) const
Returns the relative index of the tile at linear position 'i' in the image.
Definition: tilebuffer.h:631
static unsigned sizeInBytes()
Returns the size of this drawable's tile data, in bytes.
Definition: tilebuffer.h:558
void text(Int2 topLeft, const AssetImage &font, const char *str, unsigned destFrame=0, char firstChar= ' ')
Draw text, using an AssetImage as a fixed width font.
Definition: tilebuffer.h:742
void init()
Initialize the RelocatableTileBuffer's AssetImage header.
Definition: tilebuffer.h:476
void erase(uint16_t index=0)
Erase the buffer, filling it with the specified absolute tile index value.
Definition: tilebuffer.h:237
An AssetImage in which all tile indices are stored in a flat array, without any additional compressio...
Definition: image.h:247
void text(Int2 topLeft, const AssetImage &font, const char *str, unsigned destFrame=0, char firstChar= ' ')
Draw text, using an AssetImage as a fixed width font.
Definition: tilebuffer.h:397
void fill(UInt2 topLeft, UInt2 size, const PinnedAssetImage &image, unsigned frame=0)
Fill a rectangle of identical tiles, using the first tile of a pinned asset.
Definition: tilebuffer.h:690
static unsigned tileWidth()
Return the width, in tiles, of this mode.
Definition: tilebuffer.h:495
RelocatableTileBuffer()
Initialize a RelocatableTileBuffer.
Definition: tilebuffer.h:488
static int numFrames()
Return the number of frames in this image.
Definition: tilebuffer.h:537
CubeID cube() const
Return the CubeID associated with this drawable.
Definition: tilebuffer.h:98
static unsigned pixelHeight()
Return the height, in pixel, of this mode.
Definition: tilebuffer.h:523
static int numTilesPerFrame()
Return the number of tiles in each frame of the image.
Definition: tilebuffer.h:208
void image(UInt2 destXY, UInt2 size, const AssetImage &image, UInt2 srcXY, unsigned srcFrame=0, unsigned destFrame=0)
Draw part of an AssetImage frame, with its top-left corner at the specified location.
Definition: tilebuffer.h:380
static unsigned sizeInWords()
Returns the size of this drawable's tile data, in 16-bit words.
Definition: tilebuffer.h:565
uint16_t tile(UInt2 pos, unsigned frame=0) const
Return the index of the tile at the specified (x, y) tile coordinates, and optionally on the specifie...
Definition: tilebuffer.h:297
Vector2< T > vec(T x, T y)
Create a Vector2, from a set of (x,y) coordinates.
Definition: math.h:658
static int numTiles()
Return the total number of tiles in every frame of the image.
Definition: tilebuffer.h:215