1 /*
2  * ============================================================================
3  *  Title:
4  *  Author:   J. Zbiciak
5  * ============================================================================
6  *  GFX_INIT         -- Initializes a gfx_t object and gfx subsystem
7  *  GFX_TICK         -- Services a gfx_t tick
8  *  GFX_VID_ENABLE   -- Alert gfx that video has been enabled or blanked
9  * ============================================================================
10  *  GFX_PVT_T        -- Private internal state to gfx_t structure.
11  *  GFX_T            -- Generic graphics object.  The graphics object is a
12  *                      periph also so that screen updates, etc. can be
13  *                      scheduled via the global tick mechanism.
14  * ============================================================================
15  *  The graphics subsystem provides an abstraction layer between the
16  *  emulator and the graphics library being used.  Theoretically, this
17  *  should allow easy porting to other graphics libraries.
18  * ============================================================================
19  */
20 
21 #ifndef GFX_H_
22 #define GFX_H_
23 
24 #include "gfx/palette.h"    // for palette_t definition
25 
26 /* SDL-inspired flags */
27 #define GFX_DBLBUF (1 << 0)
28 #define GFX_SWSURF (1 << 1)
29 #define GFX_ASYNCB (1 << 2)
30 #define GFX_HWPAL  (1 << 3)
31 #define GFX_FULLSC (1 << 4)
32 
33 /* Dirty-rectangle inspired flags */
34 #define GFX_DRECTS (1 << 5)     /* enable dirty rectangles */
35 #define GFX_DRCMRG (1 << 6)     /* A clean rect can merge between 2 dirty */
36 
37 /* Other misc flags */
38 #define GFX_SKIP_EXTRA (1 << 7) /* Show at most 60 frames per wall-clock sec */
39 
40 /* Internal */
41 #define GFX_FAILOK (1 << 8)     /* Return -1 if setting a mode fails. */
42 
43 /*
44  * ============================================================================
45  *  GFX_PVT_T        -- Private internal state to gfx_t structure.
46  *  GFX_T            -- Generic graphics object.  The graphics object is a
47  *                      periph also so that screen updates, etc. can be
48  *                      scheduled via the global tick mechanism.
49  * ============================================================================
50  */
51 
52 struct avi_writer_t;    /* forward decl */
53 struct gfx_pvt_t;       /* forward decl */
54 struct mvi_t;           /* forward decl */
55 
56 typedef struct gfx_t
57 {
58     periph_t    periph;             /*  Yes, gfx_t is a peripheral.         */
59     uint8_t    *vid;                /*  Display bitmap (160x200x8bpp).      */
60     uint8_t     bbox[8][4];         /*  Bounding boxes for the 8 MOBs       */
61     int         dirty;              /*  FLAG: Display needs update.         */
62     uint32_t    drop_frame;         /*  while > 0 drop frames.              */
63     uint32_t    dropped_frames;     /*  counts dropped frames.              */
64     uint32_t    tot_frames;         /*  total frames                        */
65     uint32_t    tot_dropped_frames; /*  total dropped frames                */
66 
67     uint32_t    hidden;             /*  Visibility flag (set by event_t)    */
68     uint32_t    scrshot;            /*  Screen-shot/movie requested         */
69     uint32_t    toggle;             /*  Toggle full-screen / windowed       */
70 
71     int         b_color, b_dirty;   /*  Border color and dirty flag.        */
72     int         x_blank, y_blank;   /*  FLAG: Blank top row, left column.   */
73     int         x_delay, y_delay;   /*  X/Y display delay.                  */
74     bool        debug_blank;        /*  FLAG: If set, dim instead of blank  */
75 
76     bool        req_pause;          /*  We're requesting a 2-second pause.  */
77 
78     bool        movie_init;         /*  Is movie structure initialized?     */
79     struct mvi_t *movie;            /*  Pointer to mvi_t to reduce deps     */
80 
81     struct avi_writer_t *avi;       /*  Ptr to avi_write_t to reduce deps.  */
82     int         audio_rate;         /*  Ugh... only needed for AVI.         */
83     int         fps;                /*  Frame rate.                         */
84 
85     palette_t   palette;            /*  Current graphics palette.           */
86     struct gfx_pvt_t *pvt;          /*  Private data.                       */
87 } gfx_t;
88 
89 /*
90  * ============================================================================
91  *  GFX_CHECK         -- Validates graphics parameters
92  *  GFX_INIT          -- Initializes a gfx_t object and gfx subsystem
93  *  GFX_VID_ENABLE    -- Alert gfx that video has been enabled or blanked
94  * ============================================================================
95  */
96 enum
97 {
98     VID_DISABLED = 0,       /* Video disabled this frame                    */
99     VID_ENABLED  = 1,       /* Video enabled this frame                     */
100     VID_UNKNOWN  = 2        /* Unknown whether video is enabled this frame  */
101 };
102 
103 int      gfx_check       (int x, int y, int bpp, int prescale);
104 int      gfx_init        (gfx_t   *gfx,
105                           int desired_x, int desired_y, int desired_bpp,
106                           int flags, int verbose, int prescaler,
107                           int bord_x, int bord_y, int pal_mode,
108                           struct avi_writer_t *const avi, int audio_rate,
109                           const palette_t *const palette);
110 void     gfx_vid_enable  (gfx_t   *gfx, int enabled);
111 
112 /*
113  * ============================================================================
114  *  GFX_SET_BORD     -- Set the border / offset parameters for the display
115  * ============================================================================
116  */
117 void gfx_set_bord
118 (
119     gfx_t *gfx,         /*  Graphics object.                        */
120     int bord
121 );
122 
123 /*
124  * ============================================================================
125  *  GFX_SET_TITLE    -- Sets the window title
126  * ============================================================================
127  */
128 int gfx_set_title(gfx_t *gfx, const char *title);
129 
130 #define GFX_SHOT    (1 << 0)
131 #define GFX_MVTOG   (1 << 1)
132 #define GFX_MOVIE   (1 << 2)
133 #define GFX_RESET   (1 << 3)
134 #define GFX_AVTOG   (1 << 4)
135 #define GFX_AVI     (1 << 5)
136 
137 #define GFX_WIND_TOG  (1)   /* Toggle windowed / fullscreen */
138 #define GFX_WIND_ON   (2)   /* Go to windowed mode.         */
139 #define GFX_WIND_OFF  (3)   /* Go to fullscreen mode.       */
140 
141 /* ======================================================================== */
142 /*  GFX_TOGGLE_WINDOWED -- Try to toggle windowed vs. full-screen.          */
143 /* ======================================================================== */
144 bool gfx_toggle_windowed(gfx_t *gfx, int quiet);
145 
146 /* ======================================================================== */
147 /*  GFX_FORCE_WINDOWED -- Force display to be windowed mode; Returns 1 if   */
148 /*                        display was previously full-screen.               */
149 /* ======================================================================== */
150 int gfx_force_windowed(gfx_t *gfx, int quiet);
151 
152 /* ======================================================================== */
153 /*  GFX_DIRTYRECT_SPEC_T    Details that drive the dirty rectangle routine  */
154 /* ======================================================================== */
155 typedef struct gfx_dirtyrect_spec
156 {
157     int active_first_x, active_last_x, x_step;
158     int active_first_y, active_last_y, y_step;
159 
160     int pitch;
161 
162     int bord_first_x, bord_last_x;
163     int bord_first_y, bord_last_y;
164 } gfx_dirtyrect_spec;
165 
166 /* ======================================================================== */
167 /*  GFX_RESYNC   -- Resynchronize GFX internal state after a load.          */
168 /* ======================================================================== */
169 void gfx_resync(gfx_t *const gfx);
170 
171 /* ======================================================================== */
172 /*  GFX_MOVIE_IS_ACTIVE  -- Return whether we're recording an AVI/GIF, or   */
173 /*                          have a pending screenshot.                      */
174 /* ======================================================================== */
175 #define gfx_movie_is_active(g) \
176     (((g)->scrshot & \
177       (GFX_MOVIE | GFX_AVI | GFX_SHOT | GFX_MVTOG | GFX_AVTOG)) != 0)
178 
179 /* ======================================================================== */
180 /*  GFX_HIDDEN       -- Returns true if the graphics window is hidden.      */
181 /* ======================================================================== */
182 bool gfx_hidden(const gfx_t *const gfx);
183 
184 /* ======================================================================== */
185 /*  GFX_STIC_TICK    -- Called directly by STIC to sync video pipeline.     */
186 /* ======================================================================== */
187 void gfx_stic_tick(gfx_t *const gfx);
188 
189 /* ======================================================================== */
190 /*  GFX_REFRESH      -- Called when we just need to regenerate the video.   */
191 /* ======================================================================== */
192 void gfx_refresh(gfx_t *const gfx);
193 
194 /* ======================================================================== */
195 /*  GFX_SCRSHOT      -- Write a 320x200 screen shot to a GIF file.          */
196 /* ======================================================================== */
197 void gfx_scrshot(const gfx_t *const gfx);
198 
199 /* ======================================================================== */
200 /*  GFX_MOVIEUPD     -- Start/Stop/Update a movie in progress               */
201 /* ======================================================================== */
202 void gfx_movieupd(gfx_t *const gfx);
203 
204 /* ======================================================================== */
205 /*  GFX_AVIUPD       -- Start/Stop/Update an AVI in progress                */
206 /* ======================================================================== */
207 void gfx_aviupd(gfx_t *const gfx);
208 
209 #endif /* GFX_H_ */
210 
211 /* ======================================================================== */
212 /*  This program is free software; you can redistribute it and/or modify    */
213 /*  it under the terms of the GNU General Public License as published by    */
214 /*  the Free Software Foundation; either version 2 of the License, or       */
215 /*  (at your option) any later version.                                     */
216 /*                                                                          */
217 /*  This program is distributed in the hope that it will be useful,         */
218 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of          */
219 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       */
220 /*  General Public License for more details.                                */
221 /*                                                                          */
222 /*  You should have received a copy of the GNU General Public License along */
223 /*  with this program; if not, write to the Free Software Foundation, Inc., */
224 /*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             */
225 /* ======================================================================== */
226 /*                    Copyright (c) 2006, Joseph Zbiciak                    */
227 /* ======================================================================== */
228