Jo Engine 2026.11.6
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
67static __jo_force_inline void jo_set_background_sprite(const jo_img * const img, const short left, const short top)
68{
69 jo_vdp2_set_nbg1_image(img, left, top);
70}
71
76{
78}
79
80/*
81███╗ ███╗ ██████╗ ██╗ ██╗███████╗ ██╗ ███████╗ ██████╗ ██████╗ ███╗ ███╗
82████╗ ████║██╔═══██╗██║ ██║██╔════╝ ██║ ╚══███╔╝██╔═══██╗██╔═══██╗████╗ ████║
83██╔████╔██║██║ ██║██║ ██║█████╗ ████████╗ ███╔╝ ██║ ██║██║ ██║██╔████╔██║
84██║╚██╔╝██║██║ ██║╚██╗ ██╔╝██╔══╝ ██╔═██╔═╝ ███╔╝ ██║ ██║██║ ██║██║╚██╔╝██║
85██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗ ██████║ ███████╗╚██████╔╝╚██████╔╝██║ ╚═╝ ██║
86╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝
87
88*/
89
94static __jo_force_inline void jo_move_background(const int x, const int y)
95{
97}
98
103static __jo_force_inline void jo_zoom_background2(const float width_factor, const float height_factor)
104{
105 jo_vdp2_zoom_nbg1f(width_factor, height_factor);
106}
107
111static __jo_force_inline void jo_zoom_background(const float factor)
112{
113 jo_vdp2_zoom_nbg1f(factor, factor);
114}
115
116/*
117██████╗ █████╗ ███████╗██╗ ██████╗ ██████╗ ██████╗ █████╗ ██╗ ██╗██╗███╗ ██╗ ██████╗
118██╔══██╗██╔══██╗██╔════╝██║██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║ ██║██║████╗ ██║██╔════╝
119██████╔╝███████║███████╗██║██║ ██║ ██║██████╔╝███████║██║ █╗ ██║██║██╔██╗ ██║██║ ███╗
120██╔══██╗██╔══██║╚════██║██║██║ ██║ ██║██╔══██╗██╔══██║██║███╗██║██║██║╚██╗██║██║ ██║
121██████╔╝██║ ██║███████║██║╚██████╗ ██████╔╝██║ ██║██║ ██║╚███╔███╔╝██║██║ ╚████║╚██████╔╝
122╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
123*
124** ▲ ONLY WORKS IN BITMAP MODE
125*/
126
134static __jo_force_inline void jo_draw_background_line(int x0, int y0, int x1, int y1, const jo_color color)
135{
136 jo_vdp2_draw_bitmap_nbg1_line(x0, y0, x1, y1, color);
137}
138
146static __jo_force_inline void jo_draw_background_square(const int x, const int y, const short width, const short height, const jo_color color)
147{
148 jo_vdp2_draw_bitmap_nbg1_square(x, y, width, height, color);
149}
150
156static __jo_force_inline void jo_put_pixel_in_background(const int x, const int y, const jo_color color)
157{
158 jo_vdp2_put_pixel_bitmap_nbg1(x, y, color);
159}
160
168static __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)
169{
170 jo_vdp2_put_pixel_bitmap_nbg1_rgb(x, y, r, g, b);
171}
172
173/*
174██████╗ ██████╗ ██████╗ ██╗ █████╗ ███╗ ██╗███████╗███████╗
175╚════██╗██╔══██╗ ██╔══██╗██║ ██╔══██╗████╗ ██║██╔════╝██╔════╝
176 █████╔╝██║ ██║ ██████╔╝██║ ███████║██╔██╗ ██║█████╗ ███████╗
177 ╚═══██╗██║ ██║ ██╔═══╝ ██║ ██╔══██║██║╚██╗██║██╔══╝ ╚════██║
178██████╔╝██████╔╝ ██║ ███████╗██║ ██║██║ ╚████║███████╗███████║
179╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝
180** - Two planes are available: A and B
181** - Each plane is 512 x 512 size
182*/
183
188{
190 jo_set_default_background_color(background_color);
191}
192
197{
199 jo_set_default_background_color(background_color);
200}
201
209static __jo_force_inline void jo_background_3d_plane_a_img(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
210{
211 jo_vdp2_set_rbg0_plane_a_8bits_image(img, palette_id, repeat, vertical_flip);
212}
213
221static __jo_force_inline void jo_background_3d_plane_b_img(jo_img_8bits *img, int palette_id, bool repeat, bool vertical_flip)
222{
223 jo_vdp2_set_rbg0_plane_b_8bits_image(img, palette_id, repeat, vertical_flip);
224}
225
226
231static __jo_force_inline void jo_background_3d_plane_far_limit(const int max_zoom_out)
232{
233 jo_vdp2_set_rbg0_far_limit(max_zoom_out);
234}
235
241static __jo_force_inline void jo_background_3d_plane_a_draw(const bool use_scroll_format_matrix)
242{
243 jo_vdp2_draw_rbg0_plane_a(use_scroll_format_matrix);
244}
245
251static __jo_force_inline void jo_background_3d_plane_b_draw(const bool use_scroll_format_matrix)
252{
253 jo_vdp2_draw_rbg0_plane_b(use_scroll_format_matrix);
254}
255
264static __jo_force_inline void jo_background_3d_plane_b_draw_flat(const int x, const int y)
265{
267}
268
269
270/*
271██╗ ██╗ ██████╗ ██████╗ ██╗███████╗ ██████╗ ███╗ ██╗████████╗ █████╗ ██╗
272██║ ██║██╔═══██╗██╔══██╗██║╚══███╔╝██╔═══██╗████╗ ██║╚══██╔══╝██╔══██╗██║
273███████║██║ ██║██████╔╝██║ ███╔╝ ██║ ██║██╔██╗ ██║ ██║ ███████║██║
274██╔══██║██║ ██║██╔══██╗██║ ███╔╝ ██║ ██║██║╚██╗██║ ██║ ██╔══██║██║
275██║ ██║╚██████╔╝██║ ██║██║███████╗╚██████╔╝██║ ╚████║ ██║ ██║ ██║███████╗
276╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
277
278██╗ ██╗███╗ ██╗███████╗ ███████╗ ██████╗██████╗ ██████╗ ██╗ ██╗
279██║ ██║████╗ ██║██╔════╝ ██╔════╝██╔════╝██╔══██╗██╔═══██╗██║ ██║
280██║ ██║██╔██╗ ██║█████╗ ███████╗██║ ██████╔╝██║ ██║██║ ██║
281██║ ██║██║╚██╗██║██╔══╝ ╚════██║██║ ██╔══██╗██║ ██║██║ ██║
282███████╗██║██║ ╚████║███████╗ ███████║╚██████╗██║ ██║╚██████╔╝███████╗███████╗
283╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝
284
285▲ ONLY WORKS IF BACKGROUND IMAGE IS LOADED THROUH jo_set_background_8bits_sprite() ▲
286 OTHERWISE IT MAY GLITCH
287*/
288
291# define JO_SCROLL_TABLE_SIZE JO_NBG1_SCROLL_TABLE_SIZE
292
301
308
316
317#endif /* !__JO_BACKGROUND_H__ */
318
319/*
320** END OF FILE
321*/
static __jo_force_inline int * jo_enable_background_horizontal_line_scroll(void)
Enable horizontal line scroll effect.
Definition background.h:297
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:168
static __jo_force_inline void jo_disable_background_horizontal_line_scroll(void)
Disable horizontal line scroll effect.
Definition background.h:304
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:209
static __jo_force_inline void jo_disable_background_3d_plane(jo_color background_color)
Disable 3D planes.
Definition background.h:196
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:231
static __jo_force_inline void jo_zoom_background(const float factor)
Zoom background.
Definition background.h:111
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:103
static __jo_force_inline void jo_background_3d_plane_a_draw(const bool use_scroll_format_matrix)
Draw plane A.
Definition background.h:241
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:187
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:156
static __jo_force_inline void jo_background_3d_plane_b_draw(const bool use_scroll_format_matrix)
Draw plane B.
Definition background.h:251
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:312
static __jo_force_inline void jo_clear_background(const jo_color color)
Clear the background.
Definition background.h:75
static __jo_force_inline void jo_set_background_sprite(const jo_img *const img, const short left, const short top)
Add background sprite.
Definition background.h:67
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:146
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:134
static __jo_force_inline void jo_move_background(const int x, const int y)
Move background (scrolling).
Definition background.h:94
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:264
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:221
int height
Definition entity.h:4
#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:53
15 bits image struct
Definition types.h:242
8 bits image struct
Definition types.h:250
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.