Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
background.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, 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*/
36
37#ifndef __JO_BACKGROUND_H__
38# define __JO_BACKGROUND_H__
39
40/*
41██████╗ ██████╗ █████╗ ██╗ ██╗ ██╗███╗ ███╗ █████╗ ██████╗ ███████╗
42██╔══██╗██╔══██╗██╔══██╗██║ ██║ ██║████╗ ████║██╔══██╗██╔════╝ ██╔════╝
43██║ ██║██████╔╝███████║██║ █╗ ██║ ██║██╔████╔██║███████║██║ ███╗█████╗
44██║ ██║██╔══██╗██╔══██║██║███╗██║ ██║██║╚██╔╝██║██╔══██║██║ ██║██╔══╝
45██████╔╝██║ ██║██║ ██║╚███╔███╔╝ ██║██║ ╚═╝ ██║██║ ██║╚██████╔╝███████╗
46╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
47
48*/
49
56static __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
66static __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
93static __jo_force_inline void jo_move_background(const int x, const int y)
94{
96}
97
102static __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
110static __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
133static __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
145static __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
155static __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
167static __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
208static __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
220static __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
225
230static __jo_force_inline void jo_background_3d_plane_far_limit(const int max_zoom_out)
231{
232 jo_vdp2_set_rbg0_far_limit(max_zoom_out);
233}
234
238static __jo_force_inline void jo_background_3d_plane_a_draw(const bool use_scroll_format_matrix)
239{
240 jo_vdp2_draw_rbg0_plane_a(use_scroll_format_matrix);
241}
242
246static __jo_force_inline void jo_background_3d_plane_b_draw(const bool use_scroll_format_matrix)
247{
248 jo_vdp2_draw_rbg0_plane_b(use_scroll_format_matrix);
249}
250
257static __jo_force_inline void jo_background_3d_plane_b_draw_flat(const int x, const int y)
258{
260}
261
262
263/*
264██╗ ██╗ ██████╗ ██████╗ ██╗███████╗ ██████╗ ███╗ ██╗████████╗ █████╗ ██╗
265██║ ██║██╔═══██╗██╔══██╗██║╚══███╔╝██╔═══██╗████╗ ██║╚══██╔══╝██╔══██╗██║
266███████║██║ ██║██████╔╝██║ ███╔╝ ██║ ██║██╔██╗ ██║ ██║ ███████║██║
267██╔══██║██║ ██║██╔══██╗██║ ███╔╝ ██║ ██║██║╚██╗██║ ██║ ██╔══██║██║
268██║ ██║╚██████╔╝██║ ██║██║███████╗╚██████╔╝██║ ╚████║ ██║ ██║ ██║███████╗
269╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
270
271██╗ ██╗███╗ ██╗███████╗ ███████╗ ██████╗██████╗ ██████╗ ██╗ ██╗
272██║ ██║████╗ ██║██╔════╝ ██╔════╝██╔════╝██╔══██╗██╔═══██╗██║ ██║
273██║ ██║██╔██╗ ██║█████╗ ███████╗██║ ██████╔╝██║ ██║██║ ██║
274██║ ██║██║╚██╗██║██╔══╝ ╚════██║██║ ██╔══██╗██║ ██║██║ ██║
275███████╗██║██║ ╚████║███████╗ ███████║╚██████╗██║ ██║╚██████╔╝███████╗███████╗
276╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝
277
278▲ ONLY WORKS IF BACKGROUND IMAGE IS LOADED THROUH jo_set_background_8bits_sprite() ▲
279 OTHERWISE IT MAY GLITCH
280*/
281
284# define JO_SCROLL_TABLE_SIZE JO_NBG1_SCROLL_TABLE_SIZE
285
294
301
309
310#endif /* !__JO_BACKGROUND_H__ */
311
312/*
313** END OF FILE
314*/
static __jo_force_inline int * jo_enable_background_horizontal_line_scroll(void)
Enable horizontal line scroll effect.
Definition background.h:290
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
static __jo_force_inline void jo_disable_background_horizontal_line_scroll(void)
Disable horizontal line scroll effect.
Definition background.h:297
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
static __jo_force_inline void jo_disable_background_3d_plane(jo_color background_color)
Disable 3D planes.
Definition background.h:195
static __jo_force_inline void jo_background_3d_plane_far_limit(const int max_zoom_out)
Hide the farthest part of the 3D planes (the background color is visible instead).
Definition background.h:230
static __jo_force_inline void jo_zoom_background(const float factor)
Zoom background.
Definition background.h:110
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
static __jo_force_inline void jo_background_3d_plane_a_draw(const bool use_scroll_format_matrix)
Draw plane A.
Definition background.h:238
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
static __jo_force_inline void jo_enable_background_3d_plane(jo_color background_color)
Enable 3D planes.
Definition background.h:186
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
static __jo_force_inline void jo_background_3d_plane_b_draw(const bool use_scroll_format_matrix)
Draw plane B.
Definition background.h:246
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:305
static __jo_force_inline void jo_clear_background(const jo_color color)
Clear the background.
Definition background.h:74
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
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
static __jo_force_inline void jo_move_background(const int x, const int y)
Move background (scrolling).
Definition background.h:93
static __jo_force_inline void jo_background_3d_plane_b_draw_flat(const int x, const int y)
Draw plane B as a flat image, without perspective: a sky behind the plane A (sea, ground).
Definition background.h:257
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
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
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
unsigned short jo_color
15 bits color type
Definition types.h:42
15 bits image struct
Definition types.h:231
8 bits image struct
Definition types.h:239
void jo_vdp2_set_rbg0_plane_a_8bits_image(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
Setup plane A.
void jo_vdp2_zoom_nbg1f(const float width_factor, const float height_factor)
Zoom NBG1 width and height independently.
void jo_vdp2_draw_rbg0_plane_b(const bool use_scroll_format_matrix)
Draw plane B.
void jo_vdp2_move_nbg1(const int x, const int y)
Move NBG1 (scrolling).
void jo_vdp2_draw_rbg0_plane_a(const bool use_scroll_format_matrix)
Draw plane A.
void jo_vdp2_enable_rbg0(void)
Enable 3D planes.
int * jo_vdp2_enable_nbg1_line_scroll(void)
Enable NBG1 horizontal line scroll effect.
void jo_vdp2_set_rbg0_far_limit(const int max_zoom_out)
Hide the farthest part of the 3D planes (the back screen is visible instead).
void jo_vdp2_set_rbg0_plane_b_8bits_image(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
Setup plane B.
void jo_vdp2_disable_rbg0(void)
Disable 3D planes.
void jo_vdp2_set_nbg1_image(const jo_img *const img, short left, short top)
Set NBG1 bitmap image.
void jo_vdp2_draw_rbg0_plane_b_flat(const int x, const int y)
Draw plane B as a flat image, without perspective: a sky behind the plane A (sea, ground).
void jo_vdp2_clear_bitmap_nbg1(const jo_color color)
Clear NBG1 bitmap.
void jo_vdp2_set_nbg1_8bits_image(jo_img_8bits *img, int palette_id, bool vertical_flip)
Add 8 bits NBG1 image.
void jo_set_default_background_color(const jo_color background_color)
Set default background color.
void jo_vdp2_disable_nbg1_line_scroll(void)
Disable NBG1 horizontal line scroll effect.
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.
void jo_vdp2_compute_nbg1_line_scroll(unsigned short offset)
Compute NBG1 horizontal line scroll effect using specific offset.