forked from drhelius/Gearboy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefinitions.h
125 lines (99 loc) · 2.53 KB
/
definitions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Gearboy - Nintendo Game Boy Emulator
* Copyright (C) 2012 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <cstdarg>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <stdint.h>
#include <iostream>
#include <fstream>
//#define DEBUG_GEARBOY 1
#ifndef NULL
#define NULL 0
#endif
#ifdef _WIN32
#define BLARGG_USE_NAMESPACE 1
#endif
#define SAVE_FILE_SIGNATURE "GearboySaveFile"
#define SAVE_FILE_VERSION 5
#define SafeDelete(pointer) if(pointer != NULL) {delete pointer; pointer = NULL;}
#define SafeDeleteArray(pointer) if(pointer != NULL) {delete [] pointer; pointer = NULL;}
#define InitPointer(pointer) ((pointer) = NULL)
#define IsValidPointer(pointer) ((pointer) != NULL)
typedef uint8_t u8;
typedef int8_t s8;
typedef uint16_t u16;
typedef int16_t s16;
typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;
typedef int64_t s64;
#define FLAG_ZERO 0x80
#define FLAG_SUB 0x40
#define FLAG_HALF 0x20
#define FLAG_CARRY 0x10
#define FLAG_NONE 0
#define GAMEBOY_WIDTH 160
#define GAMEBOY_HEIGHT 144
struct GB_Color
{
u8 red;
u8 green;
u8 blue;
u8 alpha;
};
enum Gameboy_Keys
{
A_Key = 4,
B_Key = 5,
Start_Key = 7,
Select_Key = 6,
Right_Key = 0,
Left_Key = 1,
Up_Key = 2,
Down_Key = 3
};
#ifdef DEBUG_GEARBOY
#define Log(msg, ...) (Log_func(msg, ##__VA_ARGS__))
#else
#define Log(msg, ...)
#endif
inline void Log_func(const char* const msg, ...)
{
static int count = 1;
char szBuf[512];
va_list args;
va_start(args, msg);
vsprintf(szBuf, msg, args);
va_end(args);
printf("%d: %s\n", count, szBuf);
count++;
}
inline u8 SetBit(const u8 value, const u8 bit)
{
return value | (0x01 << bit);
}
inline u8 UnsetBit(const u8 value, const u8 bit)
{
return value & (~(0x01 << bit));
}
inline bool IsSetBit(const u8 value, const u8 bit)
{
return (value & (0x01 << bit)) != 0;
}
#endif /* DEFINITIONS_H */