Jo Engine  2020.06.22
Jo Sega Saturn Engine
background.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
37 #ifndef __JO_BACKGROUND_H__
38 # define __JO_BACKGROUND_H__
39 
40 /*
41 ██████╗ ██████╗ █████╗ ██╗ ██╗ ██╗███╗ ███╗ █████╗ ██████╗ ███████╗
42 ██╔══██╗██╔══██╗██╔══██╗██║ ██║ ██║████╗ ████║██╔══██╗██╔════╝ ██╔════╝
43 ██║ ██║██████╔╝███████║██║ █╗ ██║ ██║██╔████╔██║███████║██║ ███╗█████╗
44 ██║ ██║██╔══██╗██╔══██║██║███╗██║ ██║██║╚██╔╝██║██╔══██║██║ ██║██╔══╝
45 ██████╔╝██║ ██║██║ ██║╚███╔███╔╝ ██║██║ ╚═╝ ██║██║ ██║╚██████╔╝███████╗
46 ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
47 
48 */
49 
56 static __jo_force_inline void jo_set_background_8bits_sprite(jo_img_8bits *img, int palette_id, bool vertical_flip)
57 {
58  jo_vdp2_set_nbg1_8bits_image(img, palette_id, vertical_flip);
59 }
60 
66 static __jo_force_inline void jo_set_background_sprite(const jo_img * const img, const unsigned short left, const unsigned short top)
67 {
68  jo_vdp2_set_nbg1_image(img, left, top);
69 }
70 
75 {
77 }
78 
79 /*
80 ███╗ ███╗ ██████╗ ██╗ ██╗███████╗ ██╗ ███████╗ ██████╗ ██████╗ ███╗ ███╗
81 ████╗ ████║██╔═══██╗██║ ██║██╔════╝ ██║ ╚══███╔╝██╔═══██╗██╔═══██╗████╗ ████║
82 ██╔████╔██║██║ ██║██║ ██║█████╗ ████████╗ ███╔╝ ██║ ██║██║ ██║██╔████╔██║
83 ██║╚██╔╝██║██║ ██║╚██╗ ██╔╝██╔══╝ ██╔═██╔═╝ ███╔╝ ██║ ██║██║ ██║██║╚██╔╝██║
84 ██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗ ██████║ ███████╗╚██████╔╝╚██████╔╝██║ ╚═╝ ██║
85 ╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝
86 
87 */
88 
93 static __jo_force_inline void jo_move_background(const int x, const int y)
94 {
95  jo_vdp2_move_nbg1(x, y);
96 }
97 
102 static __jo_force_inline void jo_zoom_background2(const float width_factor, const float height_factor)
103 {
104  jo_vdp2_zoom_nbg1f(width_factor, height_factor);
105 }
106 
110 static __jo_force_inline void jo_zoom_background(const float factor)
111 {
112  jo_vdp2_zoom_nbg1f(factor, factor);
113 }
114 
115 /*
116 ██████╗ █████╗ ███████╗██╗ ██████╗ ██████╗ ██████╗ █████╗ ██╗ ██╗██╗███╗ ██╗ ██████╗
117 ██╔══██╗██╔══██╗██╔════╝██║██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║ ██║██║████╗ ██║██╔════╝
118 ██████╔╝███████║███████╗██║██║ ██║ ██║██████╔╝███████║██║ █╗ ██║██║██╔██╗ ██║██║ ███╗
119 ██╔══██╗██╔══██║╚════██║██║██║ ██║ ██║██╔══██╗██╔══██║██║███╗██║██║██║╚██╗██║██║ ██║
120 ██████╔╝██║ ██║███████║██║╚██████╗ ██████╔╝██║ ██║██║ ██║╚███╔███╔╝██║██║ ╚████║╚██████╔╝
121 ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
122 *
123 ** ▲ ONLY WORKS IN BITMAP MODE
124 */
125 
133 static __jo_force_inline void jo_draw_background_line(int x0, int y0, int x1, int y1, const jo_color color)
134 {
135  jo_vdp2_draw_bitmap_nbg1_line(x0, y0, x1, y1, color);
136 }
137 
145 static __jo_force_inline void jo_draw_background_square(const int x, const int y, const short width, const short height, const jo_color color)
146 {
147  jo_vdp2_draw_bitmap_nbg1_square(x, y, width, height, color);
148 }
149 
155 static __jo_force_inline void jo_put_pixel_in_background(const int x, const int y, const jo_color color)
156 {
157  jo_vdp2_put_pixel_bitmap_nbg1(x, y, color);
158 }
159 
167 static __jo_force_inline void jo_put_pixel_in_background_rgb(const int x, const int y, unsigned char r, unsigned char g, unsigned char b)
168 {
169  jo_vdp2_put_pixel_bitmap_nbg1_rgb(x, y, r, g, b);
170 }
171 
172 /*
173 ██████╗ ██████╗ ██████╗ ██╗ █████╗ ███╗ ██╗███████╗███████╗
174 ╚════██╗██╔══██╗ ██╔══██╗██║ ██╔══██╗████╗ ██║██╔════╝██╔════╝
175  █████╔╝██║ ██║ ██████╔╝██║ ███████║██╔██╗ ██║█████╗ ███████╗
176  ╚═══██╗██║ ██║ ██╔═══╝ ██║ ██╔══██║██║╚██╗██║██╔══╝ ╚════██║
177 ██████╔╝██████╔╝ ██║ ███████╗██║ ██║██║ ╚████║███████╗███████║
178 ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝
179 ** - Two planes are available: A and B
180 ** - Each plane is 512 x 512 size
181 */
182 
187 {
189  jo_set_default_background_color(background_color);
190 }
191 
196 {
198  jo_set_default_background_color(background_color);
199 }
200 
208 static __jo_force_inline void jo_background_3d_plane_a_img(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
209 {
210  jo_vdp2_set_rbg0_plane_a_8bits_image(img, palette_id, repeat, vertical_flip);
211 }
212 
220 static __jo_force_inline void jo_background_3d_plane_b_img(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
221 {
222  jo_vdp2_set_rbg0_plane_b_8bits_image(img, palette_id, repeat, vertical_flip);
223 }
224 
228 static __jo_force_inline void jo_background_3d_plane_a_draw(const bool use_scroll_format_matrix)
229 {
230  jo_vdp2_draw_rbg0_plane_a(use_scroll_format_matrix);
231 }
232 
236 static __jo_force_inline void jo_background_3d_plane_b_draw(const bool use_scroll_format_matrix)
237 {
238  jo_vdp2_draw_rbg0_plane_b(use_scroll_format_matrix);
239 }
240 
241 /*
242 ██╗ ██╗ ██████╗ ██████╗ ██╗███████╗ ██████╗ ███╗ ██╗████████╗ █████╗ ██╗
243 ██║ ██║██╔═══██╗██╔══██╗██║╚══███╔╝██╔═══██╗████╗ ██║╚══██╔══╝██╔══██╗██║
244 ███████║██║ ██║██████╔╝██║ ███╔╝ ██║ ██║██╔██╗ ██║ ██║ ███████║██║
245 ██╔══██║██║ ██║██╔══██╗██║ ███╔╝ ██║ ██║██║╚██╗██║ ██║ ██╔══██║██║
246 ██║ ██║╚██████╔╝██║ ██║██║███████╗╚██████╔╝██║ ╚████║ ██║ ██║ ██║███████╗
247 ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
248 
249 ██╗ ██╗███╗ ██╗███████╗ ███████╗ ██████╗██████╗ ██████╗ ██╗ ██╗
250 ██║ ██║████╗ ██║██╔════╝ ██╔════╝██╔════╝██╔══██╗██╔═══██╗██║ ██║
251 ██║ ██║██╔██╗ ██║█████╗ ███████╗██║ ██████╔╝██║ ██║██║ ██║
252 ██║ ██║██║╚██╗██║██╔══╝ ╚════██║██║ ██╔══██╗██║ ██║██║ ██║
253 ███████╗██║██║ ╚████║███████╗ ███████║╚██████╗██║ ██║╚██████╔╝███████╗███████╗
254 ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝
255 
256 ▲ ONLY WORKS IF BACKGROUND IMAGE IS LOADED THROUH jo_set_background_8bits_sprite() ▲
257  OTHERWISE IT MAY GLITCH
258 */
259 
262 # define JO_SCROLL_TABLE_SIZE JO_NBG1_SCROLL_TABLE_SIZE
263 
269 {
271 }
272 
276 {
278 }
279 
284 {
286 }
287 
288 #endif /* !__JO_BACKGROUND_H__ */
289 
290 /*
291 ** END OF FILE
292 */
jo_vdp2_draw_bitmap_nbg1_square
static __jo_force_inline void jo_vdp2_draw_bitmap_nbg1_square(const int x, const int y, const short width, const short height, const jo_color color)
Draw a square on NBG1.
Definition: vdp2.h:306
jo_zoom_background
static __jo_force_inline void jo_zoom_background(const float factor)
Zoom background.
Definition: background.h:110
jo_clear_background
static __jo_force_inline void jo_clear_background(const jo_color color)
Clear the background.
Definition: background.h:74
jo_vdp2_zoom_nbg1f
static __jo_force_inline void jo_vdp2_zoom_nbg1f(const float width_factor, const float height_factor)
Zoom NBG1 width and height independently.
Definition: vdp2.h:217
jo_draw_background_line
static __jo_force_inline void jo_draw_background_line(int x0, int y0, int x1, int y1, const jo_color color)
Draw a line using Bresenham's line algorithm.
Definition: background.h:133
jo_vdp2_enable_nbg1_line_scroll
int * jo_vdp2_enable_nbg1_line_scroll(void)
Enable NBG1 horizontal line scroll effect.
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
jo_vdp2_set_nbg1_8bits_image
void jo_vdp2_set_nbg1_8bits_image(jo_img_8bits *img, int palette_id, bool vertical_flip)
Add 8 bits NBG1 image.
jo_background_3d_plane_b_draw
static __jo_force_inline void jo_background_3d_plane_b_draw(const bool use_scroll_format_matrix)
Draw plane A.
Definition: background.h:236
jo_disable_background_horizontal_line_scroll
static __jo_force_inline void jo_disable_background_horizontal_line_scroll(void)
Disable horizontal line scroll effect.
Definition: background.h:275
jo_vdp2_draw_rbg0_plane_b
static __jo_force_inline void jo_vdp2_draw_rbg0_plane_b(const bool use_scroll_format_matrix)
Draw plane A.
Definition: vdp2.h:384
jo_disable_background_3d_plane
static __jo_force_inline void jo_disable_background_3d_plane(jo_color background_color)
Disable 3D planes.
Definition: background.h:195
jo_vdp2_compute_nbg1_line_scroll
void jo_vdp2_compute_nbg1_line_scroll(unsigned short offset)
Compute NBG1 horizontal line scroll effect using specific offset.
jo_vdp2_disable_nbg1_line_scroll
void jo_vdp2_disable_nbg1_line_scroll(void)
Disable NBG1 horizontal line scroll effect.
jo_set_default_background_color
void jo_set_default_background_color(const jo_color background_color)
Set default background color.
jo_set_background_sprite
static __jo_force_inline void jo_set_background_sprite(const jo_img *const img, const unsigned short left, const unsigned short top)
Add background sprite.
Definition: background.h:66
jo_vdp2_draw_bitmap_nbg1_line
void jo_vdp2_draw_bitmap_nbg1_line(int x0, int y0, int x1, int y1, const jo_color color)
Draw a NBG1 line using Bresenham's line algorithm.
jo_set_background_8bits_sprite
static __jo_force_inline void jo_set_background_8bits_sprite(jo_img_8bits *img, int palette_id, bool vertical_flip)
Add 8 bits background sprite.
Definition: background.h:56
jo_vdp2_disable_rbg0
void jo_vdp2_disable_rbg0(void)
Disable 3D planes.
jo_color
unsigned short jo_color
15 bits color type
Definition: types.h:39
jo_vdp2_move_nbg1
static __jo_force_inline void jo_vdp2_move_nbg1(const int x, const int y)
Move NBG1 (scrolling)
Definition: vdp2.h:203
jo_img_8bits
8 bits image struct
Definition: types.h:215
jo_background_3d_plane_b_img
static __jo_force_inline void jo_background_3d_plane_b_img(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
Setup plane B.
Definition: background.h:220
jo_enable_background_horizontal_line_scroll
static __jo_force_inline int * jo_enable_background_horizontal_line_scroll(void)
Enable horizontal line scroll effect.
Definition: background.h:268
jo_vdp2_draw_rbg0_plane_a
static __jo_force_inline void jo_vdp2_draw_rbg0_plane_a(const bool use_scroll_format_matrix)
Draw plane A.
Definition: vdp2.h:376
jo_vdp2_set_nbg1_image
void jo_vdp2_set_nbg1_image(const jo_img *const img, const unsigned short left, const unsigned short top)
Set NBG1 bitmap image.
jo_put_pixel_in_background_rgb
static __jo_force_inline void jo_put_pixel_in_background_rgb(const int x, const int y, unsigned char r, unsigned char g, unsigned char b)
Put pixel in background using composite color.
Definition: background.h:167
jo_vdp2_set_rbg0_plane_a_8bits_image
void jo_vdp2_set_rbg0_plane_a_8bits_image(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
Setup plane A.
jo_vdp2_put_pixel_bitmap_nbg1
static __jo_force_inline void jo_vdp2_put_pixel_bitmap_nbg1(const int x, const int y, const jo_color color)
Put pixel in NBG1 using color.
Definition: vdp2.h:319
jo_zoom_background2
static __jo_force_inline void jo_zoom_background2(const float width_factor, const float height_factor)
Zoom background width and height independently.
Definition: background.h:102
jo_draw_background_square
static __jo_force_inline void jo_draw_background_square(const int x, const int y, const short width, const short height, const jo_color color)
Draw a square on the background.
Definition: background.h:145
jo_background_3d_plane_a_img
static __jo_force_inline void jo_background_3d_plane_a_img(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
Setup plane A.
Definition: background.h:208
jo_put_pixel_in_background
static __jo_force_inline void jo_put_pixel_in_background(const int x, const int y, const jo_color color)
Put pixel in background using color.
Definition: background.h:155
jo_vdp2_clear_bitmap_nbg1
void jo_vdp2_clear_bitmap_nbg1(const jo_color color)
Clear NBG1 bitmap.
jo_enable_background_3d_plane
static __jo_force_inline void jo_enable_background_3d_plane(jo_color background_color)
Enable 3D planes.
Definition: background.h:186
jo_vdp2_put_pixel_bitmap_nbg1_rgb
static __jo_force_inline void jo_vdp2_put_pixel_bitmap_nbg1_rgb(const int x, const int y, unsigned char r, unsigned char g, unsigned char b)
Put pixel in NBG1 using composite color.
Definition: vdp2.h:331
jo_vdp2_enable_rbg0
void jo_vdp2_enable_rbg0(void)
Enable 3D planes.
jo_img
15 bits image struct
Definition: types.h:207
jo_move_background
static __jo_force_inline void jo_move_background(const int x, const int y)
Move background (scrolling)
Definition: background.h:93
jo_background_3d_plane_a_draw
static __jo_force_inline void jo_background_3d_plane_a_draw(const bool use_scroll_format_matrix)
Draw plane A.
Definition: background.h:228
jo_compute_background_horizontal_line_scroll
static __jo_force_inline void jo_compute_background_horizontal_line_scroll(unsigned short offset)
Compute horizontal line scroll effect using specific offset.
Definition: background.h:283
jo_vdp2_set_rbg0_plane_b_8bits_image
void jo_vdp2_set_rbg0_plane_b_8bits_image(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
Setup plane B.