Path: blob/a-new-beginning/Cherry/Core/include/definitions.h
2 views
/*1* Gearcoleco - ColecoVision Emulator2* Copyright (C) 2021 Ignacio Sanchez34* This program is free software: you can redistribute it and/or modify5* it under the terms of the GNU General Public License as published by6* the Free Software Foundation, either version 3 of the License, or7* any later version.89* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.1314* You should have received a copy of the GNU General Public License15* along with this program. If not, see http://www.gnu.org/licenses/16*17*/1819#ifndef DEFINITIONS_H20#define DEFINITIONS_H2122#include <stdarg.h>23#include <stdlib.h>24#include <stdio.h>25#include <string.h>26#include <stdint.h>27#include <iostream>28#include <fstream>29#include <sstream>3031#ifndef EMULATOR_BUILD32#define EMULATOR_BUILD "undefined"33#endif3435#define GEARCOLECO_TITLE "Gearcoleco"36#define GEARCOLECO_VERSION EMULATOR_BUILD37#define GEARCOLECO_TITLE_ASCII "" \38" ____ _ \n" \39" / ___| ___ __ _ _ __ ___ ___ | | ___ ___ ___ \n" \40" | | _ / _ \\/ _` | '__/ __/ _ \\| |/ _ \\/ __/ _ \\ \n" \41" | |_| | __/ (_| | | | (_| (_) | | __/ (_| (_) | \n" \42" \\____|\\___|\\__,_|_| \\___\\___/|_|\\___|\\___\\___/ \n"434445#ifdef DEBUG46#define DEBUG_GEARCOLECO 047#endif4849#if defined(PS2) || defined(PSP)50#define PERFORMANCE51#endif5253#ifndef NULL54#define NULL 055#endif5657#ifdef _WIN3258#define BLARGG_USE_NAMESPACE 159#endif6061//#define GEARCOLECO_DISABLE_DISASSEMBLER6263#define MAX_ROM_SIZE 0x8000006465#define SafeDelete(pointer) if(pointer != NULL) {delete pointer; pointer = NULL;}66#define SafeDeleteArray(pointer) if(pointer != NULL) {delete [] pointer; pointer = NULL;}6768#define InitPointer(pointer) ((pointer) = NULL)69#define IsValidPointer(pointer) ((pointer) != NULL)7071#if defined(MSB_FIRST) || defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)72#define IS_BIG_ENDIAN73#else74#define IS_LITTLE_ENDIAN75#endif7677#define MIN(a, b) ((a) < (b) ? (a) : (b))78#define MAX(a, b) ((a) > (b) ? (a) : (b))79#define CLAMP(value, min, max) MIN(MAX(value, min), max)8081typedef uint8_t u8;82typedef int8_t s8;83typedef uint16_t u16;84typedef int16_t s16;85typedef uint32_t u32;86typedef int32_t s32;87typedef uint64_t u64;88typedef int64_t s64;8990typedef void (*RamChangedCallback) (void);9192#define FLAG_CARRY 0x0193#define FLAG_NEGATIVE 0x0294#define FLAG_PARITY 0x0495#define FLAG_X 0x0896#define FLAG_HALF 0x1097#define FLAG_Y 0x2098#define FLAG_ZERO 0x4099#define FLAG_SIGN 0x80100#define FLAG_NONE 0101102#define GC_RESOLUTION_WIDTH 256103#define GC_RESOLUTION_HEIGHT 192104105#define GC_MAX_GAMEPADS 2106107#define GC_RESOLUTION_WIDTH_WITH_OVERSCAN 320108#define GC_RESOLUTION_HEIGHT_WITH_OVERSCAN 288109#define GC_RESOLUTION_SMS_OVERSCAN_H_320_L 32110#define GC_RESOLUTION_SMS_OVERSCAN_H_320_R 32111#define GC_RESOLUTION_SMS_OVERSCAN_H_284_L 14112#define GC_RESOLUTION_SMS_OVERSCAN_H_284_R 14113#define GC_RESOLUTION_OVERSCAN_V 24114#define GC_RESOLUTION_OVERSCAN_V_PAL 48115116#define GC_CYCLES_PER_LINE 228117118#define GC_MASTER_CLOCK_NTSC 3579545119#define GC_LINES_PER_FRAME_NTSC 262120#define GC_FRAMES_PER_SECOND_NTSC 60121122#define GC_MASTER_CLOCK_PAL 3546893123#define GC_LINES_PER_FRAME_PAL 313124#define GC_FRAMES_PER_SECOND_PAL 50125126#define GC_AUDIO_SAMPLE_RATE 44100127#define GC_AUDIO_BUFFER_SIZE 8192128129#define GC_SAVESTATE_MAGIC 0x09200902130131struct GC_Color132{133u8 red;134u8 green;135u8 blue;136};137138enum GC_Color_Format139{140GC_PIXEL_RGB565,141GC_PIXEL_RGB555,142GC_PIXEL_RGB888,143GC_PIXEL_BGR565,144GC_PIXEL_BGR555,145GC_PIXEL_BGR888146};147148enum GC_Keys149{150Keypad_8 = 0x01,151Keypad_4 = 0x02,152Keypad_5 = 0x03,153Key_Blue = 0x04,154Keypad_7 = 0x05,155Keypad_Hash = 0x06,156Keypad_2 = 0x07,157Key_Purple = 0x08,158Keypad_Asterisk = 0x09,159Keypad_0 = 0x0A,160Keypad_9 = 0x0B,161Keypad_3 = 0x0C,162Keypad_1 = 0x0D,163Keypad_6 = 0x0E,164Key_Up = 0x10,165Key_Right = 0x11,166Key_Down = 0x12,167Key_Left = 0x13,168Key_Left_Button = 0x14,169Key_Right_Button = 0x15170};171172enum GC_Controllers173{174Controller_1 = 0,175Controller_2 = 1176};177178enum GC_Region179{180Region_NTSC,181Region_PAL182};183184struct GC_RuntimeInfo185{186int screen_width;187int screen_height;188GC_Region region;189};190191inline u8 SetBit(const u8 value, const u8 bit)192{193return value | (0x01 << bit);194}195196inline u8 UnsetBit(const u8 value, const u8 bit)197{198return value & (~(0x01 << bit));199}200201inline bool IsSetBit(const u8 value, const u8 bit)202{203return (value & (0x01 << bit)) != 0;204}205206inline u8 FlipBit(const u8 value, const u8 bit)207{208return value ^ (0x01 << bit);209}210211inline u8 ReverseBits(const u8 value)212{213u8 ret = value;214ret = (ret & 0xF0) >> 4 | (ret & 0x0F) << 4;215ret = (ret & 0xCC) >> 2 | (ret & 0x33) << 2;216ret = (ret & 0xAA) >> 1 | (ret & 0x55) << 1;217return ret;218}219220inline int AsHex(const char c)221{222return c >= 'A' ? c - 'A' + 0xA : c - '0';223}224225inline unsigned int Pow2Ceil(u16 n)226{227--n;228n |= n >> 1;229n |= n >> 2;230n |= n >> 4;231n |= n >> 8;232++n;233return n;234}235236#endif /* DEFINITIONS_H */237238239