| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "video.h"cxx . . $ `<file>/src/video.h`/ |
| 20 | |
| 21 | #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/ |
| 22 | #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/ |
| 23 | #include "palette.h"cxx . . $ `<file>/src/palette.h`/ |
| 24 | #include "video_scale.h"cxx . . $ `<file>/src/video_scale.h`/ |
| 25 | |
| 26 | #include <assert.h> |
| 27 | #include <stdbool.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | |
| 32 | const char *const scaling_mode_namescxx . . $ scaling_mode_names.[ScalingMode_MAXcxx . . $ ScalingMode_MAX.] = { |
| 33 | "Center", |
| 34 | "Integer", |
| 35 | "Fit 8:5", |
| 36 | "Fit 4:3", |
| 37 | }; |
| 38 | |
| 39 | int fullscreen_displaycxx . . $ fullscreen_display.; |
| 40 | ScalingModecxx . . $ ScalingMode# scaling_modecxx . . $ scaling_mode. = SCALE_INTEGERcxx . . $ SCALE_INTEGER.; |
| 41 | static SDL_Rectcxx . . $ SDL_Rect# last_output_rectcxx . . $ last_output_rect. = { 0, 0, vga_widthcxx . . $ `src/video.h:26:9`!, vga_heightcxx . . $ `src/video.h:27:9`! }; |
| 42 | |
| 43 | SDL_Surfacecxx . . $ SDL_Surface# *VGAScreencxx . . $ VGAScreen., *VGAScreenSegcxx . . $ VGAScreenSeg.; |
| 44 | SDL_Surfacecxx . . $ SDL_Surface# *VGAScreen2cxx . . $ VGAScreen2.; |
| 45 | SDL_Surfacecxx . . $ SDL_Surface# *game_screencxx . . $ game_screen.; |
| 46 | |
| 47 | SDL_Windowcxx . . $ SDL_Window# *main_windowcxx . . $ main_window. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 48 | static SDL_Renderercxx . . $ SDL_Renderer# *main_window_renderercxx . . $ main_window_renderer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 49 | SDL_PixelFormatcxx . . $ SDL_PixelFormat# *main_window_tex_formatcxx . . $ main_window_tex_format. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 50 | static SDL_Texturecxx . . $ SDL_Texture# *main_window_texturecxx . . $ main_window_texture. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 51 | |
| 52 | static ScalerFunctioncxx . . $ ScalerFunction# scaler_functioncxx . . $ scaler_function.; |
| 53 | |
| 54 | static void init_renderercxx . . $ init_renderer(49f6e7a06ebc5aa8).(void); |
| 55 | static void deinit_renderercxx . . $ deinit_renderer(49f6e7a06ebc5aa8).(void); |
| 56 | static void init_texturecxx . . $ init_texture(49f6e7a06ebc5aa8).(void); |
| 57 | static void deinit_texturecxx . . $ deinit_texture(49f6e7a06ebc5aa8).(void); |
| 58 | |
| 59 | static int window_get_display_indexcxx . . $ window_get_display_index(b126dc7c1de90089).(void); |
| 60 | static void window_center_in_displaycxx . . $ window_center_in_display(d4f767463ce0a6b3).(int display_index); |
| 61 | static void calc_dst_render_rectcxx . . $ calc_dst_render_rect(402f0d75f18c2744).(SDL_Surfacecxx . . $ SDL_Surface# *src_surface, SDL_Rectcxx . . $ SDL_Rect# *dst_rect); |
| 62 | static void scale_and_flipcxx . . $ scale_and_flip(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *); |
| 63 | |
| 64 | void init_videocxx . . $ init_video(49f6e7a06ebc5aa8).(void) |
| 65 | { |
| 66 | if (SDL_WasInitcxx . . $ SDL_WasInit(2141b656ce2cc063).(SDL_INIT_VIDEOcxx . . $ `<external>/13597568925221565411/SDL.h:85:9`!)) |
| 67 | return; |
| 68 | |
| 69 | if (SDL_InitSubSystemcxx . . $ SDL_InitSubSystem(4c679297bf94b9eb).(SDL_INIT_VIDEOcxx . . $ `<external>/13597568925221565411/SDL.h:85:9`!) == -1) |
| 70 | { |
| 71 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: failed to initialize SDL video: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).()); |
| 72 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 73 | } |
| 74 | |
| 75 | // Create the software surfaces that the game renders to. These are all 320x200x8 regardless |
| 76 | // of the window size or monitor resolution. |
| 77 | VGAScreencxx . . $ VGAScreen. = VGAScreenSegcxx . . $ VGAScreenSeg. = SDL_CreateRGBSurfacecxx . . $ SDL_CreateRGBSurface(98f97871e32d858).(0, vga_widthcxx . . $ `src/video.h:26:9`!, vga_heightcxx . . $ `src/video.h:27:9`!, 8, 0, 0, 0, 0); |
| 78 | VGAScreen2cxx . . $ VGAScreen2. = SDL_CreateRGBSurfacecxx . . $ SDL_CreateRGBSurface(98f97871e32d858).(0, vga_widthcxx . . $ `src/video.h:26:9`!, vga_heightcxx . . $ `src/video.h:27:9`!, 8, 0, 0, 0, 0); |
| 79 | game_screencxx . . $ game_screen. = SDL_CreateRGBSurfacecxx . . $ SDL_CreateRGBSurface(98f97871e32d858).(0, vga_widthcxx . . $ `src/video.h:26:9`!, vga_heightcxx . . $ `src/video.h:27:9`!, 8, 0, 0, 0, 0); |
| 80 | |
| 81 | // The game code writes to surface->pixels directly without locking, so make sure that we |
| 82 | // indeed created software surfaces that support this. |
| 83 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(!SDL_MUSTLOCK(VGAScreen)); |
| 84 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(!SDL_MUSTLOCK(VGAScreen2)); |
| 85 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(!SDL_MUSTLOCK(game_screen)); |
| 86 | |
| 87 | JE_clr256cxx . . $ JE_clr256(60a0b30a00b4fc6d).(VGAScreencxx . . $ VGAScreen.); |
| 88 | |
| 89 | // Create the window with a temporary initial size, hidden until we set up the |
| 90 | // scaler and find the true window size |
| 91 | main_windowcxx . . $ main_window. = SDL_CreateWindowcxx . . $ SDL_CreateWindow(2360bbcd09caf609).("OpenTyrian", |
| 92 | SDL_WINDOWPOS_CENTEREDcxx . . $ `<external>/14887343297790812595/SDL_video.h:147:9`!, SDL_WINDOWPOS_CENTEREDcxx . . $ `<external>/14887343297790812595/SDL_video.h:147:9`!, |
| 93 | vga_widthcxx . . $ `src/video.h:26:9`!, vga_heightcxx . . $ `src/video.h:27:9`!, SDL_WINDOW_RESIZABLEcxx . . $ SDL_WINDOW_RESIZABLE. | SDL_WINDOW_HIDDENcxx . . $ SDL_WINDOW_HIDDEN.); |
| 94 | |
| 95 | if (main_windowcxx . . $ main_window. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 96 | { |
| 97 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: failed to create window: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).()); |
| 98 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 99 | } |
| 100 | |
| 101 | reinit_fullscreencxx . . $ reinit_fullscreen(d4f767463ce0a6b3).(fullscreen_displaycxx . . $ fullscreen_display.); |
| 102 | init_renderercxx . . $ init_renderer(49f6e7a06ebc5aa8).(); |
| 103 | init_texturecxx . . $ init_texture(49f6e7a06ebc5aa8).(); |
| 104 | init_scalercxx . . $ init_scaler(dfa6e707f7696010).(scalercxx . . $ scaler.); |
| 105 | |
| 106 | SDL_ShowWindowcxx . . $ SDL_ShowWindow(8c8d6c3b662f39a2).(main_windowcxx . . $ main_window.); |
| 107 | |
| 108 | SDL_SetRenderDrawColorcxx . . $ SDL_SetRenderDrawColor(5e8a934d568bc2e).(main_window_renderercxx . . $ main_window_renderer., 0, 0, 0, 255); |
| 109 | SDL_RenderClearcxx . . $ SDL_RenderClear(d6c53d51f81071d4).(main_window_renderercxx . . $ main_window_renderer.); |
| 110 | SDL_RenderPresentcxx . . $ SDL_RenderPresent(8a04ec9ed224ca6d).(main_window_renderercxx . . $ main_window_renderer.); |
| 111 | } |
| 112 | |
| 113 | void deinit_videocxx . . $ deinit_video(49f6e7a06ebc5aa8).(void) |
| 114 | { |
| 115 | deinit_texturecxx . . $ deinit_texture(49f6e7a06ebc5aa8).(); |
| 116 | deinit_renderercxx . . $ deinit_renderer(49f6e7a06ebc5aa8).(); |
| 117 | |
| 118 | SDL_DestroyWindowcxx . . $ SDL_DestroyWindow(8c8d6c3b662f39a2).(main_windowcxx . . $ main_window.); |
| 119 | |
| 120 | SDL_FreeSurfacecxx . . $ SDL_FreeSurface(60a0b30a00b4fc6d).(VGAScreenSegcxx . . $ VGAScreenSeg.); |
| 121 | SDL_FreeSurfacecxx . . $ SDL_FreeSurface(60a0b30a00b4fc6d).(VGAScreen2cxx . . $ VGAScreen2.); |
| 122 | SDL_FreeSurfacecxx . . $ SDL_FreeSurface(60a0b30a00b4fc6d).(game_screencxx . . $ game_screen.); |
| 123 | |
| 124 | SDL_QuitSubSystemcxx . . $ SDL_QuitSubSystem(cb2f890c2fdad230).(SDL_INIT_VIDEOcxx . . $ `<external>/13597568925221565411/SDL.h:85:9`!); |
| 125 | } |
| 126 | |
| 127 | static void init_renderercxx . . $ init_renderer(49f6e7a06ebc5aa8).(void) |
| 128 | { |
| 129 | main_window_renderercxx . . $ main_window_renderer. = SDL_CreateRenderercxx . . $ SDL_CreateRenderer(3b1a735a7ee9eed5).(main_windowcxx . . $ main_window., -1, 0); |
| 130 | |
| 131 | if (main_window_renderercxx . . $ main_window_renderer. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 132 | { |
| 133 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: failed to create renderer: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).()); |
| 134 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | static void deinit_renderercxx . . $ deinit_renderer(49f6e7a06ebc5aa8).(void) |
| 139 | { |
| 140 | if (main_window_renderercxx . . $ main_window_renderer. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 141 | { |
| 142 | SDL_DestroyRenderercxx . . $ SDL_DestroyRenderer(8a04ec9ed224ca6d).(main_window_renderercxx . . $ main_window_renderer.); |
| 143 | main_window_renderercxx . . $ main_window_renderer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | static void init_texturecxx . . $ init_texture(49f6e7a06ebc5aa8).(void) |
| 148 | { |
| 149 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(main_window_renderer != NULL); |
| 150 | |
| 151 | int bpp = 32; // TODOSDL2 |
| 152 | Uint32cxx . . $ Uint32# format = bpp == 32 ? SDL_PIXELFORMAT_RGB888cxx . . $ SDL_PIXELFORMAT_RGB888. : SDL_PIXELFORMAT_RGB565cxx . . $ SDL_PIXELFORMAT_RGB565.; |
| 153 | int scaler_w = scalerscxx . . $ scalers.[scalercxx . . $ scaler.].widthcxx . . $ Scalers#width.; |
| 154 | int scaler_h = scalerscxx . . $ scalers.[scalercxx . . $ scaler.].heightcxx . . $ Scalers#height.; |
| 155 | |
| 156 | main_window_tex_formatcxx . . $ main_window_tex_format. = SDL_AllocFormatcxx . . $ SDL_AllocFormat(fc6f8902a623d9eb).(format); |
| 157 | |
| 158 | main_window_texturecxx . . $ main_window_texture. = SDL_CreateTexturecxx . . $ SDL_CreateTexture(5c677e94b60cfdf3).(main_window_renderercxx . . $ main_window_renderer., format, SDL_TEXTUREACCESS_STREAMINGcxx . . $ SDL_TEXTUREACCESS_STREAMING., scaler_w, scaler_h); |
| 159 | |
| 160 | if (main_window_texturecxx . . $ main_window_texture. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 161 | { |
| 162 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: failed to create scaler texture %dx%dx%s: %s\n", scaler_w, scaler_h, SDL_GetPixelFormatNamecxx . . $ SDL_GetPixelFormatName(81a3ae90da26a711).(format), SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).()); |
| 163 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | static void deinit_texturecxx . . $ deinit_texture(49f6e7a06ebc5aa8).(void) |
| 168 | { |
| 169 | if (main_window_texturecxx . . $ main_window_texture. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 170 | { |
| 171 | SDL_DestroyTexturecxx . . $ SDL_DestroyTexture(95a4f98c9f663ab8).(main_window_texturecxx . . $ main_window_texture.); |
| 172 | main_window_texturecxx . . $ main_window_texture. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 173 | } |
| 174 | |
| 175 | if (main_window_tex_formatcxx . . $ main_window_tex_format. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 176 | { |
| 177 | SDL_FreeFormatcxx . . $ SDL_FreeFormat(9ab8ae915d8b791a).(main_window_tex_formatcxx . . $ main_window_tex_format.); |
| 178 | main_window_tex_formatcxx . . $ main_window_tex_format. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | static int window_get_display_indexcxx . . $ window_get_display_index(b126dc7c1de90089).(void) |
| 183 | { |
| 184 | return SDL_GetWindowDisplayIndexcxx . . $ SDL_GetWindowDisplayIndex(71e995ed7857f42c).(main_windowcxx . . $ main_window.); |
| 185 | } |
| 186 | |
| 187 | static void window_center_in_displaycxx . . $ window_center_in_display(d4f767463ce0a6b3).(int display_index) |
| 188 | { |
| 189 | int win_w, win_h; |
| 190 | SDL_GetWindowSizecxx . . $ SDL_GetWindowSize(9db8dd3ac7233d99).(main_windowcxx . . $ main_window., &win_w, &win_h); |
| 191 | |
| 192 | SDL_Rectcxx . . $ SDL_Rect# bounds; |
| 193 | SDL_GetDisplayBoundscxx . . $ SDL_GetDisplayBounds(909e36eb39f0f97d).(display_index, &bounds); |
| 194 | |
| 195 | SDL_SetWindowPositioncxx . . $ SDL_SetWindowPosition(1d6b903408df08ed).(main_windowcxx . . $ main_window., bounds.xcxx . . $ SDL_Rect#x. + (bounds.wcxx . . $ SDL_Rect#w. - win_w) / 2, bounds.ycxx . . $ SDL_Rect#y. + (bounds.hcxx . . $ SDL_Rect#h. - win_h) / 2); |
| 196 | } |
| 197 | |
| 198 | void reinit_fullscreencxx . . $ reinit_fullscreen(d4f767463ce0a6b3).(int new_display) |
| 199 | { |
| 200 | fullscreen_displaycxx . . $ fullscreen_display. = new_display; |
| 201 | |
| 202 | if (fullscreen_displaycxx . . $ fullscreen_display. >= SDL_GetNumVideoDisplayscxx . . $ SDL_GetNumVideoDisplays(b126dc7c1de90089).()) |
| 203 | { |
| 204 | fullscreen_displaycxx . . $ fullscreen_display. = 0; |
| 205 | } |
| 206 | |
| 207 | SDL_SetWindowFullscreencxx . . $ SDL_SetWindowFullscreen(aa8a99d7247a1caa).(main_windowcxx . . $ main_window., SDL_FALSEcxx . . $ SDL_FALSE.); |
| 208 | SDL_SetWindowSizecxx . . $ SDL_SetWindowSize(1d6b903408df08ed).(main_windowcxx . . $ main_window., scalerscxx . . $ scalers.[scalercxx . . $ scaler.].widthcxx . . $ Scalers#width., scalerscxx . . $ scalers.[scalercxx . . $ scaler.].heightcxx . . $ Scalers#height.); |
| 209 | |
| 210 | if (fullscreen_displaycxx . . $ fullscreen_display. == -1) |
| 211 | { |
| 212 | window_center_in_displaycxx . . $ window_center_in_display(d4f767463ce0a6b3).(window_get_display_indexcxx . . $ window_get_display_index(b126dc7c1de90089).()); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | window_center_in_displaycxx . . $ window_center_in_display(d4f767463ce0a6b3).(fullscreen_displaycxx . . $ fullscreen_display.); |
| 217 | |
| 218 | if (SDL_SetWindowFullscreencxx . . $ SDL_SetWindowFullscreen(aa8a99d7247a1caa).(main_windowcxx . . $ main_window., SDL_WINDOW_FULLSCREEN_DESKTOPcxx . . $ SDL_WINDOW_FULLSCREEN_DESKTOP.) != 0) |
| 219 | { |
| 220 | reinit_fullscreencxx . . $ reinit_fullscreen(d4f767463ce0a6b3).(-1); |
| 221 | return; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void video_on_win_resizecxx . . $ video_on_win_resize(49f6e7a06ebc5aa8).(void) |
| 227 | { |
| 228 | int w, h; |
| 229 | int scaler_w, scaler_h; |
| 230 | |
| 231 | // Tell video to reinit if the window was manually resized by the user. |
| 232 | // Also enforce a minimum size on the window. |
| 233 | |
| 234 | SDL_GetWindowSizecxx . . $ SDL_GetWindowSize(9db8dd3ac7233d99).(main_windowcxx . . $ main_window., &w, &h); |
| 235 | scaler_w = scalerscxx . . $ scalers.[scalercxx . . $ scaler.].widthcxx . . $ Scalers#width.; |
| 236 | scaler_h = scalerscxx . . $ scalers.[scalercxx . . $ scaler.].heightcxx . . $ Scalers#height.; |
| 237 | |
| 238 | if (w < scaler_w || h < scaler_h) |
| 239 | { |
| 240 | w = w < scaler_w ? scaler_w : w; |
| 241 | h = h < scaler_h ? scaler_h : h; |
| 242 | |
| 243 | SDL_SetWindowSizecxx . . $ SDL_SetWindowSize(1d6b903408df08ed).(main_windowcxx . . $ main_window., w, h); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void toggle_fullscreencxx . . $ toggle_fullscreen(49f6e7a06ebc5aa8).(void) |
| 248 | { |
| 249 | if (fullscreen_displaycxx . . $ fullscreen_display. != -1) |
| 250 | reinit_fullscreencxx . . $ reinit_fullscreen(d4f767463ce0a6b3).(-1); |
| 251 | else |
| 252 | reinit_fullscreencxx . . $ reinit_fullscreen(d4f767463ce0a6b3).(SDL_GetWindowDisplayIndexcxx . . $ SDL_GetWindowDisplayIndex(71e995ed7857f42c).(main_windowcxx . . $ main_window.)); |
| 253 | } |
| 254 | |
| 255 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! init_scalercxx . . $ init_scaler(dfa6e707f7696010).(unsigned int new_scaler) |
| 256 | { |
| 257 | int w = scalerscxx . . $ scalers.[new_scaler].widthcxx . . $ Scalers#width., |
| 258 | h = scalerscxx . . $ scalers.[new_scaler].heightcxx . . $ Scalers#height.; |
| 259 | int bpp = main_window_tex_formatcxx . . $ main_window_tex_format.->BitsPerPixelcxx . . $ SDL_PixelFormat#BitsPerPixel.; // TODOSDL2 |
| 260 | |
| 261 | scalercxx . . $ scaler. = new_scaler; |
| 262 | |
| 263 | deinit_texturecxx . . $ deinit_texture(49f6e7a06ebc5aa8).(); |
| 264 | init_texturecxx . . $ init_texture(49f6e7a06ebc5aa8).(); |
| 265 | |
| 266 | if (fullscreen_displaycxx . . $ fullscreen_display. == -1) |
| 267 | { |
| 268 | // Changing scalers, when not in fullscreen mode, forces the window |
| 269 | // to resize to exactly match the scaler's output dimensions. |
| 270 | SDL_SetWindowSizecxx . . $ SDL_SetWindowSize(1d6b903408df08ed).(main_windowcxx . . $ main_window., w, h); |
| 271 | window_center_in_displaycxx . . $ window_center_in_display(d4f767463ce0a6b3).(window_get_display_indexcxx . . $ window_get_display_index(b126dc7c1de90089).()); |
| 272 | } |
| 273 | |
| 274 | switch (bpp) |
| 275 | { |
| 276 | case 32: |
| 277 | scaler_functioncxx . . $ scaler_function. = scalerscxx . . $ scalers.[scalercxx . . $ scaler.].scaler32cxx . . $ Scalers#scaler32.; |
| 278 | break; |
| 279 | case 16: |
| 280 | scaler_functioncxx . . $ scaler_function. = scalerscxx . . $ scalers.[scalercxx . . $ scaler.].scaler16cxx . . $ Scalers#scaler16.; |
| 281 | break; |
| 282 | default: |
| 283 | scaler_functioncxx . . $ scaler_function. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | if (scaler_functioncxx . . $ scaler_function. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 288 | { |
| 289 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false); |
| 290 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 291 | } |
| 292 | |
| 293 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 294 | } |
| 295 | |
| 296 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! set_scaling_mode_by_namecxx . . $ set_scaling_mode_by_name(c5f7da30cbc0f4e9).(const char *name) |
| 297 | { |
| 298 | for (int i = 0; i < ScalingMode_MAXcxx . . $ ScalingMode_MAX.; ++i) |
| 299 | { |
| 300 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(name, scaling_mode_namescxx . . $ scaling_mode_names.[i]) == 0) |
| 301 | { |
| 302 | scaling_modecxx . . $ scaling_mode. = i; |
| 303 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 304 | } |
| 305 | } |
| 306 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 307 | } |
| 308 | |
| 309 | void JE_clr256cxx . . $ JE_clr256(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *screen) |
| 310 | { |
| 311 | SDL_FillRectcxx . . $ SDL_FillRect(3ec95406e4bae91).(screen, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 312 | } |
| 313 | |
| 314 | void JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).(void) |
| 315 | { |
| 316 | scale_and_flipcxx . . $ scale_and_flip(60a0b30a00b4fc6d).(VGAScreencxx . . $ VGAScreen.); |
| 317 | } |
| 318 | |
| 319 | static void calc_dst_render_rectcxx . . $ calc_dst_render_rect(402f0d75f18c2744).(SDL_Surfacecxx . . $ SDL_Surface# *const src_surface, SDL_Rectcxx . . $ SDL_Rect# *const dst_rect) |
| 320 | { |
| 321 | // Decides how the logical output texture (after software scaling applied) will fit |
| 322 | // in the window. |
| 323 | |
| 324 | int win_w, win_h; |
| 325 | SDL_GetWindowSizecxx . . $ SDL_GetWindowSize(9db8dd3ac7233d99).(main_windowcxx . . $ main_window., &win_w, &win_h); |
| 326 | |
| 327 | int maxh_width, maxw_height; |
| 328 | |
| 329 | switch (scaling_modecxx . . $ scaling_mode.) |
| 330 | { |
| 331 | case SCALE_CENTERcxx . . $ SCALE_CENTER.: |
| 332 | SDL_QueryTexturecxx . . $ SDL_QueryTexture(ea18ca1178d0c92c).(main_window_texturecxx . . $ main_window_texture., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &dst_rect->wcxx . . $ SDL_Rect#w., &dst_rect->hcxx . . $ SDL_Rect#h.); |
| 333 | break; |
| 334 | case SCALE_INTEGERcxx . . $ SCALE_INTEGER.: |
| 335 | dst_rect->wcxx . . $ SDL_Rect#w. = src_surface->wcxx . . $ SDL_Surface#w.; |
| 336 | dst_rect->hcxx . . $ SDL_Rect#h. = src_surface->hcxx . . $ SDL_Surface#h.; |
| 337 | while (dst_rect->wcxx . . $ SDL_Rect#w. + src_surface->wcxx . . $ SDL_Surface#w. <= win_w && dst_rect->hcxx . . $ SDL_Rect#h. + src_surface->hcxx . . $ SDL_Surface#h. <= win_h) |
| 338 | { |
| 339 | dst_rect->wcxx . . $ SDL_Rect#w. += src_surface->wcxx . . $ SDL_Surface#w.; |
| 340 | dst_rect->hcxx . . $ SDL_Rect#h. += src_surface->hcxx . . $ SDL_Surface#h.; |
| 341 | } |
| 342 | break; |
| 343 | case SCALE_ASPECT_8_5cxx . . $ SCALE_ASPECT_8_5.: |
| 344 | maxh_width = win_h * (8.f / 5.f); |
| 345 | maxw_height = win_w * (5.f / 8.f); |
| 346 | |
| 347 | if (maxh_width > win_w) |
| 348 | { |
| 349 | dst_rect->wcxx . . $ SDL_Rect#w. = win_w; |
| 350 | dst_rect->hcxx . . $ SDL_Rect#h. = maxw_height; |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | dst_rect->wcxx . . $ SDL_Rect#w. = maxh_width; |
| 355 | dst_rect->hcxx . . $ SDL_Rect#h. = win_h; |
| 356 | } |
| 357 | break; |
| 358 | case SCALE_ASPECT_4_3cxx . . $ SCALE_ASPECT_4_3.: |
| 359 | maxh_width = win_h * (4.f / 3.f); |
| 360 | maxw_height = win_w * (3.f / 4.f); |
| 361 | |
| 362 | if (maxh_width > win_w) |
| 363 | { |
| 364 | dst_rect->wcxx . . $ SDL_Rect#w. = win_w; |
| 365 | dst_rect->hcxx . . $ SDL_Rect#h. = maxw_height; |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | dst_rect->wcxx . . $ SDL_Rect#w. = maxh_width; |
| 370 | dst_rect->hcxx . . $ SDL_Rect#h. = win_h; |
| 371 | } |
| 372 | break; |
| 373 | case ScalingMode_MAXcxx . . $ ScalingMode_MAX.: |
| 374 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false); |
| 375 | break; |
| 376 | } |
| 377 | |
| 378 | dst_rect->xcxx . . $ SDL_Rect#x. = (win_w - dst_rect->wcxx . . $ SDL_Rect#w.) / 2; |
| 379 | dst_rect->ycxx . . $ SDL_Rect#y. = (win_h - dst_rect->hcxx . . $ SDL_Rect#h.) / 2; |
| 380 | } |
| 381 | |
| 382 | static void scale_and_flipcxx . . $ scale_and_flip(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *src_surface) |
| 383 | { |
| 384 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(src_surface->format->BitsPerPixel == 8); |
| 385 | |
| 386 | // Do software scaling |
| 387 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(scaler_function != NULL); |
| 388 | scaler_functioncxx . . $ scaler_function.(src_surface, main_window_texturecxx . . $ main_window_texture.); |
| 389 | |
| 390 | SDL_Rectcxx . . $ SDL_Rect# dst_rect; |
| 391 | calc_dst_render_rectcxx . . $ calc_dst_render_rect(402f0d75f18c2744).(src_surface, &dst_rect); |
| 392 | |
| 393 | // Clear the window and blit the output texture to it |
| 394 | SDL_SetRenderDrawColorcxx . . $ SDL_SetRenderDrawColor(5e8a934d568bc2e).(main_window_renderercxx . . $ main_window_renderer., 0, 0, 0, 255); |
| 395 | SDL_RenderClearcxx . . $ SDL_RenderClear(d6c53d51f81071d4).(main_window_renderercxx . . $ main_window_renderer.); |
| 396 | SDL_RenderCopycxx . . $ SDL_RenderCopy(64b845cb112b06b3).(main_window_renderercxx . . $ main_window_renderer., main_window_texturecxx . . $ main_window_texture., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &dst_rect); |
| 397 | SDL_RenderPresentcxx . . $ SDL_RenderPresent(8a04ec9ed224ca6d).(main_window_renderercxx . . $ main_window_renderer.); |
| 398 | |
| 399 | // Save output rect to be used by mouse functions |
| 400 | last_output_rectcxx . . $ last_output_rect. = dst_rect; |
| 401 | } |
| 402 | |
| 403 | /** Maps a specified point in game screen coordinates to window coordinates. */ |
| 404 | void mapScreenPointToWindowcxx . . $ mapScreenPointToWindow(ce8f7825f8908cfa).(Sint32cxx . . $ Sint32# *const inout_x, Sint32cxx . . $ Sint32# *const inout_y) |
| 405 | { |
| 406 | *inout_x = (2 * *inout_x + 1) * last_output_rectcxx . . $ last_output_rect..wcxx . . $ SDL_Rect#w. / (2 * VGAScreencxx . . $ VGAScreen.->wcxx . . $ SDL_Surface#w.) + last_output_rectcxx . . $ last_output_rect..xcxx . . $ SDL_Rect#x.; |
| 407 | *inout_y = (2 * *inout_y + 1) * last_output_rectcxx . . $ last_output_rect..hcxx . . $ SDL_Rect#h. / (2 * VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h.) + last_output_rectcxx . . $ last_output_rect..ycxx . . $ SDL_Rect#y.; |
| 408 | } |
| 409 | |
| 410 | /** Maps a specified point in window coordinates to game screen coordinates. */ |
| 411 | void mapWindowPointToScreencxx . . $ mapWindowPointToScreen(ce8f7825f8908cfa).(Sint32cxx . . $ Sint32# *const inout_x, Sint32cxx . . $ Sint32# *const inout_y) |
| 412 | { |
| 413 | *inout_x = (2 * (*inout_x - last_output_rectcxx . . $ last_output_rect..xcxx . . $ SDL_Rect#x.) + 1) * VGAScreencxx . . $ VGAScreen.->wcxx . . $ SDL_Surface#w. / (2 * last_output_rectcxx . . $ last_output_rect..wcxx . . $ SDL_Rect#w.); |
| 414 | *inout_y = (2 * (*inout_y - last_output_rectcxx . . $ last_output_rect..ycxx . . $ SDL_Rect#y.) + 1) * VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h. / (2 * last_output_rectcxx . . $ last_output_rect..hcxx . . $ SDL_Rect#h.); |
| 415 | } |
| 416 | |
| 417 | /** Scales a distance in window coordinates to game screen coordinates. */ |
| 418 | void scaleWindowDistanceToScreencxx . . $ scaleWindowDistanceToScreen(ce8f7825f8908cfa).(Sint32cxx . . $ Sint32# *const inout_x, Sint32cxx . . $ Sint32# *const inout_y) |
| 419 | { |
| 420 | *inout_x = (2 * *inout_x + 1) * VGAScreencxx . . $ VGAScreen.->wcxx . . $ SDL_Surface#w. / (2 * last_output_rectcxx . . $ last_output_rect..wcxx . . $ SDL_Rect#w.); |
| 421 | *inout_y = (2 * *inout_y + 1) * VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h. / (2 * last_output_rectcxx . . $ last_output_rect..hcxx . . $ SDL_Rect#h.); |
| 422 | } |