Jo Engine  9
Jo Sega Saturn Engine
background.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2017, 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 */
35 #ifndef __JO_BACKGROUND_H__
36 # define __JO_BACKGROUND_H__
37 
38 /*
39 ** Background (VDP2)
40 */
41 
49 void jo_draw_background_line(int x0, int y0, int x1, int y1, const jo_color color);
50 
56 static __jo_force_inline void jo_put_pixel_in_background(const int x, const int y, const jo_color color)
57 {
58  *(((unsigned short *)VDP2_VRAM_A0) + x + y * JO_VDP2_WIDTH) = color;
59 }
60 
68 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)
69 {
70  jo_put_pixel_in_background(x, y, C_RGB(r, g, b));
71 }
72 
77 static __jo_force_inline void jo_move_background(const int x, const int y)
78 {
79 #if JO_COMPILE_USING_SGL
81 #else
82  JO_VDP2_SCXIN1 = x;
83  JO_VDP2_SCYIN1 = y;
84 #endif
85 }
86 
91 static __jo_force_inline void jo_zoom_background2(const float width_factor, const float height_factor)
92 {
93 #if JO_COMPILE_USING_SGL
94  slZoomNbg1(toFIXED(width_factor), toFIXED(height_factor));
95 #else
96  int fixed_width = jo_float2fixed(width_factor);
97  int fixed_height = jo_float2fixed(height_factor);
98  JO_VDP2_ZMXIN1 = JO_DIV_BY_32768(fixed_width);
99  JO_VDP2_ZMYIN1 = JO_DIV_BY_32768(fixed_height);
100  JO_VDP2_ZMXDN1 = (fixed_width % 32768) * 2; /*TODO : fix x2 */
101  JO_VDP2_ZMYDN1 = (fixed_height % 32768) * 2;
102 #endif
103 }
104 
108 static __jo_force_inline void jo_zoom_background(const float factor)
109 {
110  jo_zoom_background2(factor, factor);
111 }
112 
118 void jo_set_background_sprite(const jo_img * const img, const unsigned short left, const unsigned short top);
119 
123 void jo_clear_background(const jo_color color);
124 
132 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)
133 {
134  jo_draw_background_line(x, y, x + width, y, color);
135  jo_draw_background_line(x + width, y + height, x + width, y, color);
136  jo_draw_background_line(x, y + height, x + width, y + height, color);
137  jo_draw_background_line(x, y + height, x, y, color);
138 }
139 
140 #endif /* !__JO_BACKGROUND_H__ */
141 
142 /*
143 ** END OF FILE
144 */
#define JO_DIV_BY_32768(X)
Devide a variable by 32768.
Definition: math.h:160
#define JO_VDP2_ZMXIN1
Definition: sega_saturn.h:300
#define JO_VDP2_ZMXDN1
Definition: sega_saturn.h:301
unsigned short jo_color
15 bits color type
Definition: types.h:39
static __jo_force_inline int jo_float2fixed(const float x)
Convert float to jo engine fixed (avoid usage of GCC Soft Float)
Definition: math.h:243
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
15 bits image struct
Definition: image.h:44
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:68
#define C_RGB(r, g, b)
Definition: sgl_prototypes.h:75
#define JO_VDP2_WIDTH
VDP2 Background bitmap width.
Definition: conf.h:141
#define JO_VDP2_ZMYIN1
Definition: sega_saturn.h:302
void jo_set_background_sprite(const jo_img *const img, const unsigned short left, const unsigned short top)
Add background sprite.
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:91
void slScrPosNbg1(FIXED x, FIXED y)
#define JO_VDP2_SCXIN1
Definition: sega_saturn.h:296
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:132
#define VDP2_VRAM_A0
Definition: sgl_prototypes.h:48
#define JO_VDP2_SCYIN1
Definition: sega_saturn.h:298
#define toFIXED(a)
Definition: sgl_prototypes.h:70
static __jo_force_inline void jo_move_background(const int x, const int y)
Move background (scrolling)
Definition: background.h:77
#define JO_MULT_BY_65536(X)
Multiply a variable by 65536.
Definition: math.h:123
void jo_clear_background(const jo_color color)
Clear the background.
static __jo_force_inline void jo_zoom_background(const float factor)
Zoom background.
Definition: background.h:108
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:56
void slZoomNbg1(FIXED x, FIXED y)
#define JO_VDP2_ZMYDN1
Definition: sega_saturn.h:303
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.