42#define MUST(cond, errcode) \
50#define MUST_RETURN(cond, errcode, retval) \
118 void seterr( Error error );
132 BUTTON_MOUSE_LEFT = 6,
160 void cls(Color color = BLACK);
185 Color color(Color color);
204 void rectfill(
fx8 x0,
fx8 y0,
fx8 x1,
fx8 y1, Color color = CURRENT);
222 void pset(
fx8 x0,
fx8 y0, Color color = CURRENT);
244 void rect(
fx8 x0,
fx8 y0,
fx8 x1,
fx8 y1, Color color = CURRENT);
264 void line(
fx8 x0,
fx8 y0,
fx8 x1,
fx8 y1, Color color = CURRENT );
283 void line(
const Line& ln, Color color = CURRENT);
300 void poly(
const Poly& pol, Color color = CURRENT);
357 void spr(
int n,
fx8 x =
fx8(0),
fx8 y =
fx8(0), u8 w = 1, u8 h = 1,
bool flip_x =
false,
bool flip_y =
false, u8 selpal = 0);
398 void sprb(u8 bank,
int n,
fx8 x =
fx8(0),
fx8 y =
fx8(0), u8 w = 1, u8 h = 1,
bool flip_x =
false,
bool flip_y =
false, u8 selpal = 0);
468 void lsp(u8 bank,
const uint8_t* srcimg);
507 void setpal(
int palsel,
const std::array<unsigned char, 16>& pidx);
541 void pal( Color c0 , Color c1 , u8 palsel=0 );
621 void circ(
fx8 x,
fx8 y,
fx8 r =
fx8(4), Color col = CURRENT);
641 void circfill(
fx8 x,
fx8 y,
fx8 r =
fx8(4), Color col = CURRENT);
745 const SprCursor&
scursor(
int x = 0,
int y = 0, Color color = CURRENT,
int z = 0);
785 void sprint(
const std::string_view format, ...);
809 void sprint(
int x,
int y, Color color, std::string_view format, ...);
832 pal = BG_PAL_CURRENT;
855 const BgCursor&
cursor(
int x = 0,
int y = 0, BgPal pal = BG_PAL_CURRENT);
888 void print(std::string_view format, ...);
906 void dprint(std::string_view format, ...);
942 void print(
int x,
int y, BgPal pal, std::string_view format, ...);
972 void fset(u8 sprite_index, u8 flag_index = 0xff, u8 value = 0, u8 sprite_pattern_bank = 0);
1002 u8
fget(u8 sprite_index, u8 flag_index = 0xff, u8 sprite_pattern_bank = 0);
1005 enum BgIndex{ BG_0, BG_1, BG_2, BG_3 , BG_MAX };
1017 using BgTilesPtr = std::shared_ptr<std::vector<b8PpuBgTile>>;
1044 void mapsetup(BgTiles wtile, BgTiles htile, std::optional<BgTilesPtr> tiles = std::nullopt , u8 uwrap = B8_PPU_BG_WRAP_CLAMP, u8 vwrap = B8_PPU_BG_WRAP_CLAMP , BgIndex index = BG_0 );
1066 void map(s16 upix,s16 vpix, BgIndex index = BG_0 );
1073 inline void mapdraw(s16 upix,s16 vpix, BgIndex index = BG_0 ){
1094 b8PpuBgTile mgett(u32 x, u32 y, BgIndex index = BG_0);
1115 u16 mget(u32 x, u32 y, BgIndex index = BG_0);
1148 void mset(u32 x, u32 y, u8 v, u8 bank = 0, BgIndex index = BG_0, uint8_t pal = 0);
1176 void msett(u32 x,u32 y,b8PpuBgTile tile,BgIndex index = BG_0 );
1189 void mcls(b8PpuBgTile tile = b8PpuBgTile{0, 0, 0, 0, 0}, BgIndex index = BG_0);
1225 u32
btn(Button button=BUTTON_ANY, u8 player = 0);
1250 bool btnp(Button button, u8 player=0);
1272 u32
btnr(Button button, u8 player=0);
1307 s32
stat(
int index);
1671 template <
typename T>
1672 const T&
rndt(std::span<const T> sp) {
1673 static const T dummy_value{};
1674 if (sp.empty())
return dummy_value;
1675 std::size_t index =
qmod( std::rand() , sp.size() );
1696 template <
typename T, std::
size_t N>
1698 return rndt(std::span<const T>(arr));
1714 void srand(u32 seed );
1754 Color sget(u8 x, u8 y , u8 bank = 0 );
1791 friend class ImplPico8;
1793 virtual void _init(){}
1794 virtual void _update(){}
1795 virtual void _draw(){}
Base class for creating PICO-8 compatible applications in C/C++.
Definition pico8.h:1790
void run()
Runs the application by calling the overridden _init(), _update(), and _draw().
Definition pico8.cpp:334
Module for managing pointers using handles.
Error
Defines error codes for drawing operations.
Definition pico8.h:111
@ NOT_DURING_DRAWING
Attempt to perform drawing outside of a valid drawing context.
Definition pico8.h:113
@ NO_ERROR
No error has occurred.
Definition pico8.h:112
@ INVALID_PARAM
An invalid parameter was passed to a function.
Definition pico8.h:114
s32 stat(int index)
Definition pico8.cpp:1098
fx8 mousey()
Retrieves the current Y position of the mouse or touch input.
Definition pico8.cpp:1117
Button
Definition pico8.h:125
@ BUTTON_X
X button ('x' key on keyboard)
Definition pico8.h:131
@ BUTTON_DOWN
Down button.
Definition pico8.h:129
@ BUTTON_UP
Up button.
Definition pico8.h:128
@ BUTTON_O
O button ('z' key on keyboard)
Definition pico8.h:130
@ BUTTON_LEFT
Left button.
Definition pico8.h:126
@ BUTTON_RIGHT
Right button.
Definition pico8.h:127
fx8 clamp(fx8 first, fx8 second, fx8 third)
Alias for mid to provide clamping functionality.
Definition pico8.h:1516
bool btnp(Button button, u8 player=0)
Definition pico8.cpp:1078
const BgCursor & cursor(int x=0, int y=0, BgPal pal=BG_PAL_CURRENT)
Sets the cursor position and palette for background-based text rendering.
Definition pico8.cpp:887
void dprint(std::string_view format,...)
Prints formatted debug output to the screen in the foremost layer.
Definition pico8.cpp:900
u32 btnr(Button button, u8 player=0)
Definition pico8.cpp:1091
const T & rndt(std::span< const T > sp)
Generates a random index and returns a reference to a randomly selected element in the given span.
Definition pico8.h:1672
fx8 flr(fx8 x)
Returns the largest integer less than or equal to the specified fixed-point number.
Definition pico8.cpp:1143
u32 mousestatus()
Retrieves the current status of the mouse buttons.
Definition pico8.cpp:1123
fx8 min(fx8 x, fx8 y)
Returns the lesser of two fixed-point numbers.
Definition pico8.cpp:1155
void dprintenable(bool enable)
Enables or disables debug text output generated by dprint().
Definition pico8.cpp:896
void sprint(const std::string_view format,...)
Prints formatted text using sprites for rendering.
Definition pico8.cpp:862
fx8 mousex()
Retrieves the current X position of the mouse or touch input.
Definition pico8.cpp:1111
u8 fget(u8 sprite_index, u8 flag_index=0xff, u8 sprite_pattern_bank=0)
Retrieves attribute flags for a sprite or background (BG) pattern.
Definition pico8.cpp:950
void fset(u8 sprite_index, u8 flag_index=0xff, u8 value=0, u8 sprite_pattern_bank=0)
Sets attribute flags for a sprite or background (BG) pattern.
Definition pico8.cpp:934
u32 btn(Button button=BUTTON_ANY, u8 player=0)
Definition pico8.cpp:1035
void map(s16 upix, s16 vpix, BgIndex index=BG_0)
Draws the configured background layer at the specified pixel offset.
Definition pico8.cpp:979
void mapdraw(s16 upix, s16 vpix, BgIndex index=BG_0)
Alias for map() function to draw the configured background layer at a specified pixel offset.
Definition pico8.h:1073
void mapsetup(BgTiles wtile, BgTiles htile, std::optional< BgTilesPtr > tiles=std::nullopt, u8 uwrap=B8_PPU_BG_WRAP_CLAMP, u8 vwrap=B8_PPU_BG_WRAP_CLAMP, BgIndex index=BG_0)
Configures a background layer for the PPU.
Definition pico8.cpp:961
void print(std::string_view format,...)
Prints formatted text on the background layer.
Definition pico8.cpp:918
fx8 mid(fx8 first, fx8 second, fx8 third)
Returns the middle (median) value of three fixed-point numbers.
Definition pico8.cpp:1159
fx8 max(fx8 x, fx8 y)
Returns the greater of two fixed-point numbers.
Definition pico8.cpp:1151
Color
Represents the color palette for drawing operations.
Definition pico8.h:72
@ BLUE
Color index 12: Blue.
Definition pico8.h:85
@ YELLOW
Color index 10: Yellow.
Definition pico8.h:83
@ LIGHT_PEACH
Color index 15: Light Peach.
Definition pico8.h:88
@ LIGHT_GREY
Color index 6: Light Grey.
Definition pico8.h:79
@ ORANGE
Color index 9: Orange.
Definition pico8.h:82
@ DARK_GREY
Color index 5: Dark Grey.
Definition pico8.h:78
@ DARK_PURPLE
Color index 2: Dark Purple.
Definition pico8.h:75
@ CURRENT
Special value representing the current color.
Definition pico8.h:89
@ DARK_BLUE
Color index 1: Dark Blue.
Definition pico8.h:74
@ LAVENDER
Color index 13: Lavender.
Definition pico8.h:86
@ GREEN
Color index 11: Green.
Definition pico8.h:84
@ BLACK
Color index 0: Black.
Definition pico8.h:73
@ WHITE
Color index 7: White.
Definition pico8.h:80
@ BROWN
Color index 4: Brown.
Definition pico8.h:77
@ RED
Color index 8: Red.
Definition pico8.h:81
@ PINK
Color index 14: Pink.
Definition pico8.h:87
@ DARK_GREEN
Color index 3: Dark Green.
Definition pico8.h:76
const SprCursor & scursor(int x=0, int y=0, Color color=CURRENT, int z=0)
Sets the cursor position, color, and depth (Z-value) for printing text using sprites.
Definition pico8.cpp:853
fx8 cel(fx8 x)
Returns the smallest integer greater than or equal to the specified fixed-point number.
Definition pico8.cpp:1147
Represents a line segment in 2D space defined by two points.
Definition submath.h:327
Represents a triangle in 2D space using three points.
Definition submath.h:355
A structure for representing rectangles with fixed-point coordinates.
Definition submath.h:372
Represents the cursor state for background-based text rendering.
Definition pico8.h:820
int y
The y-coordinate in 8x8 TILE units.
Definition pico8.h:822
BgPal pal
The palette index for text rendering (default: BG_PAL_CURRENT).
Definition pico8.h:823
int x
The x-coordinate in 8x8 TILE units.
Definition pico8.h:821
void Reset()
Resets the cursor state to its default values.
Definition pico8.h:830
Represents the cursor state for sprite-based text rendering.
Definition pico8.h:703
int y
The y-coordinate in pixels (row position).
Definition pico8.h:705
Color color
The drawing color for text (default: CURRENT).
Definition pico8.h:706
int z
The depth (Z-value) for rendering order (default: 0).
Definition pico8.h:707
int x
The x-coordinate in pixels (column position).
Definition pico8.h:704
void Reset()
Resets the cursor state to its default values.
Definition pico8.h:714
Provides mathematical functions and utilities, primarily focused on fixed-point arithmetic.
fpm::fixed< std::int32_t, std::int64_t, 8 > fx8
Alias for fixed-point type with 8 fractional bits.
Definition submath.h:56
uint32_t qmod(uint32_t x, uint32_t N)
Computes the remainder of x divided by N using an optimized method.
Definition submath.cpp:1255
Debug tracing macros for logging and monitoring program execution.