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>
70 BG1Mask result = { 0, 0, 0, 0, 0, 0, 0, 0 };
84 unsigned xBits = ((1 << size.
x) - 1) << topLeft.
x;
85 unsigned yBits = ((1 << size.
y) - 1) << topLeft.
y;
87 unsigned row0 = yBits & 0x0001 ? xBits : 0;
88 unsigned row1 = yBits & 0x0002 ? xBits : 0;
89 unsigned row2 = yBits & 0x0004 ? xBits : 0;
90 unsigned row3 = yBits & 0x0008 ? xBits : 0;
91 unsigned row4 = yBits & 0x0010 ? xBits : 0;
92 unsigned row5 = yBits & 0x0020 ? xBits : 0;
93 unsigned row6 = yBits & 0x0040 ? xBits : 0;
94 unsigned row7 = yBits & 0x0080 ? xBits : 0;
95 unsigned row8 = yBits & 0x0100 ? xBits : 0;
96 unsigned row9 = yBits & 0x0200 ? xBits : 0;
97 unsigned rowA = yBits & 0x0400 ? xBits : 0;
98 unsigned rowB = yBits & 0x0800 ? xBits : 0;
99 unsigned rowC = yBits & 0x1000 ? xBits : 0;
100 unsigned rowD = yBits & 0x2000 ? xBits : 0;
101 unsigned rowE = yBits & 0x4000 ? xBits : 0;
102 unsigned rowF = yBits & 0x8000 ? xBits : 0;
121 _SYS_memset32(&row10, 0, 8);
128 return (uint16_t*)
this;
130 const uint16_t *
rows()
const {
131 return (
const uint16_t*)
this;
139 void plot(
unsigned x,
unsigned y) {
159 for (
unsigned y = 0; y < size.
y; y++)
160 for (
unsigned x = 0; x < size.
x; x++)
161 plot(topLeft.
x + x, topLeft.
y + y);
166 row10 |= other.row10;
167 row32 |= other.row32;
168 row54 |= other.row54;
169 row76 |= other.row76;
170 row98 |= other.row98;
171 rowBA |= other.rowBA;
172 rowDC |= other.rowDC;
173 rowFE |= other.rowFE;
179 row10 &= other.row10;
180 row32 &= other.row32;
181 row54 &= other.row54;
182 row76 &= other.row76;
183 row98 &= other.row98;
184 rowBA &= other.rowBA;
185 rowDC &= other.rowDC;
186 rowFE &= other.rowFE;
192 row10 ^= other.row10;
193 row32 ^= other.row32;
194 row54 ^= other.row54;
195 row76 ^= other.row76;
196 row98 ^= other.row98;
197 rowBA ^= other.rowBA;
198 rowDC ^= other.rowDC;
199 rowFE ^= other.rowFE;
286 _SYSAttachedVideoBuffer sys;
292 return _SYS_VRAM_BG1_WIDTH;
299 return _SYS_VRAM_BG1_WIDTH;
334 return _SYS_VRAM_BG1_TILES;
344 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_BG1_TILES / 2,
362 void fill(uint16_t index = 0) {
363 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_BG1_TILES / 2,
390 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_BG1_BITMAP/2, 0, _SYS_VRAM_BG1_WIDTH);
407 _SYS_vbuf_write(&sys.vbuf,
offsetof(_SYSVideoRAM, bg1_bitmap)/2,
434 _SYS_vbuf_fill(&sys.vbuf,
435 offsetof(_SYSVideoRAM, bg1_bitmap)/2 + topLeft.
y,
436 ((1 << size.
x) - 1) << topLeft.
x, size.
y);
450 unsigned x = pixels.
x & 0xFF;
451 unsigned y = pixels.
y & 0xFF;
452 _SYS_vbuf_poke(&sys.vbuf,
offsetof(_SYSVideoRAM, bg1_x) / 2, x | (y << 8));
459 unsigned word = _SYS_vbuf_peek(&sys.vbuf,
offsetof(_SYSVideoRAM, bg0_x) / 2);
460 return vec<int>((int8_t)(word & 0xFF), (int8_t)(word >> 8));
467 void plot(
unsigned locationIndex, uint16_t tileIndex) {
469 _SYS_vbuf_poke(&sys.vbuf, _SYS_VA_BG1_TILES / 2 + locationIndex,
470 _SYS_TILE77(tileIndex));
479 void span(
unsigned locationIndex,
unsigned count,
unsigned tileIndex)
482 (locationIndex + count) <
numTiles());
483 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_BG1_TILES / 2 + locationIndex,
484 _SYS_TILE77(tileIndex), count);
500 _SYS_image_BG1Draw(&sys, image, (_SYSInt2*) &pos, frame);
516 _SYS_image_BG1DrawRect(&sys, image, (_SYSInt2*) &destXY,
517 frame, (_SYSInt2*) &srcXY, (_SYSInt2*) &size);
536 _SYS_image_BG1MaskedDraw(&sys, image, key.
tile(sys.cube, 0), frame);
557 _SYS_image_BG1MaskedDrawRect(&sys, image, key.
tile(sys.cube, 0), frame,
558 (_SYSInt2*) &srcXY, (_SYSInt2*) &size);
577 _SYS_image_BG1Draw(&sys, font, (_SYSInt2*) &pos, c - firstChar);
A BG1 tile mask. In other words, this is a 16x16-bit two-dimensional vector.
Definition: bg1.h:55
void span(unsigned locationIndex, unsigned count, unsigned tileIndex)
Plot a horizontal span of tiles in consecutively allocated locations in the BG1 tile array...
Definition: bg1.h:479
static UInt2 tileSize()
Return the size of this mode as a vector, in tiles.
Definition: bg1.h:305
CubeID cube() const
Return the CubeID associated with this drawable.
Definition: bg1.h:594
#define offsetof(t, m)
Definition: macros.h:368
void eraseMask()
Erase just the allocation mask. All tiles will now be unallocated, and BG1 will be fully transparent...
Definition: bg1.h:388
void fill(const PinnedAssetImage &image)
Fill all BG1 tiles with first tile from the specified PinnedAssetImage, without modifying the allocat...
Definition: bg1.h:371
BG1Mask operator^(BG1Mask other) const
Bitwise XOR with another mask.
Definition: bg1.h:234
void text(Int2 topLeft, const AssetImage &font, const char *str, char firstChar= ' ')
Draw text, using an AssetImage as a fixed width font.
Definition: bg1.h:567
void maskedImage(UInt2 size, const AssetImage &image, const PinnedAssetImage &key, UInt2 srcXY, unsigned frame=0)
Draw part of an AssetImage, automatically allocating tiles on the BG1 mask.
Definition: bg1.h:552
Generalized two-element cartesian coordinate vector.
Definition: math.h:488
void erase(const PinnedAssetImage &image)
Erase mode-specific VRAM, filling the BG1 buffer with the first tile from the specified PinnedAssetIm...
Definition: bg1.h:354
static unsigned numTiles()
Returns the maximum number of allcoated tiles.
Definition: bg1.h:333
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
BG1Mask & operator&=(BG1Mask other)
Bitwise AND with another mask.
Definition: bg1.h:178
static unsigned pixelHeight()
Return the height, in pixel, of this mode.
Definition: bg1.h:319
int tileWidth() const
The width of this image, in tiles.
Definition: image.h:90
static BG1Mask filled(UInt2 topLeft, UInt2 size)
Create a mask with a filled rectangle it.
Definition: bg1.h:83
void plot(unsigned locationIndex, uint16_t tileIndex)
Plot a single tile, by absolute tile index, at a specific location in the 144-tile array...
Definition: bg1.h:467
An AssetImage in which all tiles are stored sequentially in memory.
Definition: image.h:134
static unsigned pixelWidth()
Return the width, in pixels, of this mode.
Definition: bg1.h:312
uint16_t * rows()
Get a pointer to the rows in this mask, as 16-bit integers.
Definition: bg1.h:127
void setMask(const BG1Mask &mask)
Change the tile allocation bitmap.
Definition: bg1.h:405
static unsigned tileWidth()
Return the width, in tiles, of this mode.
Definition: bg1.h:291
Int2 getPanning() const
Retrieve the last value set by setPanning(). .
Definition: bg1.h:458
static UInt2 pixelSize()
Return the size of this mode as a vector, in pixels.
Definition: bg1.h:326
T x
Vector component X.
Definition: math.h:489
void erase(uint16_t index=0)
Erase mode-specific VRAM, filling the BG1 buffer with the specified absolute tile index value...
Definition: bg1.h:342
A VRAM accessor for drawing graphics in the BG1 mode.
Definition: bg1.h:285
int tileHeight() const
The height of this image, in tiles.
Definition: image.h:93
A lightweight identifier for one Sifteo cube.
Definition: cube.h:85
static BG1Mask empty()
Create an empty mask. All bits are zero.
Definition: bg1.h:69
void image(UInt2 destXY, UInt2 size, const AssetImage &image, UInt2 srcXY, unsigned frame=0)
Draw part of an AssetImage frame, with its top-left corner at the specified location.
Definition: bg1.h:514
void image(UInt2 pos, const AssetImage &image, unsigned frame=0)
Draw a full AssetImage frame, with its top-left corner at the specified location. ...
Definition: bg1.h:498
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 setPanning(Int2 pixels)
Change the hardware pixel-panning origin for this mode.
Definition: bg1.h:449
void fill(UInt2 topLeft, UInt2 size)
Mark a rectangular region of the bitmap.
Definition: bg1.h:158
static unsigned tileHeight()
Return the height, in tiles, of this mode.
Definition: bg1.h:298
void clear()
Erase a TileMask, setting all bits to zero.
Definition: bg1.h:120
BG1Mask & operator^=(BG1Mask other)
Bitwise XOR with another mask.
Definition: bg1.h:191
T y
Vector component Y.
Definition: math.h:490
BG1Mask operator|(BG1Mask other) const
Bitwise OR with another mask.
Definition: bg1.h:204
void plot(unsigned x, unsigned y)
Mark one tile in the bitmap, given as (x,y) coordinates.
Definition: bg1.h:139
BG1Mask operator&(BG1Mask other) const
Bitwise AND with another mask.
Definition: bg1.h:219
void maskedImage(const AssetImage &image, const PinnedAssetImage &key, unsigned frame=0)
Draw an AssetImage, automatically allocating tiles on the BG1 mask.
Definition: bg1.h:532
void fillMask(UInt2 topLeft, UInt2 size)
This is a specialized alternative to setMask(), for cases where each row of BG1 has a single contiguo...
Definition: bg1.h:432
void plot(UInt2 pos)
Mark one tile in the bitmap, given as a vector.
Definition: bg1.h:149
void fill(uint16_t index=0)
Fill all BG1 tiles with the specified absolute index, without modifying the allocation mask...
Definition: bg1.h:362
BG1Mask operator~() const
Bitwise complement.
Definition: bg1.h:249
_SYSVideoBuffer & videoBuffer()
Return the VideoBuffer associated with this drawable.
Definition: bg1.h:587
BG1Mask & operator|=(BG1Mask other)
Bitwise OR with another mask.
Definition: bg1.h:165
Vector2< T > vec(T x, T y)
Create a Vector2, from a set of (x,y) coordinates.
Definition: math.h:658