KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
video.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  dc/video.h
4  Copyright (C) 2001 Anders Clerwall (scav)
5 
6 */
7 
8 /** \file dc/video.h
9  \brief Functions related to video output.
10 
11  This file deals with the video output hardware in the Dreamcast. There are
12  functions defined herein that deal with setting up the video hardware,
13  defining the resolution of the display, dealing with the framebuffer, etc.
14 
15  \author Anders Clerwall
16  \author Dan Potter
17 */
18 
19 #ifndef __DC_VIDEO_H
20 #define __DC_VIDEO_H
21 
22 #include <sys/cdefs.h>
23 __BEGIN_DECLS
24 
25 #include <arch/types.h>
26 
27 /** \defgroup vid_ctype Video Cable types
28 
29  The vid_check_cable() function will return one of this set of values to let
30  you know what type of cable is connected to the Dreamcast. These are also
31  used in the video mode settings to limit modes to certain cable types.
32 
33  @{
34 */
35 #define CT_ANY -1 /**< \brief Any cable type. Used only internally. */
36 #define CT_VGA 0 /**< \brief VGA Box */
37 #define CT_NONE 1 /**< \brief Nothing connected */
38 #define CT_RGB 2 /**< \brief RGB/SCART cable */
39 #define CT_COMPOSITE 3 /**< \brief Composite cable or RF switch */
40 /** @} */
41 
42 /** \defgroup vid_pmode Video pixel modes
43 
44  This set of constants control the pixel mode that the framebuffer is set to.
45 
46  @{
47 */
48 #define PM_RGB555 0 /**< \brief RGB555 pixel mode (15-bit) */
49 #define PM_RGB565 1 /**< \brief RGB565 pixel mode (16-bit) */
50 #define PM_RGB888 3 /**< \brief RGB888 pixel mode (24-bit) */
51 /** @} */
52 
53 /** \brief Generic display modes */
54 enum {
55  DM_GENERIC_FIRST = 0x1000, /**< \brief First valid generic mode */
56  DM_320x240 = 0x1000, /**< \brief 320x240 resolution */
57  DM_640x480, /**< \brief 640x480 resolution */
58  DM_800x608, /**< \brief 800x608 resolution */
59  DM_256x256, /**< \brief 256x256 resolution */
60  DM_768x480, /**< \brief 768x480 resolution */
61  DM_768x576, /**< \brief 768x576 resolution */
62  DM_GENERIC_LAST = DM_768x576 /**< \brief Last valid generic mode */
63 };
64 
65 /** \brief Multi-buffered mode setting.
66 
67  OR this with the generic mode to get four framebuffers instead of one.
68 */
69 #define DM_MULTIBUFFER 0x2000
70 
71 //-----------------------------------------------------------------------------
72 // More specific modes (and actual indeces into the mode table)
73 
74 /** \brief Specific display modes */
75 enum {
76  DM_INVALID = 0, /**< \brief Invalid display mode */
77  // Valid modes below
78  DM_320x240_VGA = 1, /**< \brief 320x240 VGA 60Hz */
79  DM_320x240_NTSC, /**< \brief 320x240 NTSC 60Hz */
80  DM_640x480_VGA, /**< \brief 640x480 VGA 60Hz */
81  DM_640x480_NTSC_IL, /**< \brief 640x480 NTSC Interlaced 60Hz */
82  DM_800x608_VGA, /**< \brief 800x608 VGA 60Hz */
83  DM_640x480_PAL_IL, /**< \brief 640x480 PAL Interlaced 50Hz */
84  DM_256x256_PAL_IL, /**< \brief 256x256 PAL Interlaced 50Hz */
85  DM_768x480_NTSC_IL, /**< \brief 768x480 NTSC Interlaced 60Hz */
86  DM_768x576_PAL_IL, /**< \brief 768x576 PAL Interlaced 50Hz */
87  DM_768x480_PAL_IL, /**< \brief 768x480 PAL Interlaced 50Hz */
88  DM_320x240_PAL, /**< \brief 320x240 PAL 50Hz */
89  DM_320x240_VGA_MB, /**< \brief 320x240 VGA 60Hz, 4FBs */
90  DM_320x240_NTSC_MB, /**< \brief 320x240 NTSC 60Hz, 4FBs */
91  DM_640x480_VGA_MB, /**< \brief 640x480 VGA 60Hz, 4FBs */
92  DM_640x480_NTSC_IL_MB, /**< \brief 640x480 NTSC IL 60Hz, 4FBs */
93  DM_800x608_VGA_MB, /**< \brief 800x608 VGA 60Hz, 4FBs */
94  DM_640x480_PAL_IL_MB, /**< \brief 640x480 PAL IL 50Hz, 4FBs */
95  DM_256x256_PAL_IL_MB, /**< \brief 256x256 PAL IL 50Hz, 4FBs */
96  DM_768x480_NTSC_IL_MB, /**< \brief 768x480 NTSC IL 60Hz, 4FBs */
97  DM_768x576_PAL_IL_MB, /**< \brief 768x576 PAL IL 50Hz, 4FBs */
98  DM_768x480_PAL_IL_MB, /**< \brief 768x480 PAL IL 50Hz, 4FBs */
99  DM_320x240_PAL_MB, /**< \brief 320x240 PAL 50Hz, 4FBs */
100  // The below is only for counting..
101  DM_SENTINEL, /**< \brief Sentinel value, for counting */
102  DM_MODE_COUNT /**< \brief Number of modes */
103 };
104 
105 /** \brief The maximum number of framebuffers available. */
106 #define VID_MAX_FB 4 // <-- This should be enough
107 
108 // These are for the "flags" field of "vid_mode_t"
109 /** \defgroup vid_flags Flags for the field in vid_mode_t.
110 
111  These flags indicate various things related to the modes for a vid_mode_t.
112 
113  @{
114 */
115 #define VID_INTERLACE 0x00000001 /**< \brief Interlaced display */
116 #define VID_LINEDOUBLE 0x00000002 /**< \brief Display each scanline twice */
117 #define VID_PIXELDOUBLE 0x00000004 /**< \brief Display each pixel twice */
118 #define VID_PAL 0x00000008 /**< \brief 50Hz refresh rate, if not VGA */
119 /** @} */
120 
121 /** \brief Video mode structure.
122 
123  KOS maintains a list of valid video modes internally that correspond to the
124  specific display modes enumeration. Each of them is built of one of these.
125 
126  \headerfile dc/video.h
127 */
128 typedef struct vid_mode {
129  int generic; /**< \brief Generic mode type for vid_set_mode() */
130  uint16 width; /**< \brief Width of the display, in pixels */
131  uint16 height; /**< \brief Height of the display, in pixels */
132  uint32 flags; /**< \brief Combination of one or more VID_* flags */
133 
134  int16 cable_type; /**< \brief Allowed cable type */
135  uint16 pm; /**< \brief Pixel mode */
136 
137  uint16 scanlines; /**< \brief Number of scanlines */
138  uint16 clocks; /**< \brief Clocks per scanline */
139  uint16 bitmapx; /**< \brief Bitmap window X position */
140  uint16 bitmapy; /**< \brief Bitmap window Y position (automatically
141  increased for PAL) */
142  uint16 scanint1; /**< \brief First scanline interrupt position */
143  uint16 scanint2; /**< \brief Second scanline interrupt position
144  (automatically doubled for VGA) */
145  uint16 borderx1; /**< \brief Border X starting position */
146  uint16 borderx2; /**< \brief Border X stop position */
147  uint16 bordery1; /**< \brief Border Y starting position */
148  uint16 bordery2; /**< \brief Border Y stop position */
149 
150  uint16 fb_curr; /**< \brief Current framebuffer */
151  uint16 fb_count; /**< \brief Number of framebuffers */
152  uint32 fb_base[VID_MAX_FB]; /**< \brief Offset to framebuffers */
153 } vid_mode_t;
154 
155 /** \brief The list of builtin video modes. Do not modify these! */
157 
158 /** \brief The current video mode. Do not modify directly! */
159 extern vid_mode_t *vid_mode;
160 
161 // These point to the current drawing area. If you're not using a multi-buffered
162 // mode, that means they do what KOS always used to do (they'll point at the
163 // start of VRAM). If you're using a multi-buffered mode, they'll point at the
164 // next framebuffer to be displayed. You must use vid_flip for this to work
165 // though (if you use vid_set_start, they'll point at the display base, for
166 // compatibility's sake).
167 
168 /** \brief 16-bit size pointer to the current drawing area. */
169 extern uint16 *vram_s;
170 
171 /** \brief 32-bit size pointer to the current drawing area. */
172 extern uint32 *vram_l;
173 
174 
175 /** \brief Retrieve the connected video cable type.
176 
177  This function checks the video cable and reports what it finds.
178 
179  \retval CT_VGA If a VGA Box or cable is connected.
180  \retval CT_NONE If nothing is connected.
181  \retval CT_RGB If a RGB/SCART cable is connected.
182  \retval CT_COMPOSITE If a composite cable or RF switch is connected.
183 */
184 int vid_check_cable();
185 
186 /** \brief Set the VRAM base of the framebuffer.
187 
188  This function sets the vram_s and vram_l pointsers to specified offset
189  within VRAM and sets the start position of the framebuffer to the same
190  offset.
191 
192  \param base The offset within VRAM to set the base to.
193 */
194 void vid_set_start(uint32 base);
195 
196 /** \brief Set the current framebuffer in a multibuffered setup.
197 
198  This function sets the displayed framebuffer to the specified buffer and
199  sets the vram_s and vram_l pointers to point at the next framebuffer, to
200  allow for tearing-free framebuffer-direct drawing.
201 
202  \param fb The framebuffer to display (or -1 for the next one).
203 */
204 void vid_flip(int fb);
205 
206 /** \brief Set the border color of the display.
207 
208  This sets the color of the border area of the display. On some screens, the
209  border area may not be shown at all, whereas on some displays you may see
210  the whole thing.
211 
212  \param r The red value of the color (0-255).
213  \param g The green value of the color (0-255).
214  \param b The blue value of the color (0-255).
215  \return Old border color value (RGB888)
216 */
217 uint32 vid_border_color(int r, int g, int b);
218 
219 /** \brief Clear the display.
220 
221  This function sets the whole display to the specified color. Internally,
222  this uses the store queues to actually clear the display entirely.
223 
224  \param r The red value of the color (0-255).
225  \param g The green value of the color (0-255).
226  \param b The blue value of the color (0-255).
227 */
228 void vid_clear(int r, int g, int b);
229 
230 /** \brief Clear VRAM.
231 
232  This function is essentially a memset() for the whole of VRAM that will
233  clear it all to 0 bytes.
234 */
235 void vid_empty();
236 
237 /** \brief Wait for VBlank.
238 
239  This function busy loops until the vertical blanking period starts.
240 */
241 void vid_waitvbl();
242 
243 /** \brief Set the video mode.
244 
245  This function sets the current video mode to the one specified by the
246  parameters.
247 
248  \param dm The display mode to use. One of the DM_* values.
249  \param pm The pixel mode to use. One of the PM_* values.
250 */
251 void vid_set_mode(int dm, int pm);
252 
253 /** \brief Set the video mode.
254 
255  This function sets the current video mode to the mode structure passed in.
256  You can use this to add support to your program for modes that KOS doesn't
257  have support for built-in (of course, you should tell us the settings so we
258  can add them into KOS if you do this).
259 
260  \param mode A filled in vid_mode_t for the mode wanted.
261 */
262 void vid_set_mode_ex(vid_mode_t *mode);
263 
264 /** \brief Initialize the video system.
265 
266  This function initializes the video display, setting the mode to the
267  specified parameters, clearing vram, and setting the first framebuffer as
268  active.
269 
270  \param disp_mode The display mode to use. One of the DM_* values.
271  \param pixel_mode The pixel mode to use. One of the PM_* values.
272 */
273 void vid_init(int disp_mode, int pixel_mode);
274 
275 /** \brief Shut down the video system.
276 
277  This function reinitializes the video system to what dcload and friends
278  expect it to be.
279 */
280 void vid_shutdown();
281 
282 /** \brief Take a screenshot.
283 
284  This function takes the current framebuffer (vram_s/vram_l) and dumps it out
285  to a PPM file.
286 
287  \param destfn The filename to save to.
288  \return 0 on success, <0 on failure.
289 */
290 int vid_screen_shot(const char * destfn);
291 
292 __END_DECLS
293 
294 #endif // __DC_VIDEO_H
295 
640x480 resolution
Definition: video.h:57
Last valid generic mode.
Definition: video.h:62
#define VID_MAX_FB
The maximum number of framebuffers available.
Definition: video.h:106
void vid_empty()
Clear VRAM.
void vid_flip(int fb)
Set the current framebuffer in a multibuffered setup.
uint16 borderx1
Border X starting position.
Definition: video.h:145
uint16 bordery2
Border Y stop position.
Definition: video.h:148
uint32 * vram_l
32-bit size pointer to the current drawing area.
320x240 resolution
Definition: video.h:56
Common integer types.
uint32 flags
Combination of one or more VID_* flags.
Definition: video.h:132
int vid_screen_shot(const char *destfn)
Take a screenshot.
void vid_waitvbl()
Wait for VBlank.
768x480 NTSC Interlaced 60Hz
Definition: video.h:85
vid_mode_t vid_builtin[DM_MODE_COUNT]
The list of builtin video modes. Do not modify these!
256x256 PAL Interlaced 50Hz
Definition: video.h:84
Invalid display mode.
Definition: video.h:76
void vid_set_mode(int dm, int pm)
Set the video mode.
768x576 PAL Interlaced 50Hz
Definition: video.h:86
uint16 width
Width of the display, in pixels.
Definition: video.h:130
void vid_set_mode_ex(vid_mode_t *mode)
Set the video mode.
800x608 VGA 60Hz, 4FBs
Definition: video.h:93
uint32 vid_border_color(int r, int g, int b)
Set the border color of the display.
uint16 bitmapx
Bitmap window X position.
Definition: video.h:139
800x608 resolution
Definition: video.h:58
uint16 scanint2
Second scanline interrupt position (automatically doubled for VGA)
Definition: video.h:143
uint16 height
Height of the display, in pixels.
Definition: video.h:131
320x240 PAL 50Hz
Definition: video.h:88
uint16 clocks
Clocks per scanline.
Definition: video.h:138
uint16 bitmapy
Bitmap window Y position (automatically increased for PAL)
Definition: video.h:140
768x480 PAL Interlaced 50Hz
Definition: video.h:87
640x480 NTSC Interlaced 60Hz
Definition: video.h:81
768x480 NTSC IL 60Hz, 4FBs
Definition: video.h:96
uint16 bordery1
Border Y starting position.
Definition: video.h:147
Number of modes.
Definition: video.h:102
uint16 fb_curr
Current framebuffer.
Definition: video.h:150
short int16
16-bit signed integer
Definition: types.h:33
768x480 resolution
Definition: video.h:60
unsigned short uint16
16-bit unsigned integer
Definition: types.h:29
void vid_init(int disp_mode, int pixel_mode)
Initialize the video system.
uint16 pm
Pixel mode.
Definition: video.h:135
uint16 fb_count
Number of framebuffers.
Definition: video.h:151
320x240 PAL 50Hz, 4FBs
Definition: video.h:99
640x480 VGA 60Hz
Definition: video.h:80
uint16 borderx2
Border X stop position.
Definition: video.h:146
640x480 PAL Interlaced 50Hz
Definition: video.h:83
320x240 NTSC 60Hz
Definition: video.h:79
void vid_clear(int r, int g, int b)
Clear the display.
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
640x480 NTSC IL 60Hz, 4FBs
Definition: video.h:92
320x240 VGA 60Hz, 4FBs
Definition: video.h:89
First valid generic mode.
Definition: video.h:55
320x240 VGA 60Hz
Definition: video.h:78
768x576 PAL IL 50Hz, 4FBs
Definition: video.h:97
struct vid_mode vid_mode_t
Video mode structure.
void vid_shutdown()
Shut down the video system.
vid_mode_t * vid_mode
The current video mode. Do not modify directly!
uint16 scanint1
First scanline interrupt position.
Definition: video.h:142
768x480 PAL IL 50Hz, 4FBs
Definition: video.h:98
uint16 * vram_s
16-bit size pointer to the current drawing area.
int vid_check_cable()
Retrieve the connected video cable type.
256x256 resolution
Definition: video.h:59
uint32 fb_base[VID_MAX_FB]
Offset to framebuffers.
Definition: video.h:152
640x480 PAL IL 50Hz, 4FBs
Definition: video.h:94
640x480 VGA 60Hz, 4FBs
Definition: video.h:91
int16 cable_type
Allowed cable type.
Definition: video.h:134
void vid_set_start(uint32 base)
Set the VRAM base of the framebuffer.
Sentinel value, for counting.
Definition: video.h:101
256x256 PAL IL 50Hz, 4FBs
Definition: video.h:95
Video mode structure.
Definition: video.h:128
320x240 NTSC 60Hz, 4FBs
Definition: video.h:90
uint16 scanlines
Number of scanlines.
Definition: video.h:137
768x576 resolution
Definition: video.h:61
800x608 VGA 60Hz
Definition: video.h:82