1 /* vim:expandtab:ts=2 sw=2: 2 */ 3 /* Grafx2 - The Ultimate 256-color bitmap paint program 4 5 Copyright owned by various GrafX2 authors, see COPYRIGHT.txt for details. 6 7 Grafx2 is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; version 2 10 of the License. 11 12 Grafx2 is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Grafx2; if not, see <http://www.gnu.org/licenses/> 19 */ 20 21 #ifndef OLDIES_H_DEFINED 22 #define OLDIES_H_DEFINED 23 24 ///@file oldies.h 25 /// functions relative to old computers (Commodore 64, Thomsons MO/TO, Amstrad CPC, ZX Spectrum, etc.) 26 27 #include "loadsave.h" 28 29 /** 30 * identifier for each Image mode 31 * 32 * @return an ASCII label for the mode 33 */ 34 const char * Constraint_mode_label(enum IMAGE_MODES mode); 35 36 /** 37 * Search constraint mode for a label 38 * 39 * @return -1 for unknown mode or one of ::IMAGE_MODES value 40 */ 41 int Constraint_mode_from_label(const char * label); 42 43 /** @defgroup c64 Commodore 64 44 * Some C64 video mode related functions 45 * @{ 46 */ 47 /** 48 * Save a 3 layer picture to C64 FLI format 49 * 50 * @param context the Save context 51 * @param bitmap a 8000 byte buffer to store bitmap data 52 * @param screen_ram a 8192 byte buffer to store the 8 screen RAMs 53 * @param color_ram a 1000 byte buffer to store the color RAM 54 * @param background a 200 byte buffer to store the background colors 55 * @return 0 for success, 1 if the picture is less than 3 layers, 2 if the picture dimensions are not 160x200 56 */ 57 int C64_FLI(T_IO_Context * context, byte *bitmap, byte *screen_ram, byte *color_ram, byte *background); 58 59 /** 60 * Convert a (1 layer) picture to C64 FLI format 61 * 62 * Some "hints" can be put in background and color_ram. 63 * (a color value >= 16 means no hint). 64 * 65 * Errors can be either outputed to the user with Warning messages, 66 * or put in layer 4. The layer 4 has to be created before. 67 * 68 * @param bitmap a 8000 byte buffer to store bitmap data 69 * @param screen_ram a 8192 byte buffer to store the 8 screen RAMs 70 * @param color_ram a 1000 byte buffer to store the color RAM 71 * @param background a 200 byte buffer to store the background colors 72 * @param pixels source pixel buffer (at least 160x200) 73 * @param pitch bytes per line of the pixel buffer 74 * @param errmode error reporting mode 0 = report, 1 = mark in layer 4 75 * @return 0 the number of constraint errors 76 */ 77 int C64_pixels_to_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background, const byte * pixels, long pitch, int errmode); 78 79 /** 80 * Set the 16 colors Commodore 64 palette 81 */ 82 void C64_set_palette(T_Components * palette); 83 84 /** @}*/ 85 86 /** @defgroup zx_spectrum Sinclair ZX Spectrum 87 * 88 * @{ 89 */ 90 91 /** 92 * Set the 16 colors ZX Spectrum palette. 93 * 94 * The ZX Spectrum palette is a 16 color RGBI palette. 95 * The color components are in IGRB order. 96 */ 97 void ZX_Spectrum_set_palette(T_Components * palette); 98 99 /** @}*/ 100 101 /** @defgroup cpc Amstrad CPC 102 * 103 * @{ 104 */ 105 106 /** 107 * Set 32 color HW Amstrad CPC palette 108 * 109 * The palette is in fact 27 colors, with some duplicates. 110 * http://www.cpcwiki.eu/index.php/CPC_Palette 111 */ 112 void CPC_set_HW_palette(T_Components * palette); 113 114 /** 115 * Check if the color is likely to be a CPC RGB tri level color 116 */ 117 int CPC_is_CPC_old_color(T_Components * col); 118 119 /** 120 * Set 16 color default Amstrad CPC BASIC palette 121 * 122 * @note INK 14 and 15 are blinking on the real hardware. 123 */ 124 void CPC_set_default_BASIC_palette(T_Components * palette); 125 126 /** 127 * compare two RGB colors 128 * 129 * The RGB colors are compared in order as if they were 130 * converted from CPC (27 color palette), as there are several 131 * mapping of the 3 level CPC RGB signals. 132 * 133 * @return true if the RGB colors map to the same CPC color 134 */ 135 int CPC_compare_colors(T_Components * col1, T_Components * col2); 136 137 /** 138 * Convert CPC firmware color to hardware color (Gate Array) 139 * @param fw_color a CPC Firmware color index (from 0 to 26) 140 * @return a CPC Hardware color (from 0x40 to 0x5f) 141 */ 142 byte CPC_Firmware_to_Hardware_color(byte fw_color); 143 144 /** 145 * Check AMSDOS header 146 * 147 * see http://www.cpcwiki.eu/index.php/AMSDOS_Header 148 * 149 * @param[in] file an open file 150 * @param[out] loading_address the loading address from the header 151 * @param[out] exec_address the execution address from the header 152 * @param[out] file_length the file length written in the header 153 * @return 0 if the file does not contain a valid AMSDOS header 154 * @return 1 if it does. 155 */ 156 int CPC_check_AMSDOS(FILE * file, word * loading_address, word * exec_address, unsigned long * file_length); 157 158 /** 159 * Write AMSDOS header 160 */ 161 int CPC_write_AMSDOS_header(FILE * file, const char * filename, const char * ext, byte type, word load_address, word save_address, word file_length); 162 163 /** @}*/ 164 165 /** @defgroup decb DECB binary format 166 * 167 * The DECB binary format was used on 6809 based machines : 168 * Tandy CoCo, Dragon 32/64 and Thomson MO/TO. 169 * 170 * DECB stand for Disk Extended Color Basic and was a version 171 * of the Microsoft BASIC-69 (their basic for Motorola 6809) 172 * @{ 173 */ 174 /** 175 * Add a chunk to a DECB binary file 176 * 177 * @param f open file 178 * @param size size of the memory chunk 179 * @param address load address of the memory chunk 180 * @param data data to add in memory chunk 181 * @return true for success 182 */ 183 int DECB_BIN_Add_Chunk(FILE * f, word size, word address, const byte * data); 184 185 /** 186 * Add a chunk to a DECB binary file 187 * 188 * @param f open file 189 * @param address run address of the binary file (LOADM,,R) 190 * @return true for success 191 */ 192 int DECB_BIN_Add_End(FILE * f, word address); 193 194 195 /** 196 * Check if the file is in the DECB Binary format 197 * 198 * @param f open file 199 * @return 1 if the file is in DECB Binary format, or else 0 200 */ 201 int DECB_Check_binary_file(FILE * f); 202 /** @}*/ 203 204 /** @defgroup moto Thomson MO/TO 205 * Thomson MO/TO computer range 206 * 207 * The Thomson MO/TO computer range was based on a Motorola 6809 CPU 208 * and equiped with Microsoft Basic called Basic 1.0 for the first 209 * versions and then Basic 128 or Basic 512 which included a DOS 210 * and more features. 211 * 212 * The range includes : 213 * - TO7 214 * - MO5/MO5E 215 * - TO7/70 216 * - TO9 217 * - MO6/MO5NR 218 * - TO8/TO8D 219 * - TO9 220 * - Olivetti Prodest PC128 (a Thomson MO6 clone) 221 * @{ 222 */ 223 224 /** 225 * to define a specific machine in the Thomson MO/TO range of machines 226 */ 227 enum MOTO_Machine_Type { 228 MACHINE_TO7, ///< original TO7 with 8 colors 229 MACHINE_TO770, ///< the TO7-70 had 16 colors 230 MACHINE_MO5, 231 MACHINE_MO6, ///< 232 MACHINE_TO9, 233 MACHINE_TO8 ///< TO8, TO8D and TO9+ are equivalent 234 }; 235 236 /** 237 * Graphic modes available in BASIC 128/512 with CONSOLE,,,,X instruction 238 */ 239 enum MOTO_Graphic_Mode { 240 MOTO_MODE_40col = 0, ///< 320x200 16 colors with constraints 241 MOTO_MODE_80col = 1, ///< 640x200 2 colors 242 MOTO_MODE_bm4 = 2, ///< 320x200 4 colors without constraint 243 MOTO_MODE_bm16 = 3, ///< 160x200 16 colors without constraint 244 }; 245 246 /** 247 * Checks if the file is a Thomson binary file (SAVEM/LOADM format) 248 * 249 * @param f a file open for reading 250 * @return 0 if this is not a binary file 251 * @return >0 if this is a binary file : 252 * @return 1 no further details found 253 * @return 2 This is likely a MAP file (SAVEP/LOADP format) 254 * @return 3 This is likely a TO autoloading picture 255 * @return 4 This is likely a MO5/MO6 autoloading picture 256 */ 257 int MOTO_Check_binary_file(FILE * f); 258 259 /** 260 * Convert a RGB value to Thomson BGR value with gamma correction. 261 */ 262 word MOTO_gamma_correct_RGB_to_MOTO(const T_Components * color); 263 264 /** 265 * Convert a Thomson BGR value to RGB values with gamma correction. 266 */ 267 void MOTO_gamma_correct_MOTO_to_RGB(T_Components * color, word bgr); 268 269 /** 270 * Set MO5 Palette 271 * 272 * http://pulkomandy.tk/wiki/doku.php?id=documentations:devices:gate.arrays#video_generation 273 * https://16couleurs.wordpress.com/2013/03/31/archeologie-infographique-le-pixel-art-pour-thomson/ 274 */ 275 void MOTO_set_MO5_palette(T_Components * palette); 276 277 /** 278 * Set TO7/70 Palette. 279 * 280 * The 8 first colors are the TO7 palette 281 */ 282 void MOTO_set_TO7_palette(T_Components * palette); 283 284 /** @}*/ 285 286 /** @defgroup apple2 Apple II 287 * 288 * HGR and DHGR modes 289 * @{ 290 */ 291 292 /** 293 * Set the 6 color Apple II HGR palette 294 */ 295 void HGR_set_palette(T_Components * palette); 296 297 /** 298 * Set the 16 color Apple II DHGR palette 299 */ 300 void DHGR_set_palette(T_Components * palette); 301 302 /** @}*/ 303 304 /** 305 * Set the 15 color MSX palette 306 */ 307 void MSX_set_palette(T_Components * palette); 308 309 #endif 310