cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

definitions.h (3464B)


      1/*
      2 * Gearboy - Nintendo Game Boy Emulator
      3 * Copyright (C) 2012  Ignacio Sanchez
      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 * 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 */
     19
     20#ifndef DEFINITIONS_H
     21#define	DEFINITIONS_H
     22
     23#include <stdarg.h>
     24#include <stdlib.h>
     25#include <stdio.h>
     26#include <string.h>
     27#include <stdint.h>
     28#include <iostream>
     29#include <fstream>
     30#include <sstream>
     31
     32#ifdef DEBUG
     33#define DEBUG_GEARBOY 1
     34#endif
     35
     36#if defined(PS2) || defined(PSP)
     37#define PERFORMANCE
     38#endif
     39
     40#define GEARBOY_TITLE "Gearboy"
     41#define GEARBOY_VERSION "3.4.1"
     42
     43#ifndef EMULATOR_BUILD
     44#define EMULATOR_BUILD "undefined"
     45#endif
     46
     47#ifndef NULL
     48#define NULL 0
     49#endif
     50
     51#ifdef _WIN32
     52#define BLARGG_USE_NAMESPACE 1
     53#endif
     54
     55//#define GEARBOY_DISABLE_DISASSEMBLER
     56
     57#define MAX_ROM_SIZE 0x800000
     58
     59#define SafeDelete(pointer) if(pointer != NULL) {delete pointer; pointer = NULL;}
     60#define SafeDeleteArray(pointer) if(pointer != NULL) {delete [] pointer; pointer = NULL;}
     61
     62#define InitPointer(pointer) ((pointer) = NULL)
     63#define IsValidPointer(pointer) ((pointer) != NULL)
     64
     65#if defined(MSB_FIRST) || defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
     66#define IS_BIG_ENDIAN
     67#else
     68#define IS_LITTLE_ENDIAN
     69#endif
     70
     71typedef uint8_t u8;
     72typedef int8_t s8;
     73typedef uint16_t u16;
     74typedef int16_t s16;
     75typedef uint32_t u32;
     76typedef int32_t s32;
     77typedef uint64_t u64;
     78typedef int64_t s64;
     79
     80typedef void (*RamChangedCallback) (void);
     81
     82#define FLAG_ZERO 0x80
     83#define FLAG_SUB 0x40
     84#define FLAG_HALF 0x20
     85#define FLAG_CARRY 0x10
     86#define FLAG_NONE 0
     87
     88#define GAMEBOY_WIDTH 160
     89#define GAMEBOY_HEIGHT 144
     90
     91#define AUDIO_BUFFER_SIZE 4096
     92
     93#define SAVESTATE_MAGIC 0x28011983
     94
     95struct GB_Color
     96{
     97    u8 red;
     98    u8 green;
     99    u8 blue;
    100};
    101
    102enum GB_Color_Format
    103{
    104    GB_PIXEL_RGB565,
    105    GB_PIXEL_RGB555,
    106    GB_PIXEL_BGR565,
    107    GB_PIXEL_BGR555
    108};
    109
    110enum Gameboy_Keys
    111{
    112    A_Key = 4,
    113    B_Key = 5,
    114    Start_Key = 7,
    115    Select_Key = 6,
    116    Right_Key = 0,
    117    Left_Key = 1,
    118    Up_Key = 2,
    119    Down_Key = 3
    120};
    121
    122#ifdef DEBUG_GEARBOY
    123    #ifdef __ANDROID__
    124        #include <android/log.h>
    125        #define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "GEARBOY", __VA_ARGS__);
    126    #endif
    127#define Log(msg, ...) (Log_func(msg, ##__VA_ARGS__))
    128#else
    129#define Log(msg, ...)
    130#endif
    131
    132inline void Log_func(const char* const msg, ...)
    133{
    134    static int count = 1;
    135    char szBuf[512];
    136
    137    va_list args;
    138    va_start(args, msg);
    139    vsprintf(szBuf, msg, args);
    140    va_end(args);
    141
    142    printf("%d: %s\n", count, szBuf);
    143
    144    count++;
    145}
    146
    147inline u8 SetBit(const u8 value, const u8 bit)
    148{
    149    return value | static_cast<u8>(0x01 << bit);
    150}
    151
    152inline u8 UnsetBit(const u8 value, const u8 bit)
    153{
    154    return value & (~(0x01 << bit));
    155}
    156
    157inline bool IsSetBit(const u8 value, const u8 bit)
    158{
    159    return (value & (0x01 << bit)) != 0;
    160}
    161
    162inline int AsHex(const char c)
    163{
    164  return c >= 'A' ? c - 'A' + 0xA : c - '0';
    165}
    166
    167#endif	/* DEFINITIONS_H */