| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (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, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * Video library. |
| 21 | * |
| 22 | * $NoKeywords: $ |
| 23 | */ |
| 24 | |
| 25 | #include <cstring> |
| 26 | #include <cstdlib> |
| 27 | |
| 28 | #include "ddvid.h" |
| 29 | #include "application.h" |
| 30 | #include "lnxapp.h" |
| 31 | |
| 32 | struct tinfo { |
| 33 | int width, height, bytesperpixel, linewidth; |
| 34 | }; |
| 35 | |
| 36 | struct tDDVideoInfo { |
| 37 | oeLnxApplication *app; |
| 38 | // vga_modeinfo *info; |
| 39 | tinfo *info; |
| 40 | bool paged; |
| 41 | }; |
| 42 | |
| 43 | ////////////////////////////////////////////////////////////////////////////// |
| 44 | // Variables |
| 45 | |
| 46 | tDDVideoInfo DDVideo_info; |
| 47 | static bool DDVideo_init = false; |
| 48 | |
| 49 | ////////////////////////////////////////////////////////////////////////////// |
| 50 | // Prototypes |
| 51 | |
| 52 | ////////////////////////////////////////////////////////////////////////////// |
| 53 | // Functions |
| 54 | |
| 55 | // called first to allow fullscreen video access |
| 56 | bool ddvid_Init(oeApplication *app, char *driver) { |
| 57 | int subsys_id; |
| 58 | |
| 59 | // preinitialize system. |
| 60 | if (!DDVideo_init) { |
| 61 | DDVideo_info.app = NULL; |
| 62 | DDVideo_info.info = NULL; |
| 63 | atexit(ddvid_Close); |
| 64 | } else { |
| 65 | ddvid_Close(); |
| 66 | } |
| 67 | |
| 68 | DDVideo_init = true; |
| 69 | |
| 70 | DDVideo_info.app = (oeLnxApplication *)app; |
| 71 | |
| 72 | // vga_init(); |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | // closes ddvid system manually. |
| 77 | void ddvid_Close() { |
| 78 | if (!DDVideo_init) |
| 79 | return; |
| 80 | |
| 81 | /* |
| 82 | if(vga_getcurrentmode()!=TEXT) |
| 83 | vga_setmode(TEXT); |
| 84 | */ |
| 85 | DDVideo_init = false; |
| 86 | } |
| 87 | |
| 88 | // sets the appropriate video mode. |
| 89 | bool ddvid_SetVideoMode(int w, int h, int color_depth, bool paged) { |
| 90 | /* |
| 91 | ASSERT(DDVideo_init); |
| 92 | |
| 93 | int mode = -1; |
| 94 | |
| 95 | if( (w==640) && (h==480) ){ |
| 96 | switch(color_depth){ |
| 97 | case BPP_8: |
| 98 | mode = G640x480x256; |
| 99 | break; |
| 100 | case BPP_16: |
| 101 | mode = G640x480x32K; |
| 102 | break; |
| 103 | case BPP_24: |
| 104 | mode = G640x480x64K; |
| 105 | break; |
| 106 | case BPP_32: |
| 107 | mode = G640x480x16M; |
| 108 | break; |
| 109 | } |
| 110 | }else |
| 111 | if( (w==512) && (h==384) ){ |
| 112 | mode = -1; |
| 113 | }else |
| 114 | if( (w==800) && (h==600) ){ |
| 115 | switch(color_depth){ |
| 116 | case BPP_8: |
| 117 | mode = G800x600x256; |
| 118 | break; |
| 119 | case BPP_16: |
| 120 | mode = G800x600x32K; |
| 121 | break; |
| 122 | case BPP_24: |
| 123 | mode = G800x600x64K; |
| 124 | break; |
| 125 | case BPP_32: |
| 126 | mode = G800x600x16M; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if(mode==-1) |
| 132 | return false; |
| 133 | |
| 134 | if(!vga_hasmode(mode)) |
| 135 | return false; |
| 136 | |
| 137 | DDVideo_info.info = vga_getmodeinfo(mode); |
| 138 | |
| 139 | DDVideo_info.paged = (bool)(DDVideo_info.info->flags&HAVE_RWPAGE); |
| 140 | |
| 141 | if( (paged) && (!(DDVideo_info.paged)) ){ |
| 142 | DDVideo_info.info = NULL; |
| 143 | Error("Pages not supported by mode %d\n",mode); |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | vga_setmode(mode); |
| 148 | */ |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | // sets screen handle |
| 153 | void ddvid_SetVideoHandle(unsigned handle) {} |