SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
bmp.h
Go to the documentation of this file.
1
21
22#include "maths.h"
23#include "vdp.h"
24#include "pal.h"
25
26#ifndef _BMP_H_
27#define _BMP_H_
28
29
30#define BMP_PLANE_WIDTH_SFT planeWidthSft
31#define BMP_PLANE_HEIGHT_SFT planeHeightSft
36#define BMP_PLANE_WIDTH 64
41#define BMP_PLANE_HEIGHT 64
42
43#define BMP_TILE_WIDTH_SFT 5
48#define BMP_TILE_WIDTH (1 << BMP_TILE_WIDTH_SFT)
49#define BMP_TILE_WIDTH_MASK (BMP_TILE_WIDTH - 1)
54#define BMP_TILE_HEIGHT 20
55
56#define BMP_TILE_XOFFSET (((screenWidth >> 3) - BMP_TILE_WIDTH) / 2)
57#define BMP_TILE_YOFFSET (((screenHeight >> 3) - BMP_TILE_HEIGHT) / 2)
58
59#define BMP_XPIXPERTILE_SFT 3
60#define BMP_YPIXPERTILE_SFT 3
65#define BMP_XPIXPERTILE (1 << BMP_XPIXPERTILE_SFT)
70#define BMP_YPIXPERTILE (1 << BMP_YPIXPERTILE_SFT)
71#define BMP_XPIXPERTILE_MASK (BMP_XPIXPERTILE - 1)
72#define BMP_YPIXPERTILE_MASK (BMP_YPIXPERTILE - 1)
73
74#define BMP_WIDTH_SFT (BMP_TILE_WIDTH_SFT + BMP_XPIXPERTILE_SFT)
79#define BMP_WIDTH (1 << BMP_WIDTH_SFT)
84#define BMP_HEIGHT (BMP_TILE_HEIGHT * BMP_YPIXPERTILE)
85#define BMP_WIDTH_MASK (BMP_WIDTH - 1)
86
87#define BMP_PITCH_SFT (BMP_TILE_WIDTH_SFT + 2)
92#define BMP_PITCH (1 << BMP_PITCH_SFT)
93#define BMP_PITCH_MASK (BMP_PITCH - 1)
94
99#define BMP_GENBMP16_WIDTH(genbmp16) ((genbmp16)[0])
104#define BMP_GENBMP16_HEIGHT(genbmp16) ((genbmp16)[1])
109#define BMP_GENBMP16_PALETTE(genbmp16) (&((genbmp16)[2]))
114#define BMP_GENBMP16_IMAGE(genbmp16) (&((genbmp16)[18]))
115
119#define BMP_GETPIXEL(x, y) _Pragma("GCC error \"This method is deprecated, use BMP_getPixelFast(..) instead.\"")
123#define BMP_SETPIXEL(x, y, col) _Pragma("GCC error \"This method is deprecated, use BMP_setPixelFast(..) instead.\"")
124
125
126#define BMP_BASE_TILE_INDEX TILE_USER_INDEX
127
128#define BMP_FB0_TILE_INDEX BMP_BASE_TILE_INDEX
129#define BMP_FB1_TILE_INDEX (BMP_BASE_TILE_INDEX + (BMP_TILE_WIDTH * BMP_TILE_HEIGHT))
130
131#define BMP_FB0_END_TILE_INDEX (BMP_FB0_TILE_INDEX + (BMP_TILE_WIDTH * BMP_TILE_HEIGHT))
132#define BMP_FB1_END_TILE_INDEX (BMP_FB1_TILE_INDEX + (BMP_TILE_WIDTH * BMP_TILE_HEIGHT))
133#define BMP_END_TILE_INDEX BMP_FB1_END_TILE_INDEX
134
135#define BMP_BASE_ADDR (BMP_BASE_TILE_INDEX * 32)
136#define BMP_FB0_ADDR (BMP_FB0_TILE_INDEX * 32)
137#define BMP_FB1_ADDR (BMP_FB1_TILE_INDEX * 32)
138#define BMP_END_ADDR (BMP_END_TILE_INDEX * 32)
139
140
160typedef struct
161{
162 u16 compression;
163 u16 w;
164 u16 h;
165 const Palette *palette;
166 const u8 *image;
167} Bitmap;
168
179typedef struct
180{
181 Vect2D_s16 pt;
182 u16 col;
183} Pixel;
184
197typedef struct
198{
199 Vect2D_s16 pt1;
200 Vect2D_s16 pt2;
201 u16 col;
202} Line;
203
218typedef struct
219{
220 Vect2D_s16 pt1;
221 Vect2D_s16 pt2;
222 Vect2D_s16 pt3;
223 u16 col;
224} Triangle;
225
226
230extern u8 *bmp_buffer_read;
234extern u8 *bmp_buffer_write;
235
236
260void BMP_init(u16 double_buffer, VDPPlane plane, u16 palette, u16 priority);
267void BMP_end(void);
274void BMP_reset(void);
286void BMP_setBufferCopy(u16 value);
311u16 BMP_flip(u16 async);
312
317void BMP_clear(void);
318
345
346
367void BMP_waitFlipComplete(void);
368
380void BMP_drawText(const char *str, u16 x, u16 y);
392void BMP_clearText(u16 x, u16 y, u16 w);
400void BMP_clearTextLine(u16 y);
401
413void BMP_showFPS(u16 float_display, u16 x, u16 y);
414
427u8 BMP_getPixel(u16 x, u16 y);
455void BMP_setPixel(u16 x, u16 y, u8 col);
470void BMP_setPixelFast(u16 x, u16 y, u8 col);
483 void BMP_setPixels_V2D(const Vect2D_u16 *crd, u8 col, u16 num);
496 void BMP_setPixelsFast_V2D(const Vect2D_u16 *crd, u8 col, u16 num);
506 void BMP_setPixels(const Pixel *pixels, u16 num);
516 void BMP_setPixelsFast(const Pixel *pixels, u16 num);
517
565u16 BMP_drawPolygon(const Vect2D_s16 *pts, u16 num, u8 col);
566
587void BMP_drawBitmapData(const u8 *data, u16 x, u16 y, u16 w, u16 h, u32 pitch);
610bool BMP_drawBitmap(const Bitmap *bitmap, u16 x, u16 y, bool loadpal);
638bool BMP_drawBitmapScaled(const Bitmap *bitmap, u16 x, u16 y, u16 w, u16 h, bool loadpal);
639
644#define BMP_loadBitmapData(data, x, y, w, h, pitch) _Pragma("GCC error \"This method is deprecated, use BMP_drawBitmapData(..) instead.\"")
649#define BMP_loadBitmap(bitmap, x, y, loadpal) _Pragma("GCC error \"This method is deprecated, use BMP_drawBitmap(..) instead.\"")
654#define BMP_loadAndScaleBitmap(bitmap, x, y, w, h, loadpal) _Pragma("GCC error \"This method is deprecated, use BMP_drawBitmapScaled(..) instead.\"")
655
660#define BMP_getBitmapPalette(bitmap, pal) _Pragma("GCC error \"This method is deprecated, use bitmap->palette instead.\"")
661
686void BMP_scale(const u8 *src_buf, u16 src_wb, u16 src_h, u16 src_pitch, u8 *dst_buf, u16 dst_wb, u16 dst_h, u16 dst_pitch);
687
688
689#endif // _BMP_H_
690
u16 BMP_isPolygonCulled(const Vect2D_s16 *pts, u16 num)
Determine if the specified polygon is culled. The polygon points should be defined in clockwise orde...
void BMP_setPixelFast(u16 x, u16 y, u8 col)
Set pixel at specified position (fast version without bounds verification)
Definition bmp.c:372
u8 BMP_getPixel(u16 x, u16 y)
Get pixel at specified position (safe version with bounds verification)
Definition bmp.c:363
u16 BMP_hasFlipInProgess(void)
Return true (!= 0) if a flip operation is in progress.
Definition bmp.c:251
void BMP_clearText(u16 x, u16 y, u16 w)
Clear text in bitmap mode.
Definition bmp.c:298
void BMP_setPixel(u16 x, u16 y, u8 col)
Set pixel at specified position (safe version with bounds verification)
Definition bmp.c:382
void BMP_setPixelsFast(const Pixel *pixels, u16 num)
Set pixels from Pixel array (fast version without bounds verification)
bool BMP_drawBitmap(const Bitmap *bitmap, u16 x, u16 y, bool loadpal)
Draw a Genesis Bitmap.
Definition bmp.c:1100
u16 BMP_drawPolygon(const Vect2D_s16 *pts, u16 num, u8 col)
Draw a polygon. The polygon points should be defined in clockwise order. Use the BMP_isPolygonCulle...
bool BMP_drawBitmapScaled(const Bitmap *bitmap, u16 x, u16 y, u16 w, u16 h, bool loadpal)
Load and draw a Genesis Bitmap with specified dimension.
Definition bmp.c:1129
void BMP_setPixels(const Pixel *pixels, u16 num)
Set pixels from Pixel array (safe version with bounds verification)
void BMP_waitWhileFlipRequestPending(void)
Wait until no more flip request is pending.
Definition bmp.c:246
void BMP_drawBitmapData(const u8 *data, u16 x, u16 y, u16 w, u16 h, u32 pitch)
Draw the specified 4BPP bitmap data.
Definition bmp.c:1071
u16 BMP_clipLine(Line *l)
Clip the specified line so it fit in bitmap screen (0, 0, BMP_WIDTH, BMP_HEIGHT)
void BMP_setBufferCopy(u16 value)
Enable back buffer preservation.
Definition bmp.c:232
void BMP_setPixelsFast_V2D(const Vect2D_u16 *crd, u8 col, u16 num)
Set pixels from Vect2D array (fast version without bounds verification)
void BMP_waitFlipComplete(void)
Wait until the asynchronous flip operation is completed. Blit operation is the bitmap buffer transfe...
Definition bmp.c:258
void BMP_clear(void)
Clear bitmap buffer.
Definition bmp.c:332
void BMP_end(void)
End the software bitmap engine.
Definition bmp.c:113
void BMP_scale(const u8 *src_buf, u16 src_wb, u16 src_h, u16 src_pitch, u8 *dst_buf, u16 dst_wb, u16 dst_h, u16 dst_pitch)
Scale the specified source bitmap image to specified dimension.
Definition bmp.c:1160
void BMP_showFPS(u16 float_display, u16 x, u16 y)
Show the frame rate in bitmap mode.
Definition bmp.c:309
u8 * BMP_getReadPointer(u16 x, u16 y)
Get read pointer for specified pixel.
Definition bmp.c:345
void BMP_init(u16 double_buffer, VDPPlane plane, u16 palette, u16 priority)
Initialize the software bitmap engine.
Definition bmp.c:84
u8 BMP_getPixelFast(u16 x, u16 y)
Get pixel at specified position (fast version without bounds verification)
Definition bmp.c:353
void BMP_reset(void)
Reset the software bitmap engine.
Definition bmp.c:156
void BMP_setPixels_V2D(const Vect2D_u16 *crd, u8 col, u16 num)
Set pixels from Vect2D array (safe version with bounds verification)
void BMP_drawLine(Line *l)
Draw a line (no bounds verification). You can use BMP_clipLine(..) first to clip the line to view ran...
u8 * BMP_getWritePointer(u16 x, u16 y)
Get write pointer for specified pixel.
Definition bmp.c:338
void BMP_drawText(const char *str, u16 x, u16 y)
Draw text in bitmap mode.
Definition bmp.c:293
u16 BMP_flip(u16 async)
Flip bitmap buffer to screen.
Definition bmp.c:264
u16 BMP_hasFlipRequestPending(void)
Return true (!= 0) if a flip request is pending.
Definition bmp.c:239
void BMP_clearTextLine(u16 y)
Clear a line of text in bitmap mode.
Definition bmp.c:303
Mathematical methods.
Palette support (herited from vdp_pal.h unit)
Genesis 4bpp Bitmap structure definition. Use the unpackBitmap() method to unpack if compression is ...
Definition bmp.h:161
Line definition.
Definition bmp.h:198
Palette structure contains color data.
Definition pal.h:73
Pixel definition.
Definition bmp.h:180
Triangle definition.
Definition bmp.h:219
2D Vector structure - s16 type.
Definition maths.h:138
2D Vector structure - u16 type.
Definition maths.h:128
unsigned long u32
Definition types.h:105
unsigned short u16
Definition types.h:100
unsigned char u8
Definition types.h:95
VDP main.
VDPPlane
Type used to define on which plane to work (used by some methods).
Definition vdp.h:519